Author: cazfi
Date: Mon Dec 28 21:56:42 2015
New Revision: 31247

URL: http://svn.gna.org/viewcvs/freeciv?rev=31247&view=rev
Log:
Deprecated "city_growth" lua signal and added "city_size_change" as an 
replacement for it.

Requested by Alexander Fretheim <ahfretheim>

See bug #24115

Modified:
    trunk/server/citytools.c
    trunk/server/cityturn.c
    trunk/server/cityturn.h
    trunk/server/diplomats.c
    trunk/server/edithand.c
    trunk/server/scripting/script_server.c
    trunk/server/unithand.c
    trunk/server/unittools.c

Modified: trunk/server/citytools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/citytools.c?rev=31247&r1=31246&r2=31247&view=diff
==============================================================================
--- trunk/server/citytools.c    (original)
+++ trunk/server/citytools.c    Mon Dec 28 21:56:42 2015
@@ -1955,7 +1955,7 @@
   if (city_remains) {
     /* reduce size should not destroy this city */
     fc_assert(city_size_get(pcity) > 1);
-    city_reduce_size(pcity, 1, pplayer);
+    city_reduce_size(pcity, 1, pplayer, "conquest");
   }
 
   if (try_civil_war) {

Modified: trunk/server/cityturn.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/cityturn.c?rev=31247&r1=31246&r2=31247&view=diff
==============================================================================
--- trunk/server/cityturn.c     (original)
+++ trunk/server/cityturn.c     Mon Dec 28 21:56:42 2015
@@ -722,13 +722,20 @@
   loss.
 **************************************************************************/
 bool city_reduce_size(struct city *pcity, citizens pop_loss,
-                      struct player *destroyer)
+                      struct player *destroyer, const char *reason)
 {
   citizens loss_remain;
   int old_radius_sq;
 
   if (pop_loss == 0) {
     return TRUE;
+  }
+
+  if (reason != NULL) {
+    script_server_signal_emit("city_size_change", 3,
+                              API_TYPE_CITY, pcity,
+                              API_TYPE_INT, -pop_loss,
+                              API_TYPE_STRING, reason);
   }
 
   if (city_size_get(pcity) <= pop_loss) {
@@ -927,6 +934,10 @@
   notify_player(powner, city_tile(pcity), E_CITY_GROWTH, ftc_server,
                 _("%s grows to size %d."),
                 city_link(pcity), city_size_get(pcity));
+  script_server_signal_emit("city_size_change", 3,
+                            API_TYPE_CITY, pcity,
+                            API_TYPE_INT, 1,
+                            API_TYPE_STRING, "growth");
   script_server_signal_emit("city_growth", 2,
                             API_TYPE_CITY, pcity,
                             API_TYPE_INT, city_size_get(pcity));
@@ -943,21 +954,30 @@
   Change the city size.  Return TRUE iff the city is still alive afterwards.
 ****************************************************************************/
 bool city_change_size(struct city *pcity, citizens size,
-                      struct player *nationality)
-{
+                      struct player *nationality, const char *reason)
+{
+  int change = size - city_size_get(pcity);
+
   fc_assert_ret_val(size >= 0 && size <= MAX_CITY_SIZE, TRUE);
 
-  if (size > city_size_get(pcity)) {
+  if (change != 0 && reason != NULL) {
+    script_server_signal_emit("city_size_change", 3,
+                              API_TYPE_CITY, pcity,
+                              API_TYPE_INT, size - city_size_get(pcity),
+                              API_TYPE_STRING, reason);
+  }
+
+  if (change > 0) {
     /* Increase city size until size reached, or increase fails */
     while (size > city_size_get(pcity)
            && city_increase_size(pcity, nationality)) {
       /* city_increase_size() does all the work. */
     }
-  } else if (size < city_size_get(pcity)) {
+  } else if (change < 0) {
     /* We assume that city_change_size() is never called because
      * of enemy actions. If that changes, enemy must be passed
      * to city_reduce_size() */
-    return city_reduce_size(pcity, city_size_get(pcity) - size, NULL);
+    return city_reduce_size(pcity, -change, NULL, NULL);
   }
 
   map_claim_border(pcity->tile, pcity->owner, -1);
@@ -986,6 +1006,10 @@
     } else {
       city_increase_size(pcity, nationality);
       map_claim_border(pcity->tile, pcity->owner, -1);
+      script_server_signal_emit("city_size_change", 3,
+                            API_TYPE_CITY, pcity,
+                            API_TYPE_INT, 1,
+                            API_TYPE_STRING, "growth");
     }
   } else if (pcity->food_stock < 0) {
     /* FIXME: should this depend on units with ability to build
@@ -1025,7 +1049,7 @@
                    city_link(pcity));
     }
     city_reset_foodbox(pcity, city_size_get(pcity) - 1);
-    city_reduce_size(pcity, 1, NULL);
+    city_reduce_size(pcity, 1, NULL, "famine");
   }
 }
 
@@ -2119,7 +2143,7 @@
                       _("Citizens in %s perish for their failure to "
                         "upkeep %s!"),
                       city_link(pcity), unit_link(punit));
-       if (!city_reduce_size(pcity, 1, NULL)) {
+       if (!city_reduce_size(pcity, 1, NULL, "upkeep_failure")) {
          return FALSE;
        }
 
@@ -2364,7 +2388,7 @@
        * rearrange the worker to take into account the extra resources
        * (food) needed. */
       if (pop_cost > 0) {
-        city_reduce_size(pcity, pop_cost, NULL);
+        city_reduce_size(pcity, pop_cost, NULL, "unit_built");
       }
 
       /* to eliminate micromanagement, we only subtract the unit's cost */
@@ -3034,7 +3058,7 @@
         notify_player(pplayer, city_tile(pcity), E_CITY_PLAGUE, ftc_server,
                       _("%s has been struck by a plague! Population lost!"), 
                       city_link(pcity));
-        city_reduce_size(pcity, 1, NULL);
+        city_reduce_size(pcity, 1, NULL, "plague");
         pcity->turn_plague = game.info.turn;
 
         /* recalculate illness */
@@ -3457,6 +3481,10 @@
                           -1, TRUE);
       sz_strlcpy(name_from, city_tile_link(pcity_from));
 
+      script_server_signal_emit("city_size_change", 3,
+                            API_TYPE_CITY, pcity_from,
+                            API_TYPE_INT, -1,
+                            API_TYPE_STRING, "migration_from");
       script_server_signal_emit("city_destroyed", 3,
                                 API_TYPE_CITY, pcity_from,
                                 API_TYPE_PLAYER, pcity_from->owner,
@@ -3490,7 +3518,7 @@
       /* This should be followed by city_reduce_size(). */
       citizens_nation_add(pcity_from, pplayer_citizen->slot, -1);
     }
-    city_reduce_size(pcity_from, 1, pplayer_from);
+    city_reduce_size(pcity_from, 1, pplayer_from, "migration_from");
     city_refresh_vision(pcity_from);
     if (city_refresh(pcity_from)) {
       auto_arrange_workers(pcity_from);
@@ -3525,6 +3553,10 @@
   if (city_refresh(pcity_to)) {
     auto_arrange_workers(pcity_to);
   }
+  script_server_signal_emit("city_size_change", 3,
+                            API_TYPE_CITY, pcity_to,
+                            API_TYPE_INT, 1,
+                            API_TYPE_STRING, "migration_to");
 
   log_debug("[M] T%d migration successful (%s -> %s)",
             game.info.turn, name_from, name_to);
@@ -3609,7 +3641,7 @@
   if (disaster_has_effect(pdis, DE_REDUCE_DESTROY)
       || (disaster_has_effect(pdis, DE_REDUCE_POP)
           && pcity->size > 1)) {
-    if (!city_reduce_size(pcity, 1, NULL)) {
+    if (!city_reduce_size(pcity, 1, NULL, "disaster")) {
       notify_player(pplayer, ptile, E_DISASTER, ftc_server,
                     /* TRANS: "Industrial Accident destroys Bogota entirely" */
                     _("%s destroys %s entirely."),

Modified: trunk/server/cityturn.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/cityturn.h?rev=31247&r1=31246&r2=31247&view=diff
==============================================================================
--- trunk/server/cityturn.h     (original)
+++ trunk/server/cityturn.h     Mon Dec 28 21:56:42 2015
@@ -31,9 +31,9 @@
 void apply_cmresult_to_city(struct city *pcity, const struct cm_result *cmr);
 
 bool city_change_size(struct city *pcity, citizens new_size,
-                      struct player *nationality);
+                      struct player *nationality, const char *reason);
 bool city_reduce_size(struct city *pcity, citizens pop_loss,
-                      struct player *destroyer);
+                      struct player *destroyer, const char *reason);
 void city_repair_size(struct city *pcity, int change);
 
 void send_city_turn_notifications(struct connection *pconn);

Modified: trunk/server/diplomats.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/diplomats.c?rev=31247&r1=31246&r2=31247&view=diff
==============================================================================
--- trunk/server/diplomats.c    (original)
+++ trunk/server/diplomats.c    Mon Dec 28 21:56:42 2015
@@ -121,7 +121,7 @@
   log_debug("poison: succeeded");
 
   /* Poison people! */
-  if (city_reduce_size(pcity, 1, pplayer)) {
+  if (city_reduce_size(pcity, 1, pplayer, "poison")) {
     /* Notify everybody involved. */
     notify_player(pplayer, ctile, E_MY_DIPLOMAT_POISON, ftc_server,
                   _("Your %s poisoned the water supply of %s."),
@@ -845,7 +845,7 @@
 
   /* City loses some population. */
   if (city_size_get(pcity) > 1) {
-    city_reduce_size(pcity, 1, pplayer);
+    city_reduce_size(pcity, 1, pplayer, "incited");
   }
 
   /* This costs! */

Modified: trunk/server/edithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/edithand.c?rev=31247&r1=31246&r2=31247&view=diff
==============================================================================
--- trunk/server/edithand.c     (original)
+++ trunk/server/edithand.c     Mon Dec 28 21:56:42 2015
@@ -881,7 +881,7 @@
 
   if (size > 1) {
     /* FIXME: Slow and inefficient for large size changes. */
-    city_change_size(pcity, CLIP(1, size, MAX_CITY_SIZE), pplayer);
+    city_change_size(pcity, CLIP(1, size, MAX_CITY_SIZE), pplayer, NULL);
     send_city_info(NULL, pcity);
   }
 
@@ -939,7 +939,7 @@
                   packet->size, city_link(pcity));
     } else {
       /* FIXME: Slow and inefficient for large size changes. */
-      city_change_size(pcity, packet->size, NULL);
+      city_change_size(pcity, packet->size, NULL, NULL);
       changed = TRUE;
     }
   }

Modified: trunk/server/scripting/script_server.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/scripting/script_server.c?rev=31247&r1=31246&r2=31247&view=diff
==============================================================================
--- trunk/server/scripting/script_server.c      (original)
+++ trunk/server/scripting/script_server.c      Mon Dec 28 21:56:42 2015
@@ -353,6 +353,10 @@
   luascript_signal_create(fcl_main, "city_built", 1,
                           API_TYPE_CITY);
 
+  luascript_signal_create(fcl_main, "city_size_change", 3,
+                          API_TYPE_CITY, API_TYPE_INT, API_TYPE_STRING);
+
+  /* Deprecated form of the 'city_size_change' signal for the case of growth. 
*/
   luascript_signal_create(fcl_main, "city_growth", 2,
                           API_TYPE_CITY, API_TYPE_INT);
 

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=31247&r1=31246&r2=31247&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Mon Dec 28 21:56:42 2015
@@ -2257,7 +2257,7 @@
 
     fc_assert_ret_val(pcity != NULL, FALSE);
 
-    city_change_size(pcity, size, nationality);
+    city_change_size(pcity, size, nationality, NULL);
   }
   wipe_unit(punit, ULR_USED, NULL);
 
@@ -2531,7 +2531,7 @@
       && city_size_get(pcity) > 1
       && get_city_bonus(pcity, EFT_UNIT_NO_LOSE_POP) <= 0
       && kills_citizen_after_attack(punit)) {
-    city_reduce_size(pcity, 1, pplayer);
+    city_reduce_size(pcity, 1, pplayer, "bombard");
     city_refresh(pcity);
     send_city_info(NULL, pcity);
   }
@@ -2775,7 +2775,7 @@
       && city_size_get(pcity) > 1
       && get_city_bonus(pcity, EFT_UNIT_NO_LOSE_POP) <= 0
       && kills_citizen_after_attack(punit)) {
-    city_reduce_size(pcity, 1, pplayer);
+    city_reduce_size(pcity, 1, pplayer, "attack");
     city_refresh(pcity);
     send_city_info(NULL, pcity);
   }

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=31247&r1=31246&r2=31247&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Mon Dec 28 21:56:42 2015
@@ -2536,7 +2536,7 @@
                     city_link(pcity));
     }
 
-    city_reduce_size(pcity, city_size_get(pcity) / 2, pplayer);
+    city_reduce_size(pcity, city_size_get(pcity) / 2, pplayer, "nuke");
   }
 
   if (fc_rand(2) == 1) {


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

Reply via email to