Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h @ 4876

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

orxonox/branches: added branche weaponSystem
also deleted now obsolete oggPlayer branche (since simon is for at least 4 months in China, and it has partly been implemented in the TRUNK

File size: 5.0 KB
RevLine 
[4597]1/*!
[3573]2    \file weapon.h
[4836]3  *  a weapon that a  can use
[3573]4
5
6    A weapon is characterized by:
7     o firing-rate: the initial firing rate of a weapon (1/s = Herz)
8     o slowdown-factor: this is a factor d: exp(-d*x), d is element of all positive R. it determines how fast the firing-rate will slow down. if no slowdown: d=0, the bigger d is, the faster the weapon will slow down!
9     o energy-consumption: this determines the energy that has to be used to produce this projectile = costs per projectile
[4597]10
[3573]11    Furthermore there are some other attributes, that will help to represent a firing
12    weapon in this world:
13     o sound file/ressource: this is a pointer to the sound-file/ressource. however it may be represented
[3575]14     o shooting animation
[3573]15*/
16
17
18#ifndef _WEAPON_H
19#define _WEAPON_H
20
[4597]21#include "base_object.h"
[3573]22#include "world_entity.h"
23
[4759]24// FORWARD DECLARATION
[3575]25class Projectile;
[3862]26class Weapon;
[3886]27class Animation3D;
[4759]28class TiXmlElement;
[3573]29
[4830]30//! An enumerator defining actions a Weapon can take
31typedef enum {
32  WA_NONE          =    0,    //!< No Action taken
33  WA_SHOOT         =    1,    //!< emitting Shot
34  WA_CHARGE        =    2,    //!< charge action (one click before the shot)
35  WA_RELOAD        =    3,    //!< reload right after shoot is finished
36  WA_ACTIVATE      =    4,    //!< activate the GUN
37  WA_DEACTIVATE    =    5,    //!< deactivate the GUN
38  WA_SPECIAL1      =    6,    //!< Special Action taken
[4826]39
[4832]40  WA_ACTION_COUNT  =    7     //!< This must match the count of enumerations-members.
[4830]41} WeaponActions;
[4826]42
[4827]43//! An enumerator defining the States of a Weapon
[3583]44typedef enum {
[4830]45  WS_NONE          =    0,    //!< No State at all (if set, there is something wrong, or the weapon is not yet availiable)
46  WS_SHOOTING      =    1,    //!< The State of the Shooting
47  WS_RELOADING     =    3,    //!< The State of the Reloading
48  WS_ACTIVATING    =    4,    //!< The State in which the weapon gets activated
49  WS_DEACTIVATING  =    5,    //!< The State in which the weapon gets deactivated
50  WS_INACTIVE      =    6,    //!< The State where the weapon is inactive (unable to shoot)
51  WS_IDLE          =    7,    //!< The State where the weapon is idle
[4827]52
[4875]53  WS_STATE_COUNT  =     8     //!< This must match the count of enumerations-members.
[4826]54} WeaponState;
[3583]55
[3870]56
[3886]57//! a weapon can be left or right sided
[4830]58/**
59 * @todo this will be reset with mirror X/Y/Z
60 */
[4759]61#define    W_LEFT        0
62#define    W_RIGHT       1
[3886]63
[4827]64//! An abstract class, that describes weapons
65/**
66 * This is used as a container for all the different kinds of weapons that may exist
67 */
[4597]68class Weapon : public WorldEntity
[3573]69{
70  friend class World;
71
72 public:
[3881]73  Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
[4759]74  Weapon(const TiXmlElement* root);
[3573]75  virtual ~Weapon ();
[4597]76
[4759]77  void init();
78  void loadParams(const TiXmlElement* root);
79
[4746]80  void enable();
81  void disable();
82  bool isEnabled();
[3577]83
[3575]84  void setProjectile(Projectile* projectile);
[4746]85  Projectile* getProjectile();
[3575]86
[4746]87  virtual void activate();
88  virtual void deactivate();
89  bool isActive();
[3575]90
91
[4827]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 */
[4875]97  inline bool hasWeaponIdleTimeElapsed() const { return (this->localTime > this->idleTime)?true:false; };
[4597]98
[4836]99  /**  fires the weapon */
[4746]100  virtual void fire() = 0;
[4830]101  virtual void hit (WorldEntity* weapon, const Vector& loc);
[4746]102  virtual void destroy();
[4597]103
[3583]104  virtual void tick(float time);
[4746]105  virtual void weaponIdle();
106  virtual void draw();
[3573]107
[3629]108 protected:
[4830]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...
[3886]112
[4830]113  ////////////
114  // PHASES //
115  ////////////
[4875]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.
[4831]120  Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
[4830]121
[4827]122  SoundBuffer*         fireSound;
123  SoundSource*         weaponSource;
[3886]124
[4875]125  float                minCharge;
126  float                maxCharge;
[3886]127
[3573]128 private:
[4831]129   bool                 enabled;                         //<! states if the weapon is enabled or not
130   Projectile*          projectile;                      //<! the projectile used for this weapon
[3583]131  //WeaponSound sound;
[3573]132};
133
134#endif /* _WEAPON_H */
Note: See TracBrowser for help on using the repository browser.