ok, done... attack anim is still an ugly special case,

...but this will have to wait...
This commit is contained in:
Jérémy Rosen 2007-09-01 14:37:20 +00:00
parent 90846dd9ae
commit 77e2f5dc01
6 changed files with 49 additions and 98 deletions

View file

@ -377,6 +377,23 @@ Xu , Qxu , Qxu , Ql , Ql , Ql
text="Win"
[/label]
[label]
x,y=14,9
text="The silly dance"
[/label]
[event]
name="moveto"
first_time_only=no
[filter]
x,y=14,9
[/filter]
[animate_unit]
[/animate_unit]
[allow_undo]
[/allow_undo]
[/event]
[event]
name="moveto"
first_time_only=no

View file

@ -149,8 +149,6 @@ unit::unit(const unit& o):
animations_(o.animations_),
teleport_animations_(o.teleport_animations_),
extra_animations_(o.extra_animations_),
anim_(NULL),
frame_begin_time_(o.frame_begin_time_),
@ -452,10 +450,6 @@ void unit::advance_to(const unit_type* t)
// Remove old animations
cfg_.clear_children("animation");
cfg_.clear_children("defend");
cfg_.clear_children("teleport_anim");
cfg_.clear_children("extra_anim");
cfg_.clear_children("death");
cfg_.clear_children("attack");
cfg_.clear_children("abilities");
// Clear cache of movement costs
@ -505,8 +499,6 @@ void unit::advance_to(const unit_type* t)
animations_ = t->animations_;
teleport_animations_ = t->teleport_animations_;
extra_animations_ = t->extra_animations_;
flag_rgb_ = t->flag_rgb();
backup_state();
@ -1312,17 +1304,7 @@ void unit::read(const config& cfg, bool use_traits)
if(!type_set) {
if(ut) {
animations_ = ut->animations_;
teleport_animations_ = ut->teleport_animations_;
extra_animations_ = ut->extra_animations_;
// Remove animations from private cfg, since they're not needed there now
cfg_.clear_children("animation");
cfg_.clear_children("defend");
cfg_.clear_children("teleport_anim");
cfg_.clear_children("extra_anim");
cfg_.clear_children("death");
cfg_.clear_children("victory_anim");
} else {
const config::child_list& animations = cfg_.get_children("animation");
const config::child_list& recruit_anims = cfg_.get_children("recruit_anim");
@ -1452,21 +1434,21 @@ void unit::read(const config& cfg, bool use_traits)
}
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));
}
if(teleport_animations_.empty()) {
teleport_animations_.push_back(unit_animation(-20,unit_frame(absolute_image(),40)));
// Always have a teleport animation
}
for(config::child_list::const_iterator extra_anim = extra_anims.begin(); extra_anim != extra_anims.end(); ++extra_anim) {
extra_animations_.insert(std::pair<std::string,unit_animation>((**extra_anim)["flag"],unit_animation(**extra_anim)));
(**extra_anim)["apply_to"]=(**extra_anim)["flag"];
animations_.push_back(unit_animation(**extra_anim));
//lg::wml_error<<"extra 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=extra flag\n";
}
for(config::child_list::const_iterator t = teleports.begin(); t != teleports.end(); ++t) {
(**t)["apply_to"]="teleport";
animations_.push_back(unit_animation(**t));
//lg::wml_error<<"teleport 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=teleport flag\n";
}
animations_.push_back(unit_animation(-20,unit_frame(absolute_image(),40),"teleport",unit_animation::DEFAULT_ANIM));
// Always have a teleport animation
}
@ -1666,7 +1648,8 @@ void unit::set_defending(const game_display &disp,const gamemap::location& loc,
void unit::set_extra_anim(const game_display &disp,const gamemap::location& loc, std::string flag)
{
state_ = STATE_EXTRA;
start_animation(disp,loc,extra_animation(disp,loc,flag),false);
printf("aaaaa %s\n",flag.c_str());
start_animation(disp,loc,choose_animation(disp,loc,flag),false);
}
@ -1718,7 +1701,7 @@ void unit::set_poisoned(const game_display &disp,const gamemap::location& loc, i
void unit::set_teleporting(const game_display &disp,const gamemap::location& loc)
{
state_ = STATE_TELEPORT;
start_animation(disp,loc,teleport_animation(disp,loc),false);
start_animation(disp,loc,choose_animation(disp,loc,"teleport"),false);
}
void unit::set_dying(const game_display &disp,const gamemap::location& loc,const attack_type* attack,const attack_type* secondary_attack)
@ -1758,6 +1741,7 @@ void unit::set_idling(const game_display &disp,const gamemap::location& loc)
const unit_animation* unit::start_animation(const game_display &disp, const gamemap::location &loc,const unit_animation * animation,bool with_bars,bool is_attack_anim)
{
if(!animation) {
printf("missed\n");
set_standing(disp,loc,with_bars);
return NULL;
}
@ -2848,46 +2832,6 @@ const std::string& unit::image_fighting(attack_type::RANGE range) const
}
}
const unit_animation* unit::teleport_animation(const game_display& disp, const gamemap::location& loc) const
{
// Select one of the matching animations at random
std::vector<const unit_animation*> options;
int max_val = -3;
for(std::vector<unit_animation>::const_iterator i = teleport_animations_.begin(); i != teleport_animations_.end(); ++i) {
int matching = i->matches(disp,loc,this);
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::extra_animation(const game_display& disp, const gamemap::location& loc,const std::string &flag) const
{
// Select one of the matching animations at random
std::vector<const unit_animation*> options;
int max_val = -3;
std::multimap<std::string,unit_animation>::const_iterator i;
for(i = extra_animations_.lower_bound(flag); i != extra_animations_.upper_bound(flag); ++i) {
int matching = i->second.matches(disp,loc,this);
if(matching == max_val) {
options.push_back(&i->second);
} else if(matching > max_val) {
max_val = matching;
options.erase(options.begin(),options.end());
options.push_back(&i->second);
}
}
if(extra_animations_.lower_bound(flag) == extra_animations_.end()) { 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 unit_animation::hit_type hit,const attack_type* attack,const attack_type* second_attack, int swing_num) const
{

View file

@ -266,8 +266,6 @@ public:
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 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;
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;
@ -375,8 +373,6 @@ private:
// Animations:
std::vector<unit_animation> animations_;
std::vector<unit_animation> teleport_animations_;
std::multimap<std::string,unit_animation> extra_animations_;
unit_animation *anim_;
int next_idling_;
int frame_begin_time_;

View file

@ -168,7 +168,7 @@ unit_animation::unit_animation(const config& cfg,const std::string frame_string
int unit_animation::matches(const game_display &disp,const gamemap::location& loc, const unit* my_unit,const std::string & event,const int value,hit_type hit,const attack_type* attack,const attack_type* second_attack, int swing_num) const
{
int result = base_score_;
if(event_.empty() ==false) {
if(event_.empty() ==false && !event.empty()) {
if (std::find(event_.begin(),event_.end(),event)== event_.end()) {
return MATCH_FAIL;
} else {

View file

@ -508,7 +508,6 @@ unit_type::unit_type(const unit_type& o)
movementType_(o.movementType_), possibleTraits_(o.possibleTraits_),
genders_(o.genders_), animations_(o.animations_),
teleport_animations_(o.teleport_animations_), extra_animations_(o.extra_animations_),
flag_rgb_(o.flag_rgb_)
{
gender_types_[0] = o.gender_types_[0] != NULL ? new unit_type(*o.gender_types_[0]) : NULL;
@ -803,27 +802,24 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
}
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,"extra_anim");
const config::child_list& extra_anims = expanded_cfg.get_children("extra_anim");
for(config::child_list::const_iterator t = extra_anims.begin(); t != extra_anims.end(); ++t) {
(**t)["apply_to"] =(**t)["flag"];
animations_.push_back(unit_animation(**t));
//lg::wml_error<<"extra 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=extra flag\n";
}
expanded_cfg = unit_animation::prepare_animation(cfg,"teleport_anim");
const config::child_list& teleports = expanded_cfg.get_children("teleport_anim");
for(config::child_list::const_iterator t = teleports.begin(); t != teleports.end(); ++t) {
teleport_animations_.push_back(unit_animation(**t));
}
if(teleport_animations_.empty()) {
teleport_animations_.push_back(unit_animation(-20,unit_frame(image(),40)));
// Always have a defensive animation
}
expanded_cfg = unit_animation::prepare_animation(cfg,"extra_anim");
const config::child_list& extra_anims = expanded_cfg.get_children("extra_anim");
{
for(config::child_list::const_iterator t = extra_anims.begin(); t != extra_anims.end(); ++t) {
extra_animations_.insert(std::pair<std::string,unit_animation>((**t)["flag"],unit_animation(**t)));
}
(**t)["apply_to"] ="teleport";
animations_.push_back(unit_animation(**t));
//lg::wml_error<<"teleport 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=teleport flag\n";
}
animations_.push_back(unit_animation(-20,unit_frame(image(),40),"teleport",unit_animation::DEFAULT_ANIM));
// Always have a defensive animation
flag_rgb_ = cfg["flag_rgb"];
game_config::add_color_info(cfg);

View file

@ -274,8 +274,6 @@ private:
// animations
std::vector<unit_animation> animations_;
std::vector<unit_animation> teleport_animations_;
std::multimap<std::string,unit_animation> extra_animations_;
std::string flag_rgb_;
};