1 /*
2  * Copyright 2011-2012 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 // Code: Cyril Meynier
44 //
45 // Copyright (c) 1999 ARKANE Studios SA. All rights reserved
46 
47 #ifndef ARX_GAME_DAMAGE_H
48 #define ARX_GAME_DAMAGE_H
49 
50 #include <stddef.h>
51 
52 #include "math/MathFwd.h"
53 #include "math/Vector3.h"
54 #include "platform/Flags.h"
55 
56 class Entity;
57 
58 enum DamageTypeFlag {
59 	DAMAGE_TYPE_GENERIC    = 0,
60 	DAMAGE_TYPE_FIRE       = (1<<0),
61 	DAMAGE_TYPE_MAGICAL    = (1<<1),
62 	DAMAGE_TYPE_LIGHTNING  = (1<<2),
63 	DAMAGE_TYPE_COLD       = (1<<3),
64 	DAMAGE_TYPE_POISON     = (1<<4),
65 	DAMAGE_TYPE_GAS        = (1<<5),
66 	DAMAGE_TYPE_METAL      = (1<<6),
67 	DAMAGE_TYPE_WOOD       = (1<<7),
68 	DAMAGE_TYPE_STONE      = (1<<8),
69 	DAMAGE_TYPE_ACID       = (1<<9),
70 	DAMAGE_TYPE_ORGANIC    = (1<<10),
71 	DAMAGE_TYPE_PER_SECOND = (1<<11),
72 	DAMAGE_TYPE_DRAIN_LIFE = (1<<12),
73 	DAMAGE_TYPE_DRAIN_MANA = (1<<13),
74 	DAMAGE_TYPE_PUSH       = (1<<14),
75 	DAMAGE_TYPE_FAKEFIRE   = (1<<15),
76 	DAMAGE_TYPE_FIELD      = (1<<16),
77 	DAMAGE_TYPE_NO_FIX     = (1<<17)
78 };
79 DECLARE_FLAGS(DamageTypeFlag, DamageType)
80 DECLARE_FLAGS_OPERATORS(DamageType)
81 
82 enum DamageArea {
83 	DAMAGE_AREA = 0,
84 	DAMAGE_FULL = 1,
85 	DAMAGE_AREAHALF = 2
86 };
87 
88 enum DamageFlag {
89 	DAMAGE_FLAG_DONT_HURT_SOURCE = (1<<0),
90 	DAMAGE_FLAG_ADD_VISUAL_FX    = (1<<1), // depending on type
91 	DAMAGE_FLAG_FOLLOW_SOURCE    = (1<<2),
92 	DAMAGE_NOT_FRAME_DEPENDANT   = (1<<5),
93 	DAMAGE_SPAWN_BLOOD           = (1<<6)
94 };
95 DECLARE_FLAGS(DamageFlag, DamageFlags)
96 DECLARE_FLAGS_OPERATORS(DamageFlags)
97 
98 struct DAMAGE_INFO {
99 	short exist;
100 	short active;
101 	Vec3f pos;
102 	float damages;
103 	float radius;
104 	unsigned long start_time;
105 	short except[10];
106 	long duration;	// in milliseconds
107 	// -1 for apply once
108 	// else damage *=framediff
109 	long source; // io index or -1 for player
110 	DamageArea area; // damage area type
111 	DamageFlags flags; // damages flags
112 	DamageType type; // damages type
113 	long special; // slowdown, paralysis...
114 	long special_ID; // for io localised immunities or any other customization
115 	unsigned long lastupd;
116 };
117 
118 const size_t MAX_DAMAGES = 200;
119 
120 extern DAMAGE_INFO damages[MAX_DAMAGES];
121 
122 /*!
123  * mode=true ON mode=false  OFF
124  * flag & 1 no lights;
125  * flag & 2 Only affects small sources
126  */
127 void CheckForIgnition(Vec3f * pos, float radius, bool mode, long flag = 0);
128 
129 bool DoSphericDamage(Vec3f * pos, float dmg, float radius, DamageArea flags, DamageType typ = 0, long numsource = -1);
130 
131 void ARX_DAMAGE_Reset_Blood_Info();
132 void ARX_DAMAGE_Show_Hit_Blood();
133 void ARX_DAMAGES_Reset();
134 long ARX_DAMAGES_GetFree();
135 
136 void ARX_DAMAGES_UpdateAll();
137 float ARX_DAMAGES_DamagePlayer(float dmg, DamageType type, long source = -1);
138 void ARX_DAMAGES_DamageFIX(Entity * io, float dmg, long source = -1, long flags = 0);
139 float ARX_DAMAGES_DamageNPC(Entity * io, float dmg, long source = -1, long flags = 0, Vec3f * pos = NULL);
140 bool ARX_DAMAGES_TryToDoDamage(Vec3f * pos, float dmg, float radius, long source);
141 void ARX_DAMAGES_ForceDeath(Entity * io_dead, Entity * io_killer);
142 void ARX_DAMAGES_UpdateDamage(long j, float tim);
143 float ARX_DAMAGES_DealDamages(long target, float dmg, long source, DamageType flags, Vec3f * pos);
144 
145 void ARX_DAMAGES_HealInter(Entity * io, float dmg);
146 
147 void ARX_DAMAGES_DurabilityCheck(Entity * io, float ratio);
148 void ARX_DAMAGES_DurabilityLoss(Entity * io, float loss);
149 void ARX_DAMAGES_DurabilityRestore(Entity * io, float ratio);
150 void ARX_DAMAGES_DamagePlayerEquipment(float damages);
151 float ARX_DAMAGES_ComputeRepairPrice(Entity * torepair, Entity * blacksmith);
152 
153 #endif // ARX_GAME_DAMAGE_H
154