change animation cycling to be decided by WML instead of hardcoded,

...only visible effect is that drakes should flap their wing properly
in a number of border cases. Please use with caution
This commit is contained in:
Jérémy Rosen 2011-06-12 16:49:21 +00:00
parent 3d66800f6f
commit 30346223aa
6 changed files with 51 additions and 57 deletions

View file

@ -44,6 +44,7 @@ Version 1.9.6+svn:
* Removed the Liminal alignment
* Fixed: a divide by zero in the calculate_map_ownership_function function
* Possibly fixed: rounding errors when using ^ in formulas
* Animation will now cycle according to a WML parameter, use with caution
* Miscellaneous and bugfixes:
* Fixed: issues with singular variant iterators
* Fixed: the Wescamp script download part

View file

@ -1707,10 +1707,10 @@ void unit::set_standing(bool with_bars)
game_display *disp = game_display::get_singleton();
if (preferences::show_standing_animations()&& !incapacitated()) {
start_animation(INT_MAX, choose_animation(*disp, loc_, "standing"),
with_bars, true, "", 0, STATE_STANDING);
with_bars, "", 0, STATE_STANDING);
} else {
start_animation(INT_MAX, choose_animation(*disp, loc_, "_disabled_"),
with_bars, true, "", 0, STATE_STANDING);
with_bars, "", 0, STATE_STANDING);
}
}
@ -1718,21 +1718,21 @@ void unit::set_ghosted(bool with_bars)
{
game_display *disp = game_display::get_singleton();
start_animation(INT_MAX, choose_animation(*disp, loc_, "ghosted"),
with_bars, true);
with_bars);
}
void unit::set_disabled_ghosted(bool with_bars)
{
game_display *disp = game_display::get_singleton();
start_animation(INT_MAX, choose_animation(*disp, loc_, "disabled_ghosted"),
with_bars, true);
with_bars);
}
void unit::set_idling()
{
game_display *disp = game_display::get_singleton();
start_animation(INT_MAX, choose_animation(*disp, loc_, "idling"),
true, false, "", 0, STATE_FORGET);
true, "", 0, STATE_FORGET);
}
void unit::set_selecting()
@ -1740,15 +1740,15 @@ void unit::set_selecting()
const game_display *disp = game_display::get_singleton();
if (preferences::show_standing_animations() && !get_state(STATE_PETRIFIED)) {
start_animation(INT_MAX, choose_animation(*disp, loc_, "selected"),
true, false, "", 0, STATE_FORGET);
true, "", 0, STATE_FORGET);
} else {
start_animation(INT_MAX, choose_animation(*disp, loc_, "_disabled_selected_"),
true, false, "", 0, STATE_FORGET);
true, "", 0, STATE_FORGET);
}
}
void unit::start_animation(int start_time, const unit_animation *animation,
bool with_bars, bool cycles, const std::string &text, Uint32 text_color, STATE state)
bool with_bars, const std::string &text, Uint32 text_color, STATE state)
{
const game_display * disp = game_display::get_singleton();
state_ = state;
@ -1764,7 +1764,7 @@ void unit::start_animation(int start_time, const unit_animation *animation,
anim_ = new unit_animation(*animation);
const int real_start_time = start_time == INT_MAX ? anim_->get_begin_time() : start_time;
anim_->start_animation(real_start_time, loc_, loc_.get_direction(facing_),
cycles, text, text_color, accelerate);
text, text_color, accelerate);
frame_begin_time_ = anim_->get_begin_time() -1;
if (disp->idle_anim()) {
next_idling_ = get_current_animation_tick()

View file

@ -266,7 +266,7 @@ public:
STATE_FORGET, /** animation will be automatically replaced by a standing anim when finished */
STATE_ANIM}; /** normal anims */
void start_animation(int start_time, const unit_animation *animation,
bool with_bars, bool cycles = false, const std::string &text = "",
bool with_bars, const std::string &text = "",
Uint32 text_color = 0, STATE state = STATE_ANIM);
/** The name of the file to game_display (used in menus). */

View file

@ -413,11 +413,9 @@ void unit_animation::fill_initial_animations( std::vector<unit_animation> & anim
animations.back().event_ = utils::split("levelout");
animations.push_back(*itor);
animations.back().unit_anim_.override(0,1);
animations.back().event_ = utils::split("pre_movement");
animations.push_back(*itor);
animations.back().unit_anim_.override(0,1);
animations.back().event_ = utils::split("post_movement");
animations.push_back(*itor);
@ -425,13 +423,12 @@ void unit_animation::fill_initial_animations( std::vector<unit_animation> & anim
animations.back().event_ = utils::split("movement");
animations.push_back(*itor);
animations.back().unit_anim_.override(0,225,"","0.0,0.5:75,0.0:75,0.5:75,0.0",game_display::rgb(255,0,0));
animations.back().unit_anim_.override(0,animations.back().unit_anim_.get_animation_duration(),"","0.0,0.5:75,0.0:75,0.5:75,0.0",game_display::rgb(255,0,0));
animations.back().hits_.push_back(HIT);
animations.back().hits_.push_back(KILL);
animations.back().event_ = utils::split("defend");
animations.push_back(*itor);
animations.back().unit_anim_.override(0,1);
animations.back().event_ = utils::split("defend");
animations.push_back(*itor);
@ -454,7 +451,6 @@ void unit_animation::fill_initial_animations( std::vector<unit_animation> & anim
animations.back().sub_anims_["_death_sound"].add_frame(1,frame_builder().sound(cfg["die_sound"]),true);
animations.push_back(*itor);
animations.back().unit_anim_.override(0,1);
animations.back().event_ = utils::split("victory");
animations.push_back(*itor);
@ -508,19 +504,27 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
animations.push_back(unit_animation(ab.merge()));
}
int default_layer = display::LAYER_UNIT_DEFAULT - display::LAYER_UNIT_FIRST;
int move_layer = display::LAYER_UNIT_MOVE_DEFAULT - display::LAYER_UNIT_FIRST;
int missile_layer = display::LAYER_UNIT_MISSILE_DEFAULT - display::LAYER_UNIT_FIRST;
const int default_layer = display::LAYER_UNIT_DEFAULT - display::LAYER_UNIT_FIRST;
const int move_layer = display::LAYER_UNIT_MOVE_DEFAULT - display::LAYER_UNIT_FIRST;
const int missile_layer = display::LAYER_UNIT_MISSILE_DEFAULT - display::LAYER_UNIT_FIRST;
add_simple_anim(animations, cfg, "resistance_anim", "resistance");
add_simple_anim(animations, cfg, "leading_anim", "leading");
add_simple_anim(animations, cfg, "recruit_anim", "recruited");
add_simple_anim(animations, cfg, "recruiting_anim", "recruiting");
add_simple_anim(animations, cfg, "standing_anim", "standing,default", display::LAYER_UNIT_DEFAULT, false);
add_simple_anim(animations, cfg, "idle_anim", "idling", display::LAYER_UNIT_DEFAULT, false);
add_simple_anim(animations, cfg, "levelin_anim", "levelin");
add_simple_anim(animations, cfg, "levelout_anim", "levelout");
foreach (const animation_branch &ab, prepare_animation(cfg, "standing_anim"))
{
config anim = ab.merge();
anim["apply_to"] = "standing,default";
anim["cycles"] = "true";
if (anim["layer"].empty()) anim["layer"] = default_layer;
if (anim["offscreen"].empty()) anim["offscreen"] = false;
animations.push_back(unit_animation(anim));
}
foreach (const animation_branch &ab, prepare_animation(cfg, "healing_anim"))
{
config anim = ab.merge();
@ -728,6 +732,7 @@ unit_animation::particule::particule(
unit_frame tmp_frame(frame);
add_frame(tmp_frame.duration(),tmp_frame,!tmp_frame.does_not_change());
}
cycles_ = cfg[frame_string+"cycles"].to_bool(false);
parameters_ = frame_parsed_parameters(frame_builder(cfg,frame_string),get_animation_duration());
if(!parameters_.does_not_change() ) {
force_change();
@ -810,7 +815,6 @@ int unit_animation::get_begin_time() const
void unit_animation::start_animation(int start_time
, const map_location &src
, const map_location &dst
, bool cycles
, const std::string& text
, const Uint32 text_color
, const bool accelerate)
@ -818,7 +822,7 @@ void unit_animation::start_animation(int start_time
unit_anim_.accelerate = accelerate;
src_ = src;
dst_ = dst;
unit_anim_.start_animation(start_time, cycles);
unit_anim_.start_animation(start_time);
if(!text.empty()) {
particule crude_build;
crude_build.add_frame(1,frame_builder());
@ -828,7 +832,7 @@ void unit_animation::start_animation(int start_time
std::map<std::string,particule>::iterator anim_itor =sub_anims_.begin();
for( /*null*/; anim_itor != sub_anims_.end() ; ++anim_itor) {
anim_itor->second.accelerate = accelerate;
anim_itor->second.start_animation(start_time,cycles);
anim_itor->second.start_animation(start_time);
}
}
@ -953,12 +957,12 @@ unit_animation::particule::~particule()
halo_id_ = halo::NO_HALO;
}
void unit_animation::particule::start_animation(int start_time, bool cycles)
void unit_animation::particule::start_animation(int start_time)
{
halo::remove(halo_id_);
halo_id_ = halo::NO_HALO;
parameters_.override(get_animation_duration());
animated<unit_frame>::start_animation(start_time,cycles);
animated<unit_frame>::start_animation(start_time,cycles_);
last_frame_begin_time_ = get_begin_time() -1;
}
@ -968,7 +972,6 @@ void unit_animator::add_animation(unit* animated_unit
, const map_location &dst
, const int value
, bool with_bars
, bool cycles
, const std::string& text
, const Uint32 text_color
, const unit_animation::hit_type hit_type
@ -984,7 +987,6 @@ void unit_animator::add_animation(unit* animated_unit
tmp.text_color = text_color;
tmp.src = src;
tmp.with_bars= with_bars;
tmp.cycles = cycles;
tmp.animation = animated_unit->choose_animation(*disp,src,event,dst,value,hit_type,attack,second_attack,value2);
if(!tmp.animation) return;
@ -997,7 +999,6 @@ void unit_animator::add_animation(unit* animated_unit
, const unit_animation* anim
, const map_location &src
, bool with_bars
, bool cycles
, const std::string& text
, const Uint32 text_color)
{
@ -1008,7 +1009,6 @@ void unit_animator::add_animation(unit* animated_unit
tmp.text_color = text_color;
tmp.src = src;
tmp.with_bars= with_bars;
tmp.cycles = cycles;
tmp.animation = anim;
if(!tmp.animation) return;
@ -1023,7 +1023,6 @@ void unit_animator::replace_anim_if_invalid(unit* animated_unit
, const map_location & dst
, const int value
, bool with_bars
, bool cycles
, const std::string& text
, const Uint32 text_color
, const unit_animation::hit_type hit_type
@ -1042,11 +1041,10 @@ void unit_animator::replace_anim_if_invalid(unit* animated_unit
tmp.text_color = text_color;
tmp.src = src;
tmp.with_bars= with_bars;
tmp.cycles = cycles;
tmp.animation = NULL;
animated_units_.push_back(tmp);
}else {
add_animation(animated_unit,event,src,dst,value,with_bars,cycles,text,text_color,hit_type,attack,second_attack,value2);
add_animation(animated_unit,event,src,dst,value,with_bars,text,text_color,hit_type,attack,second_attack,value2);
}
}
void unit_animator::start_animations()
@ -1065,7 +1063,7 @@ void unit_animator::start_animations()
for(anim = animated_units_.begin(); anim != animated_units_.end();++anim) {
if(anim->animation) {
anim->my_unit->start_animation(begin_time, anim->animation,
anim->with_bars, anim->cycles, anim->text, anim->text_color);
anim->with_bars, anim->text, anim->text_color);
anim->animation = NULL;
} else {
anim->my_unit->get_animation()->update_parameters(anim->src,anim->src.get_direction(anim->my_unit->facing()));

View file

@ -54,7 +54,6 @@ class unit_animation
void start_animation(int start_time
, const map_location &src = map_location::null_location
, const map_location &dst = map_location::null_location
, bool cycles = false
, const std::string& text = ""
, const Uint32 text_color = 0
, const bool accelerate = true);
@ -88,7 +87,8 @@ class unit_animation
accelerate(true),
parameters_(builder),
halo_id_(0),
last_frame_begin_time_(0)
last_frame_begin_time_(0),
cycles_(false)
{};
explicit particule(const config& cfg
, const std::string& frame_string ="frame");
@ -106,7 +106,7 @@ class unit_animation
, const std::string& modifiers = "");
void redraw( const frame_parameters& value,const map_location &src, const map_location &dst);
std::set<map_location> get_overlaped_hex(const frame_parameters& value,const map_location &src, const map_location &dst);
void start_animation(int start_time, bool cycles=false);
void start_animation(int start_time);
const frame_parameters parameters(const frame_parameters & default_val) const { return get_current_frame().merge_parameters(get_current_frame_time(),parameters_.parameters(get_animation_time()-get_begin_time()),default_val); };
void clear_halo();
bool accelerate;
@ -116,6 +116,7 @@ class unit_animation
frame_parsed_parameters parameters_;
int halo_id_;
int last_frame_begin_time_;
bool cycles_;
};
t_translation::t_list terrain_types_;
@ -155,7 +156,6 @@ class unit_animator
, const unit_animation * animation
, const map_location &src = map_location::null_location
, bool with_bars = false
, bool cycles = false
, const std::string& text = ""
, const Uint32 text_color = 0);
void add_animation(unit* animated_unit
@ -164,7 +164,6 @@ class unit_animator
, const map_location &dst = map_location::null_location
, const int value = 0
, bool with_bars = false
, bool cycles = false
, const std::string& text = ""
, const Uint32 text_color = 0
, const unit_animation::hit_type hit_type =
@ -178,7 +177,6 @@ class unit_animator
, const map_location &dst = map_location::null_location
, const int value = 0
, bool with_bars = false
, bool cycles = false
, const std::string& text = ""
, const Uint32 text_color = 0
, const unit_animation::hit_type hit_type =
@ -208,10 +206,8 @@ class unit_animator
text(),
text_color(0),
src(),
with_bars(false),
cycles(false)
{
}
with_bars(false)
{}
unit *my_unit;
const unit_animation * animation;
@ -219,7 +215,6 @@ class unit_animator
Uint32 text_color;
map_location src;
bool with_bars;
bool cycles;
};
std::vector<anim_elem> animated_units_;

View file

@ -75,7 +75,7 @@ static void move_unit_between(const map_location& a, const map_location& b, unit
temp_unit.set_facing(a.get_relative_dir(b));
unit_animator animator;
animator.replace_anim_if_invalid(&temp_unit,"movement",a,b,step_num,
false,false,"",0,unit_animation::INVALID,NULL,NULL,step_left);
false,"",0,unit_animation::INVALID,NULL,NULL,step_left);
animator.start_animations();
animator.pause_animation();
disp->scroll_to_tiles(a,b,game_display::ONSCREEN,true,0.0,false);
@ -236,8 +236,8 @@ void unit_draw_weapon(const map_location& loc, unit& attacker,
return;
}
unit_animator animator;
animator.add_animation(&attacker,"draw_weapon",loc,defender_loc,0,false,false,"",0,unit_animation::HIT,attack,secondary_attack,0);
animator.add_animation(defender,"draw_weapon",defender_loc,loc,0,false,false,"",0,unit_animation::MISS,secondary_attack,attack,0);
animator.add_animation(&attacker,"draw_weapon",loc,defender_loc,0,false,"",0,unit_animation::HIT,attack,secondary_attack,0);
animator.add_animation(defender,"draw_weapon",defender_loc,loc,0,false,"",0,unit_animation::MISS,secondary_attack,attack,0);
animator.start_animations();
animator.wait_for_end();
@ -253,10 +253,10 @@ void unit_sheath_weapon(const map_location& primary_loc, unit* primary_unit,
}
unit_animator animator;
if(primary_unit) {
animator.add_animation(primary_unit,"sheath_weapon",primary_loc,secondary_loc,0,false,false,"",0,unit_animation::INVALID,primary_attack,secondary_attack,0);
animator.add_animation(primary_unit,"sheath_weapon",primary_loc,secondary_loc,0,false,"",0,unit_animation::INVALID,primary_attack,secondary_attack,0);
}
if(secondary_unit) {
animator.add_animation(secondary_unit,"sheath_weapon",secondary_loc,primary_loc,0,false,false,"",0,unit_animation::INVALID,secondary_attack,primary_attack,0);
animator.add_animation(secondary_unit,"sheath_weapon",secondary_loc,primary_loc,0,false,"",0,unit_animation::INVALID,secondary_attack,primary_attack,0);
}
if(primary_unit || secondary_unit) {
@ -283,9 +283,9 @@ void unit_die(const map_location& loc, unit& loser,
}
unit_animator animator;
// hide the hp/xp bars of the loser (useless and prevent bars around an erased unit)
animator.add_animation(&loser,"death",loc,winner_loc,0,false,false,"",0,unit_animation::KILL,attack,secondary_attack,0);
animator.add_animation(&loser,"death",loc,winner_loc,0,false,"",0,unit_animation::KILL,attack,secondary_attack,0);
// but show the bars of the winner (avoid blinking and show its xp gain)
animator.add_animation(winner,"victory",winner_loc,loc,0,true,false,"",0,
animator.add_animation(winner,"victory",winner_loc,loc,0,true,"",0,
unit_animation::KILL,secondary_attack,attack,0);
animator.start_animations();
animator.wait_for_end();
@ -357,7 +357,7 @@ void unit_attack(
hit_type = unit_animation::MISS;
}
animator.add_animation(&attacker, "attack", att->get_location(),
def->get_location(), damage, true, false, text_2,
def->get_location(), damage, true, text_2,
display::rgb(0, 255, 0), hit_type, &attack, secondary_attack,
swing);
@ -366,7 +366,7 @@ void unit_attack(
def->get_location(), "defend", att->get_location(), damage,
hit_type, &attack, secondary_attack, swing);
animator.add_animation(&defender, defender_anim, def->get_location(),
true, false, text , display::rgb(255, 0, 0));
true, text , display::rgb(255, 0, 0));
for (std::vector<std::pair<const config *, map_location> >::iterator itor = leaders.cfgs.begin(); itor != leaders.cfgs.end(); ++itor) {
if(itor->second == a) continue;
@ -375,7 +375,7 @@ void unit_attack(
assert(leader != units.end());
leader->set_facing(itor->second.get_relative_dir(a));
animator.add_animation(&*leader, "leading", itor->second,
att->get_location(), damage, true, false, "", 0,
att->get_location(), damage, true, "", 0,
hit_type, &attack, secondary_attack, swing);
}
for (std::vector<std::pair<const config *, map_location> >::iterator itor = helpers.cfgs.begin(); itor != helpers.cfgs.end(); ++itor) {
@ -385,7 +385,7 @@ void unit_attack(
assert(helper != units.end());
helper->set_facing(itor->second.get_relative_dir(b));
animator.add_animation(&*helper, "resistance", itor->second,
def->get_location(), damage, true, false, "", 0,
def->get_location(), damage, true, "", 0,
hit_type, &attack, secondary_attack, swing);
}
@ -478,9 +478,9 @@ void unit_healing(unit &healed, const map_location &healed_loc,
healed_loc, healing);
}
if (healing < 0) {
animator.add_animation(&healed,"poisoned",healed_loc,map_location::null_location,-healing,false,false,lexical_cast<std::string>(-healing), display::rgb(255,0,0));
animator.add_animation(&healed,"poisoned",healed_loc,map_location::null_location,-healing,false,lexical_cast<std::string>(-healing), display::rgb(255,0,0));
} else {
animator.add_animation(&healed,"healed",healed_loc,map_location::null_location,healing,false,false,lexical_cast<std::string>(healing), display::rgb(0,255,0));
animator.add_animation(&healed,"healed",healed_loc,map_location::null_location,healing,false,lexical_cast<std::string>(healing), display::rgb(0,255,0));
}
animator.start_animations();
animator.wait_for_end();
@ -573,7 +573,7 @@ void wml_animation_internal(unit_animator &animator, const vconfig &cfg, const m
}
}
animator.add_animation(&*u, cfg["flag"], u->get_location(),
secondary_loc, cfg["value"], cfg["with_bars"].to_bool(), false,
secondary_loc, cfg["value"], cfg["with_bars"].to_bool(),
cfg["text"], text_color, hits, primary, secondary,
cfg["value_second"]);
}