From cab98de2bf4d3204f4fd86b13ccfe40607821c3e Mon Sep 17 00:00:00 2001 From: cazfi Date: Mon, 22 May 2017 22:09:08 +0000 Subject: [PATCH] Add scripting API control over unit 'stay' See hrm Feature #661580 git-svn-id: svn://svn.gna.org/svn/freeciv/trunk@35696 a0f10bec-cc02-0410-94fc-a9cfff90b4cd --- server/scripting/api_server_edit.c | 26 ++++++++++++++++++++++++++ server/scripting/api_server_edit.h | 2 ++ server/scripting/tolua_server.pkg | 12 ++++++++++++ 3 files changed, 40 insertions(+) diff --git a/server/scripting/api_server_edit.c b/server/scripting/api_server_edit.c index 76e6acc31e..7b09c82673 100644 --- a/server/scripting/api_server_edit.c +++ b/server/scripting/api_server_edit.c @@ -592,6 +592,32 @@ bool api_edit_unit_move(lua_State *L, Unit *punit, Tile *ptile, } /***************************************************************************** + Prohibit unit from moving +*****************************************************************************/ +void api_edit_unit_moving_disallow(lua_State *L, Unit *punit) +{ + LUASCRIPT_CHECK_STATE(L); + LUASCRIPT_CHECK_SELF(L, punit); + + if (punit != NULL) { + punit->stay = TRUE; + } +} + +/***************************************************************************** + Allow unit to move +*****************************************************************************/ +void api_edit_unit_moving_allow(lua_State *L, Unit *punit) +{ + LUASCRIPT_CHECK_STATE(L); + LUASCRIPT_CHECK_SELF(L, punit); + + if (punit != NULL) { + punit->stay = FALSE; + } +} + +/***************************************************************************** Add history to a city *****************************************************************************/ void api_edit_city_add_history(lua_State *L, City *pcity, int amount) diff --git a/server/scripting/api_server_edit.h b/server/scripting/api_server_edit.h index 382414d6a0..f478262d74 100644 --- a/server/scripting/api_server_edit.h +++ b/server/scripting/api_server_edit.h @@ -73,6 +73,8 @@ Player *api_edit_civil_war(lua_State *L, Player *pplayer, int probability); void api_edit_player_victory(lua_State *L, Player *pplayer); bool api_edit_unit_move(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); void api_edit_city_add_history(lua_State *L, City *pcity, int amount); void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount); diff --git a/server/scripting/tolua_server.pkg b/server/scripting/tolua_server.pkg index 9a6382cc11..b24980e7f9 100644 --- a/server/scripting/tolua_server.pkg +++ b/server/scripting/tolua_server.pkg @@ -178,6 +178,10 @@ module edit { @ player_victory (lua_State *L, Player *self); bool api_edit_unit_move @ unit_move(lua_State *L, Unit *self, Tile *moveto, int movecost); + void api_edit_unit_moving_disallow + @ movement_disallow(lua_State *L, Unit *self); + void api_edit_unit_moving_allow + @ movement_allow(lua_State *L, Unit *self); void api_edit_city_add_history @ add_city_history(lua_State *L, City *self, int amount); @@ -342,6 +346,14 @@ function Unit:move(moveto, movecost) return edit.unit_move(self, moveto, movecost) end +function Unit:movement_disallow() + edit.movement_disallow(self) +end + +function Unit:movement_allow() + edit.movement_allow(self) +end + -- Server functions for Tile module function Tile:create_owned_extra(name, player) edit.create_owned_extra(self, name, player) -- 2.11.4.GIT