Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: more loadability functionality in Weapon and FastFactory

File size: 4.2 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
32// FORWARD DECLARATION
33class Weapon;
34class Crosshair;
35template <class T> class tAnimation;
36
37#define    WM_MAX_SLOTS            8                   //!< How many slots the WeaponManager has at its max
38#define    WM_MAX_CONFIGS          4                   //!< The maximum number of predefined Configurations
39#define    WM_MAX_LOADED_WEAPONS   20                  //!< The
40
41//! this is an identifier for the weapon config
42typedef enum
43{
44  WM_CONFIG0           = 0,
45  WM_CONFIG1           = 1,
46  WM_CONFIG2           = 2,
47  WM_CONFIG3           = 3,
48
49  WM_CONFIGCOUNT       = 4
50} WM_CONFIG;
51
52//! 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
53typedef enum
54{
55  WM_SLOT0              = 0,
56  WM_SLOT1              = 1,
57  WM_SLOT2              = 2,
58  WM_SLOT3              = 3,
59  WM_SLOT4              = 4,
60  WM_SLOT5              = 5,
61  WM_SLOT6              = 6,
62  WM_SLOT7              = 7,
63
64  WM_SLOT_COUNT         = 8,
65
66  WM_FREE_SLOT          = -1
67} WM_SLOT;
68
69typedef enum
70{
71  WM_SLOTC_DIRECTIONAL   = 1,
72  WM_SLOTC_TURRET        = 2,
73  WM_SLOTC_ALLKINDS      = 3,
74
75  WM_SLOTC_FORWARD       = 4,
76  WM_SLOTC_BACKWARD      = 8,
77  WM_SLOTC_LEFT          = 16,
78  WM_SLOTC_RIGHT         = 32,
79  WM_SLOTC_ALLDIRS       = 60,
80
81  WM_SLOTC_ALL           = 63,
82} WM_SlotCapability;
83
84typedef struct WM_Slot
85{
86  int           number;
87  long          capability;
88
89  Weapon*       currentWeapon;
90  Weapon*       nextWeapon;
91};
92
93//! this is a weapon Configuration: it has up to 8 slots
94typedef struct
95{
96  bool           bUsed;                       //!< is set to true, if this configuration is
97  Weapon*        slots[WM_MAX_SLOTS];
98} weaponConfig;
99
100
101class WeaponManager : public BaseObject {
102  public:
103    WeaponManager(int slotCount);
104    WeaponManager(const TiXmlElement* root);
105    ~WeaponManager();
106
107    void init();
108    void loadParams(const TiXmlElement* root);
109    void loadWeapons(const TiXmlElement* root);
110
111    void setSlotCount(int slotCount);
112
113    void addWeapon(Weapon* weapon, int configID = WM_CONFIG0, int slotID = WM_FREE_SLOT);
114    void removeWeapon(Weapon* weapon, int configID = WM_CONFIG0);
115    void nextWeaponConf();
116
117    void fire();
118    void tick(float dt);
119    void draw();
120
121  private:
122    int getNextFreeSlot(int configID);
123
124  private:
125    Crosshair*              crosshair;               //!< an aim.
126    tAnimation<Crosshair>*  crossHairSizeAnim;       //!< An animation for the crosshair (scaling)
127
128    int                     slotCount;               //!< number of weapon slots a ship has
129    int                     currConfID;              //!< the currently selected config
130    weaponConfig            configs[4];              //!< a list of four configurations
131
132    Weapon*                 availiableWeapons[WM_MAX_LOADED_WEAPONS];
133};
Note: See TracBrowser for help on using the repository browser.