Find available depot for a line?

Willkommen in der Transport Fever Community

Wir begrüßen euch in der Fan-Community zu den Spielen Transport Fever und Train Fever, den Wirtschaftssimulatoren von Urban Games. Die Community steht euch kostenlos zur Verfügung damit ihr euch über das Spiel austauschen und informieren könnt. Wir pflegen hier einen freundlichen und sachlichen Umgang untereinander und unser Team steht euch in allen Fragen gerne beiseite.

 

Die Registrierung und Nutzung ist selbstverständlich kostenlos.

 

Wir wünschen euch viel Spaß und hoffen auf rege Beteiligung.

Das Team der Transport-Fever Community


  • Hi there, I've been creating a mod for automatic vehicle management on lines called "LineManager", GitHub link: https://github.com/TommyC81/TPF2-LineManager.


    One item that is critical for this mod is of course the removal and addition of vehicles. Removal is easy using:

    Code
    api.cmd.sendCommand(api.cmd.make.sellVehicle(vehicle_id))


    However, for adding vehicles, you need to specify a depot. To find a depot I've made use of the following workaround, effectively (temporarily) sending an existing vehicle to depot to see if it can find one then cancel the depot call, but use the found depot_id. Like so:

    This unfortunately empties the vehicle sent to the depot, which is less than ideal.


    Is there a better/sensible way to find a suitable (and accessible) depot for a specific line?


    I've looked at the pathfinding functions (https://transportfever2.com/wi…util.pathfinding.findPath), and believe the answer might exist in that functionality. However, this is currently beyond my knowledge and skill to implement (in particular as the associated documentation is virtually non-existent).


    Any suggestions or advice is appreciated, many thanks in advance!

  • Thank you!


    Yes, there is a depot property on each vehicle, this does however not seem to receive any updates as transport network changes. Perhaps what is done when cloning, it checks if it is still valid and if not another depot is found.


    Is it possible to trigger a strict "clone" command via scripting?


    Alternatively, if there's a good guide on how to interact with transport networks, stations, waiting cargo/passengers, nodes (and edges) etc. I could perhaps figure it out. I'm unfortunately at a loss at the moment.


    For reference, sample of command and associated output:

  • I think the vehicles or lines should have a "depot" property somewhere, which is used for the default depot when cloning

    Located in the API reference now, the depot property is only applicable/valid when a vehicle is actually in the depot - it is not kept updated beyond that.

  • I think the vehicles or lines should have a "depot" property somewhere, which is used for the default depot when cloning

    Trying to find a solution to this as time permits, can confirm that this is not correct. When "cloning" a vehicle, it finds an appropriate depot at the time. This can be tested by creating a line with a distant depot, then adding a closer depot and selecting clone on the line vehicle (it will use the new and better placed depot).


    Appreciate any suggestions on how to work on this. Looks like manual path testing is the only solution...


    Edit: Looked at the source of AutoSig2, it is way over my skill level to interpret it unfortunately. But I gather it goes to show that there should be a solution in here somewhere to manually locate an appropriate depot without relying on workarounds. Ideally, however, there would simply be a "clone" api function exposed that would handle it.

    Einmal editiert, zuletzt von CARTOK () aus folgendem Grund: Added note about AutoSig2.

  • TPF2 exe has this string:

    Code
    struct transport::Path __cdecl vehicle_util::common::`anonymous-namespace'::FindPathUnified<class vehicle_util::common::FindPathToDepot::<lambda_2db12c1f012abbc47ef40621f9a91d50>>(const struct vehicle_util::MovePathUtilContext &,class std::bitset<16>,const class std::vector<struct std::pair<struct transport::EdgeId,bool>,class std::allocator<struct std::pair<struct transport::EdgeId,bool> > > &,class vehicle_util::common::FindPathToDepot::<lambda_2db12c1f012abbc47ef40621f9a91d50>,float *)


    This function is fired by the command processor, the one processing sendCommands -> sendToDepot


    vehicle_util::MovePathUtilContext = Storage to pointers to all systems and ressources

    class std::bitset<16> = Transport Modes


    So the find depot is not very likely to be accessible by any api system functionality.


    The transport vehicle depot id is only valid when the vehicle is heading to a depot. (and the flag sellOnArrival)

  • Thank you! I suspected as much.


    The only way via script would be to manually try to find all possible paths to determine if there is an appropriate depot (and also find the best one). Unfortunately, above my skill level. And also not sure if it's worth the effort.


    I'm working around it by sending an existing vehicle to depot and looking for success, then capture that depot id. It's working, but causes the vehicle to be emptied, which can/does have a bad impact on profitability.

    In an updated version of my script I'm caching the depot id (and stop id) to save on this, but this also requires some error checking code to see if it works i.e. the depot still exists, and is viable - if the vehicle remains in depot after sending to a line, that's an indication that the depot is no good for a line, and I can then re-check (by sending an existing vehicle to depot) for a new depot.


    I've managed to send a request to UrbanGames (got a response!) to expand the API to avail some function to ease the depot-finding, or at least expose the clone vehicle function (which would be sufficient for my use case, "api.cmd.makeCloneVehicle" as an example). Let's see how that goes, I gather they are very busy with the upcoming update, not to mention the likely massive trove of other requests... ;-)

BlueBrixx