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