1 /*
2  * Copyright 2011-2013 Arx Libertatis Team (see the AUTHORS file)
3  *
4  * This file is part of Arx Libertatis.
5  *
6  * Arx Libertatis is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Arx Libertatis is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Arx Libertatis.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 /* Based on:
20 ===========================================================================
21 ARX FATALIS GPL Source Code
22 Copyright (C) 1999-2010 Arkane Studios SA, a ZeniMax Media company.
23 
24 This file is part of the Arx Fatalis GPL Source Code ('Arx Fatalis Source Code').
25 
26 Arx Fatalis Source Code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
27 License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
28 
29 Arx Fatalis Source Code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
30 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
31 
32 You should have received a copy of the GNU General Public License along with Arx Fatalis Source Code.  If not, see
33 <http://www.gnu.org/licenses/>.
34 
35 In addition, the Arx Fatalis Source Code is also subject to certain additional terms. You should have received a copy of these
36 additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Arx
37 Fatalis Source Code. If not, please request a copy in writing from Arkane Studios at the address below.
38 
39 If you have questions concerning this license or the applicable additional terms, you may contact in writing Arkane Studios, c/o
40 ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
41 ===========================================================================
42 */
43 
44 #ifndef ARX_GAME_ENTITY_H
45 #define ARX_GAME_ENTITY_H
46 
47 #include <set>
48 #include <string>
49 #include <vector>
50 
51 #include "audio/AudioTypes.h"
52 #include "game/Damage.h" // TODO needed for DamageType
53 #include "game/Spells.h" // TODO needed for Spell, Rune, SpellcastFlags
54 #include "graphics/Color.h"
55 #include "graphics/BaseGraphicsTypes.h"
56 #include "io/resource/ResourcePath.h"
57 #include "math/Vector2.h"
58 #include "math/Vector3.h"
59 #include "math/Angle.h"
60 #include "platform/Flags.h"
61 #include "script/Script.h" // TODO remove this
62 
63 class TextureContainer;
64 struct ANIM_HANDLE;
65 struct ARX_PATH;
66 struct ARX_USE_PATH;
67 struct EERIE_3DOBJ;
68 struct INVENTORY_DATA;
69 struct IO_CAMDATA;
70 struct IO_FIXDATA;
71 struct IO_ITEMDATA;
72 struct IO_NPCDATA;
73 struct SYMBOL_DRAW;
74 struct TWEAK_INFO;
75 
76 #define MAX_ANIMS 200 // max loadable anims per character
77 #define MAX_ANIM_LAYERS 4
78 #define BASE_RUBBER 1.5f
79 
80 struct IO_PHYSICS {
81 	EERIE_CYLINDER cyl;
82 	Vec3f startpos;
83 	Vec3f targetpos;
84 	Vec3f velocity;
85 	Vec3f forces;
86 };
87 
88 struct ANIM_USE {
89 	ANIM_HANDLE * next_anim;
90 	ANIM_HANDLE * cur_anim;
91 	short altidx_next; // idx to alternate anims...
92 	short altidx_cur; // idx to alternate anims...
93 	long ctime;
94 	unsigned long flags;
95 	unsigned long nextflags;
96 	long lastframe;
97 	float pour;
98 	long fr;
99 };
100 
101 enum IOCollisionFlag {
102 	COLLIDE_WITH_PLAYER = (1<<0),
103 	COLLIDE_WITH_WORLD  = (1<<1)
104 };
105 DECLARE_FLAGS(IOCollisionFlag, IOCollisionFlags)
106 DECLARE_FLAGS_OPERATORS(IOCollisionFlags)
107 
108 enum ItemTypeFlag {
109 	OBJECT_TYPE_WEAPON   = (1<<0),
110 	OBJECT_TYPE_DAGGER   = (1<<1),
111 	OBJECT_TYPE_1H       = (1<<2),
112 	OBJECT_TYPE_2H       = (1<<3),
113 	OBJECT_TYPE_BOW      = (1<<4),
114 	OBJECT_TYPE_SHIELD   = (1<<5),
115 	OBJECT_TYPE_FOOD     = (1<<6),
116 	OBJECT_TYPE_GOLD     = (1<<7),
117 	OBJECT_TYPE_ARMOR    = (1<<8),
118 	OBJECT_TYPE_HELMET   = (1<<9),
119 	OBJECT_TYPE_RING     = (1<<10),
120 	OBJECT_TYPE_LEGGINGS = (1<<11)
121 };
122 DECLARE_FLAGS(ItemTypeFlag, ItemType)
123 DECLARE_FLAGS_OPERATORS(ItemType)
124 
125 enum HaloFlag {
126 	HALO_ACTIVE   = (1<<0),
127 	HALO_NEGATIVE = (1<<1),
128 	HALO_DYNLIGHT = (1<<2)
129 };
130 DECLARE_FLAGS(HaloFlag, HaloFlags)
131 DECLARE_FLAGS_OPERATORS(HaloFlags)
132 
133 struct IO_HALO {
134 	Color3f color;
135 	float radius;
136 	HaloFlags flags;
137 	long dynlight;
138 	Vec3f offset;
139 };
140 
141 struct IO_TWEAKER_INFO {
142 	res::path filename;
143 	std::string skintochange;
144 	res::path skinchangeto;
145 };
146 
147 struct IO_SPELLCAST_DATA {
148 	Spell castingspell; // spell being casted...
149 	Rune symb[4]; // symbols to draw before casting...
150 	SpellcastFlags spell_flags;
151 	short spell_level;
152 	long target;
153 	long duration;
154 };
155 
156 enum EntityFlag {
157 	IO_UNDERWATER          = (1<<0),
158 	IO_FREEZESCRIPT        = (1<<1),
159 	IO_ITEM                = (1<<2),
160 	IO_NPC                 = (1<<3),
161 	IO_FIX                 = (1<<4),
162 	IO_NOSHADOW            = (1<<5),
163 	IO_CAMERA              = (1<<6),
164 	IO_MARKER              = (1<<7),
165 	IO_ICONIC              = (1<<8),
166 	IO_NO_COLLISIONS       = (1<<9),
167 	IO_GOLD                = (1<<10),
168 	IO_INVULNERABILITY     = (1<<11),
169 	IO_NO_PHYSICS_INTERPOL = (1<<12),
170 	IO_HIT                 = (1<<13),
171 	IO_PHYSICAL_OFF        = (1<<14),
172 	IO_MOVABLE             = (1<<15),
173 	IO_UNIQUE              = (1<<16),
174 	IO_SHOP                = (1<<17),
175 	IO_BLACKSMITH          = (1<<18),
176 	IO_NOSAVE              = (1<<19),
177 	IO_FORCEDRAW           = (1<<20),
178 	IO_FIELD               = (1<<21),
179 	IO_BUMP                = (1<<22),
180 	IO_ANGULAR             = (1<<23),
181 	IO_BODY_CHUNK          = (1<<24),
182 	IO_ZMAP                = (1<<25),
183 	IO_INVERTED            = (1<<26),
184 	IO_JUST_COLLIDE        = (1<<27),
185 	IO_FIERY               = (1<<28),
186 	IO_NO_NPC_COLLIDE      = (1<<29),
187 	IO_CAN_COMBINE         = (1<<30)
188 };
189 DECLARE_FLAGS(EntityFlag, EntityFlags)
190 DECLARE_FLAGS_OPERATORS(EntityFlags)
191 
192 enum EntitySfxFlag {
193 	SFX_TYPE_YLSIDE_DEATH = (1<<0),
194 	SFX_TYPE_INCINERATE   = (1<<1)
195 };
196 DECLARE_FLAGS(EntitySfxFlag, EntitySfxFlags)
197 DECLARE_FLAGS_OPERATORS(EntitySfxFlags)
198 
199 // TODO 16-bit due to save format
200 enum GameFlag {
201 	GFLAG_INTERACTIVITY     = (1<<0),
202 	GFLAG_ISINTREATZONE     = (1<<1),
203 	GFLAG_WASINTREATZONE    = (1<<2),
204 	GFLAG_NEEDINIT          = (1<<3),
205 	GFLAG_INTERACTIVITYHIDE = (1<<4),
206 	GFLAG_DOOR              = (1<<5),
207 	GFLAG_INVISIBILITY      = (1<<6),
208 	GFLAG_NO_PHYS_IO_COL    = (1<<7),
209 	GFLAG_VIEW_BLOCKER      = (1<<8),
210 	GFLAG_PLATFORM          = (1<<9),
211 	GFLAG_ELEVATOR          = (1<<10),
212 	GFLAG_MEGAHIDE          = (1<<11),
213 	GFLAG_HIDEWEAPON        = (1<<12),
214 	GFLAG_NOGORE            = (1<<13),
215 	GFLAG_GOREEXPLODE       = (1<<14),
216 	GFLAG_NOCOMPUTATION     = (1<<15),
217 };
218 DECLARE_FLAGS(GameFlag, GameFlags)
219 DECLARE_FLAGS_OPERATORS(GameFlags)
220 
221 enum EntityVisilibity {
222 	SHOW_FLAG_NOT_DRAWN    = 0,
223 	SHOW_FLAG_IN_SCENE     = 1,
224 	SHOW_FLAG_LINKED       = 2,
225 	SHOW_FLAG_IN_INVENTORY = 4,
226 	SHOW_FLAG_HIDDEN       = 5,
227 	SHOW_FLAG_TELEPORTING  = 6,
228 	SHOW_FLAG_KILLED       = 7,
229 	SHOW_FLAG_MEGAHIDE     = 8,
230 	SHOW_FLAG_ON_PLAYER    = 9,
231 	SHOW_FLAG_DESTROYED    = 255
232 };
233 
234 class Entity {
235 
236 public:
237 
238 	explicit Entity(const res::path & classPath);
239 	~Entity();
240 
241 	EntityFlags ioflags; // IO type
242 	Vec3f lastpos; // IO last position
243 	Vec3f pos; // IO position
244 	Vec3f move;
245 	Vec3f lastmove;
246 	Vec3f forcedmove;
247 
248 	Anglef angle; // IO angle
249 	IO_PHYSICS physics;	// Movement Collision Data
250 	short room;
251 	short room_flags; // 1==need_update
252 	float original_height;
253 	float original_radius;
254 	TextureContainer * inv; // Object Icon
255 	EERIE_3DOBJ * obj; // IO Mesh data
256 	ANIM_HANDLE * anims[MAX_ANIMS]; // Object Animations
257 	ANIM_USE animlayer[MAX_ANIM_LAYERS];
258 	Vec3f * lastanimvertex; // Last Animation Positions of Vertex
259 	long nb_lastanimvertex;
260 	unsigned long lastanimtime;
261 
262 	EERIE_3D_BBOX bbox3D;
263 	Vec2s bbox1; // 2D bounding box1
264 	Vec2s bbox2; // 2D bounding box2
265 	res::path usemesh; // Alternate Mesh/path
266 	EERIE_3DOBJ * tweaky; // tweaked original obj backup
267 	audio::SourceId sound;
268 	ItemType type_flags; // object type (weapon,goblin...)
269 	long scriptload; // Is This object Loaded by Script ?
270 	Vec3f target; // Target position
271 	long targetinfo; // Target Type/Ident
272 
273 	// TODO remove and use inheritance instead
274 	union {
275 		IO_ITEMDATA * _itemdata; // ITEM Datas
276 		IO_FIXDATA * _fixdata; // FIX Datas
277 		IO_NPCDATA * _npcdata; // NPC Datas
278 		IO_CAMDATA * _camdata; // Camera Datas
279 	};
280 
281 	INVENTORY_DATA * inventory; // Inventory Data
282 	EntityVisilibity show; // Show status (in scene, in inventory...)
283 	IOCollisionFlags collision; // collision type
284 	std::string mainevent;
285 	Color3f infracolor; // Improve Vision Color (Heat)
286 	long changeanim;
287 
288 	long ident; // Ident num
289 	float weight;
290 	std::string locname; //localisation
291 	GameFlags gameFlags;
292 	Vec3f velocity; // velocity
293 	float fall;
294 
295 	long stopped;
296 	Vec3f initpos; // Initial Position
297 	Anglef initangle; // Initial Angle
298 	float scale;
299 
300 	ARX_USE_PATH * usepath;
301 	SYMBOL_DRAW * symboldraw;
302 	short dynlight;
303 	short lastspeechflag;
304 	ARX_PATH * inzone;
305 	IO_HALO halo;
306 	IO_HALO halo_native;
307 
308 	EERIE_SCRIPT script; // Primary Script
309 	EERIE_SCRIPT over_script; // Overriding Script
310 	short stat_count;
311 	short stat_sent;
312 	IO_TWEAKER_INFO * tweakerinfo; // optional tweaker infos
313 	Material material;
314 
315 	std::set<std::string> groups;
316 	char sizex; // Inventory Icon sizeX
317 	char sizey; // Inventory Icon sizeY
318 	unsigned long soundtime;
319 	unsigned long soundcount;
320 
321 	unsigned long sfx_time;
322 	unsigned long collide_door_time;
323 	unsigned long ouch_time;
324 	float dmg_sum;
325 
326 	IO_SPELLCAST_DATA spellcast_data;
327 	short flarecount;
328 	short no_collide;
329 	float invisibility;
330 	float frameloss;
331 	float basespeed;
332 
333 	float speed_modif;
334 	long * spells_on;
335 	short nb_spells_on;
336 	long damagedata;
337 
338 	float rubber;
339 	float max_durability;
340 	float durability;
341 	short poisonous;
342 	short poisonous_count;
343 
344 	float ignition;
345 	long ignit_light;
346 	audio::SampleId ignit_sound;
347 	float head_rot;
348 
349 	short damager_damages;
350 	DamageType damager_type;
351 	std::string stepmaterial;
352 	std::string armormaterial;
353 	std::string weaponmaterial;
354 	std::string strikespeech;
355 
356 	EntitySfxFlags sfx_flag;
357 	std::vector<TWEAK_INFO> tweaks;
358 	char secretvalue;
359 
360 	std::string shop_category;
361 	float shop_multiply;
362 	res::path inventory_skin;
363 	long isHit;
364 	short inzone_show;
365 	short summoner;
366 	long spark_n_blood;
367 
368 	/*!
369 	 * Return the short name for this Object where only the name
370 	 * of the file is returned
371 	 * @return The name of the file at the end of the filename path
372 	 */
373 	std::string short_name() const;
374 
375 	/*!
376 	 *  Returns the long name for this Object where the short name
377 	 * is combined with the identifying number
378 	 * in the form of "%s_%04ld"
379 	 * @return The short name combined with a 4 digit ident, padded with 0
380 	 */
381 	std::string long_name() const;
382 
383 	/*!
384 	 *  Returns the full name for this Object where the
385 	 * directory portion of the filename member is combined
386 	 * with the the result of long_name()
387 	 * @return The directory of filename + long_name()
388 	 */
389 	res::path full_name() const;
390 
391 	//! @return the index of this Entity in the EntityManager
index()392 	size_t index() const { return m_index; }
393 
394 	/*!
395 	 * Marks the entity as destroyed.
396 	 *
397 	 * If the entity was loaded by a script, the object is deleted.
398 	 * Otherwise the object is kept so that the id won't be reused.
399 	 */
400 	void destroy();
401 
402 	/*!
403 	 * Get the class path for this entity.
404 	 *
405 	 * @return the full path to this entity's class
406 	 */
classPath()407 	const res::path & classPath() const { return m_classPath; }
408 
409 private:
410 
411 	//! Remove any remaining references to this entity.
412 	void cleanReferences();
413 
414 	size_t m_index; //!< index of this Entity in the EntityManager
415 
416 	const res::path m_classPath; //!< the full path to this entity's class
417 
418 };
419 
420 // TODO move this somewhere else
421 struct IO_FIXDATA {
422 	char trapvalue;
423 	char padd[3];
424 };
425 
426 #endif // ARX_GAME_ENTITY_H
427