Complete.Org: Mailing Lists: Archives: freeciv-ai: July 2006:
[freeciv-ai] Re: [Freeciv-Dev] Re: (PR#18566) [Patch] Remove F_CARRIER c
Home

[freeciv-ai] Re: [Freeciv-Dev] Re: (PR#18566) [Patch] Remove F_CARRIER c

[Top] [All Lists]

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

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

Marko Lindqvist wrote:
> 
> 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.

  I guess it is intentional. Attached version is conversion loyal to old 
code. Autogame I run matched.

  In order to find out if given unit_type 'is_ferry', AI iterates 
through unit classes and calls several functions to each. As 'is_ferry' 
result is always same for a given unit_type, it probably should be 
cached at ruleset load. I'll leave that to later patch.


  - ML

diff -Nurd -X.diff_ignore freeciv/ai/aihunt.c freeciv/ai/aihunt.c
--- freeciv/ai/aihunt.c 2006-07-14 23:29:00.953125000 +0300
+++ freeciv/ai/aihunt.c 2006-07-15 01:00:48.859375000 +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-14 23:29:01.203125000 +0300
+++ freeciv/ai/aitools.c        2006-07-15 01:03:44.109375000 +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,20 @@
                                      / 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
+              || (uclass->move_type == AIR_MOVING
+                  && !unit_class_flag(uclass, UCF_MISSILE)))) {
+        is_ferry = TRUE;
+        break;
+      }
+    } unit_class_iterate_end;
+  }
 
   if (is_ferry) {
     /* The destination may be a coastal land tile,
@@ -858,20 +869,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;
   }
 }
 
diff -Nurd -X.diff_ignore freeciv/ai/aiunit.c freeciv/ai/aiunit.c
--- freeciv/ai/aiunit.c 2006-07-15 01:00:29.250000000 +0300
+++ freeciv/ai/aiunit.c 2006-07-15 01:05:37.000000000 +0300
@@ -2077,6 +2077,7 @@
 void ai_manage_unit(struct player *pplayer, struct unit *punit)
 {
   struct unit *bodyguard = aiguard_guard_of(punit);
+  bool is_ferry = FALSE;
 
   CHECK_UNIT(punit);
 
@@ -2111,6 +2112,18 @@
     return;
   }
 
+  if (get_transporter_capacity(punit) > 0) {
+    unit_class_iterate(pclass) {
+      if (can_unit_type_transport(unit_type(punit), pclass)
+          && (pclass->move_type == LAND_MOVING
+              || (pclass->move_type == AIR_MOVING
+                  && !unit_class_flag(pclass, UCF_MISSILE)))) {
+        is_ferry = TRUE;
+        break;
+      }
+    } unit_class_iterate_end;
+  }
+
   if ((unit_flag(punit, F_DIPLOMAT))
       || (unit_flag(punit, F_SPY))) {
     TIMING_LOG(AIT_DIPLOMAT, TIMER_START);
@@ -2133,9 +2146,7 @@
   } else if (unit_flag(punit, F_PARATROOPERS)) {
     ai_manage_paratrooper(pplayer, punit);
     return;
-  } else if (get_transporter_capacity(punit) > 0
-             && !unit_flag(punit, F_MISSILE_CARRIER)
-             && punit->ai.ai_role != AIUNIT_HUNTER) {
+  } else if (is_ferry && punit->ai.ai_role != AIUNIT_HUNTER) {
     TIMING_LOG(AIT_FERRY, TIMER_START);
     ai_manage_ferryboat(pplayer, punit);
     TIMING_LOG(AIT_FERRY, TIMER_STOP);

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