Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: version finaly changed to 0.3.0… how could i forget ….

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