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_display.cpp src/unit_display.h...


From: David White
Subject: [Wesnoth-cvs-commits] wesnoth src/unit_display.cpp src/unit_display.h...
Date: Mon, 21 Mar 2005 20:14:14 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     David White <address@hidden>    05/03/22 01:14:14

Modified files:
        src            : unit_display.cpp unit_display.hpp 
                         unit_types.cpp unit_types.hpp 
        .              : changelog 
Added files:
        images         : undead-skeleton-dying-2.png 
                         undead-skeleton-dying.png 
                         undead-revenant-dying-2.png 
                         undead-revenant-dying.png 

Log message:
        added support for animated deaths

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_display.cpp.diff?tr1=1.52&tr2=1.53&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_display.hpp.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_types.cpp.diff?tr1=1.89&tr2=1.90&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_types.hpp.diff?tr1=1.62&tr2=1.63&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/changelog.diff?tr1=1.536&tr2=1.537&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/images/undead-skeleton-dying-2.png?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/images/undead-skeleton-dying.png?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/images/undead-revenant-dying-2.png?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/images/undead-revenant-dying.png?rev=1.1

Patches:
Index: wesnoth/changelog
diff -u wesnoth/changelog:1.536 wesnoth/changelog:1.537
--- wesnoth/changelog:1.536     Mon Mar 21 23:12:27 2005
+++ wesnoth/changelog   Tue Mar 22 01:14:14 2005
@@ -1,4 +1,5 @@
 CVS HEAD:
+ * Added support for animated deaths, and added animations for skeleton and 
revenant
  * Balancing of water units: swimmer units (merfolk) have defense on water and 
swamp reduced by 10%. Merman Hunter cost: 13 -> 15. Melee attack: 5-2 -> 4-2. 
Naga have defense on shallow water reduced by 10%. Deep sea creatures have 
defense on water reduced by 10%. Naga Fighter cost: 13 -> 14.
  * Added UNIT and PLACE_IMAGE macros to utils.cfg
  * terrain improvements
Index: wesnoth/src/unit_display.cpp
diff -u wesnoth/src/unit_display.cpp:1.52 wesnoth/src/unit_display.cpp:1.53
--- wesnoth/src/unit_display.cpp:1.52   Thu Mar 10 22:57:23 2005
+++ wesnoth/src/unit_display.cpp        Tue Mar 22 01:14:14 2005
@@ -267,7 +267,7 @@
        }
 }
 
-void unit_die(display& disp, const gamemap::location& loc, const unit& u)
+void unit_die(display& disp, const gamemap::location& loc, const unit& u, 
const attack_type* attack)
 {
        if(disp.update_locked() || disp.fogged(loc.x,loc.y) || 
preferences::show_combat() == false) {
                return;
@@ -276,13 +276,36 @@
        const std::string& die_sound = u.type().die_sound();
        if(die_sound != "" && die_sound != "null") {
                sound::play_sound(die_sound);
+       }
+
+       surface unit_image(NULL);
+
+       const unit_animation* const anim_ptr = u.type().die_animation(attack);
+       if(anim_ptr != NULL) {
+               unit_animation anim(*anim_ptr);
+
+               
anim.start_animation(anim.get_first_frame_time(),unit_animation::UNIT_FRAME,disp.turbo()
 ? 5:1);
+               anim.update_current_frames();
+
+               while(!anim.animation_finished()) {
+
+                       const unit_animation::frame& frame = 
anim.get_current_frame();
+
+                       unit_image = surface(image::get_image(frame.image));
+                       disp.draw_tile(loc.x,loc.y,unit_image);
+                       disp.update_display();
+
+                       SDL_Delay(10);
+
+                       anim.update_current_frames();
+               }
        }
 
        const int frame_time = 30;
        int ticks = SDL_GetTicks();
 
        for(fixed_t alpha = ftofxp(1.0); alpha > ftofxp(0.0); alpha -= 
ftofxp(0.05)) {
-               disp.draw_tile(loc.x,loc.y,NULL,alpha);
+               disp.draw_tile(loc.x,loc.y,unit_image,alpha);
 
                const int wait_time = ticks + frame_time - SDL_GetTicks();
 
@@ -294,7 +317,7 @@
                disp.update_display();
        }
 
-       disp.draw_tile(loc.x,loc.y,NULL,ftofxp(0.0));
+       disp.draw_tile(loc.x,loc.y,unit_image,ftofxp(0.0));
        disp.update_display();
 }
 
@@ -591,7 +614,7 @@
        }
 
        if(dead) {
-               unit_die(disp,def->first,def->second);
+               unit_die(disp,def->first,def->second,&attack);
        }
 
        return dead;
@@ -853,7 +876,7 @@
        def->second.set_standing();
 
        if(dead) {
-               unit_display::unit_die(disp,def->first,def->second);
+               unit_display::unit_die(disp,def->first,def->second,&attack);
        }
 
        return dead;
Index: wesnoth/src/unit_display.hpp
diff -u wesnoth/src/unit_display.hpp:1.5 wesnoth/src/unit_display.hpp:1.6
--- wesnoth/src/unit_display.hpp:1.5    Thu Mar 10 22:57:23 2005
+++ wesnoth/src/unit_display.hpp        Tue Mar 22 01:14:14 2005
@@ -17,7 +17,7 @@
 
 ///a function to show a unit fading out. Note that this only shows the effect, 
it doesn't
 ///actually kill the unit.
-void unit_die(display& disp, const gamemap::location& loc, const unit& u);
+void unit_die(display& disp, const gamemap::location& loc, const unit& u, 
const attack_type* attack=NULL);
 
 ///a function to make the unit on tile 'a' attack the unit on tile 'b'.
 ///the 'damage' will be subtracted from the unit's hitpoints, and a die effect 
will be
Index: wesnoth/src/unit_types.cpp
diff -u wesnoth/src/unit_types.cpp:1.89 wesnoth/src/unit_types.cpp:1.90
--- wesnoth/src/unit_types.cpp:1.89     Thu Mar 17 22:49:22 2005
+++ wesnoth/src/unit_types.cpp  Tue Mar 22 01:14:14 2005
@@ -1,4 +1,4 @@
-/* $Id: unit_types.cpp,v 1.89 2005/03/17 22:49:22 Sirp Exp $ */
+/* $Id: unit_types.cpp,v 1.90 2005/03/22 01:14:14 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -531,7 +531,7 @@
       can_advance_(o.can_advance_), alignment_(o.alignment_),
       movementType_(o.movementType_), possibleTraits_(o.possibleTraits_),
       genders_(o.genders_), defensive_animations_(o.defensive_animations_),
-      teleport_animations_(o.teleport_animations_)
+      teleport_animations_(o.teleport_animations_), 
death_animations_(o.death_animations_)
 {
        gender_types_[0] = o.gender_types_[0] != NULL ? new 
unit_type(*o.gender_types_[0]) : NULL;
        gender_types_[1] = o.gender_types_[1] != NULL ? new 
unit_type(*o.gender_types_[1]) : NULL;
@@ -657,6 +657,11 @@
        const config::child_list& teleports = 
cfg_.get_children("teleport_anim");
        for(config::child_list::const_iterator t = teleports.begin(); t != 
teleports.end(); ++t) {
                teleport_animations_.push_back(unit_animation(**t));
+       }
+
+       const config::child_list& deaths = cfg_.get_children("death");
+       for(config::child_list::const_iterator death = deaths.begin(); death != 
deaths.end(); ++death) {
+               death_animations_.push_back(death_animation(**death));
        }
 }
 
@@ -1036,6 +1041,28 @@
        } else {
                return true;
        }
+}
+
+unit_type::death_animation::death_animation(const config& cfg)
+: damage_type(utils::split(cfg["damage_type"])), 
special(utils::split(cfg["attack_special"])), animation(cfg)
+{
+}
+
+bool unit_type::death_animation::matches(const attack_type* attack) const
+{
+       if(attack == NULL) {
+               return true;
+       }
+
+       if(damage_type.empty() == false && 
std::find(damage_type.begin(),damage_type.end(),attack->type()) == 
damage_type.end()) {
+               return false;
+       }
+
+       if(special.empty() == false && 
std::find(special.begin(),special.end(),attack->special()) == special.end()) {
+               return false;
+       }
+
+       return true;
 }
 
 const unit_animation* unit_type::defend_animation(bool hits, 
attack_type::RANGE range) const
@@ -1065,6 +1092,36 @@
 {
        if (teleport_animations_.empty()) return NULL;
        return &teleport_animations_[rand() % teleport_animations_.size()];
+}
+
+const unit_animation* unit_type::die_animation(const attack_type* attack) const
+{
+       if(death_animations_.empty()) {
+               return NULL;
+       }
+
+       if(attack == NULL) {
+               return 
&death_animations_[rand()%death_animations_.size()].animation;
+       }
+
+       const unit_animation* res = NULL;
+       std::vector<const unit_animation*> options;
+       for(std::vector<death_animation>::const_iterator i = 
death_animations_.begin(); i != death_animations_.end(); ++i) {
+               if(i->matches(attack)) {
+                       if(res != NULL) {
+                               options.push_back(res);
+                       }
+
+                       res = &i->animation;
+               }
+       }
+
+       if(options.empty()) {
+               return res;
+       } else {
+               options.push_back(res);
+               return options[rand()%options.size()];
+       }
 }
 
 game_data::game_data()
Index: wesnoth/src/unit_types.hpp
diff -u wesnoth/src/unit_types.hpp:1.62 wesnoth/src/unit_types.hpp:1.63
--- wesnoth/src/unit_types.hpp:1.62     Thu Mar 10 01:47:57 2005
+++ wesnoth/src/unit_types.hpp  Tue Mar 22 01:14:14 2005
@@ -1,4 +1,4 @@
-/* $Id: unit_types.hpp,v 1.62 2005/03/10 01:47:57 ydirson Exp $ */
+/* $Id: unit_types.hpp,v 1.63 2005/03/22 01:14:14 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -244,7 +244,8 @@
        const std::string& race() const;
 
        const unit_animation* defend_animation(bool hits, attack_type::RANGE 
range) const;
-       const unit_animation* teleport_animation() const;
+       const unit_animation* teleport_animation() const;
+       const unit_animation* die_animation(const attack_type* attack) const;
 
 private:
        void operator=(const unit_type& o);
@@ -284,7 +285,7 @@
 
        struct defensive_animation
        {
-               defensive_animation(const config& cfg);
+               explicit defensive_animation(const config& cfg);
                bool matches(bool hits, attack_type::RANGE range) const;
 
                enum { HIT, MISS, HIT_OR_MISS } hits;
@@ -294,7 +295,18 @@
 
        std::vector<defensive_animation> defensive_animations_;
 
-       std::vector<unit_animation> teleport_animations_;
+       std::vector<unit_animation> teleport_animations_;
+
+       struct death_animation
+       {
+               explicit death_animation(const config& cfg);
+               bool matches(const attack_type* attack) const;
+
+               std::vector<std::string> damage_type, special;
+               unit_animation animation;
+       };
+
+       std::vector<death_animation> death_animations_;
 };
 
 struct game_data




reply via email to

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