Complete.Org: Mailing Lists: Archives: freeciv-dev: July 1999:
[Freeciv-Dev] [PATCH] BUG: unit killed by barbarians wiped and still use
Home

[Freeciv-Dev] [PATCH] BUG: unit killed by barbarians wiped and still use

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] [PATCH] BUG: unit killed by barbarians wiped and still used
From: Markus Linnala <maage@xxxxxxxxx>
Date: 04 Jul 1999 02:54:23 +0300
Reply-to: Markus Linnala <maage@xxxxxxxxx>

If unit is killed by barbarians, you might get following core dump:

#0  handle_unit_move_request (pplayer=0x82125d8, punit=0x4092df90, dest_x=87, 
    dest_y=66) at /usr/src/freeciv/m/freeciv/server/unithand.c:924
924         punit->moved=1;
(gdb) print punit
$1 = (struct unit *) 0x4092df90
(gdb) print *punit
Cannot access memory at address 0x4092df90.
(gdb) where
#0  handle_unit_move_request (pplayer=0x82125d8, punit=0x4092df90, dest_x=87, 
    dest_y=66) at /usr/src/freeciv/m/freeciv/server/unithand.c:924
#1  0x8055d40 in do_unit_goto (pplayer=0x82125d8, punit=0x4092df90)
    at /usr/src/freeciv/m/freeciv/server/gotohand.c:753
#2  0x80687b9 in update_unit_activity (pplayer=0x82125d8, punit=0x4092df90)
    at /usr/src/freeciv/m/freeciv/server/unitfunc.c:1324
#3  0x80681b4 in update_unit_activities (pplayer=0x82125d8)
    at /usr/src/freeciv/m/freeciv/server/unitfunc.c:1162
#4  0x805bc02 in update_player_activities (pplayer=0x82125d8)
    at /usr/src/freeciv/m/freeciv/server/plrhand.c:545
#5  0x80505a9 in end_turn ()
    at /usr/src/freeciv/m/freeciv/server/civserver.c:751
#6  0x804fcb1 in main (argc=3, argv=0xbffff894)
    at /usr/src/freeciv/m/freeciv/server/civserver.c:474
#7  0x40041cb3 in __libc_start_main (main=0x804f170 <main>, argc=3, 
    argv=0xbffff894, init=0x8048f00 <_init>, fini=0x8086f4c <_fini>, 
    rtld_fini=0x4000a350 <_dl_fini>, stack_end=0xbffff88c)
    at ../sysdeps/generic/libc-start.c:78

1999-07-04  Markus Linnala  <maage@xxxxxxxxx>

        * server/unithand.c (handle_unit_enter_hut): return 0 if unit was
        killed
        (handle_unit_move_request): handle situation where unit is killed
        by barbarians

diff -u -u -r1.2 unithand.c
--- unithand.c  1999/07/03 12:25:56     1.2
+++ unithand.c  1999/07/03 23:50:57
@@ -602,12 +602,14 @@
 
 /**************************************************************************
 ...
+Return 1 if unit is alive, and 0 if it was killed
 **************************************************************************/
-void handle_unit_enter_hut(struct unit *punit)
+int handle_unit_enter_hut(struct unit *punit)
 {
   struct player *pplayer=&game.players[punit->owner];
+  int ok = 1;
   if (is_air_unit(punit))
-    return;
+    return ok;
   map_get_tile(punit->x, punit->y)->special^=S_HUT;
   
   send_tile_info(0, punit->x, punit->y, TILE_KNOWN);
@@ -685,6 +687,7 @@
       notify_player_ex(pplayer, punit->x, punit->y, E_NOEVENT,
                       "Game: Your unit has been cowardly slaughtered by a band 
of barbarians");
       wipe_unit(pplayer, punit);
+      ok = 0;
     }
     break;
   case 11:
@@ -702,6 +705,7 @@
     break;
   }
   send_player_info(pplayer, pplayer);
+  return ok;
 }
 
 
@@ -736,7 +740,7 @@
 int handle_unit_move_request(struct player *pplayer, struct unit *punit,
                              int dest_x, int dest_y)
 {
-  int unit_id, transport_units = 1;
+  int unit_id, transport_units = 1, ok;
   struct unit *pdefender, *ferryboat, *bodyguard, *passenger;
   struct unit_list cargolist;
   struct city *pcity;
@@ -895,14 +899,19 @@
     if(pcity)
       handle_unit_enter_city(pplayer, pcity);
 
-    if((map_get_tile(dest_x, dest_y)->special&S_HUT))
-      handle_unit_enter_hut(punit);
-
+    ok = 1;
+    if((map_get_tile(dest_x, dest_y)->special&S_HUT)) {
+      /* punit might get killed by horde of barbarians */
+      ok = handle_unit_enter_hut(punit);
+    }
+     
     wakeup_neighbor_sentries(pplayer,dest_x,dest_y);
     
     connection_do_unbuffer(pplayer->conn);
 
-/* bodyguard code */
+    if (!ok) return 1;
+    
+    /* bodyguard code */
     if(unit_list_find(&pplayer->units, unit_id)) {
       if (punit->ai.bodyguard > 0) {
         bodyguard = unit_list_find(&(map_get_tile(src_x, src_y)->units),

-- 
//Markus

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