Simutrans-Squirrel-API
Functions
Functions that should return quickly.

Functions

bool exit (player_x pl)
 
string get_api_version ()
 
string get_map_file ()
 
bool init (player_x pl)
 
string is_convoy_allowed (integer pl, convoy_x convoy, depot_x depot)
 
string is_schedule_allowed (integer pl, schedule_x schedule)
 
bool is_tool_allowed (integer pl, integer tool_id, way_types wt)
 
void is_valid_pos (player_x pl, coord3d pos, coord3d start)
 
string is_work_allowed_here (integer pl, integer tool_id, coord3d pos)
 
string jump_to_link_executed (coord3d pos)
 
void resume_game ()
 

Detailed Description

These functions are intended to quickly return a result. In network games, it is not allowed to call any map-altering tools from within such a function, see the section on Functions to alter the state of the game and map.

Function Documentation

◆ exit()

bool exit ( player_x  pl)

Exits the tool. Do cleanup here.

Returns
true upon success.
Parameters
plplayer instance to use this tool.

◆ get_api_version()

string get_api_version ( )

Returns string containing the version of the api that the scenario supports. By default returns the string scenario::api.

If it returns "*" then this indicates that the scenario works in the most current api version. Currently "112.3" and "120.1" are supported.

◆ get_map_file()

string get_map_file ( )

Called before starting the scenario. Should return filename of the savegame to be used for this scenario. If it returns "<attach>" the scenario is started with the currently running world. By default returns the string map::file.

Returns
filename or "<attach>"

◆ init()

bool init ( player_x  pl)

Initializes the tool.

Returns
true upon success.
Parameters
plplayer instance to use this tool.

◆ is_convoy_allowed()

string is_convoy_allowed ( integer  pl,
convoy_x  convoy,
depot_x  depot 
)

Called when user wants to start convoy.

Warning
Function will NOT be called in network games.
Parameters
plplayer number
convoyconvoy to start
depotconvoy is in this depot
Returns
null if allowed, an error message otherwise

◆ is_schedule_allowed()

string is_schedule_allowed ( integer  pl,
schedule_x  schedule 
)

Called when user changed a schedule (closes schedule window).

Warning
Function will NOT be called in network games.
Parameters
plplayer number
schedulethe schedule
Returns
null if allowed, an error message otherwise

◆ is_tool_allowed()

bool is_tool_allowed ( integer  pl,
integer  tool_id,
way_types  wt 
)

Function is called when toolbars are filled with icons or when a tool should be activated.

There is a default implementation, which forbids map-editing tools.

Attention
Results are not transfered over network, use the functions provided in rules in this case.
Parameters
plplayer number
tool_idsee tool_ids
wtwaytype of tool
Returns
true if tool is allowed.

◆ is_valid_pos()

void is_valid_pos ( player_x  pl,
coord3d  pos,
coord3d  start 
)

Can the tool start/end on pos? If it is the second click, start is the position of the first click. Possible return values: 0 = no 1 = This tool can work on this tile (with single click) 2 = On this tile can dragging start/end 3 = Both (1 and 2)

Parameters
plplayer instance to use this tool.
posposition to test
startfirst tile clicked by user

◆ is_work_allowed_here()

string is_work_allowed_here ( integer  pl,
integer  tool_id,
coord3d  pos 
)

Called when user clicks on a tile to build or remove something.

This function is network-aware: Error messages are sent back over network to clients.

The error message can contain a coordinate, which is used to show a location on the map. In order to show the right place, use coord_to_string. The must be enclosed in parentheses or prefixed with @ .

return "You cannot do this. The guy living at (" + coord_to_string({x=47, y=11}) + ") does not like you!"
Attention
Does not work with waybuilding and all tools that need path-finding, use the functions provided in rules in this case.
Parameters
plplayer number
tool_idsee tool_ids
poscoordinate
Returns
null if allowed, an error message otherwise

◆ jump_to_link_executed()

string jump_to_link_executed ( coord3d  pos)

Called when player click link in scenario windows.

Parameters
poscoordinate go to in link
Returns
null if allowed, an error message otherwise

◆ resume_game()

void resume_game ( )

This function is called when a savegame with active scenario is loaded. Do all the initializations and post-processing here.