Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11583) autoattack causes assert
Home

[Freeciv-Dev] (PR#11583) autoattack causes assert

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11583) autoattack causes assert
From: "Mike Kaufman" <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 17 Dec 2004 14:51:14 -0800
Reply-to: bugs@xxxxxxxxxxx

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

this is typical:

#0  0xb7e4c7b1 in kill () from /lib/libc.so.6
#1  0xb7e4c3f5 in raise () from /lib/libc.so.6
#2  0xb7e4da58 in abort () from /lib/libc.so.6
#3  0xb7e45cb9 in __assert_fail () from /lib/libc.so.6
#4  0x0813102b in ai_unit_attack (punit=0x850a4f0, ptile=0x859211c)
    at aitools.c:481
#5  0x0813644d in ai_military_attack (pplayer=0xa, punit=0x0) at
aiunit.c:1879
#6  0x08136e70 in ai_manage_military (pplayer=0x82166f8, punit=0x850a4f0)
    at aiunit.c:2074
#7  0x08137694 in ai_choose_role_unit (pplayer=0x0, pcity=0x0, choice=0x0, 
    role=0, want=0) at aiunit.c:2255
#8  0x0812ae90 in ai_do_first_activities (pplayer=0x82166f8) at
aihand.c:379
#9  0x080500f9 in ai_start_turn () at srv_main.c:464


#4  0x0813102b in ai_unit_attack (punit=0x850a4f0, ptile=0x859211c)
    at aitools.c:481
481       assert(is_tiles_adjacent(punit->tile, ptile));

The cause is autoattack. A unit X intends to attack unit Y. When the unit
gets adjacent, Y autoattacks and dies. If X has move points left, it can
move straight on to the tile where Y was. After that ai_unit_attack is
called leading to the assert since ai_unit_attack() expects adjacency.

The attached patch fixes this.

-mike

Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.340
diff -u -r1.340 aiunit.c
--- ai/aiunit.c 30 Nov 2004 08:37:02 -0000      1.340
+++ ai/aiunit.c 17 Dec 2004 22:46:33 -0000
@@ -1803,7 +1803,14 @@
         if (punit->moves_left <= 0) {
           return;
         }
-        /* Must be adjacent now. */
+        /* Either we're adjacent or we sitting on the tile. We might be
+         * sitting on the tile if the enemy that _was_ sitting there 
+         * attacked us and died _and_ we had enough movement to get there */
+        if (same_pos(punit->tile, dest_tile)) {
+          UNIT_LOG(LOG_DEBUG, punit, "mil att made it -> (%d,%d)",
+                 dest_tile->x, dest_tile->y);
+          break;
+        }
       }
       
       /* Close combat. fstk sometimes want us to attack an adjacent

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11583) autoattack causes assert, Mike Kaufman <=