Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/weaponSystem: some more definitions

File size: 4.8 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.
[4879]41} WeaponAction;
[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
[3575]80  void setProjectile(Projectile* projectile);
[4746]81  Projectile* getProjectile();
[3575]82
[4746]83  virtual void activate();
84  virtual void deactivate();
[4878]85  virtual void fire() = 0;
86  //virtual void reload();
87  //virtual void charge();
88  bool isActive() const { return this->active; };
[3575]89
[4878]90  // FUNCTIONS TO SET THE WEAPONS PROPERTIES.
91  void setStateDuration(const char* state, float duration);
92  void setStateDuration(WeaponState state, float duration);
93  float getStateDuration(WeaponState state) { return (state < WS_STATE_COUNT)?this->times[state]:0.0; };
94  /** @return true if idletime is elapsed, false otherwise */
95  inline bool stateTimeElapsed() const { return (this->stateTime > this->times[currentState])?true:false; };
[3575]96
[4836]97  /**  fires the weapon */
[4830]98  virtual void hit (WorldEntity* weapon, const Vector& loc);
[4746]99  virtual void destroy();
[4597]100
[3583]101  virtual void tick(float time);
[4746]102  virtual void draw();
[3573]103
[4879]104  private:
105    static WeaponAction  charToAction(const char* action);
106    static WeaponState   charToState(const char* state);
107
108
[3629]109 protected:
[4830]110  ////////////
111  // PHASES //
112  ////////////
[4875]113  WeaponState          currentState;                     //!< The State the weapon is in.
[4879]114  WeaponAction         requestAction;                    //!< An action to try to Engage after the currentState ends.
[4878]115  float                stateTime;                        //!< how long the state has taken until now.
[4875]116  float                times[WS_STATE_COUNT];            //!< Times to stay in the different States @see WeaponState.
117  SoundBuffer*         soundBuffers[WA_ACTION_COUNT];    //!< SoundBuffers for all actions @see WeaponAction.
[4831]118  Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
[4830]119
[4827]120  SoundBuffer*         fireSound;
121  SoundSource*         weaponSource;
[3886]122
[4875]123  float                minCharge;
124  float                maxCharge;
[3886]125
[3573]126 private:
[4878]127   bool                 active;                          //!< states wheter the weapon is enabled or not
128   Projectile*          projectile;                      //!< the projectile used for this weapon
[3573]129};
130
131#endif /* _WEAPON_H */
Note: See TracBrowser for help on using the repository browser.