Author: sveinung
Date: Thu Sep 22 18:27:08 2016
New Revision: 33845

URL: http://svn.gna.org/viewcvs/freeciv?rev=33845&view=rev
Log:
Don't call unit_conquer_city() for passengers.

A unit can't conquer a city while being moved by its transport. Don't call
unit_conquer_city() for it.

See patch #7708

Modified:
    trunk/server/citytools.c
    trunk/server/citytools.h
    trunk/server/unittools.c

Modified: trunk/server/citytools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/citytools.c?rev=33845&r1=33844&r2=33845&view=diff
==============================================================================
--- trunk/server/citytools.c    (original)
+++ trunk/server/citytools.c    Thu Sep 22 18:27:08 2016
@@ -1844,15 +1844,13 @@
       "CanOccupyCity" unit class flag.
     - A unit can't conquer a city if its unit type has the "NonMil" unit
       type flag.
-    - Transported unit cannot conquer city. (If transported unit is seen
-      here, transport is conquering city. Movement of the transported units
-      is just handled before transport itself.)
+    - Transported units trying to conquer a city should be unloaded before
+      this function is called.
 
   Returns TRUE iff action could be done, FALSE if it couldn't. Even if
   this returns TRUE, unit may have died during the action.
 **************************************************************************/
-bool unit_conquer_city(struct unit *punit, struct city *pcity,
-                       bool passenger)
+bool unit_conquer_city(struct unit *punit, struct city *pcity)
 {
   bool try_civil_war = FALSE;
   bool city_remains;
@@ -1863,10 +1861,14 @@
   /* If not at war, may peacefully enter city. Or, if we cannot occupy
    * the city, this unit entering will not trigger the effects below. */
   if (!pplayers_at_war(pplayer, cplayer)
-      || !unit_can_take_over(punit)
-      || passenger) {
+      || !unit_can_take_over(punit)) {
     return FALSE;
   }
+
+  /* A transported unit trying to conquer a city should already have been
+   * unloaded. */
+  fc_assert_ret_val_msg(punit->transporter == NULL, FALSE,
+                        "Can't conquer city while transported.");
 
   /* Okay, we're at war - invader captures/destroys city... */
   

Modified: trunk/server/citytools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/citytools.h?rev=33845&r1=33844&r2=33845&view=diff
==============================================================================
--- trunk/server/citytools.h    (original)
+++ trunk/server/citytools.h    Thu Sep 22 18:27:08 2016
@@ -44,8 +44,7 @@
                                bool only_ocean, bool only_continent,
                                bool only_known, bool only_player,
                                bool only_enemy, const struct unit_class 
*pclass);
-bool unit_conquer_city(struct unit *punit, struct city *pcity,
-                       bool passenger);
+bool unit_conquer_city(struct unit *punit, struct city *pcity);
 
 bool send_city_suppression(bool now);
 void send_city_info(struct player *dest, struct city *pcity);

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=33845&r1=33844&r2=33845&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Thu Sep 22 18:27:08 2016
@@ -3264,7 +3264,14 @@
   bool alive = TRUE;
 
   if (tocity) {
-    unit_conquer_city(punit, tocity, passenger);
+    if (!passenger) {
+      /* The unit that does the move may conquer. */
+      unit_conquer_city(punit, tocity);
+    }
+
+    /* Run for passengers too. A passenger may have been killed when its
+     * transport conquered a city. (unit_conquer_city() can cause Lua code
+     * to run) */
 
     alive = unit_is_alive(saved_id);
     if (alive) {


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

Reply via email to