Author: sveinung
Date: Fri Sep 16 04:01:56 2016
New Revision: 33812

URL: http://svn.gna.org/viewcvs/freeciv?rev=33812&view=rev
Log:
Clarify what the unit conquer city function does.

* rename it from unit_enter_city() to unit_conquer_city()
* have it return if the city was conquered

See patch #7690

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=33812&r1=33811&r2=33812&view=diff
==============================================================================
--- trunk/server/citytools.c    (original)
+++ trunk/server/citytools.c    Fri Sep 16 04:01:56 2016
@@ -1835,13 +1835,24 @@
 }
 
 /**************************************************************************
-  Handle unit entering city. During peace may enter peacefully, during
-  war conquers city.
-  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.
-**************************************************************************/
-void unit_enter_city(struct unit *punit, struct city *pcity, bool passenger)
+  Handle unit conquering a city.
+    - Can't conquer a city when not at war. (Enters cities peacefully
+      during peace. At the moment this can happen to domestic, allied and
+      team mate cities)
+    - A unit can't conquer a city if it is owned by the animal barbarian.
+    - A unit can't conquer a city if its unit class is missing the
+      "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.)
+
+  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 try_civil_war = FALSE;
   bool city_remains;
@@ -1854,7 +1865,7 @@
   if (!pplayers_at_war(pplayer, cplayer)
       || !unit_can_take_over(punit)
       || passenger) {
-    return;
+    return FALSE;
   }
 
   /* Okay, we're at war - invader captures/destroys city... */
@@ -1903,7 +1914,7 @@
     if (try_civil_war) {
       (void) civil_war(cplayer);
     }
-    return;
+    return TRUE;
   }
 
   coins = cplayer->economic.gold;
@@ -1998,6 +2009,8 @@
                               API_TYPE_PLAYER, cplayer,
                               API_TYPE_PLAYER, pplayer);
   }
+
+  return TRUE;
 }
 
 /**************************************************************************

Modified: trunk/server/citytools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/citytools.h?rev=33812&r1=33811&r2=33812&view=diff
==============================================================================
--- trunk/server/citytools.h    (original)
+++ trunk/server/citytools.h    Fri Sep 16 04:01:56 2016
@@ -44,7 +44,8 @@
                                bool only_ocean, bool only_continent,
                                bool only_known, bool only_player,
                                bool only_enemy, const struct unit_class 
*pclass);
-void unit_enter_city(struct unit *punit, struct city *pcity, bool passenger);
+bool unit_conquer_city(struct unit *punit, struct city *pcity,
+                       bool passenger);
 
 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=33812&r1=33811&r2=33812&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Fri Sep 16 04:01:56 2016
@@ -3264,7 +3264,7 @@
   bool alive = TRUE;
 
   if (tocity) {
-    unit_enter_city(punit, tocity, passenger);
+    unit_conquer_city(punit, tocity, passenger);
 
     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