Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 18, 2005, 3:36:18 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the weaponSystem back to the trunk, because it seems safe
merged with command:
svn merge -r 4847:HEAD branches/weaponSystem/ trunk/
conflict in file src/world-entities/weapons/weapon.h resolved in favor of the weaponSystem

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/world_entities/weapons/weapon.h

    r4875 r4885  
    1212    weapon in this world:
    1313     o sound file/ressource: this is a pointer to the sound-file/ressource. however it may be represented
    14      o shooting animation
     14     o animations
    1515*/
    1616
     
    3939
    4040  WA_ACTION_COUNT  =    7     //!< This must match the count of enumerations-members.
    41 } WeaponActions;
     41} WeaponAction;
    4242
    4343//! An enumerator defining the States of a Weapon
     
    4545  WS_NONE          =    0,    //!< No State at all (if set, there is something wrong, or the weapon is not yet availiable)
    4646  WS_SHOOTING      =    1,    //!< The State of the Shooting
     47  WS_CHARGING      =    2,    //!< The state of charging th weapon
    4748  WS_RELOADING     =    3,    //!< The State of the Reloading
    4849  WS_ACTIVATING    =    4,    //!< The State in which the weapon gets activated
     
    6869class Weapon : public WorldEntity
    6970{
    70   friend class World;
     71  public:
     72    // INITIALISATION //
     73    Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
     74    Weapon(const TiXmlElement* root);
     75    virtual ~Weapon ();
    7176
    72  public:
    73   Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
    74   Weapon(const TiXmlElement* root);
    75   virtual ~Weapon ();
     77    void init();
     78    void loadParams(const TiXmlElement* root);
     79    ////////////////////
    7680
    77   void init();
    78   void loadParams(const TiXmlElement* root);
     81    void requestAction(WeaponAction action);
    7982
    80   void enable();
    81   void disable();
    82   bool isEnabled();
     83    /** @returns true if the Weapon is Active */
     84    inline bool isActive() const { return this->active; };
    8385
    84   void setProjectile(Projectile* projectile);
    85   Projectile* getProjectile();
     86    // FUNCTIONS TO SET THE WEAPONS PROPERTIES.
     87    /** @param projectile a projectile for this weapon */
     88    void setProjectile(Projectile* projectile) { this->projectile = projectile; };
     89    /** @returns The projectile if availiable */
     90    Projectile* getProjectile() { return this->projectile; };
    8691
    87   virtual void activate();
    88   virtual void deactivate();
    89   bool isActive();
     92    /** @param state the State to time @param duration the duration of the State */
     93    inline void setStateDuration(const char* state, float duration) { setStateDuration(charToState(state), duration); };
     94    /** @param state the State to time @param duration the duration of the State */
     95    inline void setStateDuration(WeaponState state, float duration) { /*(state < WS_STATE_COUNT)?*/this->times[state] = duration; };
     96    /** @param state The state to query @returns the Time the queried State takes to complete */
     97    inline float getStateDuration(WeaponState state) const { return (state < WS_STATE_COUNT)?this->times[state]:0.0; };
     98    /** @returns true if the time of the currentState is elapsed, false otherwise */
     99    inline bool stateTimeElapsed() const { return (this->stateDuration > this->times[currentState])?true:false; };
     100    /** @returns the current State of the Weapon */
     101    inline WeaponState getCurrentState() const { return this->currentState; };
     102    /** @param energyMax the maximum energy the Weapon can have @param energyLoadedMax the maximum energy in the weapon buffers */
     103    inline void setMaximumEnergy(float energyMax, float energyLoadedMax = 0.0) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; };
     104
     105    void setActionSound(WeaponAction action, const char* soundFile);
     106    /** @see void setActionSound(WeaponAction action, const char* soundFile); */
     107    void setActionSound(const char* action, const char* soundFile) { this->setActionSound(charToAction(action), soundFile); };
     108
     109    virtual void destroy();
    90110
    91111
    92   /** @param idle time in ms  */
    93   inline void setWeaponIdleTime(float idleTime) { this->idleTime = idleTime; };
    94   /** @returns idle time in ms */
    95   inline float getWeaponIdleTime() const { return this->idleTime; };
    96   /** @return true if idletime is elapsed else otherwise */
    97   inline bool hasWeaponIdleTimeElapsed() const { return (this->localTime > this->idleTime)?true:false; };
     112    // FLOW
     113    virtual void tick(float dt);
     114    virtual void draw();
    98115
    99   /**  fires the weapon */
    100   virtual void fire() = 0;
    101   virtual void hit (WorldEntity* weapon, const Vector& loc);
    102   virtual void destroy();
     116    void debug() const;
    103117
    104   virtual void tick(float time);
    105   virtual void weaponIdle();
    106   virtual void draw();
     118  protected:
     119    // utility:
     120    static WeaponAction  charToAction(const char* action);
     121    static const char*   actionToChar(WeaponAction action);
     122    static WeaponState   charToState(const char* state);
     123    static const char*   stateToChar(WeaponState state);
    107124
    108  protected:
    109   float                localTime;                        //<! this is the local time. important for shooting attributes like frequency
    110   float                idleTime;                         //<! the time a weapon needs before it can shoot again. eg. shooting frequency or actication/deactivateion delay
    111   float                slowDownFactor;                   //<! if the shooting frequency is a linear function of time...
     125    //! ACTION: these functions are handled by the Weapon itself, and must be called by requestAction(WeaponAction);
     126    bool execute();
     127    virtual void activate();
     128    virtual void deactivate();
     129    virtual void fire();
     130    virtual void reload();
     131    virtual void charge();
    112132
    113   ////////////
    114   // PHASES //
    115   ////////////
    116   WeaponState          currentState;                     //!< The State the weapon is in.
    117   float                stateTime;                        //!< how long the state has teken until now.
    118   float                times[WS_STATE_COUNT];            //!< Times to stay in the different States @see WeaponState.
    119   SoundBuffer*         soundBuffers[WA_ACTION_COUNT];    //!< SoundBuffers for all actions @see WeaponAction.
    120   Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
     133  private:
     134    bool nextActionValid() const;
    121135
    122   SoundBuffer*         fireSound;
    123   SoundSource*         weaponSource;
     136  protected:
     137    SoundSource*         soundSource;
     138    // it is all about energy
     139    float                energy;
     140    float                energyLoaded;
     141    float                energyMax;
     142    float                energyLoadedMax;
     143    float                minCharge;
     144    float                maxCharge;
    124145
    125   float                minCharge;
    126   float                maxCharge;
     146    ////////////
     147    // PHASES //
     148    ////////////
     149  private:
     150    WeaponState          currentState;                     //!< The State the weapon is in.
     151    WeaponAction         requestedAction;                  //!< An action to try to Engage after the currentState ends.
     152    float                stateDuration;                    //!< how long the state has taken until now.
     153    float                times[WS_STATE_COUNT];            //!< Times to stay in the different States @see WeaponState.
     154    Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
     155    SoundBuffer*         soundBuffers[WA_ACTION_COUNT];    //!< SoundBuffers for all actions @see WeaponAction.
    127156
    128  private:
    129    bool                 enabled;                         //<! states if the weapon is enabled or not
    130    Projectile*          projectile;                      //<! the projectile used for this weapon
    131   //WeaponSound sound;
    132 };
     157
     158    bool                 hideInactive;                    //!< Hides the Weapon if it is inactive
     159
     160    bool                 active;                          //!< states wheter the weapon is enabled or not
     161    Projectile*          projectile;                      //!< the projectile used for this weapon
     162  };
    133163
    134164#endif /* _WEAPON_H */
Note: See TracChangeset for help on using the changeset viewer.