00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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 display;
00024 class unit;
00025
00026 class unit_animation
00027 {
00028
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 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 , const std::string& text = ""
00058 , const Uint32 text_color = 0
00059 , const bool accelerate = true);
00060 void update_parameters(const map_location &src, const map_location &dst);
00061 void pause_animation();
00062 void restart_animation();
00063 int get_current_frame_begin_time() const{ return unit_anim_.get_current_frame_begin_time() ; };
00064 void redraw(frame_parameters& value);
00065 void clear_haloes();
00066 bool invalidate(frame_parameters& value );
00067
00068 friend class unit;
00069
00070 explicit unit_animation(const config &cfg, const std::string &frame_string = "");
00071
00072 protected:
00073
00074 const frame_parameters get_current_params(const frame_parameters & default_val = frame_parameters()) const { return unit_anim_.parameters(default_val); };
00075 private:
00076 explicit unit_animation(int start_time
00077 , const unit_frame &frame
00078 , const std::string& event = ""
00079 , const int variation=DEFAULT_ANIM
00080 , const frame_builder & builder = frame_builder());
00081
00082 class particule:public animated<unit_frame>
00083 {
00084 public:
00085 explicit particule(int start_time=0,const frame_builder &builder = frame_builder()) :
00086 animated<unit_frame>(start_time),
00087 accelerate(true),
00088 parameters_(builder),
00089 halo_id_(0),
00090 last_frame_begin_time_(0),
00091 cycles_(false)
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 typedef enum { UNSET,CYCLE,NO_CYCLE} cycle_state;
00100 void override(int start_time
00101 , int duration
00102 , const cycle_state cycles
00103 , const std::string& highlight = ""
00104 , const std::string& blend_ratio =""
00105 , Uint32 blend_color = 0
00106 , const std::string& offset = ""
00107 , const std::string& layer = ""
00108 , const std::string& modifiers = "");
00109 void redraw( const frame_parameters& value,const map_location &src, const map_location &dst);
00110 std::set<map_location> get_overlaped_hex(const frame_parameters& value,const map_location &src, const map_location &dst);
00111 void start_animation(int start_time);
00112 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); };
00113 void clear_halo();
00114 bool accelerate;
00115 private:
00116
00117
00118 frame_parsed_parameters parameters_;
00119 int halo_id_;
00120 int last_frame_begin_time_;
00121 bool cycles_;
00122
00123 };
00124 t_translation::t_list terrain_types_;
00125 std::vector<config> unit_filter_;
00126 std::vector<config> secondary_unit_filter_;
00127 std::vector<map_location::DIRECTION> directions_;
00128 int frequency_;
00129 int base_score_;
00130 std::vector<std::string> event_;
00131 std::vector<int> value_;
00132 std::vector<config> primary_attack_filter_;
00133 std::vector<config> secondary_attack_filter_;
00134 std::vector<hit_type> hits_;
00135 std::vector<int> value2_;
00136 std::map<std::string,particule> sub_anims_;
00137 particule unit_anim_;
00138
00139 map_location src_;
00140 map_location dst_;
00141
00142 bool invalidated_;
00143 bool play_offscreen_;
00144 std::set<map_location> overlaped_hex_;
00145 };
00146
00147 class unit_animator
00148 {
00149 public:
00150 unit_animator() :
00151 animated_units_(),
00152 start_time_(INT_MIN)
00153 {
00154 }
00155
00156
00157 void add_animation(unit* animated_unit
00158 , const unit_animation * animation
00159 , const map_location &src = map_location::null_location
00160 , bool with_bars = false
00161 , const std::string& text = ""
00162 , const Uint32 text_color = 0);
00163 void add_animation(unit* animated_unit
00164 , const std::string& event
00165 , const map_location &src = map_location::null_location
00166 , const map_location &dst = map_location::null_location
00167 , const int value = 0
00168 , bool with_bars = false
00169 , const std::string& text = ""
00170 , const Uint32 text_color = 0
00171 , const unit_animation::hit_type hit_type =
00172 unit_animation::INVALID
00173 , const attack_type* attack = NULL
00174 , const attack_type* second_attack = NULL
00175 , int value2 = 0);
00176 void replace_anim_if_invalid(unit* animated_unit
00177 , const std::string& event
00178 , const map_location &src = map_location::null_location
00179 , const map_location &dst = map_location::null_location
00180 , const int value = 0
00181 , bool with_bars = 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 {}
00213
00214 unit *my_unit;
00215 const unit_animation * animation;
00216 std::string text;
00217 Uint32 text_color;
00218 map_location src;
00219 bool with_bars;
00220 };
00221
00222 std::vector<anim_elem> animated_units_;
00223 int start_time_;
00224 };
00225 #endif