Author: cazfi
Date: Sun Aug  9 19:02:32 2015
New Revision: 29426

URL: http://svn.gna.org/viewcvs/freeciv?rev=29426&view=rev
Log:
Fixed autosettlers from doing things it even itself considers to be 
counterproductive.

See bug #23748

Modified:
    branches/S2_6/server/advisors/autosettlers.c

Modified: branches/S2_6/server/advisors/autosettlers.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/advisors/autosettlers.c?rev=29426&r1=29425&r2=29426&view=diff
==============================================================================
--- branches/S2_6/server/advisors/autosettlers.c        (original)
+++ branches/S2_6/server/advisors/autosettlers.c        Sun Aug  9 19:02:32 2015
@@ -295,25 +295,30 @@
                                     struct tile **best_tile,
                                     struct tile *ptile)
 {
-  bool consider;
+  bool improves;
   int total_value = 0, base_value = 0;
   int old_improvement_value;
 
-  if (extra >= 0) {
-    consider = TRUE;
+  if (extra < 0) {
+    extra = 0;
+  }
+
+  if (new_tile_value > old_tile_value) {
+    improves = TRUE;
+  } else if (new_tile_value == old_tile_value && extra > 0) {
+    improves = TRUE;
   } else {
-    consider = (new_tile_value > old_tile_value);
-    extra = 0;
+    improves = FALSE;
   }
 
   /* find the present value of the future benefit of this action */
-  if (consider) {
+  if (improves || extra > 0) {
     if (!(*improve_worked) && !in_use) {
       /* Going to improve tile that is not yet in use.
        * Getting the best possible total for next citizen to work on is more
        * important than amount tile gets improved. */
-      if (new_tile_value > *best_value
-          || (new_tile_value == *best_value && old_tile_value < 
*best_old_tile_value)) {
+      if (improves && (new_tile_value > *best_value
+                       || (new_tile_value == *best_value && old_tile_value < 
*best_old_tile_value))) {
         *best_value = new_tile_value;
         *best_old_tile_value = old_tile_value;
         *best_act = act;
@@ -337,34 +342,32 @@
 
     /* use factor to prevent rounding errors */
     total_value = amortize(total_value, delay);
-  } else {
-    total_value = 0;
-  }
-
-  if (*improve_worked) {
-    old_improvement_value = *best_value;
-  } else {
-    /* Convert old best_value to improvement value compatible with in_use
-     * tile value */
-    old_improvement_value = amortize((*best_value - *best_old_tile_value) * 
WORKER_FACTOR / 2,
-                                     *best_delay);
-  }
-
-  if (total_value > old_improvement_value
-      || (total_value == old_improvement_value
-         && old_tile_value > *best_old_tile_value)) {
-    if (in_use) {
-      *best_value = total_value;
-      *improve_worked = TRUE;
+
+    if (*improve_worked) {
+      old_improvement_value = *best_value;
     } else {
-      *best_value = new_tile_value;
-      *improve_worked = FALSE;
-    }
-    *best_old_tile_value = old_tile_value;
-    *best_act = act;
-    *best_target = target;
-    *best_tile = ptile;
-    *best_delay = delay;
+      /* Convert old best_value to improvement value compatible with in_use
+       * tile value */
+      old_improvement_value = amortize((*best_value - *best_old_tile_value) * 
WORKER_FACTOR / 2,
+                                       *best_delay);
+    }
+
+    if (total_value > old_improvement_value
+        || (total_value == old_improvement_value
+            && old_tile_value > *best_old_tile_value)) {
+      if (in_use) {
+        *best_value = total_value;
+        *improve_worked = TRUE;
+      } else {
+        *best_value = new_tile_value;
+        *improve_worked = FALSE;
+      }
+      *best_old_tile_value = old_tile_value;
+      *best_act = act;
+      *best_target = target;
+      *best_tile = ptile;
+      *best_delay = delay;
+    }
   }
 }
 


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

Reply via email to