Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/sound_engine/src/world_entities/weapon.h @ 3898

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

orxonox/branches/sound_engine: sound works sloppy, test it

File size: 4.6 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 Sound;
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//! this is a weapon Configuration: it has up to 8 slots
71typedef struct weaponConfig {
72  bool bUsed;                       //<! is set to true, if this configuration is
73  Weapon* slots[8];
74};
75
76
77class WeaponManager {
78 public:
79  WeaponManager(int nrOfSlots = 2);
80  ~WeaponManager();
81 
82  void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT);
83  void removeWeapon(Weapon* weapon, int configID = W_CONFIG0);
84  void nextWeaponConf();
85
86  void fire();
87  void tick(float sec);
88  void draw();
89
90 private:
91  int nrOfSlots;                        //<! number of weapon slots a ship has
92  int currConfID;                       //<! the currently selected config
93  weaponConfig configs[4];              //<! a list of four configurations
94 
95  int getNextFreeSlot(int configID);
96};
97
98class Weapon : public WorldEntity
99{
100  friend class World;
101
102 public:
103  Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
104  virtual ~Weapon ();
105 
106  void enable(void);
107  void disable(void);
108  bool isEnabled(void);
109
110  void setProjectile(Projectile* projectile);
111  Projectile* getProjectile(void);
112
113  virtual void activate(void);
114  virtual void deactivate(void);
115  bool isActive(void);
116
117
118  /**
119     \brief sets a weapon idle time
120     \param idle time in ms
121     
122     a weapon idle time is the time spend after a shoot until the weapon can
123     shoot again
124  */
125  inline void setWeaponIdleTime(float time) { this->idleTime = time; }
126  /**
127     \brief gets the weapon idle time
128     \returns idle time in ms
129     
130     a weapon idle time is the time spend after a shoot until the weapon can
131     shoot again
132  */
133  inline float getWeaponIdleTime(void) const { return this->idleTime;}
134  /**
135     \brief checks if the idle time is elapsed
136     \return true if time is elapsed
137     
138     a weapon idle time is the time spend after a shoot until the weapon can
139   shoot again
140  */
141  inline bool hasWeaponIdleTimeElapsed(void) const { return (this->localTime>this->idleTime)?true:false; }
142
143  /**
144     \brief fires the weapon
145     
146     this is called from the player.cc, when fire-button is been pushed
147  */
148  virtual void fire(void) = 0;
149  virtual void hit (WorldEntity* weapon, Vector* loc);
150  virtual void destroy(void);
151 
152  virtual void tick(float time);
153  virtual void weaponIdle(void);
154  virtual void draw(void);
155
156 protected:
157  tList<WorldEntity>* worldEntities;
158  float localTime;
159  float idleTime;
160  float slowDownFactor;
161  Sound* shootSound;
162
163 private:
164  bool enabled;
165  Projectile* projectile;
166  //WeaponSound sound;
167};
168
169#endif /* _WEAPON_H */
Note: See TracBrowser for help on using the repository browser.