Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Slots are now PNodes

File size: 5.5 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 "p_node.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  PNode         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
70//! This is a special class, that can handle many different Weapons of a ship/man/whatever.
71/**
72 * this class is designed to interactively changeing multiple weapons (or just one),
73 * and to allow the Weapon itself to enable/disable itself.
74 *
75 * How to configure
76 * 1. set the default values.
77 * 2. define weapons. connect them to the WeaponManager's configurations
78 * 3. go on and run :)....
79 */
80class WeaponManager : public BaseObject {
81  public:
82    WeaponManager(PNode* parent);
83    WeaponManager(const TiXmlElement* root);
84    ~WeaponManager();
85
86    void init();
87    void loadParams(const TiXmlElement* root);
88    void loadWeapons(const TiXmlElement* root);
89
90    // setting up the WeaponManager with the following functions
91    void setSlotPosition(int slot, const Vector& position);
92    void setSlotCapability(long slotCapability);
93    void setParent(PNode* parent);
94
95    void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
96    void removeWeapon(Weapon* weapon, int configID = -1);
97
98    void nextWeaponConf();
99    void previousWeaponConfig();
100    void changeWeaponConfig(int weaponConfig);
101
102    void fire();
103
104    void tick(float dt);
105    void draw() const;
106
107    void debug() const;
108
109  private:
110    void setSlotCount(unsigned int slotCount);
111
112    int getNextFreeSlot(int configID);
113
114  private:
115    PNode*                  parent;                                  //!< The parent, this WeaponManager is connected to.
116
117    int                     slotCount;                               //!< number of weapon slots the ship has.
118    int                     currentConfigID;                         //!< the currently selected config.
119    Weapon*                 configs[WM_MAX_CONFIGS][WM_MAX_SLOTS];   //!< An array of predefined configurations and assigned weapon.
120    WM_Slot                 currentSlotConfig[WM_MAX_SLOTS];         //!< The currentConfigureation.
121
122    Weapon*                 availiableWeapons[WM_MAX_LOADED_WEAPONS];
123
124    bool                    weaponChange;
125
126    Crosshair*              crosshair;                               //!< an aim.
127    tAnimation<Crosshair>*  crossHairSizeAnim;                       //!< An animation for the crosshair (scaling)
128};
Note: See TracBrowser for help on using the repository browser.