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

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

[Top] [All Lists]

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

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

Marko Lindqvist wrote:
> 
>   This replaces F_CARRIER and F_MISSILE_CARRIER checks with calls to 
> can_unit_type_transport() in AI code.

  Missed one F_MISSILE_CARRIER check.
  That code (ai_fill_unit_param()) tagged normal carriers as ferries. 
Have to check if that was intentional and what to do if it was.


  - ML


diff -Nurd -X.diff_ignore freeciv/ai/aihunt.c freeciv/ai/aihunt.c
--- freeciv/ai/aihunt.c 2006-07-13 22:52:29.515625000 +0300
+++ freeciv/ai/aihunt.c 2006-07-13 22:52:34.296875000 +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 22:52:29.687500000 +0300
+++ freeciv/ai/aitools.c        2006-07-13 23:09:02.484375000 +0300
@@ -642,9 +642,6 @@
                        struct ai_risk_cost *risk_cost,
                        struct unit *punit, struct tile *ptile)
 {
-  const bool is_ferry = get_transporter_capacity(punit) > 0
-                        && !unit_flag(punit, F_MISSILE_CARRIER)
-                        && punit->ai.ai_role != AIUNIT_HUNTER;
   const bool is_air = is_air_unit(punit)
                       && punit->ai.ai_role != AIUNIT_ESCORT;
   const bool long_path = LONG_TIME < (map_distance(punit->tile, punit->tile)
@@ -652,6 +649,18 @@
                                      / unit_type(punit)->move_rate);
   const bool barbarian = is_barbarian(unit_owner(punit));
   const bool is_ai = unit_owner(punit)->ai.control;
+  bool is_ferry = FALSE;
+
+  if (punit->ai.ai_role != AIUNIT_HUNTER
+      && get_transporter_capacity(punit) > 0) {
+    unit_class_iterate(uclass) {
+      if (can_unit_type_transport(unit_type(punit), uclass)
+          && uclass->move_type == LAND_MOVING) {
+        is_ferry = TRUE;
+        break;
+      }
+    } unit_class_iterate_end;
+  }
 
   if (is_ferry) {
     /* The destination may be a coastal land tile,
@@ -858,20 +867,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]