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