38 dc(disp.get_disp_context()),
41 halo_man(thedisp.get_halo_manager()),
42 viewing_team(disp.viewing_team()),
43 playing_team(disp.playing_team()),
44 viewing_team_ref(teams[viewing_team]),
45 playing_team_ref(teams[playing_team]),
46 is_blindfolded(disp.is_blindfolded()),
47 show_everything(disp.show_everything()),
48 sel_hex(disp.selected_hex()),
49 mouse_hex(disp.mouseover_hex()),
50 zoom_factor(disp.get_zoom_factor()),
51 hex_size(disp.hex_size()),
52 hex_size_by_2(disp.hex_size()/2)
88 const bool is_selected_hex = (loc ==
sel_hex || is_highlighted_enemy);
93 ac.
anim_->update_last_draw_time();
100 if (!ac.
anim_)
return;
106 ac.
anim_->update_last_draw_time();
123 if (is_flying && height_adjust < 0) {
126 params.
y -= height_adjust;
127 params.
halo_y -= height_adjust;
129 int red = 0,green = 0,blue = 0,tints = 0;
130 double blend_ratio = 0;
169 const int x =
static_cast<int>(adjusted_params.offset * xdst + (1.0-adjusted_params.offset) * xsrc) +
hex_size_by_2;
170 const int y =
static_cast<int>(adjusted_params.offset * ydst + (1.0-adjusted_params.offset) * ysrc) +
hex_size_by_2;
179 }
else if(has_halo) {
189 surface ellipse_front(
nullptr);
191 int ellipse_floating = 0;
194 if(adjusted_params.submerge > 0.0) {
198 ellipse_floating =
static_cast<int>(adjusted_params.submerge *
hex_size_by_2);
202 ellipse=
"misc/ellipse";
205 if(ellipse !=
"none") {
207 const std::string nozoc = !emit_zoc ?
"nozoc-" :
"";
208 const std::string leader = can_recruit ?
"leader-" :
"";
209 const std::string
selected = is_selected_hex?
"selected-" :
"";
212 const std::string ellipse_top =
formatter() << ellipse <<
"-" << leader << nozoc << selected <<
"top.png~RC(ellipse_red>" << tc <<
")";
213 const std::string ellipse_bot =
formatter() << ellipse <<
"-" << leader << nozoc << selected <<
"bottom.png~RC(ellipse_red>" << tc <<
")";
220 if (ellipse_back !=
nullptr) {
223 xsrc, ysrc +adjusted_params.
y-ellipse_floating, ellipse_back);
226 if (ellipse_front !=
nullptr) {
229 xsrc, ysrc +adjusted_params.
y-ellipse_floating, ellipse_front);
235 const auto& cfg_offset_x = type_cfg[
"bar_offset_x"];
236 const auto& cfg_offset_y = type_cfg[
"bar_offset_y"];
239 if(cfg_offset_x.empty() && cfg_offset_y.empty()) {
241 xoff = !unit_img ? 0 : (
hex_size - unit_img->w)/2;
242 yoff = !unit_img ? 0 : (
hex_size - unit_img->h)/2;
245 xoff = cfg_offset_x.to_int();
246 yoff = cfg_offset_y.to_int();
266 orb_img = &enemy_orb;
272 else orb_img =
nullptr;
276 orb_img = &moved_orb;
277 else orb_img =
nullptr;
280 if (movement_left == total_movement) {
282 orb_img = &unmoved_orb;
283 else orb_img =
nullptr;
286 orb_img = &partmoved_orb;
287 else orb_img =
nullptr;
292 if (orb_img !=
nullptr) {
295 loc, xsrc + xoff, ysrc + yoff + adjusted_params.
y, orb);
298 double unit_energy = 0.0;
299 if(max_hitpoints > 0) {
300 unit_energy =
static_cast<double>(hitpoints)/static_cast<double>(max_hitpoints);
302 const int bar_shift =
static_cast<int>(-5*
zoom_factor);
303 const int hp_bar_height =
static_cast<int>(max_hitpoints * u.
hp_bar_scaling());
307 draw_bar(*energy_file, xsrc+xoff+bar_shift, ysrc+yoff+adjusted_params.y,
308 loc, hp_bar_height, unit_energy,hp_color, bar_alpha);
310 if(experience > 0 && can_advance) {
311 const double filled =
static_cast<double>(experience) / static_cast<double>(max_experience);
312 const int xp_bar_height =
static_cast<int>(max_experience * u.
xp_bar_scaling() / std::max<int>(u.
level(),1));
314 draw_bar(*energy_file, xsrc+xoff, ysrc+yoff+adjusted_params.y,
315 loc, xp_bar_height, filled, xp_color, bar_alpha);
325 loc, xsrc+xoff, ysrc+yoff+adjusted_params.
y, crown);
329 for(
const std::string& ov : u.
overlays()) {
331 if(ov_img !=
nullptr) {
333 loc, xsrc+xoff, ysrc+yoff+adjusted_params.
y, ov_img);
344 int height_adjust_unit =
static_cast<int>((terrain_info.
unit_height_adjust() * (1.0 - adjusted_params.offset) +
347 if (is_flying && height_adjust_unit < 0) {
348 height_adjust_unit = 0;
350 params.
y -= height_adjust_unit - height_adjust;
351 params.
halo_y -= height_adjust_unit - height_adjust;
358 const map_location& loc, std::size_t height,
double filled,
362 filled = std::min<double>(std::max<double>(filled,0.0),1.0);
363 height =
static_cast<std::size_t
>(height*
zoom_factor);
371 if(surf ==
nullptr || bar_surf ==
nullptr) {
380 if (surf->w == bar_surf->w && surf->h == bar_surf->h)
381 bar_loc = unscaled_bar_loc;
385 const SDL_Rect scaled_bar_loc {
386 fxptoi(unscaled_bar_loc. x * xratio)
387 ,
fxptoi(unscaled_bar_loc. y * yratio + 127)
388 ,
fxptoi(unscaled_bar_loc.
w * xratio + 255)
389 ,
fxptoi(unscaled_bar_loc.
h * yratio + 255)
391 bar_loc = scaled_bar_loc;
394 if(height > static_cast<std::size_t>(bar_loc.h)) {
405 const std::size_t skip_rows = bar_loc.h - height;
407 SDL_Rect top {0, 0, surf->w, bar_loc.y};
409 bot.h = surf->w - bot.y;
414 std::size_t unfilled =
static_cast<std::size_t
>(height * (1.0 - filled));
416 if(unfilled < height && alpha >=
ftofxp(0.3)) {
417 const uint8_t r_alpha = std::min<unsigned>(unsigned(
fxpmult(alpha,255)),255);
418 surface filled_surf(bar_loc.w, height - unfilled);
426 bool operator()(uint32_t color)
const {
return (color&0xFF000000) > 0x10000000 &&
427 (color&0x00FF0000) < 0x00100000 &&
428 (color&0x0000FF00) < 0x00001000 &&
429 (color&0x000000FF) < 0x00000010; }
434 const std::map<surface,SDL_Rect>::const_iterator
i = energy_bar_rects.find(surf);
435 if(i != energy_bar_rects.end()) {
439 int first_row = -1, last_row = -1, first_col = -1, last_col = -1;
442 const uint32_t*
const begin = image_lock.
pixels();
444 for(
int y = 0; y != surf->h; ++y) {
445 const uint32_t*
const i1 = begin + surf->w*y;
446 const uint32_t*
const i2 = i1 + surf->w;
451 if(first_row == -1) {
455 first_col = itor - i1;
456 last_col = first_col + count;
465 , last_row+1-first_row
467 energy_bar_rects.emplace(surf, res);
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
bool refreshing_
avoid infinite recursion. flag used for drawing / animation
std::string unmoved_color()
Reserve layers to be selected for WML.
All parameters from a frame at a given instant.
This class represents a single unit of a specific type.
#define fxptoi(x)
IN: fixed_t - OUT: int.
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 directin this unit is facing within its hex.
bool draw_bars_
bool indicating whether to draw bars with the unit
const config & get_cfg() const
std::string image_ellipse() const
Get the unit's ellipse image.
bool unit_can_move(const unit &u) const
Will return true iff the unit u has any possible moves it can do (including attacking etc)...
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.
t_translation::terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
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.
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
#define fxpmult(x, y)
IN: unsigned and fixed_t - OUT: unsigned.
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.
#define fxpdiv(x, y)
IN: unsigned and int - OUT: fixed_t.
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.
static const ::config * terrain
The terrain used to create the cache.
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, fixed_t alpha) const
draw a health/xp bar of a unit
std::set< map_location > units_that_can_reach_goal
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).
#define ftofxp(x)
IN: float or int - OUT: fixed_t.
Encapsulates the map of the game.
bool user_end_turn() const
Check whether the user ended their turn.
bool invisible(const map_location &loc, bool see_all=true) const
boost::optional< color_t > blend_with
std::string allied_color()
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
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.
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.
const map_location & get_location() const
The current map location this unit is at.
this module manages the cache of images.
bool can_advance() const
Checks whether this unit has any options to advance to.
bool incapacitated() const
Check if the unit has been petrified.
halo::handle unit_halo_
handle to the halo of this unit
int total_movement() const
The maximum moves this unit has.
bool operator()(uint32_t color) const
bool emits_zoc() const
Tests whether the unit has a zone-of-control, considering incapacitated.
int side() const
The side this unit belongs to.
void set_standing(bool with_bars=true)
Sets the animation state to standing.
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.
boost::tribool primary_frame
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
std::string image_mods() const
Gets an IPF string containing all IPF image mods.
std::string enemy_color()
static std::map< surface, SDL_Rect > energy_bar_rects
void remove(const handle &h)
Remove the halo with the given handle.