Author: cazfi
Date: Tue Aug  9 23:08:56 2016
New Revision: 33533

URL: http://svn.gna.org/viewcvs/freeciv?rev=33533&view=rev
Log:
Changed city_waste() to calculate various effect values only when it needs them.

See patch #7567

Modified:
    trunk/common/city.c

Modified: trunk/common/city.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/city.c?rev=33533&r1=33532&r2=33533&view=diff
==============================================================================
--- trunk/common/city.c (original)
+++ trunk/common/city.c Tue Aug  9 23:08:56 2016
@@ -3019,10 +3019,6 @@
                           * possible size penalty */
   int waste_level = get_city_output_bonus(pcity, get_output_type(otype),
                                           EFT_OUTPUT_WASTE);
-  int waste_by_dist = get_city_output_bonus(pcity, get_output_type(otype),
-                                            EFT_OUTPUT_WASTE_BY_DISTANCE);
-  int waste_pct = get_city_output_bonus(pcity, get_output_type(otype), 
-                                        EFT_OUTPUT_WASTE_PCT);
   bool waste_all = FALSE;
 
   if (otype == O_TRADE) {
@@ -3049,39 +3045,46 @@
 
   /* Distance-based waste.
    * Don't bother calculating if there's nothing left to lose. */
-  if (waste_by_dist > 0 && total_eft > 0) {
-    const struct city *gov_center = NULL;
-    int min_dist = FC_INFINITY;
-
-    /* Check the special case that city itself is gov center
-     * before expensive iteration through all cities. */
-    if (is_gov_center(pcity)) {
-      gov_center = pcity;
-      min_dist = 0;
-    } else {
-      city_list_iterate(city_owner(pcity)->cities, gc) {
-        /* Do not recheck current city */
-        if (gc != pcity && is_gov_center(gc)) {
-          int dist = real_map_distance(gc->tile, pcity->tile);
-
-          if (dist < min_dist) {
-            gov_center = gc;
-            min_dist = dist;
+  if (total_eft > 0) {
+    int waste_by_dist = get_city_output_bonus(pcity, get_output_type(otype),
+                                              EFT_OUTPUT_WASTE_BY_DISTANCE);
+    if (waste_by_dist > 0) {
+      const struct city *gov_center = NULL;
+      int min_dist = FC_INFINITY;
+
+      /* Check the special case that city itself is gov center
+       * before expensive iteration through all cities. */
+      if (is_gov_center(pcity)) {
+        gov_center = pcity;
+        min_dist = 0;
+      } else {
+        city_list_iterate(city_owner(pcity)->cities, gc) {
+          /* Do not recheck current city */
+          if (gc != pcity && is_gov_center(gc)) {
+            int dist = real_map_distance(gc->tile, pcity->tile);
+
+            if (dist < min_dist) {
+              gov_center = gc;
+              min_dist = dist;
+            }
           }
-        }
-      } city_list_iterate_end;
-    }
-
-    if (gov_center == NULL) {
-      waste_all = TRUE; /* no gov center - no income */
-    } else {
-      waste_level += waste_by_dist * min_dist;
+        } city_list_iterate_end;
+      }
+
+      if (gov_center == NULL) {
+        waste_all = TRUE; /* no gov center - no income */
+      } else {
+        waste_level += waste_by_dist * min_dist;
+      }
     }
   }
 
   if (waste_all) {
     penalty_waste = total_eft;
   } else {
+    int waste_pct = get_city_output_bonus(pcity, get_output_type(otype),
+                                          EFT_OUTPUT_WASTE_PCT);
+
     /* corruption/waste calculated only for the actually produced amount */
     if (waste_level > 0) {
       penalty_waste = total_eft * waste_level / 100;


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

Reply via email to