Patch: More conditonal orders (r15271)

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Patch: More conditonal orders (r15271)

Post by Hirundo » 05 Jul 2008 14:24

13/04/09 Update to trunk r16055

Update 25/01/09
Finally an update to trunk, scroll down to the bottom of this post for a patch file.

Update 20/10/08
Update to current trunk, including savegame bump. I also posted a combined patch file of this patch and the stop in depot order patch. See http://www.tt-forums.net/viewtopic.php? ... 76#p738076

Major Update 25/08/08
New Features! and more. Check out this post for more info and the patch file.
Topic renamed from the way-too-long 'order jump based on waiting/accepted cargo' to 'More conditional orders'

-----------------------------
Update 11/07/2008
Changes
- If the patch hits the end of the order list without finding a 'next station', it will continue searching at the top.
- 'Next station accepts' and 'Waiting at next station' are moved to the bottom of the dropdown list, both in the GUI and internally. This should make this patch fully savegame-compatible with the trunk. However, it broke savegame compatibility with the previous version :(
- Some coding issues were fixed. I could not fix them all before I go on holiday, though. (These are my last minutes on the internet) Further improvements of coding style, better strings and more features will have to wait a few weeks.
<<file removed>>
-----------------------------

This patch adds two more options for a conditional order jump:
- Next station accepts [cargo] is true/false
- [cargo] waiting at next station is true/false
Note: 'Next station' refers to the next real station in the order list. If no such station exists in the order list, the expression evaluates to false.

These new options can have a lot of uses, especially in combination with ECS. A few examples:

1) It becomes very easy to balance pickup from several scources. If 'cargo waiting at scource A is false', then another train is already loading there and we can go somewhere else.

2) You transport coal to an ECS steel mill. If the coal stockpile is full, the train goes to the power plant instead (see picture)
order window.PNG
example of conditional orders
order window.PNG (4.13 KiB) Viewed 21553 times
3) Distribution of stuff like ECS vehicles or fertilizer to all the industries that need them becomes a lot easier. There is no need to send the cargo to industries whose stockpile is already full any more. See the following example order list:
order window 2.PNG
example of conditional orders
order window 2.PNG (5.1 KiB) Viewed 21552 times
This is my first patch (actually the first thing ever in c++). All comments/criticism regarding bugs, functionality, coding style or anything else are welcome.

This patch has one known issue; when replacing a vehicle in a depot, conditional orders and all orders following it are lost. This is not the fault of this patch, but a trunk bug (FS #2130)

The patch file is below. Patch is against r13677. Although the savegame format/version is not changed, keep in mind that savegames are not backwards compatible.
more-cond-orders-r16055.patch
Patch file for r16055
(27.97 KiB) Downloaded 429 times
Last edited by Hirundo on 13 Apr 2009 21:41, edited 6 times in total.
Create your own NewGRF? Check out this tutorial!

User avatar
Wolf01
Tycoon
Tycoon
Posts: 2013
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Re: Patch: order jump based on waiting/accepted cargo (r13677)

Post by Wolf01 » 05 Jul 2008 14:29

Great! That's what I ever missed on conditional orders
I hope it will be applied to trunk

Youri219
Traffic Manager
Traffic Manager
Posts: 191
Joined: 28 Apr 2007 11:53

Re: Patch: order jump based on waiting/accepted cargo (r13677)

Post by Youri219 » 05 Jul 2008 18:39

This is really nice, looks like the conditional order are becoming mature. I have some more suggestions for conditional jumps:
- Jump to order x when Next station has all platforms occupied.
- Jump to order x when Next station has y trains loading <cargo>.

audigex
Tycoon
Tycoon
Posts: 1919
Joined: 09 Dec 2007 21:28
Contact:

Re: Patch: order jump based on waiting/accepted cargo (r13677)

Post by audigex » 05 Jul 2008 18:55

One problem...

If a train goes from station A to pick up at station B, UNLESS station B is full when it goes to station C

What happens if station B is not full when the train leaves, but by the time it gets there it is full? Or vice versa. IE if the stations are a long way away, the status won't be the same when the train actually needs to make the decision.
Jon

Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: Patch: order jump based on waiting/accepted cargo (r13677)

Post by Rubidium » 05 Jul 2008 23:28

Some issues/comments; coding and conceptually:
- what is the 'next' station? Should conditional orders be processed when trying to find them? If so, don't keep infinitively searching through conditional orders (see other code handling that).
- the order list is not 'looped linked list', i.e. if the last order is a waiting/accepted cargo order it will never find the next station.
- [next station] [accepts/does not accept] [<cargo type>] looks nicer to me. Same as [next station] [has/has no] [<cargo type>].
- *Cmd must always check parameters extensively for validity; now you only test whether the cargo type is in range, but it should also check whether the cargo type is actually used.
- it is "if (", not "if(".
- "else <statement>" is not allowed. Only "if (xxx) <statement>" is allowed, otherwise always use { and }.
- _order_conditional_cargo_names will overflow when all cargo slots are used.
- _order_conditional_cargo_names and _order_conditional_cargo_dropdown should be a class member (not needed to have them while the window isn't opened).
- do not add trailing whitespace; trailing whitespace in all it's forms is not accepted.
- _order_conditional_cargo_dropdown could be replaced by a bitmask of disabled dropdown buttons in which case _order_conditional_cargo_names would contain the names of the cargo indexed by the cargo type. This makes that it is not needed to do any conversions between cargo type and dropdown index or the other way around.
- please do not add order variables in between others as that breaks savegame compatability.

A major 'problem' with this patch might be the fact that the order jump is executed at the moment the previous order is fullfiled, which might cause people complaining. So I guess some documentation is needed that for these two functions to be useful one might need to add a waypoint just before the station.

User avatar
athanasios
Tycoon
Tycoon
Posts: 3138
Joined: 23 Jun 2005 00:09
Contact:

Re: Patch: order jump based on waiting/accepted cargo (r13677)

Post by athanasios » 05 Jul 2008 23:52

The waypoint solution is a very smart idea Rubidium. Thanks.
I like this patch, and waypoints are going to be very useful here; thus they will be used extensively.
http://members.fortunecity.com/gamesart
"If no one is a fool I am also a fool." -The TTD maniac.


I prefer to be contacted through PMs. Thanks.

DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Patch: order jump based on waiting/accepted cargo (r13677)

Post by DaleStan » 06 Jul 2008 02:20

Swallow wrote:This patch adds two more options for a conditional order jump:
- Next station accepts [cargo] is true/false
- [cargo] waiting at next station is true/false
When I look at the screenie, I see "Next station accepts is true/false [cargo]". Kindly make the button order match the natural language order?
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser

Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: Patch: order jump based on waiting/accepted cargo (r13677)

Post by Hirundo » 06 Jul 2008 10:46

Thanks for the replies all. I'm kinda busy at the moment but I'll try to make a new version somewhere this week.

@Youri219: I will certainly look into it. Refining the existing code will have priority however, so it will probably have to wait until after the holidays.

@audigex: Rubidium's suggestion of waypoints will help a lot I think. It's also possible to check load percentage after going to B. If it is more than zero, the train can still decide to go to C.

@Rubidium: Thanks for the comments, that is exactly the kind of feedback I needed :)
Create your own NewGRF? Check out this tutorial!

User avatar
cmoiromain
Chief Executive
Chief Executive
Posts: 655
Joined: 15 Jan 2007 21:45
Location: FRANCE
Contact:

Re: Patch: order jump based on waiting/accepted cargo (r13677)

Post by cmoiromain » 06 Jul 2008 23:54

this patch is great! It certainly will help make networks more efficient.
I am little, ugly, and nasty. How do you do?

User avatar
Timitry
Transport Coordinator
Transport Coordinator
Posts: 313
Joined: 01 Oct 2004 15:28
Contact:

Re: Patch: order jump based on waiting/accepted cargo (r13677)

Post by Timitry » 07 Jul 2008 10:55

Is there already an option like "If the train is empty, skip next station"?

Situation where this would be useful:
If playing with ECS Vectors or PBI, the train delivers cargo to a station. Now it could happen that the stockpile is full, so the train can't deliver any or all of his cargo. You set the train to go to another station which also accepts the cargo. Now it would be great if the train would check if it has still cargo left after the first station and would only then go to the second accepting station, and else to the loading station.

Hope you get what i mean :)

Greets, Tim

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9282
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Patch: order jump based on waiting/accepted cargo (r13677)

Post by planetmaker » 07 Jul 2008 11:52

Timitry wrote:Is there already an option like "If the train is empty, skip next station"?
Even in trunk.

User avatar
Timitry
Transport Coordinator
Transport Coordinator
Posts: 313
Joined: 01 Oct 2004 15:28
Contact:

Re: Patch: order jump based on waiting/accepted cargo (r13677)

Post by Timitry » 07 Jul 2008 14:23

Wow, i never noticed those conditional order jumps had been in trunk... Well hidden ;-)

Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: Patch: order jump based on waiting/accepted cargo (r13691)

Post by Hirundo » 11 Jul 2008 09:41

Update in first post
Create your own NewGRF? Check out this tutorial!

Chico008
Traffic Manager
Traffic Manager
Posts: 137
Joined: 05 Mar 2008 10:56
Location: France

Re: Patch: order jump based on waiting/accepted cargo (r13691)

Post by Chico008 » 19 Jul 2008 07:12

these kind of jump order are better than the "skip on remaining cargo".
specially with the ECS, but evan without it.

hope theses orders will get included in trunk ;)
Thanks for it, works very well ;)

eerroorr
Engineer
Engineer
Posts: 10
Joined: 28 Oct 2007 16:21

Re: Patch: order jump based on waiting/accepted cargo (r13691)

Post by eerroorr » 31 Jul 2008 23:49

Why not change controls to read

"next station" "accepts"|"doesn't accept"|"has cargo waiting"|.. <cargo type>

"is false" business is a bit clumsy:D

User avatar
ostlandr
Chairman
Chairman
Posts: 882
Joined: 12 May 2007 01:09
Location: Northeastern USA

Re: Patch: order jump based on waiting/accepted cargo (r13691)

Post by ostlandr » 06 Aug 2008 00:04

I've used this a few times now, and I like it! :)

First time, I had trains hauling coal and iron ore (in the same train) to a PBI steelmill. Of course, the coal mine is producing much more than the iron ore mine. Eventually the coal stockpile would get full and the mill station would stop accepting coal. So I set the trains up to stop first at the steelmill, then at a nearby power plant before returning to the mine. Then I added "if 'load percent' = 0, 'skip to'" the order for the iron mine station. Worked perfectly.

Next use was on trains hauling lumber and goods in one direction, and wood and goods in the other, with several stops. The forest on that line wasn't producing very much yet, but the sawmill was getting wood from the other direction, so I had lots of trains on that line. The trains transfering from the forest to the wood pickup were using full load. So a train would arrive with wood, the next 3 or so trains would load wood, then the next few would stop for no reason since the station was empty. I used "if 'waiting at next station' = 'wood' is false, 'skip to'" the next station, so that the trains would just roll on by the wood pickup on the bypass track if it was empty. Really reduced congestion and increased throughput on that line.
Who is John Galt?

mnhg
Engineer
Engineer
Posts: 29
Joined: 13 Dec 2007 17:29

Re: Patch: order jump based on waiting/accepted cargo (r13691)

Post by mnhg » 06 Aug 2008 19:17

Hi,

your patch ist great. I tried successfull to build a self regulating network similar to this one:
http://www.tt-forums.net/viewtopic.php?f=29&t=38704

The great advantage with your patch is, than you only neet a waypoint in front of every loading station and one for looping. Just add some conditions and all the feeder-hack-thing in the other thread can be skipped.

My only problem is that the building of the order is a little time expensive :). So I tried to write a patch to build an order automatically, but I had to discover that my C++ knowlegde is as bad as the documentation for OpenTDD ;)

Is anybody able to give me a hint how I could extent the following order: (as many code as possible :) )

Code: Select all

Waypoint
Station
Waypoint
Station
...
---
LoopWaypoint
UnloadingStation
To:

Code: Select all

-Begin-
Jump Next
 Waypoint
 Jump Next
  Station
  Jump End
-Next-
Jump Next
 Waypoint
 Jump Next
  Station
  Jump End
-Next-
...
---
LoopWaypoint
Jump Begin
-End-
UnloadingStation
where Jump Next is "jump on nothing waiting at next station".


I hope you understand my problem.

mnhg
Engineer
Engineer
Posts: 29
Joined: 13 Dec 2007 17:29

Re: Patch: order jump based on waiting/accepted cargo (r13691)

Post by mnhg » 07 Aug 2008 14:02

I could implement my idea, and thought everything works fine, until I restarted and loaded the game. Now I get an TOO_MANY_ORDER error on loading. Can anybody tell me where this error is raised?

Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: Patch: order jump based on waiting/accepted cargo (r13691)

Post by Hirundo » 25 Aug 2008 19:18

After quite some time finally a much-needed update to this patch. The good news is that the update is a big one. It features:

> A New Feature: Jump if next station has X platforms free. With this option one can for example divert traffic away from overcrowding stations and towards empty stations.

> Yet Another New Feature: Jump XX percent of times. The good thing is that this is non-random. So if you set it to, for example, 50%, your vehicle will jump the first, third, fifth time and so on. This also works for shared vehicles. With this option, it is possible to equally divide traffic between different stations / mainline lanes etc. Or to let only a quarter of the trains stop in that tiny village with 10 passengers/month.

> Better strings for existing features: Next station accepts/does not accept X and Next station has/does not have X waiting. Since I am no native English speaker nor a GUI hero, it may not be perfect. Suggestions for improvements are welcome.

> Behind-the-scenes improvements in code.

Picture:
order window 3.PNG
order window 3.PNG (10.24 KiB) Viewed 19425 times
Suggestions / comments / criticism / bug reports are welcome. (Well, I hope no bugs :wink: )

Note that I will create a split version of (parts of) this patch if this is requested.

EDIT: Patch file is now obsolete
Attachments
more-cond-orders-r14173.patch
the patch, for r14173
(27.89 KiB) Downloaded 378 times
Last edited by Hirundo on 20 Oct 2008 19:00, edited 1 time in total.
Create your own NewGRF? Check out this tutorial!

User avatar
Wolf01
Tycoon
Tycoon
Posts: 2013
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Re: Patch: More conditonal orders (r14173)

Post by Wolf01 » 26 Aug 2008 11:22

Really nice new additions :D
Congratulations for this patch, I wish it will be in trunk

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 4 guests