00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef UNIT_ANIMATION_H_INCLUDED
00015 #define UNIT_ANIMATION_H_INCLUDED
00016
00017 #include "animated.hpp"
00018 #include "config.hpp"
00019 #include "map.hpp"
00020 #include "unit_frame.hpp"
00021
00022 #include <climits>
00023 #include <string>
00024 #include <vector>
00025
00026 class game_display;
00027 class attack_type;
00028
00029 class unit_animation
00030 {
00031
00032 unit_animation();
00033 public:
00034 typedef enum { MATCH_FAIL=-2 , DEFAULT_ANIM=-1} variation_type;
00035 typedef enum { HIT, MISS, KILL, INVALID} hit_type;
00036 static void fill_initial_animations( std::vector<unit_animation> & animations, const config & cfg);
00037 static void add_anims( std::vector<unit_animation> & animations, const config & cfg);
00038
00039 int matches(const game_display &disp,const gamemap::location& 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 swing_num =0) const;
00040
00041
00042 const unit_frame& get_last_frame() const{ return unit_anim_.get_last_frame() ; };
00043 void add_frame(int duration, const unit_frame& value,bool force_change =false){ unit_anim_.add_frame(duration,value,force_change) ; };
00044
00045 bool need_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,const gamemap::location &src = gamemap::location::null_location, const gamemap::location &dst = gamemap::location::null_location , bool cycles=false, const std::string text="", const Uint32 text_color=0,const bool accelerate = true);
00055 void pause_animation();
00056 void restart_animation();
00057 int get_current_frame_begin_time() const{ return unit_anim_.get_current_frame_begin_time() ; };
00058 void redraw(const frame_parameters& value);
00059 void invalidate(const frame_parameters& value ) const;
00060
00061 friend class unit;
00062 protected:
00063
00064 const frame_parameters get_current_params(const frame_parameters & default_val = frame_parameters(),bool primary = true) const { return unit_anim_.parameters(default_val,primary); };
00065 private:
00066 static config prepare_animation(const config &cfg,const std::string animation_tag);
00067 explicit unit_animation(const config& cfg,const std::string frame_string ="");
00068 explicit unit_animation(int start_time,const unit_frame &frame,const std::string& event="",const int variation=DEFAULT_ANIM);
00069 class particule:public animated<unit_frame>
00070 {
00071 public:
00072 explicit particule(int start_time=0) :
00073 animated<unit_frame>(start_time),
00074 accelerate(true),
00075 parameters_(),
00076 src_(),
00077 dst_(),
00078 halo_id_(0),
00079 last_frame_begin_time_(0)
00080 {};
00081 explicit particule(const config& cfg,const std::string frame_string ="frame");
00082 virtual ~particule();
00083 bool need_update() const;
00084 void override(int start_time,const std::string highlight="", const std::string blend_ratio ="",Uint32 blend_color = 0,const std::string offset="");
00085 void redraw( const frame_parameters& value);
00086 void invalidate(const frame_parameters& value, const bool primary = false) const;
00087 void start_animation(int start_time,const gamemap::location& src,const gamemap::location& dst, bool cycles=false);
00088 const frame_parameters parameters(const frame_parameters & default_val,bool primary) const { return get_current_frame().merge_parameters(get_current_frame_time(),parameters_.parameters(get_animation_time()-get_begin_time()),default_val,primary); };
00089 bool accelerate;
00090 private:
00091
00092
00093 frame_builder parameters_;
00094 gamemap::location src_;
00095 gamemap::location dst_;
00096 int halo_id_;
00097 int last_frame_begin_time_;
00098
00099 };
00100 t_translation::t_list terrain_types_;
00101 std::vector<config> unit_filter_;
00102 std::vector<config> secondary_unit_filter_;
00103 std::vector<gamemap::location::DIRECTION> directions_;
00104 int frequency_;
00105 int base_score_;
00106 std::vector<std::string> event_;
00107 std::vector<int> value_;
00108 std::vector<config> primary_attack_filter_;
00109 std::vector<config> secondary_attack_filter_;
00110 std::vector<hit_type> hits_;
00111 std::vector<int> swing_num_;
00112 std::map<std::string,particule> sub_anims_;
00113 particule unit_anim_;
00114 };
00115
00116 class unit_animator
00117 {
00118 public:
00119 unit_animator():start_time_(INT_MIN){};
00120 void add_animation(unit* animated_unit,const std::string& event,
00121 const gamemap::location &src = gamemap::location::null_location,
00122 const int value=0,bool with_bars = false,bool cycles = false,
00123 const std::string text="",const Uint32 text_color=0,
00124 const unit_animation::hit_type hit_type = unit_animation::INVALID,
00125 const attack_type* attack=NULL, const attack_type* second_attack = NULL,
00126 int swing_num =0);
00127 void replace_anim_if_invalid(unit* animated_unit,const std::string& event,
00128 const gamemap::location &src = gamemap::location::null_location,
00129 const int value=0,bool with_bars = false,bool cycles = false,
00130 const std::string text="",const Uint32 text_color=0,
00131 const unit_animation::hit_type hit_type = unit_animation::INVALID,
00132 const attack_type* attack=NULL, const attack_type* second_attack = NULL,
00133 int swing_num =0);
00134 void start_animations();
00135 void pause_animation();
00136 void restart_animation();
00137 void empty(){start_time_ = INT_MIN ; animated_units_.clear();};
00138
00139
00140 bool would_end() const;
00141 int get_animation_time() const;
00142 int get_animation_time_potential() const;
00143 int get_end_time() const;
00144 void wait_for_end() const;
00145 void wait_until( int animation_time) const;
00146 private:
00147 typedef struct {
00148 unit *my_unit;
00149 const unit_animation * animation;
00150 std::string text;
00151 Uint32 text_color;
00152 gamemap::location src;
00153 bool with_bars;
00154 bool cycles;
00155 } anim_elem;
00156 std::vector<anim_elem> animated_units_;
00157 int start_time_;
00158 };
00159 #endif