more animations converted... 3 more to go

This commit is contained in:
Jérémy Rosen 2007-09-01 12:48:30 +00:00
parent 797ed9e2cd
commit 90846dd9ae
5 changed files with 61 additions and 173 deletions

View file

@ -149,11 +149,8 @@ unit::unit(const unit& o):
animations_(o.animations_),
defensive_animations_(o.defensive_animations_),
teleport_animations_(o.teleport_animations_),
extra_animations_(o.extra_animations_),
death_animations_(o.death_animations_),
victory_animations_(o.victory_animations_),
anim_(NULL),
frame_begin_time_(o.frame_begin_time_),
@ -508,11 +505,8 @@ void unit::advance_to(const unit_type* t)
animations_ = t->animations_;
defensive_animations_ = t->defensive_animations_;
teleport_animations_ = t->teleport_animations_;
extra_animations_ = t->extra_animations_;
death_animations_ = t->death_animations_;
victory_animations_ = t->victory_animations_;
flag_rgb_ = t->flag_rgb();
backup_state();
@ -1319,11 +1313,8 @@ void unit::read(const config& cfg, bool use_traits)
if(ut) {
animations_ = ut->animations_;
defensive_animations_ = ut->defensive_animations_;
teleport_animations_ = ut->teleport_animations_;
extra_animations_ = ut->extra_animations_;
death_animations_ = ut->death_animations_;
victory_animations_ = ut->victory_animations_;
// Remove animations from private cfg, since they're not needed there now
cfg_.clear_children("animation");
@ -1436,17 +1427,34 @@ void unit::read(const config& cfg, bool use_traits)
}
animations_.push_back(unit_animation(0,unit_frame(absolute_image(),150),"movement",unit_animation::DEFAULT_ANIM));
// Always have a movement animation
for(config::child_list::const_iterator d2 = defends.begin(); d2 != defends.end(); ++d2) {
defensive_animations_.push_back(defensive_animation(**d2));
(**d2)["apply_to"]="defend";
(**d2)["value"]=(**d2)["damage"];
animations_.push_back(unit_animation(**d2));
//lg::wml_error<<"defend animations are deprecate, support will be removed in 1.3.8 (in unit "<<id_<<")\n";
//lg::wml_error<<"please put it with an [animation] tag and apply_to=defend flag\n";
}
if(defensive_animations_.empty()) {
defensive_animations_.push_back(defensive_animation(-150,unit_frame(absolute_image(),300)));
// Always have a defensive animation
animations_.push_back(unit_animation(-150,unit_frame(absolute_image(),300),"defend",unit_animation::DEFAULT_ANIM));
// Always have a defensive animation
for(config::child_list::const_iterator death = deaths.begin(); death != deaths.end(); ++death) {
(**death)["apply_to"]="death";
animations_.push_back(unit_animation(**death));
//lg::wml_error<<"death animations are deprecate, support will be removed in 1.3.8 (in unit "<<id_<<")\n";
//lg::wml_error<<"please put it with an [animation] tag and apply_to=death flag\n";
}
animations_.push_back(unit_animation(0,unit_frame(absolute_image(),10),"death",unit_animation::DEFAULT_ANIM));
// Always have a death animation
for(config::child_list::const_iterator victory_anim = victory_anims.begin(); victory_anim != victory_anims.end(); ++victory_anim) {
(**victory_anim)["apply_to"]="victory";
animations_.push_back(unit_animation(**victory_anim));
//lg::wml_error<<"death animations are deprecate, support will be removed in 1.3.8 (in unit "<<id_<<")\n";
//lg::wml_error<<"please put it with an [animation] tag and apply_to=death flag\n";
}
animations_.push_back(unit_animation(0,unit_frame(absolute_image(),150),"victory",unit_animation::DEFAULT_ANIM));
// Always have a victory animation
for(config::child_list::const_iterator t = teleports.begin(); t != teleports.end(); ++t) {
teleport_animations_.push_back(unit_animation(**t));
@ -1460,23 +1468,6 @@ void unit::read(const config& cfg, bool use_traits)
extra_animations_.insert(std::pair<std::string,unit_animation>((**extra_anim)["flag"],unit_animation(**extra_anim)));
}
for(config::child_list::const_iterator death = deaths.begin(); death != deaths.end(); ++death) {
death_animations_.push_back(death_animation(**death));
}
if(death_animations_.empty()) {
death_animations_.push_back(death_animation(0,unit_frame(absolute_image(),10)));
// Always have a death animation
}
for(config::child_list::const_iterator victory_anim = victory_anims.begin(); victory_anim != victory_anims.end(); ++victory_anim) {
victory_animations_.push_back(victory_animation(**victory_anim));
}
if(victory_animations_.empty()) {
victory_animations_.push_back(victory_animation(0,unit_frame(absolute_image(),150)));
// Always have a victory animation
}
}
} else {
@ -1663,7 +1654,7 @@ void unit::set_defending(const game_display &disp,const gamemap::location& loc,
}else {
hit_type = unit_animation::MISS;
}
start_animation(disp,loc,defend_animation(disp,loc,hit_type,attack,secondary_attack,swing_num,damage),true);
start_animation(disp,loc,choose_animation(disp,loc,"defend",damage,hit_type,attack,secondary_attack,swing_num),true);
// Add a blink on damage effect
const image::locator image_loc = anim_->get_last_frame().image();
@ -1733,7 +1724,7 @@ void unit::set_teleporting(const game_display &disp,const gamemap::location& loc
void unit::set_dying(const game_display &disp,const gamemap::location& loc,const attack_type* attack,const attack_type* secondary_attack)
{
state_ = STATE_DYING;
start_animation(disp,loc,die_animation(disp,loc,unit_animation::KILL,attack,secondary_attack),false);
start_animation(disp,loc,choose_animation(disp,loc,"death",0,unit_animation::KILL,attack,secondary_attack),false);
image::locator image_loc = anim_->get_last_frame().image();
anim_->add_frame(600,unit_frame(image_loc,600,"1~0:600"));
}
@ -1745,7 +1736,7 @@ void unit::set_healing(const game_display &disp,const gamemap::location& loc,int
void unit::set_victorious(const game_display &disp,const gamemap::location& loc,const attack_type* attack,const attack_type* secondary_attack)
{
state_ = STATE_VICTORIOUS;
start_animation(disp,loc,victorious_animation(disp,loc,unit_animation::KILL,attack,secondary_attack),true);
start_animation(disp,loc,choose_animation(disp,loc,"victory",0,unit_animation::KILL,attack,secondary_attack),true);
}
void unit::set_walking(const game_display &disp,const gamemap::location& loc)
@ -2857,26 +2848,6 @@ const std::string& unit::image_fighting(attack_type::RANGE range) const
}
}
const defensive_animation* unit::defend_animation(const game_display& disp, const gamemap::location& loc,
unit_animation::hit_type hits, const attack_type* attack,const attack_type* secondary_attack, int swing_num,int damage) const
{
// Select one of the matching animations at random
std::vector<const defensive_animation*> options;
int max_val = -3;
for(std::vector<defensive_animation>::const_iterator i = defensive_animations_.begin(); i != defensive_animations_.end(); ++i) {
int matching = i->matches(disp,loc,this,"defend",damage,hits,attack,secondary_attack,swing_num);
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);
}
}
if(options.empty()) return NULL;
return options[rand()%options.size()];
}
const unit_animation* unit::teleport_animation(const game_display& disp, const gamemap::location& loc) const
{
// Select one of the matching animations at random
@ -2917,36 +2888,14 @@ const unit_animation* unit::extra_animation(const game_display& disp, const game
return options[rand()%options.size()];
}
const death_animation* unit::die_animation(const game_display& disp, const gamemap::location& loc,
unit_animation::hit_type hits,const attack_type* attack,const attack_type* secondary_attack) const
{
// Select one of the matching animations at random
std::vector<const death_animation*> options;
int max_val = -3;
for(std::vector<death_animation>::const_iterator i = death_animations_.begin(); i != death_animations_.end(); ++i) {
int matching = i->matches(disp,loc,this,"death",0,hits,attack,secondary_attack);
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);
}
}
if(options.empty()) return NULL;
return options[rand()%options.size()];
}
const unit_animation* unit::choose_animation(const game_display& disp, const gamemap::location& loc,const std::string& event,const int value) const
const unit_animation* unit::choose_animation(const game_display& disp, const gamemap::location& loc,const std::string& event,const int value,const unit_animation::hit_type hit,const attack_type* attack,const attack_type* second_attack, int swing_num) const
{
// Select one of the matching animations at random
std::vector<const unit_animation*> options;
int max_val = unit_animation::MATCH_FAIL;
for(std::vector<unit_animation>::const_iterator i = animations_.begin(); i != animations_.end(); ++i) {
int matching = i->matches(disp,loc,this,event,value);
int matching = i->matches(disp,loc,this,event,value,hit,attack,second_attack,swing_num);
if(matching > unit_animation::MATCH_FAIL && matching == max_val) {
options.push_back(&*i);
} else if(matching > max_val) {
@ -2963,27 +2912,6 @@ const unit_animation* unit::choose_animation(const game_display& disp, const gam
}
const victory_animation* unit::victorious_animation(const game_display& disp, const gamemap::location& loc,
unit_animation::hit_type hits,const attack_type* attack,const attack_type* secondary_attack) const
{
// Select one of the matching animations at random
std::vector<const victory_animation*> options;
int max_val = -3;
for(std::vector<victory_animation>::const_iterator i = victory_animations_.begin(); i != victory_animations_.end(); ++i) {
int matching = i->matches(disp,loc,this,"victory",0,hits,attack,secondary_attack,0);
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);
}
}
if(options.empty()) return NULL;
return options[rand()%options.size()];
}
void unit::apply_modifications()
{
log_scope("apply mods");

View file

@ -264,17 +264,10 @@ public:
unit_type::ALIGNMENT alignment() const { return alignment_; }
const std::string& race() const { return race_->name(); }
const unit_animation* choose_animation(const game_display& disp, const gamemap::location& loc,const std::string& event,const int damage=0) const;
const unit_animation* choose_animation(const game_display& disp, const gamemap::location& loc,const std::string& event,const int damage=0,const unit_animation::hit_type hit_type = unit_animation::INVALID,const attack_type* attack=NULL,const attack_type* second_attack = NULL, int swing_num =0) const;
const defensive_animation* defend_animation(const game_display& disp, const gamemap::location& loc,
unit_animation::hit_type hits,const attack_type* attack,
const attack_type* secondary_attack,int swing_num,int damage) const;
const unit_animation* teleport_animation(const game_display& disp, const gamemap::location& loc) const;
const unit_animation* extra_animation(const game_display& disp, const gamemap::location& loc,const std::string &flag) const;
const death_animation* die_animation(const game_display& disp, const gamemap::location& loc,
unit_animation::hit_type hits,const attack_type* attack,const attack_type* secondary_attack) const;
const victory_animation* victorious_animation(const game_display& disp, const gamemap::location& loc,
unit_animation::hit_type hits,const attack_type* attack,const attack_type* secondary_attack) 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;
@ -382,11 +375,8 @@ private:
// Animations:
std::vector<unit_animation> animations_;
std::vector<defensive_animation> defensive_animations_;
std::vector<unit_animation> teleport_animations_;
std::multimap<std::string,unit_animation> extra_animations_;
std::vector<death_animation> death_animations_;
std::vector<victory_animation> victory_animations_;
unit_animation *anim_;
int next_idling_;
int frame_begin_time_;

View file

@ -59,22 +59,6 @@ class unit_animation:public animated<unit_frame>
class defensive_animation:public unit_animation
{
public:
explicit defensive_animation(const config& cfg):unit_animation(cfg){};
explicit defensive_animation(int start_time,const unit_frame &frame):unit_animation(start_time,frame){};
};
class death_animation:public unit_animation
{
public:
explicit death_animation(const config& cfg):unit_animation(cfg){};
explicit death_animation(int start_time,const unit_frame &frame):unit_animation(start_time,frame) {};
private:
};
class attack_animation: public unit_animation
{
public:
@ -86,14 +70,4 @@ class attack_animation: public unit_animation
};
class victory_animation:public unit_animation
{
public:
explicit victory_animation(const config& cfg):unit_animation(cfg){};
explicit victory_animation(int start_time,const unit_frame &frame):
unit_animation(start_time,frame){};
private:
};
#endif

View file

@ -508,10 +508,7 @@ unit_type::unit_type(const unit_type& o)
movementType_(o.movementType_), possibleTraits_(o.possibleTraits_),
genders_(o.genders_), animations_(o.animations_),
defensive_animations_(o.defensive_animations_),
teleport_animations_(o.teleport_animations_), extra_animations_(o.extra_animations_),
death_animations_(o.death_animations_),
victory_animations_(o.victory_animations_),
flag_rgb_(o.flag_rgb_)
{
gender_types_[0] = o.gender_types_[0] != NULL ? new unit_type(*o.gender_types_[0]) : NULL;
@ -775,18 +772,41 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
}
animations_.push_back(unit_animation(0,unit_frame(image(),150),"movement",unit_animation::DEFAULT_ANIM));
// Always have a movement animation
expanded_cfg = unit_animation::prepare_animation(cfg,"defend");
const config::child_list& defends = expanded_cfg.get_children("defend");
for(config::child_list::const_iterator d2 = defends.begin(); d2 != defends.end(); ++d2) {
defensive_animations_.push_back(defensive_animation(**d2));
(**d2)["apply_to"] ="defend";
(**d2)["value"]=(**d2)["damage"];
animations_.push_back(unit_animation(**d2));
//lg::wml_error<<"defend animations are deprecate, support will be removed in 1.3.8 (in unit "<<id()<<")\n";
//lg::wml_error<<"please put it with an [animation] tag and apply_to=defend flag\n";
}
if(defensive_animations_.empty()) {
defensive_animations_.push_back(defensive_animation(-150,unit_frame(image(),300)));
// Always have a defensive animation
animations_.push_back(unit_animation(-150,unit_frame(image(),300),"defend",unit_animation::DEFAULT_ANIM));
// Always have a defensive animation
expanded_cfg = unit_animation::prepare_animation(cfg,"death");
const config::child_list& deaths = expanded_cfg.get_children("death");
for(config::child_list::const_iterator death = deaths.begin(); death != deaths.end(); ++death) {
(**death)["apply_to"] ="death";
animations_.push_back(unit_animation(**death));
//lg::wml_error<<"death animations are deprecate, support will be removed in 1.3.8 (in unit "<<id()<<")\n";
//lg::wml_error<<"please put it with an [animation] tag and apply_to=death flag\n";
}
animations_.push_back(unit_animation(0,unit_frame(image(),10),"death",unit_animation::DEFAULT_ANIM));
// Always have a defensive animation
expanded_cfg = unit_animation::prepare_animation(cfg,"victory_anim");
const config::child_list& victory_anims = expanded_cfg.get_children("victory_anim");
for(config::child_list::const_iterator victory_anim = victory_anims.begin(); victory_anim != victory_anims.end(); ++victory_anim) {
(**victory_anim)["apply_to"] ="victory";
animations_.push_back(unit_animation(**victory_anim));
//lg::wml_error<<"victory animations are deprecate, support will be removed in 1.3.8 (in unit "<<id()<<")\n";
//lg::wml_error<<"please put it with an [animation] tag and apply_to=victory flag\n";
}
animations_.push_back(unit_animation(0,unit_frame(image(),1),"victory",unit_animation::DEFAULT_ANIM));
// Always have a victory animation
expanded_cfg = unit_animation::prepare_animation(cfg,"teleport_anim");
const config::child_list& teleports = expanded_cfg.get_children("teleport_anim");
@ -805,27 +825,6 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
}
}
expanded_cfg = unit_animation::prepare_animation(cfg,"death");
const config::child_list& deaths = expanded_cfg.get_children("death");
for(config::child_list::const_iterator death = deaths.begin(); death != deaths.end(); ++death) {
death_animations_.push_back(death_animation(**death));
}
if(death_animations_.empty()) {
death_animations_.push_back(death_animation(0,unit_frame(image(),10)));
// Always have a defensive animation
}
expanded_cfg = unit_animation::prepare_animation(cfg,"victory_anim");
const config::child_list& victory_anims = expanded_cfg.get_children("victory_anim");
for(config::child_list::const_iterator victory_anim = victory_anims.begin(); victory_anim != victory_anims.end(); ++victory_anim) {
victory_animations_.push_back(victory_animation(**victory_anim));
}
if(victory_animations_.empty()) {
victory_animations_.push_back(victory_animation(0,unit_frame(image(),1)));
// Always have a victory animation
}
flag_rgb_ = cfg["flag_rgb"];
game_config::add_color_info(cfg);
// Deprecation messages, only seen when unit is parsed for the first time.

View file

@ -274,11 +274,8 @@ private:
// animations
std::vector<unit_animation> animations_;
std::vector<defensive_animation> defensive_animations_;
std::vector<unit_animation> teleport_animations_;
std::multimap<std::string,unit_animation> extra_animations_;
std::vector<death_animation> death_animations_;
std::vector<victory_animation> victory_animations_;
std::string flag_rgb_;
};