Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] Re: (PR#4701) autoattack oddities esp. with cruise missile
Home

[Freeciv-Dev] Re: (PR#4701) autoattack oddities esp. with cruise missile

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#4701) autoattack oddities esp. with cruise missiles
From: "Andy Smith" <andy@xxxxxxxxxxxxxx>
Date: Tue, 29 Jul 2003 02:08:55 -0700
Reply-to: rt@xxxxxxxxxxxxxx

On Tue, Jul 29, 2003 at 02:07:03AM -0700, Andy Smith wrote:
> How's this patch (attached)?

Really attached this time.

--- freeciv-cvs/server/autoattack.c     2003-07-17 19:56:51.000000000 +0100
+++ freeciv-patched/server/autoattack.c 2003-07-29 09:48:06.000000000 +0100
@@ -44,6 +44,7 @@
 #include "unit.h"
 
 #include "gotohand.h"
+#include "maphand.h"
 #include "plrhand.h"
 #include "srv_main.h"
 #include "unithand.h"
@@ -111,6 +112,44 @@
     }
 
     /*
+     * Make sure the player can see both the location and the unit at that
+     * location, before allowing an auto-attack.  Without this, units attack
+     * into locations they cannot see, and maybe submarines are made
+     * erroneously visible too.
+     *
+     * Note, cheating AI knows of and can see the whole map, unless they have
+     * H_MAP and H_FOG handicaps respectively.  Should AI get help to see
+     * submarines?
+     */
+    if ((ai_handicap(pplayer, H_MAP) && !map_get_known(x, y, pplayer))
+        || (ai_handicap(pplayer, H_FOG)
+           && !map_get_known_and_seen(x, y, pplayer))
+       || !player_can_see_unit_at_location(pplayer, enemy, x, y)) {
+      freelog(LOG_DEBUG, "can't see %s at (%d,%d)", unit_name(enemy->type), x, 
y);
+      continue;
+    }
+
+    /*
+     * is this the correct function to use here?  c_u_a_u_a_t() seems to assume
+     * that attacker is in an adjacent tile but I do not think it matters.
+     *
+     * On the other hand, we already checked everything that this function
+     * checks, except for missiles trying to attack air units, so perhaps we
+     * should just do that check here?  But doing a final sanity check to make
+     * sure our attacker can engage the enemy at all seems safest.
+     *
+     * Without this check, missiles are made useless for auto-attack as they
+     * get triggered by fighters and bombers and end up being wasted when they
+     * cannot engage.
+     */
+    if (!can_unit_attack_unit_at_tile(punit, enemy, x, y)) {
+      freelog(LOG_DEBUG, "%s at (%d,%d) cannot attack %s at (%d,%d)",
+             unit_name(punit->type), punit->x, punit->y,
+             unit_name(enemy->type), x, y);
+      continue;
+    }
+
+    /*
      *  perhaps there is a better algorithm in the ai-package -- fisch
      */
     score = (unit_type(enemy)->defense_strength + (enemy->hp / 2)

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