45 std::unique_ptr<image::locator> get_orb_image(
orb_status os)
66 dc(disp.get_disp_context()),
69 halo_man(thedisp.get_halo_manager()),
70 viewing_team(disp.viewing_team()),
71 playing_team(disp.playing_team()),
72 viewing_team_ref(teams[viewing_team]),
73 playing_team_ref(teams[playing_team]),
74 is_blindfolded(disp.is_blindfolded()),
75 show_everything(disp.show_everything()),
76 sel_hex(disp.selected_hex()),
77 mouse_hex(disp.mouseover_hex()),
78 zoom_factor(disp.get_zoom_factor()),
79 hex_size(disp.hex_size()),
80 hex_size_by_2(disp.hex_size()/2)
119 const bool is_selected_hex = (loc ==
sel_hex || is_highlighted_enemy);
124 ac.
anim_->update_last_draw_time();
131 if (!ac.
anim_)
return;
137 ac.
anim_->update_last_draw_time();
154 if (is_flying && height_adjust < 0) {
157 params.
y -= height_adjust;
158 params.
halo_y -= height_adjust;
160 int red = 0,green = 0,blue = 0,tints = 0;
161 double blend_ratio = 0;
200 const int x =
static_cast<int>(adjusted_params.offset * xdst + (1.0-adjusted_params.offset) * xsrc) +
hex_size_by_2;
201 const int y =
static_cast<int>(adjusted_params.offset * ydst + (1.0-adjusted_params.offset) * ysrc) +
hex_size_by_2;
210 }
else if(has_halo) {
220 surface ellipse_front(
nullptr);
222 int ellipse_floating = 0;
225 if(adjusted_params.submerge > 0.0) {
229 ellipse_floating =
static_cast<int>(adjusted_params.submerge *
hex_size_by_2);
233 ellipse=
"misc/ellipse";
236 if(ellipse !=
"none") {
238 const std::string nozoc = !emit_zoc ?
"nozoc-" :
"";
239 const std::string leader = can_recruit ?
"leader-" :
"";
240 const std::string
selected = is_selected_hex?
"selected-" :
"";
243 const std::string ellipse_top =
formatter() << ellipse <<
"-" << leader << nozoc << selected <<
"top.png~RC(ellipse_red>" << tc <<
")";
244 const std::string ellipse_bot =
formatter() << ellipse <<
"-" << leader << nozoc << selected <<
"bottom.png~RC(ellipse_red>" << tc <<
")";
251 if (ellipse_back !=
nullptr) {
254 xsrc, ysrc +adjusted_params.
y-ellipse_floating, ellipse_back);
257 if (ellipse_front !=
nullptr) {
260 xsrc, ysrc +adjusted_params.
y-ellipse_floating, ellipse_front);
264 const auto& cfg_offset_x = type_cfg[
"bar_offset_x"];
265 const auto& cfg_offset_y = type_cfg[
"bar_offset_y"];
268 if(cfg_offset_x.empty() && cfg_offset_y.empty()) {
270 xoff = !unit_img ? 0 : (
hex_size - unit_img->w)/2;
271 yoff = !unit_img ? 0 : (
hex_size - unit_img->h)/2;
274 xoff = cfg_offset_x.to_int();
275 yoff = cfg_offset_y.to_int();
281 std::unique_ptr<image::locator> orb_img =
nullptr;
285 }
else if(static_cast<std::size_t>(side) !=
playing_team + 1) {
292 orb_img = get_orb_image(os);
297 orb_img = get_orb_image(os);
300 if(orb_img !=
nullptr) {
305 double unit_energy = 0.0;
306 if(max_hitpoints > 0) {
307 unit_energy =
static_cast<double>(hitpoints)/static_cast<double>(max_hitpoints);
309 const int bar_shift =
static_cast<int>(-5*
zoom_factor);
310 const int hp_bar_height =
static_cast<int>(max_hitpoints * u.
hp_bar_scaling());
314 draw_bar(*energy_file, xsrc+xoff+bar_shift, ysrc+yoff+adjusted_params.y,
315 loc, hp_bar_height, unit_energy,hp_color, bar_alpha);
317 if(experience > 0 && can_advance) {
318 const double filled =
static_cast<double>(experience) / static_cast<double>(max_experience);
319 const int xp_bar_height =
static_cast<int>(max_experience * u.
xp_bar_scaling() / std::max<int>(u.
level(),1));
321 draw_bar(*energy_file, xsrc+xoff, ysrc+yoff+adjusted_params.y,
322 loc, xp_bar_height, filled, xp_color, bar_alpha);
329 loc, xsrc+xoff, ysrc+yoff+adjusted_params.
y, crown);
333 for(
const std::string& ov : u.
overlays()) {
335 if(ov_img !=
nullptr) {
337 loc, xsrc+xoff, ysrc+yoff+adjusted_params.
y, ov_img);
350 int height_adjust_unit =
static_cast<int>(terrain_info.
unit_height_adjust() * (1.0 - adjusted_params.offset) +
352 if (is_flying && height_adjust_unit < 0) {
353 height_adjust_unit = 0;
355 params.
y -= height_adjust_unit - height_adjust;
356 params.
halo_y -= height_adjust_unit - height_adjust;
363 const map_location& loc, std::size_t height,
double filled,
364 const color_t& col, int32_t alpha)
const 367 filled = std::min<double>(std::max<double>(filled,0.0),1.0);
368 height =
static_cast<std::size_t
>(height*
zoom_factor);
376 if(surf ==
nullptr || bar_surf ==
nullptr) {
385 if (surf->w == bar_surf->w && surf->h == bar_surf->h)
386 bar_loc = unscaled_bar_loc;
390 const SDL_Rect scaled_bar_loc {
396 bar_loc = scaled_bar_loc;
399 if(height > static_cast<std::size_t>(bar_loc.h)) {
403 const std::size_t skip_rows = bar_loc.h - height;
405 SDL_Rect top {0, 0, surf->w, bar_loc.y};
407 bot.h = surf->w - bot.y;
412 std::size_t unfilled =
static_cast<std::size_t
>(height * (1.0 - filled));
416 surface filled_surf(bar_loc.w, height - unfilled);
424 bool operator()(uint32_t color)
const {
return (color&0xFF000000) > 0x10000000 &&
425 (color&0x00FF0000) < 0x00100000 &&
426 (color&0x0000FF00) < 0x00001000 &&
427 (color&0x000000FF) < 0x00000010; }
432 const std::map<surface,SDL_Rect>::const_iterator
i = energy_bar_rects.find(surf);
433 if(i != energy_bar_rects.end()) {
437 int first_row = -1, last_row = -1, first_col = -1, last_col = -1;
440 const uint32_t*
const begin = image_lock.
pixels();
442 for(
int y = 0; y != surf->h; ++y) {
443 const uint32_t*
const i1 = begin + surf->w*y;
444 const uint32_t*
const i2 = i1 + surf->w;
449 if(first_row == -1) {
453 first_col = itor - i1;
454 last_col = first_col + count;
463 , last_row+1-first_row
465 energy_bar_rects.emplace(surf, res);
surface get_image(const image::locator &i_locator, TYPE type)
Caches and returns an image.
bool refreshing_
avoid infinite recursion.
Reserve layers to be selected for WML.
All parameters from a frame at a given instant.
constexpr int fixed_point_to_int(int32_t n)
If positive, just bit shift.
std::optional< color_t > blend_with
This class represents a single unit of a specific type.
bool is_flying() const
Check if the unit is a flying unit.
bool rects_overlap(const SDL_Rect &rect1, const SDL_Rect &rect2)
Tests whether two rectangles overlap.
const std::set< map_location > & units_that_can_reach_goal() const
Return the locations of units that can reach goal (.
std::unique_ptr< unit_animation > anim_
The current animation.
double unit_submerge() const
int hitpoints() const
The current number of hitpoints this unit has.
Frame for unit's animation sequence.
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
map_location::DIRECTION facing() const
The current direction this unit is facing within its hex.
bool draw_bars_
bool indicating whether to draw bars with the unit
const config & get_cfg() const
Belongs to a friendly side.
std::string image_ellipse() const
Get the unit's ellipse image.
orb_status
Corresponds to the colored orbs displayed above units' hp-bar and xp-bar.
bool get_hidden() const
Gets whether this unit is currently hidden on the map.
double hp_bar_scaling() const
The factor by which the HP bar should be scaled.
map_location get_direction(DIRECTION dir, unsigned int n=1u) const
const unit_type & type() const
This unit's type, accounting for gender and variation.
color_t hp_color() const
Color for this unit's current hitpoints.
bool poisoned() const
Check if the unit has been poisoned.
Belongs to a non-friendly side; normally visualised by not displaying an orb.
static const std::string & leader_crown()
The path to the leader crown overlay.
void clear_haloes()
Clear the haloes associated to the unit.
int unit_height_adjust() const
std::string get_orb_color(orb_status os)
Wrapper for the various preferences::unmoved_color(), moved_color(), etc methods, using the enum inst...
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
const SDL_Rect & calculate_energy_bar(surface surf) const
Finds the start and end rows on the energy bar image.
color_t xp_color() const
Color for this unit's XP.
Unit bars and overlays are drawn on this layer (for testing here).
int max_experience() const
The max number of experience points this unit can have.
bool is_enemy(int n) const
int level() const
The current level of this unit.
map_display and display: classes which take care of displaying the map and game-data on the screen...
std::string default_anim_image() const
The default image to use for animation frames with no defined image.
const std::vector< std::string > & overlays() const
Get the unit's overlay images.
constexpr unsigned fixed_point_multiply(int32_t n1, int32_t n2)
std::set< map_location > units_that_can_reach_goal
Generic locator abstracting the location of an image.
static std::string get_side_color_id(unsigned side)
handle add(int x, int y, const std::string &image, const map_location &loc, halo::ORIENTATION orientation=NORMAL, bool infinite=true)
Add a haloing effect using 'image centered on (x,y).
Image rescaled according to the zoom settings.
Encapsulates the map of the game.
bool invisible(const map_location &loc, bool see_all=true) const
unit_animation_component & anim_comp() const
int max_hitpoints() const
The max number of hitpoints this unit can have.
std::string moved_color()
Helper class for pinning SDL surfaces into memory.
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
int get_location_y(const map_location &loc) const
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
const team & viewing_team_ref
DIRECTION
Valid directions which can be moved in our hexagonal world.
const display_context & dc
All moves and possible attacks have been done.
void set_location(const handle &h, int x, int y)
Set the position of an existing haloing effect, according to its handle.
bool is_visible_to_team(const team &team, bool const see_all=true) const
double xp_bar_scaling() const
The factor by which the XP bar should be scaled.
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an SDL_Rect with the given dimensions.
std::string image_halo() const
Get the unit's halo image.
std::string partial_color()
void drawing_buffer_add(const drawing_layer layer, const map_location &loc, int x, int y, const surface &surf, const SDL_Rect &clip=SDL_Rect())
Add an item to the drawing buffer.
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
Image rescaled to fit into a hexagonal tile according to the zoom settings.
void redraw_unit(const unit &u) const
draw a unit.
unit_drawer(display &thedisp)
int experience() const
The current number of experience points this unit has.
orb_status unit_orb_status(const unit &u) const
Returns an enumurated summary of whether this unit can move and/or attack.
const map_location & get_location() const
The current map location this unit is at.
Functions to load and save images from/to disk.
bool can_advance() const
Checks whether this unit has any options to advance to.
bool incapacitated() const
Check if the unit has been petrified.
The unit can move but can't attack, and wouldn't be able to attack even if it was moved to a hex adja...
halo::handle unit_halo_
handle to the halo of this unit
bool operator()(uint32_t color) const
void draw_bar(const std::string &image, int xpos, int ypos, const map_location &loc, std::size_t height, double filled, const color_t &col, int32_t alpha) const
draw a health/xp bar of a unit
bool emits_zoc() const
Tests whether the unit has a zone-of-control, considering incapacitated.
int side() const
The side this unit belongs to.
bool prefs_show_orb(orb_status os)
Wrapper for the various preferences::show_..._orb() methods, using the enum instead of exposing a sep...
constexpr int32_t fixed_point_divide(int n1, int n2)
void set_standing(bool with_bars=true)
Sets the animation state to standing.
There are still moves and/or attacks possible, but the unit doesn't fit in the "unmoved" status...
std::string orb_two_color
bool slowed() const
Check if the unit has been slowed.
std::string TC_image_mods() const
Constructs a recolor (RC) IPF string for this unit's team color.
constexpr int32_t floating_to_fixed_point(double n)
Converts a double to a fixed point.
boost::tribool primary_frame
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
static std::map< surface, SDL_Rect > energy_bar_rects
void remove(const handle &h)
Remove the halo with the given handle.