Damage offset for bots depending on skill. Needs to be balanced better
[voretournament/voretournament.git] / data / qcsrc / server / g_damage.qc
1 .float dmg;\r
2 .float dmg_edge;\r
3 .float dmg_force;\r
4 .float dmg_radius;\r
5 \r
6 float Damage_DamageInfo_SendEntity(entity to, float sf)\r
7 {\r
8         WriteByte(MSG_ENTITY, ENT_CLIENT_DAMAGEINFO);\r
9         WriteShort(MSG_ENTITY, self.projectiledeathtype);\r
10         WriteCoord(MSG_ENTITY, floor(self.origin_x));\r
11         WriteCoord(MSG_ENTITY, floor(self.origin_y));\r
12         WriteCoord(MSG_ENTITY, floor(self.origin_z));\r
13         WriteByte(MSG_ENTITY, bound(1, self.dmg, 255));\r
14         WriteByte(MSG_ENTITY, bound(0, self.dmg_radius, 255));\r
15         WriteByte(MSG_ENTITY, bound(1, self.dmg_edge, 255));\r
16         WriteShort(MSG_ENTITY, self.oldorigin_x);\r
17         return TRUE;\r
18 }\r
19 \r
20 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, entity dmgowner)\r
21 {\r
22         // TODO maybe call this from non-edgedamage too?\r
23         // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?\r
24 \r
25         entity e;\r
26 \r
27         if(!sound_allowed(MSG_BROADCAST, dmgowner))\r
28                 deathtype |= 0x8000;\r
29 \r
30         e = spawn();\r
31         setorigin(e, org);\r
32         e.projectiledeathtype = deathtype;\r
33         e.dmg = coredamage;\r
34         e.dmg_edge = edgedamage;\r
35         e.dmg_radius = rad;\r
36         e.dmg_force = vlen(force);\r
37         e.velocity = force;\r
38 \r
39         e.oldorigin_x = compressShortVector(e.velocity);\r
40 \r
41         Net_LinkEntity(e, FALSE, 0.2, Damage_DamageInfo_SendEntity);\r
42 }\r
43 \r
44 #define DAMAGE_CENTERPRINT_SPACER NEWLINES\r
45 \r
46 float checkrules_firstblood;\r
47 \r
48 float yoda;\r
49 float damage_goodhits;\r
50 float damage_gooddamage;\r
51 float headshot;\r
52 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use\r
53 \r
54 .float dmg_team;\r
55 .float teamkill_complain;\r
56 .float teamkill_soundtime;\r
57 .entity teamkill_soundsource;\r
58 .entity pusher;\r
59 \r
60 .float taunt_soundtime;\r
61 .float taunt_soundtype;\r
62 \r
63 void SetAutoTaunt(entity e, float t_soundtime, float t_soundtype)\r
64 {\r
65         e.taunt_soundtime = t_soundtime;\r
66         e.taunt_soundtype = t_soundtype;\r
67 }\r
68 \r
69 float IsDifferentTeam(entity a, entity b)\r
70 {\r
71         if(teams_matter)\r
72         {\r
73                 if(a.team == b.team)\r
74                         return 0;\r
75         }\r
76         else\r
77         {\r
78                 if(a == b)\r
79                         return 0;\r
80         }\r
81         return 1;\r
82 }\r
83 \r
84 float IsFlying(entity a)\r
85 {\r
86         if(a.flags & FL_ONGROUND)\r
87                 return 0;\r
88         if(a.waterlevel >= WATERLEVEL_SWIMMING)\r
89                 return 0;\r
90         traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);\r
91         if(trace_fraction < 1)\r
92                 return 0;\r
93         return 1;\r
94 }\r
95 \r
96 void UpdateFrags(entity player, float f)\r
97 {\r
98         PlayerTeamScore_AddScore(player, f);\r
99 }\r
100 \r
101 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it\r
102 void W_SwitchWeapon_Force(entity e, float w);\r
103 void GiveFrags (entity attacker, entity targ, float f)\r
104 {\r
105         // TODO route through PlayerScores instead\r
106         if(gameover) return;\r
107 \r
108         if(f < 0)\r
109         {\r
110                 if(targ == attacker)\r
111                 {\r
112                         // suicide\r
113                         PlayerScore_Add(attacker, SP_SUICIDES, 1);\r
114                 }\r
115                 else\r
116                 {\r
117                         // teamkill\r
118                         PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?\r
119                 }\r
120         }\r
121         else\r
122         {\r
123                 // regular frag\r
124                 PlayerScore_Add(attacker, SP_KILLS, 1);\r
125         }\r
126 \r
127         PlayerScore_Add(targ, SP_DEATHS, 1);\r
128 \r
129         if(g_arena || g_ca)\r
130                 if(cvar("g_arena_roundbased"))\r
131                         return;\r
132 \r
133         // FIXME fix the mess this is (we have REAL points now!)\r
134         if(g_keyhunt)\r
135         {\r
136                 f = kh_HandleFrags(attacker, targ, f);\r
137         }\r
138         else if(g_lms)\r
139         {\r
140                 // remove a life\r
141                 float tl;\r
142                 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);\r
143                 if(tl < lms_lowest_lives)\r
144                         lms_lowest_lives = tl;\r
145                 if(tl <= 0)\r
146                 {\r
147                         if(!lms_next_place)\r
148                                 lms_next_place = player_count;\r
149                         PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again\r
150                         --lms_next_place;\r
151                 }\r
152                 f = 0;\r
153         }\r
154         else if(g_ctf)\r
155         {\r
156                 if(g_ctf_ignore_frags)\r
157                         f = 0;\r
158         }\r
159 \r
160         attacker.totalfrags += f;\r
161 \r
162         if(f)\r
163                 UpdateFrags(attacker, f);\r
164 }\r
165 \r
166 string AppendItemcodes(string s, entity player)\r
167 {\r
168         float w;\r
169         w = player.weapon;\r
170         //if(w == 0)\r
171         //      w = player.switchweapon;\r
172         if(w == 0)\r
173                 w = player.cnt; // previous weapon!\r
174         s = strcat(s, ftos(w));\r
175         if(time < player.strength_finished)\r
176                 s = strcat(s, "S");\r
177         if(time < player.invincible_finished)\r
178                 s = strcat(s, "I");\r
179         if(player.flagcarried != world)\r
180                 s = strcat(s, "F");\r
181         if(player.BUTTON_CHAT)\r
182                 s = strcat(s, "T");\r
183         if(player.kh_next)\r
184                 s = strcat(s, "K");\r
185         return s;\r
186 }\r
187 \r
188 void LogDeath(string mode, float deathtype, entity killer, entity killed)\r
189 {\r
190         string s;\r
191         if(!cvar("sv_eventlog"))\r
192                 return;\r
193         s = strcat(":kill:", mode);\r
194         s = strcat(s, ":", ftos(killer.playerid));\r
195         s = strcat(s, ":", ftos(killed.playerid));\r
196         s = strcat(s, ":type=", ftos(deathtype));\r
197         s = strcat(s, ":items=");\r
198         s = AppendItemcodes(s, killer);\r
199         if(killed != killer)\r
200         {\r
201                 s = strcat(s, ":victimitems=");\r
202                 s = AppendItemcodes(s, killed);\r
203         }\r
204         GameLogEcho(s);\r
205 }\r
206 \r
207 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)\r
208 {\r
209         string  s, a;\r
210         float p, w;\r
211 \r
212         if (targ.classname == "player" || targ.classname == "corpse")\r
213         {\r
214                 if (targ.classname == "corpse")\r
215                         s = "A corpse";\r
216                 else\r
217                         s = targ.netname;\r
218 \r
219                 a = attacker.netname;\r
220 \r
221                 if (targ == attacker)\r
222                 {\r
223                         if (deathtype == DEATH_TEAMCHANGE) {\r
224                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));\r
225                         } else if (deathtype == DEATH_AUTOTEAMCHANGE) {\r
226                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));\r
227                                 return;\r
228                         } else if (deathtype == DEATH_CAMP) {\r
229                                 if(sv_gentle)\r
230                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));\r
231                                 else\r
232                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));\r
233                         } else if (deathtype == DEATH_NOAMMO) {\r
234                                 if(sv_gentle)\r
235                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));\r
236                                 else\r
237                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));\r
238                         } else if (deathtype == DEATH_ROT) {\r
239                                 if(sv_gentle)\r
240                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));\r
241                                 else\r
242                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));\r
243                         } else if (deathtype == DEATH_MIRRORDAMAGE) {\r
244                                 if(sv_gentle)\r
245                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));\r
246                                 else\r
247                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));\r
248                         } else if (deathtype == DEATH_QUIET) {\r
249                                 // do nothing\r
250                         } else {\r
251                                 if(sv_gentle)\r
252                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));\r
253                                 else\r
254                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));\r
255                         }\r
256                         if(sv_gentle) {\r
257                                 if (deathtype == DEATH_CAMP)\r
258                                         bprint ("^1",s, "^1 thought they found a nice camping ground\n");\r
259                                 else if (deathtype == DEATH_MIRRORDAMAGE)\r
260                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");\r
261                                 else\r
262                                         bprint ("^1",s, "^1 will be reinserted into the game due to their own actions\n");\r
263 \r
264                                 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)\r
265                                 {\r
266                                         LogDeath("suicide", deathtype, targ, targ);\r
267                                         GiveFrags(attacker, targ, -1);\r
268                                 }\r
269                                 if (targ.killcount > 2)\r
270                                         bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");\r
271                         } else {\r
272                                 w = DEATH_WEAPONOF(deathtype);\r
273                                 if(WEP_VALID(w))\r
274                                 {\r
275                                         w_deathtypestring = "couldn't resist the urge to self-destruct";\r
276                                         w_deathtype = deathtype;\r
277                                         weapon_action(w, WR_SUICIDEMESSAGE);\r
278                                         bprint("^1", s, "^1 ", w_deathtypestring, "\n");\r
279                                 }\r
280                                 else if (deathtype == DEATH_KILL)\r
281                                         bprint ("^1",s, "^1 couldn't take it anymore\n");\r
282                                 else if (deathtype == DEATH_ROT)\r
283                                         bprint ("^1",s, "^1 died\n");\r
284                                 else if (deathtype == DEATH_NOAMMO)\r
285                                         bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");\r
286                                 else if (deathtype == DEATH_CAMP)\r
287                                         bprint ("^1",s, "^1 thought they found a nice camping ground\n");\r
288                                 else if (deathtype == DEATH_MIRRORDAMAGE)\r
289                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");\r
290                                 else if (deathtype == DEATH_CHEAT)\r
291                                         bprint ("^1",s, "^1 unfairly eliminated themself\n");\r
292                                 else if (deathtype == DEATH_FIRE)\r
293                                         bprint ("^1",s, "^1 burned to death\n");\r
294                                 else if (deathtype == DEATH_DIGESTION)\r
295                                         bprint ("^1",s, "^1 was digested\n");\r
296                                 else if (deathtype == DEATH_REGURGITATION)\r
297                                         bprint ("^1",s, "^1 regurgitated to death\n");\r
298                                 else if (deathtype == DEATH_STOMACHKICK)\r
299                                         bprint ("^1",s, "^1 was ripped apart from the inside\n");\r
300                                 else if (deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)\r
301                                         bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");\r
302 \r
303                                 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)\r
304                                 {\r
305                                         LogDeath("suicide", deathtype, targ, targ);\r
306                                         GiveFrags(attacker, targ, -1);\r
307                                 }\r
308                                 if (targ.killcount > 2)\r
309                                         bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");\r
310                         }\r
311                 }\r
312                 else if (attacker.classname == "player" || attacker.classname == "gib")\r
313                 {\r
314                         if(teams_matter && attacker.team == targ.team)\r
315                         {\r
316                                 if (deathtype == DEATH_DIGESTION)\r
317                                 {\r
318                                         if(sv_gentle) {\r
319                                                 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Furfag! You made a meal out of a team mate!"));\r
320                                                 bprint ("^1", a, "^1 took action against a team mate\n");\r
321                                         } else {\r
322                                                 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Furfag! You ate ", s, ", a team mate!"));\r
323                                                 bprint ("^1", a, "^1 mows down a team mate\n");\r
324                                         }\r
325                                 }\r
326                                 else\r
327                                 {\r
328                                         if(sv_gentle) {\r
329                                                 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Furfag! You went against a team mate!"));\r
330                                                 bprint ("^1", a, "^1 took action against a team mate\n");\r
331                                         } else {\r
332                                                 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Furfag! You killed ", s, ", a team mate!"));\r
333                                                 bprint ("^1", a, "^1 murders a team mate\n");\r
334                                         }\r
335                                 }\r
336                                 GiveFrags(attacker, targ, -1);\r
337                                 if (targ.killcount > 2) {\r
338                                         if(sv_gentle)\r
339                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");\r
340                                         else\r
341                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");\r
342                                 }\r
343                                 if (attacker.killcount > 2) {\r
344                                         if(sv_gentle)\r
345                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");\r
346                                         else\r
347                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");\r
348                                 }\r
349                                 attacker.killcount = 0;\r
350 \r
351                                 LogDeath("tk", deathtype, attacker, targ);\r
352                         }\r
353                         else\r
354                         {\r
355                                 string blood_message, victim_message;\r
356                                 if (!checkrules_firstblood)\r
357                                 {\r
358                                         checkrules_firstblood = TRUE;\r
359                                         if(sv_gentle)\r
360                                         {\r
361                                                 bprint("^1",a, "^1 was the first to score", "\n");\r
362                                                 blood_message = "^1First point\n";\r
363                                                 //victim_message = "^1First victim\n";  // or First casualty\r
364                                         }\r
365                                         else\r
366                                         {\r
367                                                 bprint("^1",a, "^1 drew first blood", "\n");\r
368                                                 blood_message = "^1First blood\n";\r
369                                                 victim_message = "^1First victim\n";  // or First casualty\r
370                                         }\r
371                                 }\r
372                                 if (deathtype == DEATH_DIGESTION)\r
373                                 {\r
374                                         if(sv_gentle > 0) {\r
375                                                 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You made ^7", s, GetAdvancedDeathReports(targ), " ^4your meal"));\r
376                                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 made you their meal ^7", GetAdvancedDeathReports(attacker)));\r
377                                         } else {\r
378                                                 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {\r
379                                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^1You type-ate ^7", s, GetAdvancedDeathReports(targ)));\r
380                                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were type-eaten by ^7", a, GetAdvancedDeathReports(attacker)));\r
381                                                 } else {\r
382                                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You ate ^7", s, GetAdvancedDeathReports(targ)));\r
383                                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were eaten by ^7", a, GetAdvancedDeathReports(attacker)));\r
384                                                 }\r
385                                                 SetAutoTaunt(attacker, time + 1, TAUNTTYPE_DEATH);\r
386                                         }\r
387                                         portrait(attacker, targ);\r
388                                 }\r
389                                 else\r
390                                 {\r
391                                         if(sv_gentle > 0) {\r
392                                                 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You scored against ^7", s, GetAdvancedDeathReports(targ)));\r
393                                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7", GetAdvancedDeathReports(attacker)));\r
394                                         } else {\r
395                                                 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {\r
396                                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^1You type-ate ^7", s, GetAdvancedDeathReports(targ)));\r
397                                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were type-eaten by ^7", a, GetAdvancedDeathReports(attacker)));\r
398                                                 } else {\r
399                                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You killed ^7", s, GetAdvancedDeathReports(targ)));\r
400                                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were killed by ^7", a, GetAdvancedDeathReports(attacker)));\r
401                                                 }\r
402                                                 SetAutoTaunt(attacker, time + 1, TAUNTTYPE_DEATH);\r
403                                         }\r
404                                         portrait(attacker, targ);\r
405                                 }\r
406 \r
407                                 if(sv_gentle) {\r
408                                         bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");\r
409                                 } else {\r
410                                         w = DEATH_WEAPONOF(deathtype);\r
411                                         if(WEP_VALID(w))\r
412                                         {\r
413                                                 w_deathtypestring = "was blasted by";\r
414                                                 w_deathtype = deathtype;\r
415                                                 weapon_action(w, WR_KILLMESSAGE);\r
416                                                 p = strstrofs(w_deathtypestring, "#", 0);\r
417                                                 if(p < 0)\r
418                                                         bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");\r
419                                                 else\r
420                                                         bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");\r
421                                         }\r
422                                         else if (deathtype == DEATH_TELEFRAG)\r
423                                                 bprint ("^1",s, "^1 was telefragged by ", a, "\n");\r
424                                         else if (deathtype == DEATH_DROWN)\r
425                                                 bprint ("^1",s, "^1 was drowned by ", a, "\n");\r
426                                         else if (deathtype == DEATH_SLIME)\r
427                                                 bprint ("^1",s, "^1 was slimed by ", a, "\n");\r
428                                         else if (deathtype == DEATH_LAVA)\r
429                                                 bprint ("^1",s, "^1 was cooked by ", a, "\n");\r
430                                         else if (deathtype == DEATH_FALL)\r
431                                                 bprint ("^1",s, "^1 was grounded by ", a, "\n");\r
432                                         else if (deathtype == DEATH_SHOOTING_STAR)\r
433                                                 bprint ("^1",s, "^1 was shot into space by ", a, "\n");\r
434                                         else if (deathtype == DEATH_SWAMP)\r
435                                                 bprint ("^1",s, "^1 was conserved by ", a, "\n");\r
436                                         else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")\r
437                                         {\r
438                                                 p = strstrofs(inflictor.message2, "#", 0);\r
439                                                 if(p < 0)\r
440                                                         bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");\r
441                                                 else\r
442                                                         bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");\r
443                                         }\r
444                                         else if(deathtype == DEATH_SBCRUSH)\r
445                         bprint ("^1",s, "^1 was crushed by ^1", a, "\n");\r
446                                         else if(deathtype == DEATH_SBMINIGUN)\r
447                         bprint ("^1",s, "^1 got shredded by ^1", a, "\n");\r
448                                         else if(deathtype == DEATH_SBROCKET)\r
449                         bprint ("^1",s, "^1 was blased to bits by ^1", a, "\n");\r
450                                         else if(deathtype == DEATH_SBBLOWUP)\r
451                         bprint ("^1",s, "^1 got cought in the destruction of ^1", a, "'s vehicle\n");\r
452 \r
453                                         else if(deathtype == DEATH_WAKIGUN)\r
454                         bprint ("^1",s, "^1 was bolted down by ^1", a, "\n");\r
455                                         else if(deathtype == DEATH_WAKIROCKET)\r
456                         bprint ("^1",s, "^1 could find no shelter from ^1", a, "'s rockets\n");\r
457                                         else if(deathtype == DEATH_WAKIBLOWUP)\r
458                         bprint ("^1",s, "^1 dies when ^1", a, "'s wakizashi dies.\n");\r
459 \r
460                                         else if(deathtype == DEATH_TURRET)\r
461                                                 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");\r
462                                         else if(deathtype == DEATH_TOUCHEXPLODE)\r
463                                                 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");\r
464                                         else if(deathtype == DEATH_CHEAT)\r
465                                                 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");\r
466                                         else if (deathtype == DEATH_FIRE)\r
467                                                 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");\r
468                                         else if (deathtype == DEATH_DIGESTION)\r
469                                                 bprint ("^1",s, "^1 was digested by ^1", a, "\n");\r
470                                         else if (deathtype == DEATH_REGURGITATION)\r
471                                                 bprint ("^1",s, "^1 regurgitated to death due to ^1", a, "\n");\r
472                                         else if (deathtype == DEATH_STOMACHKICK)\r
473                                                 bprint ("^1",s, "^1 was ripped apart from the inside by ^1", a, "\n");\r
474                                         else if (deathtype == DEATH_CUSTOM)\r
475                                                 bprint ("^1",s, "^1 ", deathmessage, " by ^1", a, "\n");\r
476                                         else\r
477                                                 bprint ("^1",s, "^1 was fragged by ", a, "\n");\r
478                                 }\r
479 \r
480                                 if(g_ctf && targ.flagcarried)\r
481                                 {\r
482                                         UpdateFrags(attacker, ctf_score_value("score_kill"));\r
483                                         PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);\r
484                                         GiveFrags(attacker, targ, 0); // for logging\r
485                                 }\r
486                                 else\r
487                                 {\r
488                                         if(cvar("g_vore_reversescoring") && deathtype == DEATH_DIGESTION) // reversed vore scoring\r
489                                                 GiveFrags(targ, attacker, 1);\r
490                                         else\r
491                                                 GiveFrags(attacker, targ, 1);\r
492                                 }\r
493 \r
494                                 if (targ.killcount > 2) {\r
495                                         if(sv_gentle)\r
496                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");\r
497                                         else\r
498                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");\r
499                                 }\r
500 \r
501                                 attacker.killcount = attacker.killcount + 1;\r
502 \r
503                                 if (attacker.killcount > 2) {\r
504                                         if(sv_gentle)\r
505                                                 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");\r
506                                         else\r
507                                                 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");\r
508                                 }\r
509 \r
510                                 LogDeath("frag", deathtype, attacker, targ);\r
511 \r
512                                 if (attacker.killcount == 3)\r
513                                 {\r
514                                         if(sv_gentle) {\r
515                                                 bprint (a,"^7 made a ^1TRIPLE SCORE\n");\r
516                                         } else {\r
517                                                 bprint (a,"^7 made a ^1TRIPLE FRAG\n");\r
518                                                 AnnounceTo(attacker, "03kills");\r
519                                         }\r
520                                 }\r
521                                 else if (attacker.killcount == 5)\r
522                                 {\r
523                                         if(sv_gentle) {\r
524                                                 bprint (a,"^7 unleashes ^1SCORING RAGE\n");\r
525                                         } else {\r
526                                                 bprint (a,"^7 unleashes ^1RAGE\n");\r
527                                                 AnnounceTo(attacker, "05kills");\r
528                                         }\r
529                                 }\r
530                                 else if (attacker.killcount == 10)\r
531                                 {\r
532                                         if(sv_gentle) {\r
533                                                 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");\r
534                                         } else {\r
535                                                 bprint (a,"^7 starts the ^1MASSACRE!\n");\r
536                                                 AnnounceTo(attacker, "10kills");\r
537                                         }\r
538                                 }\r
539                                 else if (attacker.killcount == 15)\r
540                                 {\r
541                                         if(sv_gentle) {\r
542                                                 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");\r
543                                         } else {\r
544                                                 bprint (a,"^7 executes ^1MAYHEM!\n");\r
545                                                 AnnounceTo(attacker, "15kills");\r
546                                         }\r
547                                 }\r
548                                 else if (attacker.killcount == 20)\r
549                                 {\r
550                                         if(sv_gentle) {\r
551                                                 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");\r
552                                         } else {\r
553                                                 bprint (a,"^7 is a ^1BERSERKER!\n");\r
554                                                 AnnounceTo(attacker, "20kills");\r
555                                         }\r
556                                 }\r
557                                 else if (attacker.killcount == 25)\r
558                                 {\r
559                                         if(sv_gentle) {\r
560                                                 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");\r
561                                         } else {\r
562                                                 bprint (a,"^7 inflicts ^1CARNAGE!\n");\r
563                                                 AnnounceTo(attacker, "25kills");\r
564                                         }\r
565                                 }\r
566                                 else if (attacker.killcount == 30)\r
567                                 {\r
568                                         if(sv_gentle) {\r
569                                                 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");\r
570                                         } else {\r
571                                                 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");\r
572                                                 AnnounceTo(attacker, "30kills");\r
573                                         }\r
574                                 }\r
575                         }\r
576                 }\r
577                 else\r
578                 {\r
579                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));\r
580                         if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")\r
581                                 bprint ("^1",s, "^1 ", inflictor.message, "\n");\r
582                         else if (deathtype == DEATH_DROWN)\r
583                                 if(sv_gentle)\r
584                                         bprint ("^1",s, "^1 was in the water for too long\n");\r
585                                 else\r
586                                         bprint ("^1",s, "^1 drowned\n");\r
587                         else if (deathtype == DEATH_SLIME)\r
588                                 bprint ("^1",s, "^1 was slimed\n");\r
589                         else if (deathtype == DEATH_LAVA)\r
590                                 if(sv_gentle)\r
591                                         bprint ("^1",s, "^1 found a hot place\n");\r
592                                 else\r
593                                         bprint ("^1",s, "^1 turned into hot slag\n");\r
594                         else if (deathtype == DEATH_FALL)\r
595                                 if(sv_gentle)\r
596                                         bprint ("^1",s, "^1 tested gravity (and it worked)\n");\r
597                                 else\r
598                                         bprint ("^1",s, "^1 hit the ground with a crunch\n");\r
599                         else if (deathtype == DEATH_SHOOTING_STAR)\r
600                                 bprint ("^1",s, "^1 became a shooting star\n");\r
601                         else if (deathtype == DEATH_SWAMP)\r
602                                 if(sv_gentle)\r
603                                         bprint ("^1",s, "^1 discovered a swamp\n");\r
604                                 else\r
605                                         bprint ("^1",s, "^1 is now conserved for centuries to come\n");\r
606                         else if(deathtype == DEATH_TURRET)\r
607                                 bprint ("^1",s, "^1 was mowed down by a turret \n");\r
608             else if (deathtype == DEATH_CUSTOM)\r
609                 bprint ("^1",s, "^1 ", deathmessage, "\n");\r
610                         else if(deathtype == DEATH_TOUCHEXPLODE)\r
611                                 bprint ("^1",s, "^1 died in an accident\n");\r
612                         else if(deathtype == DEATH_CHEAT)\r
613                                 bprint ("^1",s, "^1 was unfairly eliminated\n");\r
614                         else if(deathtype == DEATH_FIRE)\r
615                                 if(sv_gentle)\r
616                                         bprint ("^1",s, "^1 felt a little hot\n");\r
617                                 else\r
618                                         bprint ("^1",s, "^1 burnt to death\n");\r
619                         else\r
620                                 if(sv_gentle)\r
621                                         bprint ("^1",s, "^1 needs a restart\n");\r
622                                 else\r
623                                         bprint ("^1",s, "^1 died\n");\r
624                         GiveFrags(targ, targ, -1);\r
625                         if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {\r
626                                 AnnounceTo(targ, "botlike");\r
627                         }\r
628 \r
629                         if (targ.killcount > 2)\r
630                                 if(sv_gentle)\r
631                                         bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");\r
632                                 else\r
633                                         bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");\r
634 \r
635                         LogDeath("accident", deathtype, targ, targ);\r
636                 }\r
637 \r
638                 // we lose all armor when we die\r
639                 targ.armorvalue = 0;\r
640 \r
641                 targ.death_origin = targ.origin;\r
642                 if(targ != attacker)\r
643                         targ.killer_origin = attacker.origin;\r
644 \r
645                 // FIXME: this should go in PutClientInServer\r
646                 if (targ.killcount)\r
647                         targ.killcount = 0;\r
648         }\r
649 }\r
650 \r
651 // these are updated by each Damage call for use in button triggering and such\r
652 entity damage_targ;\r
653 entity damage_inflictor;\r
654 entity damage_attacker;\r
655 \r
656 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)\r
657 {\r
658         float mirrordamage;\r
659         float mirrorforce;\r
660         float teamdamage0;\r
661         entity attacker_save;\r
662         mirrordamage = 0;\r
663         mirrorforce = 0;\r
664 \r
665         if (gameover || targ.killcount == -666)\r
666                 return;\r
667 \r
668         local entity oldself;\r
669         oldself = self;\r
670         self = targ;\r
671         damage_targ = targ;\r
672         damage_inflictor = inflictor;\r
673         damage_attacker = attacker;\r
674                 attacker_save = attacker;\r
675 \r
676         if(targ.classname == "player")\r
677                 if(targ.grabber)\r
678                         if(targ.grabber.aiment)\r
679                                 if(targ.grabber.aiment == attacker)\r
680                                         RemoveGrabber(targ); // STOP THAT, you parasite!\r
681 \r
682         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)\r
683         {\r
684                 // These are ALWAYS lethal\r
685                 // No damage modification here\r
686                 // Instead, prepare the victim for his death...\r
687                 targ.armorvalue = 0;\r
688                 targ.spawnshieldtime = 0;\r
689                 targ.health = 0.9; // this is < 1\r
690                 targ.flags -= targ.flags & FL_GODMODE;\r
691                 damage = 100000;\r
692         }\r
693         else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)\r
694         {\r
695                 // no processing\r
696         }\r
697         else\r
698         {\r
699                 if (targ.classname == "player")\r
700                 if (attacker.classname == "player")\r
701                 if (!targ.isbot)\r
702                 if (attacker.isbot)\r
703                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);\r
704 \r
705                 // if a predator is taking damage, check if he should regurgitate his prey, based on the damage he took\r
706                 if(cvar("g_balance_vore_escapeprobability"))\r
707                 if(targ.stomach_load && random() < cvar("g_balance_vore_escapeprobability") * damage)\r
708                         targ.regurgitate_prepare = -1;\r
709 \r
710                 // nullify damage if teamplay is on\r
711                 if(deathtype != DEATH_TELEFRAG)\r
712                 if(attacker.classname == "player")\r
713                 {\r
714                         if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))\r
715                         {\r
716                                 damage = 0;\r
717                                 force = '0 0 0';\r
718                         }\r
719                         else if(attacker.team == targ.team)\r
720                         {\r
721                                 if(teamplay == 1)\r
722                                         damage = 0;\r
723                                 else if(attacker != targ)\r
724                                 {\r
725                                         if(teamplay == 3)\r
726                                                 damage = 0;\r
727                                         else if(teamplay == 4)\r
728                                         {\r
729                                                 if(targ.classname == "player" && targ.deadflag == DEAD_NO)\r
730                                                 {\r
731                                                         teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));\r
732                                                         attacker.dmg_team = attacker.dmg_team + damage;\r
733                                                         if(attacker.dmg_team > teamdamage0 && !g_ca)\r
734                                                                 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);\r
735                                                         mirrorforce = cvar("g_mirrordamage") * vlen(force);\r
736                                                         if(g_ca)\r
737                                                                 damage = 0;\r
738                                                         else\r
739                                                                 damage = cvar("g_friendlyfire") * damage;\r
740                                                         // mirrordamage will be used LATER\r
741                                                 }\r
742                                                 else\r
743                                                         damage = 0;\r
744                                         }\r
745                                 }\r
746                         }\r
747                 }\r
748 \r
749                 if(targ.classname == "player")\r
750                 if(attacker.classname == "player")\r
751                 if(attacker != targ)\r
752                 {\r
753                         targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");\r
754                         attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");\r
755                 }\r
756 \r
757                 if not(DEATH_ISSPECIAL(deathtype))\r
758                 {\r
759                         damage *= g_weapondamagefactor;\r
760                         mirrordamage *= g_weapondamagefactor;\r
761                         force = force * g_weaponforcefactor;\r
762                         mirrorforce *= g_weaponforcefactor;\r
763                 }\r
764 \r
765                 // apply strength multiplier\r
766                 if ((attacker.items & IT_STRENGTH))\r
767                 {\r
768                         if(targ == attacker)\r
769                         {\r
770                                 damage = damage * cvar("g_balance_powerup_strength_selfdamage");\r
771                                 force = force * cvar("g_balance_powerup_strength_selfforce");\r
772                         }\r
773                         else\r
774                         {\r
775                                 damage = damage * cvar("g_balance_powerup_strength_damage");\r
776                                 force = force * cvar("g_balance_powerup_strength_force");\r
777                         }\r
778                 }\r
779 \r
780                 // apply invincibility multiplier\r
781                 if (targ.items & IT_INVINCIBLE)\r
782                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");\r
783 \r
784                 if (targ == attacker)\r
785                 {\r
786                         if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))\r
787                                 damage = 0;\r
788                         else\r
789                                 damage = damage * cvar("g_balance_selfdamagepercent");  // Partial damage if the attacker hits himself\r
790                 }\r
791 \r
792                 // CTF: reduce damage/force\r
793                 if(g_ctf)\r
794                 if(targ == attacker)\r
795                 if(targ.flagcarried)\r
796                 {\r
797                         damage = damage * cvar("g_ctf_flagcarrier_selfdamage");\r
798                         force = force * cvar("g_ctf_flagcarrier_selfforce");\r
799                 }\r
800 \r
801                 // skill-based damage offset for bots\r
802                 if(skill && cvar("skill_damage"))\r
803                 {\r
804                         float ofs;\r
805                         ofs = pow(skill / cvar("skill_damage_center"), cvar("skill_damage"));\r
806                         if(clienttype(attacker) == CLIENTTYPE_BOT)\r
807                                 damage *= ofs;\r
808                         if(clienttype(targ) == CLIENTTYPE_BOT)\r
809                                 damage /= ofs;\r
810 dprint(strcat(ftos(ofs), " --------\n"));\r
811                 }\r
812 \r
813                 // count the damage\r
814                 if(attacker)\r
815                 if(!targ.deadflag)\r
816                 if(targ.takedamage == DAMAGE_AIM)\r
817                 if(targ != attacker)\r
818                 {\r
819                         if(targ.classname == "player")\r
820                         {\r
821                                 // HEAD SHOT:\r
822                                 // find height of hit on player axis\r
823                                 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot\r
824                                 vector headmins, headmaxs, org;\r
825                                 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));\r
826                                 headmins = org + '0.6 0 0' * targ.mins_x + '0 0.6 0' * targ.mins_y + '0 0 1' * (1.3 * targ.view_ofs_z - 0.3 * targ.maxs_z);\r
827                                 headmaxs = org + '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;\r
828                                 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))\r
829                                 {\r
830                                         deathtype |= HITTYPE_HEADSHOT;\r
831                                 }\r
832                         }\r
833                         else if(targ.classname == "turret_head")\r
834                         {\r
835                                 deathtype |= HITTYPE_HEADSHOT;\r
836                         }\r
837                         if(deathtype & HITTYPE_HEADSHOT)\r
838                                 damage *= 1 + damage_headshotbonus;\r
839 \r
840                         if(targ.classname == "player")\r
841                         {\r
842                                 if(IsDifferentTeam(targ, attacker))\r
843                                 {\r
844                                         if(damage > 0)\r
845                                         {\r
846                                                 if(targ.BUTTON_CHAT)\r
847                                                         attacker.typehitsound += 1;\r
848                                                 else\r
849                                                         attacker.hitsound += 1;\r
850 \r
851                                                 damage_goodhits += 1;\r
852                                                 damage_gooddamage += damage;\r
853 \r
854                                                 if not(DEATH_ISSPECIAL(deathtype))\r
855                                                 {\r
856                                                         if(IsFlying(targ))\r
857                                                                 yoda = 1;\r
858 \r
859                                                         if(deathtype & HITTYPE_HEADSHOT)\r
860                                                                 headshot = 1;\r
861                                                 }\r
862                                         }\r
863                                 }\r
864                                 else\r
865                                 {\r
866                                         if(deathtype != DEATH_FIRE)\r
867                                                 attacker.typehitsound += 1;\r
868                                         if(time > attacker.teamkill_complain)\r
869                                         {\r
870                                                 attacker.teamkill_complain = time + 5;\r
871                                                 attacker.teamkill_soundtime = time + 0.4;\r
872                                                 attacker.teamkill_soundsource = targ;\r
873                                                 portrait(targ, attacker);\r
874                                         }\r
875                                 }\r
876                         }\r
877                 }\r
878 \r
879                 // lean the player based on the amount of damage taken\r
880                 if(cvar("g_leanplayer_damage"))\r
881                 if(targ.classname == "player" && WEP_VALID(DEATH_WEAPONOF(deathtype))) // only for damage caused by weapons\r
882                 {\r
883                         targ.leanangle_damage_loc = hitloc - targ.origin;\r
884                         targ.leanangle_damage_force += force * cvar("g_leanplayer_damage"); // keep existing force if any\r
885 \r
886                         // bound angles to the specified limit\r
887                         targ.leanangle_damage_force_x = bound(-cvar("g_leanplayer_damage_max"), targ.leanangle_damage_force_x, cvar("g_leanplayer_damage_max"));\r
888                         targ.leanangle_damage_force_y = bound(-cvar("g_leanplayer_damage_max"), targ.leanangle_damage_force_y, cvar("g_leanplayer_damage_max"));\r
889                         targ.leanangle_damage_force_z = bound(-cvar("g_leanplayer_damage_max"), targ.leanangle_damage_force_z, cvar("g_leanplayer_damage_max"));\r
890                 }\r
891         }\r
892 \r
893         // apply push\r
894         if (self.damageforcescale)\r
895         if (vlen(force))\r
896         if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)\r
897         {\r
898                 self.velocity = self.velocity + self.damageforcescale * force;\r
899                 self.flags &~= FL_ONGROUND;\r
900                 UpdateCSQCProjectile(self);\r
901         }\r
902         // apply damage\r
903         if (damage != 0 || (self.damageforcescale && vlen(force)))\r
904         if (self.event_damage)\r
905                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);\r
906         self = oldself;\r
907 \r
908         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)\r
909         {\r
910                 // Savage: vampire mode\r
911                 if (g_vampire)\r
912                 if (time >= self.spawnshieldtime)\r
913                 if (deathtype != DEATH_DIGESTION) // a different vampire system is used for this\r
914                 {\r
915                         attacker.health += damage;\r
916                 }\r
917         }\r
918 \r
919         // apply mirror damage if any\r
920         if(mirrordamage > 0 || mirrorforce > 0)\r
921         {\r
922                 attacker = attacker_save;\r
923                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;\r
924                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);\r
925         }\r
926 }\r
927 \r
928 vector NearestPointOnBox(entity box, vector org)\r
929 {\r
930         vector m1, m2, nearest;\r
931 \r
932         m1 = box.mins + box.origin;\r
933         m2 = box.maxs + box.origin;\r
934 \r
935         nearest_x = bound(m1_x, org_x, m2_x);\r
936         nearest_y = bound(m1_y, org_y, m2_y);\r
937         nearest_z = bound(m1_z, org_z, m2_z);\r
938 \r
939         return nearest;\r
940 }\r
941 \r
942 void Damage_RecordDamage(entity attacker, float deathtype, float damage)\r
943 {\r
944         float weaponid;\r
945         weaponid = DEATH_WEAPONOF(deathtype);\r
946 \r
947         if not(inWarmupStage)\r
948         if (weaponid)\r
949         if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {\r
950                 attacker.stats_hit[weaponid - 1] += damage;\r
951                 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);\r
952         }\r
953 }\r
954 \r
955 float RadiusDamage_running;\r
956 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)\r
957 // Returns total damage applies to creatures\r
958 {\r
959         entity  targ;\r
960         float   finaldmg;\r
961         float   power;\r
962         vector  blastorigin;\r
963         vector  force;\r
964         vector  diff;\r
965         vector  center;\r
966         vector  nearest;\r
967         float   total_damage_to_creatures;\r
968         entity  next;\r
969         float   tfloordmg;\r
970         float   tfloorforce;\r
971 \r
972         float stat_damagedone;\r
973         float stat_maxdamage;\r
974 \r
975         if(RadiusDamage_running)\r
976         {\r
977                 string save;\r
978                 print("RadiusDamage called recursively!\n");\r
979                 print("Expect stuff to go HORRIBLY wrong.\n");\r
980                 print("Causing a stack trace...\n");\r
981                 save = cvar_string("prvm_backtraceforwarnings");\r
982                 cvar_set("prvm_backtraceforwarnings", "1");\r
983                 fclose(-1); // calls VM_Warning\r
984                 cvar_set("prvm_backtraceforwarnings", save);\r
985                 return 0;\r
986         }\r
987 \r
988         RadiusDamage_running = 1;\r
989 \r
990         tfloordmg = cvar("g_throughfloor_damage");\r
991         tfloorforce = cvar("g_throughfloor_force");\r
992 \r
993         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);\r
994         total_damage_to_creatures = 0;\r
995 \r
996         if(deathtype != (WEP_GRABBER | HITTYPE_SECONDARY | HITTYPE_BOUNCE))\r
997         {\r
998                 force = inflictor.velocity;\r
999                 if(vlen(force) == 0)\r
1000                         force = '0 0 -1';\r
1001                 else\r
1002                         force = normalize(force);\r
1003                 if(forceintensity >= 0)\r
1004                         Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);\r
1005                 else\r
1006                         Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);\r
1007         }\r
1008 \r
1009         stat_damagedone = 0;\r
1010         stat_maxdamage = 0;\r
1011 \r
1012         targ = WarpZone_FindRadius (blastorigin, rad, FALSE);\r
1013         while (targ)\r
1014         {\r
1015                 next = targ.chain;\r
1016                 if (targ != inflictor)\r
1017                         if (ignore != targ) if(targ.takedamage)\r
1018                         {\r
1019                                 // LordHavoc: measure distance to nearest point on target (not origin)\r
1020                                 // (this guarentees 100% damage on a touch impact)\r
1021                                 nearest = targ.WarpZone_findradius_nearest;\r
1022                                 diff = targ.WarpZone_findradius_dist;\r
1023                                 // round up a little on the damage to ensure full damage on impacts\r
1024                                 // and turn the distance into a fraction of the radius\r
1025                                 power = 1 - ((vlen (diff) - 2) / rad);\r
1026                                 //bprint(" ");\r
1027                                 //bprint(ftos(power));\r
1028                                 //if (targ == attacker)\r
1029                                 //      print(ftos(power), "\n");\r
1030                                 if (power > 0)\r
1031                                 {\r
1032                                         if (power > 1)\r
1033                                                 power = 1;\r
1034                                         finaldmg = coredamage * power + edgedamage * (1 - power);\r
1035                                         if (finaldmg > 0)\r
1036                                         {\r
1037                                                 local float a;\r
1038                                                 local float c;\r
1039                                                 local float hits;\r
1040                                                 local float total;\r
1041                                                 local float hitratio;\r
1042                                                 local vector hitloc;\r
1043                                                 local vector myblastorigin;\r
1044                                                 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);\r
1045                                                 center = targ.origin + (targ.mins + targ.maxs) * 0.5;\r
1046                                                 // if it's a player, use the view origin as reference\r
1047                                                 if (targ.classname == "player")\r
1048                                                         center = targ.origin + targ.view_ofs;\r
1049                                                 force = normalize(center - myblastorigin);\r
1050                                                 force = force * (finaldmg / coredamage) * forceintensity;\r
1051                                                 // test line of sight to multiple positions on box,\r
1052                                                 // and do damage if any of them hit\r
1053                                                 hits = 0;\r
1054                                                 if (targ.classname == "player")\r
1055                                                         total = ceil(bound(1, finaldmg, 50));\r
1056                                                 else\r
1057                                                         total = ceil(bound(1, finaldmg/10, 5));\r
1058                                                 hitloc = nearest;\r
1059                                                 c = 0;\r
1060                                                 while (c < total)\r
1061                                                 {\r
1062                                                         //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);\r
1063                                                         WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);\r
1064                                                         if (trace_fraction == 1 || trace_ent == targ)\r
1065                                                         {\r
1066                                                                 hits = hits + 1;\r
1067                                                                 if (hits > 1)\r
1068                                                                         hitloc = hitloc + nearest;\r
1069                                                                 else\r
1070                                                                         hitloc = nearest;\r
1071                                                         }\r
1072                                                         nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;\r
1073                                                         nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;\r
1074                                                         nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;\r
1075                                                         c = c + 1;\r
1076                                                 }\r
1077                                                 nearest = hitloc * (1 / max(1, hits));\r
1078                                                 hitratio = (hits / total);\r
1079                                                 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);\r
1080                                                 finaldmg = finaldmg * a;\r
1081                                                 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);\r
1082                                                 force = force * a;\r
1083                                                 //if (targ == attacker)\r
1084                                                 //{\r
1085                                                 //      print("hits ", ftos(hits), " / ", ftos(total));\r
1086                                                 //      print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));\r
1087                                                 //      print(" (", ftos(a), ")\n");\r
1088                                                 //}\r
1089                                                 if(hits || tfloordmg || tfloorforce)\r
1090                                                 {\r
1091                                                         if(targ.iscreature)\r
1092                                                         {\r
1093                                                                 total_damage_to_creatures += finaldmg;\r
1094 \r
1095                                                                 if(targ.flags & FL_CLIENT)\r
1096                                                                 if(targ.deadflag == DEAD_NO)\r
1097                                                                 if(targ != attacker)\r
1098                                                                 if(!teamplay || targ.team != attacker.team)\r
1099                                                                 {\r
1100                                                                         stat_damagedone += finaldmg;\r
1101                                                                         stat_maxdamage += coredamage;\r
1102                                                                 }\r
1103                                                         }\r
1104 \r
1105                                                         if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))\r
1106                                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);\r
1107                                                         else\r
1108                                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);\r
1109                                                 }\r
1110                                         }\r
1111                                 }\r
1112                         }\r
1113                 targ = next;\r
1114         }\r
1115 \r
1116         RadiusDamage_running = 0;\r
1117 \r
1118         Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));\r
1119 \r
1120         return total_damage_to_creatures;\r
1121 }\r
1122 \r
1123 .float fire_damagepersec;\r
1124 .float fire_endtime;\r
1125 .float fire_deathtype;\r
1126 .entity fire_owner;\r
1127 .float fire_hitsound;\r
1128 .entity fire_burner;\r
1129 \r
1130 void fireburner_think();\r
1131 \r
1132 float Fire_IsBurning(entity e)\r
1133 {\r
1134         return (time < e.fire_endtime);\r
1135 }\r
1136 \r
1137 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)\r
1138 {\r
1139         float dps;\r
1140         float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;\r
1141 \r
1142         if(e.classname == "player")\r
1143         {\r
1144                 if(e.deadflag)\r
1145                         return -1;\r
1146         }\r
1147         else\r
1148         {\r
1149                 if(!e.fire_burner)\r
1150                 {\r
1151                         // print("adding a fire burner to ", e.classname, "\n");\r
1152                         e.fire_burner = spawn();\r
1153                         e.fire_burner.classname = "fireburner";\r
1154                         e.fire_burner.think = fireburner_think;\r
1155                         e.fire_burner.nextthink = time;\r
1156                         e.fire_burner.owner = e;\r
1157                 }\r
1158         }\r
1159 \r
1160         t = max(t, 0.1);\r
1161         dps = d / t;\r
1162         if(Fire_IsBurning(e))\r
1163         {\r
1164                 mintime = e.fire_endtime - time;\r
1165                 maxtime = max(mintime, t);\r
1166 \r
1167                 mindps = e.fire_damagepersec;\r
1168                 maxdps = max(mindps, dps);\r
1169 \r
1170                 if(maxtime > mintime || maxdps > mindps)\r
1171                 {\r
1172                         mindamage = mindps * mintime;\r
1173                         maxdamage = mindamage + d;\r
1174 \r
1175                         // interval [mintime, maxtime] * [mindps, maxdps]\r
1176                         // intersected with\r
1177                         // [mindamage, maxdamage]\r
1178                         // maximum of this!\r
1179 \r
1180                         if(maxdamage >= maxtime * maxdps)\r
1181                         {\r
1182                                 totaltime = maxtime;\r
1183                                 totaldamage = maxtime * maxdps;\r
1184 \r
1185                                 // this branch increases totaldamage if either t > mintime, or dps > mindps\r
1186                         }\r
1187                         else\r
1188                         {\r
1189                                 // maxdamage is inside the interval!\r
1190                                 // first, try to use mindps; only if this fails, increase dps as needed\r
1191                                 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime\r
1192                                 totaldamage = maxdamage;\r
1193                                 // can totaldamage / totaltime be >= maxdps?\r
1194                                 // max(mindps, maxdamage / maxtime) >= maxdps?\r
1195                                 // we know maxdamage < maxtime * maxdps\r
1196                                 // so it cannot be\r
1197 \r
1198                                 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps\r
1199                         }\r
1200 \r
1201                         // total conditions for increasing:\r
1202                         //     maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage\r
1203                         // however:\r
1204                         //     if maxtime = mintime, maxdps = mindps\r
1205                         // then:\r
1206                         //     maxdamage = mindamage + d\r
1207                         //     mindamage = mindps * mintime = maxdps * maxtime < maxdamage!\r
1208                         // so the last condition is not needed\r
1209 \r
1210                         e.fire_damagepersec = totaldamage / totaltime;\r
1211                         e.fire_endtime = time + totaltime;\r
1212                         if(totaldamage > 1.2 * mindamage)\r
1213                         {\r
1214                                 e.fire_deathtype = dt;\r
1215                                 if(e.fire_owner != o)\r
1216                                 {\r
1217                                         e.fire_owner = o;\r
1218                                         e.fire_hitsound = FALSE;\r
1219                                 }\r
1220                         }\r
1221                         return max(0, totaldamage - mindamage); // can never be negative, but to make sure\r
1222                 }\r
1223                 else\r
1224                         return 0;\r
1225         }\r
1226         else\r
1227         {\r
1228                 e.fire_damagepersec = dps;\r
1229                 e.fire_endtime = time + t;\r
1230                 e.fire_deathtype = dt;\r
1231                 e.fire_owner = o;\r
1232                 e.fire_hitsound = FALSE;\r
1233                 return d;\r
1234         }\r
1235 }\r
1236 \r
1237 void Fire_ApplyDamage(entity e)\r
1238 {\r
1239         float t, d, hi, ty;\r
1240         entity o;\r
1241 \r
1242         if not(Fire_IsBurning(e))\r
1243                 return;\r
1244 \r
1245         o = e.owner;\r
1246         while(o.owner)\r
1247                 o = o.owner;\r
1248         if(clienttype(o) == CLIENTTYPE_NOTACLIENT)\r
1249                 o = e.fire_owner;\r
1250 \r
1251         // water and slime stop fire\r
1252         if(e.waterlevel)\r
1253         if(e.watertype != CONTENT_LAVA)\r
1254                 e.fire_endtime = 0;\r
1255 \r
1256         t = min(frametime, e.fire_endtime - time);\r
1257         d = e.fire_damagepersec * t;\r
1258 \r
1259         hi = e.fire_owner.hitsound;\r
1260         ty = e.fire_owner.typehitsound;\r
1261         Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');\r
1262         if(e.fire_hitsound && e.fire_owner)\r
1263         {\r
1264                 e.fire_owner.hitsound = hi;\r
1265                 e.fire_owner.typehitsound = ty;\r
1266         }\r
1267         e.fire_hitsound = TRUE;\r
1268 \r
1269         Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);\r
1270 \r
1271         if not(IS_INDEPENDENT_PLAYER(e))\r
1272         FOR_EACH_PLAYER(other) if(e != other)\r
1273         {\r
1274                 if(other.classname == "player")\r
1275                 if(other.deadflag == DEAD_NO)\r
1276                 if not(IS_INDEPENDENT_PLAYER(other))\r
1277                 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))\r
1278                 {\r
1279                         t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);\r
1280                         d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;\r
1281                         Fire_AddDamage(other, o, d, t, DEATH_FIRE);\r
1282                 }\r
1283         }\r
1284 }\r
1285 \r
1286 void Fire_ApplyEffect(entity e)\r
1287 {\r
1288         if(Fire_IsBurning(e))\r
1289                 e.effects |= EF_FLAME;\r
1290         else\r
1291                 e.effects &~= EF_FLAME;\r
1292 }\r
1293 \r
1294 void fireburner_think()\r
1295 {\r
1296         // for players, this is done in the regular loop\r
1297         if(wasfreed(self.owner))\r
1298         {\r
1299                 remove(self);\r
1300                 return;\r
1301         }\r
1302         Fire_ApplyEffect(self.owner);\r
1303         if(!Fire_IsBurning(self.owner))\r
1304         {\r
1305                 self.owner.fire_burner = world;\r
1306                 remove(self);\r
1307                 return;\r
1308         }\r
1309         Fire_ApplyDamage(self.owner);\r
1310         self.nextthink = time;\r
1311 }\r