Page 1 of 1
I'd like a little advice on making a patch, please.
Posted: 21 Sep 2009 19:33
by tubes
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.
Re: I'd like a little advice on making patch, please.
Posted: 21 Sep 2009 20:06
by Nite Owl
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?
Re: I'd like a little advice on making patch, please.
Posted: 21 Sep 2009 20:21
by tubes
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.
Re: I'd like a little advice on making patch, please.
Posted: 23 Sep 2009 19:23
by tubes
Ok, I think I've figured it out for myself...
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;
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'?
Re: I'd like a little advice on making patch, please.
Posted: 23 Sep 2009 20:31
by Yexo
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.
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).
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'?
You can do that yourself by editing your first post and changing the subject.
Re: I'd like a little advice on making a patch, please.
Posted: 24 Sep 2009 07:06
by tubes
Thank you very much, that's perfect. I'll get to work on the GUI then.
Re: I'd like a little advice on making a patch, please.
Posted: 24 Sep 2009 08:32
by HackaLittleBit
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