Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6476 was 6445, checked in by bensch, 19 years ago

trunk: bars are nicer now

File size: 11.6 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"
18
[4759]19// FORWARD DECLARATION
[3575]20class Projectile;
[4955]21class WeaponManager;
[3886]22class Animation3D;
[4759]23class TiXmlElement;
[5355]24class FastFactory;
[4934]25template<class T> class tFastFactory;
[6438]26class GLGuiWidget;
[3573]27
[4890]28//! An enumerator defining Actions a Weapon can take
[4830]29typedef enum {
30  WA_NONE          =    0,    //!< No Action taken
31  WA_SHOOT         =    1,    //!< emitting Shot
32  WA_CHARGE        =    2,    //!< charge action (one click before the shot)
33  WA_RELOAD        =    3,    //!< reload right after shoot is finished
34  WA_ACTIVATE      =    4,    //!< activate the GUN
35  WA_DEACTIVATE    =    5,    //!< deactivate the GUN
36  WA_SPECIAL1      =    6,    //!< Special Action taken
[4826]37
[4832]38  WA_ACTION_COUNT  =    7     //!< This must match the count of enumerations-members.
[4885]39} WeaponAction;
[4826]40
[4827]41//! An enumerator defining the States of a Weapon
[3583]42typedef enum {
[4830]43  WS_NONE          =    0,    //!< No State at all (if set, there is something wrong, or the weapon is not yet availiable)
44  WS_SHOOTING      =    1,    //!< The State of the Shooting
[4885]45  WS_CHARGING      =    2,    //!< The state of charging th weapon
[4830]46  WS_RELOADING     =    3,    //!< The State of the Reloading
47  WS_ACTIVATING    =    4,    //!< The State in which the weapon gets activated
48  WS_DEACTIVATING  =    5,    //!< The State in which the weapon gets deactivated
49  WS_INACTIVE      =    6,    //!< The State where the weapon is inactive (unable to shoot)
50  WS_IDLE          =    7,    //!< The State where the weapon is idle
[4827]51
[4875]52  WS_STATE_COUNT  =     8     //!< This must match the count of enumerations-members.
[4826]53} WeaponState;
[3583]54
[4959]55//! an enumerator defining capabilities of a WeaponSlot
56typedef enum
57{
58  WTYPE_DIRECTIONAL   = 0x00000001,           //!< Weapon is directional/Slot is able to carry directional weapons
59  WTYPE_TURRET        = 0x00000002,           //!< Weapon is a turret/slot is able to carry turrets
60  WTYPE_ALLKINDS      = 0x0000000f,           //!< Weapon is all types/Slot is able to carry all kinds of weapons
[3870]61
[4959]62  WTYPE_FORWARD       = 0x00000010,           //!< Weapon fires forwards/Slot is able to carry weapons firing forwards
63  WTYPE_BACKWARD      = 0x00000020,           //!< Weapon fires backwards/Slot is able to carry weapons firing backwards
64  WTYPE_LEFT          = 0x00000040,           //!< Weapon fires to the left/Slot is able to carry weapons firing to the left
65  WTYPE_RIGHT         = 0x00000080,           //!< Weapon fires to the right/Slot is able to carry weapons firing to the right
66  WTYPE_ALLDIRS       = 0x000000f0,           //!< Weapon has no specific firing direction/Slot can fire into all directions
[3886]67
[4959]68  WTYPE_ALL           = 0x000000ff,           //!< Weapon has no limitations/Slot can handle all kinds of Weapon.
69} W_Capability;
70
[4827]71//! An abstract class, that describes weapons
72/**
73 * This is used as a container for all the different kinds of weapons that may exist
[4975]74 *
75 * Weapons have certain states, and actions, that can inflict them.
76 * ex. Action WA_SHOOT leeds to State WS_SHOOTING.
77 * each action has a sound connected to it,
78 * each state a time and an animation.
[4827]79 */
[4597]80class Weapon : public WorldEntity
[3573]81{
[4885]82  public:
83    // INITIALISATION //
[5750]84    Weapon ();
[4885]85    virtual ~Weapon ();
[3573]86
[4885]87    void init();
88    void loadParams(const TiXmlElement* root);
89    ////////////////////
[4597]90
[4947]91    // INTERACTIVITY //
[4885]92    void requestAction(WeaponAction action);
[4890]93    float increaseEnergy(float energyToAdd);
[4947]94    ///////////////////
[4759]95
[4906]96    /** @returns true if the Weapon is Active  (this is used to check if the weapon must be drawn)*/
[5750]97    inline bool isActive() const { return (this->currentState == WS_INACTIVE)? false : true; };
[4906]98    /** @returns true if the weapon must be drawn */
[5750]99    inline bool isVisible() const { return (this->currentState != WS_INACTIVE || !this->hideInactive) ? true : false; };
[4949]100    /** @returns true if the Weapon is chargeable */
101    inline bool isChargeable() const { return this->chargeable; };
[3577]102
[4885]103    // FUNCTIONS TO SET THE WEAPONS PROPERTIES.
[5441]104    /** sets the Weapons Capabilities */
105    inline void setCapability(long capabilities) { this->capability = capabilities; };
106    /** @returns the Capabilities of this Weapon */
107    inline long getCapability() { return this->capability; };
[5356]108    void setProjectileType(ClassID projectile);
109    void setProjectileType(const char* projectile);
[4947]110    /** @returns The projectile's classID */
[5356]111    inline ClassID getProjectileType() { return this->projectile; };
[4947]112    /** @returns the FastFactory, that creates Projectiles of type getProjectile */
113    inline FastFactory* getProjectileFactory() { return this->projectileFactory; };
[5356]114    void prepareProjectiles(unsigned int count);
115    Projectile* getProjectile();
[3575]116
[4947]117
[5750]118    // EMISSION
[4892]119    void setEmissionPoint(const Vector& point);
120    /** @see void setEmissionPoint(const Vector& point); */
[4972]121    inline void setEmissionPoint(float x, float y, float z) { this->setEmissionPoint(Vector(x, y, z)); };
[4927]122    /** @returns the absolute Position of the EmissionPoint */
123    inline const Vector& getEmissionPoint() const { return this->emissionPoint.getAbsCoor(); };
[4892]124
[5750]125    // STATE CHANGES //
[4885]126    /** @param state the State to time @param duration the duration of the State */
127    inline void setStateDuration(const char* state, float duration) { setStateDuration(charToState(state), duration); };
128    /** @param state the State to time @param duration the duration of the State */
129    inline void setStateDuration(WeaponState state, float duration) { /*(state < WS_STATE_COUNT)?*/this->times[state] = duration; };
130    /** @param state The state to query @returns the Time the queried State takes to complete */
[5750]131    inline float getStateDuration(WeaponState state) const { return (state < WS_STATE_COUNT)? this->times[state] : 0.0; };
[4885]132    /** @returns true if the time of the currentState is elapsed, false otherwise */
[5750]133    inline bool stateTimeElapsed() const { return (this->stateDuration > this->times[currentState])? true : false; };
[4885]134    /** @returns the current State of the Weapon */
135    inline WeaponState getCurrentState() const { return this->currentState; };
[4892]136
[4885]137    /** @param energyMax the maximum energy the Weapon can have @param energyLoadedMax the maximum energy in the weapon buffers */
[4930]138    inline void setMaximumEnergy(float energyMax, float energyLoadedMax) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; };
[6306]139    inline float getLoadedEnergyMax() const { return this->energyLoadedMax; };
140    inline float getEnergyMax() const { return this->energyMax; };
141    inline float getEnergy() const { return this->energy; };
142    inline float getLoadedEnergy() const { return this->energyLoaded; };
[3575]143
[4885]144    void setActionSound(WeaponAction action, const char* soundFile);
145    /** @see void setActionSound(WeaponAction action, const char* soundFile); */
146    void setActionSound(const char* action, const char* soundFile) { this->setActionSound(charToAction(action), soundFile); };
[3575]147
[4895]148    Animation3D* getAnimation(WeaponState state, PNode* node = NULL);
[4906]149    Animation3D* copyAnimation(WeaponState from, WeaponState to);
[4597]150
[6438]151    GLGuiWidget* getEnergyWidget();
[6445]152    GLGuiWidget* getLoadedEnergyWidget();
[6438]153
[4885]154    // FLOW
[6439]155    void 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]156
[6439]157    virtual void tick(float dt) {};
158
[4891]159    bool check() const;
[4885]160    void debug() const;
[3886]161
[4885]162  protected:
163    //! ACTION: these functions are handled by the Weapon itself, and must be called by requestAction(WeaponAction);
[4892]164    virtual void activate() {};
165    virtual void deactivate() {};
166    virtual void charge() {};
167    virtual void fire() {};
168    virtual void reload() {};
169    virtual void destroy() {};
[3886]170
[4890]171
172    // utility:
173    static WeaponAction  charToAction(const char* action);
174    static const char*   actionToChar(WeaponAction action);
175    static WeaponState   charToState(const char* state);
176    static const char*   stateToChar(WeaponState state);
[4891]177
[4885]178  private:
[4892]179    /** executive functions, that handle timing with actions.
180     * This is for the action-functions in derived functions to be easy
181     * The main function is execute, that calls all the other functions
182     * for being fast, the Functions are private and as such will be inlined
183     * into the execute function. (this is work of the compiler)
184     */
185    bool execute();
186    bool activateW();
187    bool deactivateW();
188    bool chargeW();
189    bool fireW();
190    bool reloadW();
[4926]191    inline void enterState(WeaponState state);
[3886]192
[6438]193    void updateWidgets();
[4926]194
[4927]195  private:
[5441]196    // type of Weapon
197    long                 capability;                       //!< what capabilities the Weapon has @see W_Capability
198
[4885]199    // it is all about energy
[4890]200    float                energy;                           //!< The energy stored in the weapons secondary buffers (reserve)
[5750]201    float                energyLoaded;                     //!< The energy stored in the weapons primary buffers (fire without reload)
[4890]202    float                energyMax;                        //!< The maximal energy that can be stored in the secondary buffers (reserveMax)
203    float                energyLoadedMax;                  //!< The maximal energy that can be stored in the primary buffers
[4910]204    //! @todo move this to projectile
[4890]205    float                minCharge;                        //!< The minimal energy to be loaded onto one projectile if chargeable otherwise the power consumed by one projectile
206    float                maxCharge;                        //!< The maximal energy to be loaded onto one projectile (this is only availible if chargeable is enabled)
[3573]207
[6438]208    GLGuiBar*            energyWidget;
209    GLGuiBar*            energyLoadedWidget;
210
[4885]211    ////////////
212    // PHASES //
213    ////////////
[4910]214    SoundSource*         soundSource;                      //!< A SoundSource to play sound from (this is connected to the PNode of the Weapon)
215
[4885]216    WeaponState          currentState;                     //!< The State the weapon is in.
217    WeaponAction         requestedAction;                  //!< An action to try to Engage after the currentState ends.
218    float                stateDuration;                    //!< how long the state has taken until now.
219    float                times[WS_STATE_COUNT];            //!< Times to stay in the different States @see WeaponState.
220    Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
221    SoundBuffer*         soundBuffers[WA_ACTION_COUNT];    //!< SoundBuffers for all actions @see WeaponAction.
222
[4892]223    PNode                emissionPoint;                   //!< The point, where the projectiles are emitted. (this is coppled with the Weapon by default)
[4885]224
225    bool                 hideInactive;                    //!< Hides the Weapon if it is inactive
[4930]226    bool                 chargeable;                      //!< if the Weapon is charcheable (if true, the weapon will charge before it fires.)
[4885]227
[4947]228    ClassID              projectile;                      //!< the projectile used for this weapon (since they should be generated via macro and the FastFactory, only the ClassID must be known.)
229    FastFactory*         projectileFactory;               //!< A factory, that produces and handles the projectiles.
[4885]230  };
231
[3573]232#endif /* _WEAPON_H */
Note: See TracBrowser for help on using the repository browser.