Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/weapon_manager.h @ 5235

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

orxonox/trunk: many loadParams

File size: 4.3 KB
Line 
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 "crosshair.h"
16#include "weapon.h"
17
18// FORWARD DECLARATION
19template <class T> class tAnimation;
20
21
22#define    WM_MAX_SLOTS            8              //!< How many slots the WeaponManager has at its max
23#define    WM_MAX_CONFIGS          4              //!< The maximum number of predefined Configurations
24#define    WM_MAX_LOADED_WEAPONS   20             //!< The
25
26//! an enumerator defining a Slot, where a Weapon can be stored inside.
27typedef struct
28{
29  PNode         position;               //!< the relative Position to the position of the carrying entity. (const PNode* parent; of WeaponManager)
30  long          capability;             //!< the capabilities of the Slot @see WM_SlotCapability.
31
32  Weapon*       currentWeapon;          //!< The current weapon this slot is carrying.
33  Weapon*       nextWeapon;             //!< either NULL or the next weapon that will be set (require currentWeapon to deactivate)
34} WM_Slot;
35
36//! This is a special class, that can handle many different Weapons of a ship/man/whatever.
37/**
38 * this class is designed to interactively changeing multiple weapons (or just one),
39 * and to allow the Weapon itself to enable/disable itself.
40 *
41 * How to configure
42 * 1. set the default values.
43 * 2. define weapons. connect them to the WeaponManager's configurations (have a look at "player.cc", to see how it works)
44 * 3. go on and run :)....
45 */
46class WeaponManager : public BaseObject {
47  public:
48    WeaponManager(PNode* parent);
49    WeaponManager(const TiXmlElement* root);
50    ~WeaponManager();
51
52    void init();
53    void loadParams(const TiXmlElement* root);
54    void loadWeapons(const TiXmlElement* root);
55
56    void setSlotCount(unsigned int slotCount);
57    // setting up the WeaponManager with the following functions
58    void setSlotPosition(int slot, const Vector& position);
59    void setSlotDirection(int slot, const Quaternion& rotation);
60    /** @param slot the slot to get the relative position from @returns the relative position of the Carrier to the Slot */
61    const Vector& getSlotPosition(int slot) const { return this->currentSlotConfig[slot].position.getRelCoor(); };
62    void setSlotCapability(int slot, long slotCapability);
63    /** @param slot the slot to get the capabilities from @returns the capabilies */
64    long getSlotCapability(int slot) const { return this->currentSlotConfig[slot].capability; };
65
66    void setParent(PNode* parent);
67    /** @returns the Parent (carrier) of this WeaponManager */
68    PNode* getParent() const { return this->parent; };
69
70    void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
71    void removeWeapon(Weapon* weapon, int configID = -1);
72
73
74
75    void nextWeaponConfig();
76    void previousWeaponConfig();
77    void changeWeaponConfig(int weaponConfig);
78
79    /** @returns a fixed target namely the Crosshair's 3D position */
80    inline PNode* getFixedTarget() { return this->crosshair; };
81    void fire();
82
83    void tick(float dt);
84    void draw() const;
85
86    void debug() const;
87
88  private:
89    int getNextFreeSlot(int configID);
90
91  private:
92    PNode*                  parent;                                   //!< The parent, this WeaponManager is connected to.
93
94    int                     slotCount;                                //!< number of weapon slots the ship has.
95    int                     currentConfigID;                          //!< the currently selected config.
96    Weapon*                 configs[WM_MAX_CONFIGS][WM_MAX_SLOTS];    //!< An array of predefined configurations and assigned weapon.
97    WM_Slot                 currentSlotConfig[WM_MAX_SLOTS];          //!< The currentConfigureation.
98
99    Weapon*                 availiableWeapons[WM_MAX_LOADED_WEAPONS]; //!< The availiable Weapons of this WeaponManager
100
101    bool                    weaponChange;
102
103    Crosshair*              crosshair;                                //!< an aim.
104    tAnimation<Crosshair>*  crossHairSizeAnim;                        //!< An animation for the crosshair (scaling)
105};
Note: See TracBrowser for help on using the repository browser.