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: Wed, 30 Jul 2003 19:08:35 -0700
Reply-to: rt@xxxxxxxxxxxxxx

On Wed, Jul 30, 2003 at 06:29:14AM -0700, Gregory Berkolaiko wrote:
> 
> On Wed, 30 Jul 2003, Per I. Mathisen wrote:
> 
> > On Tue, 29 Jul 2003, Andy Smith wrote:
> > > To be clear, are you suggesting that H_TARGETS should be checked for
> > > auto-attack instead of H_MAP and H_FOG? If so, I agree, since the
> > > intention of H_TARGETS clearly seems to be to prevent the AI from
> > > doing exactly this.
> > 
> > Yes.
> 
> It should be noted though that AI doesn't use autoattack and most likely 
> never will.
> 
> > > Do you suggest it replaces both H_MAP and H_FOG here, or just H_FOG?
> > 
> > I haven't looked at the code in question yet, but I think so, yes.
> 
> Yes, I also think both.

Attached is a patch with these changes made.

> > > > H_HUTS can be subsumed under PP_AI_FAKE_FOG.
> > >
> > > Assume you mean H_TARGETS...
> > 
> > I mean both. H_HUTS is just another kind of fake fog of war that the AI
> > uses, and I don't see how it is really different from H_TARGETS.
> 
> Yes, HUTS must and will die, in the new autoexplorer patch.

Yes, apologies, I confused it with H_LIMITEDHUTS.

--- freeciv-cvs/server/autoattack.c     2003-07-17 19:56:51.000000000 +0100
+++ freeciv-patched/server/autoattack.c 2003-07-31 02:30:36.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,43 @@
     }
 
     /*
+     * 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 may attack units it cannot see unless it has
+     * H_TARGETS handicap, but currently AI never uses auto-attack.
+     */
+    if ((ai_handicap(pplayer, H_TARGETS)
+         && !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;
+    }
+
+    /*
+     * 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]