diff --git a/changelog b/changelog index 7894d18aa48..f5eeb73fc33 100644 --- a/changelog +++ b/changelog @@ -12,6 +12,8 @@ Trunk (1.1.3+svn): description for Illuminate in Help. * WML engine * modify ranged animation timing, all animations (attack, defend, missile + * leading_image is deprecated please use the new [leading_anim] animation + block have the same clock) * multiplayer maps: * revised multiplayer maps: Charge diff --git a/data/campaigns/Eastern_Invasion/units/Lord.cfg b/data/campaigns/Eastern_Invasion/units/Lord.cfg index 0082c2c5893..e564521e7c8 100644 --- a/data/campaigns/Eastern_Invasion/units/Lord.cfg +++ b/data/campaigns/Eastern_Invasion/units/Lord.cfg @@ -17,7 +17,13 @@ image="konrad-lord-bow-defend.png" [/frame] [/defend] - image_leading="konrad-lord-leading.png" + [leading_anim] + [frame] + begin=-150 + end=150 + image="konrad-lord-leading.png" + [/frame] + [/leading_anim] profile=portraits/konrad.png hitpoints=68 [abilities] @@ -169,7 +175,13 @@ image="konrad-lord-defend.png" [/frame] [/defend] - image_leading="konrad-lord-leading.png" + [leading_anim] + [frame] + begin=-150 + end=150 + image="konrad-lord-leading.png" + [/frame] + [/leading_anim] profile=portraits/konrad.png hitpoints=68 [abilities] diff --git a/data/units/Drake_Flameheart.cfg b/data/units/Drake_Flameheart.cfg index 325d589621f..1988c4d9359 100644 --- a/data/units/Drake_Flameheart.cfg +++ b/data/units/Drake_Flameheart.cfg @@ -3,7 +3,13 @@ name= _ "Drake Flameheart" race=drake image="units/drakes/flameheart.png" - image_leading="units/drakes/flameheart-lead.png" + [leading_anim] + [frame] + begin=-150 + end=150 + image="units/drakes/flameheart-lead.png" + [/frame] + [/leading_anim] profile="portraits/core/Alex_Jarocha-Ernst/drake-burner.png" hitpoints=72 movement_type=drakefly diff --git a/data/units/Drake_Flare.cfg b/data/units/Drake_Flare.cfg index 76c52cdd898..350a8e76f91 100644 --- a/data/units/Drake_Flare.cfg +++ b/data/units/Drake_Flare.cfg @@ -3,7 +3,13 @@ name= _ "Drake Flare" race=drake image="units/drakes/flare.png" - image_leading="units/drakes/flare-lead.png" + [leading_anim] + [frame] + begin=-150 + end=150 + image="units/drakes/flare-lead.png" + [/frame] + [/leading_anim] profile="portraits/core/Alex_Jarocha-Ernst/drake-burner.png" hitpoints=54 movement_type=drakefly diff --git a/data/units/Elvish_Captain.cfg b/data/units/Elvish_Captain.cfg index df4d5225491..579e2de6f6f 100644 --- a/data/units/Elvish_Captain.cfg +++ b/data/units/Elvish_Captain.cfg @@ -4,7 +4,13 @@ race=elf image="units/elves-wood/captain.png" image_long="units/elves-wood/captain-bow.png" - image_leading="units/elves-wood/captain-leading.png" + [leading_anim] + [frame] + begin=-150 + end=150 + image="units/elves-wood/captain-leading.png" + [/frame] + [/leading_anim] flag_rgb=230,0,64,138,0,35,72,0,6,60,20,4,255,91,156,196,68,4,132,28,4 hitpoints=47 movement_type=woodland diff --git a/data/units/Elvish_Marshal.cfg b/data/units/Elvish_Marshal.cfg index 47cae835c39..920406c8ce6 100644 --- a/data/units/Elvish_Marshal.cfg +++ b/data/units/Elvish_Marshal.cfg @@ -4,7 +4,13 @@ race=elf image="units/elves-wood/marshal.png" image_long="units/elves-wood/marshal-bow.png" - image_leading="units/elves-wood/marshal-leading.png" + [leading_anim] + [frame] + begin=-150 + end=150 + image="units/elves-wood/marshal-leading.png" + [/frame] + [/leading_anim] flag_rgb=16,24,57,24,57,115,49,99,181,115,173,231,181,222,255 hitpoints=62 movement_type=woodland diff --git a/data/units/Goblin_Rouser.cfg b/data/units/Goblin_Rouser.cfg index adc2a939519..e45bfda3f6d 100644 --- a/data/units/Goblin_Rouser.cfg +++ b/data/units/Goblin_Rouser.cfg @@ -3,7 +3,13 @@ name= _ "Goblin Rouser" race=goblin image=units/goblins/rouser.png - image_leading=units/goblins/rouser-leading.png + [leading_anim] + [frame] + begin=-150 + end=150 + image=units/goblins/rouser-leading.png + [/frame] + [/leading_anim] hitpoints=26 movement_type=orcishfoot movement=4 diff --git a/data/units/Human_Loyalist_General.cfg b/data/units/Human_Loyalist_General.cfg index 45d69ee52e9..897d4173eb9 100644 --- a/data/units/Human_Loyalist_General.cfg +++ b/data/units/Human_Loyalist_General.cfg @@ -3,7 +3,13 @@ name= _ "General" race=human image="units/human-loyalists/general.png" - image_leading="units/human-loyalists/general-leading.png" + [leading_anim] + [frame] + begin=-150 + end=150 + image="units/human-loyalists/general-leading.png" + [/frame] + [/leading_anim] #ifdef CAMPAIGN_EASTERN_INVASION profile=portraits/gweddry.png #endif diff --git a/data/units/Human_Loyalist_Grand_Marshal.cfg b/data/units/Human_Loyalist_Grand_Marshal.cfg index 70c13b2d5cb..5abb221f2c5 100644 --- a/data/units/Human_Loyalist_Grand_Marshal.cfg +++ b/data/units/Human_Loyalist_Grand_Marshal.cfg @@ -3,7 +3,13 @@ name= _ "Grand Marshal" race=human image="units/human-loyalists/marshal.png" - image_leading="units/human-loyalists/marshal-leading.png" + [leading_anim] + [frame] + begin=-150 + end=150 + image="units/human-loyalists/marshal-leading.png" + [/frame] + [/leading_anim] #ifdef CAMPAIGN_EASTERN_INVASION profile=portraits/gweddry.png #endif diff --git a/data/units/Human_Loyalist_Lieutenant.cfg b/data/units/Human_Loyalist_Lieutenant.cfg index 5a8d404e244..28644ff680b 100644 --- a/data/units/Human_Loyalist_Lieutenant.cfg +++ b/data/units/Human_Loyalist_Lieutenant.cfg @@ -3,7 +3,13 @@ name= _ "Lieutenant" race=human image="units/human-loyalists/lieutenant.png" - image_leading="units/human-loyalists/lieutenant-leading.png" + [leading_anim] + [frame] + begin=-150 + end=150 + image="units/human-loyalists/lieutenant-leading.png" + [/frame] + [/leading_anim] #ifdef CAMPAIGN_EASTERN_INVASION profile=portraits/gweddry.png #endif diff --git a/data/units/Human_Loyalist_Sergeant.cfg b/data/units/Human_Loyalist_Sergeant.cfg index 799fddb54cf..c2f22db0896 100644 --- a/data/units/Human_Loyalist_Sergeant.cfg +++ b/data/units/Human_Loyalist_Sergeant.cfg @@ -3,7 +3,13 @@ name= _ "Sergeant" race=human image="units/human-loyalists/sergeant.png" - image_leading="units/human-loyalists/sergeant-leading.png" + [leading_anim] + [frame] + begin=-150 + end=150 + image="units/human-loyalists/sergeant-leading.png" + [/frame] + [/leading_anim] #ifdef CAMPAIGN_EASTERN_INVASION profile=portraits/gweddry.png #endif diff --git a/data/units/Undead_Skele_Death_Knight.cfg b/data/units/Undead_Skele_Death_Knight.cfg index 6ec1227a323..41e52df616e 100644 --- a/data/units/Undead_Skele_Death_Knight.cfg +++ b/data/units/Undead_Skele_Death_Knight.cfg @@ -3,7 +3,13 @@ name= _ "Death Knight" race=undead image="units/undead-skeletal/deathknight.png" - image_leading="units/undead-skeletal/deathknight-leading.png" + [leading_anim] + [frame] + begin=-150 + end=150 + image="units/undead-skeletal/deathknight-leading.png" + [/frame] + [/leading_anim] {MAGENTA_IS_THE_TEAM_COLOR} hitpoints=66 movement_type=undeadfoot diff --git a/src/unit.cpp b/src/unit.cpp index f393e2e3c93..29c345657f5 100644 --- a/src/unit.cpp +++ b/src/unit.cpp @@ -281,6 +281,7 @@ void unit::advance_to(const unit_type* t) death_animations_ = t->death_animations_; movement_animations_ = t->movement_animations_; standing_animations_ = t->standing_animations_; + leading_animations_ = t->leading_animations_; flag_rgb_ = t->flag_rgb(); backup_state(); @@ -1095,6 +1096,14 @@ void unit::read(const config& cfg) standing_animations_.push_back(standing_animation(absolute_image())); // always have a standing animation } + const config::child_list& leading_anims = cfg_.get_children("leading_anim"); + for(config::child_list::const_iterator leading_anim = leading_anims.begin(); leading_anim != leading_anims.end(); ++leading_anim) { + leading_animations_.push_back(leading_animation(**leading_anim)); + } + if(leading_animations_.empty()) { + leading_animations_.push_back(leading_animation(absolute_image())); + // always have a leading animation + } } } void unit::write(config& cfg) const @@ -1340,12 +1349,12 @@ const unit_animation & unit::set_attacking(const display &disp,const gamemap::lo void unit::set_leading(const display &disp,const gamemap::location& loc) { state_ = STATE_LEADING; - draw_bars_ = false; + draw_bars_ = true; if(anim_) { delete anim_; anim_ = NULL; } - anim_ = new unit_animation(image_leading()); + anim_ = new leading_animation(lead_animation(disp.get_map().underlying_union_terrain(loc),facing_)); anim_->start_animation(anim_->get_first_frame_time(),1,disp.turbo()?5:1); frame_begin_time = anim_->get_first_frame_time() -1; anim_->update_current_frame(); @@ -2437,15 +2446,8 @@ const std::string& unit::image_fighting(attack_type::RANGE range) const return absolute_image(); } } -const std::string& unit::image_leading() const -{ - const std::string& val = cfg_["image_leading"]; - if(val.empty()) { - return absolute_image(); - } else { - return val; - } -} + + const std::string& unit::image_healing() const { const std::string& val = cfg_["image_healing"]; @@ -2585,6 +2587,25 @@ const standing_animation& unit::stand_animation(const std::string terrain,gamema return *options[rand()%options.size()]; } +const leading_animation& unit::lead_animation(const std::string terrain,gamemap::location::DIRECTION dir) const +{ + //select one of the matching animations at random + std::vector options; + int max_val = -1; + for(std::vector::const_iterator i = leading_animations_.begin(); i != leading_animations_.end(); ++i) { + int matching = i->matches(terrain,dir); + if(matching == max_val) { + options.push_back(&*i); + } else if(matching > max_val) { + max_val = matching; + options.erase(options.begin(),options.end()); + options.push_back(&*i); + } + } + + wassert(!options.empty()); + return *options[rand()%options.size()]; +} void unit::apply_modifications() @@ -2626,77 +2647,6 @@ void unit::apply_modifications() } } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool unit::invisible(const gamemap::location& loc, const unit_map& units,const std::vector& teams) const { diff --git a/src/unit.hpp b/src/unit.hpp index 7a6141a21e5..5aeeefcd043 100644 --- a/src/unit.hpp +++ b/src/unit.hpp @@ -223,7 +223,6 @@ class unit const std::string& image_halo() const; const std::string& image_profile() const; const std::string& image_fighting(attack_type::RANGE range) const; - const std::string& image_leading() const; const std::string& image_healing() const; const std::string& image_halo_healing() const; const std::string& get_hit_sound() const; @@ -242,6 +241,7 @@ class unit fighting_animation::hit_type hits,const attack_type* attack) const; const movement_animation& move_animation(const std::string terrain,gamemap::location::DIRECTION) const; const standing_animation& stand_animation(const std::string terrain,gamemap::location::DIRECTION) const; + const leading_animation& lead_animation(const std::string terrain,gamemap::location::DIRECTION) const; bool get_ability_bool(const std::string& ability, const gamemap::location& loc) const; unit_ability_list get_abilities(const std::string& ability, const gamemap::location& loc) const; @@ -344,6 +344,8 @@ class unit std::vector movement_animations_; std::vector standing_animations_; + + std::vector leading_animations_; unit_animation *anim_; int frame_begin_time; double offset_; diff --git a/src/unit_animation.hpp b/src/unit_animation.hpp index 418a0e4721d..d90e60b0049 100644 --- a/src/unit_animation.hpp +++ b/src/unit_animation.hpp @@ -101,5 +101,15 @@ class standing_animation:public unit_animation private: }; +class leading_animation:public unit_animation +{ + public: + explicit leading_animation(const config& cfg):unit_animation(cfg){}; + explicit leading_animation(const std::string& image): + unit_animation(image,0,150){}; + + private: +}; + #endif diff --git a/src/unit_display.cpp b/src/unit_display.cpp index 98b3e443102..fe21481e728 100644 --- a/src/unit_display.cpp +++ b/src/unit_display.cpp @@ -292,6 +292,7 @@ bool unit_attack_ranged(display& disp, unit_map& units, !attacker.get_animation()->animation_finished() || !missile_animation.animation_finished() || (leader_loc.valid() && !leader->second.get_animation()->animation_finished())) { + printf("%d %d %d\n",animation_time,missile_animation.get_last_frame_time(),missile_animation.get_animation_time()); const double pos = animation_time < missile_animation.get_first_frame_time()?1.0: double(animation_time)/double(missile_animation.get_first_frame_time()); const int posx = int(pos*xsrc + (1.0-pos)*xdst); @@ -346,6 +347,7 @@ bool unit_attack_ranged(display& disp, unit_map& units, events::pump(); disp.non_turbo_delay(); animation_time = defender.get_animation()->get_animation_time(); + missile_animation.update_current_frame(); } halo::remove(missile_halo); missile_halo = 0; diff --git a/src/unit_types.cpp b/src/unit_types.cpp index 4d63ee03f34..43740412b62 100644 --- a/src/unit_types.cpp +++ b/src/unit_types.cpp @@ -617,7 +617,7 @@ unit_type::unit_type(const unit_type& o) genders_(o.genders_), defensive_animations_(o.defensive_animations_), teleport_animations_(o.teleport_animations_), extra_animations_(o.extra_animations_), death_animations_(o.death_animations_), movement_animations_(o.movement_animations_), - standing_animations_(o.standing_animations_), + standing_animations_(o.standing_animations_),leading_animations_(o.leading_animations_), flag_rgb_(o.flag_rgb_) { gender_types_[0] = o.gender_types_[0] != NULL ? new unit_type(*o.gender_types_[0]) : NULL; @@ -843,6 +843,16 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types, // always have a standing animation } + expanded_cfg = unit_animation::prepare_animation(cfg,"leading_anim"); + const config::child_list& leading_anims = expanded_cfg.get_children("leading_anim"); + for(config::child_list::const_iterator leading_anim = leading_anims.begin(); leading_anim != leading_anims.end(); ++leading_anim) { + leading_animations_.push_back(leading_animation(**leading_anim)); + } + if(leading_animations_.empty()) { + leading_animations_.push_back(leading_animation(image())); + // always have a leading animation + } + flag_rgb_ = string2rgb(cfg["flag_rgb"]); // deprecation messages, only seen when unit is parsed for the first time } diff --git a/src/unit_types.hpp b/src/unit_types.hpp index d5e1f9c7634..bcfea1ce4d5 100644 --- a/src/unit_types.hpp +++ b/src/unit_types.hpp @@ -284,6 +284,8 @@ private: std::vector movement_animations_; std::vector standing_animations_; + + std::vector leading_animations_; std::vector flag_rgb_; };