Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entities/weapon.h @ 4597

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

orxonox/trunk: setClassID implemented in all files

File size: 5.5 KB
RevLine 
[4597]1/*!
[3573]2    \file weapon.h
3    \brief 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
[4597]14
[3573]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
[3575]18     o shooting animation
[3862]19
[4597]20
[3862]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...
[3573]27*/
28
29
30#ifndef _WEAPON_H
31#define _WEAPON_H
32
[4597]33#include "base_object.h"
[3573]34#include "world_entity.h"
35
[3862]36#define W_MAX_SLOTS 8
[3870]37#define W_MAX_CONFIGS 4
[3862]38
[3575]39class Projectile;
[3862]40class Weapon;
[3886]41class Animation3D;
[3573]42
[3583]43typedef enum {
44  SHOOT,
45  EMPTY,
46  RELOAD,
47  SPECIAL1,
48  SPECIAL2,
49  SPECIAL3
50} weaponSoundType;
51
[3870]52
[3862]53//! 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
[3870]54#define W_SLOT0 0
55#define W_SLOT1 1
56#define W_SLOT2 2
57#define W_SLOT3 3
58#define W_SLOT4 4
59#define W_SLOT5 5
60#define W_SLOT6 6
61#define W_SLOT7 7
62#define W_FREE_SLOT 99
[3583]63
[3870]64
[3862]65//! this is an identifier for the weapon config
[3870]66#define W_CONFIG0 0
67#define W_CONFIG1 1
68#define W_CONFIG2 2
69#define W_CONFIG3 3
[3862]70
[3886]71//! a weapon can be left or right sided
72#define W_LEFT 0
73#define W_RIGHT 1
74
[3862]75//! this is a weapon Configuration: it has up to 8 slots
76typedef struct weaponConfig {
[4597]77  bool bUsed;                       //<! is set to true, if this configuration is
[3870]78  Weapon* slots[8];
[3862]79};
80
81
[4597]82class WeaponManager : public BaseObject {
[3862]83 public:
84  WeaponManager(int nrOfSlots = 2);
85  ~WeaponManager();
[4597]86
[3878]87  void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT);
88  void removeWeapon(Weapon* weapon, int configID = W_CONFIG0);
[3862]89  void nextWeaponConf();
90
[3875]91  void fire();
[3877]92  void tick(float sec);
93  void draw();
[3873]94
[3862]95 private:
96  int nrOfSlots;                        //<! number of weapon slots a ship has
[3875]97  int currConfID;                       //<! the currently selected config
[3870]98  weaponConfig configs[4];              //<! a list of four configurations
[4597]99
[3878]100  int getNextFreeSlot(int configID);
[3862]101};
102
[4597]103class Weapon : public WorldEntity
[3573]104{
105  friend class World;
106
107 public:
[3881]108  Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
[3573]109  virtual ~Weapon ();
[4597]110
[3583]111  void enable(void);
112  void disable(void);
113  bool isEnabled(void);
[3577]114
[3575]115  void setProjectile(Projectile* projectile);
[3583]116  Projectile* getProjectile(void);
[3575]117
[3583]118  virtual void activate(void);
119  virtual void deactivate(void);
120  bool isActive(void);
[3575]121
122
[3881]123  /**
124     \brief sets a weapon idle time
125     \param idle time in ms
[4597]126
[3881]127     a weapon idle time is the time spend after a shoot until the weapon can
128     shoot again
129  */
130  inline void setWeaponIdleTime(float time) { this->idleTime = time; }
131  /**
132     \brief gets the weapon idle time
133     \returns idle time in ms
[4597]134
[3881]135     a weapon idle time is the time spend after a shoot until the weapon can
136     shoot again
137  */
138  inline float getWeaponIdleTime(void) const { return this->idleTime;}
139  /**
140     \brief checks if the idle time is elapsed
141     \return true if time is elapsed
[4597]142
[3881]143     a weapon idle time is the time spend after a shoot until the weapon can
144   shoot again
145  */
146  inline bool hasWeaponIdleTimeElapsed(void) const { return (this->localTime>this->idleTime)?true:false; }
147
148  /**
149     \brief fires the weapon
[4597]150
[3881]151     this is called from the player.cc, when fire-button is been pushed
152  */
[3646]153  virtual void fire(void) = 0;
[3578]154  virtual void hit (WorldEntity* weapon, Vector* loc);
[3583]155  virtual void destroy(void);
[4597]156
[3583]157  virtual void tick(float time);
158  virtual void weaponIdle(void);
159  virtual void draw(void);
[3573]160
[3629]161 protected:
162  tList<WorldEntity>* worldEntities;
[3886]163  float localTime;                 //<! this is the local time. important for shooting attributes like frequency
164  float idleTime;                  //<! the time a weapon needs before it can shoot again. eg. shooting frequency or actication/deactivateion delay
165  float slowDownFactor;            //<! if the shooting frequency is a linear function of time...
[3575]166
[3886]167  PNode* objectComponent1;         //<! the gun is made of multiple parts, these PNodes represent their location and orientation
168  PNode* objectComponent2;
169  PNode* objectComponent3;
170
171  Animation3D* animation1;
172  Animation3D* animation2;
173  Animation3D* animation3;
174
[3888]175  Vector projectileOffset;
[3886]176  int leftRight;   // this will become an enum
177
[4504]178  SoundBuffer* fireSound;
179  SoundSource* weaponSource;
180
181
[3573]182 private:
[3886]183  bool enabled;                    //<! states if the weapon is enabled or not
184  Projectile* projectile;          //<! the projectile used for this weapon
[3583]185  //WeaponSound sound;
[3573]186};
187
188#endif /* _WEAPON_H */
Note: See TracBrowser for help on using the repository browser.