Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: setClassID implemented in all files

File size: 5.5 KB
Line 
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
18     o shooting animation
19
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...
27*/
28
29
30#ifndef _WEAPON_H
31#define _WEAPON_H
32
33#include "base_object.h"
34#include "world_entity.h"
35
36#define W_MAX_SLOTS 8
37#define W_MAX_CONFIGS 4
38
39class Projectile;
40class Weapon;
41class Animation3D;
42
43typedef enum {
44  SHOOT,
45  EMPTY,
46  RELOAD,
47  SPECIAL1,
48  SPECIAL2,
49  SPECIAL3
50} weaponSoundType;
51
52
53//! 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
54#define W_SLOT0 0
55#define W_SLOT1 1
56#define W_SLOT2 2
57#define W_SLOT3 3
58#define W_SLOT4 4
59#define W_SLOT5 5
60#define W_SLOT6 6
61#define W_SLOT7 7
62#define W_FREE_SLOT 99
63
64
65//! this is an identifier for the weapon config
66#define W_CONFIG0 0
67#define W_CONFIG1 1
68#define W_CONFIG2 2
69#define W_CONFIG3 3
70
71//! a weapon can be left or right sided
72#define W_LEFT 0
73#define W_RIGHT 1
74
75//! this is a weapon Configuration: it has up to 8 slots
76typedef struct weaponConfig {
77  bool bUsed;                       //<! is set to true, if this configuration is
78  Weapon* slots[8];
79};
80
81
82class WeaponManager : public BaseObject {
83 public:
84  WeaponManager(int nrOfSlots = 2);
85  ~WeaponManager();
86
87  void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT);
88  void removeWeapon(Weapon* weapon, int configID = W_CONFIG0);
89  void nextWeaponConf();
90
91  void fire();
92  void tick(float sec);
93  void draw();
94
95 private:
96  int nrOfSlots;                        //<! number of weapon slots a ship has
97  int currConfID;                       //<! the currently selected config
98  weaponConfig configs[4];              //<! a list of four configurations
99
100  int getNextFreeSlot(int configID);
101};
102
103class Weapon : public WorldEntity
104{
105  friend class World;
106
107 public:
108  Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
109  virtual ~Weapon ();
110
111  void enable(void);
112  void disable(void);
113  bool isEnabled(void);
114
115  void setProjectile(Projectile* projectile);
116  Projectile* getProjectile(void);
117
118  virtual void activate(void);
119  virtual void deactivate(void);
120  bool isActive(void);
121
122
123  /**
124     \brief sets a weapon idle time
125     \param idle time in ms
126
127     a weapon idle time is the time spend after a shoot until the weapon can
128     shoot again
129  */
130  inline void setWeaponIdleTime(float time) { this->idleTime = time; }
131  /**
132     \brief gets the weapon idle time
133     \returns idle time in ms
134
135     a weapon idle time is the time spend after a shoot until the weapon can
136     shoot again
137  */
138  inline float getWeaponIdleTime(void) const { return this->idleTime;}
139  /**
140     \brief checks if the idle time is elapsed
141     \return true if time is elapsed
142
143     a weapon idle time is the time spend after a shoot until the weapon can
144   shoot again
145  */
146  inline bool hasWeaponIdleTimeElapsed(void) const { return (this->localTime>this->idleTime)?true:false; }
147
148  /**
149     \brief fires the weapon
150
151     this is called from the player.cc, when fire-button is been pushed
152  */
153  virtual void fire(void) = 0;
154  virtual void hit (WorldEntity* weapon, Vector* loc);
155  virtual void destroy(void);
156
157  virtual void tick(float time);
158  virtual void weaponIdle(void);
159  virtual void draw(void);
160
161 protected:
162  tList<WorldEntity>* worldEntities;
163  float localTime;                 //<! this is the local time. important for shooting attributes like frequency
164  float idleTime;                  //<! the time a weapon needs before it can shoot again. eg. shooting frequency or actication/deactivateion delay
165  float slowDownFactor;            //<! if the shooting frequency is a linear function of time...
166
167  PNode* objectComponent1;         //<! the gun is made of multiple parts, these PNodes represent their location and orientation
168  PNode* objectComponent2;
169  PNode* objectComponent3;
170
171  Animation3D* animation1;
172  Animation3D* animation2;
173  Animation3D* animation3;
174
175  Vector projectileOffset;
176  int leftRight;   // this will become an enum
177
178  SoundBuffer* fireSound;
179  SoundSource* weaponSource;
180
181
182 private:
183  bool enabled;                    //<! states if the weapon is enabled or not
184  Projectile* projectile;          //<! the projectile used for this weapon
185  //WeaponSound sound;
186};
187
188#endif /* _WEAPON_H */
Note: See TracBrowser for help on using the repository browser.