implement healing anims
yes, I know, feature freeze and all that, but that's actually the simplest way to fix bug #6231.
This commit is contained in:
parent
521de7641a
commit
564475aa7f
8 changed files with 124 additions and 11 deletions
|
@ -4,6 +4,8 @@ Version 1.1.7+SVN:
|
|||
* fixed a few broken image paths
|
||||
* language and i18n:
|
||||
* updated translations: Czech, Dutch, French, German, Polish, Slovak
|
||||
* Engine changes
|
||||
* added healing anims
|
||||
|
||||
Version 1.1.7:
|
||||
* campaigns
|
||||
|
|
|
@ -7,8 +7,53 @@
|
|||
ellipse="misc/ellipse"
|
||||
profile=portraits/core/Alex_Jarocha-Ernst/elvish-shaman.png
|
||||
{MAGENTA_IS_THE_TEAM_COLOR}
|
||||
image_healing="null"
|
||||
image_halo_healing="units/elves-wood/shaman-heal1.png:65,units/elves-wood/shaman-heal2.png:85,units/elves-wood/shaman-heal3.png:65,units/elves-wood/shaman-heal4.png:65,units/elves-wood/shaman-heal5.png:65,units/elves-wood/shaman-heal6.png:65,units/elves-wood/shaman-heal7.png:65,units/elves-wood/shaman-heal8.png:65,units/elves-wood/shaman-heal9.png:65"
|
||||
[healing_anim]
|
||||
[frame]
|
||||
begin=-290
|
||||
end=-225
|
||||
image="units/elves-wood/shaman-heal1.png"
|
||||
[/frame]
|
||||
[frame]
|
||||
begin=-225
|
||||
end=-160
|
||||
image="units/elves-wood/shaman-heal2.png"
|
||||
[/frame]
|
||||
[frame]
|
||||
begin=-160
|
||||
end=-95
|
||||
image="units/elves-wood/shaman-heal3.png"
|
||||
[/frame]
|
||||
[frame]
|
||||
begin=-95
|
||||
end=-30
|
||||
image="units/elves-wood/shaman-heal4.png"
|
||||
[/frame]
|
||||
[frame]
|
||||
begin=-30
|
||||
end=35
|
||||
image="units/elves-wood/shaman-heal5.png"
|
||||
[/frame]
|
||||
[frame]
|
||||
begin=35
|
||||
end=100
|
||||
image="units/elves-wood/shaman-heal6.png"
|
||||
[/frame]
|
||||
[frame]
|
||||
begin=100
|
||||
end=165
|
||||
image="units/elves-wood/shaman-heal7.png"
|
||||
[/frame]
|
||||
[frame]
|
||||
begin=165
|
||||
end=230
|
||||
image="units/elves-wood/shaman-heal8.png"
|
||||
[/frame]
|
||||
[frame]
|
||||
begin=230
|
||||
end=295
|
||||
image="units/elves-wood/shaman-heal9.png"
|
||||
[/frame]
|
||||
[/healing_anim]
|
||||
hitpoints=26
|
||||
movement_type=woodland
|
||||
movement=5
|
||||
|
|
43
src/unit.cpp
43
src/unit.cpp
|
@ -147,6 +147,8 @@ unit::unit(const unit& o):
|
|||
standing_animations_(o.standing_animations_),
|
||||
|
||||
leading_animations_(o.leading_animations_),
|
||||
|
||||
healing_animations_(o.healing_animations_),
|
||||
anim_(o.anim_),
|
||||
frame_begin_time(o.frame_begin_time),
|
||||
offset_(o.offset_),
|
||||
|
@ -404,6 +406,7 @@ void unit::advance_to(const unit_type* t)
|
|||
movement_animations_ = t->movement_animations_;
|
||||
standing_animations_ = t->standing_animations_;
|
||||
leading_animations_ = t->leading_animations_;
|
||||
healing_animations_ = t->healing_animations_;
|
||||
flag_rgb_ = t->flag_rgb();
|
||||
|
||||
backup_state();
|
||||
|
@ -1219,6 +1222,14 @@ void unit::read(const config& cfg)
|
|||
leading_animations_.push_back(leading_animation(absolute_image()));
|
||||
// always have a leading animation
|
||||
}
|
||||
const config::child_list& healing_anims = cfg_.get_children("healing_anim");
|
||||
for(config::child_list::const_iterator healing_anim = healing_anims.begin(); healing_anim != healing_anims.end(); ++healing_anim) {
|
||||
healing_animations_.push_back(healing_animation(**healing_anim));
|
||||
}
|
||||
if(healing_animations_.empty()) {
|
||||
healing_animations_.push_back(healing_animation(image_healing(),image_halo_healing()));
|
||||
// always have a leading animation
|
||||
}
|
||||
}
|
||||
}
|
||||
void unit::write(config& cfg) const
|
||||
|
@ -1619,7 +1630,7 @@ void unit::set_dying(const display &disp,const gamemap::location& loc,const atta
|
|||
frame_begin_time = anim_->get_first_frame_time() -1;
|
||||
anim_->update_current_frame();
|
||||
}
|
||||
void unit::set_healing(const display &disp,const gamemap::location& /*loc*/)
|
||||
void unit::set_healing(const display &disp,const gamemap::location& loc)
|
||||
{
|
||||
state_ = STATE_HEALING;
|
||||
draw_bars_ = true;
|
||||
|
@ -1627,14 +1638,7 @@ void unit::set_healing(const display &disp,const gamemap::location& /*loc*/)
|
|||
delete anim_;
|
||||
anim_ = NULL;
|
||||
}
|
||||
int duration =0;
|
||||
const std::vector<std::pair<std::string,int> > halos = unit_frame::prepare_halo(image_halo_healing(),0,0);
|
||||
std::vector<std::pair<std::string,int> >::const_iterator cur_halo;
|
||||
for(cur_halo = halos.begin() ; cur_halo != halos.end() ; cur_halo++) {
|
||||
duration += cur_halo->second;
|
||||
}
|
||||
duration = maximum<int>(200,duration);
|
||||
anim_ = new unit_animation(image_healing(),0,duration,"",image_halo_healing(),0);
|
||||
anim_ = new healing_animation(heal_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();
|
||||
|
@ -2728,6 +2732,27 @@ const leading_animation& unit::lead_animation(const std::string terrain,gamemap:
|
|||
}
|
||||
|
||||
|
||||
const healing_animation& unit::heal_animation(const std::string terrain,gamemap::location::DIRECTION dir) const
|
||||
{
|
||||
//select one of the matching animations at random
|
||||
std::vector<const healing_animation*> options;
|
||||
int max_val = -1;
|
||||
for(std::vector<healing_animation>::const_iterator i = healing_animations_.begin(); i != healing_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()
|
||||
{
|
||||
log_scope("apply mods");
|
||||
|
|
|
@ -246,6 +246,7 @@ class unit
|
|||
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;
|
||||
const healing_animation& heal_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;
|
||||
|
@ -351,6 +352,8 @@ class unit
|
|||
std::vector<standing_animation> standing_animations_;
|
||||
|
||||
std::vector<leading_animation> leading_animations_;
|
||||
|
||||
std::vector<healing_animation> healing_animations_;
|
||||
unit_animation *anim_;
|
||||
int frame_begin_time;
|
||||
double offset_;
|
||||
|
|
|
@ -148,6 +148,21 @@ unit_animation::unit_animation(const std::string image, int begin_at, int end_at
|
|||
}
|
||||
}
|
||||
|
||||
unit_animation::unit_animation(const std::string image, const std::string halo,int halo_x,int halo_y)
|
||||
{
|
||||
int duration =0;
|
||||
const std::vector<std::pair<std::string,int> > halos = unit_frame::prepare_halo(halo,0,0);
|
||||
std::vector<std::pair<std::string,int> >::const_iterator cur_halo;
|
||||
for(cur_halo = halos.begin() ; cur_halo != halos.end() ; cur_halo++) {
|
||||
duration += cur_halo->second;
|
||||
}
|
||||
duration = maximum<int>(200,duration);
|
||||
add_frame(0, unit_frame(image,"",0,duration,0,0.0,ftofxp(1),halo,halo_x,halo_y));
|
||||
if (duration != 0) {
|
||||
add_frame(duration);
|
||||
}
|
||||
}
|
||||
|
||||
int unit_animation::matches(const std::string &terrain,const gamemap::location::DIRECTION dir) const
|
||||
{
|
||||
int result = 0;
|
||||
|
|
|
@ -35,6 +35,7 @@ class unit_animation:public animated<unit_frame>
|
|||
explicit unit_animation(const config& cfg,const std::string frame_string ="frame");
|
||||
explicit unit_animation(const std::string image, int begin_at, int end_at,
|
||||
const std::string image_diagonal = "",const std::string halo="",int halo_x=0,int halo_y=0);
|
||||
explicit unit_animation(const std::string image,const std::string halo,int halo_x=0,int halo_y=0);
|
||||
explicit unit_animation(const std::string image);
|
||||
int matches(const std::string &terrain,const gamemap::location::DIRECTION dir) const;
|
||||
|
||||
|
@ -111,5 +112,15 @@ class leading_animation:public unit_animation
|
|||
private:
|
||||
};
|
||||
|
||||
class healing_animation:public unit_animation
|
||||
{
|
||||
public:
|
||||
explicit healing_animation(const config& cfg):unit_animation(cfg){};
|
||||
explicit healing_animation(const std::string& image, const std::string& halo ="",int halo_x=0,int halo_y=0):
|
||||
unit_animation(image,halo,halo_x,halo_y){};
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -618,6 +618,7 @@ unit_type::unit_type(const unit_type& o)
|
|||
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_),leading_animations_(o.leading_animations_),
|
||||
healing_animations_(o.healing_animations_),
|
||||
flag_rgb_(o.flag_rgb_)
|
||||
{
|
||||
gender_types_[0] = o.gender_types_[0] != NULL ? new unit_type(*o.gender_types_[0]) : NULL;
|
||||
|
@ -853,6 +854,15 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
|
|||
// always have a leading animation
|
||||
}
|
||||
|
||||
expanded_cfg = unit_animation::prepare_animation(cfg,"healing_anim");
|
||||
const config::child_list& healing_anims = expanded_cfg.get_children("healing_anim");
|
||||
for(config::child_list::const_iterator healing_anim = healing_anims.begin(); healing_anim != healing_anims.end(); ++healing_anim) {
|
||||
healing_animations_.push_back(healing_animation(**healing_anim));
|
||||
}
|
||||
if(healing_animations_.empty()) {
|
||||
healing_animations_.push_back(healing_animation(cfg["image_healing"],cfg["image_halo_healing"]));
|
||||
// always have a healing animation
|
||||
}
|
||||
flag_rgb_ = string2rgb(cfg["flag_rgb"]);
|
||||
// deprecation messages, only seen when unit is parsed for the first time
|
||||
}
|
||||
|
|
|
@ -286,6 +286,8 @@ private:
|
|||
std::vector<standing_animation> standing_animations_;
|
||||
|
||||
std::vector<leading_animation> leading_animations_;
|
||||
|
||||
std::vector<healing_animation> healing_animations_;
|
||||
std::vector<Uint32> flag_rgb_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue