make drain numbers be handled by the animation engine instead of the game engine

This commit is contained in:
Jérémy Rosen 2008-03-16 19:44:57 +00:00
parent f62d7491e0
commit 14aaeaa23a
3 changed files with 13 additions and 16 deletions

View File

@ -989,7 +989,7 @@ attack::attack(game_display& gui, const gamemap& map,
unit_display::unit_attack(attacker_,defender_,
damage_defender_takes,
*a_stats_->weapon,d_stats_->weapon,
abs_n_attack_,float_text);
abs_n_attack_,float_text,a_stats_->drains,"");
}
bool dies = d_->second.take_hit(damage_defender_takes);
LOG_NG << "defender took " << damage_defender_takes << (dies ? " and died" : "") << "\n";
@ -1042,11 +1042,6 @@ attack::attack(game_display& gui, const gamemap& map,
int amount_drained = a_stats_->drains ? attacker_damage_ / 2 : 0;
if(amount_drained > 0) {
char buf[50];
snprintf(buf,sizeof(buf),"%d",amount_drained);
if (update_display_){
gui_.float_label(a_->first,buf,0,255,0);
}
a_->second.heal(amount_drained);
}
}
@ -1245,7 +1240,7 @@ attack::attack(game_display& gui, const gamemap& map,
unit_display::unit_attack(defender_,attacker_,
damage_attacker_takes,
*d_stats_->weapon,a_stats_->weapon,
abs_n_defend_,float_text);
abs_n_defend_,float_text,d_stats_->drains,"");
}
bool dies = a_->second.take_hit(damage_attacker_takes);
LOG_NG << "attacker took " << damage_attacker_takes << (dies ? " and died" : "") << "\n";
@ -1296,11 +1291,6 @@ attack::attack(game_display& gui, const gamemap& map,
int amount_drained = d_stats_->drains ? defender_damage_ / 2 : 0;
if(amount_drained > 0) {
char buf[50];
snprintf(buf,sizeof(buf),"%d",amount_drained);
if (update_display_){
gui_.float_label(d_->first,buf,0,255,0);
}
d_->second.heal(amount_drained);
}
}

View File

@ -204,7 +204,7 @@ void unit_die(const gamemap::location& loc, unit& loser,
void unit_attack(
const gamemap::location& a, const gamemap::location& b, int damage,
const attack_type& attack, const attack_type* secondary_attack,
int swing,std::string hit_text)
int swing,std::string hit_text,bool drain,std::string att_text)
{
game_display* disp = game_display::get_singleton();
if(!disp || preferences::show_combat() == false) return;
@ -243,6 +243,13 @@ void unit_attack(
text = text + "\n" + hit_text;
}
std::string text_2 ;
if(drain && damage) text_2 = lexical_cast<std::string>(minimum<int>(damage,defender.hitpoints())/2);
if(!att_text.empty()) {
text_2.insert(text_2.begin(),att_text.size()/2,' ');
text_2 = text_2 + "\n" + att_text;
}
unit_animation::hit_type hit_type;
if(damage >= defender.hitpoints()) {
hit_type = unit_animation::KILL;
@ -251,8 +258,8 @@ void unit_attack(
}else {
hit_type = unit_animation::MISS;
}
animator.add_animation(&attacker,"attack",att->first,damage,true,false,"",0,hit_type,&attack,secondary_attack,swing);
animator.add_animation(&defender,"defend",def->first,damage,true,false,text,display::rgb(255,0,0),hit_type,&attack,secondary_attack,swing);
animator.add_animation(&attacker,"attack",att->first,damage,true,false,text_2,display::rgb(0,255,0),hit_type,&attack,secondary_attack,swing);
animator.add_animation(&defender,"defend",def->first,damage,true,false,text ,display::rgb(255,0,0),hit_type,&attack,secondary_attack,swing);
if(leader_loc.valid()){
leader = units.find(leader_loc);

View File

@ -46,7 +46,7 @@ void unit_die( const gamemap::location& loc, unit& u, const attack_type* attack=
void unit_attack(
const gamemap::location& a, const gamemap::location& b, int damage,
const attack_type& attack, const attack_type* secondary_attack,
int swing,std::string hit_text);
int swing,std::string hit_text,bool drain,std::string att_text);
void unit_recruited(gamemap::location& loc);