16 #define GETTEXT_DOMAIN "wesnoth-lib" 37 #define DBG_DP LOG_STREAM(debug, log_display) 38 #define WRN_DP LOG_STREAM(warn, log_display) 53 const int scale = (preferences_minimap_draw_terrain && preferences_minimap_terrain_coding) ? 24 : 4;
55 DBG_DP <<
"creating minimap " << int(map.
w()*scale*0.75) <<
"," << map.
h()*
scale;
57 const std::size_t map_width = map.
w()*scale*3/4;
58 const std::size_t map_height = map.
h()*
scale;
59 if(map_width == 0 || map_height == 0) {
63 if(!preferences_minimap_draw_villages && !preferences_minimap_draw_terrain)
67 double ratio = std::min<double>( w*1.0 / map_width, h*1.0 / map_height);
68 return surface(map_width * ratio, map_height * ratio);
71 surface minimap(map_width, map_height);
72 if(minimap ==
nullptr)
89 const bool fogged = (vw !=
nullptr && !shrouded && vw->
fogged(loc));
91 const bool highlighted = reach_map && reach_map->count(loc) != 0 && !shrouded;
102 x * scale * 3 / 4 - (scale / 4)
103 , y * scale + scale / 4 * (
is_odd(x) ? 1 : -1) - (scale / 4)
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()) {
139 std::string base_file =
146 std::string overlay_file =
150 if(overlay !=
nullptr && overlay != tile) {
151 surface combined(tile->w, tile->h);
152 SDL_Rect r {0,0,0,0};
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);
156 sdl_blit(overlay,
nullptr, combined, &r);
163 i = normal_cache->emplace(terrain, surf).first;
166 if (i != cache->end())
172 fog_cache->emplace(terrain, surf);
175 if (need_highlighting) {
177 highlight_cache->emplace(terrain, surf);
182 sdl_blit(surf,
nullptr, minimap, &maprect);
193 col = it->second.rep();
204 color_t tmp = it->second.rep();
207 if (tmp.b < 50) tmp.b = 0;
209 if (tmp.g < 50) tmp.g = 0;
211 if (tmp.r < 50) tmp.r = 0;
216 if (tmp.b > 205) tmp.b = 255;
218 if (tmp.g > 205) tmp.g = 255;
220 if (tmp.r > 205) tmp.r = 255;
228 col.r = col.r - (col.r - tmp.r)/2;
229 col.g = col.g - (col.g - tmp.g)/2;
230 col.b = col.b - (col.b - tmp.b)/2;
233 SDL_Rect fillrect {maprect.x, maprect.y, scale * 3/4, scale};
234 const uint32_t mapped_col = SDL_MapRGB(minimap->format,col.r,col.g,col.b);
239 if (terrain_info.
is_village() && preferences_minimap_draw_villages) {
247 col = iter->second.min();
253 if (preferences_minimap_unit_coding || !vw ) {
274 const uint32_t mapped_col = SDL_MapRGB(minimap->format,col.r,col.g,col.b);
281 double wratio = w*1.0 / minimap->w;
282 double hratio = h*1.0 / minimap->h;
283 double ratio = std::min<double>(wratio, hratio);
286 static_cast<int>(minimap->w * ratio), static_cast<int>(minimap->h * ratio));
288 DBG_DP <<
"done generating minimap";
298 const std::map<map_location, unsigned int>* reach_map,
299 bool ignore_terrain_disabled)
308 const int scale = (preferences_minimap_draw_terrain && preferences_minimap_terrain_coding) ? 24 : 4;
310 DBG_DP <<
"Creating minimap: " <<
static_cast<int>(map.
w() * scale * 0.75) <<
", " << map.
h() *
scale;
312 const std::size_t map_width = std::max(0, map.
w()) * scale * 3 / 4;
313 const std::size_t map_height = std::max(0, map.
h()) * scale;
316 if(map_width == 0 || map_height == 0) {
321 if(!preferences_minimap_draw_villages && !preferences_minimap_draw_terrain) {
329 return is_blindfolded || (vw && vw->
shrouded(loc));
334 return vw && !shrouded(loc) && vw->
fogged(loc);
342 loc.x * scale * 3 / 4 - (scale / 4),
343 loc.y * scale + scale / 4 * (
is_odd(loc.x) ? 1 : -1) - (scale / 4),
354 texture minimap(map_width, map_height, SDL_TEXTUREACCESS_TARGET);
371 if(preferences_minimap_draw_terrain) {
373 const bool highlighted = reach_map && reach_map->count(loc) != 0 && !shrouded(loc);
379 rect dest = get_dst_rect(loc);
384 if(preferences_minimap_terrain_coding) {
386 const std::string base_file =
"terrain/" + terrain_info.
minimap_image() +
".png";
393 if(tile && map.
tdata()->get_terrain_info(terrain).is_combined()
413 col = it->second.rep();
418 for(
const auto& underlying_terrain : map.
tdata()->underlying_union_terrain(terrain)) {
419 const std::string& terrain_id = map.
tdata()->get_terrain_info(underlying_terrain).id();
426 color_t tmp = it->second.rep();
429 tmp.r = std::max(0, tmp.r - 50);
430 tmp.g = std::max(0, tmp.g - 50);
431 tmp.b = std::max(0, tmp.b - 50);
435 tmp.r = std::min(255, tmp.r + 50);
436 tmp.g = std::min(255, tmp.g + 50);
437 tmp.b = std::min(255, tmp.b + 50);
444 col.r = col.r - (col.r - tmp.r) / 2;
445 col.g = col.g - (col.g - tmp.g) / 2;
446 col.b = col.b - (col.b - tmp.b) / 2;
450 dest.w = scale * 3 / 4;
459 if(preferences_minimap_draw_villages) {
469 col = iter->second.min();
472 if(!fogged(loc) && side_num > 0) {
473 if(preferences_minimap_unit_coding || !vw) {
486 rect dest = get_dst_rect(loc);
487 dest.w = scale * 3 / 4;
496 if(units && preferences_minimap_draw_units && !is_blindfolded) {
497 for(
const auto& u : *units) {
499 const int side = u.side();
500 const bool is_enemy = vw && vw->
is_enemy(side);
502 if((vw && vw->
fogged(u_loc)) || (is_enemy && disp && u.invisible(u_loc)) || u.get_hidden()) {
508 if(!preferences_minimap_unit_coding) {
513 }
else if(vw && vw->
side() == side) {
522 rect fillrect = get_dst_rect(u_loc);
523 fillrect.w = scale * 3 / 4;
532 const double wratio = dst_w * 1.0 / raw_size.x;
533 const double hratio = dst_h * 1.0 / raw_size.y;
535 const double ratio = std::min<double>(wratio, hratio);
543 static_cast<int>(raw_size.x * ratio),
544 static_cast<int>(raw_size.y * ratio)
547 DBG_DP <<
"done generating minimap";
Drawing functions, for drawing things on the screen.
int village_owner(const map_location &loc) const
Given the location of a village, will return the 1-based number of the team that currently owns it...
surface get_image(const image::locator &i_locator, TYPE type)
[DEPRECATED] Caches and returns an image.
std::string unmoved_color()
void sdl_blit(const surface &src, const SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
bool minimap_draw_units()
static display * get_singleton()
Returns the display object if a display object exists.
void set_blend_mode(SDL_BlendMode b)
Set the blend mode used for drawing operations such as fill() and line().
constexpr bool is_odd(T num)
std::map< std::string, color_range > team_rgb_range
Colors defined by WML [color_range] tags.
surface adjust_surface_color(const surface &surf, int red, int green, int blue)
bool minimap_movement_coding()
point get_raw_size() const
The raw internal texture size.
mini_terrain_cache_map mini_fogged_terrain_cache
void fill_surface_rect(surface &dst, SDL_Rect *dst_rect, const uint32_t color)
Fill a rectangle on a given surface.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
const terrain_type & get_terrain_info(const t_translation::terrain_code &terrain) const
Get the corresponding terrain_type information object for a given type of terrain.
void for_each_loc(const F &f) const
void render_minimap(unsigned dst_w, unsigned dst_h, const gamemap &map, const team *vw, const unit_map *units, const std::map< map_location, unsigned int > *reach_map, bool ignore_terrain_disabled)
Renders the minimap to the screen.
std::map< t_translation::terrain_code, surface > mini_terrain_cache_map
Belongs to a friendly side.
surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::map< map_location, unsigned int > *reach_map, bool ignore_terrain_disabled)
function to create the minimap for a given map the surface returned must be freed by the user ...
Standard hexagonal tile mask applied, removing portions that don't fit.
Wrapper class to encapsulate creation and management of an SDL_Texture.
const terrain_code VOID_TERRAIN
VOID_TERRAIN is used for shrouded hexes.
Contains the database of all known terrain types, both those defined explicitly by WML [terrain_type]...
bool minimap_draw_villages()
This class stores all the data for a single 'side' (in game nomenclature).
Belongs to a non-friendly side; normally visualised by not displaying an orb.
bool is_combined() const
True for instances created by the terrain_code(base, overlay) constructor.
void scale(size_t factor, const uint32_t *src, uint32_t *trg, int srcWidth, int srcHeight, const ScalerCfg &cfg=ScalerCfg(), int yFirst=0, int yLast=std::numeric_limits< int >::max())
static lg::log_domain log_display("display")
int w() const
Effective map width.
std::string get_orb_color(orb_status os)
Wrapper for the various preferences::unmoved_color(), moved_color(), etc methods, using the enum inst...
bool on_board_with_border(const map_location &loc) const
Encapsulates the map of the game.
The basic class for representing 8-bit RGB or RGBA colour values.
bool is_enemy(int n) const
map_display and display: classes which take care of displaying the map and game-data on the screen...
const std::shared_ptr< terrain_type_data > & tdata() const
Encapsulates the map of the game.
int total_width() const
Real width of the map, including borders.
bool shrouded(const map_location &loc) const
std::string allied_color()
bool is_blindfolded() const
A class to manage automatic restoration of the render target.
An abstract description of a rectangle with integer coordinates.
const display_context & get_disp_context() const
mini_terrain_cache_map mini_highlighted_terrain_cache
const std::string & minimap_image() const
const t_translation::ter_list & underlying_union_terrain(const t_translation::terrain_code &terrain) const
Unordered set of all terrains used in either underlying_mvt_terrain or underlying_def_terrain.
int total_height() const
Real height of the map, including borders.
void blit(const texture &tex, const SDL_Rect &dst)
Draws a texture, or part of a texture, at the given location.
mini_terrain_cache_map mini_terrain_cache
static color_t get_minimap_color(int side)
color_t rep() const
High-contrast shade, intended for the minimap markers.
orb_status unit_orb_status(const unit &u) const
Returns an enumurated summary of whether this unit can move and/or attack.
bool minimap_draw_terrain()
const std::vector< map_location > & villages() const
Return a list of the locations of villages on the map.
void set_texture_scale_quality(const char *value)
Sets the texture scale quality.
const color_range & color_info(const std::string &name)
Functions to load and save images from/to disk.
surface scale_surface_sharp(const surface &surf, int w, int h)
Scale a surface using modified nearest neighbour algorithm.
Standard logging facilities (interface).
const std::string & id() const
std::vector< terrain_code > ter_list
Container associating units to locations.
bool fogged(const map_location &loc) const
bool owns_village(const map_location &loc) const
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
int h() const
Effective map height.
const std::string & minimap_image_overlay() const
void fill(const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Fill an area with the given colour.
std::string::const_iterator iterator
std::string enemy_color()
bool minimap_terrain_coding()