I'd like a little advice on making a patch, please.
Moderator: OpenTTD Developers
I'd like a little advice on making a patch, please.
Hi.
I'm trying to create a patch that adds new signal type - one that is always green.
my problem is me - I have basically no experience of C++, and I will be learning it as I go (stupid, I know, but hopefully, this will help me learn it).
Anyway, I decided to download the source, and take a look. It seems that what I need to do is add something along the lines of 'SIGTYPE_ALWAYS_GREEN = 6' to signal_type.h, then add a section to signal.cpp (somewhere around lines 275-350) that checks for that type of signal, then sets it to green, regardless of whether or not a train is occupying that block.
I've probably got this completely wrong, so I am hoping that someone might be able to give a short (if short is possible) explanation of how signals work within OpenTTD, and how exactly I would have to go about creating a new signal type.
Sorry if this is should be in OpenTTD Developement, but it seemed a little too trivial for that.
Thanks.
I'm trying to create a patch that adds new signal type - one that is always green.
my problem is me - I have basically no experience of C++, and I will be learning it as I go (stupid, I know, but hopefully, this will help me learn it).
Anyway, I decided to download the source, and take a look. It seems that what I need to do is add something along the lines of 'SIGTYPE_ALWAYS_GREEN = 6' to signal_type.h, then add a section to signal.cpp (somewhere around lines 275-350) that checks for that type of signal, then sets it to green, regardless of whether or not a train is occupying that block.
I've probably got this completely wrong, so I am hoping that someone might be able to give a short (if short is possible) explanation of how signals work within OpenTTD, and how exactly I would have to go about creating a new signal type.
Sorry if this is should be in OpenTTD Developement, but it seemed a little too trivial for that.
Thanks.
Last edited by tubes on 24 Sep 2009 06:36, edited 1 time in total.
Re: I'd like a little advice on making patch, please.
If a signal is always green (allowing a train to pass through it) regardless of there being another train in a signal block (and with the approaching train having no clear path through the signal block) would that not lead to trains crashing into each other on a regular basis?
Humor is the second most subjective thing on the planet
------------------------------------------------------------
Brevity is the soul of wit and obscenity is its downfall
--------------------------------------------------------
Good Night And Good Luck - Read You Soon
------------------------------------------------------------
Brevity is the soul of wit and obscenity is its downfall
--------------------------------------------------------
Good Night And Good Luck - Read You Soon
Re: I'd like a little advice on making patch, please.
Well... yes, if not done carefully.
I was imaging a carefully timed system - obviously, you'd have to have breakdowns off, and not mix train speeds, but it could be done.
For example, you could have a network comprised of fully presignaled stations, but no signals between them - instead, you just use a little signaling when merging lines, and then you can pack trains closer together. The signals would be used as a way of swtiching from signalled track to unsignalled track - without them, trains would just treat it as one massive block, and pile up at the entrance to it.
...obviously, it only works provide none of stations/junctions are over capacity, and no train ever has to wait in a queue.
tl;dr: Yes. Yes it would.
I was imaging a carefully timed system - obviously, you'd have to have breakdowns off, and not mix train speeds, but it could be done.
For example, you could have a network comprised of fully presignaled stations, but no signals between them - instead, you just use a little signaling when merging lines, and then you can pack trains closer together. The signals would be used as a way of swtiching from signalled track to unsignalled track - without them, trains would just treat it as one massive block, and pile up at the entrance to it.
...obviously, it only works provide none of stations/junctions are over capacity, and no train ever has to wait in a queue.
tl;dr: Yes. Yes it would.
Re: I'd like a little advice on making patch, please.
Ok, I think I've figured it out for myself...
I think I need to make lines 419-421 of signal.cpp read:so that it doesn't a make signal red if it is of my new type. Could someone maybe verify that I have that right?
on another note, is there anyone who can tell me how to add a new signal type to the GUI? I've rooted around the source code for quite some time, trying to find how, and also looked at http://docs.openttd.org/, but there's a lot of it... if someone could just tell me what file to look in, that would be a great help.
also, I've noticed the emmbarassing typo in my thread title. Oh dear. Is there some way I can change it to read 'making a patch'?
I think I need to make lines 419-421 of signal.cpp read:
Code: Select all
if ((flags & SF_TRAIN) && (sig != SIGTYPE_ALWAYS_GREEN)) {
/* train in the segment */
newstate = SIGNAL_STATE_RED;
on another note, is there anyone who can tell me how to add a new signal type to the GUI? I've rooted around the source code for quite some time, trying to find how, and also looked at http://docs.openttd.org/, but there's a lot of it... if someone could just tell me what file to look in, that would be a great help.
also, I've noticed the emmbarassing typo in my thread title. Oh dear. Is there some way I can change it to read 'making a patch'?
Re: I'd like a little advice on making patch, please.
All (or at least almost all) gui code is in _gui.cpp files. First place to look would thus be signal_gui.cpp. Because that file doesn't exist, you look in related files, and you'll find BuildSignalWindow in rail_gui.cpp (around line 1520, but that will change of course).tubes wrote:is there anyone who can tell me how to add a new signal type to the GUI? I've rooted around the source code for quite some time, trying to find how, and also looked at http://docs.openttd.org/, but there's a lot of it... if someone could just tell me what file to look in, that would be a great help.
You can do that yourself by editing your first post and changing the subject.also, I've noticed the emmbarassing typo in my thread title. Oh dear. Is there some way I can change it to read 'making a patch'?
Re: I'd like a little advice on making a patch, please.
Thank you very much, that's perfect. I'll get to work on the GUI then.
- HackaLittleBit
- Director
- Posts: 550
- Joined: 10 Dec 2008 16:08
- Location: tile 0x0000
Re: I'd like a little advice on making a patch, please.
Hello tubes
It might be interesting to have a look at my signal tunnel patch.
I think I do something there that is the same as what you want.
Regards HackaLittleBit
It might be interesting to have a look at my signal tunnel patch.
I think I do something there that is the same as what you want.

Regards HackaLittleBit
Who is online
Users browsing this forum: No registered users and 5 guests