Author: jtn
Date: Mon Jun  2 23:28:48 2014
New Revision: 25027

URL: http://svn.gna.org/viewcvs/freeciv?rev=25027&view=rev
Log:
Reorder disaster effects code for consistency with trunk, and so that if
assertion fails, NULL pointer isn't dereferenced.

See gna bug #22083.

Modified:
    branches/S2_5/server/cityturn.c

Modified: branches/S2_5/server/cityturn.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/cityturn.c?rev=25027&r1=25026&r2=25027&view=diff
==============================================================================
--- branches/S2_5/server/cityturn.c     (original)
+++ branches/S2_5/server/cityturn.c     Mon Jun  2 23:28:48 2014
@@ -2924,7 +2924,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));
 
@@ -2934,65 +2933,6 @@
                 _("%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]);
-
-      notify_player(pplayer, ptile, E_DISASTER, ftc_server,
-                    _("%s destroyed."),
-                    improvement_name_translation(imprs[num]));
-
-      had_effect = TRUE;
-    }
-  }
-
-  if (disaster_has_effect(pdis, DE_REDUCE_POP)
-      && pcity->size > 1) {
-    if (!city_reduce_size(pcity, 1, NULL)) {
-      fc_assert(FALSE);
-      city_or_null = NULL;
-    } else {
-      notify_player(pplayer, ptile, E_DISASTER, ftc_server,
-                    _("Some population lost."));
-    }
-
-    had_effect = TRUE;
-  }
-
-  if (disaster_has_effect(pdis, DE_EMPTY_FOODSTOCK)) {
-    if (pcity->food_stock > 0) {
-      pcity->food_stock = 0;
-
-      notify_player(pplayer, ptile, E_DISASTER, ftc_server,
-                    _("Foodbox emptied."));
-
-      had_effect = TRUE;
-    }
-  }
-
-  if (disaster_has_effect(pdis, DE_EMPTY_PRODSTOCK)) {
-    if (pcity->shield_stock > 0) {
-      pcity->shield_stock = 0;
-
-      notify_player(pplayer, ptile, E_DISASTER, ftc_server,
-                    _("Production box emptied."));
-
-      had_effect = TRUE;
-
-    }
-  }
-
   if (disaster_has_effect(pdis, DE_POLLUTION)) {
     if (place_pollution(pcity, S_POLLUTION)) {
       notify_player(pplayer, ptile, E_DISASTER, ftc_server,
@@ -3009,6 +2949,65 @@
     }
   }
 
+  if (disaster_has_effect(pdis, DE_REDUCE_POP)
+      && pcity->size > 1) {
+    if (!city_reduce_size(pcity, 1, NULL)) {
+      fc_assert(FALSE);
+      pcity = NULL;
+    } else {
+      notify_player(pplayer, ptile, E_DISASTER, ftc_server,
+                    _("Some population lost."));
+    }
+
+    had_effect = TRUE;
+  }
+
+  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;
+
+      notify_player(pplayer, ptile, E_DISASTER, ftc_server,
+                    _("Foodbox emptied."));
+
+      had_effect = TRUE;
+    }
+  }
+
+  if (pcity && disaster_has_effect(pdis, DE_EMPTY_PRODSTOCK)) {
+    if (pcity->shield_stock > 0) {
+      pcity->shield_stock = 0;
+
+      notify_player(pplayer, ptile, E_DISASTER, ftc_server,
+                    _("Production box emptied."));
+
+      had_effect = TRUE;
+
+    }
+  }
+
   if (!had_effect) {
     notify_player(pplayer, ptile, E_DISASTER, ftc_server,
                   _("We survived the disaster without serious damages."));
@@ -3016,7 +3015,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