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
RevLine 
[4826]1/*!
2    \file weapon.h
[4836]3  *  a weapon that a player can use
[4826]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
[4953]31#include "p_node.h"
[4826]32
33// FORWARD DECLARATION
[4951]34class PNode;
[4826]35class Weapon;
[4834]36class Crosshair;
[4837]37template <class T> class tAnimation;
[4826]38
39
[4951]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
[4826]43
[4951]44//! an enumerator defining capabilities of a WeaponSlot
[4906]45typedef enum
46{
[4951]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
[4826]50
[4951]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
[4826]56
[4951]57  WM_SLOTC_ALL           = 0x000000ff,           //!< everything allowed in this slot
[4949]58} WM_SlotCapability;
59
[4951]60//! an enumerator defining a Slot, where a Weapon can be stored inside.
[4837]61typedef struct
[4833]62{
[4953]63  PNode         position;               //!< the relative Position to the position of the carrying entity. (const PNode* parent; of WeaponManager)
[4951]64  long          capability;             //!< the capabilities of the Slot @see WM_SlotCapability.
[4826]65
[4951]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;
[4826]69
[4953]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 */
[4826]80class WeaponManager : public BaseObject {
81  public:
[4953]82    WeaponManager(PNode* parent);
[4826]83    WeaponManager(const TiXmlElement* root);
84    ~WeaponManager();
85
86    void init();
87    void loadParams(const TiXmlElement* root);
[4834]88    void loadWeapons(const TiXmlElement* root);
[4826]89
[4951]90    // setting up the WeaponManager with the following functions
91    void setSlotPosition(int slot, const Vector& position);
92    void setSlotCapability(long slotCapability);
[4953]93    void setParent(PNode* parent);
[4834]94
[4951]95    void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
96    void removeWeapon(Weapon* weapon, int configID = -1);
97
[4826]98    void nextWeaponConf();
[4952]99    void previousWeaponConfig();
100    void changeWeaponConfig(int weaponConfig);
[4826]101
102    void fire();
[4951]103
[4833]104    void tick(float dt);
[4951]105    void draw() const;
[4826]106
[4951]107    void debug() const;
108
[4826]109  private:
[4951]110    void setSlotCount(unsigned int slotCount);
111
[4837]112    int getNextFreeSlot(int configID);
[4834]113
[4837]114  private:
[4951]115    PNode*                  parent;                                  //!< The parent, this WeaponManager is connected to.
[4826]116
[4951]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.
[4949]121
122    Weapon*                 availiableWeapons[WM_MAX_LOADED_WEAPONS];
[4951]123
124    bool                    weaponChange;
125
126    Crosshair*              crosshair;                               //!< an aim.
127    tAnimation<Crosshair>*  crossHairSizeAnim;                       //!< An animation for the crosshair (scaling)
[4826]128};
Note: See TracBrowser for help on using the repository browser.