Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3870 was 3870, checked in by patrick, 19 years ago

orxonox/trunk: reimplemented WeaponManager, made it as simple as possible. not yet all done

File size: 3.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 "world_entity.h"
34
35#define W_MAX_SLOTS 8
36#define W_MAX_CONFIGS 4
37
38class Projectile;
39class Weapon;
40
41typedef enum {
42  SHOOT,
43  EMPTY,
44  RELOAD,
45  SPECIAL1,
46  SPECIAL2,
47  SPECIAL3
48} weaponSoundType;
49
50
51//! 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
52#define W_SLOT0 0
53#define W_SLOT1 1
54#define W_SLOT2 2
55#define W_SLOT3 3
56#define W_SLOT4 4
57#define W_SLOT5 5
58#define W_SLOT6 6
59#define W_SLOT7 7
60#define W_FREE_SLOT 99
61
62
63//! this is an identifier for the weapon config
64#define W_CONFIG0 0
65#define W_CONFIG1 1
66#define W_CONFIG2 2
67#define W_CONFIG3 3
68
69//! this is a weapon Configuration: it has up to 8 slots
70typedef struct weaponConfig {
71  bool bUsed;                       //<! is set to true, if this configuration is
72  Weapon* slots[8];
73};
74
75
76class WeaponManager {
77 public:
78  WeaponManager(int nrOfSlots = 2);
79  ~WeaponManager();
80 
81  void addWeapon(Weapon* weapon, int slotID = W_FREE_SLOT, int configID = W_CONFIG1);
82
83  void nextWeaponConf();
84  void prevWeaponConf();
85  void selectConfig(int configID);
86
87 private:
88  int nrOfConfigs;                      //<! number of configurations defined
89  int nrOfSlots;                        //<! number of weapon slots a ship has
90  int currConfID;                    //<! the currently selected config
91  weaponConfig configs[4];              //<! a list of four configurations
92 
93  int getNextFreeSlot();
94};
95
96class Weapon : public WorldEntity
97{
98  friend class World;
99
100 public:
101  Weapon (PNode* parent, Vector* coordinate, Quaternion* direction);
102  virtual ~Weapon ();
103 
104  void enable(void);
105  void disable(void);
106  bool isEnabled(void);
107
108  void setProjectile(Projectile* projectile);
109  Projectile* getProjectile(void);
110
111  virtual void activate(void);
112  virtual void deactivate(void);
113  bool isActive(void);
114
115  void setWeaponIdleTime(float time);
116  float getWeaponIdleTime(void);
117  bool hasWeaponIdleTimeElapsed(void);
118
119  virtual void fire(void) = 0;
120  virtual void hit (WorldEntity* weapon, Vector* loc);
121  virtual void destroy(void);
122 
123  virtual void tick(float time);
124  virtual void weaponIdle(void);
125  virtual void draw(void);
126
127 protected:
128  tList<WorldEntity>* worldEntities;
129  float localTime;
130  float idleTime;
131  float slowDownFactor;
132
133 private:
134  bool enabled;
135  Projectile* projectile;
136  //WeaponSound sound;
137};
138
139#endif /* _WEAPON_H */
Note: See TracBrowser for help on using the repository browser.