[patch] Programmable waypoints

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

Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

[patch] Programmable waypoints

Post by Yexo »

This patch provides programmable waypoints. You define a set of criteria per waypoint, and each train that matches that criteria is either assigned a penaltie for crossing it or is denied access to that tile.
Current gui
Current gui
progwaypoints.png (80.62 KiB) Viewed 1748 times
The patch is against revision 11834

Ideas for this patch come from programmable signals in ttdpatch (it at least once was) and the colored trains patch.

Version 0.3: Loading of games is implemented. Loading/saving of the waypoint state not yet. Made a start with converting all RuleSet pointers to a mempool.
Version 0.4: Loading/saving of the game now works! I've tested multiplayer only a little bit (starting openttd twice on my computer) and it seems to work. Also see this post
Version 0.5: Cloning/sharing of rules between waypoints is now possible. New rule: current order. Select a station/waypoint/depot to match. I'm still working on groups. The code works, but the gui does not.
Version 0.6: It's now possible to make rules based on the group a vehicle is in (or not in). Updated to r11834. Due to a savegame-version update in trunk it's not possible to load savegames created with v0.5 or before.
Updated version so it compiles on windows.
Attachments
progwaypoints.diff
Programmable waypoints v0.6
(61.57 KiB) Downloaded 454 times
Last edited by Yexo on 16 Jan 2008 12:42, edited 11 times in total.
Brainy
Engineer
Engineer
Posts: 10
Joined: 18 Jul 2003 15:26

Re: Programmable waypoints

Post by Brainy »

Wonderful, can't wait for it to be released.
I am the Superior Intelligence
User avatar
Ben_K
Tycoon
Tycoon
Posts: 1166
Joined: 01 Jun 2006 15:15
Location: Sydney, AUS

Re: Programmable waypoints

Post by Ben_K »

Looks like a neat idea Yexo! Sorry I can't help with the coding but I hope you stick with it and get a good feature out of it! :D
User avatar
Ammler
President
President
Posts: 953
Joined: 18 Jun 2006 18:18
Location: Switzerland
Contact:

Re: Programmable waypoints

Post by Ammler »

Hmm, I would prefer the way like TTDP goes, is it possible to programm a signal instead of waypoints?

The problem of waypoints is, you can't place them everywhere and maybe there is no space left for it anyway...

Greets
Ammler
User avatar
pavel1269
Route Supervisor
Route Supervisor
Posts: 473
Joined: 03 Dec 2006 13:22
Location: Czech Republic
Contact:

Re: Programmable waypoints

Post by pavel1269 »

ammler wrote:Hmm, I would prefer the way like TTDP goes, is it possible to programm a signal instead of waypoints?
Atm, i ma coding them ;) but it's quite hard :(
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Programmable waypoints

Post by Yexo »

ammler wrote:Hmm, I would prefer the way like TTDP goes, is it possible to programm a signal instead of waypoints?

The problem of waypoints is, you can't place them everywhere and maybe there is no space left for it anyway...

Greets
Ammler
It's relatively easy to change this patch to work on signals instead of waypoints, but initially this was easier. So I'll first make this work and maybe I'll change it later to work on signals instead of waypoints.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Programmable waypoints

Post by Yexo »

Just uploaded the first version of the patch. I would like comments about the gui/functionality. See first post for the patch.
Buhmann
Engineer
Engineer
Posts: 20
Joined: 20 Dec 2007 18:20

Re: Programmable waypoints

Post by Buhmann »

Woa that looks awsome!
I think I'm going to test this patch tomorrow.

[EDIT]
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp: In function »int GetRuleFromRuleWndPt(Window*, int)«:
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:153: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp: In function »void RulesProc(Window*, WindowEvent*)«:
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:330: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp: In function »CommandCost CmdChangeRule(TileIndex, uint32, uint32, uint32)«:
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:459: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:463: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp: In function »CommandCost CmdRemoveRule(TileIndex, uint32, uint32, uint32)«:
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:549: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:565: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:573: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
(in english: You compare unsigned integers to signed integers quite often)


[EDIT2]
Would it be possible to check things like cargo-type?

Code: Select all

Cargo is only passengers

Code: Select all

Cargo is not passengers

Code: Select all

Cargo is amongst others passengers
AND
Cargo is not goods
and stuff like that.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Programmable waypoints

Post by Yexo »

Buhmann wrote:Woa that looks awsome!
I think I'm going to test this patch tomorrow.

[EDIT]
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp: In function »int GetRuleFromRuleWndPt(Window*, int)«:
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:153: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp: In function »void RulesProc(Window*, WindowEvent*)«:
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:330: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp: In function »CommandCost CmdChangeRule(TileIndex, uint32, uint32, uint32)«:
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:459: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:463: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp: In function »CommandCost CmdRemoveRule(TileIndex, uint32, uint32, uint32)«:
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:549: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:565: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
/home/thomas/OTTD-dev/test/trunk/src/progsignal.cpp:573: Warnung: Vergleich zwischen vorzeichenbehafteten und vorzeichenlosen Ganzzahlausdrücken
(in english: You compare unsigned integers to signed integers quite often)
I know, but this is only the first version :). I'll fix this in the next version.
[EDIT2]
Would it be possible to check things like cargo-type?

Code: Select all

Cargo is only passengers

Code: Select all

Cargo is not passengers

Code: Select all

Cargo is amongst others passengers
AND
Cargo is not goods
and stuff like that.
Good idea, hadn't thought of that myself, but I'll try to implement it.
T-Unit
Transport Coordinator
Transport Coordinator
Posts: 368
Joined: 03 Feb 2007 18:53
Location: Leeds, England

Re: Programmable waypoints

Post by T-Unit »

Buhmann wrote: [EDIT2]
Would it be possible to check things like cargo-type?

Code: Select all

Cargo is amongst others passengers
and stuff like that.
Would that be the same as:

Code: Select all

Cargo includes passengers
?
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Programmable waypoints

Post by Yexo »

T-Unit wrote:
Buhmann wrote: [EDIT2]
Would it be possible to check things like cargo-type?

Code: Select all

Cargo is amongst others passengers
and stuff like that.
Would that be the same as:

Code: Select all

Cargo includes passengers
?
That's how I interpretted it. The option will be like this:
Cargo (passengers) >= 0
AND
Cargo (mail) == 0

So that would match a train with passengers but only those that don't transport mail.
Buhmann
Engineer
Engineer
Posts: 20
Joined: 20 Dec 2007 18:20

Re: Programmable waypoints

Post by Buhmann »

Yap, that's what I meant

But what is the unit for the length of the train?
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Programmable waypoints

Post by Yexo »

Buhmann wrote:Yap, that's what I meant

But what is the unit for the length of the train?
1/8 or 1/16 of a tile. I'll have to fix that to be tile-length.

I have updated the first post to include v0.2 of the patch. Amount of cargo is now one of the options and the compile-time warnings are gone.
andrewas
Engineer
Engineer
Posts: 115
Joined: 03 Oct 2005 19:14

Re: [patch] Programmable waypoints

Post by andrewas »

Yexo wrote: Saving and loading of the state is not yet implemented. And for some reason that I can't find it won't load savegames created with the unmodified version.
You add three settings variables, and then tell the program that they should be present for save versions 33 through to SL_MAX_VERSION. Since they are not present, the save code cannot read the file. Increment the save version in saveload.cpp, and alter those three variables to be present from 83 onwards, and it should work. Any other variables added to the save will need similar treatment.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: [patch] Programmable waypoints

Post by Yexo »

andrewas wrote:
Yexo wrote: Saving and loading of the state is not yet implemented. And for some reason that I can't find it won't load savegames created with the unmodified version.
You add three settings variables, and then tell the program that they should be present for save versions 33 through to SL_MAX_VERSION. Since they are not present, the save code cannot read the file. Increment the save version in saveload.cpp, and alter those three variables to be present from 83 onwards, and it should work. Any other variables added to the save will need similar treatment.
Thank you, I fixed that. Can anyone tell me what block_size_bits in DECLARE_OLD_POOL is for?
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: [patch] Programmable waypoints

Post by Yexo »

Just uploaded v0.4 of this patch. v0.4 is a diff against r11748. Loading/saving now works completely. With that, multiplayer should also work, but I haven't tested that much. In multiplayer, it's not possible to see the rules of other company's. You'll just get a "Not allowed to change name of waypoint" (or something like it) error.

I'd like to hear more ideas about possible rules. Currently the following is possible:
Maximum speed.
Train length (currently in 1/16 tile-length)
Horsepower
Train weight
The amount of cargo loaded (per cargo-type and total)
The maximum amount of cargo (per cargo-type and total)
True (always matches)
False (never matches)

For every rule, you're able to select </<=/==/>=/> and fill in a value. Multiple rules can be combined with and/or/xor/nand.

Ideas for new rules:
Next order (and pick a station to match)
Last order (and pick a station to match)
Number of days since last service,

Those are a bit more difficult to code, as I'll have to look how I can pick a station. But that'll be version 0.5

If you miss anything, please let me know.
User avatar
athanasios
Tycoon
Tycoon
Posts: 3138
Joined: 23 Jun 2005 00:09
Contact:

Re: [patch] Programmable waypoints

Post by athanasios »

Type of cargo isn't in the list?
I don't know if the type of order the train has would be useful. Someone might think to give priority to "Transfer" as such cargo may travel longer distances.

Also what about checking if a train belongs to a specific Group?
Let us say we have 2 lines:
1: From city A to nearby city B (GroupX)
2: From city A to distant city C (GroupY)

Trains are identical. But I want to direct GroupX through a fast lane, as pay rates decrease by time.

Currently I have to use 2 waypoints or with the above option in your patch only 1.
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.
Acerbus
Engineer
Engineer
Posts: 94
Joined: 08 Dec 2006 21:42
Location: Estonia

Re: [patch] Programmable waypoints

Post by Acerbus »

Might I suggest a wiki page, once this project matures, to explain how to use these to thicks like me who haven't got a clue about programming?
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: [patch] Programmable waypoints

Post by Yexo »

Acerbus wrote:Might I suggest a wiki page, once this project matures, to explain how to use these to thicks like me who haven't got a clue about programming?
What exactly don't you understand? If you can't apply the diff read this post. If you have any question about how to create a set of rules to do something please ask here :)
athanasios wrote:Type of cargo isn't in the list?
Well, type of cargo isn't in the list directly, but if you want to select a train with passengers and post, you can make a rule like this:
Cargo loaded (passengers) > 0
AND
Cargo loaded (post) > 0

To select a non-goods train, simply do
Cargo capacity (goods) = 0
I don't know if the type of order the train has would be useful. Someone might think to give priority to "Transfer" as such cargo may travel longer distances.

Also what about checking if a train belongs to a specific Group?
Let us say we have 2 lines:
1: From city A to nearby city B (GroupX)
2: From city A to distant city C (GroupY)

Trains are identical. But I want to direct GroupX through a fast lane, as pay rates decrease by time.

Currently I have to use 2 waypoints or with the above option in your patch only 1.
That's a good idea. I'll have to do some research about how to get the group a trains belongs to, but that shouldn't be too difficult. Expect it in one of the upcoming versions :o
Buhmann
Engineer
Engineer
Posts: 20
Joined: 20 Dec 2007 18:20

Re: [patch] Programmable waypoints

Post by Buhmann »

This particular case could be solved with the option "next order", couldn't it?

But different penalties for differen't groups would be wonderful, anyway :)
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 20 guests