Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/weapon.h @ 10706

Last change on this file since 10706 was 10698, checked in by snellen, 18 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

File size: 13.9 KB
RevLine 
[4597]1/*!
[4959]2 * @file weapon.h
3 *
4 * Weapon is the mayor baseclass for all weapons. it is quite extensive, and expensive in use,
5 * because each weapon will know virutal functions for the WorldEntity's part, and also virtuals
6 * for Fireing/Reloading/...,
7 * quickly said: Weapon is a wrapper for weapons, that makes it easy to very quickly implement
8 * new Weapons, and with them make this game better, than any game before it, because still
9 * Weapons (GUNS) are the most important thing in life :?... no to be serious
10 * @see Weapon
11 */
[3573]12
13
14#ifndef _WEAPON_H
15#define _WEAPON_H
16
17#include "world_entity.h"
[6669]18#include "count_pointer.h"
19#include "ammo_container.h"
[3573]20
[9869]21#include "sound_buffer.h"
22
[4759]23// FORWARD DECLARATION
[3575]24class Projectile;
[4955]25class WeaponManager;
[3886]26class Animation3D;
[4759]27class TiXmlElement;
[5355]28class FastFactory;
[4934]29template<class T> class tFastFactory;
[3573]30
[4890]31//! An enumerator defining Actions a Weapon can take
[4830]32typedef enum {
33  WA_NONE          =    0,    //!< No Action taken
34  WA_SHOOT         =    1,    //!< emitting Shot
35  WA_CHARGE        =    2,    //!< charge action (one click before the shot)
36  WA_RELOAD        =    3,    //!< reload right after shoot is finished
37  WA_ACTIVATE      =    4,    //!< activate the GUN
38  WA_DEACTIVATE    =    5,    //!< deactivate the GUN
39  WA_SPECIAL1      =    6,    //!< Special Action taken
[4826]40
[4832]41  WA_ACTION_COUNT  =    7     //!< This must match the count of enumerations-members.
[4885]42} WeaponAction;
[4826]43
[4827]44//! An enumerator defining the States of a Weapon
[3583]45typedef enum {
[4830]46  WS_NONE          =    0,    //!< No State at all (if set, there is something wrong, or the weapon is not yet availiable)
47  WS_SHOOTING      =    1,    //!< The State of the Shooting
[4885]48  WS_CHARGING      =    2,    //!< The state of charging th weapon
[4830]49  WS_RELOADING     =    3,    //!< The State of the Reloading
50  WS_ACTIVATING    =    4,    //!< The State in which the weapon gets activated
51  WS_DEACTIVATING  =    5,    //!< The State in which the weapon gets deactivated
52  WS_INACTIVE      =    6,    //!< The State where the weapon is inactive (unable to shoot)
53  WS_IDLE          =    7,    //!< The State where the weapon is idle
[4827]54
[4875]55  WS_STATE_COUNT  =     8     //!< This must match the count of enumerations-members.
[4826]56} WeaponState;
[3583]57
[4959]58//! an enumerator defining capabilities of a WeaponSlot
59typedef enum
60{
61  WTYPE_DIRECTIONAL   = 0x00000001,           //!< Weapon is directional/Slot is able to carry directional weapons
62  WTYPE_TURRET        = 0x00000002,           //!< Weapon is a turret/slot is able to carry turrets
[6803]63  WTYPE_LIGHT         = 0x00000004,           //!< For light Armament.
64  WTYPE_HEAVY         = 0x00000008,           //!< The heavy Armament (Cannons).
[4959]65  WTYPE_ALLKINDS      = 0x0000000f,           //!< Weapon is all types/Slot is able to carry all kinds of weapons
[3870]66
[4959]67  WTYPE_FORWARD       = 0x00000010,           //!< Weapon fires forwards/Slot is able to carry weapons firing forwards
68  WTYPE_BACKWARD      = 0x00000020,           //!< Weapon fires backwards/Slot is able to carry weapons firing backwards
69  WTYPE_LEFT          = 0x00000040,           //!< Weapon fires to the left/Slot is able to carry weapons firing to the left
70  WTYPE_RIGHT         = 0x00000080,           //!< Weapon fires to the right/Slot is able to carry weapons firing to the right
71  WTYPE_ALLDIRS       = 0x000000f0,           //!< Weapon has no specific firing direction/Slot can fire into all directions
[3886]72
[4959]73  WTYPE_ALL           = 0x000000ff,           //!< Weapon has no limitations/Slot can handle all kinds of Weapon.
74} W_Capability;
75
[4827]76//! An abstract class, that describes weapons
77/**
78 * This is used as a container for all the different kinds of weapons that may exist
[4975]79 *
80 * Weapons have certain states, and actions, that can inflict them.
81 * ex. Action WA_SHOOT leeds to State WS_SHOOTING.
82 * each action has a sound connected to it,
83 * each state a time and an animation.
[4827]84 */
[4597]85class Weapon : public WorldEntity
[3573]86{
[9869]87  ObjectListDeclaration(Weapon);
88
[4885]89  public:
90    // INITIALISATION //
[5750]91    Weapon ();
[4885]92    virtual ~Weapon ();
[9869]93    static Weapon* createWeapon(const ClassID& weaponID);
94    static Weapon* createWeapon(const std::string& weaponName);
[3573]95
[4885]96    void init();
[6512]97    virtual void loadParams(const TiXmlElement* root);
[4885]98    ////////////////////
[4597]99
[4947]100    // INTERACTIVITY //
[4885]101    void requestAction(WeaponAction action);
[4890]102    float increaseEnergy(float energyToAdd);
[4947]103    ///////////////////
[4759]104
[4906]105    /** @returns true if the Weapon is Active  (this is used to check if the weapon must be drawn)*/
[5750]106    inline bool isActive() const { return (this->currentState == WS_INACTIVE)? false : true; };
[4906]107    /** @returns true if the weapon must be drawn */
[5750]108    inline bool isVisible() const { return (this->currentState != WS_INACTIVE || !this->hideInactive) ? true : false; };
[4949]109    /** @returns true if the Weapon is chargeable */
110    inline bool isChargeable() const { return this->chargeable; };
[3577]111
[4885]112    // FUNCTIONS TO SET THE WEAPONS PROPERTIES.
[5441]113    /** sets the Weapons Capabilities */
114    inline void setCapability(long capabilities) { this->capability = capabilities; };
115    /** @returns the Capabilities of this Weapon */
[6669]116    inline long getCapability() const { return this->capability; };
[9869]117    void setProjectileType(const ClassID& projectile);
[7221]118    void setProjectileTypeC(const std::string& projectile);
[4947]119    /** @returns The projectile's classID */
[5356]120    inline ClassID getProjectileType() { return this->projectile; };
[4947]121    /** @returns the FastFactory, that creates Projectiles of type getProjectile */
122    inline FastFactory* getProjectileFactory() { return this->projectileFactory; };
[5356]123    void prepareProjectiles(unsigned int count);
124    Projectile* getProjectile();
[3575]125
[10698]126    inline void setScaling(float scaling) { this->scaling = scaling; };
127    inline float getScaling() { return this->scaling; };
[4947]128
[5750]129    // EMISSION
[10368]130    /** keeping old functions*/
131    void setEmissionPoint(const Vector& point, int barrel);
[4892]132    void setEmissionPoint(const Vector& point);
133    /** @see void setEmissionPoint(const Vector& point); */
[10368]134    inline void setEmissionPoint(float x, float y, float z, int barrel) { this->setEmissionPoint(Vector(x, y, z), barrel); };
[4972]135    inline void setEmissionPoint(float x, float y, float z) { this->setEmissionPoint(Vector(x, y, z)); };
[4927]136    /** @returns the absolute Position of the EmissionPoint */
[10368]137    inline const Vector& getEmissionPoint(int barrel) const { return this->emissionPoint[barrel]->getAbsCoor(); };
138    inline const Vector& getEmissionPoint() const { return this->emissionPoint[0]->getAbsCoor(); };
[4892]139
[10368]140
[6920]141    inline void setDefaultTarget(PNode* defaultTarget) { this->defaultTarget = defaultTarget; };
142    inline PNode* getDefaultTarget() const { return this->defaultTarget; };
[6756]143
[5750]144    // STATE CHANGES //
[4885]145    /** @param state the State to time @param duration the duration of the State */
[7221]146    inline void setStateDuration(const std::string& state, float duration) { setStateDuration(charToState(state), duration); };
[4885]147    /** @param state the State to time @param duration the duration of the State */
148    inline void setStateDuration(WeaponState state, float duration) { /*(state < WS_STATE_COUNT)?*/this->times[state] = duration; };
149    /** @param state The state to query @returns the Time the queried State takes to complete */
[5750]150    inline float getStateDuration(WeaponState state) const { return (state < WS_STATE_COUNT)? this->times[state] : 0.0; };
[4885]151    /** @returns true if the time of the currentState is elapsed, false otherwise */
[5750]152    inline bool stateTimeElapsed() const { return (this->stateDuration > this->times[currentState])? true : false; };
[4885]153    /** @returns the current State of the Weapon */
154    inline WeaponState getCurrentState() const { return this->currentState; };
[4892]155
[6671]156    /** @param energyMax the maximum energy the Weapon can have */
157    inline void setEnergyMax(float energyMax) { this->energyMax = energyMax; };
158    inline float getEnergy() const { return this->energy; };
[6306]159    inline float getEnergyMax() const { return this->energyMax; };
[6669]160    inline void setAmmoContainer(const CountPointer<AmmoContainer>& ammoContainer) { this->ammoContainer = ammoContainer;}
[3575]161
[7221]162    void setActionSound(WeaponAction action, const std::string& soundFile);
163    /** @see void setActionSound(WeaponAction action, const std::string& soundFile); */
164    void setActionSound(const std::string& action, const std::string& soundFile) { this->setActionSound(charToAction(action), soundFile); };
[3575]165
[4895]166    Animation3D* getAnimation(WeaponState state, PNode* node = NULL);
[10368]167    Animation3D* getAnimation(int barrel, int seg, PNode* node);
[4906]168    Animation3D* copyAnimation(WeaponState from, WeaponState to);
[4597]169
[7779]170    OrxGui::GLGuiWidget* getEnergyWidget();
[6438]171
[4885]172    // FLOW
[6736]173    bool tickW(float dt); //!< this is a function that must be called by the weaponManager, or any other weaponHandler, all other functions are handled from within
[5750]174
[6736]175    virtual void tick(float dt) { tickW(dt); };
[6439]176
[4891]177    bool check() const;
[4885]178    void debug() const;
[3886]179
[10368]180    inline int getBarrels() {return this->barrels; };
181    inline int getSegs() { return this->segs; };
182    inline void setBarrels(int barrels) { this->barrels = barrels; };
183    inline void setSegs(int segs) { this->segs = segs; };
184
[10698]185//     inline Animation3D* getShootAnim(int barrel, int seg) { return this->shootAnim[barrel][seg]; };
186//     inline void setShootAnim(int barrel, int seg, PNode* component) { this->shootAnim[barrel][seg] = this->getAnimation(barrel, seg, component); };
[10368]187
[10698]188//     void init2();
[10368]189    void deconstr();
190
[10443]191    inline int getPreferedSide() { return this->preferedSide; }
192    inline int getPreferedSlot() { return this->preferedSlot; }
193
[10516]194    inline void setEnergyWidgetInitialized(bool b) {this->isEnergyWidgetInitialized = b;};
[10443]195
[10516]196
[4885]197  protected:
198    //! ACTION: these functions are handled by the Weapon itself, and must be called by requestAction(WeaponAction);
[4892]199    virtual void activate() {};
200    virtual void deactivate() {};
201    virtual void charge() {};
202    virtual void fire() {};
203    virtual void reload() {};
[3886]204
[4890]205
206    // utility:
[7221]207    static WeaponAction  charToAction(const std::string& action);
[4890]208    static const char*   actionToChar(WeaponAction action);
[7221]209    static WeaponState   charToState(const std::string& state);
[4890]210    static const char*   stateToChar(WeaponState state);
[4891]211
[10443]212    void setPreferedSlot(int slot, int side) { this->preferedSlot = slot; this->preferedSide = side; }
[10368]213
[10516]214    //gui
215    OrxGui::GLGuiEnergyWidgetVertical* energyWidget;
216    bool  isEnergyWidgetInitialized;
[10368]217
[10516]218
[4885]219  private:
[4892]220    /** executive functions, that handle timing with actions.
221     * This is for the action-functions in derived functions to be easy
222     * The main function is execute, that calls all the other functions
223     * for being fast, the Functions are private and as such will be inlined
224     * into the execute function. (this is work of the compiler)
225     */
226    bool execute();
227    bool activateW();
228    bool deactivateW();
229    bool chargeW();
230    bool fireW();
231    bool reloadW();
[4926]232    inline void enterState(WeaponState state);
[3886]233
[6438]234    void updateWidgets();
[4926]235
[4927]236  private:
[5441]237    // type of Weapon
238    long                 capability;                       //!< what capabilities the Weapon has @see W_Capability
239
[4885]240    // it is all about energy
[6671]241    float                energy;                           //!< The energy stored in the weapons buffers
242    float                energyMax;                        //!< The maximal energy that can be stored in the secondary buffers (reserveMax)
[6669]243    CountPointer<AmmoContainer> ammoContainer;             //!< Pointer to the AmmoContainer this weapon grabs Energy from.
[4910]244    //! @todo move this to projectile
[4890]245    float                minCharge;                        //!< The minimal energy to be loaded onto one projectile if chargeable otherwise the power consumed by one projectile
246    float                maxCharge;                        //!< The maximal energy to be loaded onto one projectile (this is only availible if chargeable is enabled)
[3573]247
[10516]248    //OrxGui::GLGuiEnergyWidgetVertical* energyWidget;
[6438]249
[6920]250    PNode*               defaultTarget;                    //!< A target for targeting Weapons.
[6756]251
[10698]252    float                scaling;                          //!< Local scaling factor. any scaling will be done through this vector.
253
[4885]254    ////////////
255    // PHASES //
256    ////////////
[9869]257    OrxSound::SoundSource* soundSource;                     //!< A SoundSource to play sound from (this is connected to the PNode of the Weapon)
[4910]258
[9869]259    WeaponState            currentState;                    //!< The State the weapon is in.
260    WeaponAction           requestedAction;                 //!< An action to try to Engage after the currentState ends.
261    float                  stateDuration;                   //!< how long the state has taken until now.
262    float                  times[WS_STATE_COUNT];           //!< Times to stay in the different States @see WeaponState.
263    Animation3D*           animation[WS_STATE_COUNT];       //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
264    OrxSound::SoundBuffer  soundBuffers[WA_ACTION_COUNT];   //!< SoundBuffers for all actions @see WeaponAction.
[4885]265
[10368]266    PNode**                emissionPoint;                   //!< The point, where the projectiles are emitted. (this is coppled with the Weapon by default)
[4885]267
[7460]268    bool                   hideInactive;                    //!< Hides the Weapon if it is inactive
269    bool                   chargeable;                      //!< if the Weapon is charcheable (if true, the weapon will charge before it fires.)
[4885]270
[7460]271    ClassID                projectile;                      //!< the projectile used for this weapon (since they should be generated via macro and the FastFactory, only the ClassID must be known.)
272    FastFactory*           projectileFactory;               //!< A factory, that produces and handles the projectiles.
[10368]273
274    int                    barrels;                         //!< # of barrels
275    int                    segs;                             //!< # of segments, one barrel has
276    Animation3D***         shootAnim;
277
[10443]278    int                    preferedSlot;                    //!< prefered slot to add
279    int                    preferedSide;                    //!< prefered side (left/right) to be added
280
[4885]281  };
282
[3573]283#endif /* _WEAPON_H */
Note: See TracBrowser for help on using the repository browser.