Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/openAL/src/world_entities/weapon.h @ 4208

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

orxonox/branches/openAL: shoots now have a cool sound

File size: 5.5 KB
RevLine 
[3573]1/*!
2    \file weapon.h
3    \brief a weapon that a player can use
4
5    A Player has a list of weapons, that can be choosen to shoot projectiles
6    (projectiles.{cc,h}) at ennemies. These weapons can be shooted sequentially
7    or (if able) combined. Therefore you can choose the weapon mode = choose
8    a weapon.
9
10    A weapon is characterized by:
11     o firing-rate: the initial firing rate of a weapon (1/s = Herz)
12     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!
13     o energy-consumption: this determines the energy that has to be used to produce this projectile = costs per projectile
14   
15    Furthermore there are some other attributes, that will help to represent a firing
16    weapon in this world:
17     o sound file/ressource: this is a pointer to the sound-file/ressource. however it may be represented
[3575]18     o shooting animation
[3573]19     
[3862]20
21     a player defines one or more weapon configurations. a player has got one to eight
22     weapon slots: places where weapons can be attached to. a weapon configuration
23     is a matching between weapons and slots.
24     Since its clear how many weapons a player will have, there is no list of weapons:
25     its hard coded and limited to 8 slots and 4 configs. More would be a waste of
26     memory and time you need to customize and change to a weapon config...
[3573]27*/
28
29
30#ifndef _WEAPON_H
31#define _WEAPON_H
32
33#include "world_entity.h"
34
[3862]35#define W_MAX_SLOTS 8
[3870]36#define W_MAX_CONFIGS 4
[3862]37
[3575]38class Projectile;
[3862]39class Weapon;
[3886]40class Animation3D;
[3573]41
[3583]42typedef enum {
43  SHOOT,
44  EMPTY,
45  RELOAD,
46  SPECIAL1,
47  SPECIAL2,
48  SPECIAL3
49} weaponSoundType;
50
[3870]51
[3862]52//! this is an identifier for the slot. there are up to 8 weapon slots -> this means there can't be more than 8 weapons at the same time
[3870]53#define W_SLOT0 0
54#define W_SLOT1 1
55#define W_SLOT2 2
56#define W_SLOT3 3
57#define W_SLOT4 4
58#define W_SLOT5 5
59#define W_SLOT6 6
60#define W_SLOT7 7
61#define W_FREE_SLOT 99
[3583]62
[3870]63
[3862]64//! this is an identifier for the weapon config
[3870]65#define W_CONFIG0 0
66#define W_CONFIG1 1
67#define W_CONFIG2 2
68#define W_CONFIG3 3
[3862]69
[3886]70//! a weapon can be left or right sided
71#define W_LEFT 0
72#define W_RIGHT 1
73
[3862]74//! this is a weapon Configuration: it has up to 8 slots
75typedef struct weaponConfig {
[3870]76  bool bUsed;                       //<! is set to true, if this configuration is
77  Weapon* slots[8];
[3862]78};
79
80
81class WeaponManager {
82 public:
83  WeaponManager(int nrOfSlots = 2);
84  ~WeaponManager();
85 
[3878]86  void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT);
87  void removeWeapon(Weapon* weapon, int configID = W_CONFIG0);
[3862]88  void nextWeaponConf();
89
[3875]90  void fire();
[3877]91  void tick(float sec);
92  void draw();
[3873]93
[3862]94 private:
95  int nrOfSlots;                        //<! number of weapon slots a ship has
[3875]96  int currConfID;                       //<! the currently selected config
[3870]97  weaponConfig configs[4];              //<! a list of four configurations
98 
[3878]99  int getNextFreeSlot(int configID);
[3862]100};
101
[3573]102class Weapon : public WorldEntity
103{
104  friend class World;
105
106 public:
[3881]107  Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
[3573]108  virtual ~Weapon ();
109 
[3583]110  void enable(void);
111  void disable(void);
112  bool isEnabled(void);
[3577]113
[3575]114  void setProjectile(Projectile* projectile);
[3583]115  Projectile* getProjectile(void);
[3575]116
[3583]117  virtual void activate(void);
118  virtual void deactivate(void);
119  bool isActive(void);
[3575]120
121
[3881]122  /**
123     \brief sets a weapon idle time
124     \param idle time in ms
125     
126     a weapon idle time is the time spend after a shoot until the weapon can
127     shoot again
128  */
129  inline void setWeaponIdleTime(float time) { this->idleTime = time; }
130  /**
131     \brief gets the weapon idle time
132     \returns idle time in ms
133     
134     a weapon idle time is the time spend after a shoot until the weapon can
135     shoot again
136  */
137  inline float getWeaponIdleTime(void) const { return this->idleTime;}
138  /**
139     \brief checks if the idle time is elapsed
140     \return true if time is elapsed
141     
142     a weapon idle time is the time spend after a shoot until the weapon can
143   shoot again
144  */
145  inline bool hasWeaponIdleTimeElapsed(void) const { return (this->localTime>this->idleTime)?true:false; }
146
147  /**
148     \brief fires the weapon
149     
150     this is called from the player.cc, when fire-button is been pushed
151  */
[3646]152  virtual void fire(void) = 0;
[3578]153  virtual void hit (WorldEntity* weapon, Vector* loc);
[3583]154  virtual void destroy(void);
[3575]155 
[3583]156  virtual void tick(float time);
157  virtual void weaponIdle(void);
158  virtual void draw(void);
[3573]159
[3629]160 protected:
161  tList<WorldEntity>* worldEntities;
[3886]162  float localTime;                 //<! this is the local time. important for shooting attributes like frequency
163  float idleTime;                  //<! the time a weapon needs before it can shoot again. eg. shooting frequency or actication/deactivateion delay
164  float slowDownFactor;            //<! if the shooting frequency is a linear function of time...
[3575]165
[3886]166  PNode* objectComponent1;         //<! the gun is made of multiple parts, these PNodes represent their location and orientation
167  PNode* objectComponent2;
168  PNode* objectComponent3;
169
170  Animation3D* animation1;
171  Animation3D* animation2;
172  Animation3D* animation3;
173
[3888]174  Vector projectileOffset;
[3886]175  int leftRight;   // this will become an enum
176
[4208]177  SoundBuffer* fireSound;
178  SoundSource* weaponSource;
179
180
[3573]181 private:
[3886]182  bool enabled;                    //<! states if the weapon is enabled or not
183  Projectile* projectile;          //<! the projectile used for this weapon
[3583]184  //WeaponSound sound;
[3573]185};
186
187#endif /* _WEAPON_H */
Note: See TracBrowser for help on using the repository browser.