00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef WEAPON_H
00024 #define WEAPON_H
00025 #include <string>
00026 #include "weapon_cfg.h"
00027 #include "../graphic/surface.h"
00028 #include "../graphic/sprite.h"
00029 #include "../gui/progress_bar.h"
00030 #include "../include/base.h"
00031 #include "../particles/particle.h"
00032 #include "../object/physical_obj.h"
00033 #include "../sound/jukebox.h"
00034 #include "../interface/keyboard.h"
00035
00036 class Character;
00037
00038
00039 extern const int INFINITE_AMMO;
00040
00041 extern const uint BUTTON_ICO_WIDTH;
00042 extern const uint BUTTON_ICO_HEIGHT;
00043
00044 extern const uint WEAPON_ICO_WIDTH;
00045 extern const uint WEAPON_ICO_HEIGHT;
00046
00047 class WeaponStrengthBar : public ProgressBar
00048 {
00049 public:
00050 bool visible ;
00051 } ;
00052
00053
00054
00055 class Weapon
00056 {
00057 public:
00058 typedef enum
00059 {
00060 WEAPON_BAZOOKA, WEAPON_AUTOMATIC_BAZOOKA, WEAPON_RIOT_BOMB, WEAPON_GRENADE,
00061 WEAPON_DISCO_GRENADE, WEAPON_CLUSTER_BOMB, WEAPON_GUN, WEAPON_SHOTGUN,
00062 WEAPON_SUBMACHINE_GUN, WEAPON_BASEBALL,
00063
00064 WEAPON_DYNAMITE, WEAPON_MINE,
00065
00066 WEAPON_SUPERTUX, WEAPON_AIR_ATTACK, WEAPON_ANVIL, WEAPON_GNU,
00067 WEAPON_POLECAT, WEAPON_BOUNCE_BALL,
00068
00069 WEAPON_TELEPORTATION, WEAPON_NINJA_ROPE, WEAPON_LOWGRAV, WEAPON_SUICIDE,
00070 WEAPON_SKIP_TURN, WEAPON_JETPACK, WEAPON_PARACHUTE, WEAPON_AIR_HAMMER,
00071 WEAPON_CONSTRUCT, WEAPON_SNIPE_RIFLE, WEAPON_BLOWTORCH, WEAPON_SYRINGE
00072 } Weapon_type;
00073
00074 protected:
00075 Weapon::Weapon_type m_type;
00076 std::string m_id;
00077 std::string m_name;
00078 bool m_is_active;
00079 Sprite *m_image;
00080 Sprite *m_weapon_fire;
00081 uint m_fire_remanence_time;
00082
00083 typedef enum {
00084 weapon_origin_HAND,
00085 weapon_origin_OVER
00086 } weapon_origin_t;
00087 weapon_origin_t origin;
00088
00089 Point2i hole_delta;
00090 Point2i position;
00091
00092
00093 uint m_time_anim_begin;
00094
00095
00096 double m_strength;
00097
00098
00099 uint m_first_time_loading;
00100
00101
00102 uint m_last_fire_time;
00103
00104
00105 bool m_can_change_weapon;
00106
00107
00108 EmptyWeaponConfig *extra_params;
00109
00110 typedef enum weapon_visibility {
00111 ALWAYS_VISIBLE,
00112 NEVER_VISIBLE,
00113 VISIBLE_ONLY_WHEN_ACTIVE,
00114 VISIBLE_ONLY_WHEN_INACTIVE
00115 } weapon_visibility_t;
00116
00117
00118 weapon_visibility_t m_visibility;
00119 weapon_visibility_t m_unit_visibility;
00120
00121
00122 int m_initial_nb_ammo;
00123 int m_initial_nb_unit_per_ammo;
00124 bool use_unit_on_first_shoot;
00125 bool can_be_used_on_closed_map;
00126
00127
00128 int channel_load;
00129
00130 public:
00131
00132 Sprite * icon;
00133
00134
00135 double max_strength;
00136
00137
00138 bool override_keys ;
00139
00140
00141 bool force_override_keys ;
00142
00143 bool use_flipping;
00144
00145 protected:
00146 virtual void p_Select();
00147 virtual void p_Deselect();
00148 virtual void Refresh() = 0;
00149 virtual bool p_Shoot() = 0;
00150
00151 public:
00152 Weapon(Weapon_type type,
00153 const std::string &id,
00154 EmptyWeaponConfig * params,
00155 weapon_visibility_t visibility = ALWAYS_VISIBLE);
00156 virtual ~Weapon();
00157
00158
00159 void Select();
00160 void Deselect();
00161
00162
00163 void Manage();
00164 bool CanChangeWeapon() const ;
00165
00166
00167 virtual void Draw();
00168 virtual void DrawWeaponFire();
00169
00170 void DrawUnit(int unit) const;
00171
00172 Sprite & GetIcon() const;
00173
00174 bool EnoughAmmo() const;
00175 void UseAmmo();
00176 bool EnoughAmmoUnit() const;
00177 void UseAmmoUnit();
00178 int ReadInitialNbAmmo() const;
00179 int ReadInitialNbUnit() const;
00180
00181 bool CanBeUsedOnClosedMap() const;
00182 bool UseCrossHair() const { return min_angle != max_angle; };
00183
00184
00185 virtual void PosXY (int &x, int &y) const;
00186
00187
00188 void NewActionShoot() const;
00189
00190
00191
00192 void PrepareShoot(double strength, double angle);
00193
00194
00195
00196 bool Shoot();
00197
00198
00199 bool IsActive() const;
00200
00201
00202 virtual bool IsReady() const ;
00203
00204
00205 virtual void InitLoading() ;
00206
00207
00208 virtual bool IsLoading() const;
00209
00210
00211 virtual void StopLoading() ;
00212
00213
00214 virtual void UpdateStrength();
00215
00216 const Point2i GetGunHolePosition();
00217
00218
00219 virtual void ChooseTarget (Point2i mouse_pos);
00220
00221
00222 virtual void ActionUp ();
00223 virtual void ActionDown ();
00224
00225
00226 virtual void HandleKeyEvent(Action::Action_t action, Keyboard::Key_Event_t event_type) ;
00227
00228
00229 virtual void SignalTurnEnd();
00230
00231
00232 virtual void ActionStopUse();
00233
00234
00235
00236 bool LoadXml(xmlpp::Element * weapon);
00237
00238
00239 const double ReadStrength() const;
00240
00241
00242 const std::string& GetName() const;
00243 const std::string& GetID() const;
00244 Weapon_type GetType() const;
00245
00246
00247
00248
00249 bool mouse_character_selection;
00250
00251 inline void SetMinAngle(double min) {min_angle = min;}
00252 inline const double &GetMinAngle() const {return min_angle;}
00253 inline void SetMaxAngle(double max) {max_angle = max;}
00254 inline const double &GetMaxAngle() const {return max_angle;}
00255 private:
00256
00257 double min_angle, max_angle;
00258 };
00259
00260
00261 #endif