Get Cargo/Passenger (SimEntity) at Terminal waiting for a specific 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


  • Apologies, writing on phone as away from computer.


    Looking for some guidance, or hint, for a sensible way to find the max CARGO or PASSENGER (SimEntities) waiting at any terminal used by line. This needs to be done for all lines.


    A brute force way is to use getSimCargoForLine (and Person equivalent), and then cycle through them to fetch the SIM_CARGO_AT_TERMINAL (or ENTITY/PERSON) component.


    This will however be rather inefficient as the same SimEntity will be applicable for many lines.


    Is it possible to, for instance, cycle through each station (foreach), and then retrieve just the SimEntities waiting at that specific station?


    The API reference is not particularly clear, and seems to be missing lots of existing functionality. Any assistance is appreciated!


    Edit: I've noticed the following function exists:


    getSimCargoAtTerminalForTransportNetwork(tnEntity)

    Obtains all cargo that is waiting at the terminal.

    Parameters:


    tnEntity Entity the entity of the transport network


    It is however unclear what tnEntity is in this instance, and how it is obtained. What constitutes an entity of the transport network? A station?

    Einmal editiert, zuletzt von CARTOK ()

  • game.interface.getEntity from a STATION_GROUP will give you "cargoWaiting" - which is used e.g. in ADvanced Statistics

    Thanks!


    I ended up using api_helper.getSimPersonsForLine(line_id) and api_helper.getSimCargosForLine(line_id), and then scan through all the entities with api.engine.getComponent(entity_id, api.type.ComponentType.SIM_ENTITY_AT_TERMINAL). Turns out that this is a pretty fast process and you can fetch hundreds of these within milliseconds.


    Actual code below:


  • Tips:


    Use pcall only when not possible otherwise. (If it fails because of the entity; there is an api function entityExists)


    Already a few ms may affect sim performance if you are at the border of performance limit, as there are only 200ms for each step.

    Test it with a large map.

    You can use my timer.lua for measuring: https://github.com/Vacuum-Tube…atistics/script/timer.lua

  • Thank you! I've tested quite a bit and run at about 6-8 ms per step, so I'm well within margin. The first steps fetches the a Cargo2Entity map which takes about 30ms, but that's essentially all that is done in that step. The remaining workload I'm spreading out over several ticks, carefully limiting the amount of work done within each tick. There's a bit of overhead associated with this, but not a problem.

BlueBrixx