Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] Re: (PR#12725) Attacking Ferries and ai_fill_unit_param
Home

[Freeciv-Dev] Re: (PR#12725) Attacking Ferries and ai_fill_unit_param

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#12725) Attacking Ferries and ai_fill_unit_param
From: "Benedict Adamson" <badamson@xxxxxxxxxxx>
Date: Wed, 6 Apr 2005 15:16:13 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Here is a patch.

Index: ai/aitools.c
===================================================================
--- ai/aitools.c        (revision 1891)
+++ ai/aitools.c        (working copy)
@@ -597,26 +597,27 @@
                        struct ai_risk_cost *risk_cost,
                        struct unit *punit, struct tile *ptile)
 {
+  const bool is_ai = unit_owner(punit)->ai.control;
+  const bool combat_role = is_ai
+                           && (punit->ai.ai_role == AIUNIT_DEFEND_HOME
+                               || punit->ai.ai_role == AIUNIT_ATTACK
+                               || punit->ai.ai_role ==  AIUNIT_ESCORT
+                               || punit->ai.ai_role == AIUNIT_HUNTER);
   const bool is_ferry = get_transporter_capacity(punit) > 0
                         && !unit_flag(punit, F_MISSILE_CARRIER)
-                        && punit->ai.ai_role != AIUNIT_HUNTER;
+                        && !combat_role;
   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)
                                      * SINGLE_MOVE
                                      / unit_type(punit)->move_rate);
   const bool barbarian = is_barbarian(unit_owner(punit));
-  const bool is_ai = unit_owner(punit)->ai.control;
 
   if (is_ferry) {
     /* The destination may be a coastal land tile,
      * in which case the ferry should stop on an adjacent tile. */
     pft_fill_unit_overlap_param(parameter, punit);
-  } else if (is_ai && !is_air && is_military_unit(punit)
-            && (punit->ai.ai_role == AIUNIT_DEFEND_HOME
-                || punit->ai.ai_role == AIUNIT_ATTACK
-                || punit->ai.ai_role ==  AIUNIT_ESCORT
-                || punit->ai.ai_role == AIUNIT_HUNTER)) {
+  } else if (combat_role && !is_air && is_military_unit(punit)) {
     /* Use attack movement for defenders and escorts so they can
      * make defensive attacks */
     pft_fill_unit_attack_param(parameter, punit);
@@ -693,7 +694,7 @@
     /* Default tile behaviour */
   } else if (is_heli_unit(punit)) {
     /* Default tile behaviour */
-  } else if (is_military_unit(punit)) {
+  } else if (is_military_unit(punit) || combat_role) {
     switch (punit->ai.ai_role) {
     case AIUNIT_AUTO_SETTLER:
     case AIUNIT_BUILD_CITY:
@@ -701,8 +702,16 @@
       parameter->get_TB = no_fights;
       break;
     case AIUNIT_DEFEND_HOME:
+    case AIUNIT_ESCORT:
+      if (is_military_unit(punit)) {
+        /* allow defensive attacks */
+        parameter->get_TB = no_intermediate_fights;
+      } else {
+        /* all we can do is soak up damage */
+        parameter->get_TB = no_fights;
+      }
+      break;
     case AIUNIT_ATTACK:
-    case AIUNIT_ESCORT:
     case AIUNIT_HUNTER:
       parameter->get_TB = no_intermediate_fights;
       break;
@@ -719,9 +728,11 @@
     parameter->get_TB = no_fights;
   }
 
-  if (is_ferry) {
+  if (parameter->is_pos_dangerous) {
     /* Must use TM_WORST_TIME, so triremes move safely */
     parameter->turn_mode = TM_WORST_TIME;
+  }
+  if (is_ferry) {
     /* Show the destination in the client when watching an AI: */
     punit->goto_tile = ptile;
   }

[Prev in Thread] Current Thread [Next in Thread]