48 #define ERR_DP LOG_STREAM(err, log_display)
49 #define LOG_DP LOG_STREAM(info, log_display)
50 #define DBG_DP LOG_STREAM(debug, log_display)
53 #define ERR_NG LOG_STREAM(err, log_engine)
57 std::weak_ptr<wb::manager>
wb,
59 const std::string& theme_id,
63 , attack_indicator_src_()
64 , attack_indicator_dst_()
71 , needs_rebuild_(false)
169 if (std::shared_ptr<wb::manager>
w =
wb_.lock()) {
185 if (std::shared_ptr<wb::manager>
w =
wb_.lock()) {
209 {
"misc/hover-hex-top.png",
"~RC(magenta>gold)"};
211 {
"misc/hover-hex-bottom.png",
"~RC(magenta>gold)"};
214 {
"misc/hover-hex-enemy-top.png",
"~RC(magenta>red)"};
216 {
"misc/hover-hex-enemy-bottom.png",
"~RC(magenta>red)"};
219 {
"misc/hover-hex-top.png",
"~RC(magenta>green)"};
221 {
"misc/hover-hex-bottom.png",
"~RC(magenta>green)"};
224 {
"misc/hover-hex-top.png",
"~RC(magenta>lightblue)"};
226 {
"misc/hover-hex-bottom.png",
"~RC(magenta>lightblue)"};
234 std::vector<texture> res;
236 if (route.
steps.size() < 2) {
240 std::vector<map_location>::const_iterator
i =
243 if(
i == route.
steps.end()) {
254 if (image_number < 1) {
263 const int first_half = (
i == route.
steps.begin()) ? 1 : 0;
265 const int second_half = (
i+1 == route.
steps.end()) ? 0 : 1;
267 for (
int h = first_half;
h <= second_half; ++
h) {
268 const std::string sense(
h==0 ?
"-in" :
"-out" );
271 std::string teleport_image =
283 dir =
i->get_opposite_direction(dir);
284 rotate =
"~FL(horiz)~FL(vert)";
288 + sense +
"-" +
i->write_direction(dir)
295 if (teleport !=
nullptr) res.push_back(teleport);
324 mo_top_path = &mouseover_normal_top;
325 mo_bot_path = &mouseover_normal_bot;
327 mo_top_path = &mouseover_enemy_top;
328 mo_bot_path = &mouseover_enemy_bot;
330 mo_top_path = &mouseover_self_top;
331 mo_bot_path = &mouseover_self_bot;
333 mo_top_path = &mouseover_ally_top;
334 mo_bot_path = &mouseover_ally_bot;
364 if(std::shared_ptr<wb::manager>
w =
wb_.lock()) {
367 if(!(
w->is_active() &&
w->has_temp_move())) {
368 std::vector<texture> footstepImages = footsteps_images(
loc,
route_,
dc_);
369 if(!footstepImages.empty()) {
427 if(
context().teams().empty()) {
462 std::shared_ptr<wb::manager>
wb =
wb_.lock();
468 (
wb &&
wb->get_temp_move_unit().valid()) ?
470 if(un !=
context().units().end()) {
472 int move_cost = un->movement_cost(
context().map().get_terrain(
loc));
474 0 : 100 - un->defense_modifier(
context().map().get_terrain(
loc)));
475 std::stringstream def_text;
476 def_text << def <<
"%";
481 int def_font =
w->second.turns > 0 ? 18 : 16;
485 [inv =
w->second.invisible, zoc =
w->second.zoc, cap =
w->second.capture](
const rect& dest) {
487 draw::blit(image::get_texture(image::locator{
"misc/hidden.png"}, image::HEXED), dest);
491 draw::blit(image::get_texture(image::locator{
"misc/zoc.png"},
image::HEXED), dest);
500 if (
w->second.turns > 1 || (
w->second.turns == 1 &&
loc !=
route_.
steps.back())) {
501 std::stringstream turns_text;
502 turns_text <<
w->second.turns;
511 else if (selectedHex_.valid() &&
loc == mouseoverHex_)
515 if(selectedUnit != context().units().
end() && mouseoveredUnit == context().units().
end()) {
517 int move_cost = selectedUnit->movement_cost(context().map().get_terrain(
loc));
519 0 : 100 - selectedUnit->defense_modifier(context().map().get_terrain(
loc)));
520 std::stringstream def_text;
521 def_text << def <<
"%";
531 if (!reach_map_.empty()) {
533 if (reach != reach_map_.end() && reach->second > 1) {
534 const std::string num = std::to_string(reach->second);
557 const map_location enemy_unit_location = path_to_goal[0];
576 for(std::vector<map_location>::const_iterator
i =
route_.
steps.begin();
586 if(route !=
nullptr) {
665 std::vector<std::string>
names;
668 enum visibility { REACH = 0, ENEMY = 1, CLEAR = 2 };
669 std::array<visibility, 6> tiles;
671 for(
int i = 0;
i < 6; ++
i) {
673 std::string test_location = std::to_string(adjacent[
i].x) +
"," + std::to_string(adjacent[
i].y);
676 DBG_DP << test_location <<
" is REACHABLE";
684 DBG_DP << test_location <<
" is NOT REACHABLE";
689 DBG_DP << test_location <<
" has an ENEMY";
692 DBG_DP << test_location <<
" is NOT REACHABLE";
699 for(
s = 0;
s != 6; ++
s) {
700 if(tiles[
s] != REACH) {
707 DBG_DP <<
"Tried completely surrounding";
710 names.push_back(std::move(name));
715 for(
int i = 0, cap1 = 0; cap1 != 6; ++cap1) {
716 if(tiles[
i] != REACH) {
717 std::ostringstream stream;
726 if(tiles[
i] == ENEMY) {
727 suffix =
".png~RC(magenta>"+enemy_color+
")~O("+border_opacity+
"%)";
729 suffix =
".png~RC(magenta>"+color+
")~O("+border_opacity+
"%)";
732 for(
int cap2 = 0; tiles[
i] != REACH && cap2 != 6;
i = (
i + 1) % 6, ++cap2) {
735 DBG_DP <<
"Image does not exist: " << stream.str() +
".png on " <<
loc;
748 names.push_back(name + suffix);
756 std::vector<texture> res;
758 for(
const std::string& name :
names) {
759 DBG_DP <<
"Pushing: " << name;
761 res.push_back(std::move(tex));
const std::vector< map_location > & route_
std::vector< std::string > names
A config object defines a single node in a WML file, with access to child nodes.
Abstract class for exposing game data that doesn't depend on the GUI, however which for historical re...
const unit * get_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false) const
virtual const gamemap & map() const =0
virtual const unit_map & units() const =0
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
const team & viewing_team() const
bool map_screenshot_
Used to indicate to drawing functions that we are doing a map screenshot.
void draw_text_in_hex(const map_location &loc, const drawing_layer layer, const std::string &text, std::size_t font_size, color_t color, double x_in_hex=0.5, double y_in_hex=0.5)
Draw text on a hex.
std::size_t viewing_team_index_
std::map< map_location, std::vector< overlay > > overlay_map
map_location selectedHex_
void recalculate_minimap()
Schedule the minimap for recalculation.
bool unit_can_draw_here(const map_location &loc, const unit &unit) const
Returns true if there is no exclusive draw request for loc, or if there is, that it's for unit.
virtual void render() override
Update offscreen render buffers.
void fade_tod_mask(const std::string &old, const std::string &new_)
ToD mask smooth fade.
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
double turbo_speed() const
static double get_zoom_factor()
Returns the current zoom factor.
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
void rebuild_all()
Rebuild all dynamic terrain.
virtual void layout() override
Finalize screen layout.
virtual void highlight_hex(map_location hex)
void update_tod(const time_of_day *tod_override=nullptr)
Applies r,g,b coloring to the map.
void process_reachmap_changes()
void scroll_to_tile(const map_location &loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool force=true)
Scroll such that location loc is on-screen.
map_location mouseoverHex_
bool fogged(const map_location &loc) const
Returns true if location (x,y) is covered in fog.
void invalidate_all()
Function to invalidate all tiles.
void drawing_buffer_add(const drawing_layer layer, const map_location &loc, decltype(draw_helper::do_draw) draw_func)
Add an item to the drawing buffer.
std::size_t reach_map_team_index_
const display_context & context() const
rect get_location_rect(const map_location &loc) const
Returns the on-screen rect corresponding to a loc.
std::set< map_location > invalidated_
bool invalidateGameStatus_
virtual void draw_invalidated()
Only called when there's actual redrawing to do.
reports * reports_object_
virtual void update() override
Update animations and internal state.
virtual void draw_hex(const map_location &loc)
Redraws a single gamemap location.
const std::unique_ptr< fake_unit_manager > fake_unit_man_
const display_context * dc_
bool shrouded(const map_location &loc) const
Returns true if location (x,y) is covered in shroud.
void refresh_report(const std::string &report_name, const config *new_cfg=nullptr)
Update the given report.
std::weak_ptr< wb::manager > wb_
virtual void select_hex(map_location hex)
void set_move(double xmove, double ymove)
void set_position(double xpos, double ypos)
void set_lifetime(const std::chrono::milliseconds &lifetime, const std::chrono::milliseconds &fadeout=std::chrono::milliseconds{100})
void set_color(const color_t &color)
void set_scroll_mode(LABEL_SCROLL_MODE scroll)
void set_font_size(int font_size)
unit_map::iterator find_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
virtual void draw_invalidated() override
Only called when there's actual redrawing to do.
void draw_movement_info(const map_location &loc)
Draws the movement info (turns available) for a given location.
void display_unit_hex(map_location hex)
Change the unit to be displayed in the sidebar.
void invalidate_unit_after_move(const map_location &src, const map_location &dst)
Same as invalidate_unit() if moving the displayed unit.
std::string attack_indicator_direction() const
Function to get attack direction suffix.
virtual void highlight_hex(map_location hex) override
Function to highlight a location.
map_location displayedUnitHex_
std::vector< texture > get_reachmap_images(const map_location &loc) const
void scroll_to_leader(int side, SCROLL_TYPE scroll_type=ONSCREEN, bool force=true)
Scrolls to the leader of a certain side.
void set_game_mode(const game_mode mode)
virtual void draw_hex(const map_location &loc) override
Redraws a single gamemap location.
void set_attack_indicator(const map_location &src, const map_location &dst)
Set the attack direction indicator.
const std::unique_ptr< display_chat_manager > chat_man_
pathfind::marked_route route_
virtual void render() override
TLD render() override.
void set_route(const pathfind::marked_route *route)
Sets the route along which footsteps are drawn to show movement of a unit.
virtual overlay_map & get_overlays() override
Inherited from display.
std::set< map_location > units_that_can_reach_goal_
void invalidate_unit()
Function to invalidate that unit status displayed on the sidebar.
virtual void select_hex(map_location hex) override
Function to display a location as selected.
void highlight_reach(const pathfind::paths &paths_list)
Sets the paths that are currently displayed as available for the unit to move along.
void new_turn()
Update lighting settings.
void clear_attack_indicator()
virtual const time_of_day & get_time_of_day(const map_location &loc) const override
void highlight_another_reach(const pathfind::paths &paths_list, const map_location &goal=map_location::null_location())
Add more paths to highlight.
map_location attack_indicator_dst_
game_mode
Sets the linger mode for the display.
@ RUNNING
no linger overlay, show fog and shroud.
bool unhighlight_reach()
Reset highlighting of paths.
void needs_rebuild(bool b)
Sets whether the screen (map visuals) needs to be rebuilt.
bool maybe_rebuild()
Rebuilds the screen if needs_rebuild(true) was previously called, and resets the flag.
virtual void layout() override
TLD layout() override.
virtual bool has_time_area() const override
game_display(game_board &board, std::weak_ptr< wb::manager > wb, reports &reports_object, const std::string &theme_id, const config &level)
virtual void update() override
TLD update() override.
map_location attack_indicator_src_
void float_label(const map_location &loc, const std::string &text, const color_t &color)
Function to float a label above a tile.
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Generic locator abstracting the location of an image.
static const int UNREACHABLE
Magic value that signifies a hex is unreachable.
std::string reach_map_color()
std::string reach_map_enemy_color()
const std::set< std::string > & report_list()
Wrapper class to encapsulate creation and management of an SDL_Texture.
bool has_time_area() const
const time_of_day & get_time_of_day(int for_turn=0) const
Returns global time of day for the passed turn.
const time_of_day & get_previous_time_of_day() const
void redraw_unit(const unit &u) const
draw a unit.
unit_iterator find(std::size_t id)
unit_iterator find_leader(int side)
This class represents a single unit of a specific type.
Drawing functions, for drawing things on the screen.
@ linger_overlay
The overlay used for the linger mode.
@ reachmap_highlight
Overlay on reachable hexes.
@ footsteps
Footsteps showing path from unit to mouse.
@ attack_indicator
Layer which holds the attack indicator.
@ reachmap_border
Overlay border of reachable hexes.
@ mouseover_top
Top half of image following the mouse.
@ mouseover_bottom
Bottom half of image following the mouse.
@ move_info
Movement info (defense%, etc...)
@ selected_hex
Image on the selected unit.
static lg::log_domain log_engine("engine")
static lg::log_domain log_display("display")
int side() const
The side this unit belongs to.
T end(const std::pair< T, T > &p)
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
bool tiles_adjacent(const map_location &a, const map_location &b)
Function which tells if two locations are adjacent.
Standard logging facilities (interface).
bool is_shrouded(const display *disp, const map_location &loc)
Our definition of map labels being obscured is if the tile is obscured, or the tile below is obscured...
void blit(const texture &tex, const SDL_Rect &dst)
Draws a texture, or part of a texture, at the given location.
const int SIZE_FLOAT_LABEL
const color_t YELLOW_COLOR
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
const color_t NORMAL_COLOR
std::string foot_teleport_enter
std::vector< std::string > foot_speed_prefix
std::string foot_teleport_exit
int reach_map_border_opacity
std::string reach_map_prefix
int reach_map_tint_opacity
color_t red_to_green(double val, bool for_text)
Return a color corresponding to the value val red for val=0.0 to green for val=100....
Functions to load and save images from/to disk.
bool exists(const image::locator &i_locator)
Returns true if the given image actually exists, without loading it.
@ HEXED
Standard hexagonal tile mask applied, removing portions that don't fit.
@ TOD_COLORED
Same as HEXED, but with Time of Day color tint applied.
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
Unit and team statistics.
::tod_manager * tod_manager
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
std::string::const_iterator iterator
rect dst
Location on the final composed sheet.
rect src
Non-transparent portion of the surface to compose.
The basic class for representing 8-bit RGB or RGBA colour values.
Encapsulates the map of the game.
static std::string write_direction(direction dir)
direction
Valid directions which can be moved in our hexagonal world.
static const map_location & null_location()
Structure which holds a single route and marks for special events.
std::vector< map_location > & steps
std::vector< map_location > get_path(const const_iterator &) const
Returns the path going from the source point (included) to the destination point j (excluded).
bool contains(const map_location &) const
const_iterator find(const map_location &) const
Object which contains all the possible locations a unit can move to, with associated best routes to t...
An abstract description of a rectangle with integer coordinates.
constexpr point center() const
The center point of the rectangle, accounting for origin.
Object which defines a time of day with associated bonuses, image, sounds etc.
std::string image_mask
The image that is to be laid over all images while this time of day lasts.
Applies the planned unit map for the duration of the struct's life.
static map_location::direction s