Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/heightMap/src/world_entities/weapon.h @ 4127

Last change on this file since 4127 was 3888, checked in by patrick, 20 years ago

orxonox/trunk: deconstructor cleanup in weapon/gun

File size: 5.4 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 "world_entity.h"
34
35#define W_MAX_SLOTS 8
36#define W_MAX_CONFIGS 4
37
38class Projectile;
39class Weapon;
40class Animation3D;
41
42typedef enum {
43  SHOOT,
44  EMPTY,
45  RELOAD,
46  SPECIAL1,
47  SPECIAL2,
48  SPECIAL3
49} weaponSoundType;
50
51
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
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
62
63
64//! this is an identifier for the weapon config
65#define W_CONFIG0 0
66#define W_CONFIG1 1
67#define W_CONFIG2 2
68#define W_CONFIG3 3
69
70//! a weapon can be left or right sided
71#define W_LEFT 0
72#define W_RIGHT 1
73
74//! this is a weapon Configuration: it has up to 8 slots
75typedef struct weaponConfig {
76  bool bUsed;                       //<! is set to true, if this configuration is
77  Weapon* slots[8];
78};
79
80
81class WeaponManager {
82 public:
83  WeaponManager(int nrOfSlots = 2);
84  ~WeaponManager();
85 
86  void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT);
87  void removeWeapon(Weapon* weapon, int configID = W_CONFIG0);
88  void nextWeaponConf();
89
90  void fire();
91  void tick(float sec);
92  void draw();
93
94 private:
95  int nrOfSlots;                        //<! number of weapon slots a ship has
96  int currConfID;                       //<! the currently selected config
97  weaponConfig configs[4];              //<! a list of four configurations
98 
99  int getNextFreeSlot(int configID);
100};
101
102class Weapon : public WorldEntity
103{
104  friend class World;
105
106 public:
107  Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
108  virtual ~Weapon ();
109 
110  void enable(void);
111  void disable(void);
112  bool isEnabled(void);
113
114  void setProjectile(Projectile* projectile);
115  Projectile* getProjectile(void);
116
117  virtual void activate(void);
118  virtual void deactivate(void);
119  bool isActive(void);
120
121
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  */
152  virtual void fire(void) = 0;
153  virtual void hit (WorldEntity* weapon, Vector* loc);
154  virtual void destroy(void);
155 
156  virtual void tick(float time);
157  virtual void weaponIdle(void);
158  virtual void draw(void);
159
160 protected:
161  tList<WorldEntity>* worldEntities;
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...
165
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
174  Vector projectileOffset;
175  int leftRight;   // this will become an enum
176
177 private:
178  bool enabled;                    //<! states if the weapon is enabled or not
179  Projectile* projectile;          //<! the projectile used for this weapon
180  //WeaponSound sound;
181};
182
183#endif /* _WEAPON_H */
Note: See TracBrowser for help on using the repository browser.