Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Thu May 25, 2017 2:22 pm

All times are UTC




Post new topic  Reply to topic  [ 16 posts ] 
Author Message
PostPosted: Tue Jul 29, 2014 1:17 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Thu Jul 16, 2009 10:04 am
Posts: 321
This patch gives the possibility of setting waiting times in depots, exactly as we can in station.


Attachment:
Screenshot-Wait_in_depot.png
Screenshot-Wait_in_depot.png [ 106.87 KiB | Viewed 4163 times ]


In my view, this is particularly useful - even necessary - for some cases of timetabling. It is specially useful for timetabled trams. Even when they are properly timetabled, trams are often overtaken by those who come behind and after that, it's quite tedious/hard to reorder properly all the vehicles. Waiting some time in depots allows the vehicles to reorder properly. Setting waiting times in depots and not (or less) in stations, also allows vehicles to leave platforms sooner and hence, have some more fluid traffic.

In the way I coded it, there is still one difference with the behaviour a vehicle has in stations: when you set a travel time to the depot, but not a wait time in the depot, the vehicle will behave as without the patch: it means, that - in case the vehicle arrives at the depot sooner as scheduled - it will not wait there, as it would in stations. That was chosen to maintain the original behaviour if needed.

That's my first try in patching, so I only hope everything works. Normally the patch file should be applicable without problems to latest trunk (now r26706). As a side note, so far there is not any savegame compatibility problem.

Any bugs/problems report will be welcome. Also, any coding advice will be very useful ! Probably there is a lot to make better.


Attachments:
wait_in_depot-v2.patch [8.5 KiB]
Downloaded 120 times

_________________
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.


Last edited by keoz on Mon Aug 04, 2014 12:18 pm, edited 1 time in total.
Top
   
PostPosted: Tue Jul 29, 2014 1:39 pm 
Offline
Transport Coordinator
Transport Coordinator

Joined: Fri Jan 19, 2007 7:26 pm
Posts: 326
\o/

Have been wanting this for years :) It's much easier to timetable this way and keep good separation/order. Now I sometimes used very very big stations on the end of the timetable, even though they were often in small places.

EDIT: saw it was over 6 years ago :D viewtopic.php?f=29&t=37166&start=20#p691994 .


Top
   
PostPosted: Tue Jul 29, 2014 4:51 pm 
Offline
Tycoon
Tycoon

Joined: Wed Jan 17, 2007 12:14 am
Posts: 6908
it might be a good idea in general to treat 0 wait time as "don't wait here" instead of "this is unscheduled" also for stations

_________________
You might not exactly be interested in Ferion, but if you are, have fun :)


Top
   
PostPosted: Wed Jul 30, 2014 12:29 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Thu Jul 16, 2009 10:04 am
Posts: 321
Eddi wrote:
it might be a good idea in general to treat 0 wait time as "don't wait here" instead of "this is unscheduled" also for stations


Indeed. That would allow no waiting stations in scheduled timetables - original behaviour could still be maintained by giving some, even minimal, waiting time in stations - and, in the scope of this patch, unify the behaviour between depots and stations. I'll think about that.

Anyway. In so far, everything seems to work fine without problems.

_________________
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.


Top
   
PostPosted: Mon Aug 04, 2014 12:20 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Thu Jul 16, 2009 10:04 am
Posts: 321
Update to v2. Some code cleaning and corrections (depot "stop" orders can not anymore be timetabled).

_________________
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.


Top
   
PostPosted: Mon Aug 04, 2014 5:08 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4529
Location: /home/sweden
First, I have never worked with orders in the C++ code so this comment is just from just now looking at the code. Before I have only worked programmatically with orders from AI side which is a bit simplified sometimes when not all complexity needs to be exposed.

I wonder though, why adding a new OT_WAITING? As I understand it, stations don't have a separate OT_* enum value for when to wait at the station. So why do this for depots? Is it not enough that the depot order has the depot flag set to ODATF_SERVICE_ONLY which I assume correspond to "go always to depot (but not stop there)", and set order->wait_time to a value > 0 for you as condition on when to wait?

From my quick look, dropping OT_WAITING would be more consistent with how it works for stations, but if I'm wrong on this (or that it will not work without it), please enlighten me. :-)


You can find the OpenTTD coding style documented here: https://wiki.openttd.org/Coding_style . You have spaces as indentation and deviate from how multi-line comments should be made. Also if-statements with code on the next line should use curly brackets. This is all explained in the wiki. Your code is already readable as such, but before going into trunk it need to follow the coding style. Though this is less important than how you actually solved things in your patch.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
PostPosted: Mon Aug 04, 2014 7:29 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Thu Jul 16, 2009 10:04 am
Posts: 321
Thank you for your remarks, Zuu.

The answers I can give so far:

Zuu wrote:
I wonder though, why adding a new OT_WAITING?


I knew that this was going to be, eventually, the most discussed point. It's a quite a change. I'll try to explain my reasons for this choice.

Zuu wrote:
As I understand it, stations don't have a separate OT_* enum value for when to wait at the station. So why do this for depots?


Actually, they do have specific orders for stations. When a train stops in station, it triggers some order-type changing. Specifically: when arriving, order type becomes OT_LOADING and after that, when the train is going to leave, it becomes OT_LEAVESTATION. So, internally, what looks as a single goto station order actually changes in at least 3 order-types during its processing (all this orders are listed in order_base.h, l. 37).

A lot of my choices were mainly guided exactly by what you mention as important: trying to make the in-depot behaviour as consistent as possible with what happens in stations. Some other choices also results from that. The HandleWaiting() function, i.e. (in vehicle.cpp), is largely inspired from the HandleLoading() function.

Zuu wrote:
Is it not enough that the depot order has the depot flag set to ODATF_SERVICE_ONLY which I assume correspond to "go always to depot (but not stop there)", and set order->wait_time to a value > 0 for you as condition on when to wait?


Well. Actually, when I decided to introduce the OT_WAITING order, I had the feeling that this was necessary to make things properly. Now that I worked a lot more on the code, and that I better understand it, I think it is probably possible to make the thing without it. I'm trying to do that right at the moment and I'll be able to answer you more consistently.

But I also already see that avoiding this order seems to bring to some inconsistencies. A lot of tests can be better achieved if there is actually a clear way to check whether the train is waiting or not (example: when processing orders; when recalculating the arrival/departure board; also in the skip orders function). My thought also was that a such kind of order could be interesting to be used in a lot of cases other than depots (waiting at Waypoints ?), thus useful for future development.

Zuu wrote:
You can find the OpenTTD coding style documented here: https://wiki.openttd.org/Coding_style . You have spaces as indentation and deviate from how multi-line comments should be made. Also if-statements with code on the next line should use curly brackets. This is all explained in the wiki. Your code is already readable as such, but before going into trunk it need to follow the coding style. Though this is less important than how you actually solved things in your patch.


Yes, I tried to comply the best but obviously, I read that part a little bit to fast. Will fix that. :)

_________________
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.


Top
   
PostPosted: Mon Aug 04, 2014 8:31 pm 
Offline
Tycoon
Tycoon

Joined: Wed Jan 17, 2007 12:14 am
Posts: 6908
waiting at a waypoint won't work properly, because the train doesn't know whether it needs to stop when approaching the waypoint. so either you always slow down at a waypoint (bad), or you come to a full stop immediately (bad).

_________________
You might not exactly be interested in Ferion, but if you are, have fun :)


Top
   
PostPosted: Mon Aug 04, 2014 11:19 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Thu Jul 16, 2009 10:04 am
Posts: 321
Eddi wrote:
waiting at a waypoint won't work properly, because the train doesn't know whether it needs to stop when approaching the waypoint. so either you always slow down at a waypoint (bad), or you come to a full stop immediately (bad).


Well, supposing that someone defines a waiting time at a waypoint, the train would know that it's gonna to stop and wait (just as in stations). And anyway, it also does not know whether it'll have to stop when approaching a signal, but it still stops if needed.

BTW, that's not exacly my point. By no way I am now proposing to further have Waypoint's wait time. I just meant that it's not impossible that this kind of order may be useful for other further/corner cases. I may be wrong, of course.

_________________
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.


Top
   
PostPosted: Tue Aug 05, 2014 2:10 am 
Offline
Tycoon
Tycoon

Joined: Wed Jan 17, 2007 12:14 am
Posts: 6908
keoz wrote:
Well, supposing that someone defines a waiting time at a waypoint, the train would know that it's gonna to stop and wait (just as in stations).
well, that can easily be achieved currently by placing a station and using it with a "go via" order (without stopping) or a "no loading and no unloading" order (with stopping and timetabling)
Quote:
And anyway, it also does not know whether it'll have to stop when approaching a signal, but it still stops if needed.
well, that is some giant hack that is supposed to be removed at some point in the future, so it makes for a very bad argument. also, the case is different, because you know that you need to stop at a signal at least one tile in advance, but you don't really know whether the wait time on the waypoint will be over until you are on the exact stopping location. or you need to figure out a formula that easily predicts the amount of time it will take, including current speed and acceleration, to travel X steps. (1 tile = 16 steps).

_________________
You might not exactly be interested in Ferion, but if you are, have fun :)


Top
   
PostPosted: Wed Aug 06, 2014 2:25 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Thu Jul 16, 2009 10:04 am
Posts: 321
Zuu, I've been exploring some time about your suggestion (getting rid of the introduced OT_WAITING order type).

The problem is that if I remove it, I can't find a proper way to check whether the train is - or is not - waiting in a depot at a given time.

Some other possibilities have been explored to check that "waiting in depot" state:
- the function "bool IsInDepot()": but this one returns true even if a vehicle is only partially - and still not entirely - entered in depot and still after that, when it is leaving the depot, but still not entirely out.
- the function "bool IsChainInDepot()": this one returns true only when the vehicle completely arrived in depot, but keeps returning true when it's going out from the depot and still not completely out.
- the state ODATF_SERVICE_ONLY (which you mentioned over): the problem with this state flag, is that it is true during the entire processing of the OT_GOTO_DEPOT order, which means it is true already when the train is travelling TO the depot. Hence, it is unreliable to determine whether the train already arrived in the depot and is waiting there.

Now, the point is that at some moments, I need to have an accurate way to make that check. An example:

Code:
bool travelling = (!v->current_order.IsType(OT_LOADING) || v->current_order.GetNonStopType() == ONSF_STOP_EVERYWHERE);


This variable definition is found in the function used to build the arrival/departure board. The variable "travelling" is necessary to properly make the calculations. Note that here, this check is performed using the OT_LOADING state for vehicles waiting in stations. But I also need this variable to be true when a vehicle is waiting in depot. Here, the OT_WAITING order lets make that check :

Code:
bool travelling = (!(v->current_order.IsType(OT_LOADING) || v->current_order.IsType(OT_WAITING)) ||
v->current_order.GetNonStopType() == ONSF_STOP_EVERYWHERE);


Which is clear and neat, IMO. In other places too, I need that check to be made properly. In the vehicle controllers, (example RoadVehController(), in roadveh_cmd.cpp), when calling the waiting handling function (HandleWaiting()), I need to perfectly know whether the vehicle is waiting or not.

So far, all of this let's me think that trying to remove the OT_WAITING order is a dead end.

_________________
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.


Top
   
PostPosted: Wed Aug 06, 2014 3:08 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Sun Sep 09, 2007 5:03 am
Posts: 4353
Location: home
The other direction is concluding that IsChainInDepot is broken, and must be fixed.
The Doxygen documentation excludes going out of the depot for returning true.

Either the code or the documentation is wrong thus at least.


Top
   
PostPosted: Wed Aug 06, 2014 5:36 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Thu Jul 16, 2009 10:04 am
Posts: 321
Alberth wrote:
The other direction is concluding that IsChainInDepot is broken, and must be fixed.
The Doxygen documentation excludes going out of the depot for returning true.

Either the code or the documentation is wrong thus at least.


I'll have better look on that, then. I'm maybee wrong on this point and badly interpreted the tests I did.

_________________
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.


Top
   
PostPosted: Thu Aug 07, 2014 5:33 am 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Sun Sep 09, 2007 5:03 am
Posts: 4353
Location: home
keoz wrote:
I'll have better look on that, then. I'm maybee wrong on this point and badly interpreted the tests I did.
To be clear on this, I was not saying your tests were wrong.

The name "IsChainInDepot" suggests to me all vehicles of a train should be in the depot for the function to return true. This is also what the documentation of the function says. If you have a test that shows a train can partially drive out of the depot while the function still returns true, something is wrong.

I don't know train code well enough to understand the function, so I cannot quickly check what the function is actually doing. It seems to be used at least in autoreplace, where having fully entered the depot is important. I don't know what the other uses do exactly, but it may well be that currently only the "having fully entered" case matters, and the "not started leaving" case is never relevant currently. (You should check that probably.)

In that situation, nobody checks what the function does in the "not started leaving" case, and nobody would find a contradiction between the documentation and the actual behavior.


Top
   
PostPosted: Thu Aug 07, 2014 5:41 am 
Offline
Tycoon
Tycoon

Joined: Wed Jan 17, 2007 12:14 am
Posts: 6908
it may very well be that the "chain is leaving the depot" case is a "don't care", as the front vehicle won't be in the depot during that phase anyway. a vehicle is unlisted from the depot view as soon as the front vehicle leaves.

_________________
You might not exactly be interested in Ferion, but if you are, have fun :)


Top
   
PostPosted: Fri Sep 11, 2015 7:44 pm 
Offline
Director
Director

Joined: Tue Jul 17, 2007 5:56 pm
Posts: 572
Thank you very much for this patch, I started integrating it into my own patch, as I never got that particular feature running before.

If anyone has some clue into which problem I might be running here viewtopic.php?f=33&t=63721&p=1156165#p1156165 your hints would be highly welcome.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 16 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2017 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2017.
Hosted by Zernebok Hosting.