Author: sveinung
Date: Wed Oct  5 02:24:30 2016
New Revision: 33996

URL: http://svn.gna.org/viewcvs/freeciv?rev=33996&view=rev
Log:
Lua move: city conquest only when possible.

The Lua functions unit_teleport() and unit_move() can result in the conquest
of a city on the tile the unit is moved to. Don't try to conquer unless the
target tile has a city, the actor unit can take over cities and the actor
unit's owner is at war with the target city's owner.

See patch #7754

Modified:
    trunk/server/scripting/api_server_edit.c

Modified: trunk/server/scripting/api_server_edit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/scripting/api_server_edit.c?rev=33996&r1=33995&r2=33996&view=diff
==============================================================================
--- trunk/server/scripting/api_server_edit.c    (original)
+++ trunk/server/scripting/api_server_edit.c    Wed Oct  5 02:24:30 2016
@@ -140,6 +140,7 @@
 bool api_edit_unit_teleport(lua_State *L, Unit *punit, Tile *dest)
 {
   bool alive;
+  struct city *pcity;
 
   LUASCRIPT_CHECK_STATE(L, FALSE);
   LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
@@ -149,10 +150,12 @@
   alive = unit_move(punit, dest, 0, NULL,
                     /* The old call would result in occupation before the
                      * checks below. */
-                    TRUE);
+                    ((pcity = tile_city(dest))
+                     && unit_can_take_over(punit)
+                     && pplayers_at_war(unit_owner(punit),
+                                        city_owner(pcity))));
   if (alive) {
     struct player *owner = unit_owner(punit);
-    struct city *pcity = tile_city(dest);
 
     if (!can_unit_exist_at_tile(punit, dest)) {
       wipe_unit(punit, ULR_NONNATIVE_TERR, NULL);
@@ -516,6 +519,8 @@
 bool api_edit_unit_move(lua_State *L, Unit *punit, Tile *ptile,
                         int movecost)
 {
+  struct city *pcity;
+
   LUASCRIPT_CHECK_STATE(L, FALSE);
   LUASCRIPT_CHECK_SELF(L, punit, FALSE);
   LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, FALSE);
@@ -524,7 +529,10 @@
   return unit_move(punit, ptile, movecost, NULL,
                    /* Backwards compatibility for old scripts in rulesets
                     * and (scenario) savegames. */
-                   TRUE);
+                   ((pcity = tile_city(ptile))
+                    && unit_can_take_over(punit)
+                    && pplayers_at_war(unit_owner(punit),
+                                       city_owner(pcity))));
 }
 
 /*****************************************************************************


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to