Index: client/climisc.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v retrieving revision 1.103 diff -u -r1.103 climisc.c --- client/climisc.c 2002/09/11 17:04:39 1.103 +++ client/climisc.c 2002/09/13 14:24:11 @@ -212,57 +212,50 @@ /************************************************************************** ... **************************************************************************/ -void client_remove_unit(int unit_id) +void client_remove_unit(struct unit *punit) { - struct unit *punit; struct city *pcity; + int x = punit->x; + int y = punit->y; + int hc = punit->homecity; + struct unit *ufocus = get_unit_in_focus(); - freelog(LOG_DEBUG, "client_remove_unit %d", unit_id); - - if((punit=find_unit_by_id(unit_id))) { - int x=punit->x; - int y=punit->y; - int hc=punit->homecity; - struct unit *ufocus = get_unit_in_focus(); - - freelog(LOG_DEBUG, "removing unit %d, %s %s (%d %d) hcity %d", - unit_id, get_nation_name(unit_owner(punit)->nation), - unit_name(punit->type), punit->x, punit->y, hc); - - if(punit==ufocus) { - set_unit_focus_no_center(NULL); - game_remove_unit(punit); - punit = ufocus = NULL; - advance_unit_focus(); - } - else { - /* calculate before punit disappears, use after punit removed: */ - bool update = (ufocus - && same_pos(ufocus->x, ufocus->y, punit->x, punit->y)); - - game_remove_unit(punit); - punit = NULL; - if (update) { - update_unit_pix_label(ufocus); - } - } + freelog(LOG_DEBUG, "removing unit %d, %s %s (%d %d) hcity %d", + punit->id, get_nation_name(unit_owner(punit)->nation), + unit_name(punit->type), punit->x, punit->y, hc); - pcity = map_get_city(x, y); - if (pcity) { - refresh_city_dialog(pcity); - freelog(LOG_DEBUG, "map city %s, %s, (%d %d)", pcity->name, - get_nation_name(city_owner(pcity)->nation), pcity->x, pcity->y); - } - - pcity = player_find_city_by_id(game.player_ptr, hc); - if (pcity) { - refresh_city_dialog(pcity); - freelog(LOG_DEBUG, "home city %s, %s, (%d %d)", pcity->name, - get_nation_name(city_owner(pcity)->nation), pcity->x, pcity->y); + if (punit == ufocus) { + set_unit_focus_no_center(NULL); + game_remove_unit(punit); + punit = ufocus = NULL; + advance_unit_focus(); + } else { + /* calculate before punit disappears, use after punit removed: */ + bool update = (ufocus + && same_pos(ufocus->x, ufocus->y, punit->x, punit->y)); + + game_remove_unit(punit); + punit = NULL; + if (update) { + update_unit_pix_label(ufocus); } - - refresh_tile_mapcanvas(x, y, TRUE); } + + pcity = map_get_city(x, y); + if (pcity) { + refresh_city_dialog(pcity); + freelog(LOG_DEBUG, "map city %s, %s, (%d %d)", pcity->name, + get_nation_name(city_owner(pcity)->nation), pcity->x, pcity->y); + } + + pcity = player_find_city_by_id(game.player_ptr, hc); + if (pcity) { + refresh_city_dialog(pcity); + freelog(LOG_DEBUG, "home city %s, %s, (%d %d)", pcity->name, + get_nation_name(city_owner(pcity)->nation), pcity->x, pcity->y); + } + + refresh_tile_mapcanvas(x, y, TRUE); } /************************************************************************** Index: client/climisc.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/climisc.h,v retrieving revision 1.37 diff -u -r1.37 climisc.h --- client/climisc.h 2002/07/27 14:29:09 1.37 +++ client/climisc.h 2002/09/13 14:24:11 @@ -26,7 +26,7 @@ void client_init_player(struct player *plr); void client_remove_player(int plrno); void client_remove_city(struct city *pcity); -void client_remove_unit(int unit_id); +void client_remove_unit(struct unit *punit); void climap_init_continents(void); void climap_update_continents(int x, int y); Index: client/packhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v retrieving revision 1.254 diff -u -r1.254 packhand.c --- client/packhand.c 2002/09/11 17:04:39 1.254 +++ client/packhand.c 2002/09/13 14:24:13 @@ -172,8 +172,14 @@ **************************************************************************/ void handle_remove_unit(struct packet_generic_integer *packet) { - agents_unit_remove(find_unit_by_id(packet->value)); - client_remove_unit(packet->value); + struct unit *punit = find_unit_by_id(packet->value); + + if (!punit) { + return; + } + + agents_unit_remove(punit); + client_remove_unit(punit); } /************************************************************************** @@ -902,7 +908,7 @@ } else { do_move_unit(punit, packet); /* nice to see where a unit is going */ - client_remove_unit(punit->id); + client_remove_unit(punit); refresh_tile_mapcanvas(packet->x, packet->y, TRUE); return; } @@ -968,7 +974,7 @@ dest_y = packet->y; /*fog of war*/ if (!(tile_get_known(punit->x,punit->y) == TILE_KNOWN)) { - client_remove_unit(packet->id); + client_remove_unit(punit); refresh_tile_mapcanvas(dest_x, dest_y, TRUE); } agents_unit_changed(punit); @@ -1523,7 +1529,7 @@ /* fog of war remove units */ if (ptile->known <= TILE_KNOWN_FOGGED && old_known == TILE_KNOWN) { unit_list_iterate(ptile->units, punit) { - client_remove_unit(punit->id); + client_remove_unit(punit); } unit_list_iterate_end; } Index: client/agents/agents.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/agents/agents.c,v retrieving revision 1.17 diff -u -r1.17 agents.c --- client/agents/agents.c 2002/09/10 14:01:07 1.17 +++ client/agents/agents.c 2002/09/13 14:24:13 @@ -41,7 +41,7 @@ struct my_agent *agent; enum oct { OCT_NEW_TURN, OCT_UNIT, OCT_CITY } type; enum callback_type cb_type; - void *arg; + int arg; }; #define SPECLIST_TAG call @@ -118,7 +118,7 @@ ***********************************************************************/ static void enqueue_call(struct my_agent *agent, enum oct type, - enum callback_type cb_type, void *arg) + enum callback_type cb_type, int arg) { struct call *pcall2; @@ -192,11 +192,9 @@ if (call->type == OCT_NEW_TURN) { call->agent->agent.turn_start_notify(); } else if (call->type == OCT_UNIT) { - call->agent->agent.unit_callbacks[call-> - cb_type] ((struct unit *) call->arg); + call->agent->agent.unit_callbacks[call->cb_type] (call->arg); } else if (call->type == OCT_CITY) { - call->agent->agent.city_callbacks[call-> - cb_type] ((struct city *) call->arg); + call->agent->agent.city_callbacks[call->cb_type] (call->arg); } else { assert(0); } @@ -414,7 +412,7 @@ continue; } if (agent->agent.turn_start_notify) { - enqueue_call(agent, OCT_NEW_TURN, CB_LAST, NULL); + enqueue_call(agent, OCT_NEW_TURN, CB_LAST, 0); } } /* @@ -447,7 +445,7 @@ continue; } if (agent->agent.unit_callbacks[CB_CHANGE]) { - enqueue_call(agent, OCT_UNIT, CB_CHANGE, punit); + enqueue_call(agent, OCT_UNIT, CB_CHANGE, punit->id); } } call_handle_methods(); @@ -473,7 +471,7 @@ continue; } if (agent->agent.unit_callbacks[CB_NEW]) { - enqueue_call(agent, OCT_UNIT, CB_NEW, punit); + enqueue_call(agent, OCT_UNIT, CB_NEW, punit->id); } } @@ -500,7 +498,7 @@ continue; } if (agent->agent.unit_callbacks[CB_REMOVE]) { - enqueue_call(agent, OCT_UNIT, CB_REMOVE, punit); + enqueue_call(agent, OCT_UNIT, CB_REMOVE, punit->id); } } @@ -525,7 +523,7 @@ continue; } if (agent->agent.city_callbacks[CB_CHANGE]) { - enqueue_call(agent, OCT_CITY, CB_CHANGE, pcity); + enqueue_call(agent, OCT_CITY, CB_CHANGE, pcity->id); } } call_handle_methods(); @@ -551,7 +549,7 @@ continue; } if (agent->agent.city_callbacks[CB_NEW]) { - enqueue_call(agent, OCT_CITY, CB_NEW, pcity); + enqueue_call(agent, OCT_CITY, CB_NEW, pcity->id); } } @@ -578,7 +576,7 @@ continue; } if (agent->agent.city_callbacks[CB_REMOVE]) { - enqueue_call(agent, OCT_CITY, CB_REMOVE, pcity); + enqueue_call(agent, OCT_CITY, CB_REMOVE, pcity->id); } } @@ -632,7 +630,7 @@ struct my_agent *agent = find_agent_by_name(name_of_calling_agent); assert(agent->agent.unit_callbacks[CB_CHANGE] != NULL); - enqueue_call(agent, OCT_UNIT, CB_CHANGE, punit); + enqueue_call(agent, OCT_UNIT, CB_CHANGE, punit->id); call_handle_methods(); } @@ -645,7 +643,7 @@ struct my_agent *agent = find_agent_by_name(name_of_calling_agent); assert(agent->agent.city_callbacks[CB_CHANGE] != NULL); - enqueue_call(agent, OCT_CITY, CB_CHANGE, pcity); + enqueue_call(agent, OCT_CITY, CB_CHANGE, pcity->id); call_handle_methods(); } Index: client/agents/agents.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/agents/agents.h,v retrieving revision 1.5 diff -u -r1.5 agents.h --- client/agents/agents.h 2002/09/10 14:01:07 1.5 +++ client/agents/agents.h 2002/09/13 14:24:13 @@ -36,8 +36,8 @@ int level; void (*turn_start_notify) (void); - void (*city_callbacks[CB_LAST]) (struct city *); - void (*unit_callbacks[CB_LAST]) (struct unit *); + void (*city_callbacks[CB_LAST]) (int); + void (*unit_callbacks[CB_LAST]) (int); }; void agents_init(void); Index: client/agents/cma_core.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.c,v retrieving revision 1.29 diff -u -r1.29 cma_core.c --- client/agents/cma_core.c 2002/09/06 19:07:34 1.29 +++ client/agents/cma_core.c 2002/09/13 14:24:14 @@ -1041,6 +1041,13 @@ #endif } +/**************************************************************************** +... +*****************************************************************************/ +static void release_city(int city_id) +{ + attr_city_set(ATTR_CITY_CMA_PARAMETER, city_id, 0, NULL); +} /**************************************************************************** algorithmic functions @@ -1802,18 +1809,22 @@ /**************************************************************************** Callback for the agent interface. *****************************************************************************/ -static void city_changed(struct city *pcity) +static void city_changed(int city_id) { - clear_caches(pcity); - handle_city(pcity); + struct city *pcity = find_city_by_id(city_id); + + if (pcity) { + clear_caches(pcity); + handle_city(pcity); + } } /**************************************************************************** Callback for the agent interface. *****************************************************************************/ -static void city_remove(struct city *pcity) +static void city_remove(int city_id) { - cma_release_city(pcity); + release_city(city_id); } /**************************************************************************** @@ -1920,7 +1931,7 @@ *****************************************************************************/ void cma_release_city(struct city *pcity) { - attr_city_set(ATTR_CITY_CMA_PARAMETER, pcity->id, 0, NULL); + release_city(pcity->id); } /**************************************************************************** Index: client/agents/cma_fec.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_fec.c,v retrieving revision 1.9 diff -u -r1.9 cma_fec.c --- client/agents/cma_fec.c 2002/06/13 22:43:21 1.9 +++ client/agents/cma_fec.c 2002/09/13 14:24:14 @@ -61,9 +61,9 @@ Is called if the game removes a city. It will clear the "fe parameter" attribute to reduce the size of the savegame. *****************************************************************************/ -static void city_remove(struct city *pcity) +static void city_remove(int city_id) { - attr_city_set(ATTR_CITY_CMAFE_PARAMETER, pcity->id, 0, NULL); + attr_city_set(ATTR_CITY_CMAFE_PARAMETER, city_id, 0, NULL); } /**************************************************************************