-
Notifications
You must be signed in to change notification settings - Fork 1
/
Weapon.h
175 lines (161 loc) · 5.56 KB
/
Weapon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
Copyright (C) 2011-2012 Alican Sekerefe
TeamTwo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TeamTwo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Contact: projectteamtwo@gmail.com
*/
#ifndef WEAPON_H
#define WEAPON_H
#include "stdafx.h"
#include "Bullet.h"
#include "AnimationController.h"
#include "ItemStructure.h"
#include "Util/Logger.h"
namespace WeaponSlot
{
enum WeaponSlots
{
Primary=0,
Secondary,
Tertiary,
Quaternary,
Quinary,
None
};
}
/* Weapon class
This class is responsible for providing
common attributes of a weapon such as
its bullet speed, muzzle flashes and etc.
Weapon cannot be used by itself, instead
it has to be inherited by another class
in order to utilize from it.
*/
class Weapon
{
public:
//constructor of the class. requires the owner id of the weapon
//weapon's type and team
Weapon(int ownerID,int weaponType,unsigned char team);
//destructor of the class.
~Weapon()
{
Logger::getSingleton()->addLine("Weapon: deleting weapon");
delete fireTimer;
delete reloadTimer;
Logger::getSingleton()->addLine("Weapon: weapon deleted");
}
//returns muzzleflash node
SceneNode* getMuzzleFlashNode();
//updates the weapon's graphics, reload timers etc.
void update();
//starts a timer to reload the weapon
void reload();
//fires the weapon, starts a timer to calculate the next fire
void fire();
//returns the ammo count on the current clip
int getClipAmmo();
//returns the number of clips the weapon has
int getClipCount();
//returns the ammo capacity of the weapon's clip
int getClipSize();
//returns the weaponslot which the weapon object belongs
int getWeaponSlot();
//returns the maximum ammo that the weapon can have
int getMaxClip();
//returns the type of the weapon
int getWeaponType();
//returns the total ammo that the weapon has
int getTotalAmmo();
//returns true if the weapon can fire, considers the previous reload and fire actions
bool canFire();
//returns true if weapon can be reloaded. cosiders the previous reload action
bool canReload();
//returns true if the weapon can be added extra clips
bool canTakeClips();
//adds the given number of clips to the weapon
void addClip(int count);
//enables ammunition check. in this case fire() and canFire() will return variying results
//enabled by default
void enableAmmunitionCheck();
//disables ammunition check for the weapon. weapon will always be able to fire without
//checking the ammunition
void disableAmmunitionCheck();
//shows the weapon and its sub objects
void show();
//hides the weapon and its sub objects
void hide();
//sets the number of ammo that the clips has
void setClipAmmo(int ammo);
//returns the AnimationController object for the weapon
AnimationController* getAnimationController();
//retunrs the weapon' node
Ogre::SceneNode* getWeaponNode();
//returns the weapon' entity
Ogre::Entity* getWeaponEntity();
//returns the weapon's light object
Ogre::Light* getWeaponLight();
//sets a SceneNode for the weapon
void setSceneNode(Ogre::SceneNode* weaponNode);
//returns the bullet origin of the weapon
Ogre::Vector3 getBulletOrigin();
//zeros the clip and ammo count of the weapon. useful for reinitializing
void zero();
//creates bullet
virtual Bullet* createBullet(SceneManager* sceneManager,OgreBulletDynamics::DynamicsWorld* dynamics, Ogre::Vector3 position, Ogre::Quaternion orientation)=0;
//creates bullet
virtual Bullet* createBullet(SceneManager* sceneManager,OgreBulletDynamics::DynamicsWorld* dynamics, Ogre::Quaternion orientation){return NULL;}
//creates visual of the weapon
virtual void createVisual(SceneManager* sceneManager, SceneNode* playerNode)=0;
//changes the necessary colors of the weapon
virtual void changeColor(unsigned char color)=0;
private:
//initializes the weapon. must be implemented by the derived class
virtual void initialize()=0;
bool justFired;
int visualizationEndFrame;
int visualizationCurrentFrame;
bool fireVisualized;
protected:
std::string name;
int ownerID;
unsigned char team;
int totalAmmo;
int clipAmmo;
int clipCount;
int clipSize;
int maxClip;
int roundsPerSecond;
int weaponSlot;
int weaponType;
long nextFireTime;
long reloadDuration;
long reloadEndTime;
bool reloading;
bool fired;
bool check;
bool local;
Entity* bulletEntity;
AnimationController* animationController;
Ogre::Vector3 bulletOrigin;
Ogre::Timer* fireTimer;
Ogre::Timer* reloadTimer;
SceneNode* playerNode;
SceneNode* weaponNode;
SceneNode* muzzleFlashNode;
Entity* weaponEntity;
Entity* muzzleFlashEntity;
Light* weaponLight;
unsigned char color;
std::string fireSoundID;
std::vector<std::string> reloadSoundIDs;
};
#endif /* WEAPON_H */