Go a bit through the mutators. Fix a bug with one, and note a big with another
[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 typeate ^7", s, GetAdvancedDeathReports(targ)));\r
371                                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typeeaten 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 typefragged ^7", s, GetAdvancedDeathReports(targ)));\r
387                                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typefragged 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                                         GiveFrags(attacker, targ, 1);\r
475 \r
476                                 if (targ.killcount > 2) {\r
477                                         if(sv_gentle)\r
478                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");\r
479                                         else\r
480                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");\r
481                                 }\r
482 \r
483                                 attacker.killcount = attacker.killcount + 1;\r
484 \r
485                                 if (attacker.killcount > 2) {\r
486                                         if(sv_gentle)\r
487                                                 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");\r
488                                         else\r
489                                                 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");\r
490                                 }\r
491 \r
492                                 LogDeath("frag", deathtype, attacker, targ);\r
493 \r
494                                 if (attacker.killcount == 3)\r
495                                 {\r
496                                         if(sv_gentle) {\r
497                                                 bprint (a,"^7 made a ^1TRIPLE SCORE\n");\r
498                                         } else {\r
499                                                 bprint (a,"^7 made a ^1TRIPLE FRAG\n");\r
500                                                 AnnounceTo(attacker, "03kills");\r
501                                         }\r
502                                 }\r
503                                 else if (attacker.killcount == 5)\r
504                                 {\r
505                                         if(sv_gentle) {\r
506                                                 bprint (a,"^7 unleashes ^1SCORING RAGE\n");\r
507                                         } else {\r
508                                                 bprint (a,"^7 unleashes ^1RAGE\n");\r
509                                                 AnnounceTo(attacker, "05kills");\r
510                                         }\r
511                                 }\r
512                                 else if (attacker.killcount == 10)\r
513                                 {\r
514                                         if(sv_gentle) {\r
515                                                 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");\r
516                                         } else {\r
517                                                 bprint (a,"^7 starts the ^1MASSACRE!\n");\r
518                                                 AnnounceTo(attacker, "10kills");\r
519                                         }\r
520                                 }\r
521                                 else if (attacker.killcount == 15)\r
522                                 {\r
523                                         if(sv_gentle) {\r
524                                                 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");\r
525                                         } else {\r
526                                                 bprint (a,"^7 executes ^1MAYHEM!\n");\r
527                                                 AnnounceTo(attacker, "15kills");\r
528                                         }\r
529                                 }\r
530                                 else if (attacker.killcount == 20)\r
531                                 {\r
532                                         if(sv_gentle) {\r
533                                                 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");\r
534                                         } else {\r
535                                                 bprint (a,"^7 is a ^1BERSERKER!\n");\r
536                                                 AnnounceTo(attacker, "20kills");\r
537                                         }\r
538                                 }\r
539                                 else if (attacker.killcount == 25)\r
540                                 {\r
541                                         if(sv_gentle) {\r
542                                                 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");\r
543                                         } else {\r
544                                                 bprint (a,"^7 inflicts ^1CARNAGE!\n");\r
545                                                 AnnounceTo(attacker, "25kills");\r
546                                         }\r
547                                 }\r
548                                 else if (attacker.killcount == 30)\r
549                                 {\r
550                                         if(sv_gentle) {\r
551                                                 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");\r
552                                         } else {\r
553                                                 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");\r
554                                                 AnnounceTo(attacker, "30kills");\r
555                                         }\r
556                                 }\r
557                         }\r
558                 }\r
559                 else\r
560                 {\r
561                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));\r
562                         if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")\r
563                                 bprint ("^1",s, "^1 ", inflictor.message, "\n");\r
564                         else if (deathtype == DEATH_DROWN)\r
565                                 if(sv_gentle)\r
566                                         bprint ("^1",s, "^1 was in the water for too long\n");\r
567                                 else\r
568                                         bprint ("^1",s, "^1 drowned\n");\r
569                         else if (deathtype == DEATH_SLIME)\r
570                                 bprint ("^1",s, "^1 was slimed\n");\r
571                         else if (deathtype == DEATH_LAVA)\r
572                                 if(sv_gentle)\r
573                                         bprint ("^1",s, "^1 found a hot place\n");\r
574                                 else\r
575                                         bprint ("^1",s, "^1 turned into hot slag\n");\r
576                         else if (deathtype == DEATH_FALL)\r
577                                 if(sv_gentle)\r
578                                         bprint ("^1",s, "^1 tested gravity (and it worked)\n");\r
579                                 else\r
580                                         bprint ("^1",s, "^1 hit the ground with a crunch\n");\r
581                         else if (deathtype == DEATH_SHOOTING_STAR)\r
582                                 bprint ("^1",s, "^1 became a shooting star\n");\r
583                         else if (deathtype == DEATH_SWAMP)\r
584                                 if(sv_gentle)\r
585                                         bprint ("^1",s, "^1 discovered a swamp\n");\r
586                                 else\r
587                                         bprint ("^1",s, "^1 is now conserved for centuries to come\n");\r
588                         else if(deathtype == DEATH_TURRET)\r
589                                 bprint ("^1",s, "^1 was mowed down by a turret \n");\r
590             else if (deathtype == DEATH_CUSTOM)\r
591                 bprint ("^1",s, "^1 ", deathmessage, "\n");\r
592                         else if(deathtype == DEATH_TOUCHEXPLODE)\r
593                                 bprint ("^1",s, "^1 died in an accident\n");\r
594                         else if(deathtype == DEATH_CHEAT)\r
595                                 bprint ("^1",s, "^1 was unfairly eliminated\n");\r
596                         else if(deathtype == DEATH_FIRE)\r
597                                 if(sv_gentle)\r
598                                         bprint ("^1",s, "^1 felt a little hot\n");\r
599                                 else\r
600                                         bprint ("^1",s, "^1 burnt to death\n");\r
601                         else\r
602                                 if(sv_gentle)\r
603                                         bprint ("^1",s, "^1 needs a restart\n");\r
604                                 else\r
605                                         bprint ("^1",s, "^1 died\n");\r
606                         GiveFrags(targ, targ, -1);\r
607                         if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {\r
608                                 AnnounceTo(targ, "botlike");\r
609                         }\r
610 \r
611                         if (targ.killcount > 2)\r
612                                 if(sv_gentle)\r
613                                         bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");\r
614                                 else\r
615                                         bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");\r
616 \r
617                         LogDeath("accident", deathtype, targ, targ);\r
618                 }\r
619 \r
620                 targ.death_origin = targ.origin;\r
621                 if(targ != attacker)\r
622                         targ.killer_origin = attacker.origin;\r
623 \r
624                 // FIXME: this should go in PutClientInServer\r
625                 if (targ.killcount)\r
626                         targ.killcount = 0;\r
627         }\r
628 }\r
629 \r
630 // these are updated by each Damage call for use in button triggering and such\r
631 entity damage_targ;\r
632 entity damage_inflictor;\r
633 entity damage_attacker;\r
634 \r
635 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)\r
636 {\r
637         float mirrordamage;\r
638         float mirrorforce;\r
639         float teamdamage0;\r
640         entity attacker_save;\r
641         mirrordamage = 0;\r
642         mirrorforce = 0;\r
643 \r
644         if (gameover || targ.killcount == -666)\r
645                 return;\r
646 \r
647         local entity oldself;\r
648         oldself = self;\r
649         self = targ;\r
650         damage_targ = targ;\r
651         damage_inflictor = inflictor;\r
652         damage_attacker = attacker;\r
653                 attacker_save = attacker;\r
654 \r
655         if(targ.classname == "player")\r
656                 if(targ.grabber)\r
657                         if(targ.grabber.aiment)\r
658                                 if(targ.grabber.aiment == attacker)\r
659                                         RemoveGrabber(targ); // STOP THAT, you parasite!\r
660 \r
661         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)\r
662         {\r
663                 // These are ALWAYS lethal\r
664                 // No damage modification here\r
665                 // Instead, prepare the victim for his death...\r
666                 targ.armorvalue = 0;\r
667                 targ.spawnshieldtime = 0;\r
668                 targ.health = 0.9; // this is < 1\r
669                 targ.flags -= targ.flags & FL_GODMODE;\r
670                 damage = 100000;\r
671         }\r
672         else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)\r
673         {\r
674                 // no processing\r
675         }\r
676         else\r
677         {\r
678                 if (targ.classname == "player")\r
679                 if (attacker.classname == "player")\r
680                 if (!targ.isbot)\r
681                 if (attacker.isbot)\r
682                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);\r
683 \r
684                 // nullify damage if teamplay is on\r
685                 if(deathtype != DEATH_TELEFRAG)\r
686                 if(attacker.classname == "player")\r
687                 {\r
688                         if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))\r
689                         {\r
690                                 damage = 0;\r
691                                 force = '0 0 0';\r
692                         }\r
693                         else if(attacker.team == targ.team)\r
694                         {\r
695                                 if(teamplay == 1)\r
696                                         damage = 0;\r
697                                 else if(attacker != targ)\r
698                                 {\r
699                                         if(teamplay == 3)\r
700                                                 damage = 0;\r
701                                         else if(teamplay == 4)\r
702                                         {\r
703                                                 if(targ.classname == "player" && targ.deadflag == DEAD_NO)\r
704                                                 {\r
705                                                         teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));\r
706                                                         attacker.dmg_team = attacker.dmg_team + damage;\r
707                                                         if(attacker.dmg_team > teamdamage0 && !g_ca)\r
708                                                                 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);\r
709                                                         mirrorforce = cvar("g_mirrordamage") * vlen(force);\r
710                                                         if(g_ca)\r
711                                                                 damage = 0;\r
712                                                         else\r
713                                                                 damage = cvar("g_friendlyfire") * damage;\r
714                                                         // mirrordamage will be used LATER\r
715                                                 }\r
716                                                 else\r
717                                                         damage = 0;\r
718                                         }\r
719                                 }\r
720                         }\r
721                 }\r
722 \r
723                 if(targ.classname == "player")\r
724                 if(attacker.classname == "player")\r
725                 if(attacker != targ)\r
726                 {\r
727                         targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");\r
728                         attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");\r
729                 }\r
730 \r
731                 if not(DEATH_ISSPECIAL(deathtype))\r
732                 {\r
733                         damage *= g_weapondamagefactor;\r
734                         mirrordamage *= g_weapondamagefactor;\r
735                         force = force * g_weaponforcefactor;\r
736                         mirrorforce *= g_weaponforcefactor;\r
737                 }\r
738 \r
739                 // apply strength multiplier\r
740                 if ((attacker.items & IT_STRENGTH))\r
741                 {\r
742                         if(targ == attacker)\r
743                         {\r
744                                 damage = damage * cvar("g_balance_powerup_strength_selfdamage");\r
745                                 force = force * cvar("g_balance_powerup_strength_selfforce");\r
746                         }\r
747                         else\r
748                         {\r
749                                 damage = damage * cvar("g_balance_powerup_strength_damage");\r
750                                 force = force * cvar("g_balance_powerup_strength_force");\r
751                         }\r
752                 }\r
753 \r
754                 // apply invincibility multiplier\r
755                 if (targ.items & IT_INVINCIBLE)\r
756                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");\r
757 \r
758                 if (targ == attacker)\r
759                 {\r
760                         if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))\r
761                                 damage = 0;\r
762                         else\r
763                                 damage = damage * cvar("g_balance_selfdamagepercent");  // Partial damage if the attacker hits himself\r
764                 }\r
765 \r
766                 // CTF: reduce damage/force\r
767                 if(g_ctf)\r
768                 if(targ == attacker)\r
769                 if(targ.flagcarried)\r
770                 {\r
771                         damage = damage * cvar("g_ctf_flagcarrier_selfdamage");\r
772                         force = force * cvar("g_ctf_flagcarrier_selfforce");\r
773                 }\r
774 \r
775                 // count the damage\r
776                 if(attacker)\r
777                 if(!targ.deadflag)\r
778                 if(targ.takedamage == DAMAGE_AIM)\r
779                 if(targ != attacker)\r
780                 {\r
781                         if(targ.classname == "player")\r
782                         {\r
783                                 // HEAD SHOT:\r
784                                 // find height of hit on player axis\r
785                                 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot\r
786                                 vector headmins, headmaxs, org;\r
787                                 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));\r
788                                 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
789                                 headmaxs = org + '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;\r
790                                 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))\r
791                                 {\r
792                                         deathtype |= HITTYPE_HEADSHOT;\r
793                                 }\r
794                         }\r
795                         else if(targ.classname == "turret_head")\r
796                         {\r
797                                 deathtype |= HITTYPE_HEADSHOT;\r
798                         }\r
799                         if(deathtype & HITTYPE_HEADSHOT)\r
800                                 damage *= 1 + damage_headshotbonus;\r
801 \r
802                         if(targ.classname == "player")\r
803                         {\r
804                                 if(IsDifferentTeam(targ, attacker))\r
805                                 {\r
806                                         if(damage > 0)\r
807                                         {\r
808                                                 if(targ.BUTTON_CHAT)\r
809                                                         attacker.typehitsound += 1;\r
810                                                 else\r
811                                                         attacker.hitsound += 1;\r
812 \r
813                                                 damage_goodhits += 1;\r
814                                                 damage_gooddamage += damage;\r
815 \r
816                                                 if not(DEATH_ISSPECIAL(deathtype))\r
817                                                 {\r
818                                                         if(IsFlying(targ))\r
819                                                                 yoda = 1;\r
820 \r
821                                                         if(deathtype & HITTYPE_HEADSHOT)\r
822                                                                 headshot = 1;\r
823                                                 }\r
824                                         }\r
825                                 }\r
826                                 else\r
827                                 {\r
828                                         if(deathtype != DEATH_FIRE)\r
829                                                 attacker.typehitsound += 1;\r
830                                         if(mirrordamage > 0)\r
831                                                 if(time > attacker.teamkill_complain)\r
832                                                 {\r
833                                                         attacker.teamkill_complain = time + 5;\r
834                                                         attacker.teamkill_soundtime = time + 0.4;\r
835                                                         attacker.teamkill_soundsource = targ;\r
836                                                 }\r
837                                 }\r
838                         }\r
839                 }\r
840         }\r
841 \r
842         // apply push\r
843         if (self.damageforcescale)\r
844         if (vlen(force))\r
845         if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)\r
846         {\r
847                 self.velocity = self.velocity + self.damageforcescale * force;\r
848                 self.flags &~= FL_ONGROUND;\r
849                 UpdateCSQCProjectile(self);\r
850         }\r
851         // apply damage\r
852         if (damage != 0 || (self.damageforcescale && vlen(force)))\r
853         if (self.event_damage)\r
854                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);\r
855         self = oldself;\r
856 \r
857         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)\r
858         {\r
859                 // Savage: vampire mode\r
860                 if (g_vampire)\r
861                 if (time >= self.spawnshieldtime)\r
862                 if (deathtype != DEATH_DIGESTION) // a different vampire system is used for this\r
863                 {\r
864                         attacker.health += damage;\r
865                 }\r
866         }\r
867 \r
868         // apply mirror damage if any\r
869         if(mirrordamage > 0 || mirrorforce > 0)\r
870         {\r
871                 attacker = attacker_save;\r
872                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;\r
873                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);\r
874         }\r
875 }\r
876 \r
877 vector NearestPointOnBox(entity box, vector org)\r
878 {\r
879         vector m1, m2, nearest;\r
880 \r
881         m1 = box.mins + box.origin;\r
882         m2 = box.maxs + box.origin;\r
883 \r
884         nearest_x = bound(m1_x, org_x, m2_x);\r
885         nearest_y = bound(m1_y, org_y, m2_y);\r
886         nearest_z = bound(m1_z, org_z, m2_z);\r
887 \r
888         return nearest;\r
889 }\r
890 \r
891 void Damage_RecordDamage(entity attacker, float deathtype, float damage)\r
892 {\r
893         float weaponid;\r
894         weaponid = DEATH_WEAPONOF(deathtype);\r
895 \r
896         if not(inWarmupStage)\r
897         if (weaponid)\r
898         if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {\r
899                 attacker.stats_hit[weaponid - 1] += damage;\r
900                 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);\r
901         }\r
902 }\r
903 \r
904 float RadiusDamage_running;\r
905 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)\r
906 // Returns total damage applies to creatures\r
907 {\r
908         entity  targ;\r
909         float   finaldmg;\r
910         float   power;\r
911         vector  blastorigin;\r
912         vector  force;\r
913         vector  diff;\r
914         vector  center;\r
915         vector  nearest;\r
916         float   total_damage_to_creatures;\r
917         entity  next;\r
918         float   tfloordmg;\r
919         float   tfloorforce;\r
920 \r
921         float stat_damagedone;\r
922         float stat_maxdamage;\r
923 \r
924         if(RadiusDamage_running)\r
925         {\r
926                 string save;\r
927                 print("RadiusDamage called recursively!\n");\r
928                 print("Expect stuff to go HORRIBLY wrong.\n");\r
929                 print("Causing a stack trace...\n");\r
930                 save = cvar_string("prvm_backtraceforwarnings");\r
931                 cvar_set("prvm_backtraceforwarnings", "1");\r
932                 fclose(-1); // calls VM_Warning\r
933                 cvar_set("prvm_backtraceforwarnings", save);\r
934                 return 0;\r
935         }\r
936 \r
937         RadiusDamage_running = 1;\r
938 \r
939         tfloordmg = cvar("g_throughfloor_damage");\r
940         tfloorforce = cvar("g_throughfloor_force");\r
941 \r
942         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);\r
943         total_damage_to_creatures = 0;\r
944 \r
945         if(deathtype != (WEP_GRABBER | HITTYPE_SECONDARY | HITTYPE_BOUNCE))\r
946         {\r
947                 force = inflictor.velocity;\r
948                 if(vlen(force) == 0)\r
949                         force = '0 0 -1';\r
950                 else\r
951                         force = normalize(force);\r
952                 if(forceintensity >= 0)\r
953                         Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);\r
954                 else\r
955                         Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);\r
956         }\r
957 \r
958         stat_damagedone = 0;\r
959         stat_maxdamage = 0;\r
960 \r
961         targ = WarpZone_FindRadius (blastorigin, rad, FALSE);\r
962         while (targ)\r
963         {\r
964                 next = targ.chain;\r
965                 if (targ != inflictor)\r
966                         if (ignore != targ) if(targ.takedamage)\r
967                         {\r
968                                 // LordHavoc: measure distance to nearest point on target (not origin)\r
969                                 // (this guarentees 100% damage on a touch impact)\r
970                                 nearest = targ.WarpZone_findradius_nearest;\r
971                                 diff = targ.WarpZone_findradius_dist;\r
972                                 // round up a little on the damage to ensure full damage on impacts\r
973                                 // and turn the distance into a fraction of the radius\r
974                                 power = 1 - ((vlen (diff) - 2) / rad);\r
975                                 //bprint(" ");\r
976                                 //bprint(ftos(power));\r
977                                 //if (targ == attacker)\r
978                                 //      print(ftos(power), "\n");\r
979                                 if (power > 0)\r
980                                 {\r
981                                         if (power > 1)\r
982                                                 power = 1;\r
983                                         finaldmg = coredamage * power + edgedamage * (1 - power);\r
984                                         if (finaldmg > 0)\r
985                                         {\r
986                                                 local float a;\r
987                                                 local float c;\r
988                                                 local float hits;\r
989                                                 local float total;\r
990                                                 local float hitratio;\r
991                                                 local vector hitloc;\r
992                                                 local vector myblastorigin;\r
993                                                 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);\r
994                                                 center = targ.origin + (targ.mins + targ.maxs) * 0.5;\r
995                                                 // if it's a player, use the view origin as reference\r
996                                                 if (targ.classname == "player")\r
997                                                         center = targ.origin + targ.view_ofs;\r
998                                                 force = normalize(center - myblastorigin);\r
999                                                 force = force * (finaldmg / coredamage) * forceintensity;\r
1000                                                 // test line of sight to multiple positions on box,\r
1001                                                 // and do damage if any of them hit\r
1002                                                 hits = 0;\r
1003                                                 if (targ.classname == "player")\r
1004                                                         total = ceil(bound(1, finaldmg, 50));\r
1005                                                 else\r
1006                                                         total = ceil(bound(1, finaldmg/10, 5));\r
1007                                                 hitloc = nearest;\r
1008                                                 c = 0;\r
1009                                                 while (c < total)\r
1010                                                 {\r
1011                                                         //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);\r
1012                                                         WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);\r
1013                                                         if (trace_fraction == 1 || trace_ent == targ)\r
1014                                                         {\r
1015                                                                 hits = hits + 1;\r
1016                                                                 if (hits > 1)\r
1017                                                                         hitloc = hitloc + nearest;\r
1018                                                                 else\r
1019                                                                         hitloc = nearest;\r
1020                                                         }\r
1021                                                         nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;\r
1022                                                         nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;\r
1023                                                         nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;\r
1024                                                         c = c + 1;\r
1025                                                 }\r
1026                                                 nearest = hitloc * (1 / max(1, hits));\r
1027                                                 hitratio = (hits / total);\r
1028                                                 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);\r
1029                                                 finaldmg = finaldmg * a;\r
1030                                                 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);\r
1031                                                 force = force * a;\r
1032                                                 //if (targ == attacker)\r
1033                                                 //{\r
1034                                                 //      print("hits ", ftos(hits), " / ", ftos(total));\r
1035                                                 //      print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));\r
1036                                                 //      print(" (", ftos(a), ")\n");\r
1037                                                 //}\r
1038                                                 if(hits || tfloordmg || tfloorforce)\r
1039                                                 {\r
1040                                                         if(targ.iscreature)\r
1041                                                         {\r
1042                                                                 total_damage_to_creatures += finaldmg;\r
1043 \r
1044                                                                 if(targ.flags & FL_CLIENT)\r
1045                                                                 if(targ.deadflag == DEAD_NO)\r
1046                                                                 if(targ != attacker)\r
1047                                                                 if(!teamplay || targ.team != attacker.team)\r
1048                                                                 {\r
1049                                                                         stat_damagedone += finaldmg;\r
1050                                                                         stat_maxdamage += coredamage;\r
1051                                                                 }\r
1052                                                         }\r
1053 \r
1054                                                         if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))\r
1055                                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);\r
1056                                                         else\r
1057                                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);\r
1058                                                 }\r
1059                                         }\r
1060                                 }\r
1061                         }\r
1062                 targ = next;\r
1063         }\r
1064 \r
1065         RadiusDamage_running = 0;\r
1066 \r
1067         Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));\r
1068 \r
1069         return total_damage_to_creatures;\r
1070 }\r
1071 \r
1072 .float fire_damagepersec;\r
1073 .float fire_endtime;\r
1074 .float fire_deathtype;\r
1075 .entity fire_owner;\r
1076 .float fire_hitsound;\r
1077 .entity fire_burner;\r
1078 \r
1079 void fireburner_think();\r
1080 \r
1081 float Fire_IsBurning(entity e)\r
1082 {\r
1083         return (time < e.fire_endtime);\r
1084 }\r
1085 \r
1086 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)\r
1087 {\r
1088         float dps;\r
1089         float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;\r
1090 \r
1091         if(e.classname == "player")\r
1092         {\r
1093                 if(e.deadflag)\r
1094                         return -1;\r
1095         }\r
1096         else\r
1097         {\r
1098                 if(!e.fire_burner)\r
1099                 {\r
1100                         // print("adding a fire burner to ", e.classname, "\n");\r
1101                         e.fire_burner = spawn();\r
1102                         e.fire_burner.classname = "fireburner";\r
1103                         e.fire_burner.think = fireburner_think;\r
1104                         e.fire_burner.nextthink = time;\r
1105                         e.fire_burner.owner = e;\r
1106                 }\r
1107         }\r
1108 \r
1109         t = max(t, 0.1);\r
1110         dps = d / t;\r
1111         if(Fire_IsBurning(e))\r
1112         {\r
1113                 mintime = e.fire_endtime - time;\r
1114                 maxtime = max(mintime, t);\r
1115 \r
1116                 mindps = e.fire_damagepersec;\r
1117                 maxdps = max(mindps, dps);\r
1118 \r
1119                 if(maxtime > mintime || maxdps > mindps)\r
1120                 {\r
1121                         mindamage = mindps * mintime;\r
1122                         maxdamage = mindamage + d;\r
1123 \r
1124                         // interval [mintime, maxtime] * [mindps, maxdps]\r
1125                         // intersected with\r
1126                         // [mindamage, maxdamage]\r
1127                         // maximum of this!\r
1128 \r
1129                         if(maxdamage >= maxtime * maxdps)\r
1130                         {\r
1131                                 totaltime = maxtime;\r
1132                                 totaldamage = maxtime * maxdps;\r
1133 \r
1134                                 // this branch increases totaldamage if either t > mintime, or dps > mindps\r
1135                         }\r
1136                         else\r
1137                         {\r
1138                                 // maxdamage is inside the interval!\r
1139                                 // first, try to use mindps; only if this fails, increase dps as needed\r
1140                                 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime\r
1141                                 totaldamage = maxdamage;\r
1142                                 // can totaldamage / totaltime be >= maxdps?\r
1143                                 // max(mindps, maxdamage / maxtime) >= maxdps?\r
1144                                 // we know maxdamage < maxtime * maxdps\r
1145                                 // so it cannot be\r
1146 \r
1147                                 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps\r
1148                         }\r
1149 \r
1150                         // total conditions for increasing:\r
1151                         //     maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage\r
1152                         // however:\r
1153                         //     if maxtime = mintime, maxdps = mindps\r
1154                         // then:\r
1155                         //     maxdamage = mindamage + d\r
1156                         //     mindamage = mindps * mintime = maxdps * maxtime < maxdamage!\r
1157                         // so the last condition is not needed\r
1158 \r
1159                         e.fire_damagepersec = totaldamage / totaltime;\r
1160                         e.fire_endtime = time + totaltime;\r
1161                         if(totaldamage > 1.2 * mindamage)\r
1162                         {\r
1163                                 e.fire_deathtype = dt;\r
1164                                 if(e.fire_owner != o)\r
1165                                 {\r
1166                                         e.fire_owner = o;\r
1167                                         e.fire_hitsound = FALSE;\r
1168                                 }\r
1169                         }\r
1170                         return max(0, totaldamage - mindamage); // can never be negative, but to make sure\r
1171                 }\r
1172                 else\r
1173                         return 0;\r
1174         }\r
1175         else\r
1176         {\r
1177                 e.fire_damagepersec = dps;\r
1178                 e.fire_endtime = time + t;\r
1179                 e.fire_deathtype = dt;\r
1180                 e.fire_owner = o;\r
1181                 e.fire_hitsound = FALSE;\r
1182                 return d;\r
1183         }\r
1184 }\r
1185 \r
1186 void Fire_ApplyDamage(entity e)\r
1187 {\r
1188         float t, d, hi, ty;\r
1189         entity o;\r
1190 \r
1191         if not(Fire_IsBurning(e))\r
1192                 return;\r
1193 \r
1194         o = e.owner;\r
1195         while(o.owner)\r
1196                 o = o.owner;\r
1197         if(clienttype(o) == CLIENTTYPE_NOTACLIENT)\r
1198                 o = e.fire_owner;\r
1199 \r
1200         // water and slime stop fire\r
1201         if(e.waterlevel)\r
1202         if(e.watertype != CONTENT_LAVA)\r
1203                 e.fire_endtime = 0;\r
1204 \r
1205         t = min(frametime, e.fire_endtime - time);\r
1206         d = e.fire_damagepersec * t;\r
1207 \r
1208         hi = e.fire_owner.hitsound;\r
1209         ty = e.fire_owner.typehitsound;\r
1210         Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');\r
1211         if(e.fire_hitsound && e.fire_owner)\r
1212         {\r
1213                 e.fire_owner.hitsound = hi;\r
1214                 e.fire_owner.typehitsound = ty;\r
1215         }\r
1216         e.fire_hitsound = TRUE;\r
1217 \r
1218         Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);\r
1219 \r
1220         if not(IS_INDEPENDENT_PLAYER(e))\r
1221         FOR_EACH_PLAYER(other) if(e != other)\r
1222         {\r
1223                 if(other.classname == "player")\r
1224                 if(other.deadflag == DEAD_NO)\r
1225                 if not(IS_INDEPENDENT_PLAYER(other))\r
1226                 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))\r
1227                 {\r
1228                         t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);\r
1229                         d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;\r
1230                         Fire_AddDamage(other, o, d, t, DEATH_FIRE);\r
1231                 }\r
1232         }\r
1233 }\r
1234 \r
1235 void Fire_ApplyEffect(entity e)\r
1236 {\r
1237         if(Fire_IsBurning(e))\r
1238                 e.effects |= EF_FLAME;\r
1239         else\r
1240                 e.effects &~= EF_FLAME;\r
1241 }\r
1242 \r
1243 void fireburner_think()\r
1244 {\r
1245         // for players, this is done in the regular loop\r
1246         if(wasfreed(self.owner))\r
1247         {\r
1248                 remove(self);\r
1249                 return;\r
1250         }\r
1251         Fire_ApplyEffect(self.owner);\r
1252         if(!Fire_IsBurning(self.owner))\r
1253         {\r
1254                 self.owner.fire_burner = world;\r
1255                 remove(self);\r
1256                 return;\r
1257         }\r
1258         Fire_ApplyDamage(self.owner);\r
1259         self.nextthink = time;\r
1260 }\r