diff -ur freeciv/client/control.c show_transporter_on_top/client/control.c --- freeciv/client/control.c Mon Mar 13 14:08:08 2000 +++ show_transporter_on_top/client/control.c Mon Mar 13 15:51:48 2000 @@ -1109,3 +1109,31 @@ if(get_unit_in_focus()) request_unit_wakeup(punit_focus); } + +/*************************************************************** + Return a pointer to a visible unit, if there is one. +***************************************************************/ +struct unit *player_find_visible_unit(struct tile *ptile) +{ + if(unit_list_size(&ptile->units)==0) return NULL; + + /* If the unit in focus is at this tile it is always the topmost of the players units */ + if (punit_focus && map_get_tile(punit_focus->x,punit_focus->y) == ptile) { + unit_list_iterate(ptile->units, punit) + if(punit->owner == game.player_ptr->player_no) 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_top/client/control.h --- freeciv/client/control.h Mon Mar 13 14:07:22 2000 +++ show_transporter_on_top/client/control.h Mon Mar 13 16:14:03 2000 @@ -22,6 +22,7 @@ int do_goto(int xtile, int ytile); void do_map_click(int xtile, int ytile); +struct unit *player_find_visible_unit(struct tile *ptile); void request_center_focus_unit(void); void request_move_unit_direction(struct unit *punit, int dx, int dy); /* used by key_xxx */ void request_new_unit_activity(struct unit *punit, enum unit_activity act); diff -ur freeciv/client/gui-gtk/mapctrl.c show_transporter_on_top/client/gui-gtk/mapctrl.c --- freeciv/client/gui-gtk/mapctrl.c Mon Mar 13 14:08:08 2000 +++ show_transporter_on_top/client/gui-gtk/mapctrl.c Mon Mar 13 15:15:09 2000 @@ -159,7 +159,7 @@ count++; } - if((punit=player_find_visible_unit(game.player_ptr, ptile)) && !pcity) { + if((punit=player_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_top/client/gui-gtk/mapview.c --- freeciv/client/gui-gtk/mapview.c Mon Mar 13 14:08:08 2000 +++ show_transporter_on_top/client/gui-gtk/mapview.c Mon Mar 13 15:15:42 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=player_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=player_find_visible_unit(ptile))) pplayer = &game.players[punit->owner]; } else diff -ur freeciv/client/gui-mui/mapclass.c show_transporter_on_top/client/gui-mui/mapclass.c --- freeciv/client/gui-mui/mapclass.c Mon Mar 13 14:08:08 2000 +++ show_transporter_on_top/client/gui-mui/mapclass.c Mon Mar 13 15:18:48 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 = player_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 = player_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 = player_find_visible_unit(ptile); focus = get_unit_in_focus(); if (pcity) diff -ur freeciv/client/gui-mui/overviewclass.c show_transporter_on_top/client/gui-mui/overviewclass.c --- freeciv/client/gui-mui/overviewclass.c Mon Mar 13 14:07:23 2000 +++ show_transporter_on_top/client/gui-mui/overviewclass.c Mon Mar 13 15:19:14 2000 @@ -124,7 +124,7 @@ } else { - if ((punit = player_find_visible_unit(game.player_ptr, ptile))) + if ((punit = player_find_visible_unit(ptile))) { if (punit->owner == game.player_idx) { diff -ur freeciv/client/gui-xaw/mapctrl.c show_transporter_on_top/client/gui-xaw/mapctrl.c --- freeciv/client/gui-xaw/mapctrl.c Mon Mar 13 14:08:08 2000 +++ show_transporter_on_top/client/gui-xaw/mapctrl.c Mon Mar 13 15:48:55 2000 @@ -149,7 +149,7 @@ XtCreateManagedWidget(s, smeBSBObjectClass, p, NULL, 0); } - if((punit=player_find_visible_unit(game.player_ptr, ptile)) && !pcity) { + if((punit=player_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_top/client/gui-xaw/mapview.c --- freeciv/client/gui-xaw/mapview.c Mon Mar 13 14:07:22 2000 +++ show_transporter_on_top/client/gui-xaw/mapview.c Mon Mar 13 15:17:35 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=player_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=player_find_visible_unit(ptile))) pplayer = &game.players[punit->owner]; } else diff -ur freeciv/client/tilespec.c show_transporter_on_top/client/tilespec.c --- freeciv/client/tilespec.c Mon Mar 13 14:08:08 2000 +++ show_transporter_on_top/client/tilespec.c Mon Mar 13 15:18:00 2000 @@ -934,7 +934,7 @@ return sprs - save_sprs; } - if((punit=player_find_visible_unit(game.player_ptr, ptile))) { + if((punit=player_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=player_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_top/common/player.c --- freeciv/common/player.c Mon Mar 13 14:07:24 2000 +++ show_transporter_on_top/common/player.c Mon Mar 13 15:07:50 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_top/common/player.h --- freeciv/common/player.h Mon Mar 13 14:07:24 2000 +++ show_transporter_on_top/common/player.h Mon Mar 13 15:09:15 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);