src/weapon/weapon.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Virtual class to handle weapon in wormux.
00020  * Weapon projectile are handled in WeaponLauncher (see launcher.cpp and launcher.h).
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 // Infinite ammos constant
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; // relative position of the hole of the weapon
00090   Point2i position;   // Position of the weapon
00091 
00092   // Time when the weapon is selected for the animation
00093   uint m_time_anim_begin;
00094 
00095   // Actual strength of the weapon
00096   double m_strength;
00097 
00098   // time of beginning to load (for choosing the strength)
00099   uint m_first_time_loading;
00100 
00101   // time of the last fire
00102   uint m_last_fire_time;
00103 
00104   // change weapon after ? (for the ninja cord = true)
00105   bool m_can_change_weapon;
00106 
00107   // Extra parameters
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  // Visibility
00118   weapon_visibility_t m_visibility;
00119   weapon_visibility_t m_unit_visibility;
00120 
00121   // how many times can we use this weapon (since the beginning of the game) ?
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   // For sound
00128   int channel_load;
00129 
00130 public:
00131   // weapon's icon
00132   Sprite * icon;
00133 
00134   // if max_strength != 0, display the strength bar
00135   double max_strength;
00136 
00137   // True if the weapon uses keys when activated.
00138   bool override_keys ;
00139 
00140   //Force weapons to use keys when true
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   // Select or deselect the weapon
00159   void Select();
00160   void Deselect();
00161 
00162   // Gestion de l'arme
00163   void Manage();
00164   bool CanChangeWeapon() const ;
00165 
00166   // Draw the weapon
00167   virtual void Draw();
00168   virtual void DrawWeaponFire();
00169 
00170   void DrawUnit(int unit) const;
00171 
00172   Sprite & GetIcon() const;
00173   // Manage the numbers of ammunitions
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   // Calculate weapon position
00185   virtual void PosXY (int &x, int &y) const;
00186 
00187   // Create a new action "shoot" in action handler
00188   void NewActionShoot() const;
00189 
00190   // Prepare the shoot : set the angle and strenght of the weapon
00191   // Begin the shooting animation of the character
00192   void PrepareShoot(double strength, double angle);
00193 
00194   // Shot with the weapon
00195   // Return true if we have been able to trigger the weapon
00196   bool Shoot();
00197 
00198   // L'arme est encore active (animation par ex.) ?
00199   bool IsActive() const;
00200 
00201   // the weapon is ready to use ? (is there bullets left ?)
00202   virtual bool IsReady() const ;
00203 
00204   // Begin to load, to choose the strength
00205   virtual void InitLoading() ;
00206 
00207   // Are we loading to choose the strength
00208   virtual bool IsLoading() const;
00209 
00210   // Stop loading
00211   virtual void StopLoading() ;
00212 
00213   // update strength (so the strength bar can be updated)
00214   virtual void UpdateStrength();
00215 
00216   const Point2i GetGunHolePosition();
00217 
00218   // Choose a target.
00219   virtual void ChooseTarget (Point2i mouse_pos);
00220 
00221   //Misc actions.
00222   virtual void ActionUp ();//called by mousse.cpp when mousewhellup
00223   virtual void ActionDown ();//called by mousse.cpp when mousewhelldown
00224 
00225   // Handle a keyboard event.
00226   virtual void HandleKeyEvent(Action::Action_t action, Keyboard::Key_Event_t event_type) ;
00227 
00228   // Get informed that the turn is over.
00229   virtual void SignalTurnEnd();
00230 
00231   // Stop using this weapon (only used with lowgrav and jetpack)
00232   virtual void ActionStopUse();
00233 
00234   // Load parameters from the xml config file
00235   // Return true if xml has been succesfully load
00236   bool LoadXml(xmlpp::Element * weapon);
00237 
00238   // return the strength of the weapon
00239   const double ReadStrength() const;
00240 
00241   // Acc� aux donn�s
00242   const std::string& GetName() const;
00243   const std::string& GetID() const;
00244   Weapon_type GetType() const;
00245 
00246   // Allows or not the character selection with mouse click (tab is allowed)
00247   // This is used in weapons like the automated bazooka, where it's required
00248   // a target. Default is true.
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   // Angle in radian between -PI to PI
00257   double min_angle, max_angle;
00258 };
00259 
00260 //-----------------------------------------------------------------------------
00261 #endif

Generated on Mon Jan 1 13:11:00 2007 for Wormux by  doxygen 1.4.7