Index: ai/aiunit.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v retrieving revision 1.195 diff -u -r1.195 aiunit.c --- ai/aiunit.c 2002/04/04 03:51:03 1.195 +++ ai/aiunit.c 2002/04/04 15:39:04 @@ -1245,8 +1245,9 @@ punit->goto_dest_x = bx; punit->goto_dest_y = by; set_unit_activity(punit, ACTIVITY_GOTO); - do_unit_goto(punit, GOTO_MOVE_ANY, FALSE); - if (!player_find_unit_by_id(pplayer, id)) return(-1); /* died */ + if (do_unit_goto(punit, GOTO_MOVE_ANY, FALSE) == GR_DIED) { + return -1; /* died */ + } } ptile = map_get_tile(punit->x, punit->y); ferryboat = unit_list_find(&ptile->units, punit->ai.ferryboat); @@ -1275,8 +1276,9 @@ if (def) set_unit_activity(def, ACTIVITY_SENTRY); } unit_list_iterate_end; /* passengers are safely stowed away */ - do_unit_goto(ferryboat, GOTO_MOVE_ANY, FALSE); - if (!player_find_unit_by_id(pplayer, boatid)) return(-1); /* died */ + if (do_unit_goto(ferryboat, GOTO_MOVE_ANY, FALSE) == GR_DIED) { + return -1; /* died */ + } set_unit_activity(punit, ACTIVITY_IDLE); } /* else wait, we can GOTO later. */ } @@ -1321,7 +1323,9 @@ punit->x, punit->y, dest_x, dest_y); } set_unit_activity(punit, ACTIVITY_GOTO); - do_unit_goto(punit, GOTO_MOVE_ANY, FALSE); + if (do_unit_goto(punit, GOTO_MOVE_ANY, FALSE) == GR_DIED) { + return -1; /* died */ + } /* liable to bump into someone that will kill us. Should avoid? */ } else { freelog(LOG_DEBUG, "%s#%d@(%d,%d) not moving -> (%d, %d)", @@ -1329,12 +1333,16 @@ punit->x, punit->y, dest_x, dest_y); } } - if (player_find_unit_by_id(pplayer, id)) { /* didn't die */ - punit->ai.ai_role = AIUNIT_NONE; /* in case we need to change */ - if (x != punit->x || y != punit->y) return 1; /* moved */ - else return 0; /* didn't move, didn't die */ + + /* Dead unit shouldn't reach this point */ + assert(player_find_unit_by_id(pplayer, id)); + + punit->ai.ai_role = AIUNIT_NONE; /* in case we need to change */ + if (x != punit->x || y != punit->y) { + return 1; /* moved */ + } else { + return 0; /* didn't move, didn't die */ } - return(-1); /* died */ } /************************************************************************* @@ -1894,8 +1902,11 @@ if (same_pos(punit->x, punit->y, dest_x, dest_y)) { /* nothing to kill. Adjacency is something for us to kill later. */ if (is_sailing_unit(punit)) { - if (find_nearest_friendly_port(punit)) - do_unit_goto(punit, GOTO_MOVE_ANY, FALSE); + if (find_nearest_friendly_port(punit)) { + if (do_unit_goto(punit, GOTO_MOVE_ANY, FALSE) == GR_DIED) { + return; + } + } } else { ai_manage_explorer(punit); /* nothing else to do */ /* you can still have some moves left here, but barbarians should @@ -2025,7 +2036,6 @@ It is well constructed of teak, and looks seaworthy. */ struct city *pcity; struct unit *bodyguard; - int id = punit->id; int best = 4 * unit_type(punit)->move_rate, x = punit->x, y = punit->y; int n = 0, p = 0; @@ -2058,9 +2068,10 @@ do_unit_goto(punit, GOTO_MOVE_ANY, FALSE); else if (n == 0 && !map_get_city(punit->x, punit->y)) { /* rest in a city, for unhap */ x = punit->goto_dest_x; y = punit->goto_dest_y; - if (find_nearest_friendly_port(punit)) - do_unit_goto(punit, GOTO_MOVE_ANY, FALSE); - if (!player_find_unit_by_id(pplayer, id)) return; /* oops! */ + if (find_nearest_friendly_port(punit) + && do_unit_goto(punit, GOTO_MOVE_ANY, FALSE) == GR_DIED) { + return; /* oops! */ + } punit->goto_dest_x = x; punit->goto_dest_y = y; send_unit_info(pplayer, punit); /* to get the crosshairs right -- Syela */ } else { @@ -2111,9 +2122,9 @@ punit->goto_dest_x = x; punit->goto_dest_y = y; set_unit_activity(punit, ACTIVITY_GOTO); - do_unit_goto(punit, GOTO_MOVE_ANY, FALSE); - if ((punit = player_find_unit_by_id(pplayer, id))) + if (do_unit_goto(punit, GOTO_MOVE_ANY, FALSE) != GR_DIED) { set_unit_activity(punit, ACTIVITY_IDLE); + } return; } Index: server/unittools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v retrieving revision 1.172 diff -u -r1.172 unittools.c --- server/unittools.c 2002/04/04 03:51:06 1.172 +++ server/unittools.c 2002/04/04 15:39:07 @@ -788,9 +788,10 @@ if (punit->connecting && !can_unit_do_activity(punit, activity)) { punit->activity_count = 0; - do_unit_goto(punit, get_activity_move_restriction(activity), FALSE); - if (!player_find_unit_by_id(pplayer, id)) + if (do_unit_goto(punit, get_activity_move_restriction(activity), FALSE) + == GR_DIED) { return; + } } /* if connecting, automagically build prerequisities first */ @@ -962,16 +963,18 @@ send_tile_info(NULL, punit->x, punit->y); unit_list_iterate (map_get_tile(punit->x, punit->y)->units, punit2) { if (punit2->activity == activity) { - int id2 = punit2->id; + bool alive = TRUE; if (punit2->connecting) { punit2->activity_count = 0; - do_unit_goto(punit2, get_activity_move_restriction(activity), FALSE); - } - else { + alive = (do_unit_goto(punit2, + get_activity_move_restriction(activity), + FALSE) != GR_DIED); + } else { set_unit_activity(punit2, ACTIVITY_IDLE); } - if (find_unit_by_id(id2)) + if (alive) { send_unit_info(NULL, punit2); + } } } unit_list_iterate_end; } @@ -993,9 +996,9 @@ } if (punit->activity == ACTIVITY_PATROL) { - goto_route_execute(punit); - if (!player_find_unit_by_id(pplayer, id)) + if (goto_route_execute(punit) == GR_DIED) { return; + } } send_unit_info(NULL, punit);