15 #define GETTEXT_DOMAIN "wesnoth-lib"
37 #define DBG_DP LOG_STREAM(debug, log_display)
38 #define WRN_DP LOG_STREAM(warn, log_display)
49 DBG_DP <<
"creating minimap " <<
int(map.
w()*scale*0.75) <<
"," << map.
h()*scale <<
"\n";
56 const size_t map_width = map.
w()*scale*3/4;
57 const size_t map_height = map.
h()*
scale;
58 if(map_width == 0 || map_height == 0) {
62 if(!preferences_minimap_draw_villages && !preferences_minimap_draw_terrain)
66 double ratio = std::min<double>( w*1.0 / map_width, h*1.0 / map_height);
71 if(minimap ==
nullptr)
86 const bool highlighted = reach_map && reach_map->count(loc) != 0;
90 const bool fogged = (vw !=
nullptr && !shrouded && vw->
fogged(loc));
103 x * scale * 3 / 4 - 1
104 ,
y * scale + scale / 4 * (
is_odd(
x) ? 1 : -1) - 1
108 if (preferences_minimap_draw_terrain) {
110 if (preferences_minimap_terrain_coding) {
114 bool need_fogging =
false;
115 bool need_highlighting =
false;
117 cache_map*
cache = fogged ? fog_cache : normal_cache;
119 cache = highlight_cache;
122 if (fogged && i == cache->end()) {
125 cache = normal_cache;
126 i = cache->find(terrain);
130 if (highlighted && i == cache->end()) {
133 cache = normal_cache;
134 i = cache->find(terrain);
135 need_highlighting =
true;
138 if(i == cache->end() && !terrain_info.
minimap_image().empty()) {
150 if(overlay !=
nullptr && overlay != tile) {
153 sdl_blit(tile,
nullptr, combined, &r);
154 r.x = std::max(0, (tile->w - overlay->w)/2);
155 r.y = std::max(0, (tile->h - overlay->h)/2);
165 i = normal_cache->insert(cache_map::value_type(terrain,surf)).first;
172 fog_cache->insert(cache_map::value_type(terrain,surf));
175 if (need_highlighting) {
177 highlight_cache->insert(cache_map::value_type(terrain,surf));
181 sdl_blit(surf,
nullptr, minimap, &maprect);
204 if (tmp.b < 50) tmp.b = 0;
206 if (tmp.g < 50) tmp.g = 0;
208 if (tmp.r < 50) tmp.r = 0;
213 if (tmp.b > 205) tmp.b = 255;
215 if (tmp.g > 205) tmp.g = 255;
217 if (tmp.r > 205) tmp.r = 255;
225 col.r = col.r - (col.r - tmp.r)/2;
226 col.g = col.g - (col.g - tmp.g)/2;
227 col.b = col.b - (col.b - tmp.b)/2;
230 SDL_Rect fillrect =
sdl::create_rect(maprect.x, maprect.y, scale * 3/4, scale);
231 const Uint32 mapped_col = SDL_MapRGB(minimap->format,col.r,col.g,col.b);
236 if (terrain_info.
is_village() && preferences_minimap_draw_villages) {
245 if (preferences_minimap_unit_coding || !vw ) {
266 const Uint32 mapped_col = SDL_MapRGB(minimap->format,col.r,col.g,col.b);
273 double wratio = w*1.0 / minimap->w;
274 double hratio = h*1.0 / minimap->h;
275 double ratio = std::min<double>(wratio, hratio);
278 static_cast<int>(minimap->w * ratio), static_cast<int>(minimap->h * ratio));
280 DBG_DP <<
"done generating minimap\n";
286 SDL_Rect draw_minimap(
CVideo &video,
const SDL_Rect &area,
const gamemap &map,
const team *vw,
const std::map<map_location, unsigned int> *reach_map)
290 const float width = map.
w() * 72 * 3/4;
291 const float height = map.
h() * 72 + 72 * 1/4;
292 const float scale_factor = std::min(area.w / width, area.h / height);
293 const float tile_size = 72 * scale_factor;
294 const int xoff = area.x + (area.w - scale_factor *
width) / 2;
295 const int yoff = area.y + (area.h - scale_factor *
height) / 2 + 1;
307 const bool highlighted = reach_map && reach_map->count(loc) != 0;
310 const bool fogged = (vw !=
nullptr && !shrouded && vw->
fogged(loc));
316 const int xpos =
x * tile_size * 3/4 + xoff;
317 const int ypos =
y * tile_size + tile_size / 4 * (
is_odd(
x) ? 2 : 0) + yoff;
320 if (terrain_coding) {
324 img.set_color_mod(100, 100, 100);
327 img.set_color_mod(150, 150, 150);
330 img.set_scale(scale_factor, scale_factor);
332 video.draw_texture(img, xpos, ypos);
337 overlay.set_color_mod(100, 100, 100);
340 overlay.set_color_mod(150, 150, 150);
343 overlay.set_scale(scale_factor, scale_factor);
344 video.draw_texture(overlay, xpos, ypos);
366 if (tmp.b < 50) tmp.b = 0;
368 if (tmp.g < 50) tmp.g = 0;
370 if (tmp.r < 50) tmp.r = 0;
375 if (tmp.b > 205) tmp.b = 255;
377 if (tmp.g > 205) tmp.g = 255;
379 if (tmp.r > 205) tmp.r = 255;
387 col.r = col.r - (col.r - tmp.r)/2;
388 col.g = col.g - (col.g - tmp.g)/2;
389 col.b = col.b - (col.b - tmp.b)/2;
392 SDL_Rect fillrect =
sdl::create_rect(xpos, ypos, tile_size * 3/4, tile_size);
398 if (terrain_info.
is_village() && draw_villages) {
433 return sdl::create_rect(xoff, yoff, width * scale_factor, height * scale_factor);
int total_width() const
Real width of the map, including borders.
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
const t_translation::t_list & underlying_union_terrain(const t_translation::t_terrain &terrain) const
std::string unmoved_color()
surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::map< map_location, unsigned int > *reach_map)
function to create the minimap for a given map the surface returned must be freed by the user ...
surface create_neutral_surface(int w, int h)
std::map< t_translation::t_terrain, surface > mini_terrain_cache_map
void fill_rect(surface &dst, SDL_Rect *dst_rect, const Uint32 color)
Fill a rectangle on a given surface.
GLenum GLenum GLenum GLenum GLenum scale
std::map< std::string, color_range > team_rgb_range
SDL_Color create_color(const unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
bool shrouded(const map_location &loc) const
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
Uint32 rep() const
High-contrast shade, intended for the minimap markers.
const std::string & minimap_image_overlay() const
bool owns_village(const map_location &loc) const
SDL_Color int_to_color(const Uint32 rgb)
bool minimap_movement_coding()
mini_terrain_cache_map mini_fogged_terrain_cache
bool is_enemy(int n) const
const std::string & id() const
int village_owner(const map_location &loc) const
Given the location of a village, will return the 0-based index of the team that currently owns it...
GLint GLint GLint GLint GLint GLint y
const tdata_cache & tdata() const
int total_height() const
Real height of the map, including borders.
void blit_surface(const surface &surf, const SDL_Rect *srcrect, surface &dst, const SDL_Rect *dstrect)
Replacement for sdl_blit.
bool minimap_draw_villages()
This class stores all the data for a single 'side' (in game nomenclature).
static lg::log_domain log_display("display")
GLubyte GLubyte GLubyte GLubyte w
int w() const
Effective map width.
const terrain_type & get_terrain_info(const t_translation::t_terrain &terrain) const
Get the corresponding terrain_type information object for a given type of terrain.
Encapsulates the map of the game.
static const ::config * terrain
The terrain used to create the cache.
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
bool is_blindfolded() const
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Encapsulates the map of the game.
surface adjust_surface_color(const surface &surf, int red, int green, int blue, bool optimize)
std::string allied_color()
int h() const
Effective map height.
static SDL_Color get_minimap_color(int side)
GLfloat GLfloat GLfloat GLfloat h
GLint GLint GLint GLint GLint x
mini_terrain_cache_map mini_highlighted_terrain_cache
bool fogged(const map_location &loc) const
GLdouble GLdouble GLdouble r
mini_terrain_cache_map mini_terrain_cache
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
const t_terrain VOID_TERRAIN
bool minimap_draw_terrain()
bool find(E event, F functor)
Tests whether an event handler is available.
surface make_neutral_surface(const surface &surf)
const color_range & color_info(const std::string &name)
this module manages the cache of images.
Standard logging facilities (interface).
GLint GLint GLint GLint GLint GLint GLsizei width
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
surface scale_surface_sharp(const surface &surf, int w, int h, bool optimize)
Scale a surface using modified nearest neighbour algorithm.
const std::string & minimap_image() const
GLsizei const GLcharARB ** string
std::string enemy_color()
std::vector< t_terrain > t_list
bool minimap_terrain_coding()