diff -ur freeciv/client/control.c show_transporter_on_top2/client/control.c --- freeciv/client/control.c Mon Mar 13 14:08:08 2000 +++ show_transporter_on_top2/client/control.c Tue Mar 14 15:40:57 2000 @@ -103,9 +103,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 +120,6 @@ } } - /************************************************************************** ... **************************************************************************/ @@ -206,6 +202,36 @@ 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 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; +} + /************************************************************************** ... diff -ur freeciv/client/control.h show_transporter_on_top2/client/control.h --- freeciv/client/control.h Mon Mar 13 14:07:22 2000 +++ show_transporter_on_top2/client/control.h Tue Mar 14 15:22:38 2000 @@ -51,6 +51,7 @@ 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 key_cancel_action(void); void key_end_turn(void); diff -ur freeciv/client/gui-gtk/mapctrl.c show_transporter_on_top2/client/gui-gtk/mapctrl.c --- freeciv/client/gui-gtk/mapctrl.c Mon Mar 13 14:08:08 2000 +++ show_transporter_on_top2/client/gui-gtk/mapctrl.c Tue Mar 14 15:22:38 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 -ur freeciv/client/gui-gtk/mapview.c show_transporter_on_top2/client/gui-gtk/mapview.c --- freeciv/client/gui-gtk/mapview.c Mon Mar 13 14:08:08 2000 +++ show_transporter_on_top2/client/gui-gtk/mapview.c Tue Mar 14 15:26:29 2000 @@ -674,7 +674,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 @@ -1209,7 +1209,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 -ur freeciv/client/gui-mui/mapclass.c show_transporter_on_top2/client/gui-mui/mapclass.c --- freeciv/client/gui-mui/mapclass.c Mon Mar 13 14:08:08 2000 +++ show_transporter_on_top2/client/gui-mui/mapclass.c Tue Mar 14 15:27:38 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 -ur freeciv/client/gui-mui/overviewclass.c show_transporter_on_top2/client/gui-mui/overviewclass.c --- freeciv/client/gui-mui/overviewclass.c Mon Mar 13 14:07:23 2000 +++ show_transporter_on_top2/client/gui-mui/overviewclass.c Tue Mar 14 15:27:55 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 -ur freeciv/client/gui-xaw/mapctrl.c show_transporter_on_top2/client/gui-xaw/mapctrl.c --- freeciv/client/gui-xaw/mapctrl.c Mon Mar 13 14:08:08 2000 +++ show_transporter_on_top2/client/gui-xaw/mapctrl.c Tue Mar 14 15:22:38 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 -ur freeciv/client/gui-xaw/mapview.c show_transporter_on_top2/client/gui-xaw/mapview.c --- freeciv/client/gui-xaw/mapview.c Mon Mar 13 14:07:22 2000 +++ show_transporter_on_top2/client/gui-xaw/mapview.c Tue Mar 14 15:29:24 2000 @@ -647,7 +647,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 @@ -1135,7 +1135,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 -ur freeciv/client/tilespec.c show_transporter_on_top2/client/tilespec.c --- freeciv/client/tilespec.c Mon Mar 13 14:08:08 2000 +++ show_transporter_on_top2/client/tilespec.c Tue Mar 14 15:29:55 2000 @@ -934,7 +934,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) @@ -1152,7 +1152,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 -ur freeciv/common/player.c show_transporter_on_top2/common/player.c --- freeciv/common/player.c Mon Mar 13 14:07:24 2000 +++ show_transporter_on_top2/common/player.c Tue Mar 14 15:22:38 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 -ur freeciv/common/player.h show_transporter_on_top2/common/player.h --- freeciv/common/player.h Mon Mar 13 14:07:24 2000 +++ show_transporter_on_top2/common/player.h Tue Mar 14 15:22:38 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);