Apply patch from Rusty Russel...

...(wow!) to print the number of enemies who can reach a given hex
when "Showing enemy moves"
This commit is contained in:
Isaac Clerencia Perez 2005-11-22 00:07:49 +00:00
parent ab0d4bd0a0
commit 1f15bbf440
4 changed files with 61 additions and 7 deletions

View file

@ -80,7 +80,7 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
screen_(video), xpos_(0), ypos_(0),
zoom_(DefaultZoom), map_(map), units_(units),
minimap_(NULL), redrawMinimap_(false),
pathsList_(NULL), status_(status),
pathsList_(NULL), enemy_reach_(NULL), status_(status),
teams_(t), lastDraw_(0), drawSkips_(0),
invalidateAll_(true), invalidateUnit_(true),
invalidateGameStatus_(true), panelsDrawn_(false),
@ -1456,6 +1456,9 @@ void display::draw_tile(int x, int y, surface unit_image, fixed_t alpha, Uint32
pathsList_->routes.end()) {
image_type = image::GREYED;
}
if(enemy_reach_ != NULL && enemy_reach_->find(loc) == enemy_reach_->end()) {
image_type = image::GREYED;
}
unit_map::iterator un = find_visible_unit(units_, loc, map_,
status_.get_time_of_day().lawful_bonus,teams_,teams_[currentTeam_]);
@ -1505,6 +1508,8 @@ void display::draw_tile(int x, int y, surface unit_image, fixed_t alpha, Uint32
SDL_BlitSurface(surface,NULL,dst,&dstrect);
}
if (enemy_reach_ != NULL)
draw_enemies_reach(loc,xpos,ypos);
draw_footstep(loc,xpos,ypos);
draw_unit_on_tile(x,y,unit_image,alpha,blend_to);
@ -1561,6 +1566,40 @@ void display::draw_tile(int x, int y, surface unit_image, fixed_t alpha, Uint32
update_rect(xpos,ypos,zoom_,zoom_);
}
void display::draw_enemies_reach(const gamemap::location& loc, int xloc, int yloc)
{
const reach_map::const_iterator reach_it = enemy_reach_->find(loc);
// not reachable, leave greyed out.
if (reach_it == enemy_reach_->end())
return;
// only one can reach, leave highlighted.
if (reach_it->second == 1)
return;
// multiple can reach: print number
std::stringstream text;
text << reach_it->second;
const std::string &str = text.str();
const SDL_Rect& rect = map_area();
const SDL_Rect& text_area = font::text_area(str,font::SIZE_LARGE);
const int x = xloc + zoom_/2 - text_area.w/2;
const int y = yloc + zoom_/2 - text_area.h/2;
//draw the text with a black outline
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x-1,y-1);
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x-1,y);
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x-1,y+1);
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x,y-1);
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x+1,y-1);
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x+1,y);
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x+1,y+1);
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x,y+1);
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::YELLOW_COLOUR,str,x,y);
}
void display::draw_footstep(const gamemap::location& loc, int xloc, int yloc)
{
std::vector<gamemap::location>::const_iterator i =
@ -1859,6 +1898,14 @@ surface display::get_minimap(int w, int h)
void display::set_paths(const paths* paths_list)
{
pathsList_ = paths_list;
enemy_reach_ = NULL;
invalidate_all();
}
void display::set_reach_map(const reach_map *reach_map)
{
pathsList_ = NULL;
enemy_reach_ = reach_map;
invalidate_all();
}

View file

@ -174,6 +174,11 @@ public:
//paths_list must remain valid until it is set again
void set_paths(const paths* paths_list);
//variation of set_paths which shows how many units can reach each tile.
//Setting the reach_map clears the paths_list, and vice-versa.
typedef std::map<gamemap::location,unsigned int> reach_map;
void set_reach_map(const reach_map *reach_map);
//sets the route along which footsteps are drawn to show movement of a
//unit. If NULL, no route is displayed.
//route does not have to remain valid after being set
@ -215,6 +220,7 @@ private:
// void draw_tile_adjacent(int x, int y, image::TYPE image_type, ADJACENT_TERRAIN_TYPE type);
void draw_enemies_reach(const gamemap::location& loc, int xloc, int yloc);
public:
//function to draw a footstep for the given location, on screen at
@ -504,6 +510,8 @@ private:
typedef std::map<gamemap::location,int> halo_map;
halo_map haloes_;
const reach_map *enemy_reach_;
//for debug mode
static std::map<gamemap::location,fixed_t> debugHighlights_;

View file

@ -2637,10 +2637,10 @@ bool turn_info::enemies_visible() const
return false;
}
// Highlights squares that an enemy could move to on their turn
// Highlights squares that an enemy could move to on their turn, showing how many can reach each square.
void turn_info::show_enemy_moves(bool ignore_units)
{
all_paths_ = paths();
reach_map_ = display::reach_map();
// Compute enemy movement positions
for(unit_map::iterator u = units_.begin(); u != units_.end(); ++u) {
@ -2654,14 +2654,12 @@ void turn_info::show_enemy_moves(bool ignore_units)
u->first,teams_,is_skirmisher,teleports);
for (paths::routes_map::const_iterator route = path.routes.begin(); route != path.routes.end(); ++route) {
// map<...>::operator[](const key_type& key) inserts key into
// the map with a default instance of value_type
all_paths_.routes[route->first];
reach_map_[route->first]++;
}
}
}
gui_.set_paths(&all_paths_);
gui_.set_reach_map(&reach_map_);
}
void turn_info::toggle_shroud_updates() {

View file

@ -227,6 +227,7 @@ private:
gamemap::location next_unit_;
paths current_paths_, all_paths_;
paths::route current_route_;
display::reach_map reach_map_;
bool enemy_paths_;
gamemap::location last_hex_;
gamemap::location::DIRECTION last_nearest_, last_second_nearest_;