1 | /*! |
---|
2 | * @file weapon_manager.h |
---|
3 | * every big WorldEntity has the ability to carry many different Weapons. |
---|
4 | * for this to be easy there is the WeaponManager, that handels these weapons, |
---|
5 | * and changes between them. |
---|
6 | * |
---|
7 | * |
---|
8 | * |
---|
9 | * @TODO 1. WeaponManager should also handle a List of availiableWeapons. |
---|
10 | * @TODO 2. Weapons should now Types the counteract to capabilities, so we know where we can put them on the ship. |
---|
11 | */ |
---|
12 | |
---|
13 | #include "base_object.h" |
---|
14 | |
---|
15 | #include "p_node.h" |
---|
16 | |
---|
17 | // FORWARD DECLARATION |
---|
18 | class PNode; |
---|
19 | class Weapon; |
---|
20 | class Crosshair; |
---|
21 | template <class T> class tAnimation; |
---|
22 | |
---|
23 | |
---|
24 | #define WM_MAX_SLOTS 8 //!< How many slots the WeaponManager has at its max |
---|
25 | #define WM_MAX_CONFIGS 4 //!< The maximum number of predefined Configurations |
---|
26 | #define WM_MAX_LOADED_WEAPONS 20 //!< The |
---|
27 | |
---|
28 | //! an enumerator defining capabilities of a WeaponSlot |
---|
29 | typedef enum |
---|
30 | { |
---|
31 | WM_SLOTC_DIRECTIONAL = 0x00000001, //!< if the Slot is able to carry directional weapons |
---|
32 | WM_SLOTC_TURRET = 0x00000002, //!< if the Slot is able to carry turrets |
---|
33 | WM_SLOTC_ALLKINDS = 0x0000000f, //!< if the Slot is able to carry all kinds of weapons |
---|
34 | |
---|
35 | WM_SLOTC_FORWARD = 0x00000010, //!< if the Slot is able to carry weapons firing forward |
---|
36 | WM_SLOTC_BACKWARD = 0x00000020, //!< if the Slot is able to carry weapons firing backwards |
---|
37 | WM_SLOTC_LEFT = 0x00000040, //!< if the Slot is able to carry weapons firing to the left |
---|
38 | WM_SLOTC_RIGHT = 0x00000080, //!< if the Slot is able to carry weapons firing to the right |
---|
39 | WM_SLOTC_ALLDIRS = 0x000000f0, //!< this slot can fire into all directions |
---|
40 | |
---|
41 | WM_SLOTC_ALL = 0x000000ff, //!< everything allowed in this slot |
---|
42 | } WM_SlotCapability; |
---|
43 | |
---|
44 | //! an enumerator defining a Slot, where a Weapon can be stored inside. |
---|
45 | typedef struct |
---|
46 | { |
---|
47 | PNode position; //!< the relative Position to the position of the carrying entity. (const PNode* parent; of WeaponManager) |
---|
48 | long capability; //!< the capabilities of the Slot @see WM_SlotCapability. |
---|
49 | |
---|
50 | Weapon* currentWeapon; //!< The current weapon this slot is carrying. |
---|
51 | Weapon* nextWeapon; //!< either NULL or the next weapon that will be set (require currentWeapon to deactivate) |
---|
52 | } WM_Slot; |
---|
53 | |
---|
54 | //! This is a special class, that can handle many different Weapons of a ship/man/whatever. |
---|
55 | /** |
---|
56 | * this class is designed to interactively changeing multiple weapons (or just one), |
---|
57 | * and to allow the Weapon itself to enable/disable itself. |
---|
58 | * |
---|
59 | * How to configure |
---|
60 | * 1. set the default values. |
---|
61 | * 2. define weapons. connect them to the WeaponManager's configurations |
---|
62 | * 3. go on and run :).... |
---|
63 | */ |
---|
64 | class WeaponManager : public BaseObject { |
---|
65 | public: |
---|
66 | WeaponManager(PNode* parent); |
---|
67 | WeaponManager(const TiXmlElement* root); |
---|
68 | ~WeaponManager(); |
---|
69 | |
---|
70 | void init(); |
---|
71 | void loadParams(const TiXmlElement* root); |
---|
72 | void loadWeapons(const TiXmlElement* root); |
---|
73 | |
---|
74 | // setting up the WeaponManager with the following functions |
---|
75 | void setSlotPosition(int slot, const Vector& position); |
---|
76 | /** @param slot the slot to get the relative position from @returns the relative position of the Carrier to the Slot */ |
---|
77 | const Vector& getSlotPosition(int slot) const { return this->currentSlotConfig[slot].position.getRelCoor(); }; |
---|
78 | void setSlotCapability(int slot, long slotCapability); |
---|
79 | /** @param slot the slot to get the capabilities from @returns the capabilies */ |
---|
80 | long getSlotCapability(int slot) const { return this->currentSlotConfig[slot].capability; }; |
---|
81 | |
---|
82 | void setParent(PNode* parent); |
---|
83 | /** @returns the Parent (carrier) of this WeaponManager */ |
---|
84 | PNode* getParent() const { return this->parent; }; |
---|
85 | |
---|
86 | void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1); |
---|
87 | void removeWeapon(Weapon* weapon, int configID = -1); |
---|
88 | |
---|
89 | void nextWeaponConfig(); |
---|
90 | void previousWeaponConfig(); |
---|
91 | void changeWeaponConfig(int weaponConfig); |
---|
92 | |
---|
93 | void fire(); |
---|
94 | |
---|
95 | void tick(float dt); |
---|
96 | void draw() const; |
---|
97 | |
---|
98 | void debug() const; |
---|
99 | |
---|
100 | private: |
---|
101 | void setSlotCount(unsigned int slotCount); |
---|
102 | |
---|
103 | int getNextFreeSlot(int configID); |
---|
104 | |
---|
105 | private: |
---|
106 | PNode* parent; //!< The parent, this WeaponManager is connected to. |
---|
107 | |
---|
108 | int slotCount; //!< number of weapon slots the ship has. |
---|
109 | int currentConfigID; //!< the currently selected config. |
---|
110 | Weapon* configs[WM_MAX_CONFIGS][WM_MAX_SLOTS]; //!< An array of predefined configurations and assigned weapon. |
---|
111 | WM_Slot currentSlotConfig[WM_MAX_SLOTS]; //!< The currentConfigureation. |
---|
112 | |
---|
113 | Weapon* availiableWeapons[WM_MAX_LOADED_WEAPONS]; //!< The availiable Weapons of this WeaponManager |
---|
114 | |
---|
115 | bool weaponChange; |
---|
116 | |
---|
117 | Crosshair* crosshair; //!< an aim. |
---|
118 | tAnimation<Crosshair>* crossHairSizeAnim; //!< An animation for the crosshair (scaling) |
---|
119 | }; |
---|