NoGo - How can I get the origin of a cargo load?

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
kyori
Engineer
Engineer
Posts: 3
Joined: 09 Jun 2015 13:29

NoGo - How can I get the origin of a cargo load?

Post by kyori »

Hello,

I'm new in scripting in NoGo.
I'm currently trying to generate traces from the events of the game.
It has proven fairly easy to do, however I have a problem with a piece of information.
While using cargo distribution, the source of the cargo load transported by a vehicle is showed in the game, in the information box of a vehicle as:

"40 passengers from Letborough"

I attach an image for this example.

My problem is that I cannot find within the NoGo framework a method to obtain this information.
In the class GSVehicle, the method "GetCargoLoad()" returns "40", however my question is how can I find the source, this is the part of the info that says "from Letborough".

Thanks in advance for any help.
scrennsh.png
scrennsh.png (20.49 KiB) Viewed 249 times
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: NoGo - How can I get the origin of a cargo load?

Post by frosch »

Currently there is no such API for vehicles.

There is only an API to query stations about waiting cargo and planned/expected cargo for specific routes:
GSStation.GetCargo(Waiting|Planned)[From][Via] and GSStationList_Cargo{Waiting|Planned}[By][From][Via]

If you have a good idea for names and parameters, we can add an API for vehicles though.
Names, parameters and class/list layout is always the hardest part of that :)
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
kyori
Engineer
Engineer
Posts: 3
Joined: 09 Jun 2015 13:29

Re: NoGo - How can I get the origin of a cargo load?

Post by kyori »

Thank you for you answer.
Actually, at this point I was trying to implement it myself, but I'm having quite a lot of troubles compiling OpenTTD on mac.

I think that the main problem is that this requires a different class, namely GSCargoPacket (mirroring CargoPacket in the original source).
In GSVehicle the methods for access should be:

CargoPacketID GetCargoPacket(VehicleID vehicle_id);
CargoPacketID GetWagonCargoPacket(VehicleID vehicle_id, int32 wagon_index);

The methods of GSCargoPacket would be:

// Gets the station where the cargo was initially loaded
static StationID GetSourceStation(CargoPacketID cargopacket_id);
// Gets the tile index where the cargo was initially loaded
static TileIndex GetSourceTile(CargoPacketID cargopacket_id);
// Gets the last station where the cargo was loaded
static StationID GetLastSourceStation(CargoPacketID cargopacket_id);
// Gets the last tile index where the cargo was loaded
static TileIndex GetLastSourceTile(CargoPacketID cargopacket_id);
// Gets the number of 'items' in this packet.
static int32 Count(CargoPacketID cargopacket_id);

After these changes, the method GetCargoLoad in GSVehicle should probably be deprecated since it would be redundant (maybe not, 'cause it's convenient).

There are several other methods implemented in CargoPacket in the original source containing reserved load and so on, but I think these are the most important and at least, those I'm interested on.


What do you think?

Thanks again for your remarks.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: NoGo - How can I get the origin of a cargo load?

Post by Alberth »

kyori wrote:Thank you for you answer.
Actually, at this point I was trying to implement it myself, but I'm having quite a lot of troubles compiling OpenTTD on mac.

I think that the main problem is that this requires a different class, namely GSCargoPacket (mirroring CargoPacket in the original source).
GSCargoPacket should come from src/script/api/ScriptCargoPacket (I hope the path is right, I don't have source code nearby to check).
The GS files are generated as part of the build, in fact much stuff is generated along the way. Unless you want to re-implement all the generation steps, the best way to compile is using the ./configure system.
There should be some explanation about compiling for mac at the wiki, otherwise, visit the IRC channel. Often there are people there who can point you in the right direction.
Being a retired OpenTTD developer does not mean I know what I am doing.
kyori
Engineer
Engineer
Posts: 3
Joined: 09 Jun 2015 13:29

Re: NoGo - How can I get the origin of a cargo load?

Post by kyori »

Alberth wrote:
kyori wrote:Thank you for you answer.
Actually, at this point I was trying to implement it myself, but I'm having quite a lot of troubles compiling OpenTTD on mac.

I think that the main problem is that this requires a different class, namely GSCargoPacket (mirroring CargoPacket in the original source).
GSCargoPacket should come from src/script/api/ScriptCargoPacket (I hope the path is right, I don't have source code nearby to check).
The GS files are generated as part of the build, in fact much stuff is generated along the way. Unless you want to re-implement all the generation steps, the best way to compile is using the ./configure system.
There should be some explanation about compiling for mac at the wiki, otherwise, visit the IRC channel. Often there are people there who can point you in the right direction.
Thanks for your answer.

There's not such file in the trunk, at least.
I guess the mapping for that class has not been made yet.
I think I'll hack my way to it :p
Thanks again.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: NoGo - How can I get the origin of a cargo load?

Post by Zuu »

IIRC there is a script you can manually execute to generate the GS/AI files from Script files. At least when developing on Windows not using ./configure, this is how I have to do it. But perhaps ./configure && make will call this script for you. However, as I remember running this script take a good minute or two and we commit the files it produce, so actually I think you need to run it manually also on Mac and Linux.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 8 guests