Author: jtn
Date: Mon Jun  2 23:27:12 2014
New Revision: 25023

URL: http://svn.gna.org/viewcvs/freeciv?rev=25023&view=rev
Log:
Reorder disaster effects so that city destroyed by population loss is
not subsequently referenced.

See gna bug #22083.

Modified:
    trunk/server/cityturn.c

Modified: trunk/server/cityturn.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/cityturn.c?rev=25023&r1=25022&r2=25023&view=diff
==============================================================================
--- trunk/server/cityturn.c     (original)
+++ trunk/server/cityturn.c     Mon Jun  2 23:27:12 2014
@@ -3051,7 +3051,6 @@
   struct player *pplayer = city_owner(pcity);
   struct tile *ptile = city_tile(pcity);
   bool had_effect = FALSE;
-  struct city *city_or_null = pcity;
 
   log_debug("%s at %s", disaster_rule_name(pdis), city_name(pcity));
 
@@ -3061,25 +3060,18 @@
                 _("%s was hit by %s."), city_name(pcity),
                 disaster_rule_name(pdis));
 
-  if (disaster_has_effect(pdis, DE_DESTROY_BUILDING)) {
-    int total = 0;
-    struct impr_type *imprs[B_LAST];
-
-    city_built_iterate(pcity, pimprove) {
-      if (is_improvement(pimprove)) {
-        imprs[total++] = pimprove;
-      }
-    } city_built_iterate_end;
-
-    if (total > 0) {
-      int num = fc_rand(total);
-
-      building_lost(pcity, imprs[num]);
-
+  if (disaster_has_effect(pdis, DE_POLLUTION)) {
+    if (place_pollution(pcity, EC_POLLUTION)) {
       notify_player(pplayer, ptile, E_DISASTER, ftc_server,
-                    _("%s destroyed."),
-                    improvement_name_translation(imprs[num]));
-
+                    _("Tile polluted"));
+      had_effect = TRUE;
+    }
+  }
+
+  if (disaster_has_effect(pdis, DE_FALLOUT)) {
+    if (place_pollution(pcity, EC_FALLOUT)) {
+      notify_player(pplayer, ptile, E_DISASTER, ftc_server,
+                    _("Fallout contaminated tile."));
       had_effect = TRUE;
     }
   }
@@ -3090,7 +3082,7 @@
     if (!city_reduce_size(pcity, 1, NULL)) {
       notify_player(pplayer, ptile, E_DISASTER, ftc_server,
                     _("City got destroyed completely."));
-      city_or_null = NULL;
+      pcity = NULL;
     } else {
       notify_player(pplayer, ptile, E_DISASTER, ftc_server,
                     _("Some population lost."));
@@ -3099,7 +3091,30 @@
     had_effect = TRUE;
   }
 
-  if (disaster_has_effect(pdis, DE_EMPTY_FOODSTOCK)) {
+  if (pcity && disaster_has_effect(pdis, DE_DESTROY_BUILDING)) {
+    int total = 0;
+    struct impr_type *imprs[B_LAST];
+
+    city_built_iterate(pcity, pimprove) {
+      if (is_improvement(pimprove)) {
+        imprs[total++] = pimprove;
+      }
+    } city_built_iterate_end;
+
+    if (total > 0) {
+      int num = fc_rand(total);
+
+      building_lost(pcity, imprs[num]);
+
+      notify_player(pplayer, ptile, E_DISASTER, ftc_server,
+                    _("%s destroyed."),
+                    improvement_name_translation(imprs[num]));
+
+      had_effect = TRUE;
+    }
+  }
+
+  if (pcity && disaster_has_effect(pdis, DE_EMPTY_FOODSTOCK)) {
     if (pcity->food_stock > 0) {
       pcity->food_stock = 0;
 
@@ -3110,7 +3125,7 @@
     }
   }
 
-  if (disaster_has_effect(pdis, DE_EMPTY_PRODSTOCK)) {
+  if (pcity && disaster_has_effect(pdis, DE_EMPTY_PRODSTOCK)) {
     if (pcity->shield_stock > 0) {
       pcity->shield_stock = 0;
 
@@ -3119,22 +3134,6 @@
 
       had_effect = TRUE;
 
-    }
-  }
-
-  if (disaster_has_effect(pdis, DE_POLLUTION)) {
-    if (place_pollution(pcity, EC_POLLUTION)) {
-      notify_player(pplayer, ptile, E_DISASTER, ftc_server,
-                    _("Tile polluted"));
-      had_effect = TRUE;
-    }
-  }
-
-  if (disaster_has_effect(pdis, DE_FALLOUT)) {
-    if (place_pollution(pcity, EC_FALLOUT)) {
-      notify_player(pplayer, ptile, E_DISASTER, ftc_server,
-                    _("Fallout contaminated tile."));
-      had_effect = TRUE;
     }
   }
 
@@ -3145,7 +3144,7 @@
 
   script_server_signal_emit("disaster", 2,
                             API_TYPE_DISASTER, pdis,
-                            API_TYPE_CITY, city_or_null);
+                            API_TYPE_CITY, pcity);
 }
 
 /**************************************************************************


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

Reply via email to