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