Complete.Org: Mailing Lists: Archives: freeciv-ai: November 2004:
[freeciv-ai] Re: (PR#11009) AI Hunts Own Units
Home

[freeciv-ai] Re: (PR#11009) AI Hunts Own Units

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: badamson@xxxxxxxxxxxxx
Subject: [freeciv-ai] Re: (PR#11009) AI Hunts Own Units
From: "Benedict Adamson" <badamson@xxxxxxxxxxx>
Date: Tue, 16 Nov 2004 15:59:03 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=11009 >

Gregory Berkolaiko wrote:
...
> This patch is a band-aid.  The real problem is that is_player_dangerous
> seems to return TRUE on self (according to the bug report).  This
> shouldn't happen.  Please investigate why does it happen and fix it there.
...

Attached is a better fix, with comments indicating some of the related 
peculiarities.

diff -ru -Xfreeciv.PR11009/diff_ignore vendor.freeciv.beta/ai/advmilitary.c 
freeciv.PR11009/ai/advmilitary.c
--- vendor.freeciv.beta/ai/advmilitary.c        2004-11-05 22:58:49.000000000 
+0000
+++ freeciv.PR11009/ai/advmilitary.c    2004-11-17 00:01:27.000000000 +0000
@@ -465,6 +465,8 @@
     if (!is_player_dangerous(city_owner(pcity), aplayer)) {
       continue;
     }
+    /* Note that we still consider the units of players we are not (yet)
+     * at war with. */
 
     /* Look for enemy units */
     unit_list_iterate(aplayer->units, punit) {
@@ -472,6 +474,9 @@
       int move_rate = unit_move_rate(punit);
       unsigned int vulnerability = assess_danger_unit(pcity, punit);
       int dist = assess_distance(pcity, punit, move_rate);
+      /* Although enemy units will not be in our cities,
+       * we might stll consider allies to be dangerous,
+       * so dist can be 0. */
       bool igwall = unit_really_ignores_citywalls(punit);
 
       if (unit_flag(punit, F_PARATROOPERS)) {
diff -ru -Xfreeciv.PR11009/diff_ignore vendor.freeciv.beta/ai/aihunt.c 
freeciv.PR11009/ai/aihunt.c
--- vendor.freeciv.beta/ai/aihunt.c     2004-10-09 21:01:42.000000000 +0100
+++ freeciv.PR11009/ai/aihunt.c 2004-11-17 00:01:27.000000000 +0000
@@ -269,6 +269,7 @@
     if (!aplayer->is_alive || !is_player_dangerous(pplayer, aplayer)) {
       continue;
     }
+    /* Note that we need not (yet) be at war with aplayer */
     unit_list_iterate(aplayer->units, target) {
       struct tile *ptile = target->tile;
       int dist1, dist2, stackthreat = 0, stackcost = 0;
@@ -328,6 +329,8 @@
                unit_owner(defender)->name, unit_type(defender)->name, 
                defender->tile, defender->id, stackthreat, dist1, 
                dist2);
+      /* TO DO: probably ought to WAG down targets of players we are not (yet)
+       * at war with */
       /* Ok, now we FINALLY have a candidate */
       if (stackthreat > best_val) {
         best_val = stackthreat;
diff -ru -Xfreeciv.PR11009/diff_ignore vendor.freeciv.beta/ai/aitools.c 
freeciv.PR11009/ai/aitools.c
--- vendor.freeciv.beta/ai/aitools.c    2004-11-05 22:58:49.000000000 +0000
+++ freeciv.PR11009/ai/aitools.c        2004-11-17 00:01:27.000000000 +0000
@@ -88,11 +88,12 @@
   struct ai_dip_intel *adip 
     = &ai->diplomacy.player_intel[aplayer->player_no];
 
-  return (pplayers_at_war(pplayer, aplayer)
-          || ai->diplomacy.target == aplayer
-          || pplayer->diplstates[aplayer->player_no].has_reason_to_cancel != 0
-          || ai->diplomacy.acceptable_reputation > aplayer->reputation
-          || adip->is_allied_with_enemy);
+  return (pplayer != aplayer)
+         && ((pplayers_at_war(pplayer, aplayer)
+           || ai->diplomacy.target == aplayer
+           || pplayer->diplstates[aplayer->player_no].has_reason_to_cancel != 0
+           || ai->diplomacy.acceptable_reputation > aplayer->reputation
+           || adip->is_allied_with_enemy));
 }
 
 /*************************************************************************
diff -ru -Xfreeciv.PR11009/diff_ignore vendor.freeciv.beta/diff_ignore 
freeciv.PR11009/diff_ignore
--- vendor.freeciv.beta/diff_ignore     2004-10-22 22:48:23.000000000 +0100
+++ freeciv.PR11009/diff_ignore 2004-11-17 00:01:27.000000000 +0000
@@ -17,6 +17,7 @@
 *~
 .#*
 .deps
+.svn
 CVS
 Freeciv.h
 Makefile

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