News:

Simutrans Tools
Know our tools that can help you to create add-ons, install and customize Simutrans.

What is a halt?

Started by jameskuyper, November 27, 2015, 10:11:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jameskuyper

While investigating the Squirrel API for scenario scripts, I've gotten somewhat confused about "halts". To put this in context, I'll explain my understanding from a game player's point of view: there are many stops and station extensions that I can build. Whenever I build an isolated one, it creates a new station. If I build one sufficiently close to an existing one, it gets merged into the same station. A schedule consists of a series of stops and way points that should be visited in the specified order. The same stop can be visited two or more times in the same schedule, so long as there's a visit to at least one other place between them. As a practical matter, there's no point in visiting two stops at the same station without visiting at least one other station in between them. Multiple visits to the same stop in the same schedule must be distinguished; they could be given different load or wait values, and they should have different associated statistics.

Is a halt
a) a stop,
b) a station, or
c) a stop at a particular step of a schedule, such that two different visits to the same stop are considered to be different halts?

Whichever one of those three that is referred to as a "halt", how do I get access to the other two? Specifically, from within a scenario script:
How do I get a list of the stations owned by a given player?
How do I get a list of the stops and extension buildings that make up a station?
How can I test whether two different buildings are part of the same station?

Dwachs

It is

b) a station

As in: the station, something consisting of multiple buildings and platforms.

To access a halt / station you need either its id or a coordinate of one of its buildings

local station1 = tile_x(12,34,0).get_halt()
local station2 = halt_x(4711)

There is the class halt_list_x, which can be iterated, and contains all stations on the map.

I will answer your three questions later. Need to check up before.
Parsley, sage, rosemary, and maggikraut.

jameskuyper

Before you've had time to answer those three questions, let me add two more.
Is there any easy way to get a list of the halts that have a given factory covered?
Is there any easy way to get a list of the factories that are covered by a given halt?

I can think of complicated ways, that involve searching every tile that is within the coverage range of the halt/factory in question. I'm wondering whether I'm missing out on a more direct way to do it.

A completely unrelated question, except that it's still in the context of scenario scripts: is there a routine that takes two arguments, a coord and a dir, and returns a coord object corresponding to moving one tile in the specified direction, starting at the specified position?

DrSuperGood

QuoteIs there any easy way to get a list of the halts that have a given factory covered?
Check the factory and city code. It is done both for distributing goods between factories and for worker traffic to and from factories. I recall there being a function which returns all stops servicing a point. It is also done by the UI code to produce the list of servicing stops.

QuoteIs there any easy way to get a list of the factories that are covered by a given halt?
This is done by the UI to show which factories are connected to a stop.

Ters

Literally speaking, a halt is a stop. A halt/stop in Simutrans being a named entity made up of one or more loading bays, bus platforms, train platforms, tram platforms, each being a sort of sub-unit made up of multiple tiles; docks, piers (which are multi-tile, but where the tiles function individually as sub-units of the stop) and airport gates, plus the various buildings that add capacity and coverage.

Stop might not be the right word, but neither is station. One of several misuses of terms in Simutrans due to lack of a better word.

Dwachs

Quote from: jameskuyper on November 28, 2015, 12:16:03 AM
A completely unrelated question, except that it's still in the context of scenario scripts: is there a routine that takes two arguments, a coord and a dir, and returns a coord object corresponding to moving one tile in the specified direction, starting at the specified position?
Check tile_x.get_neighbour: http://dwachs.github.io/simutrans-sqapi-doc/classtile__x.html#ab78a9b440e82430565ae17494897f267
Parsley, sage, rosemary, and maggikraut.

Dwachs

Quote from: jameskuyper on November 27, 2015, 10:11:20 PM
How do I get a list of the stations owned by a given player?
you have to iterate through all stations (halt_list_x()), and check the owner
Quote from: jameskuyper on November 27, 2015, 10:11:20 PM
How do I get a list of the stops and extension buildings that make up a station?
halt_x.get_tile_list (*)
Quote from: jameskuyper on November 27, 2015, 10:11:20 PM
How can I test whether two different buildings are part of the same station?
check whether two tiles belong to the same station can be done like this:

local t1 = tile_x(a,b,c)
local t2 = tile_x(x,y,z)
if (t1.get_halt()  &&  t2.get_halt()) {
   // there are stations at both tiles
   local equal = t1.get_halt().id == t2.get_halt().id
}

Quote from: jameskuyper on November 28, 2015, 12:16:03 AM
Is there any easy way to get a list of the halts that have a given factory covered?
Is there any easy way to get a list of the factories that are covered by a given halt?
halt_x.get_factory_list() and factory_x.get_halt_list() (*)

(*) these functions need a recent nightly (r>=7675), see changelog: http://dwachs.github.io/simutrans-sqapi-doc/changelog.html
Parsley, sage, rosemary, and maggikraut.

jameskuyper

#7
Quote from: DrSuperGood on November 28, 2015, 12:34:43 AM
Check the factory and city code. It is done both for distributing goods between factories and for worker traffic to and from factories. I recall there being a function which returns all stops servicing a point. It is also done by the UI code to produce the list of servicing stops.
This is done by the UI to show which factories are connected to a stop.
I'm looking for something that I can use from within a scenario script. If I can call those functions from a scenario script, where can I find documentation explaining how to do it and documenting the interface for those functions?

Quote from: Ters on November 28, 2015, 09:19:30 AM
Literally speaking, a halt is a stop. A halt/stop in Simutrans being a named entity made up of one or more loading bays, bus platforms, train platforms, tram platforms, each being a sort of sub-unit made up of multiple tiles; docks, piers (which are multi-tile, but where the tiles function individually as sub-units of the stop) and airport gates, plus the various buildings that add capacity and coverage.

Stop might not be the right word, but neither is station. One of several misuses of terms in Simutrans due to lack of a better word.
I somehow got the impression that "stop" was used to identify a single particular tile where it was possible to stop a convoy for loading or unloading. If not, there needs to be a name for such things, distinct from "station", which can be multi-tile. I know from the small number of games that I've actually played, that each entry in a schedule identifies the particular tile within a station that you selected, and not merely the entire station. I've not tested it yet, but I'd guess that schedule_entry_x::get_halt() should return a halt_x object whose x,y,z values represent the actual tile I selected, rather than a single x,y,z value used to describe the entire station. If not, how is that distinction made?
I've not tested it yet, but I'd expect building_desc_x::get_building_type() to return building_type::station for the tiles where you can load and unload, and building_type::station_extension for those that extend the coverage and storage capacity of a station, but cannot be used to load and unload.

Quote from: Dwachs on November 28, 2015, 10:13:03 AM
Check tile_x.get_neighbour: http://dwachs.github.io/simutrans-sqapi-doc/classtile__x.html#ab78a9b440e82430565ae17494897f267
Ah! I'd thought that was waytype-specific - I missed the fact that you could choose wt_all as the waytype. I presume that works even if there are no ways on the tile?

Quote from: Dwachs on November 28, 2015, 11:52:38 AM
...
halt_x.get_tile_list
...
halt_x.get_factory_list() and factory_x.get_halt_list() (*)

I've been using my spare time for several days now studying the scenario scripting documentation, but somehow failed to notice any one of those three functions. If I had noticed them, I wouldn't have had the questions that prompted my original message.

Ters

Whoa! Stop with that double and quadruple-posting, or our benevolent dictator might become less benevolent.

Quote from: jameskuyper on November 28, 2015, 06:34:20 PM
I somehow got the impression that "stop" was used to identify a single particular tile where it was possible to stop a convoy for loading or unloading. If not, there needs to be a name for such things, distinct from "station", which can be multi-tile.

Actually, Simutrans doesn't really identify single tiles for loading or unloading from what I remember seeing. You put a waypoint on a tile containing both a way and a building belonging to a stop/halt. The routing might not even end up stopping the vehicle on that tile.

Dwachs

Quote from: jameskuyper on November 28, 2015, 06:39:26 PM
I've been using my spare time for several days now studying the scenario scripting documentation, but somehow failed to notice any one of those three functions. If I had noticed them, I wouldn't have had the questions that prompted my original message.
They were created this morning, to answer your request :)

A schedule entry is used for vehicle routing. If the entry belongs to a station then get_halt() will return the station object.

What are you trying to achieve with these stations?
Parsley, sage, rosemary, and maggikraut.

jameskuyper

Quote from: Ters on November 28, 2015, 07:34:33 PM
Whoa! Stop with that double and quadruple-posting, or our benevolent dictator might become less benevolent.

My apologies. I read the rules when I first registered here, but I've not been able to spare anywhere near as much time on simutrans as I'd like. As a result, I've posted only infrequently, and forgot the rules. I just reviewed them and saw that we're not supposed to post a second message on a given thread within 24 hours. So I'll put my responses to all the message I've a response to, in a single message.

Quote from: Dwachs on November 28, 2015, 09:13:48 PM
They were created this morning, to answer your request :)

A schedule entry is used for vehicle routing. If the entry belongs to a station then get_halt() will return the station object.

What are you trying to achieve with these stations?

The recent announcement of a new version of simutrans caused me to take a look at the scenario scripting documentation for the first time. When I did, I realized that it would make it a lot easier to implement an idea I'd had for some time.

The scenario involves a disaster that requires a rapid reconfiguration of the transportation network. The government has temporarily given the player emergency control of those parts of the transportation network that will need the biggest changes, and a budget big enough to last until the new network becomes profitable (if managed carefully). However, in order to allow the human player to concentrate attention on that part of the network, the parts of the network that should not need significant reconfiguration are left in the hands of AI players. Those players should be cooperating with the human player, not competing. The government has assigned a specific domain of responsibility for each player, human and AI, delimited by geography, waytype, and good category, so they won't interfere with each other. I'm using the forbid*() functions to implement many of those restrictions, but I'm also defining the is_schedule_allowed() function.

In particular, some of the restrictions I'm applying to non-air schedules depend upon whether or not one of the stops on the schedule is at an airport station. An airport station means any station containing at least one tile where building_desc_x::get_type()  == station and building_desc_x::get_waytype() == wt_air. The function halt_x::get_tile_list() makes it a lot easier to check that.

Another restriction I'm applying depends upon which goods are intended to be transported by a given line. I don't have the power to veto an AI player's choice of which convoys to assign to a given schedule, so checking convoy_x::get_goods_catg_index() isn't an option, but calling halt_x::get_factory_list() for each halt in a schedule, would allow me to identify likely candidates.

I considered imposing similar restrictions on the human player, but ended up deciding against it. Letting the AI players run part of the transportation network was meant to remove distractions, but if the AI players mess something up, being unable to fix it would be an even bigger distraction.