From 569e008afe5f085233ffc99e7330b9029df674ee Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Mon, 8 Feb 2021 16:38:08 +0100 Subject: [PATCH 18/18] Lua API: remove move unit side effect setting. Disable all side effects of Unit:move() and Unit:teleport() rather than setting them based on the old rules when they aren't specified. This allows us to soft code rules that the setting of the side effect relied on. Thanks to Marko for feed back on my previous attempt at doing this. See osdn #41523 --- server/scripting/api_server_edit.c | 125 ----------------------------- server/scripting/api_server_edit.h | 3 - server/scripting/tolua_server.pkg | 10 +-- 3 files changed, 4 insertions(+), 134 deletions(-) diff --git a/server/scripting/api_server_edit.c b/server/scripting/api_server_edit.c index 4bcb69de2a..0018350766 100644 --- a/server/scripting/api_server_edit.c +++ b/server/scripting/api_server_edit.c @@ -16,7 +16,6 @@ #endif /* utility */ -#include "deprecations.h" #include "rand.h" /* common */ @@ -52,21 +51,6 @@ #include "api_server_edit.h" -/**********************************************************************//** - Warn about use of a deprecated number of arguments. -**************************************************************************/ -static void deprecated_semantic_warning(const char *call, const char *aka, - const char *deprecated_since) -{ - if (are_deprecation_warnings_enabled()) { - log_deprecation_always( - "Deprecated: Lua call %s aka %s filling out the remaining" - " parameters based on the old rules is deprecated" - " since Freeciv %s.", - call, aka, deprecated_since); - } -} - /*************************************************************************//** Unleash barbarians on a tile, for example from a hut *****************************************************************************/ @@ -214,68 +198,6 @@ bool api_edit_unit_teleport(lua_State *L, Unit *punit, Tile *dest, return alive; } -/*************************************************************************//** - Teleport unit to destination tile -*****************************************************************************/ -bool api_edit_unit_teleport_old(lua_State *L, Unit *punit, Tile *dest) -{ - bool alive; - struct city *pcity; - - deprecated_semantic_warning("edit.unit_teleport(unit, dest)", - "Unit:teleport(dest)", "3.1"); - - LUASCRIPT_CHECK_STATE(L, FALSE); - LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE); - LUASCRIPT_CHECK_ARG_NIL(L, dest, 3, Tile, FALSE); - - /* Teleport first so destination is revealed even if unit dies */ - alive = unit_move(punit, dest, 0, - /* Auto embark kept for backward compatibility. I have - * no objection if you see the old behavior as a bug and - * remove auto embarking completely or for transports - * the unit can't legally board. -- Sveinung */ - NULL, TRUE, - /* Backwards compatibility for old scripts in rulesets - * and (scenario) savegames. I have no objection if you - * see the old behavior as a bug and remove auto - * conquering completely or for cities the unit can't - * legally conquer. -- Sveinung */ - ((pcity = tile_city(dest)) - && (unit_owner(punit)->ai_common.barbarian_type - != ANIMAL_BARBARIAN) - && uclass_has_flag(unit_class_get(punit), - UCF_CAN_OCCUPY_CITY) - && !unit_has_type_flag(punit, UTYF_CIVILIAN) - && pplayers_at_war(unit_owner(punit), - city_owner(pcity))), - (extra_owner(dest) == NULL - || pplayers_at_war(extra_owner(dest), - unit_owner(punit))) - && tile_has_claimable_base(dest, unit_type_get(punit)), - /* Backwards compatibility: unit_enter_hut() would - * return without doing anything if the unit was - * HUT_NOTHING. Setting this parameter to FALSE makes - * sure unit_enter_hut() isn't called. */ - unit_can_do_action_result(punit, ACTRES_HUT_ENTER), - unit_can_do_action_result(punit, ACTRES_HUT_FRIGHTEN)); - if (alive) { - struct player *owner = unit_owner(punit); - - if (!can_unit_exist_at_tile(&(wld.map), punit, dest)) { - wipe_unit(punit, ULR_NONNATIVE_TERR, NULL); - return FALSE; - } - if (is_non_allied_unit_tile(dest, owner) - || (pcity && !pplayers_allied(city_owner(pcity), owner))) { - wipe_unit(punit, ULR_STACK_CONFLICT, NULL); - return FALSE; - } - } - - return alive; -} - /***********************************************************************//** Force a unit to perform an action against a city. ***************************************************************************/ @@ -904,53 +826,6 @@ bool api_edit_unit_move(lua_State *L, Unit *punit, Tile *ptile, enter_hut, frighten_hut); } -/*************************************************************************//** - Move a unit. -*****************************************************************************/ -bool api_edit_unit_move_old(lua_State *L, Unit *punit, Tile *ptile, - int movecost) -{ - struct city *pcity; - - deprecated_semantic_warning("edit.unit_move(unit, moveto, movecost)", - "Unit:move(moveto, movecost)", "3.1"); - - LUASCRIPT_CHECK_STATE(L, FALSE); - LUASCRIPT_CHECK_SELF(L, punit, FALSE); - LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, FALSE); - LUASCRIPT_CHECK_ARG(L, movecost >= 0, 4, "Negative move cost!", FALSE); - - return unit_move(punit, ptile, movecost, - /* Auto embark kept for backward compatibility. I have - * no objection if you see the old behavior as a bug and - * remove auto embarking completely or for transports - * the unit can't legally board. -- Sveinung */ - NULL, TRUE, - /* Backwards compatibility for old scripts in rulesets - * and (scenario) savegames. I have no objection if you - * see the old behavior as a bug and remove auto - * conquering completely or for cities the unit can't - * legally conquer. -- Sveinung */ - ((pcity = tile_city(ptile)) - && (unit_owner(punit)->ai_common.barbarian_type - != ANIMAL_BARBARIAN) - && uclass_has_flag(unit_class_get(punit), - UCF_CAN_OCCUPY_CITY) - && !unit_has_type_flag(punit, UTYF_CIVILIAN) - && pplayers_at_war(unit_owner(punit), - city_owner(pcity))), - (extra_owner(ptile) == NULL - || pplayers_at_war(extra_owner(ptile), - unit_owner(punit))) - && tile_has_claimable_base(ptile, unit_type_get(punit)), - /* Backwards compatibility: unit_enter_hut() would - * return without doing anything if the unit was - * HUT_NOTHING. Setting this parameter to FALSE makes - * sure unit_enter_hut() isn't called. */ - unit_can_do_action_result(punit, ACTRES_HUT_ENTER), - unit_can_do_action_result(punit, ACTRES_HUT_FRIGHTEN)); -} - /*************************************************************************//** Prohibit unit from moving *****************************************************************************/ diff --git a/server/scripting/api_server_edit.h b/server/scripting/api_server_edit.h index 3f85e61ad1..ddc1dbcf8c 100644 --- a/server/scripting/api_server_edit.h +++ b/server/scripting/api_server_edit.h @@ -39,7 +39,6 @@ bool api_edit_unit_teleport(lua_State *L, Unit *punit, Tile *dest, Unit *embark_to, bool allow_disembark, bool conquer_city, bool conquer_extra, bool enter_hut, bool frighten_hut); -bool api_edit_unit_teleport_old(lua_State *L, Unit *punit, Tile *dest); bool api_edit_perform_action_unit_vs_city(lua_State *L, Unit *punit, Action *paction, City *tgt); @@ -98,8 +97,6 @@ bool api_edit_unit_move(lua_State *L, Unit *punit, Tile *ptile, Unit *embark_to, bool allow_disembark, bool conquer_city, bool conquer_extra, bool enter_hut, bool frighten_hut); -bool api_edit_unit_move_old(lua_State *L, Unit *punit, Tile *ptile, - int movecost); void api_edit_unit_moving_disallow(lua_State *L, Unit *punit); void api_edit_unit_moving_allow(lua_State *L, Unit *punit); diff --git a/server/scripting/tolua_server.pkg b/server/scripting/tolua_server.pkg index 965af66055..85ca709f36 100644 --- a/server/scripting/tolua_server.pkg +++ b/server/scripting/tolua_server.pkg @@ -116,8 +116,6 @@ module edit { @ create_unit_full (lua_State *L, Player *pplayer, Tile *ptile, Unit_Type *ptype, int veteran_level, City *homecity, int moves_left, int hp_left, Unit *ptransport); - bool api_edit_unit_teleport_old - @ unit_teleport(lua_State *L, Unit *self, Tile *dest); bool api_edit_unit_teleport @ unit_teleport(lua_State *L, Unit *self, Tile *dest, Unit *embark_to, bool allow_disembark, @@ -181,8 +179,6 @@ module edit { @ unit_turn(lua_State *L, Unit *punit, Direction dir); void api_edit_player_victory @ player_victory (lua_State *L, Player *self); - bool api_edit_unit_move_old - @ unit_move(lua_State *L, Unit *self, Tile *moveto, int movecost); bool api_edit_unit_move @ unit_move(lua_State *L, Unit *self, Tile *moveto, int movecost, Unit *embark_to, bool allow_disembark, @@ -366,7 +362,8 @@ function Unit:teleport(dest, conquer_city, conquer_extra, enter_hut, frighten_hut) if allow_disembark == nil then - return edit.unit_teleport(self, dest) + return edit.unit_teleport(self, dest, nil, false, + false, false, false, false) else return edit.unit_teleport(self, dest, embark_to, allow_disembark, @@ -398,7 +395,8 @@ function Unit:move(moveto, movecost, conquer_city, conquer_extra, enter_hut, frighten_hut) if allow_disembark == nil then - return edit.unit_move(self, moveto, movecost) + return edit.unit_move(self, moveto, movecost, nil, false, + false, false, false, false) else return edit.unit_move(self, moveto, movecost, embark_to, allow_disembark, -- 2.20.1