-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weapon.h
executable file
·68 lines (52 loc) · 1.5 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
#ifndef Weapon_h
#define Weapon_h
/**
Thing.h
Description:
Class stores state of weapon and its properties.
*/
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include "Geometry.h"
#include "Thing.h"
class Player;
class Person;
class GameMap;
class Weapon {
public:
Weapon(float range, int damage, float cooldown) :
range_(range),
damage_(damage),
max_cooldown_(cooldown) {}
/**
@return Returns float 0 ... 1, 0 means "ready", 1 means "just fired".
*/
float get_cooldown_progress() const { return (float)cooldown_ / (float)max_cooldown_; }
/**
@param from Shooter's position.
@param to Target position.
@return True if param to is reachable from param from by this weapon.
*/
bool in_range(const Vector& from, const Vector& to) const { return (to - from).length() <= range_; }
void update(int milliseconds) {
if (cooldown_ < 0) cooldown_ = 0;
if (cooldown_ == 0) return;
cooldown_ -= milliseconds;
}
void fire(const Enemy& shooter);
void fire(const Player& shooter);
private:
/**
@param thing Target.
@param shooter Owner of this weapon.
@return Returns validity flag and parameter expressing distance from thing center.
*/
std::tuple<float, bool> shoot_thing(const Thing& thing, const Person& shooter);
float range_; // centimeters
int damage_; // number of hp if hitted ideally
int cooldown_ = 0; // milliseconds
float max_cooldown_;
};
#endif // !Weapon_h_h