I managed to trigger strange behaviour, see attached screen shot. A split track, one is empty, one is occupied with a slow train. The follow up train, a fast one, slows down, speeds up, slows down, speeds up, etc.
Hm, I can't seem to reproduce this. Under certain conditions, however, acceleration may cause the train to break too much, increasing the number of signal blocks between the trains, causing it to accelerate and so forth, making it oscillate between two different values. It could also be that the train leaves the 20-tile "search radius".
It may also behave strangely when two trains are heading for a head-on collision. I may include a check for this.
At stations, it may appear to be behaving strangely, since it'll slow down oncoming trains to arrival speed (24km/h). I'm not sure how to fix it though, I could add a check for station tiles, or I could increase the lower speed limit for which the rule is applied. I'm not a big fan of magic numbers, so the first option is probably the way to go.
A few remarks and thoughts, though:
- you totally break savegame compatibiliy. In settings.h you remove existing lines without comment, necessity and on the penalty of breaking the loading of old savegames. Nor do you bump the savegame version when introducing your new setting which alone also needs this savegame bump. Thus it needs taking care also in the saveload code.
- it doesn't fulfill its purpose flawlessly. Trains also slow down if they pass a slow train on a two-track arrangement or "see" a train in a depot (see screenshot and let two trains run on a similar thing). As this flaws became obvious after looking at a new game in 5 minutes I expect many other cases to fail or suffer from similar bugs.
- As a result of the above point, my guess is that you'll have to integrate this into the path finder - and worse - have a train know about the paths of other trains. The performance impact of this will need assessment.
- Especially in settings.h but also elsewhere you should watch the coding style. Indentation is done by tabs, avoid trailing and leading white space.
Thanks, I'll have a look at these things.Edit:
I've looked over the code, bumped the savegame version and fixed most (all?) style issues. The problem concerning stations should also be fixed (a train is no longer considered if it is braking), as should the dual-track issue (search stops when a switch is encountered, this is an ugly solution but it's the best I can do without meddling with the pathfinder... I think). Obviously this needs more testing, and I appreciate any input I receive.