1 #ifndef __GNUC__
2 #pragma once
3 #endif
4 #ifndef __XR_ENTITY_H__
5 #define __XR_ENTITY_H__
6 
7 #include <string>
8 #include <vector>
9 #include <stack>
10 #include "xr_shape.h"
11 #include "xr_color.h"
12 #include "xr_quaternion.h"
13 #include "xr_packet.h"
14 #include "xr_clsid.h"
15 
16 namespace xray_re {
17 
18 enum {
19 	M_UPDATE	= 0,
20 	M_SPAWN		= 1,
21 };
22 
23 enum {
24 	CSE_VERSION_0x01	= 0x01,
25 	CSE_VERSION_0x03	= 0x03,
26 	CSE_VERSION_0x04	= 0x04,
27 	CSE_VERSION_0x05	= 0x05,
28 	CSE_VERSION_0x08	= 0x08,
29 	CSE_VERSION_0x09	= 0x09,
30 	CSE_VERSION_0x0a	= 0x0a,
31 	CSE_VERSION_0x0b	= 0x0b,
32 	CSE_VERSION_0x0c	= 0x0c,
33 	CSE_VERSION_0x0e	= 0x0e,
34 	CSE_VERSION_0x10	= 0x10,
35 	CSE_VERSION_0x11	= 0x11,
36 	CSE_VERSION_0x12	= 0x12,
37 	CSE_VERSION_0x13	= 0x13,
38 	CSE_VERSION_0x14	= 0x14,
39 	CSE_VERSION_0x15	= 0x15,
40 	CSE_VERSION_0x16	= 0x16,
41 	CSE_VERSION_0x17	= 0x17,
42 	CSE_VERSION_0x18	= 0x18,
43 	CSE_VERSION_0x19	= 0x19,
44 	CSE_VERSION_0x1a	= 0x1a,
45 	CSE_VERSION_0x1b	= 0x1b,
46 	CSE_VERSION_0x1c	= 0x1c,
47 	CSE_VERSION_0x1d	= 0x1d,
48 	CSE_VERSION_0x1e	= 0x1e,
49 	CSE_VERSION_0x1f	= 0x1f,
50 	CSE_VERSION_0x20	= 0x20,
51 	CSE_VERSION_0x21	= 0x21,
52 	CSE_VERSION_0x22	= 0x22,
53 	CSE_VERSION_0x23	= 0x23,
54 	CSE_VERSION_0x24	= 0x24,
55 	CSE_VERSION_0x25	= 0x25,
56 	CSE_VERSION_0x26	= 0x26,
57 	CSE_VERSION_0x27	= 0x27,
58 	CSE_VERSION_0x28	= 0x28,
59 	CSE_VERSION_0x2a	= 0x2a,
60 	CSE_VERSION_0x2b	= 0x2b,
61 	CSE_VERSION_0x2c	= 0x2c,
62 	CSE_VERSION_0x2e	= 0x2e,//build 1829
63 	CSE_VERSION_0x31	= 0x31,
64 	CSE_VERSION_0x34	= 0x34,
65 	CSE_VERSION_0x35	= 0x35,
66 	CSE_VERSION_0x37	= 0x37,
67 	CSE_VERSION_0x38	= 0x38,
68 	CSE_VERSION_0x39	= 0x39,
69 	CSE_VERSION_0x3a	= 0x3a,
70 	CSE_VERSION_0x3c	= 0x3c,
71 	CSE_VERSION_0x3d	= 0x3d,
72 	CSE_VERSION_0x3e	= 0x3e,
73 	CSE_VERSION_0x40	= 0x40,
74 	CSE_VERSION_0x41	= 0x41,
75 	CSE_VERSION_0x42	= 0x42,
76 	CSE_VERSION_0x43	= 0x43,
77 	CSE_VERSION_0x44	= 0x44,
78 	CSE_VERSION_0x45	= 0x45,
79 	CSE_VERSION_0x46	= 0x46,
80 	CSE_VERSION_0x48	= 0x48,
81 	CSE_VERSION_0x49	= 0x49,
82 	CSE_VERSION_0x4a	= 0x4a,
83 	CSE_VERSION_0x4b	= 0x4b,
84 	CSE_VERSION_0x4e	= 0x4e,
85 	CSE_VERSION_0x4d	= 0x4d,
86 	CSE_VERSION_0x4f	= 0x4f,
87 	CSE_VERSION_0x51	= 0x51,
88 	CSE_VERSION_0x52	= 0x52,
89 	CSE_VERSION_0x53	= 0x53,
90 	CSE_VERSION_0x54	= 0x54,
91 	CSE_VERSION_0x55	= 0x55,
92 	CSE_VERSION_0x56	= 0x56,
93 	CSE_VERSION_0x57	= 0x57,
94 	CSE_VERSION_0x58	= 0x58,
95 	CSE_VERSION_0x59	= 0x59,
96 	CSE_VERSION_0x5a	= 0x5a,
97 	CSE_VERSION_0x5b	= 0x5b,
98 	CSE_VERSION_0x5c	= 0x5c,
99 	CSE_VERSION_0x5d	= 0x5d,
100 	CSE_VERSION_0x5e	= 0x5e,
101 	CSE_VERSION_0x5f	= 0x5f,
102 	CSE_VERSION_0x60	= 0x60,
103 	CSE_VERSION_0x62	= 0x62,
104 	CSE_VERSION_0x63	= 0x63,
105 	CSE_VERSION_0x65	= 0x65,
106 	CSE_VERSION_0x66	= 0x66,
107 	CSE_VERSION_0x67	= 0x67,
108 	CSE_VERSION_0x68	= 0x68,
109 	CSE_VERSION_0x69	= 0x69,
110 	CSE_VERSION_0x6a	= 0x6a,
111 	CSE_VERSION_0x6c	= 0x6c,
112 	CSE_VERSION_0x6d	= 0x6d,
113 	CSE_VERSION_0x6e	= 0x6e,
114 	CSE_VERSION_0x6f	= 0x6f,
115 	CSE_VERSION_0x70	= 0x70,
116 	CSE_VERSION_0x71	= 0x71,
117 	CSE_VERSION_0x73	= 0x73,
118 	CSE_VERSION_0x74	= 0x74,
119 	CSE_VERSION_0x75	= 0x75,
120 	CSE_VERSION_0x76	= 0x76,
121 	CSE_VERSION_0x78	= 0x78,
122 	CSE_VERSION_0x7a	= 0x7a,
123 	CSE_VERSION_0x7b	= 0x7b,
124 	CSE_VERSION_0x7c	= 0x7c,
125 	CSE_VERSION_0x80	= 0x80,
126 
127 	// build 1580
128 	CSE_VERSION_1580 = 0x27,
129 
130 	// patch 04 introduced following changes:
131 	// 1) se_level_changer instead of cse_alife_level_changer (0x7b)
132 	// 2) save markers (0x7b)
133 	// 3) persistent upgrades for cse_alife_item (0x7c)
134 	// so let's use this hack and broke builds 3456-3487.
135 	CSE_VERSION_0x7c_HACK	= 0x7b,
136 
137 	// build 2215: version=0x65, script_version=2
138 	CSE_VERSION_2215	= CSE_VERSION_0x65,
139 
140 	// build 22xx-2571: version=0x6a(dunno, where to look this?), script_version=3
141 	CSE_VERSION_2232	= CSE_VERSION_0x68, //guest it.. lol
142 
143 	// build 2571: version 0x75 script_version = 4
144 	CSE_VERSION_2571	= CSE_VERSION_0x75,
145 
146 	// builds 2945, 2939, 2947: version=0x76, script_version=5
147 	// builds 2942, 3006+, 3120: version=0x76, script_version=6
148 	// builds 3188, 3191+: version=0x76, script_version=7
149 	CSE_VERSION_SOC		= CSE_VERSION_0x76,
150 
151 	// build 3456: version=0x7b, script_version=8 (some level.spawn files are at version=0x7a)
152 	// build 3487: version=0x7b, script_version=8
153 	// build 3502: version=0x7c, script_version=8
154 	CSE_VERSION_CS		= CSE_VERSION_0x7c,
155 
156 	// build 3870: CoP 1.6.00
157 	// build 3912: CoP 1.6.01
158 	//�build�3967:�COP�1.6.02�version�0x80,�script_version=12
159 	CSE_VERSION_COP		= CSE_VERSION_0x80,
160 };
161 
162 struct ph_net_state {
163 	fvector3	linear_vel;
164 	fvector3	angular_vel;
165 	fvector3	force;
166 	fvector3	torque;
167 	fvector3	position;
168 	fvector3	prev_position;
169 	union {
170 		fquaternion	quaternion;
171 		fvector3	accel;
172 		float		max_velocity;
173 	};
174 	fquaternion	prev_quaternion;
175 	bool		enabled;
176 };
177 
178 class cse_motion {
179 public:
180 				cse_motion();
181 	virtual			~cse_motion();
182 	void			motion_read(xr_packet& packet);
183 	void			motion_write(xr_packet& packet);
184 	virtual cse_motion*	motion() = 0;
185 private:
186 	std::string		m_motion_name;
187 };
188 
189 class cse_visual {
190 public:
191 				cse_visual();
192 	virtual			~cse_visual();
193 	void			visual_read(xr_packet& packet, uint16_t version);
194 	void			visual_write(xr_packet& packet, uint16_t version);
195 	virtual cse_visual*	visual() = 0;
196 
197 	enum {
198 		FL_OBSTACLE,
199 	};
200 protected:
201 	std::string	m_visual_name;
202 	std::string	m_startup_animation;
203 	uint8_t		m_flags;
204 };
205 
206 class cse_shape {
207 public:
208 				cse_shape();
209 	virtual			~cse_shape();
210 	void			cform_merge(xr_packet& packet);
211 	void			cform_read(xr_packet& packet);
212 	void			cform_write(xr_packet& packet);
213 	virtual cse_shape*	shape() = 0;
214 	shape_def_vec&		shapes();
215 
216 protected:
217 	shape_def_vec		m_shapes;
218 };
219 
220 class cse_ph_skeleton {
221 public:
222 			cse_ph_skeleton();
223 	virtual		~cse_ph_skeleton();
224 	virtual void	state_read(xr_packet& packet, uint16_t size);
225 	virtual void	state_write(xr_packet& packet);
226 	virtual void	update_read(xr_packet& packet);
227 	virtual void	update_write(xr_packet& packet);
228 	virtual void	data_load(xr_packet& packet);
229 	virtual void	data_save(xr_packet& packet);
230 	enum {
231 		FL_ACTIVE	= 0x01,
232 		FL_SPAWN_COPY	= 0x02,
233 		FL_SAVED_DATA	= 0x04,
234 		FL_NOT_SAVE	= 0x08,
235 	};
236 protected:
237 	std::string	m_root_bone;
238 	uint8_t		m_flags;
239 	uint16_t	m_source_id;
240 };
241 
242 class cse_abstract {
243 public:
244 				cse_abstract();
245 	virtual			~cse_abstract();
246 	void			spawn_merge(xr_packet& packet);
247 	void			spawn_read(xr_packet& packet);
248 	void			spawn_write(xr_packet& packet, bool local);
249 	virtual void		state_merge(xr_packet& packet, uint16_t version) = 0;
250 	virtual void		state_read(xr_packet& packet, uint16_t size) = 0;
251 	virtual void		state_write(xr_packet& packet) = 0;
252 	virtual void		update_read(xr_packet& packet) = 0;
253 	virtual void		update_write(xr_packet& packet) = 0;
254 	virtual cse_shape*	shape();
255 	virtual cse_visual*	visual();
256 	virtual cse_motion*	motion();
257 	virtual cse_abstract*	base();
258 
259 	enum esm_mode {
260 		SM_SAVE,
261 		SM_LOAD,
262 	};
263 	void			set_save_marker(xr_packet& packet, esm_mode mode,
264 						bool check, const char* name);
265 
266 	std::string&		name();
267 	const std::string&	name() const;
268 	std::string&		name_replace();
269 	const std::string&	name_replace() const;
270 	xr_clsid&		clsid();
271 	const xr_clsid&		clsid() const;
272 	const uint8_t		game_id() const;
273 	fvector3&		position();
274 	const fvector3&		position() const;
275 	fvector3&		rotation();
276 	const fvector3&		rotation() const;
277 	uint16_t&		version();
278 	uint16_t		version() const;
279 	uint16_t&		script_version();
280 	uint16_t		script_version() const;
281 	uint16_t&		spawn_id();
282 	uint16_t		spawn_id() const;
283 
284 	enum game_id {
285 		GAME_ANY		= 0,
286 		GAME_SINGLE		= 1,
287 		GAME_DEATHMATCH		= 2,
288 		GAME_CTF		= 3,
289 		GAME_ASSAULT		= 4,
290 		GAME_CS			= 5,
291 		GAME_TEAMDEATHMATCH	= 6,
292 		GAME_ARTEFACTHUNT	= 7,
293 		GAME_LASTSTANDING	= 100,
294 		GAME_DUMMY		= 255,
295 	};
296 	enum {
297 		FL_SPAWN_ENABLED		= 0x01,
298 		FL_SPAWN_ON_SURGE_ONLY		= 0x02,
299 		FL_SPAWN_SINGLE_ITEM_ONLY	= 0x04,
300 		FL_SPAWN_IF_DESTROYED_ONLY	= 0x08,
301 		FL_SPAWN_INFINITE_COUNT		= 0x10,
302 		FL_SPAWN_DESTROY_ON_SPAWN	= 0x20,
303 	};
304 
305 protected:
306 	std::string	m_s_name_replace;
307 
308 	uint16_t	m_version;
309 	uint16_t	m_script_version;
310 	uint16_t	m_respawn_time;
311 
312 	uint16_t	m_id;
313 	uint16_t	m_id_parent;
314 	uint16_t	m_id_phantom;
315 
316 	std::string	m_s_name;
317 	uint8_t		m_s_game_id;
318 	uint8_t		m_s_rp;
319 	uint16_t	m_s_flags;
320 
321 	uint16_t	m_cs_unk1_u16;		// introduced in clear sky
322 
323 	fvector3	m_o_position;
324 	fvector3	m_o_angle;
325 
326 	std::string	m_ini_string;
327 
328 	uint16_t	m_spawn_id;
329 
330 	xr_clsid	m_clsid;
331 
332 private:
333 	struct sm_record {
334 				sm_record(const char* _name, size_t _offset);
335 		const char*	name;
336 		size_t		offset;
337 	};
338 	std::stack<sm_record>	m_markers;
339 };
340 
341 typedef std::vector<cse_abstract*> xr_entity_vec;
342 typedef std::vector<cse_abstract*>::iterator xr_entity_vec_it;
343 typedef std::vector<cse_abstract*>::const_iterator xr_entity_vec_cit;
344 
name()345 inline std::string& cse_abstract::name() { return m_s_name; }
name()346 inline const std::string& cse_abstract::name() const { return m_s_name; }
347 
name_replace()348 inline std::string& cse_abstract::name_replace() { return m_s_name_replace; }
name_replace()349 inline const std::string& cse_abstract::name_replace() const { return m_s_name_replace; }
350 
position()351 inline fvector3& cse_abstract::position() { return m_o_position; }
position()352 inline const fvector3& cse_abstract::position() const { return m_o_position; }
353 
rotation()354 inline fvector3& cse_abstract::rotation() { return m_o_angle; }
rotation()355 inline const fvector3& cse_abstract::rotation() const { return m_o_angle; }
356 
clsid()357 inline xr_clsid& cse_abstract::clsid() { return m_clsid; }
clsid()358 inline const xr_clsid& cse_abstract::clsid() const { return m_clsid; }
359 
game_id()360 inline const uint8_t cse_abstract::game_id() const { return m_s_game_id; }
361 
version()362 inline uint16_t& cse_abstract::version() { return m_version; }
version()363 inline uint16_t cse_abstract::version() const { return m_version; }
364 
script_version()365 inline uint16_t& cse_abstract::script_version() { return m_script_version; }
script_version()366 inline uint16_t cse_abstract::script_version() const { return m_script_version; }
367 
spawn_id()368 inline uint16_t& cse_abstract::spawn_id() { return m_spawn_id; }
spawn_id()369 inline uint16_t cse_abstract::spawn_id() const { return m_spawn_id; }
370 
371 class cse_alife_graph_point: public cse_abstract {
372 public:
373 			cse_alife_graph_point();
374 	virtual void	state_merge(xr_packet& packet, uint16_t version);
375 	virtual void	state_read(xr_packet& packet, uint16_t size);
376 	virtual void	state_write(xr_packet& packet);
377 	virtual void	update_read(xr_packet& packet);
378 	virtual void	update_write(xr_packet& packet);
379 
380 	std::string&		connection_level();
381 	const std::string&	connection_level() const;
382 	std::string&		connection_point();
383 	const std::string&	connection_point() const;
384 
385 protected:
386 	std::string	m_connection_level_name;
387 	std::string	m_connection_point_name;
388 	uint8_t		m_locations[4];
389 };
390 
connection_level()391 inline std::string& cse_alife_graph_point::connection_level() { return m_connection_level_name; }
connection_level()392 inline const std::string& cse_alife_graph_point::connection_level() const { return m_connection_level_name; }
393 
connection_point()394 inline std::string& cse_alife_graph_point::connection_point() { return m_connection_point_name; }
connection_point()395 inline const std::string& cse_alife_graph_point::connection_point() const { return m_connection_point_name; }
396 
397 class cse_alife_object: public cse_abstract {
398 public:
399 				cse_alife_object();
400 	virtual void		state_merge(xr_packet& packet, uint16_t version);
401 	virtual void		state_read(xr_packet& packet, uint16_t size);
402 	virtual void		state_write(xr_packet& packet);
403 	virtual void		update_read(xr_packet& packet);
404 	virtual void		update_write(xr_packet& packet);
405 
406 	uint16_t&		graph_id();
407 	uint16_t		graph_id() const;
408 	float&			distance();
409 	float			distance() const;
410 	uint32_t&		node_id();
411 	uint32_t		node_id() const;
412 	uint32_t&		flags();
413 	uint32_t		flags() const;
414 
415 	enum {
416 		FL_USE_SWITCHES		= 0x0001,
417 		FL_SWITCH_ONLINE	= 0x0002,
418 		FL_SWITCH_OFFLINE	= 0x0004,
419 		FL_INTERACTIVE		= 0x0008,
420 		FL_VISIBLE_FOR_AI	= 0x0010,
421 		FL_USEFUL_FOR_AI	= 0x0020,
422 		FL_OFFLINE_NO_MOVE	= 0x0040,
423 		FL_USED_AI_LOCATIONS	= 0x0080,
424 		FL_GROUP_BEHAVIOUR	= 0x0100,
425 		FL_CAN_SAVE		= 0x0200,
426 		FL_VISIBLE_FOR_MAP	= 0x0400,
427 		FL_USE_SMART_TERRAINS	= 0x0800,
428 		FL_CHECK_FOR_SEPARATOR	= 0x1000,
429 		FL_CORPSE_REMOVAL	= 0x2000,
430 		FL_CUSTOM		= 0x800000,
431 	};
432 protected:
433 	uint16_t	m_graph_id;
434 	float		m_distance;
435 	bool		m_direct_control;
436 	uint32_t	m_node_id;
437 	uint32_t	m_flags;
438 	uint32_t	m_story_id;
439 	uint32_t	m_spawn_story_id;
440 };
441 
graph_id()442 inline uint16_t& cse_alife_object::graph_id() { return m_graph_id; }
graph_id()443 inline uint16_t cse_alife_object::graph_id() const { return m_graph_id; }
444 
distance()445 inline float& cse_alife_object::distance() { return m_distance; }
distance()446 inline float cse_alife_object::distance() const { return m_distance; }
447 
node_id()448 inline uint32_t& cse_alife_object::node_id() { return m_node_id; }
node_id()449 inline uint32_t cse_alife_object::node_id() const { return m_node_id; }
450 
flags()451 inline uint32_t& cse_alife_object::flags() { return m_flags; }
flags()452 inline uint32_t cse_alife_object::flags() const { return m_flags; }
453 
454 class cse_alife_dynamic_object: public cse_alife_object {
455 public:
456 	virtual void	state_merge(xr_packet& packet, uint16_t version);
457 	virtual void	state_read(xr_packet& packet, uint16_t size);
458 	virtual void	state_write(xr_packet& packet);
459 	virtual void	update_read(xr_packet& packet);
460 	virtual void	update_write(xr_packet& packet);
461 protected:
462 };
463 
464 class cse_alife_dynamic_object_visual: public cse_alife_dynamic_object, public cse_visual {
465 public:
466 	virtual void		state_read(xr_packet& packet, uint16_t size);
467 	virtual void		state_write(xr_packet& packet);
468 	virtual void		update_read(xr_packet& packet);
469 	virtual void		update_write(xr_packet& packet);
470 	virtual cse_visual*	visual();
471 };
472 
473 class cse_alife_object_climable: public cse_shape, public cse_alife_dynamic_object {
474 public:
475 				cse_alife_object_climable();
476 	virtual void		state_read(xr_packet& packet, uint16_t size);
477 	virtual void		state_write(xr_packet& packet);
478 	virtual void		update_read(xr_packet& packet);
479 	virtual void		update_write(xr_packet& packet);
480 	virtual cse_shape*	shape();
481 protected:
482 	uint16_t		m_flags;
483 
484 	// CoP addition
485 	std::string		m_game_material;
486 };
487 
488 class cse_smart_cover: public cse_shape, public cse_alife_dynamic_object {
489 public:
490 				cse_smart_cover();
491 	virtual void		state_read(xr_packet& packet, uint16_t size);
492 	virtual void		state_write(xr_packet& packet);
493 	virtual void		update_read(xr_packet& packet);
494 	virtual void		update_write(xr_packet& packet);
495 	virtual cse_shape*	shape();
496 protected:
497 	std::string		m_cs_unk1_sz;
498 	float			m_cs_unk2_float;
499 	float			m_enter_min_enemy_distance;
500 	float			m_exit_min_enemy_distance;
501 	bool			m_is_combat_cover;
502 
503 	// CoP addition
504 	uint8_t		m_cs_unk3_u8;
505 };
506 
507 class cse_alife_object_physic: public cse_alife_dynamic_object_visual, public cse_ph_skeleton {
508 public:
509 			cse_alife_object_physic();
510 	virtual void	state_read(xr_packet& packet, uint16_t size);
511 	virtual void	state_write(xr_packet& packet);
512 	virtual void	update_read(xr_packet& packet);
513 	virtual void	update_write(xr_packet& packet);
514 protected:
515 	uint32_t	m_type;
516 	float		m_mass;
517 	std::string	m_fixed_bones;
518 
519 	// clear sky addition
520 	uint8_t		m_num_items;
521 	ph_net_state	m_state;
522 };
523 
524 class cse_alife_object_hanging_lamp: public cse_alife_dynamic_object_visual, public cse_ph_skeleton {
525 public:
526 			cse_alife_object_hanging_lamp();
527 	virtual void	state_read(xr_packet& packet, uint16_t size);
528 	virtual void	state_write(xr_packet& packet);
529 	virtual void	update_read(xr_packet& packet);
530 	virtual void	update_write(xr_packet& packet);
531 	enum {
532 		FL_PHYSIC	= 0x01,
533 		FL_CAST_SHADOW	= 0x02,
534 		FL_R1		= 0x04,
535 		FL_R2		= 0x08,
536 		FL_TYPE_SPOT	= 0x10,
537 		FL_POINT_AMBIENT= 0x20,
538 	};
539 protected:
540 	uint16_t	m_flags;
541 	rgba32		m_color;
542 	float		m_brightness;
543 	std::string	m_color_animator;
544 	std::string	m_light_texture;
545 	float		m_range;
546 	float		m_virtual_size;
547 	std::string	m_light_ambient_bone;
548 	std::string	m_light_main_bone;
549 	std::string	m_fixed_bones;
550 	float		m_spot_cone_angle;
551 	float		m_ambient_radius;
552 	float		m_ambient_power;
553 	std::string	m_ambient_texture;
554 	std::string	m_glow_texture;
555 	float		m_glow_radius;
556 	float		m_health;
557 
558 	// clear sky additions
559 	float		m_cs_unk1_float;
560 	float		m_cs_unk2_float;
561 	float		m_cs_unk3_float;
562 };
563 
564 class cse_alife_object_projector: public cse_alife_dynamic_object_visual {
565 public:
566 	virtual void	state_read(xr_packet& packet, uint16_t size);
567 	virtual void	state_write(xr_packet& packet);
568 	virtual void	update_read(xr_packet& packet);
569 	virtual void	update_write(xr_packet& packet);
570 };
571 
572 class cse_inventory_box: public cse_alife_dynamic_object_visual {
573 public:
574 	cse_inventory_box();
575 	virtual void	state_read(xr_packet& packet, uint16_t size);
576 	virtual void	state_write(xr_packet& packet);
577 	virtual void	update_read(xr_packet& packet);
578 	virtual void	update_write(xr_packet& packet);
579 
580 	uint8_t cse_alive_inventory_box__unk1_u8;
581 	uint8_t cse_alive_inventory_box__unk2_u8;
582 	std::string tip;
583 };
584 
585 class cse_alife_object_breakable: public cse_alife_dynamic_object_visual {
586 public:
587 			cse_alife_object_breakable();
588 	virtual void	state_read(xr_packet& packet, uint16_t size);
589 	virtual void	state_write(xr_packet& packet);
590 	virtual void	update_read(xr_packet& packet);
591 	virtual void	update_write(xr_packet& packet);
592 protected:
593 	float		m_health;
594 };
595 
596 class cse_alife_mounted_weapon: public cse_alife_dynamic_object_visual {
597 public:
598 	virtual void	state_read(xr_packet& packet, uint16_t size);
599 	virtual void	state_write(xr_packet& packet);
600 	virtual void	update_read(xr_packet& packet);
601 	virtual void	update_write(xr_packet& packet);
602 };
603 
604 class cse_alife_stationary_mgun: public cse_alife_dynamic_object_visual {
605 public:
606 			cse_alife_stationary_mgun();
607 	virtual void	state_read(xr_packet& packet, uint16_t size);
608 	virtual void	state_write(xr_packet& packet);
609 	virtual void	update_read(xr_packet& packet);
610 	virtual void	update_write(xr_packet& packet);
611 protected:
612 	bool		m_working;
613 	fvector3	m_dest_enemy_dir;
614 };
615 
616 class cse_alife_ph_skeleton_object: public cse_alife_dynamic_object_visual, public cse_ph_skeleton {
617 public:
618 	virtual void	state_read(xr_packet& packet, uint16_t size);
619 	virtual void	state_write(xr_packet& packet);
620 	virtual void	update_read(xr_packet& packet);
621 	virtual void	update_write(xr_packet& packet);
622 };
623 
624 class cse_alife_car: public cse_alife_dynamic_object_visual, public cse_ph_skeleton {
625 public:
626 			cse_alife_car();
627 	virtual void	state_read(xr_packet& packet, uint16_t size);
628 	virtual void	state_write(xr_packet& packet);
629 	virtual void	update_read(xr_packet& packet);
630 	virtual void	update_write(xr_packet& packet);
631 protected:
632 	float		m_health;
633 };
634 
635 class cse_alife_helicopter: public cse_alife_dynamic_object_visual, public cse_motion, public cse_ph_skeleton {
636 public:
637 	virtual void		state_read(xr_packet& packet, uint16_t size);
638 	virtual void		state_write(xr_packet& packet);
639 	virtual void		update_read(xr_packet& packet);
640 	virtual void		update_write(xr_packet& packet);
641 	virtual cse_motion*	motion();
642 
643 protected:
644 	std::string	m_engine_sound;
645 };
646 
647 struct s_rotation {
648 	float	yaw;
649 	float	pitch;
650 	float	roll;
651 };
652 
653 class cse_alife_creature_abstract: public cse_alife_dynamic_object_visual {
654 public:
655 			cse_alife_creature_abstract();
656 	virtual void	state_read(xr_packet& packet, uint16_t size);
657 	virtual void	state_write(xr_packet& packet);
658 	virtual void	update_read(xr_packet& packet);
659 	virtual void	update_write(xr_packet& packet);
660 protected:
661 	uint8_t		m_s_team;
662 	uint8_t		m_s_squad;
663 	uint8_t		m_s_group;
664 	float		m_health;
665 	uint32_t	m_timestamp;
666 	uint8_t		m_flags;
667 	float		m_o_model;
668 	s_rotation	m_o_torso;
669 	std::vector<uint16_t>	m_dynamic_out_restrictions;
670 	std::vector<uint16_t>	m_dynamic_in_restrictions;
671 	uint16_t	m_killer_id;
672 	uint64_t	m_game_death_time;
673 };
674 
675 class cse_alife_creature_crow: public cse_alife_creature_abstract {
676 public:
677 	virtual void	state_read(xr_packet& packet, uint16_t size);
678 	virtual void	state_write(xr_packet& packet);
679 	virtual void	update_read(xr_packet& packet);
680 	virtual void	update_write(xr_packet& packet);
681 };
682 
683 class cse_alife_creature_phantom: public cse_alife_creature_abstract {
684 public:
685 	virtual void	state_read(xr_packet& packet, uint16_t size);
686 	virtual void	state_write(xr_packet& packet);
687 	virtual void	update_read(xr_packet& packet);
688 	virtual void	update_write(xr_packet& packet);
689 };
690 
691 class cse_alife_monster_abstract: public cse_alife_creature_abstract {
692 public:
693 			cse_alife_monster_abstract();
694 	virtual void	state_read(xr_packet& packet, uint16_t size);
695 	virtual void	state_write(xr_packet& packet);
696 	virtual void	update_read(xr_packet& packet);
697 	virtual void	update_write(xr_packet& packet);
698 protected:
699 	uint16_t	m_next_graph_id;
700 	uint16_t	m_prev_graph_id;
701 	float		m_distance_from_point;
702 	float		m_distance_to_point;
703 	std::string	m_out_space_restrictors;
704 	std::string	m_in_space_restrictors;
705 	uint16_t	m_smart_terrain_id;
706 	bool		m_task_reached;
707 };
708 
709 class cse_alife_monster_zombie: public cse_alife_monster_abstract {
710 public:
711 			cse_alife_monster_zombie();
712 	virtual void	state_read(xr_packet& packet, uint16_t size);
713 	virtual void	state_write(xr_packet& packet);
714 	virtual void	update_read(xr_packet& packet);
715 	virtual void	update_write(xr_packet& packet);
716 protected:
717 	float		m_eye_fov;
718 	float		m_eye_range;
719 	float		m_min_range;
720 	float		m_max_range;
721 	float		m_attack_speed;
722 	float		m_max_pursuit_radius;
723 	float		m_max_home_radius;
724 	float		m_hit_power;
725 	uint16_t	m_hit_interval;
726 	float		m_attack_distance;
727 	float		m_attack_angle;
728 };
729 
730 class cse_alife_monster_base: public cse_alife_monster_abstract, public cse_ph_skeleton {
731 public:
732 			cse_alife_monster_base();
733 	virtual void	state_read(xr_packet& packet, uint16_t size);
734 	virtual void	state_write(xr_packet& packet);
735 	virtual void	update_read(xr_packet& packet);
736 	virtual void	update_write(xr_packet& packet);
737 protected:
738 	uint16_t	m_spec_object_id;
739 };
740 
741 class cse_alife_psy_dog_phantom: public cse_alife_monster_base {
742 public:
743 	virtual void	state_read(xr_packet& packet, uint16_t size);
744 	virtual void	state_write(xr_packet& packet);
745 	virtual void	update_read(xr_packet& packet);
746 	virtual void	update_write(xr_packet& packet);
747 };
748 
749 class cse_alife_trader_abstract {
750 public:
751 				cse_alife_trader_abstract();
752 	virtual void		state_merge(xr_packet& packet, uint16_t version);
753 	virtual void		state_read(xr_packet& packet, uint16_t size);
754 	virtual void		state_write(xr_packet& packet);
755 	virtual void		update_read(xr_packet& packet);
756 	virtual void		update_write(xr_packet& packet);
757 	virtual cse_abstract*	base() = 0;
758 
759 	enum {
760 		FLAG_INFINITE_AMMO	= 0x1,
761 	};
762 protected:
763 	uint32_t	m_money;
764 	uint32_t	m_trader_flags;
765 	int32_t		m_community_index;
766 	int32_t		m_reputation;
767 	int32_t		m_rank;
768 	std::string	m_character_profile;
769 	std::string	m_specific_character;
770 	std::string	m_character_name;
771 
772 	// CoP additions
773 	uint8_t		m_unk1_u8;
774 	uint8_t		m_unk2_u8;
775 };
776 
777 class cse_alife_trader: public cse_alife_dynamic_object_visual, public cse_alife_trader_abstract {
778 public:
779 	virtual void		state_read(xr_packet& packet, uint16_t size);
780 	virtual void		state_write(xr_packet& packet);
781 	virtual void		update_read(xr_packet& packet);
782 	virtual void		update_write(xr_packet& packet);
783 	virtual cse_abstract*	base();
784 };
785 
786 class cse_alife_human_abstract: public cse_alife_trader_abstract, public cse_alife_monster_abstract {
787 public:
788 	virtual void		state_merge(xr_packet& packet, uint16_t version);
789 	virtual void		state_read(xr_packet& packet, uint16_t size);
790 	virtual void		state_write(xr_packet& packet);
791 	virtual void		update_read(xr_packet& packet);
792 	virtual void		update_write(xr_packet& packet);
793 	virtual cse_abstract*	base();
794 protected:
795 	// from CALifeHumanBrain
796 	std::vector<uint8_t>	m_equipment_preferences;
797 	std::vector<uint8_t>	m_main_weapon_preferences;
798 };
799 
800 class cse_alife_human_stalker: public cse_alife_human_abstract, public cse_ph_skeleton {
801 public:
802 	virtual void	state_read(xr_packet& packet, uint16_t size);
803 	virtual void	state_write(xr_packet& packet);
804 	virtual void	update_read(xr_packet& packet);
805 	virtual void	update_write(xr_packet& packet);
806 protected:
807 	std::string	m_start_dialog;
808 };
809 
810 class cse_alife_creature_actor: public cse_alife_creature_abstract, public cse_alife_trader_abstract, cse_ph_skeleton {
811 public:
812 				cse_alife_creature_actor();
813 	virtual void		state_read(xr_packet& packet, uint16_t size);
814 	virtual void		state_write(xr_packet& packet);
815 	virtual void		update_read(xr_packet& packet);
816 	virtual void		update_write(xr_packet& packet);
817 	virtual cse_abstract*	base();
818 protected:
819 	uint16_t	m_state;
820 	fvector3	m_accel;
821 	fvector3	m_velocity;
822 	float		m_radiation;
823 	uint8_t		m_weapon;
824 	uint16_t	m_holder_id;
825 	uint16_t	m_num_items;
826 };
827 
828 class cse_alife_space_restrictor: public cse_alife_dynamic_object, public cse_shape {
829 public:
830 				cse_alife_space_restrictor();
831 	virtual void		state_merge(xr_packet& packet, uint16_t version);
832 	virtual void		state_read(xr_packet& packet, uint16_t size);
833 	virtual void		state_write(xr_packet& packet);
834 	virtual void		update_read(xr_packet& packet);
835 	virtual void		update_write(xr_packet& packet);
836 	virtual cse_shape*	shape();
837 	enum {
838 		DEFAULT_RESTRICTOR_TYPE_NONE	= 0,
839 	};
840 protected:
841 	uint8_t		m_space_restrictor_type;
842 };
843 
844 class cse_alife_smart_zone: public cse_alife_space_restrictor {
845 public:
846 	virtual void	state_read(xr_packet& packet, uint16_t size);
847 	virtual void	state_write(xr_packet& packet);
848 	virtual void	update_read(xr_packet& packet);
849 	virtual void	update_write(xr_packet& packet);
850 };
851 
852 class cse_alife_team_base_zone: public cse_alife_space_restrictor {
853 public:
854 			cse_alife_team_base_zone();
855 	virtual void	state_read(xr_packet& packet, uint16_t size);
856 	virtual void	state_write(xr_packet& packet);
857 	virtual void	update_read(xr_packet& packet);
858 	virtual void	update_write(xr_packet& packet);
859 protected:
860 	uint8_t		m_team;
861 };
862 
863 class cse_alife_level_changer: public cse_alife_space_restrictor {
864 public:
865 			cse_alife_level_changer();
866 	virtual void	state_read(xr_packet& packet, uint16_t size);
867 	virtual void	state_write(xr_packet& packet);
868 	virtual void	update_read(xr_packet& packet);
869 	virtual void	update_write(xr_packet& packet);
870 protected:
871 	uint16_t	m_next_graph_id;
872 	uint32_t	m_next_node_id;
873 	fvector3	m_next_position;
874 	fvector3	m_angles;
875 	std::string	m_level_to_change;
876 	std::string	m_level_point_to_change;
877 	bool		m_silent_mode;
878 };
879 
880 class cse_alife_custom_zone: public cse_alife_space_restrictor {
881 public:
882 			cse_alife_custom_zone();
883 	virtual void	state_merge(xr_packet& packet, uint16_t version);
884 	virtual void	state_read(xr_packet& packet, uint16_t size);
885 	virtual void	state_write(xr_packet& packet);
886 	virtual void	update_read(xr_packet& packet);
887 	virtual void	update_write(xr_packet& packet);
888 protected:
889 	float		m_max_power;
890 	uint32_t	m_owner_id;
891 	uint32_t	m_enabled_time;
892 	uint32_t	m_disabled_time;
893 	uint32_t	m_start_time_shift;
894 };
895 
896 class cse_alife_anomalous_zone: public cse_alife_custom_zone {
897 public:
898 			cse_alife_anomalous_zone();
899 	virtual void	state_merge(xr_packet& packet, uint16_t version);
900 	virtual void	state_read(xr_packet& packet, uint16_t size);
901 	virtual void	state_write(xr_packet& packet);
902 	virtual void	update_read(xr_packet& packet);
903 	virtual void	update_write(xr_packet& packet);
904 protected:
905 	float		m_offline_interactive_radius;
906 	uint32_t	m_artefact_position_offset;
907 	uint16_t	m_artefact_spawn_count;
908 };
909 
910 class cse_alife_zone_visual: public cse_alife_anomalous_zone, public cse_visual {
911 public:
912 	virtual void		state_read(xr_packet& packet, uint16_t size);
913 	virtual void		state_write(xr_packet& packet);
914 	virtual void		update_read(xr_packet& packet);
915 	virtual void		update_write(xr_packet& packet);
916 	virtual cse_visual*	visual();
917 protected:
918 	std::string		m_attack_animation;
919 };
920 
921 class cse_alife_torrid_zone: public cse_alife_custom_zone, public cse_motion {
922 public:
923 	virtual void		state_read(xr_packet& packet, uint16_t size);
924 	virtual void		state_write(xr_packet& packet);
925 	virtual void		update_read(xr_packet& packet);
926 	virtual void		update_write(xr_packet& packet);
927 	virtual cse_motion*	motion();
928 };
929 
930 
931 
932 class cse_alife_online_offline_group: public cse_alife_dynamic_object {
933 public:
934 	virtual void	state_read(xr_packet& packet, uint16_t size);
935 	virtual void	state_write(xr_packet& packet);
936 	virtual void	update_read(xr_packet& packet);
937 	virtual void	update_write(xr_packet& packet);
938 protected:
939 	std::vector<uint16_t>	m_members;
940 };
941 
942 class cse_alife_inventory_item {
943 public:
944 				cse_alife_inventory_item();
945 	virtual			~cse_alife_inventory_item();
946 	virtual void		state_read(xr_packet& packet, uint16_t size);
947 	virtual void		state_write(xr_packet& packet);
948 	virtual void		update_read(xr_packet& packet);
949 	virtual void		update_write(xr_packet& packet);
950 	virtual cse_abstract*	base() = 0;
951 	enum {
952 		FLAG_NO_POSITION = 0x8000,
953 	};
954 protected:
955 	float		m_condition;
956 	uint32_t	m_timestamp;
957 	uint16_t	m_num_items;
958 	ph_net_state	m_state;
959 
960 	// clear sky additions
961 	std::vector<std::string>	m_upgrades;
962 };
963 
964 class cse_alife_item: public cse_alife_dynamic_object_visual, public cse_alife_inventory_item {
965 public:
966 	virtual void		state_read(xr_packet& packet, uint16_t size);
967 	virtual void		state_write(xr_packet& packet);
968 	virtual void		update_read(xr_packet& packet);
969 	virtual void		update_write(xr_packet& packet);
970 	virtual cse_abstract*	base();
971 };
972 
973 class cse_alife_item_torch: public cse_alife_item {
974 public:
975 			cse_alife_item_torch();
976 	virtual void	state_read(xr_packet& packet, uint16_t size);
977 	virtual void	state_write(xr_packet& packet);
978 	virtual void	update_read(xr_packet& packet);
979 	virtual void	update_write(xr_packet& packet);
980 	enum {
981 		FL_TORCH_ACTIVE		= 0x01,
982 		FL_NIGHT_VISION_ACTIVE	= 0x02,
983 		FL_UNKNOWN		= 0x03,
984 	};
985 protected:
986 	bool		m_active;
987 	bool		m_nightvision_active;
988 	bool		m_unknown;
989 };
990 
991 class cse_alife_item_detector: public cse_alife_item {
992 public:
993 	virtual void	state_read(xr_packet& packet, uint16_t size);
994 	virtual void	state_write(xr_packet& packet);
995 	virtual void	update_read(xr_packet& packet);
996 	virtual void	update_write(xr_packet& packet);
997 };
998 
999 class cse_alife_item_artefact: public cse_alife_item {
1000 public:
1001 	virtual void	state_read(xr_packet& packet, uint16_t size);
1002 	virtual void	state_write(xr_packet& packet);
1003 	virtual void	update_read(xr_packet& packet);
1004 	virtual void	update_write(xr_packet& packet);
1005 };
1006 
1007 class cse_alife_item_grenade: public cse_alife_item {
1008 public:
1009 	virtual void	state_read(xr_packet& packet, uint16_t size);
1010 	virtual void	state_write(xr_packet& packet);
1011 	virtual void	update_read(xr_packet& packet);
1012 	virtual void	update_write(xr_packet& packet);
1013 };
1014 
1015 class cse_alife_item_explosive: public cse_alife_item {
1016 public:
1017 	virtual void	state_read(xr_packet& packet, uint16_t size);
1018 	virtual void	state_write(xr_packet& packet);
1019 	virtual void	update_read(xr_packet& packet);
1020 	virtual void	update_write(xr_packet& packet);
1021 };
1022 
1023 class cse_alife_item_bolt: public cse_alife_item {
1024 public:
1025 	virtual void	state_read(xr_packet& packet, uint16_t size);
1026 	virtual void	state_write(xr_packet& packet);
1027 	virtual void	update_read(xr_packet& packet);
1028 	virtual void	update_write(xr_packet& packet);
1029 };
1030 
1031 class cse_alife_item_helmet: public cse_alife_item {
1032 public:
1033 	virtual void	state_read(xr_packet& packet, uint16_t size);
1034 	virtual void	state_write(xr_packet& packet);
1035 	virtual void	update_read(xr_packet& packet);
1036 	virtual void	update_write(xr_packet& packet);
1037 };
1038 
1039 class cse_alife_item_custom_outfit: public cse_alife_item {
1040 public:
1041 	virtual void	state_read(xr_packet& packet, uint16_t size);
1042 	virtual void	state_write(xr_packet& packet);
1043 	virtual void	update_read(xr_packet& packet);
1044 	virtual void	update_write(xr_packet& packet);
1045 };
1046 
1047 class cse_alife_item_pda: public cse_alife_item {
1048 public:
1049 			cse_alife_item_pda();
1050 	virtual void	state_read(xr_packet& packet, uint16_t size);
1051 	virtual void	state_write(xr_packet& packet);
1052 	virtual void	update_read(xr_packet& packet);
1053 	virtual void	update_write(xr_packet& packet);
1054 protected:
1055 	uint16_t	m_original_owner;
1056 	std::string	m_specific_character;
1057 	std::string	m_info_portion;
1058 };
1059 
1060 class cse_alife_item_document: public cse_alife_item {
1061 public:
1062 	virtual void	state_read(xr_packet& packet, uint16_t size);
1063 	virtual void	state_write(xr_packet& packet);
1064 	virtual void	update_read(xr_packet& packet);
1065 	virtual void	update_write(xr_packet& packet);
1066 protected:
1067 	std::string	m_doc;
1068 };
1069 
1070 class cse_alife_item_ammo: public cse_alife_item {
1071 public:
1072 			cse_alife_item_ammo();
1073 	virtual void	state_read(xr_packet& packet, uint16_t size);
1074 	virtual void	state_write(xr_packet& packet);
1075 	virtual void	update_read(xr_packet& packet);
1076 	virtual void	update_write(xr_packet& packet);
1077 protected:
1078 	uint16_t	m_elapsed;
1079 };
1080 
1081 class cse_alife_item_weapon: public cse_alife_item {
1082 public:
1083 			cse_alife_item_weapon();
1084 	virtual void	state_read(xr_packet& packet, uint16_t size);
1085 	virtual void	state_write(xr_packet& packet);
1086 	virtual void	update_read(xr_packet& packet);
1087 	virtual void	update_write(xr_packet& packet);
1088 	enum addon_status {
1089 		ADDON_DISABLED	= 0,
1090 		ADDON_PERMANENT	= 1,
1091 		ADDON_ATTACHABLE= 2,
1092 	};
1093 protected:
1094 	addon_status	m_scope;
1095 	addon_status	m_silencer;
1096 	addon_status	m_grenade_launcher;
1097 	uint8_t		m_flags;
1098 	uint8_t		m_state;
1099 	uint8_t		m_ammo_type;
1100 	uint16_t	m_ammo_current;
1101 	uint16_t	m_ammo_elapsed;
1102 	uint8_t		m_addon_flags;
1103 // FIXME: see update_{read|write}() implementation
1104 //	bool		m_zoom;
1105 	uint8_t		m_zoom;
1106 
1107 	// clear sky addition
1108 	uint8_t		m_cs_unk1_u8;
1109 };
1110 
1111 class cse_alife_item_weapon_magazined: public cse_alife_item_weapon {
1112 public:
1113 			cse_alife_item_weapon_magazined();
1114 	virtual void	state_read(xr_packet& packet, uint16_t size);
1115 	virtual void	state_write(xr_packet& packet);
1116 	virtual void	update_read(xr_packet& packet);
1117 	virtual void	update_write(xr_packet& packet);
1118 protected:
1119 	uint8_t		m_cur_fire_mode;
1120 };
1121 
1122 class cse_alife_item_weapon_magazined_w_gl: public cse_alife_item_weapon_magazined {
1123 public:
1124 			cse_alife_item_weapon_magazined_w_gl();
1125 	virtual void	state_read(xr_packet& packet, uint16_t size);
1126 	virtual void	state_write(xr_packet& packet);
1127 	virtual void	update_read(xr_packet& packet);
1128 	virtual void	update_write(xr_packet& packet);
1129 protected:
1130 	bool		m_grenade_mode;
1131 };
1132 
1133 class cse_alife_item_weapon_shotgun: public cse_alife_item_weapon_magazined {
1134 public:
1135 	virtual void	state_read(xr_packet& packet, uint16_t size);
1136 	virtual void	state_write(xr_packet& packet);
1137 	virtual void	update_read(xr_packet& packet);
1138 	virtual void	update_write(xr_packet& packet);
1139 protected:
1140 	std::vector<uint8_t>	m_ammo_ids;
1141 };
1142 
1143 } // end of namespace xray_re
1144 
1145 #endif
1146