News:

Simutrans.com Portal
Our Simutrans site. You can find everything about Simutrans from here.

squirrel script - building_desc_x.get_available_stations waytype filter

Started by Andarix, January 19, 2026, 03:45:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andarix

Simutrans r11871

Despite specifying Waytype 0, objects with other waytypes are also returned.

list = building_desc_x.get_available_stations(building_desc_x.station_extension, 0, good_desc_x(good))
good is "Post"

pak64
Screenshot 2026-01-19 163650.png

pak64.german
Screenshot 2026-01-19 163112.png

victor_18993

I had a look at this. The behaviour is actually by design: waytype 0 means "all
waytypes" here, so getting entries of other waytypes back is expected.

In the script API, `wt_all` is defined as `ignore_wt`, which is 0 (api_const.cc:
`enum_slot(vm, "wt_all", ignore_wt);`). And get_available_stations treats 0 as the
catch-all:

    // ...
    bool accept_all_wt = wt == invalid_wt || wt == ignore_wt;  // ignore_wt == 0
    // ...
    && (accept_all_wt || desc->get_extra() == (uint32)wt)

So `get_available_stations(station_extension, 0, good)` deliberately returns every
matching building regardless of waytype (the API changelog even lists "Changed
get_available_stations to accept wt_all"). To filter, pass a concrete waytype, e.g.
`wt_road`, `wt_water`, etc., instead of 0.

The reason this is confusing is a wrong comment in the function itself, which says
wt_all "is equal to invalid_wt". It is not — api_const.cc maps wt_all to ignore_wt
(0); invalid_wt is -1 (both are accepted, but the equality claim is wrong). I've
attached a one-line, behaviour-neutral comment fix that states this correctly.

One caveat for station extensions specifically: extensions are normally
waytype-agnostic (their stored waytype is ignore_wt / 0), so filtering by a concrete
waytype tends to return nothing for them, and 0 (wt_all) is really the only way to
list them. Because wt_all and ignore_wt are the same value (0), there is no way to
ask for "only the waytype-agnostic ones" — that is the known overlap flagged by the
FIXME on `ignore_wt` in simtypes.h. Changing that would be an API change (moving
wt_all off 0), which is a maintainer decision; the comment fix alone does not touch
behaviour.
En la vida todo son vivencias y cada una de ellas nos hace mas grandes,¿Como de grande eres tu? :)

Yona-TYT

I'm not very familiar with pak parameters, but shouldn't extension buildings have a waytype value = 0?.