diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/control.c freeciv/client/control.c --- FreecivCVS/client/control.c Sun May 28 00:46:42 2000 +++ freeciv/client/control.c Tue May 30 14:20:16 2000 @@ -30,6 +30,7 @@ #include "civclient.h" #include "options.h" +#include "tilespec.h" #include "control.h" @@ -231,7 +232,10 @@ { struct unit *panyowned = NULL, *panyother = NULL, *ptptother = NULL; - if(unit_list_size(&ptile->units)==0) return NULL; + /* If no units here, return nothing. */ + 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) { @@ -254,6 +258,11 @@ unit_list_iterate_end; } + /* If a city is here, return nothing (unit hidden by city). */ + if (ptile->city) { + return NULL; + } + /* Iterate through the units to find the best one we prioritize this way: 1: owned transporter. 2: any owned unit @@ -296,21 +305,15 @@ { static int is_shown; struct unit *punit; - - if((punit=get_unit_in_focus())) { - struct tile *ptile; - ptile=map_get_tile(punit->x, punit->y); + if((punit=get_unit_in_focus())) { if(is_shown) { - struct unit_list units; - units=ptile->units; - unit_list_init(&ptile->units); + set_focus_unit_hidden_state(1); refresh_tile_mapcanvas(punit->x, punit->y, 1); - ptile->units=units; + set_focus_unit_hidden_state(0); } else { refresh_tile_mapcanvas(punit->x, punit->y, 1); } - is_shown=!is_shown; } } @@ -1393,4 +1396,3 @@ if(get_unit_in_focus()) request_unit_wakeup(punit_focus); } - 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 May 24 15:13:21 2000 +++ freeciv/client/gui-gtk/mapview.c Tue May 30 14:36:51 2000 @@ -662,30 +662,9 @@ **************************************************************************/ static void set_overview_tile_foreground_color(int x, int y) { - struct tile *ptile=map_get_tile(x, y); - struct unit *punit; - struct city *pcity; - - if(!ptile->known) - gdk_gc_set_foreground (fill_bg_gc, colors_standard[COLOR_STD_BLACK]); - 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 - gdk_gc_set_foreground (fill_bg_gc, colors_standard[COLOR_STD_RED]); - } - else if((pcity=map_get_city(x, y))) { - if(pcity->owner==game.player_idx) - gdk_gc_set_foreground (fill_bg_gc, colors_standard[COLOR_STD_WHITE]); - else - gdk_gc_set_foreground (fill_bg_gc, colors_standard[COLOR_STD_CYAN]); - } - else if(ptile->terrain==T_OCEAN) - gdk_gc_set_foreground (fill_bg_gc, colors_standard[COLOR_STD_OCEAN]); - else - gdk_gc_set_foreground (fill_bg_gc, colors_standard[COLOR_STD_GROUND]); + gdk_gc_set_foreground (fill_bg_gc, + colors_standard[overview_tile_color(x, y)]); } - /************************************************************************** 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 May 24 15:13:21 2000 +++ freeciv/client/gui-xaw/mapview.c Tue May 30 14:35:47 2000 @@ -632,28 +632,8 @@ **************************************************************************/ static void set_overview_tile_foreground_color(int x, int y) { - struct tile *ptile=map_get_tile(x, y); - struct unit *punit; - struct city *pcity; - - if(!ptile->known) - XSetForeground(display, fill_bg_gc, colors_standard[COLOR_STD_BLACK]); - else if ((punit=find_visible_unit(ptile))) { - if(punit->owner==game.player_idx) - XSetForeground(display, fill_bg_gc, colors_standard[COLOR_STD_YELLOW]); - else - XSetForeground(display, fill_bg_gc, colors_standard[COLOR_STD_RED]); - } - else if((pcity=map_get_city(x, y))) { - if(pcity->owner==game.player_idx) - XSetForeground(display, fill_bg_gc, colors_standard[COLOR_STD_WHITE]); - else - XSetForeground(display, fill_bg_gc, colors_standard[COLOR_STD_CYAN]); - } - else if(ptile->terrain==T_OCEAN) - XSetForeground(display, fill_bg_gc, colors_standard[COLOR_STD_OCEAN]); - else - XSetForeground(display, fill_bg_gc, colors_standard[COLOR_STD_GROUND]); + XSetForeground(display, fill_bg_gc, + colors_standard[overview_tile_color(x, y)]); } diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/tilespec.c freeciv/client/tilespec.c --- FreecivCVS/client/tilespec.c Tue May 9 14:38:44 2000 +++ freeciv/client/tilespec.c Tue May 30 14:40:54 2000 @@ -42,7 +42,6 @@ #include "support.h" #include "unit.h" -#include "colors_g.h" #include "control.h" /* for fill_xxx */ #include "graphics_g.h" #include "options.h" /* for fill_xxx */ @@ -96,6 +95,17 @@ */ +/* + If focus_unit_hidden is true, then no units at + the location of the foc unit are ever drawn. +*/ +static int focus_unit_hidden = 0; + +/* + If no_backdrop is true, then no color/flag is drawn behind the city/unit. +*/ +static int no_backdrop = 0; + /********************************************************************** Gets full filename for tilespec file, based on input name. Returned data is allocated, and freed by user as required. @@ -739,10 +749,12 @@ struct Sprite **save_sprs=sprs; struct tile *ptile = map_get_tile(pcity->x, pcity->y); - if(!use_solid_color_behind_units) { - /* will be the first sprite if flags_are_transparent == FALSE */ - *sprs++ = get_city_nation_flag_sprite(pcity); - } else *sprs++ = NULL; + if(!no_backdrop) { + if(!use_solid_color_behind_units) { + /* will be the first sprite if flags_are_transparent == FALSE */ + *sprs++ = get_city_nation_flag_sprite(pcity); + } else *sprs++ = NULL; + } if(genlist_size(&(ptile->units.list)) > 0) *sprs++ = get_city_occupied_sprite(pcity); @@ -780,14 +792,15 @@ struct Sprite **save_sprs=sprs; int ihp; - if(!use_solid_color_behind_units) { - /* will be the first sprite if flags_are_transparent == FALSE */ - *sprs++ = get_unit_nation_flag_sprite(punit); - } - else { - /* Two NULLs means unit */ - *sprs++ = NULL; - *sprs++ = NULL; + if(!no_backdrop) { + if(!use_solid_color_behind_units) { + /* will be the first sprite if flags_are_transparent == FALSE */ + *sprs++ = get_unit_nation_flag_sprite(punit); + } else { + /* Two NULLs means unit */ + *sprs++ = NULL; + *sprs++ = NULL; + } } *sprs++ = get_unit_type(punit->type)->sprite; @@ -876,39 +889,41 @@ int tileno; struct tile *ptile; struct Sprite *mysprite; - struct unit *punit; struct city *pcity; + struct unit *pfocus; + struct unit *punit; int den_y=map.ysize*.24; struct Sprite **save_sprs=sprs; ptile=map_get_tile(abs_x0, abs_y0); - punit=get_unit_in_focus(); if(abs_y0>=map.ysize || ptile->known == TILE_UNKNOWN) { return 0; } - if(!flags_are_transparent || use_solid_color_behind_units) { - /* non-transparent flags -> just draw city or unit. */ - if((pcity=map_get_city(abs_x0, abs_y0)) - && (citymode || !(punit=get_unit_in_focus()) - || punit->x!=abs_x0 || punit->y!=abs_y0 - || (unit_list_size(&ptile->units)==0))) { + pcity=map_get_city(abs_x0, abs_y0); + pfocus=get_unit_in_focus(); - /* above, unit_list_size==0 happens when focus unit is blinking --dwp */ - sprs += fill_city_sprite_array(sprs,pcity); - return sprs - save_sprs; - } + if(!flags_are_transparent || use_solid_color_behind_units) { + /* non-transparent flags -> just draw city or unit */ - if ((punit=find_visible_unit(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) - *sprs++ = sprites.unit.stack; - return sprs - save_sprs; + if(!focus_unit_hidden || !pfocus || + punit->x!=pfocus->x || punit->y!=pfocus->y) { + sprs+=fill_unit_sprite_array(sprs,punit); + if(unit_list_size(&ptile->units)>1) + *sprs++ = sprites.unit.stack; + return sprs - save_sprs; + } } } + + if(pcity) { + sprs+=fill_city_sprite_array(sprs,pcity); + return sprs - save_sprs; + } } ttype=map_get_terrain(abs_x0, abs_y0); @@ -1114,17 +1129,23 @@ *sprs++ = sprites.tx.darkness[tileno]; } - if(flags_are_transparent) { /* transparent flags -> draw city or unit last */ - if((pcity=map_get_city(abs_x0, abs_y0))) { + if(flags_are_transparent) { + /* transparent flags -> draw city or unit last */ + + if(pcity) { sprs+=fill_city_sprite_array(sprs,pcity); } - if ((punit=find_visible_unit(ptile))) { - if(pcity && punit!=get_unit_in_focus()) return sprs - save_sprs; + 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) - *sprs++ = sprites.unit.stack; + if(!focus_unit_hidden || !pfocus || + punit->x!=pfocus->x || punit->y!=pfocus->y) { + no_backdrop=BOOL_VAL(pcity); + sprs+=fill_unit_sprite_array(sprs,punit); + no_backdrop=FALSE; + if(unit_list_size(&ptile->units)>1) + *sprs++ = sprites.unit.stack; + } } } } @@ -1242,11 +1263,49 @@ fixed number of nations. Now base on player number instead, since still limited to less than 14. Could possibly improve to allow players to choose their preferred color etc. - Return is really "enum color_std". A hack added to avoid returning more that COLOR_STD_RACE13. But really there should be more colors available -- jk. ***********************************************************************/ -int player_color(struct player *pplayer) +enum color_std player_color(struct player *pplayer) { return COLOR_STD_RACE0 + (pplayer->player_no % MAX_NUM_PLAYERS); +} + +/********************************************************************** + Return color for overview map tile. +***********************************************************************/ +enum color_std overview_tile_color(int x, int y) +{ + enum color_std color; + struct tile *ptile=map_get_tile(x, y); + struct unit *punit; + struct city *pcity; + + if(!ptile->known) { + color=COLOR_STD_BLACK; + } else if((pcity=map_get_city(x, y))) { + if(pcity->owner==game.player_idx) + color=COLOR_STD_WHITE; + else + color=COLOR_STD_CYAN; + } else if ((punit=find_visible_unit(ptile))) { + if(punit->owner==game.player_idx) + color=COLOR_STD_YELLOW; + else + color=COLOR_STD_RED; + } else if(ptile->terrain==T_OCEAN) { + color=COLOR_STD_OCEAN; + } else { + color=COLOR_STD_GROUND; + } + + return color; +} + +/********************************************************************** + Set focus_unit_hidden (q.v.) variable to given value. +***********************************************************************/ +void set_focus_unit_hidden_state(int hide) +{ + focus_unit_hidden = hide; } diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/tilespec.h freeciv/client/tilespec.h --- FreecivCVS/client/tilespec.h Sun Apr 2 13:27:30 2000 +++ freeciv/client/tilespec.h Tue May 30 14:32:33 2000 @@ -21,6 +21,8 @@ #include "map.h" /* NUM_DIRECTION_NSEW */ +#include "colors_g.h" + struct Sprite; /* opaque; gui-dep */ struct unit; struct player; @@ -41,7 +43,10 @@ int fill_tile_sprite_array(struct Sprite **sprs, int abs_x0, int abs_y0, int citymode); int fill_unit_sprite_array(struct Sprite **sprs, struct unit *punit); -int player_color(struct player *pplayer); +enum color_std player_color(struct player *pplayer); +enum color_std overview_tile_color(int x, int y); + +void set_focus_unit_hidden_state(int hide); /* This the way directional indices are now encoded: */