fix infinite loop on ranged attack and also add leading anims
yes, yes I know I should do two commits, but I'm really in a hurry right now
This commit is contained in:
parent
0aae47cb83
commit
e715d188b9
18 changed files with 146 additions and 96 deletions
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
114
src/unit.cpp
114
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<const leading_animation*> options;
|
||||
int max_val = -1;
|
||||
for(std::vector<leading_animation>::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<team>& teams) const
|
||||
{
|
||||
|
|
|
@ -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_animation> movement_animations_;
|
||||
|
||||
std::vector<standing_animation> standing_animations_;
|
||||
|
||||
std::vector<leading_animation> leading_animations_;
|
||||
unit_animation *anim_;
|
||||
int frame_begin_time;
|
||||
double offset_;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -284,6 +284,8 @@ private:
|
|||
std::vector<movement_animation> movement_animations_;
|
||||
|
||||
std::vector<standing_animation> standing_animations_;
|
||||
|
||||
std::vector<leading_animation> leading_animations_;
|
||||
std::vector<Uint32> flag_rgb_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue