Author: cazfi
Date: Thu Jan 15 06:24:34 2015
New Revision: 27693

URL: http://svn.gna.org/viewcvs/freeciv?rev=27693&view=rev
Log:
Replaced separate iterations for roads and bases with one iteration over all 
extras when
threaded AI settlers evaluate what to build.

See patch #5676

Modified:
    branches/S2_6/ai/threaded/taicity.c
    branches/S2_6/common/extras.c
    branches/S2_6/common/extras.h
    branches/S2_6/server/advisors/autosettlers.c
    branches/S2_6/server/advisors/autosettlers.h

Modified: branches/S2_6/ai/threaded/taicity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/threaded/taicity.c?rev=27693&r1=27692&r2=27693&view=diff
==============================================================================
--- branches/S2_6/ai/threaded/taicity.c (original)
+++ branches/S2_6/ai/threaded/taicity.c Thu Jan 15 06:24:34 2015
@@ -189,27 +189,44 @@
       }
     } as_transform_activity_iterate_end;
 
-    road_type_iterate(proad) {
-      bool possible = FALSE;
+    extra_type_iterate(tgt) {
+      enum unit_activity act = ACTIVITY_LAST;
 
       unit_list_iterate(units, punit) {
-        struct extra_type *tgt = road_extra_get(proad);
-
-        if (can_unit_do_activity_targeted_at(punit, ACTIVITY_GEN_ROAD, tgt, 
ptile)) {
-          possible = TRUE;
-          break;
-        }
+        as_extra_activity_iterate(try_act) {
+          if (is_extra_caused_by_action(tgt, try_act)
+              && can_unit_do_activity_targeted_at(punit, try_act, tgt, ptile)) 
{
+            act = try_act;
+            break;
+          }
+        } as_extra_activity_iterate_end;
       } unit_list_iterate_end;
 
-      if (possible) {
+      if (act != ACTIVITY_LAST) {
         int value;
         int extra;
-        struct extra_type *pextra;
-
-        pextra = road_extra_get(proad);
-        value = adv_city_worker_extra_get(pcity, cindex, pextra);
-
-        if (road_provides_move_bonus(proad)) {
+        bool consider = TRUE;
+        struct road_type *proad;
+
+        /* Do not request activities that already are under way. */
+        unit_list_iterate(ptile->units, punit) {
+          if (unit_owner(punit) == pplayer
+              && unit_has_type_flag(punit, UTYF_SETTLERS)
+              && punit->activity == act) {
+            consider = FALSE;
+            break;
+          }
+        } unit_list_iterate_end;
+
+        if (!consider) {
+          continue;
+        }
+
+        proad = extra_road_get(tgt);
+
+        value = adv_city_worker_extra_get(pcity, cindex, tgt);
+
+        if (proad != NULL && road_provides_move_bonus(proad)) {
           int old_move_cost;
           int mc_multiplier = 1;
           int mc_divisor = 1;
@@ -250,8 +267,8 @@
           if ((value - orig_value) * TWMP > worked.want) {
             worked.want  = TWMP * (value - orig_value);
             worked.ptile = ptile;
-            worked.act   = ACTIVITY_GEN_ROAD;
-            worked.tgt   = NULL;
+            worked.act   = act;
+            worked.tgt   = tgt;
           }
           if (value > old_worst_worked) {
             /* After improvement it would not be the worst */
@@ -264,56 +281,12 @@
             uw_max = value;
             unworked.want  = TWMP * (value - orig_value);
             unworked.ptile = ptile;
-            unworked.act   = ACTIVITY_GEN_ROAD;
-            unworked.tgt   = NULL;
+            unworked.act   = act;
+            unworked.tgt   = tgt;
           }
         }
       }
-    } road_type_iterate_end;
-
-    base_type_iterate(pbase) {
-      bool possible = FALSE;
-
-      unit_list_iterate(units, punit) {
-        struct extra_type *tgt = base_extra_get(pbase);
-
-        if (can_unit_do_activity_targeted_at(punit, ACTIVITY_BASE, tgt, 
ptile)) {
-          possible = TRUE;
-          break;
-        }
-      } unit_list_iterate_end;
-
-      if (possible) {
-        int value;
-        struct extra_type *pextra;
-
-        pextra = base_extra_get(pbase);
-        value = adv_city_worker_extra_get(pcity, cindex, pextra);
-
-        if (tile_worked(ptile) == pcity) {
-          if ((value - orig_value) * TWMP > worked.want) {
-            worked.want  = TWMP * (value - orig_value);
-            worked.ptile = ptile;
-            worked.act   = ACTIVITY_BASE;
-            worked.tgt   = NULL;
-          }
-          if (value > old_worst_worked) {
-            /* After improvement it would not be the worst */
-            potential_worst_worked = FALSE;
-          } else {
-            worst_worked = value;
-          }
-        } else {
-          if (value > orig_value && value > uw_max) {
-            uw_max = value;
-            unworked.want  = TWMP * (value - orig_value);
-            unworked.ptile = ptile;
-            unworked.act   = ACTIVITY_BASE;
-            unworked.tgt   = NULL;
-          }
-        }
-      }
-    } base_type_iterate_end;
+    } extra_type_iterate_end;
 
     if (potential_worst_worked) {
       /* Would still be worst worked even if we improved *it*. */

Modified: branches/S2_6/common/extras.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/extras.c?rev=27693&r1=27692&r2=27693&view=diff
==============================================================================
--- branches/S2_6/common/extras.c       (original)
+++ branches/S2_6/common/extras.c       Thu Jan 15 06:24:34 2015
@@ -693,6 +693,15 @@
 }
 
 /**************************************************************************
+  Is the extra caused by specific worker action?
+**************************************************************************/
+bool is_extra_caused_by_action(const struct extra_type *pextra,
+                               enum unit_activity act)
+{
+  return is_extra_caused_by(pextra, activity_to_extra_cause(act));
+}
+
+/**************************************************************************
   What extra cause activity is considered to be?
 **************************************************************************/
 enum extra_cause activity_to_extra_cause(enum unit_activity act)

Modified: branches/S2_6/common/extras.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/extras.h?rev=27693&r1=27692&r2=27693&view=diff
==============================================================================
--- branches/S2_6/common/extras.h       (original)
+++ branches/S2_6/common/extras.h       Thu Jan 15 06:24:34 2015
@@ -142,6 +142,8 @@
 
 bool is_extra_caused_by(const struct extra_type *pextra, enum extra_cause 
cause);
 bool is_extra_caused_by_worker_action(const struct extra_type *pextra);
+bool is_extra_caused_by_action(const struct extra_type *pextra,
+                               enum unit_activity act);
 
 void extra_to_removed_by_list(struct extra_type *pextra, enum extra_rmcause 
rmcause);
 struct extra_type_list *extra_type_list_by_rmcause(enum extra_rmcause rmcause);

Modified: branches/S2_6/server/advisors/autosettlers.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/advisors/autosettlers.c?rev=27693&r1=27692&r2=27693&view=diff
==============================================================================
--- branches/S2_6/server/advisors/autosettlers.c        (original)
+++ branches/S2_6/server/advisors/autosettlers.c        Thu Jan 15 06:24:34 2015
@@ -73,6 +73,7 @@
 };
 
 Activity_type_id as_activities_transform[ACTIVITY_LAST];
+Activity_type_id as_activities_extra[ACTIVITY_LAST];
 
 /**************************************************************************
   Initialize advisor systems.
@@ -91,6 +92,13 @@
   as_activities_transform[i++] = ACTIVITY_FALLOUT;
 
   as_activities_transform[i++] = ACTIVITY_LAST;
+
+  i = 0;
+  as_activities_extra[i++] = ACTIVITY_IRRIGATE;
+  as_activities_extra[i++] = ACTIVITY_MINE;
+  as_activities_extra[i++] = ACTIVITY_GEN_ROAD;
+  as_activities_extra[i++] = ACTIVITY_BASE;
+  as_activities_extra[i++] = ACTIVITY_LAST;
 }
 
 /**************************************************************************

Modified: branches/S2_6/server/advisors/autosettlers.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/advisors/autosettlers.h?rev=27693&r1=27692&r2=27693&view=diff
==============================================================================
--- branches/S2_6/server/advisors/autosettlers.h        (original)
+++ branches/S2_6/server/advisors/autosettlers.h        Thu Jan 15 06:24:34 2015
@@ -69,4 +69,14 @@
   activity_type_list_iterate_end                                            \
 }
 
+extern Activity_type_id as_activities_extra[ACTIVITY_LAST];
+
+#define as_extra_activity_iterate(_act_)                                    \
+{                                                                           \
+  activity_type_list_iterate(as_activities_extra, _act_)
+
+#define as_extra_activity_iterate_end                                       \
+  activity_type_list_iterate_end                                            \
+}
+
 #endif   /* FC__AUTOSETTLERS_H */


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

Reply via email to