Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2006:
[Freeciv-Dev] (PR#18566) [Patch] Remove F_CARRIER checks from AI code
Home

[Freeciv-Dev] (PR#18566) [Patch] Remove F_CARRIER checks from AI code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#18566) [Patch] Remove F_CARRIER checks from AI code
From: "Marko Lindqvist" <cazfi74@xxxxxxxxx>
Date: Thu, 13 Jul 2006 11:14:05 -0700
Reply-to: bugs@xxxxxxxxxxx

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


  This replaces F_CARRIER and F_MISSILE_CARRIER checks with calls to 
can_unit_type_transport() in AI code.


  - ML

diff -Nurd -X.diff_ignore freeciv/ai/aihunt.c freeciv/ai/aihunt.c
--- freeciv/ai/aihunt.c 2006-07-13 15:32:17.897125000 +0300
+++ freeciv/ai/aihunt.c 2006-07-13 19:25:00.375000000 +0300
@@ -83,10 +83,14 @@
               * ut->move_rate
               + ut->defense_strength) / MAX(UNITTYPE_COSTS(ut), 1);
 
-    if (unit_type_flag(ut, F_CARRIER)
-        || unit_type_flag(ut, F_MISSILE_CARRIER)) {
-      desire += desire / 6;
-    }
+    unit_class_iterate(uclass) {
+      if (can_unit_type_transport(ut, uclass)
+          && unit_class_flag(uclass, UCF_MISSILE)) {
+        desire += desire / 6;
+        break;
+      }
+    } unit_class_iterate_end;
+
     if (unit_type_flag(ut, F_IGTER)) {
       desire += desire / 2;
     }
@@ -123,20 +127,24 @@
 {
   int best = -1;
   struct unit_type *best_unit_type = NULL;
-  bool have_hunter = FALSE;
+  struct unit *hunter = NULL;
 
   unit_list_iterate(pcity->tile->units, punit) {
-    if (ai_hunter_qualify(pplayer, punit)
-        && (unit_flag(punit, F_MISSILE_CARRIER)
-            || unit_flag(punit, F_CARRIER))) {
-      /* There is a potential hunter in our city which we can equip 
-       * with a missile. Do it. */
-      have_hunter = TRUE;
-      break;
+    if (ai_hunter_qualify(pplayer, punit)) {
+      unit_class_iterate(uclass) {
+        if (can_unit_type_transport(unit_type(punit), uclass)
+            && unit_class_flag(uclass, UCF_MISSILE)) {
+          hunter = punit;
+          break;
+        }
+      } unit_class_iterate_end;
+      if (hunter) {
+        break;
+      }
     }
   } unit_list_iterate_end;
 
-  if (!have_hunter) {
+  if (!hunter) {
     return;
   }
 
@@ -147,6 +155,10 @@
       continue;
     }
 
+    if (!can_unit_type_transport(unit_type(hunter), get_unit_class(ut))) {
+      continue;
+    }
+
     /* FIXME: We need to store some data that can tell us if
      * enemy transports are protected by anti-missile technology. 
      * In this case, want nuclear much more! */
diff -Nurd -X.diff_ignore freeciv/ai/aitools.c freeciv/ai/aitools.c
--- freeciv/ai/aitools.c        2006-07-13 15:32:18.381500000 +0300
+++ freeciv/ai/aitools.c        2006-07-13 19:03:03.015625000 +0300
@@ -858,20 +858,17 @@
     UNIT_LOG(LOGLEVEL_HUNT, target, "is being hunted");
 
     /* Grab missiles lying around and bring them along */
-    if (unit_flag(punit, F_MISSILE_CARRIER)
-        || unit_flag(punit, F_CARRIER)) {
-      unit_list_iterate(punit->tile->units, missile) {
-        if (missile->ai.ai_role != AIUNIT_ESCORT
-            && missile->transported_by == -1
-            && missile->owner == punit->owner
-            && unit_class_flag(get_unit_class(unit_type(missile)), UCF_MISSILE)
-            && can_unit_load(missile, punit)) {
-          UNIT_LOG(LOGLEVEL_HUNT, missile, "loaded on hunter");
-          ai_unit_new_role(missile, AIUNIT_ESCORT, target->tile);
-          load_unit_onto_transporter(missile, punit);
-        }
-      } unit_list_iterate_end;
-    }
+    unit_list_iterate(punit->tile->units, missile) {
+      if (missile->ai.ai_role != AIUNIT_ESCORT
+          && missile->transported_by == -1
+          && missile->owner == punit->owner
+          && unit_class_flag(get_unit_class(unit_type(missile)), UCF_MISSILE)
+          && can_unit_load(missile, punit)) {
+        UNIT_LOG(LOGLEVEL_HUNT, missile, "loaded on hunter");
+        ai_unit_new_role(missile, AIUNIT_ESCORT, target->tile);
+        load_unit_onto_transporter(missile, punit);
+      }
+    } unit_list_iterate_end;
   }
 }
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#18566) [Patch] Remove F_CARRIER checks from AI code, Marko Lindqvist <=