From 14aaeaa23a2cadf02475f72b8899659cd4cd6262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rosen?= Date: Sun, 16 Mar 2008 19:44:57 +0000 Subject: [PATCH] make drain numbers be handled by the animation engine instead of the game engine --- src/actions.cpp | 14 ++------------ src/unit_display.cpp | 13 ++++++++++--- src/unit_display.hpp | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index 767b44eeb42..b2d9f051f4c 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -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); } } diff --git a/src/unit_display.cpp b/src/unit_display.cpp index 8ae6d1aaa6b..6a465f39dd2 100644 --- a/src/unit_display.cpp +++ b/src/unit_display.cpp @@ -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(minimum(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); diff --git a/src/unit_display.hpp b/src/unit_display.hpp index 0bed7c48df2..f6bbf36cee2 100644 --- a/src/unit_display.hpp +++ b/src/unit_display.hpp @@ -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);