wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src unit.hpp unit.cpp unit_display.cpp


From: David White
Subject: [Wesnoth-cvs-commits] wesnoth/src unit.hpp unit.cpp unit_display.cpp
Date: Wed, 29 Dec 2004 18:23:18 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     David White <address@hidden>    04/12/29 23:11:45

Modified files:
        src            : unit.hpp unit.cpp unit_display.cpp 

Log message:
        fixed defender animations

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit.hpp.diff?tr1=1.55&tr2=1.56&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit.cpp.diff?tr1=1.107&tr2=1.108&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_display.cpp.diff?tr1=1.42&tr2=1.43&r1=text&r2=text

Patches:
Index: wesnoth/src/unit.cpp
diff -u wesnoth/src/unit.cpp:1.107 wesnoth/src/unit.cpp:1.108
--- wesnoth/src/unit.cpp:1.107  Thu Dec 23 23:34:38 2004
+++ wesnoth/src/unit.cpp        Wed Dec 29 23:11:45 2004
@@ -1,4 +1,4 @@
-/* $Id: unit.cpp,v 1.107 2004/12/23 23:34:38 Sirp Exp $ */
+/* $Id: unit.cpp,v 1.108 2004/12/29 23:11:45 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -858,13 +858,16 @@
        switch(state_) {
                case STATE_NORMAL: return type_->image();
                case STATE_DEFENDING_LONG:
-               case STATE_DEFENDING_SHORT: {
-                       const attack_type::RANGE range = (state_ == 
STATE_DEFENDING_LONG) ? attack_type::LONG_RANGE : attack_type::SHORT_RANGE;
-                       const unit_animation* const anim = 
type_->defend_animation(getsHit_,range);
-                       if (anim != NULL)
-                               return anim->get_current_frame().image;
-                       else
-                               return type_->image_defensive(range);
+               case STATE_DEFENDING_SHORT: {
+                       if(get_animation()) {
+                               const std::string& res = 
anim_.get_current_frame().image;
+                               if(res != "") {
+                                       return res;
+                               }
+                       }
+
+                       const attack_type::RANGE range = (state_ == 
STATE_DEFENDING_LONG) ? attack_type::LONG_RANGE : attack_type::SHORT_RANGE;
+                       return type_->image_defensive(range);
                }
                case STATE_ATTACKING: {
                        if(attackType_ == NULL)
@@ -883,15 +886,44 @@
 
                default: return type_->image();
        }
+}
+
+const unit_animation* unit::get_animation() const
+{
+       switch(state_) {
+       case STATE_DEFENDING_LONG:
+       case STATE_DEFENDING_SHORT: {
+                       const attack_type::RANGE range = (state_ == 
STATE_DEFENDING_LONG) ? attack_type::LONG_RANGE : attack_type::SHORT_RANGE;
+                       const unit_animation* const anim = 
type_->defend_animation(getsHit_,range);
+                       return anim;
+       }
+       default:
+               return NULL;
+       }
 }
+
+void unit::set_standing()
+{
+       state_ = STATE_NORMAL;
+}
 
-void unit::set_defending(bool newval, bool hits, attack_type::RANGE range)
+void unit::set_defending(bool hits, attack_type::RANGE range, int start_frame, 
int acceleration)
 {
-       state_ = newval ? (range == attack_type::LONG_RANGE ? 
STATE_DEFENDING_LONG :
-                          STATE_DEFENDING_SHORT): STATE_NORMAL;
-       type_->defend_animation(getsHit_,range);
-
-       getsHit_ = hits;
+       state_ = range == attack_type::LONG_RANGE ? STATE_DEFENDING_LONG : 
STATE_DEFENDING_SHORT;
+       getsHit_ = hits;
+                                          
+       const unit_animation* const anim = get_animation();
+       if(anim != NULL) {
+               anim_ = *anim;
+               
anim_.start_animation(start_frame,unit_animation::UNIT_FRAME,acceleration);
+       }
+}
+
+void unit::update_defending_frame()
+{
+       if(get_animation()) {
+               anim_.update_current_frames();
+       }
 }
 
 void unit::set_attacking(bool newval, const attack_type* type, int ms)
Index: wesnoth/src/unit.hpp
diff -u wesnoth/src/unit.hpp:1.55 wesnoth/src/unit.hpp:1.56
--- wesnoth/src/unit.hpp:1.55   Tue Nov 30 21:14:13 2004
+++ wesnoth/src/unit.hpp        Wed Dec 29 23:11:45 2004
@@ -1,4 +1,4 @@
-/* $Id: unit.hpp,v 1.55 2004/11/30 21:14:13 silene Exp $ */
+/* $Id: unit.hpp,v 1.56 2004/12/29 23:11:45 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -116,9 +116,10 @@
        //gets the unit image that should currently be displayed
        //(could be in the middle of an attack etc)
        const std::string& image() const;
-
-       void set_defending(bool newval, bool hits = false,
-                          attack_type::RANGE range=attack_type::LONG_RANGE);
+
+       void set_standing();
+       void set_defending(bool hits, attack_type::RANGE range, int 
start_frame, int acceleration);
+       void update_defending_frame();
        void set_attacking(bool newval, const attack_type* type=NULL, int ms=0);
 
        void set_leading(bool newval);
@@ -217,7 +218,10 @@
 
        UPKEEP_COST upkeep_;
 
-       bool unrenamable_;
+       bool unrenamable_;
+
+       unit_animation anim_;
+       const unit_animation* get_animation() const;
 
        void reset_modifications();
        void apply_modifications();
Index: wesnoth/src/unit_display.cpp
diff -u wesnoth/src/unit_display.cpp:1.42 wesnoth/src/unit_display.cpp:1.43
--- wesnoth/src/unit_display.cpp:1.42   Sat Dec  4 14:50:20 2004
+++ wesnoth/src/unit_display.cpp        Wed Dec 29 23:11:45 2004
@@ -374,11 +374,11 @@
 
        attack_anim.update_current_frames();
        int animation_time = attack_anim.get_animation_time();
+
+       def->second.set_defending(hits, attack_type::LONG_RANGE, 
animation_time, acceleration);
 
        while(animation_time < end_at) {
 
-               def->second.set_defending(true, hits, attack_type::LONG_RANGE);
-
                //this is a while instead of an if, because there might be 
multiple
                //sounds playing simultaneously or close together
                while(!hide && sfx_it != sounds.end() && animation_time >= 
sfx_it->time) {
@@ -559,7 +559,8 @@
 
                // ticks = SDL_GetTicks();
 
-               attack_anim.update_current_frames();
+               attack_anim.update_current_frames();
+               def->second.update_defending_frame();
                animation_time = attack_anim.get_animation_time();
                events::pump();
                disp.update_display();
@@ -578,7 +579,7 @@
                damage = 0;
        }
 
-       def->second.set_defending(false);
+       def->second.set_standing();
 
        if(leader_loc.valid()){
                leader->second.set_leading(false);
@@ -660,8 +661,6 @@
        const int time_resolution = 20;
        const int acceleration = disp.turbo() ? 5 : 1;
 
-       def->second.set_defending(true, hits, attack_type::SHORT_RANGE);
-
        const gamemap::location leader_loc = under_leadership(units,a);
        unit_map::iterator leader = units.end();
        if(leader_loc.valid()){
@@ -709,10 +708,11 @@
 
        attack_anim.start_animation(begin_at, unit_animation::UNIT_FRAME, 
acceleration);
 
-       int animation_time = attack_anim.get_animation_time();
-       while(animation_time < end_at) {
+       int animation_time = attack_anim.get_animation_time();
+
+       def->second.set_defending(hits, attack_type::SHORT_RANGE, 
animation_time, acceleration);
 
-               def->second.set_defending(true, hits, attack_type::SHORT_RANGE);
+       while(animation_time < end_at) {
 
                //this is a while instead of an if, because there might be 
multiple
                //sounds playing simultaneously or close together
@@ -825,7 +825,8 @@
 
                ticks = SDL_GetTicks();
 
-               attack_anim.update_current_frames();
+               attack_anim.update_current_frames();
+               def->second.update_defending_frame();
                animation_time = attack_anim.get_animation_time();
                events::pump();
                disp.update_display();
@@ -845,7 +846,7 @@
                damage = 0;
        }
 
-       def->second.set_defending(false);
+       def->second.set_standing();
 
        if(leader_loc.valid()){
                leader->second.set_leading(false);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]