Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 857b3cdd6389ca0d7ac0535b1b4ca03fc1ce33a1 (plain)
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
   base/weapon.h
   This file is part of the Osirion project and is distributed under
   the terms and conditions of the GNU General Public License version 2
*/

#ifndef __INCLUDED_BASE_WEAPON_H__
#define __INCLUDED_BASE_WEAPON_H__

#include "core/info.h"

namespace game
{
class Weapon : public core::Info {

public:
	enum SubType {Ammo = 0, Cannon = 1, Turret = 2, Mine = 3 };
	
	Weapon();
	~Weapon();
	
	/* --- inspectors ------------------------------------------ */
	
	inline SubType subtype() const {
		return weapon_subtype;
	}
		
	/**
	 * @brief player level required to buy this weapon
	 * */
	inline int level() const {
		return weapon_level;
	}
		
	/**
	 * @brief the amount of damage this weapon inflicts
	 * */
	inline const float damage() const
	{
		return weapon_damage;
	}
	
	/**
	 * @brief lifespan of projectiles generated by this weapon, in milliseconds
	 * */
	inline const unsigned long projectile_lifespan() const
	{
		return weapon_projectile_lifespan;
	}
	
	/**
	 * @brief speed of projectiles generated by this weapon, in game units per second
	 * */
	inline const float projectile_speed() const
	{
		return weapon_projectile_speed;
	}
	
	/**
	 * @brief projectile range, in game units
	 * */
	inline const float projectile_range() const
	{
		return (weapon_projectile_speed * ((float) weapon_projectile_lifespan) / 1000.0f);
	}
	
	/**
	 * @brief interval between consequtive projectils fired by this weapon, in milliseconds
	 * */
	inline const unsigned long projectile_interval() const
	{
		return weapon_projectile_interval;
	}
	
	/**
	 * @brief name of the model used for projectiles generated by this weapon
	 * */
	inline const std::string & projectile_modelname() const
	{
		return weapon_projectile_modelname;
	}
	
	/**
	 * @brief name of the sound used when a projectile is fired by this weapon
	 * */
	inline const std::string & projectile_soundname() const
	{
		return weapon_projectile_soundname;
	}
	
	inline const model::Slot::Type slot_type() const
	{
		switch (weapon_subtype) {
			case Cannon:
				return model::Slot::Cannon;
				break;
			case Turret:
				return model::Slot::Turret;
				break;
			default:
				return model::Slot::None;
		}
	}
		

	/* --- mutators -------------------------------------------- */

	void set_level(const int level);
	
	void set_subtype(const SubType subtype);
	
	/**
	 * @brief set the projectile lifespan, in milliseconds
	 * */
	inline void set_projectile_lifespan(const unsigned long projectile_lifespan)
	{
		weapon_projectile_lifespan = projectile_lifespan;
	}
	
	/**
	 * @brief set the interval between two consecutive shots by this weapon
	 * */
	inline void set_projectile_interval(const unsigned long projectile_interval)
	{
		weapon_projectile_interval = projectile_interval;
	}

	/**
	 * @brief set_projectile speed, in game units per second
	 * */
	inline void set_projectile_speed(const float projectile_speed)
	{
		weapon_projectile_speed = projectile_speed;
	}
	
	/**
	 * @brief set the amount of damage this weapon inflicts
	 * */
	inline void set_damage(const float damage)
	{
		weapon_damage = damage;
	}
	
	/**
	 * @brief set projectile model name
	 * */
	inline void set_projectile_modelname(const std::string & projectile_modelname)
	{
		weapon_projectile_modelname.assign(projectile_modelname);
	}
	
	/**
	 * @brief set the projectile sound name
	 * */
	inline void set_projectile_soundname(const std::string soundname)
	{
		weapon_projectile_soundname.assign(soundname);
	}

	/**
	 * @brief generate specifications info.
	 * */
	void generate_info();
	
	/* --- static registry functions ---------------------------------- */
	
	static Weapon *find(const std::string & label);
	
	static bool init();
	
	static void done();
	
	static void list();
	
	static inline const core::InfoType *infotype() {
		return weapon_infotype;
	}

private:
	static core::InfoType *weapon_infotype;
	
	SubType		weapon_subtype;
	
	int		weapon_level;
	
	unsigned long	weapon_projectile_interval;
	
	unsigned long	weapon_projectile_lifespan;
	
	float		weapon_projectile_speed;
	
	float		weapon_damage;
	
	std::string	weapon_projectile_modelname;
	
	std::string	weapon_projectile_soundname;
};

} // namespace game

#endif // __INCLUDED_BASE_WEAPON_H__