35 #define LOG_DP LOG_STREAM(info, display)
54 result <<
std::string((text.size()+1)/2,
' ') << number <<
'\n' << text;
119 unit_ptr temp_unit,
unsigned int step_num,
127 temp_unit->set_location(a);
145 target_time -= target_time%200;
162 can_draw_(
disp_ && !
disp_->video().update_locked() &&
163 !
disp_->video().faked() && path.
size() > 1),
165 force_scroll_(force_scroll),
167 wait_until_(INT_MIN),
179 assert(!
path_.empty());
205 if (
disp_ ==
nullptr )
298 u->anim_comp().set_standing(
false);
335 path_index = std::min(path_index,
path_.size()-1);
367 else if (
path_[current_] !=
path_[current_+1] )
374 u->anim_comp().set_standing(
false);
421 u->anim_comp().set_standing(
true);
450 if ( mousehandler ) {
462 u->anim_comp().set_standing(
true);
490 unit_mover mover(path, animate, force_scroll);
510 animator.
add_animation(&attacker,
"draw_weapon",loc,defender_loc,0,
false,
"",0,
unit_animation::HIT,attack,secondary_attack,0);
511 animator.
add_animation(defender,
"draw_weapon",defender_loc,loc,0,
false,
"",0,
unit_animation::MISS,secondary_attack,attack,0);
527 animator.
add_animation(primary_unit,
"sheath_weapon",primary_loc,secondary_loc,0,
false,
"",0,
unit_animation::INVALID,primary_attack,secondary_attack,0);
530 animator.
add_animation(secondary_unit,
"sheath_weapon",secondary_loc,primary_loc,0,
false,
"",0,
unit_animation::INVALID,secondary_attack,primary_attack,0);
533 if(primary_unit || secondary_unit) {
557 animator.
add_animation(&loser,
"death",loc,winner_loc,0,
false,
"",0,
unit_animation::KILL,attack,secondary_attack,0);
559 animator.
add_animation(winner,
"victory",winner_loc,loc,0,
true,
"",0,
575 int swing,
std::string hit_text,
int drain_amount,
std::string att_text,
const std::vector<std::string>* extra_hit_sounds)
591 const unit& attacker = *att;
595 unit &defender = *def;
596 int def_hitpoints = defender.hitpoints();
611 if(damage >= defender.hitpoints()) {
613 }
else if(damage > 0) {
618 animator.
add_animation(&attacker,
"attack", att->get_location(),
619 def->get_location(), damage,
true, text_2,
621 hit_type, &attack, secondary_attack, swing);
624 const unit_animation *defender_anim = def->anim_comp().choose_animation(*disp,
625 def->get_location(),
"defend", att->get_location(), damage,
626 hit_type, &attack, secondary_attack, swing);
627 animator.
add_animation(&defender, defender_anim, def->get_location(),
631 if(ability.second == a)
continue;
632 if(ability.second == b)
continue;
634 assert(leader.
valid());
635 leader->set_facing(ability.second.get_relative_dir(a));
637 att->get_location(), damage,
true,
"", 0,
638 hit_type, &attack, secondary_attack, swing);
641 if(ability.second == a)
continue;
642 if(ability.second == b)
continue;
644 assert(helper.
valid());
645 helper->set_facing(ability.second.get_relative_dir(b));
646 animator.
add_animation(&*helper,
"resistance", ability.second,
647 def->get_location(), damage,
true,
"", 0,
648 hit_type, &attack, secondary_attack, swing);
654 int damage_left = damage;
655 bool extra_hit_sounds_played =
false;
656 while(damage_left > 0 && !animator.
would_end()) {
657 if(!extra_hit_sounds_played && extra_hit_sounds !=
nullptr) {
661 extra_hit_sounds_played =
true;
665 if(step_left < 1) step_left = 1;
666 int removed_hp = damage_left/step_left ;
667 if(removed_hp < 1) removed_hp = 1;
668 defender.take_hit(removed_hp);
669 damage_left -= removed_hp;
674 def->anim_comp().start_animation(animator.
get_end_time(), defender_anim,
true);
676 def->set_hitpoints(def_hitpoints);
688 assert(leader != units.
end());
689 leader->anim_comp().set_standing();
697 assert(helper != units.
end());
698 helper->anim_comp().set_standing();
717 animator.
add_animation(&*leader,
"recruiting", leader_loc, loc, 0,
true);
723 u->set_hidden(
false);
743 for (
unit *
h : healers) {
744 h->set_facing(
h->get_location().get_relative_dir(healed_loc));
746 healed_loc, healing);
754 }
else if ( healing > 0 ) {
806 std::vector<attack_type> attacks = u->attacks();
808 boost::scoped_ptr<attack_type> dummy_primary;
809 boost::scoped_ptr<attack_type> dummy_secondary;
816 if (cfg[
"flag"] ==
"death" || cfg[
"flag"] ==
"victory") {
817 filter = cfg.
child(
"primary_attack");
820 primary = dummy_primary.get();
822 filter = cfg.
child(
"secondary_attack");
825 secondary = dummy_secondary.get();
830 filter = cfg.
child(
"primary_attack");
832 for(itor = attacks.begin(); itor != attacks.end(); ++
itor){
840 filter = cfg.
child(
"secondary_attack");
842 for(itor = attacks.begin(); itor != attacks.end(); ++
itor){
851 if(cfg[
"hits"] ==
"yes" || cfg[
"hits"] ==
"hit") {
854 if(cfg[
"hits"] ==
"no" || cfg[
"hits"] ==
"miss") {
857 if( cfg[
"hits"] ==
"kill" ) {
860 if(cfg[
"red"].empty() && cfg[
"green"].
empty() && cfg[
"blue"].
empty()) {
863 text_color =
display::rgb(cfg[
"red"], cfg[
"green"], cfg[
"blue"]);
868 if(!t_filter.
empty()) {
870 std::set<map_location> locs;
872 if (!locs.empty() && u->get_location() != *locs.begin()) {
875 secondary_loc = u->get_location().get_direction(dir);
883 secondary_loc, cfg[
"value"], cfg[
"with_bars"].to_bool(),
884 text.
str(), text_color, hits, primary, secondary,
885 cfg[
"value_second"]);
888 vconfig::child_list::const_iterator anim_itor;
889 for(anim_itor = sub_anims.begin(); anim_itor != sub_anims.end();++anim_itor) {
bool fogged(const map_location &loc) const
Returns true if location (x,y) is covered in fog.
virtual void select_hex(map_location hex)
virtual const unit_map & units() const
const map_location & get_location() const
static display * get_singleton()
Returns the display object if a display object exists.
void wait_until(int animation_time) const
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
game_display *const disp_
static void teleport_unit_between(const map_location &a, const map_location &b, unit &temp_unit, display &disp)
Animates a teleportation between hexes.
void unit_attack(display *disp, game_board &board, const map_location &a, const map_location &b, int damage, const attack_type &attack, const attack_type *secondary_attack, int swing, std::string hit_text, int drain_amount, std::string att_text, const std::vector< std::string > *extra_hit_sounds)
Make the unit on tile 'a' attack the unit on tile 'b'.
int get_animation_time_potential() const
internal_ptr get_unit_ptr()
Get a copy of the internal unit pointer.
vconfig child(const std::string &key) const
Returns a child of *this whose key is key.
config get_parsed_config() const
void invalidate_unit()
Function to invalidate that unit status displayed on the sidebar.
DIRECTION get_relative_dir(const map_location &loc, map_location::RELATIVE_DIR_MODE mode) const
bool tile_fully_on_screen(const map_location &loc)
Check if a tile is fully visible on screen.
virtual void draw()
Draws invalidated items.
const std::string number
template to number regex
static std::string number_and_text(int number, const std::string &text)
Returns a string whose first line is number, centered over a second line, which consists of text...
Variant for storing WML attributes.
void update_display()
Copy the backbuffer to the framebuffer.
void wml_animation(const vconfig &cfg, const map_location &default_location)
Parse a standard WML for animations and play the corresponding animation.
void play_sound(const std::string &files, channel_group group, unsigned int repeats)
bool blank() const
Tests for an attribute that was never set.
Contains a number of free functions which display units.
GLdouble GLdouble GLdouble b
unit_ptr shown_unit_
The animation potential to wait until. INT_MIN for no wait; INT_MAX to wait for end.
unit_mover(const std::vector< map_location > &path, bool animate=true, bool force_scroll=false)
The path must remain unchanged for the life of this object.
static mouse_handler * get_singleton()
void set_facing(map_location::DIRECTION dir) const
GLsizei const char ** path
const map_location & mouseover_hex() const
bool tiles_adjacent(const map_location &a, const map_location &b)
Function which tells if two locations are adjacent.
void finish(unit_ptr u, map_location::DIRECTION dir=map_location::NDIRECTIONS)
Finishes the display of movement for the supplied unit.
pointer get_shared_ptr() const
void proceed_to(unit_ptr u, size_t path_index, bool update=false, bool wait=true)
Visually moves a unit from the last hex we drew to the one specified by path_index.
void replace_anim_if_invalid(const unit *animated_unit, const std::string &event, const map_location &src=map_location::null_location(), const map_location &dst=map_location::null_location(), const int value=0, bool with_bars=false, const std::string &text="", const Uint32 text_color=0, const unit_animation::hit_type hit_type=unit_animation::INVALID, const attack_type *attack=nullptr, const attack_type *second_attack=nullptr, int value2=0)
child_list get_children(const std::string &key) const
unit_const_ptr first_match_on_map() const
void update_shown_unit()
Switches the display back to *shown_unit_ after animating.
filter_context * filter_con
GLboolean GLboolean GLboolean GLboolean a
fake_unit_manager * fake_units
A class to encapsulate the steps of drawing a unit's move.
void unit_healing(unit &healed, const std::vector< unit * > &healers, int healing, const std::string &extra_text)
This will use a poisoning anim if healing<0.
void invalidate_reachmap()
const std::vector< map_location > & path_
The unit to be (re-)shown after an animation finishes.
void wait_for_anims()
Waits for the final animation of the most recent proceed_to() to finish.
unit_animation_component & anim_comp() const
static const map_location & null_location()
void unit_draw_weapon(const map_location &loc, unit &attacker, const attack_type *attack, const attack_type *secondary_attack, const map_location &defender_loc, unit *defender)
Play a pre-fight animation First unit is the attacker, second unit the defender.
const unit_map & get_units() const
Encapsulates the map of the game.
void unit_die(const map_location &loc, unit &loser, const attack_type *attack, const attack_type *secondary_attack, const map_location &winner_loc, unit *winner)
Show a unit fading out.
unit * get()
Get a raw pointer to the underlying unit.
void replace_temporary(unit_ptr u)
Makes the temporary unit used by this match the supplied unit.
void get_locations(std::set< map_location > &locs, bool with_border=false) const
std::map< std::string, tfilter >::iterator itor
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.
static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
bool update_locked() const
void set_location(const map_location &loc)
To be called by unit_map or for temporary units only.
void scroll_to_tiles(map_location loc1, map_location loc2, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, double add_spacing=0.0, bool force=true)
Scroll such that location loc1 is on-screen.
std::pair< const config *, map_location > unit_ability
The things contained within a unit_ability_list.
const config & get_config() const
unit_map::iterator find_unit(const map_location &loc)
void start(unit_ptr u)
Initiates the display of movement for the supplied unit.
#define log_scope(description)
GLfloat GLfloat GLfloat GLfloat h
DIRECTION
Valid directions which can be moved in our hexagonal world.
void wml_animation_internal(unit_animator &animator, const vconfig &cfg, const map_location &default_location=map_location::null_location())
void add_animation(const unit *animated_unit, const unit_animation *animation, const map_location &src=map_location::null_location(), bool with_bars=false, const std::string &text="", const Uint32 text_color=0)
unit_ability_list get_abilities(const std::string &tag_name, const map_location &loc) const
void reset_helpers(const unit *attacker, const unit *defender)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
void unit_sheath_weapon(const map_location &primary_loc, unit *primary_unit, const attack_type *primary_attack, const attack_type *secondary_attack, const map_location &secondary_loc, unit *secondary_unit)
Play a post-fight animation Both unit can be set to null, only valid units will play their animation...
boost::intrusive_ptr< unit > unit_ptr
void unit_recruited(const map_location &loc, const map_location &leader_loc)
A variable-expanding proxy for the config class.
Standard logging facilities (interface).
fake_unit_ptr temp_unit_ptr_
CVideo & video()
Gets the underlying screen object.
Container associating units to locations.
void set_standing(bool with_bars=true)
Sets the animation state to standing.
unit_iterator find(size_t id)
std::vector< vconfig > child_list
int get_animation_time() const
GLsizei const GLcharARB ** string
void display_unit_hex(map_location hex)
Change the unit to be displayed in the sidebar.
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
Display units performing various actions: moving, attacking, and dying.
void move_unit(const std::vector< map_location > &path, unit_ptr u, bool animate, map_location::DIRECTION dir, bool force_scroll)
Display a unit moving along a given path.
void wait_for_end() const
static game_display * get_singleton()
static int move_unit_between(const map_location &a, const map_location &b, unit_ptr temp_unit, unsigned int step_num, unsigned int step_left, unit_animator &animator, display &disp)
Animates a single step between hexes.