1 | /*! |
---|
2 | \file weapon.h |
---|
3 | * 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 | #include "base_object.h" |
---|
30 | |
---|
31 | |
---|
32 | // FORWARD DECLARATION |
---|
33 | class Weapon; |
---|
34 | class Crosshair; |
---|
35 | template <class T> class tAnimation; |
---|
36 | |
---|
37 | #define W_MAX_SLOTS 8 |
---|
38 | #define W_MAX_CONFIGS 4 |
---|
39 | |
---|
40 | //! this is an identifier for the weapon config |
---|
41 | #define W_CONFIG0 0 |
---|
42 | #define W_CONFIG1 1 |
---|
43 | #define W_CONFIG2 2 |
---|
44 | #define W_CONFIG3 3 |
---|
45 | |
---|
46 | |
---|
47 | //! 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 |
---|
48 | #define W_SLOT0 0 |
---|
49 | #define W_SLOT1 1 |
---|
50 | #define W_SLOT2 2 |
---|
51 | #define W_SLOT3 3 |
---|
52 | #define W_SLOT4 4 |
---|
53 | #define W_SLOT5 5 |
---|
54 | #define W_SLOT6 6 |
---|
55 | #define W_SLOT7 7 |
---|
56 | #define W_FREE_SLOT 99 |
---|
57 | |
---|
58 | |
---|
59 | //! this is a weapon Configuration: it has up to 8 slots |
---|
60 | typedef struct |
---|
61 | { |
---|
62 | bool bUsed; //!< is set to true, if this configuration is |
---|
63 | Weapon* slots[8]; |
---|
64 | } weaponConfig; |
---|
65 | |
---|
66 | |
---|
67 | class WeaponManager : public BaseObject { |
---|
68 | public: |
---|
69 | WeaponManager(int nrOfSlots = 2); |
---|
70 | WeaponManager(const TiXmlElement* root); |
---|
71 | ~WeaponManager(); |
---|
72 | |
---|
73 | void init(); |
---|
74 | void loadParams(const TiXmlElement* root); |
---|
75 | void loadWeapons(const TiXmlElement* root); |
---|
76 | |
---|
77 | void setSlotCount(int nrOfSlots); |
---|
78 | |
---|
79 | void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT); |
---|
80 | void removeWeapon(Weapon* weapon, int configID = W_CONFIG0); |
---|
81 | void nextWeaponConf(); |
---|
82 | |
---|
83 | void fire(); |
---|
84 | void tick(float dt); |
---|
85 | void draw(); |
---|
86 | |
---|
87 | private: |
---|
88 | int getNextFreeSlot(int configID); |
---|
89 | |
---|
90 | private: |
---|
91 | Crosshair* crosshair; //!< an aim. |
---|
92 | tAnimation<Crosshair>* crossHairSizeAnim; |
---|
93 | |
---|
94 | int nrOfSlots; //<! number of weapon slots a ship has |
---|
95 | int currConfID; //<! the currently selected config |
---|
96 | weaponConfig configs[4]; //<! a list of four configurations |
---|
97 | |
---|
98 | }; |
---|