Author: boucman
Date: Sun May 27 12:00:05 2007
New Revision: 17900

URL: http://svn.gna.org/viewcvs/wesnoth?rev=17900&view=rev
Log:
 fix crash on ranged attack... this is very hacky, but cleaning will have to 
wait for deeper structural change

Modified:
    trunk/src/unit.cpp
    trunk/src/unit.hpp

Modified: trunk/src/unit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=17900&r1=17899&r2=17900&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Sun May 27 12:00:05 2007
@@ -1503,8 +1503,6 @@
 {
        state_ =  STATE_DEFENDING;
 
-       delete anim_;
-
        fighting_animation::hit_type hit_type;
        if(damage >= hitpoints()) {
                hit_type = fighting_animation::KILL;
@@ -1540,9 +1538,8 @@
        }else {
                hit_type = fighting_animation::MISS;
        }
-       
start_animation(disp,loc,type.animation(disp,loc,this,hit_type,secondary_attack,swing_num,damage),true);
-
-       return ((attack_animation*)anim_)->get_missile_anim();
+       return 
*start_animation(disp,loc,type.animation(disp,loc,this,hit_type,secondary_attack,swing_num,damage),true,true);
+
 }
 void unit::set_leading(const display &disp,const gamemap::location& loc)
 {
@@ -1615,19 +1612,27 @@
        start_animation(disp,loc,idling_animation(disp,loc),true);
 }
 
-void unit::start_animation(const display &disp, const gamemap::location 
&loc,const unit_animation * animation,bool with_bars)
+const unit_animation* unit::start_animation(const display &disp, const 
gamemap::location &loc,const unit_animation * animation,bool with_bars,bool 
is_attack_anim)
 {
        draw_bars_ =  with_bars;
        if(anim_) delete anim_;
-       if(animation) {
+       if(animation && !is_attack_anim) {
                anim_ = new unit_animation(*animation);
+       }else if(animation && is_attack_anim) {
+               //TODO this, the is_attack_anim param and the return value are 
ugly hacks that need to be taken care of eventually
+               anim_ = new attack_animation(*(const 
attack_animation*)animation);
        } else {
                set_standing(disp,loc,with_bars);
-               return;
+               return NULL;
        }
        anim_->start_animation(anim_->get_begin_time(), false, 
disp.turbo_speed());
        frame_begin_time_ = anim_->get_begin_time() -1;
        next_idling_= get_current_animation_tick() +10000 +rand()%10000;
+       if(is_attack_anim) {
+               return &((attack_animation*)anim_)->get_missile_anim();
+       } else {
+               return NULL;
+       }
 }
 
 void unit::restart_animation(const display& disp,int start_time) {

Modified: trunk/src/unit.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=17900&r1=17899&r2=17900&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Sun May 27 12:00:05 2007
@@ -238,8 +238,7 @@
                STATE_LEADING, STATE_HEALING, STATE_WALKING, STATE_LEVELIN,
                STATE_LEVELOUT, STATE_DYING, STATE_EXTRA, STATE_TELEPORT,
                STATE_RECRUITED, STATE_HEALED, STATE_POISONED, STATE_IDLEIN, 
STATE_IDLING, STATE_VICTORIOUS};
-               //STATE state() const { return (state_ == STATE_IDLING) ? 
STATE_STANDING : state_; }
-               void start_animation(const display &disp, const 
gamemap::location &loc,const unit_animation* animation, bool with_bars);
+               const unit_animation * start_animation(const display &disp, 
const gamemap::location &loc,const unit_animation* animation, bool 
with_bars,bool is_attack_anim =false);
 
                //the name of the file to display (used in menus
                const std::string& absolute_image() const { return 
cfg_["image"]; }


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to