unit_animation.hpp

Go to the documentation of this file.
00001 /* $Id: unit_animation.hpp 48153 2011-01-01 15:57:50Z mordante $ */
00002 /*
00003    Copyright (C) 2006 - 2011 by Jeremy Rosen <jeremy.rosen@enst-bretagne.fr>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014    */
00015 #ifndef UNIT_ANIMATION_H_INCLUDED
00016 #define UNIT_ANIMATION_H_INCLUDED
00017 
00018 #include "animated.hpp"
00019 #include "config.hpp"
00020 #include "unit_frame.hpp"
00021 
00022 class attack_type;
00023 class game_display;
00024 class unit;
00025 
00026 class unit_animation
00027 {
00028         /** Shouldn't be used so only declared. */
00029         unit_animation();
00030     public:
00031         typedef enum { MATCH_FAIL=-10 , DEFAULT_ANIM=-9} variation_type;
00032         typedef enum { HIT, MISS, KILL, INVALID} hit_type;
00033 
00034         static const std::vector<std::string>& all_tag_names();
00035         static void fill_initial_animations( std::vector<unit_animation> & animations, const config & cfg);
00036         static void add_anims( std::vector<unit_animation> & animations, const config & cfg);
00037 
00038         int matches(const game_display &disp,const map_location& loc,const map_location& second_loc,const unit* my_unit,const std::string & event="",const int value=0,hit_type hit=INVALID,const attack_type* attack=NULL,const attack_type* second_attack = NULL, int value2 =0) const;
00039 
00040 
00041         const unit_frame& get_last_frame() const{ return unit_anim_.get_last_frame() ; };
00042         void add_frame(int duration, const unit_frame& value,bool force_change =false){ unit_anim_.add_frame(duration,value,force_change) ; };
00043 
00044         bool need_update() const;
00045         bool need_minimal_update() const;
00046         bool animation_finished() const;
00047         bool animation_finished_potential() const;
00048         void update_last_draw_time();
00049         int get_begin_time() const;
00050         int get_end_time() const;
00051                 int time_to_tick(int animation_time) const { return unit_anim_.time_to_tick(animation_time); };
00052         int get_animation_time() const{ return unit_anim_.get_animation_time() ; };
00053         int get_animation_time_potential() const{ return unit_anim_.get_animation_time_potential() ; };
00054         void start_animation(int start_time
00055                 , const map_location &src = map_location::null_location
00056                 , const map_location &dst = map_location::null_location
00057                 , bool cycles = false
00058                 , const std::string& text = ""
00059                 , const Uint32 text_color = 0
00060                 , const bool accelerate = true);
00061         void update_parameters(const map_location &src, const map_location &dst);
00062                 void pause_animation();
00063                 void restart_animation();
00064         int get_current_frame_begin_time() const{ return unit_anim_.get_current_frame_begin_time() ; };
00065         void redraw(frame_parameters& value);
00066         void clear_haloes();
00067         bool invalidate(frame_parameters& value );
00068 
00069     friend class unit;
00070 
00071     explicit unit_animation(const config &cfg, const std::string &frame_string = "");
00072 
00073     protected:
00074     // reserved to class unit, for the special case of redrawing the unit base frame
00075     const frame_parameters get_current_params(const frame_parameters & default_val = frame_parameters()) const { return unit_anim_.parameters(default_val); };
00076     private:
00077         explicit unit_animation(int start_time
00078                 , const unit_frame &frame
00079                 , const std::string& event = ""
00080                 , const int variation=DEFAULT_ANIM
00081                 , const frame_builder & builder = frame_builder());
00082 
00083         class particule:public animated<unit_frame>
00084     {
00085         public:
00086             explicit particule(int start_time=0,const frame_builder &builder = frame_builder()) :
00087                 animated<unit_frame>(start_time),
00088                 accelerate(true),
00089                 parameters_(builder),
00090                 halo_id_(0),
00091                 last_frame_begin_time_(0)
00092                 {};
00093             explicit particule(const config& cfg
00094                     , const std::string& frame_string ="frame");
00095 
00096             virtual ~particule();
00097             bool need_update() const;
00098             bool need_minimal_update() const;
00099             void override(int start_time
00100                     , int duration
00101                     , const std::string& highlight = ""
00102                     , const std::string& blend_ratio =""
00103                     , Uint32 blend_color = 0
00104                     , const std::string& offset = ""
00105                     , const std::string& layer = ""
00106                     , const std::string& modifiers = "");
00107             void redraw( const frame_parameters& value,const map_location &src, const map_location &dst);
00108             std::set<map_location> get_overlaped_hex(const frame_parameters& value,const map_location &src, const map_location &dst);
00109             void start_animation(int start_time, bool cycles=false);
00110             const frame_parameters parameters(const frame_parameters & default_val) const { return get_current_frame().merge_parameters(get_current_frame_time(),parameters_.parameters(get_animation_time()-get_begin_time()),default_val); };
00111             void clear_halo();
00112             bool accelerate;
00113         private:
00114 
00115             //animation params that can be locally overridden by frames
00116             frame_parsed_parameters parameters_;
00117             int halo_id_;
00118             int last_frame_begin_time_;
00119 
00120     };
00121         t_translation::t_list terrain_types_;
00122         std::vector<config> unit_filter_;
00123         std::vector<config> secondary_unit_filter_;
00124         std::vector<map_location::DIRECTION> directions_;
00125         int frequency_;
00126         int base_score_;
00127         std::vector<std::string> event_;
00128         std::vector<int> value_;
00129         std::vector<config> primary_attack_filter_;
00130         std::vector<config> secondary_attack_filter_;
00131         std::vector<hit_type> hits_;
00132         std::vector<int> value2_;
00133         std::map<std::string,particule> sub_anims_;
00134         particule unit_anim_;
00135         /* these are drawing parameters, but for efficiancy reason they are in the anim and not in the particle */
00136         map_location src_;
00137         map_location dst_;
00138         // optimization
00139         bool invalidated_;
00140         bool play_offscreen_;
00141         std::set<map_location> overlaped_hex_;
00142 };
00143 
00144 class unit_animator
00145 {
00146     public:
00147         unit_animator() :
00148             animated_units_(),
00149             start_time_(INT_MIN)
00150         {
00151         }
00152 
00153 
00154         void add_animation(unit* animated_unit
00155                 , const unit_animation * animation
00156                 , const map_location &src = map_location::null_location
00157                 , bool with_bars = false
00158                 , bool cycles = false
00159                 , const std::string& text = ""
00160                 , const Uint32 text_color = 0);
00161         void add_animation(unit* animated_unit
00162                 , const std::string& event
00163                 , const map_location &src = map_location::null_location
00164                 , const map_location &dst = map_location::null_location
00165                 , const int value = 0
00166                 , bool with_bars = false
00167                 , bool cycles = false
00168                 , const std::string& text = ""
00169                 , const Uint32 text_color = 0
00170                 , const unit_animation::hit_type hit_type =
00171                     unit_animation::INVALID
00172                 , const attack_type* attack = NULL
00173                 , const attack_type* second_attack = NULL
00174                 , int value2 = 0);
00175         void replace_anim_if_invalid(unit* animated_unit
00176                 , const std::string& event
00177                 , const map_location &src = map_location::null_location
00178                 , const map_location &dst = map_location::null_location
00179                 , const int value = 0
00180                 , bool with_bars = false
00181                 , bool cycles = false
00182                 , const std::string& text = ""
00183                 , const Uint32 text_color = 0
00184                 , const unit_animation::hit_type hit_type =
00185                     unit_animation::INVALID
00186                 , const attack_type* attack = NULL
00187                 , const attack_type* second_attack = NULL
00188                 , int value2 = 0);
00189         void start_animations();
00190                 void pause_animation();
00191                 void restart_animation();
00192         void clear(){start_time_ = INT_MIN ; animated_units_.clear();};
00193         void set_all_standing();
00194 
00195 
00196         bool would_end() const;
00197         int get_animation_time() const;
00198         int get_animation_time_potential() const;
00199         int get_end_time() const;
00200         void wait_for_end() const;
00201         void wait_until( int animation_time) const;
00202     private:
00203          struct anim_elem {
00204 
00205             anim_elem() :
00206                 my_unit(0),
00207                 animation(0),
00208                 text(),
00209                 text_color(0),
00210                 src(),
00211                 with_bars(false),
00212                 cycles(false)
00213             {
00214             }
00215 
00216             unit *my_unit;
00217             const unit_animation * animation;
00218             std::string text;
00219             Uint32 text_color;
00220             map_location src;
00221             bool with_bars;
00222             bool cycles;
00223         };
00224 
00225         std::vector<anim_elem> animated_units_;
00226         int start_time_;
00227 };
00228 #endif

Generated by doxygen 1.5.6 on Thu Feb 10 01:01:28 2011 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs