News:

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

squirrel script - tutorial astar.nut

Started by Andarix, Yesterday at 06:49:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andarix

Quote from: Yona-TYT on August 30, 2026, 10:54:36 PMThe truth is, I don't really understand astar.nut, but implementing common functions in the tutorial should be the right approach. Any bugs in the tutorial should be easy to fix, or so I think.

I'm a bit rusty when it comes to scripting, I'm afraid.

The functions in `astar.nut` were originally created by Dwachs; you do not necessarily need to understand them in detail.

The important thing is that they handle pathfinding:
a) New pathfinding (i.e., without an existing way)
b) Pathfinding for an existing way

The pathfinding function returns either 'err' or an array containing the tiles that make up the way.

In the tutorial, scenario b) is used to check whether the player has built a way from the starting tile to the target tile.

For the tutorial, the original `astar.nut` functions have been extended so that the last tile of an existing way is stored in `check_way_last_tile`. This is necessary to mark this tile for further construction by the player.

function test_select_way(start, end, wt = wt_rail)
.../class/astar.nut#L769

This function is already used for road construction in Chapter 2.

In the case of railway construction in Chapter 3, there was a problem: the construction area could not be properly defined.
see https://forum.simutrans.com/index.php?msg=212287

I am having trouble with the path validation around 'r_way.' so far.