--- /home/yonatyt/simu-git/simutrans-master/dataobj/scenario.cc 2021-08-27 10:46:16.000000000 -0400 +++ /home/yonatyt/simu-git/files/scenario.cc 2021-08-27 12:49:37.126707000 -0400 @@ -208,6 +208,7 @@ bool scenario_t::forbidden_t::operator <(const forbidden_t &other) const { + bool lt = type < other.type; if (!lt && type == other.type) { sint32 diff = (sint32)player_nr - (sint32)other.player_nr; @@ -215,8 +216,12 @@ diff = (sint32)toolnr - (sint32)other.toolnr; } if (diff == 0) { - diff = (sint32)waytype - (sint32)other.waytype; + //diff = (sint32)system_type - (sint32)other.system_type; + } + if (diff == 0) { + diff = ((sint32)waytype - (sint32)other.waytype ); } + lt = diff < 0; } return lt; @@ -225,7 +230,7 @@ bool scenario_t::forbidden_t::operator ==(const forbidden_t &other) const { - bool eq = (type == other.type) && (player_nr == other.player_nr) && (waytype == other.waytype); + bool eq = (type == other.type) && (player_nr == other.player_nr) && (waytype == other.waytype) && (system_type == other.system_type); if (eq) { switch(type) { case forbid_tool_rect: @@ -244,7 +249,7 @@ scenario_t::forbidden_t::forbidden_t(const forbidden_t& other) : type(other.type), player_nr(other.player_nr), toolnr(other.player_nr), - waytype(other.waytype), pos_nw(other.pos_nw), pos_se(other.pos_se), + waytype(other.waytype), system_type(other.system_type), pos_nw(other.pos_nw), pos_se(other.pos_se), hmin(other.hmin), hmax(other.hmax), error(other.error) { } @@ -340,28 +345,27 @@ void scenario_t::forbid_tool(uint8 player_nr, uint16 tool_id) { - forbidden_t *test = new forbidden_t(forbidden_t::forbid_tool, player_nr, tool_id, invalid_wt); + forbidden_t *test = new forbidden_t(forbidden_t::forbid_tool, player_nr, tool_id, invalid_wt, type_invalid); call_forbid_tool(test, true); } void scenario_t::allow_tool(uint8 player_nr, uint16 tool_id) { - forbidden_t *test = new forbidden_t(forbidden_t::forbid_tool, player_nr, tool_id, invalid_wt); + forbidden_t *test = new forbidden_t(forbidden_t::forbid_tool, player_nr, tool_id, invalid_wt, type_invalid); call_forbid_tool(test, false); } -void scenario_t::forbid_way_tool(uint8 player_nr, uint16 tool_id, waytype_t wt) +void scenario_t::forbid_way_tool(uint8 player_nr, uint16 tool_id, waytype_t wt, systemtype_t styp) { - forbidden_t *test = new forbidden_t(forbidden_t::forbid_tool, player_nr, tool_id, wt); + forbidden_t *test = new forbidden_t(forbidden_t::forbid_tool, player_nr, tool_id, wt, styp); call_forbid_tool(test, true); } - -void scenario_t::allow_way_tool(uint8 player_nr, uint16 tool_id, waytype_t wt) +void scenario_t::allow_way_tool(uint8 player_nr, uint16 tool_id, waytype_t wt, systemtype_t styp) { - forbidden_t *test = new forbidden_t(forbidden_t::forbid_tool, player_nr, tool_id, wt); + forbidden_t *test = new forbidden_t(forbidden_t::forbid_tool, player_nr, tool_id, wt, styp); call_forbid_tool(test, false); } @@ -410,19 +414,18 @@ } -bool scenario_t::is_tool_allowed(const player_t* player, uint16 tool_id, sint16 wt) +bool scenario_t::is_tool_allowed(const player_t* player, uint16 tool_id, sint16 wt, sint16 styp) { if (what_scenario != SCRIPTED && what_scenario != SCRIPTED_NETWORK) { return true; } // first test the list if (!forbidden_tools.empty()) { - forbidden_t test(forbidden_t::forbid_tool, PLAYER_UNOWNED, tool_id, invalid_wt); + forbidden_t test(forbidden_t::forbid_tool, PLAYER_UNOWNED, tool_id, invalid_wt, type_invalid); uint8 player_nr = player ? player->get_player_nr() : PLAYER_UNOWNED; - // first test waytype invalid_wt, then wt // .. and all players then specific player - for(uint32 wti = 0; wti<4; wti++) { + for(uint32 wti = 0; wti<5; wti++) { if (find_first(test) < forbidden_tools.get_count()) { // there is something, hence forbidden return false; @@ -430,17 +433,20 @@ // logic to test all possible four cases sim::swap( wt, test.waytype ); if (test.waytype == invalid_wt) { + //sim::swap( styp, test.system_type ); + //if (test.system_type == type_invalid) sim::swap( player_nr, test.player_nr ); if (test.player_nr == PLAYER_UNOWNED) { break; } + } } } // then call script if available if (what_scenario == SCRIPTED) { bool ok = true; - const char* err = script->call_function(script_vm_t::FORCE, "is_tool_allowed", ok, (uint8)(player ? player->get_player_nr() : PLAYER_UNOWNED), tool_id, wt); + const char* err = script->call_function(script_vm_t::FORCE, "is_tool_allowed", ok, (uint8)(player ? player->get_player_nr() : PLAYER_UNOWNED), tool_id, wt, styp); return err != NULL || ok; } --- /home/yonatyt/simu-git/simutrans-master/dataobj/scenario.h 2021-08-27 10:46:16.000000000 -0400 +++ /home/yonatyt/simu-git/files/scenario.h 2021-08-27 12:47:40.863784000 -0400 @@ -93,19 +93,20 @@ uint16 toolnr; /// waytype of tool, @see waytype_t sint16 waytype; + sint16 system_type; koord pos_nw, pos_se; sint8 hmin, hmax; /// error message to be displayed if user tries to work with the tool plainstring error; /// constructor: forbid tool/etc for a certain player - forbidden_t(forbid_type type_=forbid_tool, uint8 player_nr_=255, uint16 toolnr_=0, sint16 waytype_=invalid_wt) : - type(type_), player_nr(player_nr_), toolnr(toolnr_), waytype(waytype_), + forbidden_t(forbid_type type_=forbid_tool, uint8 player_nr_=255, uint16 toolnr_=0, sint16 waytype_=invalid_wt, sint16 system_type_=type_invalid) : + type(type_), player_nr(player_nr_), toolnr(toolnr_), waytype(waytype_), system_type(system_type_), pos_nw(koord::invalid), pos_se(koord::invalid), hmin(-128), hmax(127), error() {} /// constructor: forbid tool for a certain player at certain locations (and heights) forbidden_t(uint8 player_nr_, uint16 toolnr_, sint16 waytype_, koord nw, koord se, sint8 hmin_=-128, sint8 hmax_=127) : - type(forbid_tool_rect), player_nr(player_nr_), toolnr(toolnr_), waytype(waytype_), + type(forbid_tool_rect), player_nr(player_nr_), toolnr(toolnr_), waytype(waytype_), pos_nw(nw), pos_se(se), hmin(hmin_), hmax(hmax_), error() {} // copy constructor @@ -140,7 +141,8 @@ type= (forbid_type)t; file->rdwr_byte(player_nr); file->rdwr_short(toolnr); - file->rdwr_short(waytype); + file->rdwr_short(waytype); + file->rdwr_short(system_type); file->rdwr_short(pos_nw.x); file->rdwr_short(pos_nw.y); file->rdwr_short(pos_se.x); file->rdwr_short(pos_se.y); file->rdwr_byte(hmin); @@ -343,13 +345,13 @@ * @param tool_id id of tool * @param wt waytype */ - void forbid_way_tool(uint8 player_nr, uint16 tool_id, waytype_t wt); + void forbid_way_tool(uint8 player_nr, uint16 tool_id, waytype_t wt, systemtype_t styp); /** * @ingroup squirrel-api * @see forbid_way_tool */ - void allow_way_tool(uint8 player_nr, uint16 tool_id, waytype_t wt); + void allow_way_tool(uint8 player_nr, uint16 tool_id, waytype_t wt, systemtype_t styp); /** * Forbid tool with certain waytype within rectangular region on the map @@ -408,7 +410,7 @@ * Called for instance in karte_t::local_set_tool to change active tool or when filling toolbars. * @return true if player can use this tool. */ - bool is_tool_allowed(const player_t* player, uint16 tool_id, sint16 wt = invalid_wt); + bool is_tool_allowed(const player_t* player, uint16 tool_id, sint16 wt = invalid_wt, sint16 styp = type_invalid); /** * Checks if player can use the tool at this position. --- /home/yonatyt/simu-git/simutrans-master/bauer/wegbauer.cc 2021-08-27 10:46:16.000000000 -0400 +++ /home/yonatyt/simu-git/files/wegbauer.cc 2021-08-27 11:58:00.078253000 -0400 @@ -294,7 +294,7 @@ { // check if scenario forbids this const waytype_t rwtyp = wtyp!=track_wt || styp!=type_tram ? wtyp : tram_wt; - if (!welt->get_scenario()->is_tool_allowed(welt->get_active_player(), TOOL_BUILD_WAY | GENERAL_TOOL, rwtyp)) { + if (!welt->get_scenario()->is_tool_allowed(welt->get_active_player(), TOOL_BUILD_WAY | GENERAL_TOOL, rwtyp, styp)) { return; } --- /home/yonatyt/simu-git/simutrans-master/simtypes.h 2021-08-27 10:46:16.000000000 -0400 +++ /home/yonatyt/simu-git/files/simtypes.h 2021-08-26 00:46:52.804493000 -0400 @@ -151,6 +151,7 @@ * System types for ways */ enum systemtype_t { + type_invalid = -1, type_flat = 0, ///< flat track type_elevated = 1, ///< flag for elevated ways type_runway = 1, ///< flag for runway (only aircrafts) --- /home/yonatyt/simu-git/simutrans-master/script/script.h 2021-08-27 10:46:16.000000000 -0400 +++ /home/yonatyt/simu-git/files/script.h 2021-08-26 11:32:25.077561000 -0400 @@ -151,6 +151,16 @@ do_function_call(); } + template + const char* call_function(call_type_t ct, const char* function, R& ret, A1 arg1, A2 arg2, A3 arg3, A4 arg4) { + prep_function_call(); + push_param(A1, arg1); + push_param(A2, arg2); + push_param(A3, arg3); + push_param(A4, arg4); + do_function_call(); + } + /** * Registers a c++ function to be available as callback. * A callback is called when a function call got suspended, resumed, and returned something. --- /home/yonatyt/simu-git/simutrans-master/script/api/api_const.cc 2021-08-27 10:46:16.000000000 -0400 +++ /home/yonatyt/simu-git/files/api_const.cc 2021-08-27 02:03:52.293381000 -0400 @@ -139,6 +139,9 @@ begin_enum("way_types"); /// catch all value: used to forbid tools for all waytypes enum_slot(vm, "wt_all", invalid_wt); + + enum_slot(vm, "wt_ignore", ignore_wt); + /// road enum_slot(vm, "wt_road", road_wt); /// rail @@ -166,6 +169,8 @@ * System type could take also other values than the ones defined here. */ begin_enum("way_system_types"); + /// catch all value: used to forbid tools for all systemtype + enum_slot(vm, "st_all", type_invalid); /// flat ways enum_slot(vm, "st_flat", type_flat); /// elevated ways