Support for drawing highlighted regions.

Basic support for showing the reach of a unit or similar reach map
related issues in the minimap.
This commit is contained in:
fendrin 2013-12-05 21:14:17 +01:00
parent 3464f99469
commit 5afac25dd8
2 changed files with 25 additions and 2 deletions

View file

@ -38,7 +38,7 @@ static lg::log_domain log_display("display");
namespace image {
surface getMinimap(int w, int h, const gamemap &map, const team *vw)
surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::map<map_location,unsigned int> *reach_map)
{
const int scale = 8;
@ -57,6 +57,7 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw)
typedef mini_terrain_cache_map cache_map;
cache_map *normal_cache = &mini_terrain_cache;
cache_map *fog_cache = &mini_fogged_terrain_cache;
cache_map *highlight_cache = &mini_highlighted_terrain_cache;
for(int y = 0; y != map.total_height(); ++y)
for(int x = 0; x != map.total_width(); ++x) {
@ -65,6 +66,8 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw)
if(!map.on_board(loc))
continue;
const bool highlighted = reach_map && reach_map->count(loc) != 0;
const bool shrouded = (vw != NULL && vw->shrouded(loc));
// shrouded hex are not considered fogged (no need to fog a black image)
const bool fogged = (vw != NULL && !shrouded && vw->fogged(loc));
@ -92,8 +95,11 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw)
surface surf(NULL);
bool need_fogging = false;
bool need_highlighting = false;
cache_map* cache = fogged ? fog_cache : normal_cache;
if (highlighted)
cache = highlight_cache;
cache_map::iterator i = cache->find(terrain);
if (fogged && i == cache->end()) {
@ -104,6 +110,14 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw)
need_fogging = true;
}
if (highlighted && i == cache->end()) {
// we don't have the highlighted version in cache
// try the normal cache and ask fogging the image
cache = normal_cache;
i = cache->find(terrain);
need_highlighting = true;
}
if(i == cache->end()) {
std::string base_file =
"terrain/" + terrain_info.minimap_image() + ".png";
@ -141,6 +155,10 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw)
fog_cache->insert(cache_map::value_type(terrain,surf));
}
if (need_highlighting) {
surf = adjust_surface_color(surf,50,50,50);
highlight_cache->insert(cache_map::value_type(terrain,surf));
}
if(surf != NULL)
sdl_blit(surf, NULL, minimap, &maprect);
@ -157,6 +175,9 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw)
int_to_color(game_config::team_rgb_range.find(terrain_id)->second.min()) :
int_to_color(game_config::team_rgb_range.find(terrain_id)->second.mid());
if (highlighted)
tmp = int_to_color(game_config::team_rgb_range.find(terrain_id)->second.max());
if (first) {
first = false;
col = tmp;

View file

@ -15,15 +15,17 @@
#define MINIMAP_HPP_INCLUDED
#include <cstddef>
#include <map.hpp>
class gamemap;
struct surface;
class team;
class map_location;
namespace image {
///function to create the minimap for a given map
///the surface returned must be freed by the user
surface getMinimap(int w, int h, const gamemap &map_, const team *vm = NULL);
surface getMinimap(int w, int h, const gamemap &map_, const team *vm = NULL, const std::map<map_location,unsigned int> *reach_map = NULL);
}
#endif