fix filtering on most fighting animations

This commit is contained in:
Jérémy Rosen 2007-04-18 19:07:46 +00:00
parent 0810205a4d
commit e97d041fd8
8 changed files with 59 additions and 24 deletions

View File

@ -140,6 +140,7 @@ Version 1.3.1+svn:
* fixed Ethiliel not showing up in the scenario "Vengeance" of TSG
* with a move attack action if the moveto event moves the defender Wesnoth
would crash (part 1 of bug #8882)
* fix missing filterings on some animations
Version 1.3.1:
* Campaignd

View File

@ -19,14 +19,14 @@
unit_description= _ "Dwarvish Fighters wield mighty battle axes and hammers, which make them feared opponents in close range combat. They are excellent in mountainous terrain or underground. Though not swift, their power and endurance more than compensate."
die_sound={SOUND_LIST:DWARF_DIE}
{DEFENSE_ANIM_FILTERED "units/dwarves/fighter-defend.png" "units/dwarves/fighter.png" {SOUND_LIST:DWARF_HIT} (
[attack_filter]
[secondary_attack_filter]
name=axe
[/attack_filter]
[/secondary_attack_filter]
)}
{DEFENSE_ANIM_FILTERED "units/dwarves/fighter-hammer-defend.png" "units/dwarves/fighter-hammer.png" {SOUND_LIST:DWARF_HIT} (
[attack_filter]
[secondary_attack_filter]
name=hammer
[/attack_filter]
[/secondary_attack_filter]
)}
[attack]
name=axe

View File

@ -1501,7 +1501,7 @@ void calculate_healing(display& disp, const gamemap& map,
for(std::vector<unit_map::iterator>::iterator heal_anim_it = healers.begin(); heal_anim_it != healers.end(); ++heal_anim_it) {
(*heal_anim_it)->second.set_facing((*heal_anim_it)->first.get_relative_dir(i->first));
(*heal_anim_it)->second.set_healing(disp,(*heal_anim_it)->first);
(*heal_anim_it)->second.set_healing(disp,(*heal_anim_it)->first,healing);
start_time = (*heal_anim_it)->second.get_animation()->get_begin_time();
}
if (healing < 0) {

View File

@ -880,7 +880,7 @@ bool unit::internal_matches_filter(const vconfig& cfg, const gamemap::location&
config unit_cfg;
write(unit_cfg);
//now, match the kids, WML based
for(int i=0; i < wmlcfgs.size(); ++i) {
for(unsigned int i=0; i < wmlcfgs.size(); ++i) {
if(!unit_cfg.matches(wmlcfgs[i].get_parsed_config())) {
return false;
}
@ -1640,25 +1640,25 @@ void unit::set_dying(const display &disp,const gamemap::location& loc,const atta
anim_->start_animation(anim_->get_begin_time(), false, disp.turbo_speed());
frame_begin_time_ = anim_->get_begin_time() -1;
}
void unit::set_healing(const display &disp,const gamemap::location& loc)
void unit::set_healing(const display &disp,const gamemap::location& loc,int healing)
{
state_ = STATE_HEALING;
draw_bars_ = true;
delete anim_;
anim_ = new healing_animation(heal_animation(disp,loc));
anim_ = new healing_animation(heal_animation(disp,loc,healing));
anim_->start_animation(anim_->get_begin_time(), false, disp.turbo_speed());
frame_begin_time_ = anim_->get_begin_time() -1;
}
void unit::set_victorious(const display &disp,const gamemap::location& loc)
void unit::set_victorious(const display &disp,const gamemap::location& loc,const attack_type* attack,const attack_type* secondary_attack)
{
state_ = STATE_VICTORIOUS;
draw_bars_ = false;
delete anim_;
anim_ = new victory_animation(victorious_animation(disp,loc));
anim_ = new victory_animation(victorious_animation(disp,loc,fighting_animation::KILL,attack,secondary_attack));
anim_->start_animation(anim_->get_begin_time(), false, disp.turbo_speed());
frame_begin_time_ = anim_->get_begin_time() -1;
}
@ -2797,13 +2797,14 @@ const leading_animation& unit::lead_animation(const display& disp, const gamemap
}
const victory_animation& unit::victorious_animation(const display& disp, const gamemap::location& loc) const
const victory_animation& unit::victorious_animation(const display& disp, const gamemap::location& loc,
fighting_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 = -1;
for(std::vector<victory_animation>::const_iterator i = victory_animations_.begin(); i != victory_animations_.end(); ++i) {
int matching = i->matches(disp,loc,this);
int matching = i->matches(disp,loc,this,hits,attack,secondary_attack,0,0);
if(matching == max_val) {
options.push_back(&*i);
} else if(matching > max_val) {
@ -2817,13 +2818,13 @@ const victory_animation& unit::victorious_animation(const display& disp, const g
return *options[rand()%options.size()];
}
const healing_animation& unit::heal_animation(const display& disp, const gamemap::location& loc) const
const healing_animation& unit::heal_animation(const display& disp, const gamemap::location& loc,int damage) 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(disp,loc,this);
int matching = i->matches(disp,loc,this,damage);
if(matching == max_val) {
options.push_back(&*i);
} else if(matching > max_val) {

View File

@ -174,7 +174,7 @@ class unit
void set_standing(const display& disp,const gamemap::location& loc, bool with_bars = true);
void set_defending(const display &disp,const gamemap::location& loc, int damage,const attack_type* attack,const attack_type* secondary_attack,int swing_num);
void set_leading(const display& disp,const gamemap::location& loc);
void set_healing(const display& disp,const gamemap::location& loc);
void set_healing(const display& disp,const gamemap::location& loc,int damage);
void set_leveling_in(const display& disp,const gamemap::location& loc);
void set_leveling_out(const display& disp,const gamemap::location& loc);
void set_teleporting (const display& disp,const gamemap::location& loc);
@ -184,7 +184,7 @@ class unit
const unit_animation & set_attacking( const display &disp,const gamemap::location& loc,int damage,const attack_type& type,const attack_type* secondary_attack,int swing_num);
void set_recruited(const display& disp,const gamemap::location& loc);
void set_healed(const display& disp,const gamemap::location& loc,int healing);
void set_victorious(const display &disp,const gamemap::location& loc);
void set_victorious(const display &disp,const gamemap::location& loc,const attack_type* attack,const attack_type* secondary_attack);
void set_poisoned(const display& disp,const gamemap::location& loc,int damage);
void set_idling(const display& disp,const gamemap::location& loc);
void restart_animation(const display& disp,int start_time);
@ -264,8 +264,9 @@ class unit
const movement_animation& move_animation(const display& disp, const gamemap::location& loc) const;
const standing_animation& stand_animation(const display& disp, const gamemap::location& loc) const;
const leading_animation& lead_animation(const display& disp, const gamemap::location& loc) const;
const healing_animation& heal_animation(const display& disp, const gamemap::location& loc) const;
const victory_animation& victorious_animation(const display& disp, const gamemap::location& loc) const;
const healing_animation& heal_animation(const display& disp, const gamemap::location& loc,int damage) const;
const victory_animation& victorious_animation(const display& disp, const gamemap::location& loc,
fighting_animation::hit_type hits,const attack_type* attack,const attack_type* secondary_attack) const;
const recruit_animation& recruiting_animation(const display& disp, const gamemap::location& loc) const;
const idle_animation* idling_animation(const display& disp, const gamemap::location& loc) const;
const levelin_animation& levelingin_animation(const display& disp, const gamemap::location& loc) const;

View File

@ -250,6 +250,7 @@ int fighting_animation::matches(const display& disp, const gamemap::location & l
hit_type hit,const attack_type* attack, const attack_type* secondary_attack,int swing,int damage) const
{
int result = unit_animation::matches(disp,loc,my_unit);
if(result == -1) return -1;
if(hits.empty() == false ) {
if (std::find(hits.begin(),hits.end(),hit)== hits.end()) {
return -1;
@ -277,6 +278,7 @@ int fighting_animation::matches(const display& disp, const gamemap::location & l
}
std::vector<config>::const_iterator myitor;
for(myitor = primary_filter.begin(); myitor != primary_filter.end(); myitor++) {
myitor->debug();
if(!attack->matches_filter(*myitor)) return -1;
result++;
}
@ -285,6 +287,7 @@ int fighting_animation::matches(const display& disp, const gamemap::location & l
return -1;
}
for(myitor = secondary_filter.begin(); myitor != secondary_filter.end(); myitor++) {
myitor->debug();
if(!secondary_attack->matches_filter(*myitor)) return -1;
result++;
}
@ -295,6 +298,7 @@ int fighting_animation::matches(const display& disp, const gamemap::location & l
int poison_animation::matches(const display& disp, const gamemap::location & loc,const unit* my_unit,int damage) const
{
int result = unit_animation::matches(disp,loc,my_unit);
if(result == -1) return -1;
if(damage_.empty() == false ) {
if (std::find(damage_.begin(),damage_.end(),damage)== damage_.end()) {
return -1;
@ -308,6 +312,7 @@ int poison_animation::matches(const display& disp, const gamemap::location & loc
int healed_animation::matches(const display& disp, const gamemap::location & loc,const unit* my_unit,int healing) const
{
int result = unit_animation::matches(disp,loc,my_unit);
if(result == -1) return -1;
if(healing_.empty() == false ) {
if (std::find(healing_.begin(),healing_.end(),healing)== healing_.end()) {
return -1;
@ -318,6 +323,20 @@ int healed_animation::matches(const display& disp, const gamemap::location & loc
return result;
}
int healing_animation::matches(const display& disp, const gamemap::location & loc,const unit* my_unit,int damage) const
{
int result = unit_animation::matches(disp,loc,my_unit);
if(result == -1) return -1;
if(damage_.empty() == false ) {
if (std::find(damage_.begin(),damage_.end(),damage)== damage_.end()) {
return -1;
} else {
result ++;
}
}
return result;
}
poison_animation::poison_animation(const config& cfg) :unit_animation(cfg)
{
std::vector<std::string> damage_str = utils::split(cfg["damage"]);
@ -335,3 +354,13 @@ healed_animation::healed_animation(const config& cfg) :unit_animation(cfg)
healing_.push_back(atoi(damage->c_str()));
}
}
healing_animation::healing_animation(const config& cfg) :unit_animation(cfg)
{
std::vector<std::string> damage_str = utils::split(cfg["damage"]);
std::vector<std::string>::iterator damage;
for(damage=damage_str.begin() ; damage != damage_str.end() ; damage++) {
damage_.push_back(atoi(damage->c_str()));
}
}

View File

@ -127,19 +127,22 @@ class leading_animation:public unit_animation
class healing_animation:public unit_animation
{
public:
explicit healing_animation(const config& cfg):unit_animation(cfg){};
explicit healing_animation(const config& cfg);
explicit healing_animation(int start_time,const unit_frame &frame):
unit_animation(start_time,frame){};
int matches(const display &disp,const gamemap::location& loc,const unit* my_unit,int damage) const;
private:
std::vector<int> damage_;
};
class victory_animation:public unit_animation
class victory_animation:public fighting_animation
{
public:
explicit victory_animation(const config& cfg):unit_animation(cfg){};
explicit victory_animation(const config& cfg):fighting_animation(cfg){};
explicit victory_animation(int start_time,const unit_frame &frame):
unit_animation(start_time,frame){};
fighting_animation(start_time,frame){};
private:
};

View File

@ -79,7 +79,7 @@ static void move_unit_between(display& disp, const gamemap& map, const gamemap::
gamemap::location dst_adjacent[6];
get_adjacent_tiles(b, dst_adjacent);
const int total_mvt_time = 150 * temp_unit.movement_cost(dst_terrain)/acceleration;
const int total_mvt_time = (int)150 * temp_unit.movement_cost(dst_terrain)/acceleration;
const unsigned int start_time = SDL_GetTicks();
int mvt_time = 1;
disp.scroll_to_tiles(a.x,a.y,b.x,b.y,display::ONSCREEN);
@ -192,7 +192,7 @@ const attack_type* attack,const attack_type* secondary_attack, unit* winner)
}
return;
}
winner->set_victorious(disp,loc);
winner->set_victorious(disp,loc,attack,secondary_attack);
int start_time = minimum<int>(loser.get_animation()->get_begin_time(),winner->get_animation()->get_begin_time());
winner->restart_animation(disp,start_time);