diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/control.c freeciv/client/control.c --- FreecivCVS/client/control.c Wed Mar 15 15:15:54 2000 +++ freeciv/client/control.c Wed Mar 15 16:14:54 2000 @@ -50,6 +50,12 @@ /* set high if the player has selected connect */ int connect_state; +/* units involved in current combat */ +static struct unit *punit_attacking; +static struct unit *punit_defending; + +/*************************************************************************/ + static struct unit *find_best_focus_candidate(void); /************************************************************************** @@ -103,9 +109,6 @@ } } - - - /************************************************************************** If there is no unit currently in focus, or if the current unit in focus should not be in focus, then get a new focus unit. @@ -123,7 +126,6 @@ } } - /************************************************************************** ... **************************************************************************/ @@ -211,6 +213,58 @@ } unit_list_iterate_end; return best_candidate; +} + +/************************************************************************** +Return a pointer to a visible unit, if there is one. +**************************************************************************/ +struct unit *find_visible_unit(struct tile *ptile) +{ + if(unit_list_size(&ptile->units)==0) return NULL; + + /* If a unit is attacking we should show that on top */ + if (punit_attacking && map_get_tile(punit_attacking->x,punit_attacking->y) == ptile) { + unit_list_iterate(ptile->units, punit) + if(punit == punit_attacking) return punit; + unit_list_iterate_end; + } + + /* If a unit is defending we should show that on top */ + if (punit_defending && map_get_tile(punit_defending->x,punit_defending->y) == ptile) { + unit_list_iterate(ptile->units, punit) + if(punit == punit_defending) return punit; + unit_list_iterate_end; + } + + /* If the unit in focus is at this tile, show that on top */ + if (punit_focus && map_get_tile(punit_focus->x,punit_focus->y) == ptile) { + unit_list_iterate(ptile->units, punit) + if(punit == punit_focus) return punit; + unit_list_iterate_end; + } + + /* If there is a transporter in the stack we will show that on top */ + unit_list_iterate(ptile->units, punit) + if (get_transporter_capacity(punit) && + player_can_see_unit(game.player_ptr, punit)) + return punit; + unit_list_iterate_end; + + /* Else just return the first unit we can see */ + unit_list_iterate(ptile->units, punit) + if(player_can_see_unit(game.player_ptr, punit)) return punit; + unit_list_iterate_end; + + return NULL; +} + +/************************************************************************** +... +**************************************************************************/ +void set_units_in_combat(struct unit *pattacker, struct unit *pdefender) +{ + punit_attacking = pattacker; + punit_defending = pdefender; } /************************************************************************** diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/control.h freeciv/client/control.h --- FreecivCVS/client/control.h Wed Mar 15 12:58:36 2000 +++ freeciv/client/control.h Wed Mar 15 16:14:54 2000 @@ -53,6 +53,8 @@ void set_unit_focus(struct unit *punit); void set_unit_focus_no_center(struct unit *punit); void update_unit_focus(void); +struct unit *find_visible_unit(struct tile *ptile); +void set_units_in_combat(struct unit *pattacker, struct unit *pdefender); void key_cancel_action(void); void key_end_turn(void); diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/gui-gtk/mapctrl.c freeciv/client/gui-gtk/mapctrl.c --- FreecivCVS/client/gui-gtk/mapctrl.c Wed Mar 15 15:15:54 2000 +++ freeciv/client/gui-gtk/mapctrl.c Wed Mar 15 16:14:54 2000 @@ -159,7 +159,7 @@ count++; } - if((punit=player_find_visible_unit(game.player_ptr, ptile)) && !pcity) { + if((punit=find_visible_unit(ptile)) && !pcity) { char cn[64]; struct unit_type *ptype=get_unit_type(punit->type); cn[0]='\0'; diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/gui-gtk/mapview.c freeciv/client/gui-gtk/mapview.c --- FreecivCVS/client/gui-gtk/mapview.c Wed Mar 15 12:18:50 2000 +++ freeciv/client/gui-gtk/mapview.c Wed Mar 15 16:33:43 2000 @@ -156,18 +156,19 @@ struct unit *losing_unit = (hp0 == 0 ? punit0 : punit1); int i; - set_unit_focus_no_center(punit0); - set_unit_focus_no_center(punit1); - if (!do_combat_animation) { punit0->hp = hp0; punit1->hp = hp1; + + set_units_in_combat(NULL, NULL); refresh_tile_mapcanvas(punit0->x, punit0->y, 1); refresh_tile_mapcanvas(punit1->x, punit1->y, 1); return; } + set_units_in_combat(punit0, punit1); + do { anim_timer = renew_timer_start(anim_timer, TIMER_USER, TIMER_ACTIVE); @@ -206,6 +207,7 @@ usleep_since_timer_start(anim_timer, 20000); } + set_units_in_combat(NULL, NULL); refresh_tile_mapcanvas(punit0->x, punit0->y, 1); refresh_tile_mapcanvas(punit1->x, punit1->y, 1); } @@ -695,7 +697,7 @@ if(!ptile->known) gdk_gc_set_foreground (fill_bg_gc, colors_standard[COLOR_STD_BLACK]); - else if((punit=player_find_visible_unit(game.player_ptr, ptile))) { + else if ((punit=find_visible_unit(ptile))) { if(punit->owner==game.player_idx) gdk_gc_set_foreground (fill_bg_gc, colors_standard[COLOR_STD_YELLOW]); else @@ -1230,7 +1232,7 @@ struct tile *ptile; struct unit *punit; ptile=map_get_tile(abs_x0, abs_y0); - if((punit=player_find_visible_unit(game.player_ptr, ptile))) + if ((punit=find_visible_unit(ptile))) pplayer = &game.players[punit->owner]; } else diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/gui-mui/mapclass.c freeciv/client/gui-mui/mapclass.c --- FreecivCVS/client/gui-mui/mapclass.c Wed Mar 15 09:04:25 2000 +++ freeciv/client/gui-mui/mapclass.c Wed Mar 15 16:21:37 2000 @@ -563,7 +563,7 @@ struct tile *ptile; struct unit *punit; ptile = map_get_tile(abs_x0, abs_y0); - if ((punit = player_find_visible_unit(game.player_ptr, ptile))) + if ((punit = find_visible_unit(ptile))) pplayer = &game.players[punit->owner]; } @@ -708,7 +708,7 @@ DoMethod(group, OM_ADDMEMBER, text_obj); } - if ((punit = player_find_visible_unit(game.player_ptr, ptile)) && !pcity) + if ((punit = find_visible_unit(ptile)) && !pcity) { char cn[64]; struct unit_type *ptype = get_unit_type(punit->type); @@ -1741,7 +1741,7 @@ static char title[256]; pcity = map_get_city(x, y); - punit = player_find_visible_unit(game.player_ptr, ptile); + punit = find_visible_unit(ptile); focus = get_unit_in_focus(); if (pcity) diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/gui-mui/overviewclass.c freeciv/client/gui-mui/overviewclass.c --- FreecivCVS/client/gui-mui/overviewclass.c Wed Nov 17 13:50:04 1999 +++ freeciv/client/gui-mui/overviewclass.c Wed Mar 15 16:22:07 2000 @@ -124,7 +124,7 @@ } else { - if ((punit = player_find_visible_unit(game.player_ptr, ptile))) + if ((punit = find_visible_unit(ptile))) { if (punit->owner == game.player_idx) { diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/gui-xaw/mapctrl.c freeciv/client/gui-xaw/mapctrl.c --- FreecivCVS/client/gui-xaw/mapctrl.c Wed Mar 15 15:15:54 2000 +++ freeciv/client/gui-xaw/mapctrl.c Wed Mar 15 16:14:54 2000 @@ -149,7 +149,7 @@ XtCreateManagedWidget(s, smeBSBObjectClass, p, NULL, 0); } - if((punit=player_find_visible_unit(game.player_ptr, ptile)) && !pcity) { + if((punit=find_visible_unit(ptile)) && !pcity) { char cn[64]; struct unit_type *ptype=get_unit_type(punit->type); cn[0]='\0'; diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/gui-xaw/mapview.c freeciv/client/gui-xaw/mapview.c --- FreecivCVS/client/gui-xaw/mapview.c Wed Mar 15 12:28:19 2000 +++ freeciv/client/gui-xaw/mapview.c Wed Mar 15 16:30:03 2000 @@ -130,18 +130,19 @@ struct unit *losing_unit = (hp0 == 0 ? punit0 : punit1); int i; - set_unit_focus_no_center(punit0); - set_unit_focus_no_center(punit1); - if (!do_combat_animation) { punit0->hp = hp0; punit1->hp = hp1; + + set_units_in_combat(NULL, NULL); refresh_tile_mapcanvas(punit0->x, punit0->y, 1); refresh_tile_mapcanvas(punit1->x, punit1->y, 1); return; } + set_units_in_combat(punit0, punit1); + do { anim_timer = renew_timer_start(anim_timer, TIMER_USER, TIMER_ACTIVE); @@ -179,6 +180,7 @@ usleep_since_timer_start(anim_timer, 20000); } + set_units_in_combat(NULL, NULL); refresh_tile_mapcanvas(punit0->x, punit0->y, 1); refresh_tile_mapcanvas(punit1->x, punit1->y, 1); } @@ -667,7 +669,7 @@ if(!ptile->known) XSetForeground(display, fill_bg_gc, colors_standard[COLOR_STD_BLACK]); - else if((punit=player_find_visible_unit(game.player_ptr, ptile))) { + else if ((punit=find_visible_unit(ptile))) { if(punit->owner==game.player_idx) XSetForeground(display, fill_bg_gc, colors_standard[COLOR_STD_YELLOW]); else @@ -1164,7 +1166,7 @@ struct tile *ptile; struct unit *punit; ptile=map_get_tile(abs_x0, abs_y0); - if((punit=player_find_visible_unit(game.player_ptr, ptile))) + if ((punit=find_visible_unit(ptile))) pplayer = &game.players[punit->owner]; } else diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/packhand.c freeciv/client/packhand.c --- FreecivCVS/client/packhand.c Sun Mar 12 23:32:57 2000 +++ freeciv/client/packhand.c Wed Mar 15 16:14:54 2000 @@ -128,12 +128,8 @@ if(punit0 && tile_visible_mapcanvas(punit0->x, punit0->y) && punit1 && tile_visible_mapcanvas(punit1->x, punit1->y)) { - struct unit *pfocus; - pfocus=get_unit_in_focus(); - decrease_unit_hp_smooth(punit0, packet->attacker_hp, punit1, packet->defender_hp); - set_unit_focus(pfocus); } } diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/tilespec.c freeciv/client/tilespec.c --- FreecivCVS/client/tilespec.c Wed Mar 15 09:04:24 2000 +++ freeciv/client/tilespec.c Wed Mar 15 16:14:54 2000 @@ -938,7 +938,7 @@ return sprs - save_sprs; } - if((punit=player_find_visible_unit(game.player_ptr, ptile))) { + if ((punit=find_visible_unit(ptile))) { if(!citymode || punit->owner!=game.player_idx) { sprs += fill_unit_sprite_array(sprs,punit); if(unit_list_size(&ptile->units)>1) @@ -1156,7 +1156,7 @@ sprs+=fill_city_sprite_array(sprs,pcity); } - if((punit=player_find_visible_unit(game.player_ptr, ptile))) { + if ((punit=find_visible_unit(ptile))) { if(pcity && punit!=get_unit_in_focus()) return sprs - save_sprs; if(!citymode || punit->owner!=game.player_idx) { sprs+=fill_unit_sprite_array(sprs,punit); diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/common/player.c freeciv/common/player.c --- FreecivCVS/common/player.c Wed Feb 2 12:06:18 2000 +++ freeciv/common/player.c Wed Mar 15 16:14:54 2000 @@ -180,20 +180,6 @@ } /*************************************************************** - Return a pointer to a visible unit, if there is one. -***************************************************************/ -struct unit *player_find_visible_unit(struct player *pplayer, struct tile *ptile) -{ - if(unit_list_size(&ptile->units)==0) return NULL; - - unit_list_iterate(ptile->units, punit) - if(player_can_see_unit(pplayer, punit)) return punit; - unit_list_iterate_end; - - return NULL; -} - -/*************************************************************** If the specified player owns the city with the specified id, return pointer to the city struct. Else return 0. In the server we want to use find_city_by_id, which is fast due diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/common/player.h freeciv/common/player.h --- FreecivCVS/common/player.h Wed Feb 2 12:06:18 2000 +++ freeciv/common/player.h Wed Mar 15 16:14:54 2000 @@ -157,7 +157,6 @@ int player_has_embassy(struct player *pplayer, struct player *pplayer2); int player_can_see_unit(struct player *pplayer, struct unit *punit); -struct unit *player_find_visible_unit(struct player *pplayer, struct tile *); int player_owns_city(struct player *pplayer, struct city *pcity); struct city *player_find_city_by_id(struct player *pplayer, int city_id);