<URL: http://bugs.freeciv.org/Ticket/Display.html?id=34737 >

On 1/29/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  This caches unit class move restrictions for AI usage after rulesets
> are loaded. No actual users yet.

 - Moved code part from common to ai


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiunit.c freeciv/ai/aiunit.c
--- freeciv/ai/aiunit.c	2007-03-05 01:06:08.000000000 +0200
+++ freeciv/ai/aiunit.c	2007-03-05 01:55:08.000000000 +0200
@@ -2513,3 +2513,56 @@
 
   simple_ai_types[i] = NULL;
 }
+
+/****************************************************************************
+  Build cached values about unit classes for AI
+****************************************************************************/
+void unit_class_ai_init(void)
+{
+  bv_special special;
+  BV_CLR_ALL(special); /* Can it move even without road */
+
+  unit_class_iterate(pclass) {
+    bool move_land_enabled  = FALSE; /* Can move at some land terrains */
+    bool move_land_disabled = FALSE; /* Cannot move at some land terrains */
+    bool move_sea_enabled   = FALSE; /* Can move at some ocean terrains */
+    bool move_sea_disabled  = FALSE; /* Cannot move at some ocean terrains */
+
+    terrain_type_iterate(pterrain) {
+      if (is_native_to_class(pclass, pterrain, special)) {
+        /* Can move at terrain */
+        if (is_ocean(pterrain)) {
+          move_sea_enabled = TRUE;
+        } else {
+          move_land_enabled = TRUE;
+        }
+      } else {
+        /* Cannot move at terrain */
+        if (is_ocean(pterrain)) {
+          move_sea_disabled = TRUE;
+        } else {
+          move_land_disabled = TRUE;
+        }
+      }
+    } terrain_type_iterate_end;
+
+    if (move_land_enabled && !move_land_disabled) {
+      pclass->ai.land_move = MOVE_FULL;
+    } else if (move_land_enabled && move_land_disabled) {
+      pclass->ai.land_move = MOVE_PARTIAL;
+    } else {
+      assert(!move_land_enabled);
+      pclass->ai.land_move = MOVE_NONE;
+    }
+
+    if (move_sea_enabled && !move_sea_disabled) {
+      pclass->ai.sea_move = MOVE_FULL;
+    } else if (move_sea_enabled && move_sea_disabled) {
+      pclass->ai.sea_move = MOVE_PARTIAL;
+    } else {
+      assert(!move_sea_enabled);
+      pclass->ai.sea_move = MOVE_NONE;
+    }
+
+  } unit_class_iterate_end;
+}
diff -Nurd -X.diff_ignore freeciv/ai/aiunit.h freeciv/ai/aiunit.h
--- freeciv/ai/aiunit.h	2006-07-17 23:56:46.000000000 +0300
+++ freeciv/ai/aiunit.h	2007-03-05 01:55:51.000000000 +0200
@@ -98,6 +98,9 @@
 
 void update_simple_ai_types(void);
 
+/* Call this after rulesets are loaded */
+void unit_class_ai_init(void);
+
 #define simple_ai_unit_type_iterate(m_i)                                    \
 {                                                                           \
   int m_c;                                                                  \
diff -Nurd -X.diff_ignore freeciv/common/unittype.h freeciv/common/unittype.h
--- freeciv/common/unittype.h	2007-03-01 01:49:07.000000000 +0200
+++ freeciv/common/unittype.h	2007-03-05 01:56:58.000000000 +0200
@@ -41,6 +41,8 @@
 BV_DEFINE(bv_unit_classes, UCL_LAST);
 BV_DEFINE(bv_unit_class_flags, UCF_LAST);
 
+enum move_level { MOVE_NONE, MOVE_PARTIAL, MOVE_FULL };
+
 struct unit_class {
   Unit_Class_id id;
   const char *name;        /* Translated name */
@@ -49,6 +51,11 @@
   int min_speed;           /* Minimum speed after damage and effects */
   int hp_loss_pct;         /* Percentage of hitpoints lost each turn not in city or airbase */
   bv_unit_class_flags flags;
+
+  struct {
+    enum move_level land_move;
+    enum move_level sea_move;
+  } ai;
 };
 
 /* Unit "special effects" flags:
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c	2007-03-04 16:55:04.000000000 +0200
+++ freeciv/server/ruleset.c	2007-03-05 01:51:43.000000000 +0200
@@ -3309,6 +3309,9 @@
      * connected clients. */
     send_rulesets(game.all_connections);
   }
+
+  /* Build AI unit class cache corresponding to loaded rulesets */
+  unit_class_ai_init();
 }
 
 /**************************************************************************
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to