Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: the new WeaponManager is online :)

File size: 5.0 KB
Line 
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#include "vector.h"
32
33// FORWARD DECLARATION
34class PNode;
35class Weapon;
36class Crosshair;
37template <class T> class tAnimation;
38
39
40#define    WM_MAX_SLOTS            8              //!< How many slots the WeaponManager has at its max
41#define    WM_MAX_CONFIGS          4              //!< The maximum number of predefined Configurations
42#define    WM_MAX_LOADED_WEAPONS   20             //!< The
43
44//! an enumerator defining capabilities of a WeaponSlot
45typedef enum
46{
47  WM_SLOTC_DIRECTIONAL   = 0x00000001,           //!< if the Slot is able to carry directional weapons
48  WM_SLOTC_TURRET        = 0x00000002,           //!< if the Slot is able to carry turrets
49  WM_SLOTC_ALLKINDS      = 0x0000000f,           //!< if the Slot is able to carry all kinds of weapons
50
51  WM_SLOTC_FORWARD       = 0x00000010,           //!< if the Slot is able to carry weapons firing forward
52  WM_SLOTC_BACKWARD      = 0x00000020,           //!< if the Slot is able to carry weapons firing backwards
53  WM_SLOTC_LEFT          = 0x00000040,           //!< if the Slot is able to carry weapons firing to the left
54  WM_SLOTC_RIGHT         = 0x00000080,           //!< if the Slot is able to carry weapons firing to the right
55  WM_SLOTC_ALLDIRS       = 0x000000f0,           //!< this slot can fire into all directions
56
57  WM_SLOTC_ALL           = 0x000000ff,           //!< everything allowed in this slot
58} WM_SlotCapability;
59
60//! an enumerator defining a Slot, where a Weapon can be stored inside.
61typedef struct
62{
63  Vector        position;               //!< the relative Position to the position of the carrying entity. (const PNode* parent; of WeaponManager)
64  long          capability;             //!< the capabilities of the Slot @see WM_SlotCapability.
65
66  Weapon*       currentWeapon;          //!< The current weapon this slot is carrying.
67  Weapon*       nextWeapon;             //!< either NULL or the next weapon that will be set (require currentWeapon to deactivate)
68} WM_Slot;
69
70class WeaponManager : public BaseObject {
71  public:
72    WeaponManager(unsigned int slotCount);
73    WeaponManager(const TiXmlElement* root);
74    ~WeaponManager();
75
76    void init();
77    void loadParams(const TiXmlElement* root);
78    void loadWeapons(const TiXmlElement* root);
79
80    // setting up the WeaponManager with the following functions
81    void setSlotPosition(int slot, const Vector& position);
82    void setSlotCapability(long slotCapability);
83
84    void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
85    void removeWeapon(Weapon* weapon, int configID = -1);
86
87    void nextWeaponConf();
88
89    void fire();
90
91    void tick(float dt);
92    void draw() const;
93
94    void debug() const;
95
96  private:
97    void setSlotCount(unsigned int slotCount);
98
99    int getNextFreeSlot(int configID);
100
101  private:
102    PNode*                  parent;                                  //!< The parent, this WeaponManager is connected to.
103
104    int                     slotCount;                               //!< number of weapon slots the ship has.
105    int                     currentConfigID;                         //!< the currently selected config.
106    Weapon*                 configs[WM_MAX_CONFIGS][WM_MAX_SLOTS];   //!< An array of predefined configurations and assigned weapon.
107    WM_Slot                 currentSlotConfig[WM_MAX_SLOTS];         //!< The currentConfigureation.
108
109    Weapon*                 availiableWeapons[WM_MAX_LOADED_WEAPONS];
110
111    bool                    weaponChange;
112
113    Crosshair*              crosshair;                               //!< an aim.
114    tAnimation<Crosshair>*  crossHairSizeAnim;                       //!< An animation for the crosshair (scaling)
115};
Note: See TracBrowser for help on using the repository browser.