Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 932b0829c7698e9fa9019fad6a2559cedb1f6762 (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
/*
   core/entityprojectile.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_CORE_PROJECTILE_H__
#define __INCLUDED_CORE_PROJECTILE_H__

#include "core/entity.h"

namespace core
{

const float PROJECTILE_RADIUS = 0.025f;

class EntityProjectile : public core::EntityDynamic
{
public:
	EntityProjectile(const Entity *spawn = 0);
	EntityProjectile(std::istream & is);	
	
	virtual ~EntityProjectile();

	virtual void upkeep(const unsigned long timestamp);

	virtual void collision(Entity *other);
	
	virtual void frame(const unsigned long elapsed);

	/* --- inspectors ------------------------------------------ */
	
	/**
	 * @brief  core type id
	 * */
	virtual inline const unsigned int type() const {
		return Projectile;
	}
	
	inline const unsigned long timestamp() const
	{
		return projectile_timestamp;
	}
	
	/**
	 * @brief the lifespan of this projectile, in milliseconds
	 * */
	inline const unsigned long lifespan() const
	{
		return projectile_lifespan;
	}
	
	/**
	 * @brief the amount of damage this projectile inflicts
	 * */
	inline const float damage() const
	{
		return projectile_damage;
	}
	
	/**
	 * @brief id of the player who fired the projectile
	 * */
	inline const int owner_id() const
	{
		return projectile_owner_id;
	}
	
	/**
	 * @brief id of the entity that spawned the projectile
	 * */
	inline const unsigned int spawn_id() const
	{
		return projectile_spawn_id;
	}
	
	/**
	 * @brief return the projectile model name
	 * */
	inline const std::string & projectile_modelname() const
	{
		return projectile_modelname_str;
	}
	
	/**
	 * @brief return the projectile sound name
	 * */
	inline const std::string & projectile_soundname() const
	{
		return projectile_soundname_str;
	}
	
	/*----- serializers ----------------------------------------------- */

	/**
	 * @brief serialize the entity to a stream
	 * */
	virtual void serialize_server_create(std::ostream & os) const;

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

	/**
	 * @brief  receive a server-to-client create from a stream
	 * */
	virtual void receive_server_create(std::istream &is);
	
	/**
	 * @brief reset physics state
	 * */
	virtual void reset();
	
	/**
	 * @brief set the amount of damage this projectile inflicts
	 * */
	inline void set_damage(const float damage)
	{
		projectile_damage = damage;
	}
	
	/**
	 * @brief set the lifespan of the projectile
	 * */
	inline void set_lifespan(const unsigned long lifespan)
	{
		projectile_lifespan = lifespan;
	}

	/**
	 * @brief set the projectile timestamp
	 * */
	inline void set_timestamp(const unsigned int timestamp)
	{
		projectile_timestamp = timestamp;
	}
	
	/**
	 * @brief set the projectile model name
	 * */
	void set_projectile_modelname(const std::string modelname);
	
	/**
	 * @brief set the projectile sound name
	 * */
	void set_projectile_soundname(const std::string soundname);
	
	/**
	 * @brief set the entity that spawned the projectile
	 * This sets spawn_id() to the id of the entity and owner_id() to the id
	 * of the owner of the spawn, if any.
	 * */
	void set_spawn(const Entity *spawn);
	
private:
	unsigned long 		projectile_timestamp;
	unsigned long 		projectile_lifespan;
	
	std::string 		projectile_modelname_str;
	std::string 		projectile_soundname_str;
	
	float 			projectile_damage;
	
	int 			projectile_owner_id;
	unsigned int 		projectile_spawn_id;
};

} // namespace game

#endif // __INCLUDED_CORE_PROJECTILE_H__