Index: common/unit.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v retrieving revision 1.68 diff -u -r1.68 unit.h --- common/unit.h 2001/05/18 13:34:25 1.68 +++ common/unit.h 2001/07/08 15:16:01 @@ -116,6 +116,23 @@ #define MOVE_COST_RAIL 0 #define MOVE_COST_ROAD 1 +#define unit_list_iterate_safe(unitlist, punit) \ +{ \ + int _size = unit_list_size(&unitlist); \ + int *_ids = fc_malloc(sizeof(int) * _size); \ + int _i = 0; \ + unit_list_iterate(unitlist, punit) { \ + _ids[_i++] = punit->id; \ + } unit_list_iterate_end; \ + for (_i=0; _i<_size; _i++) { \ + struct unit *punit = find_unit_by_id(_ids[_i]); \ + if (punit) { \ + +#define unit_list_iterate_safe_end \ + } \ + } \ + free(_ids); \ +} struct unit *unit_list_find(struct unit_list *This, int id); Index: server/unittools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v retrieving revision 1.122 diff -u -r1.122 unittools.c --- server/unittools.c 2001/07/04 11:24:24 1.122 +++ server/unittools.c 2001/07/08 15:16:03 @@ -56,8 +56,7 @@ static void unit_restore_hitpoints(struct player *pplayer, struct unit *punit); static void unit_restore_movepoints(struct player *pplayer, struct unit *punit); -static void update_unit_activity(struct player *pplayer, struct unit *punit, - struct genlist_iterator *iter); +static void update_unit_activity(struct unit *punit); static void wakeup_neighbor_sentries(struct unit *punit); static int upgrade_would_strand(struct unit *punit, int upgrade_type); static void handle_leonardo(struct player *pplayer); @@ -748,9 +747,9 @@ **************************************************************************/ void update_unit_activities(struct player *pplayer) { - unit_list_iterate(pplayer->units, punit) - update_unit_activity(pplayer, punit, &myiter); - unit_list_iterate_end; + unit_list_iterate_safe(pplayer->units, punit) + update_unit_activity(punit); + unit_list_iterate_safe_end; } /************************************************************************** @@ -928,9 +927,9 @@ also move units that is on a goto. restore unit move points (information needed for settler tasks) **************************************************************************/ -static void update_unit_activity(struct player *pplayer, struct unit *punit, - struct genlist_iterator *iter) +static void update_unit_activity(struct unit *punit) { + struct player *pplayer = unit_owner(punit); int id = punit->id; int mr = get_unit_type (punit->type)->move_rate; int unit_activity_done = 0; @@ -949,6 +948,8 @@ if (punit->connecting && !can_unit_do_activity(punit, activity)) { punit->activity_count = 0; do_unit_goto(punit, get_activity_move_restriction(activity), 0); + if (!player_find_unit_by_id(pplayer, id)) + return; } /* if connecting, automagically build prerequisities first */ @@ -987,10 +988,10 @@ if ((punit2->activity == ACTIVITY_PILLAGE) && (punit2->activity_target == what_pillaged)) { set_unit_activity(punit2, ACTIVITY_IDLE); - send_unit_info(0, punit2); + send_unit_info(NULL, punit2); } unit_list_iterate_end; - send_tile_info(0, punit->x, punit->y); + send_tile_info(NULL, punit->x, punit->y); } } @@ -1069,9 +1070,10 @@ } if (unit_activity_done) { - send_tile_info(0, punit->x, punit->y); - unit_list_iterate (map_get_tile(punit->x, punit->y)->units, punit2) + 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; if (punit2->connecting) { punit2->activity_count = 0; do_unit_goto(punit2, get_activity_move_restriction(activity), 0); @@ -1079,9 +1081,10 @@ else { set_unit_activity(punit2, ACTIVITY_IDLE); } - send_unit_info(0, punit2); + if (find_unit_by_id(id2)) + send_unit_info(NULL, punit2); } - unit_list_iterate_end; + } unit_list_iterate_end; } if (activity==ACTIVITY_FORTIFYING) { @@ -1100,10 +1103,13 @@ return; } - if (punit->activity == ACTIVITY_PATROL) + if (punit->activity == ACTIVITY_PATROL) { goto_route_execute(punit); + if (!player_find_unit_by_id(pplayer, id)) + return; + } - send_unit_info(0, punit); + send_unit_info(NULL, punit); unit_list_iterate(ptile->units, punit2) { if (!can_unit_continue_current_activity(punit2)) @@ -1185,8 +1191,6 @@ _("Game: Disbanded your %s due to changing" " land to sea at (%d, %d)."), unit_name(punit2->type), punit2->x, punit2->y); - if (iter && ((struct unit*)ITERATOR_PTR((*iter))) == punit2) - ITERATOR_NEXT((*iter)); wipe_unit_spec_safe(punit2, NULL, 0); goto START; } @@ -1246,8 +1250,6 @@ _("Game: Disbanded your %s due to changing" " sea to land at (%d, %d)."), unit_name(punit2->type), punit2->x, punit2->y); - if (iter && ((struct unit*)ITERATOR_PTR((*iter))) == punit2) - ITERATOR_NEXT((*iter)); wipe_unit_spec_safe(punit2, NULL, 0); goto START; }