32 dc(disp.get_disp_context()),
35 halo_man(thedisp.get_halo_manager()),
36 energy_bar_rects_(bar_rects),
37 viewing_team(disp.viewing_team()),
38 playing_team(disp.playing_team()),
39 viewing_team_ref(
teams[viewing_team]),
40 playing_team_ref(
teams[playing_team]),
41 is_blindfolded(disp.is_blindfolded()),
42 show_everything(disp.show_everything()),
43 sel_hex(disp.selected_hex()),
44 mouse_hex(disp.mouseover_hex()),
45 zoom_factor(disp.get_zoom_factor()),
46 hex_size(disp.hex_size()),
47 hex_size_by_2(disp.hex_size()/2)
82 ac.
anim_->update_last_draw_time();
89 if (!ac.
anim_)
return;
95 ac.
anim_->update_last_draw_time();
113 if (is_flying && height_adjust < 0) {
116 params.
y -= height_adjust;
117 params.
halo_y -= height_adjust;
119 int red = 0,
green = 0,
blue = 0,tints = 0;
120 double blend_ratio = 0;
159 const int x =
static_cast<int>(adjusted_params.offset * xdst + (1.0-adjusted_params.offset) * xsrc) +
hex_size_by_2;
160 const int y =
static_cast<int>(adjusted_params.offset * ydst + (1.0-adjusted_params.offset) * ysrc) +
hex_size_by_2;
169 }
else if(has_halo) {
182 sdl::timage ellipse_front;
183 sdl::timage ellipse_back;
185 surface ellipse_front(
nullptr);
188 int ellipse_floating = 0;
191 if(adjusted_params.submerge > 0.0) {
195 ellipse_floating =
static_cast<int>(adjusted_params.submerge *
hex_size_by_2);
199 ellipse=
"misc/ellipse";
202 if(ellipse !=
"none") {
204 const char*
const nozoc = emit_zoc ?
"" :
"nozoc-";
205 const char*
const leader = can_recruit ?
"leader-" :
"";
212 snprintf(buf,
sizeof(buf),
"%s-%s%s%stop.png~RC(ellipse_red>%s)",ellipse.c_str(),leader,nozoc,
selected,tc.c_str());
214 snprintf(buf,
sizeof(buf),
"%s-%s%s%sbottom.png~RC(ellipse_red>%s)",ellipse.c_str(),leader,nozoc,
selected,tc.c_str());
217 snprintf(buf,
sizeof(buf),
"%s-%s%s%stop.png~RC(ellipse_red>%s)",ellipse.c_str(),leader,nozoc,
selected,tc.c_str());
219 snprintf(buf,
sizeof(buf),
"%s-%s%s%sbottom.png~RC(ellipse_red>%s)",ellipse.c_str(),leader,nozoc,
selected,tc.c_str());
225 if (!ellipse_back.
null()) {
228 xsrc, ysrc +adjusted_params.
y-ellipse_floating, ellipse_back);
231 if (!ellipse_front.
null()) {
234 xsrc, ysrc +adjusted_params.
y-ellipse_floating, ellipse_front);
237 if (ellipse_back !=
nullptr) {
240 xsrc, ysrc +adjusted_params.
y-ellipse_floating, ellipse_back);
243 if (ellipse_front !=
nullptr) {
246 xsrc, ysrc +adjusted_params.
y-ellipse_floating, ellipse_front);
252 const int xoff = (
hex_size - unit_img->w)/2;
253 const int yoff = (
hex_size - unit_img->h)/2;
271 orb_img = &enemy_orb;
277 else orb_img =
nullptr;
281 orb_img = &moved_orb;
282 else orb_img =
nullptr;
285 if (movement_left == total_movement) {
287 orb_img = &unmoved_orb;
288 else orb_img =
nullptr;
291 orb_img = &partmoved_orb;
292 else orb_img =
nullptr;
297 if (orb_img !=
nullptr) {
300 loc, xsrc + xoff, ysrc + yoff + adjusted_params.
y, orb);
303 double unit_energy = 0.0;
304 if(max_hitpoints > 0) {
305 unit_energy = double(hitpoints)/double(max_hitpoints);
307 const int bar_shift =
static_cast<int>(-5*
zoom_factor);
308 const int hp_bar_height =
static_cast<int>(max_hitpoints * u.
hp_bar_scaling());
312 draw_bar(*energy_file, xsrc+xoff+bar_shift, ysrc+yoff+adjusted_params.y,
313 loc, hp_bar_height, unit_energy,hp_color, bar_alpha);
315 if(experience > 0 && can_advance) {
316 const double filled = double(experience)/double(max_experience);
318 const int xp_bar_height =
static_cast<int>(max_experience * u.
xp_bar_scaling() / std::max<int>(u.
level(),1));
320 draw_bar(*energy_file, xsrc+xoff, ysrc+yoff+adjusted_params.y,
321 loc, xp_bar_height, filled, xp_color, bar_alpha);
331 loc, xsrc+xoff, ysrc+yoff+adjusted_params.
y, crown);
335 for(std::vector<std::string>::const_iterator ov = u.
overlays().begin(); ov != u.
overlays().end(); ++ov) {
340 loc, xsrc, ysrc +adjusted_params.
y, ov_img);
344 if(ov_img !=
nullptr) {
346 loc, xsrc+xoff, ysrc+yoff+adjusted_params.
y, ov_img);
358 int height_adjust_unit =
static_cast<int>((terrain_info.
unit_height_adjust() * (1.0 - adjusted_params.offset) +
361 if (is_flying && height_adjust_unit < 0) {
362 height_adjust_unit = 0;
364 params.
y -= height_adjust_unit - height_adjust;
365 params.
halo_y -= height_adjust_unit - height_adjust;
377 filled = std::min<double>(std::max<double>(filled,0.0),1.0);
386 if(surf ==
nullptr || bar_surf ==
nullptr) {
395 if (surf->w == bar_surf->w && surf->h == bar_surf->h)
396 bar_loc = unscaled_bar_loc;
401 fxptoi(unscaled_bar_loc.
x * xratio)
402 ,
fxptoi(unscaled_bar_loc.
y * yratio + 127)
403 ,
fxptoi(unscaled_bar_loc.
w * xratio + 255)
404 ,
fxptoi(unscaled_bar_loc.
h * yratio + 255));
405 bar_loc = scaled_bar_loc;
408 if(height > static_cast<size_t>(bar_loc.h)) {
419 const size_t skip_rows = bar_loc.h -
height;
423 bot.h = surf->w - bot.y;
426 sdl::timage
img(surf);
436 size_t unfilled =
static_cast<size_t>(height * (1.0 - filled));
438 if(unfilled < height && alpha >=
ftofxp(0.3)) {
439 const Uint8 r_alpha = std::min<unsigned>(unsigned(
fxpmult(alpha,255)),255);
442 sdl::fill_rect(filled_surf,&filled_area,SDL_MapRGBA(bar_surf->format,col.r,col.g,col.b, r_alpha));
453 (color&0x00FF0000) < 0x00100000 &&
454 (color&0x0000FF00) < 0x00001000 &&
455 (color&0x000000FF) < 0x00000010; }
465 int first_row = -1, last_row = -1, first_col = -1, last_col = -1;
470 const Uint32*
const begin = image_lock.
pixels();
472 for(
int y = 0;
y != image->h; ++
y) {
473 const Uint32*
const i1 = begin + image->w*
y;
474 const Uint32*
const i2 = i1 + image->w;
479 if(first_row == -1) {
483 first_col = itor - i1;
484 last_col = first_col +
count;
492 , last_row+1-first_row);
std::string image_halo() const
std::string image_mods() const
void drawing_buffer_add(const tdrawing_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.
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
int total_movement() const
std::string unmoved_color()
bool is_visible_to_team(team const &team, gamemap const &map, bool const see_all=true) const
const map_location & get_location() const
void fill_rect(surface &dst, SDL_Rect *dst_rect, const Uint32 color)
Fill a rectangle on a given surface.
int max_hitpoints() const
std::string TC_image_mods() const
bool user_end_turn() const
double hp_bar_scaling() const
bool rects_overlap(const SDL_Rect &rect1, const SDL_Rect &rect2)
Tests whether two rectangles overlap.
double xp_bar_scaling() const
Frame for unit's animation sequence.
#define fxpdiv(x, y)
IN: unsigned and int - OUT: fixed_t.
const Uint32 * pixels() const
bool is_enemy(int n) const
unit_drawer(display &thedisp, std::map< surface, SDL_Rect > &bar_rects)
GLenum GLsizei GLenum GLenum const GLvoid * image
bool draw_bars_
bool indicating whether to draw bars with the unit
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
GLint GLint GLint GLint GLint GLint y
SDL_Color xp_color() const
Colors for the unit's XP.
All parameters from a frame at a given instant.
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)...
Unit bars and overlays are drawn on this layer (for testing here).
int get_location_y(const map_location &loc) const
int unit_height_adjust() const
#define fxptoi(x)
IN: fixed_t - OUT: int.
static std::vector< team > *& teams
bool operator()(Uint32 color) const
static const std::string & leader_crown()
The path to the leader crown overlay.
#define fxpmult(x, y)
IN: unsigned and fixed_t - OUT: unsigned.
bool incapacitated() const
void clear_haloes()
Clear the haloes associated to the unit.
const std::vector< std::string > & overlays() const
GLubyte GLubyte GLubyte GLubyte w
const SDL_Rect & calculate_energy_bar(surface surf) const
Finds the start and end rows on the energy bar image.
GLclampf GLclampf GLclampf alpha
GLenum GLuint GLsizei const char * buf
std::string image_ellipse() const
map_display and display: classes which take care of displaying the map and game-data on the screen...
unit_animation_component & anim_comp() const
int movement_left() const
Returns how far a unit can move this turn (zero if incapacitated).
static const ::config * terrain
The terrain used to create the cache.
GLuint GLuint GLsizei count
double unit_submerge() const
bool invisible(const map_location &loc, bool see_all=true) const
boost::scoped_ptr< unit_animation > anim_
The current animation.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
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).
Encapsulates the map of the game.
const terrain_type & get_terrain_info(const t_translation::t_terrain &terrain) const
std::string default_anim_image() const
The default image to use for animation frames with no defined image.
Reserve layers to be selected for WML.
std::string allied_color()
std::map< std::string, tfilter >::iterator itor
map_location::DIRECTION facing() const
static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
std::string moved_color()
GLfloat GLfloat GLfloat GLfloat h
const team & viewing_team_ref
GLint GLint GLint GLint GLint x
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.
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
t_translation::t_terrain get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
std::string partial_color()
int max_experience() const
SDL_Color hp_color() const
Colors for the unit's current hitpoints.
void draw_bar(const std::string &image, int xpos, int ypos, const map_location &loc, size_t height, double filled, const SDL_Color &col, fixed_t alpha) const
draw a health/xp bar of a unit
surface make_neutral_surface(const surface &surf)
this module manages the cache of images.
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
surface create_compatible_surface(const surface &surf, int width, int height)
map_location get_direction(DIRECTION d, unsigned int n=1u) const
static std::string get_side_color_index(int side)
halo::handle unit_halo_
handle to the halo of this unit
std::map< surface, SDL_Rect > & energy_bar_rects_
void set_standing(bool with_bars=true)
Sets the animation state to standing.
void redraw_unit(const unit &u) const
draw a unit.
GLsizei const GLcharARB ** string
std::string enemy_color()
#define ftofxp(x)
IN: float or int - OUT: fixed_t.
boost::shared_ptr< halo_record > handle
void remove(const handle &h)
Remove the halo with the given handle.