]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_damage.qc
tuba: don't hurt team mates, they have ear plugs matching your team's tubas ;)
[divverent/nexuiz.git] / data / qcsrc / server / g_damage.qc
1 .float dmg;
2 .float dmg_edge;
3 .float dmg_force;
4 .float dmg_radius;
5
6 float Damage_DamageInfo_SendEntity(entity to, float sf)
7 {
8         WriteByte(MSG_ENTITY, ENT_CLIENT_DAMAGEINFO);
9         WriteShort(MSG_ENTITY, self.projectiledeathtype);
10         WriteCoord(MSG_ENTITY, floor(self.origin_x));
11         WriteCoord(MSG_ENTITY, floor(self.origin_y));
12         WriteCoord(MSG_ENTITY, floor(self.origin_z));
13         WriteByte(MSG_ENTITY, bound(1, self.dmg, 255));
14         WriteByte(MSG_ENTITY, bound(0, self.dmg_radius, 255));
15         WriteByte(MSG_ENTITY, bound(1, self.dmg_edge, 255));
16         WriteShort(MSG_ENTITY, self.oldorigin_x);
17         return TRUE;
18 }
19
20 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype)
21 {
22         // TODO maybe call this from non-edgedamage too?
23         // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
24
25         entity e;
26
27         e = spawn();
28         setorigin(e, org);
29         e.projectiledeathtype = deathtype;
30         e.dmg = coredamage;
31         e.dmg_edge = edgedamage;
32         e.dmg_radius = rad;
33         e.dmg_force = vlen(force);
34         e.velocity = force;
35
36         e.oldorigin_x = compressShortVector(e.velocity);
37
38         Net_LinkEntity(e, FALSE, 0.2, Damage_DamageInfo_SendEntity);
39 }
40
41 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
42
43 float checkrules_firstblood;
44
45 float yoda;
46 float damage_goodhits;
47 float damage_gooddamage;
48 float headshot;
49 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
50
51 .float dmg_team;
52 .float teamkill_complain;
53 .float teamkill_soundtime;
54 .entity teamkill_soundsource;
55 .entity pusher;
56 .float taunt_soundtime;
57
58
59 float IsDifferentTeam(entity a, entity b)
60 {
61         if(teams_matter)
62         {
63                 if(a.team == b.team)
64                         return 0;
65         }
66         else
67         {
68                 if(a == b)
69                         return 0;
70         }
71         return 1;
72 }
73
74 float IsFlying(entity a)
75 {
76         if(a.flags & FL_ONGROUND)
77                 return 0;
78         if(a.waterlevel >= WATERLEVEL_SWIMMING)
79                 return 0;
80         traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
81         if(trace_fraction < 1)
82                 return 0;
83         return 1;
84 }
85
86 void UpdateFrags(entity player, float f)
87 {
88         PlayerTeamScore_AddScore(player, f);
89 }
90
91 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
92 void GiveFrags (entity attacker, entity targ, float f)
93 {
94         // TODO route through PlayerScores instead
95         if(gameover) return;
96
97         if(f < 0)
98         {
99                 if(targ == attacker)
100                 {
101                         // suicide
102                         PlayerScore_Add(attacker, SP_SUICIDES, 1);
103                 }
104                 else
105                 {
106                         // teamkill
107                         PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
108                 }
109         }
110         else
111         {
112                 // regular frag
113                 PlayerScore_Add(attacker, SP_KILLS, 1);
114         }
115
116         PlayerScore_Add(targ, SP_DEATHS, 1);
117
118         if(g_arena)
119                 if(cvar("g_arena_roundbased"))
120                         return;
121
122         // FIXME fix the mess this is (we have REAL points now!)
123         if(g_runematch)
124         {
125                 f = RunematchHandleFrags(attacker, targ, f);
126         }
127         else if(g_keyhunt)
128         {
129                 f = kh_HandleFrags(attacker, targ, f);
130         }
131         else if(g_lms)
132         {
133                 // remove a life
134                 float tl;
135                 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
136                 if(tl < lms_lowest_lives)
137                         lms_lowest_lives = tl;
138                 if(tl <= 0)
139                 {
140                         if(!lms_next_place)
141                                 lms_next_place = player_count;
142                         PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
143                         --lms_next_place;
144                 }
145                 f = 0;
146         }
147         else if(g_ctf)
148         {
149                 if(g_ctf_ignore_frags)
150                         f = 0;
151         }
152
153         attacker.totalfrags += f;
154
155         if(f)
156                 UpdateFrags(attacker, f);
157 }
158
159 string AppendItemcodes(string s, entity player)
160 {
161         float w;
162         w = player.weapon;
163         //if(w == 0)
164         //      w = player.switchweapon;
165         if(w == 0)
166                 w = player.cnt; // previous weapon!
167         s = strcat(s, ftos(w));
168         if(time < player.strength_finished)
169                 s = strcat(s, "S");
170         if(time < player.invincible_finished)
171                 s = strcat(s, "I");
172         if(player.flagcarried != world)
173                 s = strcat(s, "F");
174         if(player.BUTTON_CHAT)
175                 s = strcat(s, "T");
176         if(player.kh_next)
177                 s = strcat(s, "K");
178         if(player.runes)
179                 s = strcat(s, "|", ftos(player.runes));
180         return s;
181 }
182
183 void LogDeath(string mode, float deathtype, entity killer, entity killed)
184 {
185         string s;
186         if(!cvar("sv_eventlog"))
187                 return;
188         s = strcat(":kill:", mode);
189         s = strcat(s, ":", ftos(killer.playerid));
190         s = strcat(s, ":", ftos(killed.playerid));
191         s = strcat(s, ":type=", ftos(deathtype));
192         s = strcat(s, ":items=");
193         s = AppendItemcodes(s, killer);
194         if(killed != killer)
195         {
196                 s = strcat(s, ":victimitems=");
197                 s = AppendItemcodes(s, killed);
198         }
199         GameLogEcho(s);
200 }
201
202 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
203 {
204         string  s, a;
205         float p, w;
206
207         if (targ.classname == "player" || targ.classname == "corpse")
208         {
209                 if (targ.classname == "corpse")
210                         s = "A corpse";
211                 else
212                         s = targ.netname;
213                 a = attacker.netname;
214
215                 if (targ == attacker)
216                 {
217                         if (deathtype == DEATH_TEAMCHANGE) {
218                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
219                         } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
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)));
221                                 return;
222                         } else if (deathtype == DEATH_CAMP) {
223                                 if(sv_gentle)
224                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
225                                 else
226                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
227                         } else if (deathtype == DEATH_NOAMMO) {
228                                 if(sv_gentle)
229                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
230                                 else
231                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
232                         } else if (deathtype == DEATH_ROT) {
233                                 if(sv_gentle)
234                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
235                                 else
236                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
237                         } else if (deathtype == DEATH_MIRRORDAMAGE) {
238                                 if(sv_gentle)
239                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
240                                 else
241                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
242                         } else {
243                                 if(sv_gentle)
244                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
245                                 else
246                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
247                         }
248
249                         if(sv_gentle) {
250                                 if (deathtype == DEATH_CAMP)
251                                         bprint ("^1",s, "^1 thought he found a nice camping ground\n");
252                                 else if (deathtype == DEATH_MIRRORDAMAGE)
253                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
254                                 else
255                                         bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
256
257                                 if(deathtype != DEATH_TEAMCHANGE)
258                                 {
259                                         LogDeath("suicide", deathtype, targ, targ);
260                                         GiveFrags(attacker, targ, -1);
261                                 }
262                                 if (targ.killcount > 2)
263                                         bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
264                         } else {
265                                 w = DEATH_WEAPONOF(deathtype);
266                                 if(WEP_VALID(w))
267                                 {
268                                         w_deathtypestring = "couldn't resist the urge to self-destruct";
269                                         w_deathtype = deathtype;
270                                         weapon_action(w, WR_SUICIDEMESSAGE);
271                                         bprint("^1", s, "^1 ", w_deathtypestring, "\n");
272                                 }
273                                 else if (deathtype == DEATH_KILL)
274                                         bprint ("^1",s, "^1 couldn't take it anymore\n");
275                                 else if (deathtype == DEATH_ROT)
276                                         bprint ("^1",s, "^1 died\n");
277                                 else if (deathtype == DEATH_NOAMMO)
278                                         bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
279                                 else if (deathtype == DEATH_CAMP)
280                                         bprint ("^1",s, "^1 thought he found a nice camping ground\n");
281                                 else if (deathtype == DEATH_MIRRORDAMAGE)
282                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
283                                 else if (deathtype == DEATH_CHEAT)
284                                         bprint ("^1",s, "^1 unfairly eliminated himself\n");
285                                 else if (deathtype != DEATH_TEAMCHANGE)
286                                         bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
287
288                                 if(deathtype != DEATH_TEAMCHANGE)
289                                 {
290                                         LogDeath("suicide", deathtype, targ, targ);
291                                         GiveFrags(attacker, targ, -1);
292                                 }
293                                 if (targ.killcount > 2)
294                                         bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
295                         }
296                 }
297                 else if (attacker.classname == "player" || attacker.classname == "gib")
298                 {
299                         if(teams_matter && attacker.team == targ.team)
300                         {
301                                 if(sv_gentle) {
302                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
303                                         bprint ("^1", a, "^1 took action against a team mate\n");
304                                 } else {
305                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
306                                         bprint ("^1", a, "^1 mows down a team mate\n");
307                                 }
308                                 GiveFrags(attacker, targ, -1);
309                                 if (targ.killcount > 2) {
310                                         if(sv_gentle)
311                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
312                                         else
313                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
314                                 }
315                                 if (attacker.killcount > 2) {
316                                         if(sv_gentle)
317                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
318                                         else
319                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
320                                 }
321                                 attacker.killcount = 0;
322
323                                 LogDeath("tk", deathtype, attacker, targ);
324                         }
325                         else
326                         {
327                                 string blood_message, victim_message;
328                                 if (!checkrules_firstblood)
329                                 {
330                                         checkrules_firstblood = TRUE;
331                                         if(sv_gentle)
332                                         {
333                                                 bprint("^1",a, "^1 was the first to score", "\n");
334                                                 blood_message = "^1First point\n";
335                                                 //victim_message = "^1First victim\n";  // or First casualty
336                                         }
337                                         else
338                                         {
339                                                 bprint("^1",a, "^1 drew first blood", "\n");
340                                                 blood_message = "^1First blood\n";
341                                                 victim_message = "^1First victim\n";  // or First casualty
342                                         }
343                                 }
344
345                                 if(sv_gentle > 0) {
346                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s));
347                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7"));
348                                 } else {
349                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s));
350                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a));
351                                         attacker.taunt_soundtime = time + 1;
352                                 }
353
354                                 if(sv_gentle) {
355                                         bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
356                                 } else {
357                                         w = DEATH_WEAPONOF(deathtype);
358                                         if(WEP_VALID(w))
359                                         {
360                                                 w_deathtypestring = "was blasted by";
361                                                 w_deathtype = deathtype;
362                                                 weapon_action(w, WR_KILLMESSAGE);
363                                                 p = strstrofs(w_deathtypestring, "#", 0);
364                                                 if(p < 0)
365                                                         bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
366                                                 else
367                                                         bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
368                                         }
369                                         else if (deathtype == DEATH_TELEFRAG)
370                                                 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
371                                         else if (deathtype == DEATH_DROWN)
372                                                 bprint ("^1",s, "^1 was drowned by ", a, "\n");
373                                         else if (deathtype == DEATH_SLIME)
374                                                 bprint ("^1",s, "^1 was slimed by ", a, "\n");
375                                         else if (deathtype == DEATH_LAVA)
376                                                 bprint ("^1",s, "^1 was cooked by ", a, "\n");
377                                         else if (deathtype == DEATH_FALL)
378                                                 bprint ("^1",s, "^1 was grounded by ", a, "\n");
379                                         else if (deathtype == DEATH_SHOOTING_STAR)
380                                                 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
381                                         else if (deathtype == DEATH_SWAMP)
382                                                 bprint ("^1",s, "^1 was conserved by ", a, "\n");
383                                         else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
384                                         {
385                                                 p = strstrofs(inflictor.message2, "#", 0);
386                                                 if(p < 0)
387                                                         bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
388                                                 else
389                                                         bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
390                                         }
391                                         else if(deathtype == DEATH_TURRET)
392                                                 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
393                                         else if(deathtype == DEATH_TOUCHEXPLODE)
394                                                 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
395                                         else if(deathtype == DEATH_CHEAT)
396                                                 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
397                                         else
398                                                 bprint ("^1",s, "^1 was fragged by ", a, "\n");
399                                 }
400
401                                 if(g_ctf && targ.flagcarried)
402                                 {
403                                         UpdateFrags(attacker, ctf_score_value("score_kill"));
404                                         PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
405                                         GiveFrags(attacker, targ, 0); // for logging
406                                 }
407                                 else
408                                         GiveFrags(attacker, targ, 1);
409
410                                 if (targ.killcount > 2) {
411                                         if(sv_gentle)
412                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
413                                         else
414                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
415                                 }
416
417                                 attacker.killcount = attacker.killcount + 1;
418
419                                 if (attacker.killcount > 2) {
420                                         if(sv_gentle)
421                                                 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
422                                         else
423                                                 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
424                                 }
425
426                                 LogDeath("frag", deathtype, attacker, targ);
427
428                                 if (attacker.killcount == 3)
429                                 {
430                                         if(sv_gentle) {
431                                                 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
432                                         } else {
433                                                 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
434                                                 announce(attacker, "announcer/male/03kills.wav");
435                                         }
436                                 }
437                                 else if (attacker.killcount == 5)
438                                 {
439                                         if(sv_gentle) {
440                                                 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
441                                         } else {
442                                                 bprint (a,"^7 unleashes ^1RAGE\n");
443                                                 announce(attacker, "announcer/male/05kills.wav");
444                                         }
445                                 }
446                                 else if (attacker.killcount == 10)
447                                 {
448                                         if(sv_gentle) {
449                                                 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
450                                         } else {
451                                                 bprint (a,"^7 starts the ^1MASSACRE!\n");
452                                                 announce(attacker, "announcer/male/10kills.wav");
453                                         }
454                                 }
455                                 else if (attacker.killcount == 15)
456                                 {
457                                         if(sv_gentle) {
458                                                 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
459                                         } else {
460                                                 bprint (a,"^7 executes ^1MAYHEM!\n");
461                                                 announce(attacker, "announcer/male/15kills.wav");
462                                         }
463                                 }
464                                 else if (attacker.killcount == 20)
465                                 {
466                                         if(sv_gentle) {
467                                                 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
468                                         } else {
469                                                 bprint (a,"^7 is a ^1BERSERKER!\n");
470                                                 announce(attacker, "announcer/male/20kills.wav");
471                                         }
472                                 }
473                                 else if (attacker.killcount == 25)
474                                 {
475                                         if(sv_gentle) {
476                                                 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
477                                         } else {
478                                                 bprint (a,"^7 inflicts ^1CARNAGE!\n");
479                                                 announce(attacker, "announcer/male/25kills.wav");
480                                         }
481                                 }
482                                 else if (attacker.killcount == 30)
483                                 {
484                                         if(sv_gentle) {
485                                                 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
486                                         } else {
487                                                 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
488                                                 announce(attacker, "announcer/male/30kills.wav");
489                                         }
490                                 }
491                         }
492                 }
493                 else
494                 {
495                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
496                         if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
497                                 bprint ("^1",s, "^1 ", inflictor.message, "\n");
498                         else if (deathtype == DEATH_DROWN)
499                                 if(sv_gentle)
500                                         bprint ("^1",s, "^1 was in the water for too long\n");
501                                 else
502                                         bprint ("^1",s, "^1 drowned\n");
503                         else if (deathtype == DEATH_SLIME)
504                                 bprint ("^1",s, "^1 was slimed\n");
505                         else if (deathtype == DEATH_LAVA)
506                                 if(sv_gentle)
507                                         bprint ("^1",s, "^1 found a hot place\n");
508                                 else
509                                         bprint ("^1",s, "^1 turned into hot slag\n");
510                         else if (deathtype == DEATH_FALL)
511                                 if(sv_gentle)
512                                         bprint ("^1",s, "^1 tested gravity (and it worked)\n");
513                                 else
514                                         bprint ("^1",s, "^1 hit the ground with a crunch\n");
515                         else if (deathtype == DEATH_SHOOTING_STAR)
516                                 bprint ("^1",s, "^1 became a shooting star\n");
517                         else if (deathtype == DEATH_SWAMP)
518                                 if(sv_gentle)
519                                         bprint ("^1",s, "^1 discovered a swamp\n");
520                                 else
521                                         bprint ("^1",s, "^1 is now conserved for centuries to come\n");
522                         else if(deathtype == DEATH_TURRET)
523                                 bprint ("^1",s, "^1 was mowed down by a turret \n");
524                         else if(deathtype == DEATH_TOUCHEXPLODE)
525                                 bprint ("^1",s, "^1 died in an accident\n");
526                         else if(deathtype == DEATH_CHEAT)
527                                 bprint ("^1",s, "^1 was unfairly eliminated\n");
528                         else
529                                 if(sv_gentle)
530                                         bprint ("^1",s, "^1 needs a restart\n");
531                                 else
532                                         bprint ("^1",s, "^1 died\n");
533                         GiveFrags(targ, targ, -1);
534                         if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
535                                 announce(targ, "announcer/male/botlike.wav");
536                         }
537
538                         if (targ.killcount > 2)
539                                 if(sv_gentle)
540                                         bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
541                                 else
542                                         bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
543
544                         LogDeath("accident", deathtype, targ, targ);
545                 }
546                 targ.death_origin = targ.origin;
547                 if(targ != attacker)
548                         targ.killer_origin = attacker.origin;
549                 // FIXME: this should go in PutClientInServer
550                 if (targ.killcount)
551                         targ.killcount = 0;
552         }
553 }
554
555 // these are updated by each Damage call for use in button triggering and such
556 entity damage_targ;
557 entity damage_inflictor;
558 entity damage_attacker;
559
560 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
561 {
562         float mirrordamage;
563         float mirrorforce;
564         float teamdamage0;
565         entity attacker_save;
566         mirrordamage = 0;
567         mirrorforce = 0;
568
569         if (gameover || targ.killcount == -666)
570                 return;
571
572         local entity oldself;
573         oldself = self;
574         self = targ;
575         damage_targ = targ;
576         damage_inflictor = inflictor;
577         damage_attacker = attacker;
578                 attacker_save = attacker;
579         
580         if(targ.classname == "player")
581                 if(targ.hook)
582                         if(targ.hook.aiment)
583                                 if(targ.hook.aiment == attacker)
584                                         RemoveGrapplingHook(targ); // STOP THAT, you parasite!
585
586         // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
587         if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
588         {
589                 if(targ.classname == "player")
590                         if not(IsDifferentTeam(targ, attacker))
591                         {
592                                 self = oldself;
593                                 return;
594                         }
595         }
596
597         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
598         {
599                 // These are ALWAYS lethal
600                 // No damage modification here
601                 // Instead, prepare the victim for his death...
602                 targ.armorvalue = 0;
603                 targ.spawnshieldtime = 0;
604                 targ.health = 0.9; // this is < 1
605                 targ.flags -= targ.flags & FL_GODMODE;
606                 damage = 100000;
607         }
608         else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
609         {
610                 // no processing
611         }
612         else
613         {
614                 if (targ.classname == "player")
615                 if (attacker.classname == "player")
616                 if (!targ.isbot)
617                 if (attacker.isbot)
618                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
619
620                 // nullify damage if teamplay is on
621                 if(deathtype != DEATH_TELEFRAG)
622                 if(attacker.classname == "player")
623                 {
624                         if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
625                         {
626                                 damage = 0;
627                                 force = '0 0 0';
628                         }
629                         else if(attacker.team == targ.team)
630                         {
631                                 if(teamplay == 1)
632                                         damage = 0;
633                                 else if(attacker != targ)
634                                 {
635                                         if(teamplay == 3)
636                                                 damage = 0;
637                                         else if(teamplay == 4)
638                                         {
639                                                 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
640                                                 {
641                                                         teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
642                                                         attacker.dmg_team = attacker.dmg_team + damage;
643                                                         if(attacker.dmg_team > teamdamage0)
644                                                                 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
645                                                         mirrorforce = cvar("g_mirrordamage") * vlen(force);
646                                                         if(g_minstagib)
647                                                         {
648                                                                 if(cvar("g_friendlyfire") == 0)
649                                                                         damage = 0;
650                                                         }
651                                                         else
652                                                                 damage = cvar("g_friendlyfire") * damage;
653                                                         // mirrordamage will be used LATER
654                                                 }
655                                                 else
656                                                         damage = 0;
657                                         }
658                                 }
659                         }
660                 }
661
662                 if(targ.classname == "player")
663                 if(attacker.classname == "player")
664                 if(attacker != targ)
665                 {
666                         targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
667                         attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
668                 }
669
670                 if(targ.classname == "player")
671                 if (g_minstagib)
672                 {
673                         if ((deathtype == DEATH_FALL)  ||
674                                 (deathtype == DEATH_DROWN) ||
675                                 (deathtype == DEATH_SLIME) ||
676                                 (deathtype == DEATH_LAVA))
677                         {
678                                 self = oldself;
679                                 return;
680                         }
681                         if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
682                         {
683                                 targ.armorvalue -= 1;
684                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
685                                 damage = 0;
686                                 targ.hitsound += 1;
687                                 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
688                         }
689                         if (DEATH_ISWEAPON(deathtype, WEP_LASER))
690                         {
691                                 damage = 0;
692                                 if (targ != attacker)
693                                 {
694                                         if (targ.classname == "player")
695                                                 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
696                                         damage = 0;
697                                         mirrordamage = 0;
698                                         force = '0 0 0';
699                                         // keep mirrorforce
700                                         attacker = targ;
701                                 }
702                         }
703                 }
704
705                 if not(DEATH_ISSPECIAL(deathtype))
706                         damage *= g_weapondamagefactor;
707
708                 // apply strength multiplier
709                 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
710                 {
711                         if(targ == attacker)
712                         {
713                                 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
714                                 force = force * cvar("g_balance_powerup_strength_selfforce");
715                         }
716                         else
717                         {
718                                 damage = damage * cvar("g_balance_powerup_strength_damage");
719                                 force = force * cvar("g_balance_powerup_strength_force");
720                         }
721                 }
722
723                 // apply invincibility multiplier
724                 if (targ.items & IT_INVINCIBLE && !g_minstagib)
725                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");
726
727                 if (targ == attacker)
728                         damage = damage * cvar("g_balance_selfdamagepercent");  // Partial damage if the attacker hits himself
729
730                 // CTF: reduce damage/force
731                 if(g_ctf)
732                 if(targ == attacker)
733                 if(targ.flagcarried)
734                 {
735                         damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
736                         force = force * cvar("g_ctf_flagcarrier_selfforce");
737                 }
738
739                 if(g_runematch)
740                 {
741                         // apply strength rune
742                         if (attacker.runes & RUNE_STRENGTH)
743                         {
744                                 if(attacker.runes & CURSE_WEAK) // have both curse & rune
745                                 {
746                                         damage = damage * cvar("g_balance_rune_strength_combo_damage");
747                                         force = force * cvar("g_balance_rune_strength_combo_force");
748                                 }
749                                 else
750                                 {
751                                         damage = damage * cvar("g_balance_rune_strength_damage");
752                                         force = force * cvar("g_balance_rune_strength_force");
753                                 }
754                         }
755                         else if (attacker.runes & CURSE_WEAK)
756                         {
757                                 damage = damage * cvar("g_balance_curse_weak_damage");
758                                 force = force * cvar("g_balance_curse_weak_force");
759                         }
760
761                         // apply defense rune
762                         if (targ.runes & RUNE_DEFENSE)
763                         {
764                                 if (targ.runes & CURSE_VULNER) // have both curse & rune
765                                         damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
766                                 else
767                                         damage = damage * cvar("g_balance_rune_defense_takedamage");
768                         }
769                         else if (targ.runes & CURSE_VULNER)
770                                 damage = damage * cvar("g_balance_curse_vulner_takedamage");
771                 }
772
773                 // count the damage
774                 if(attacker)
775                 if(!targ.deadflag)
776                 if(targ.takedamage == DAMAGE_AIM)
777                 if(targ != attacker)
778                 if(targ.classname == "player")
779                 {
780                         if(IsDifferentTeam(targ, attacker))
781                         {
782                                 if(damage > 0)
783                                 {
784                                         if(targ.BUTTON_CHAT)
785                                                 attacker.typehitsound += 1;
786                                         else
787                                                 attacker.hitsound += 1;
788
789                                         damage_goodhits += 1;
790                                         damage_gooddamage += damage;
791
792                                         if not(DEATH_ISSPECIAL(deathtype))
793                                         {
794                                                 if(!g_minstagib)
795                                                 if(IsFlying(targ))
796                                                         yoda = 1;
797
798                                                 if(g_minstagib)
799                                                 if(targ.items & IT_STRENGTH)
800                                                         yoda = 1;
801
802                                                 // HEAD SHOT:
803                                                 // find height of hit on player axis
804                                                 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
805                                                 vector headmins, headmaxs, org;
806                                                 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
807                                                 headmins = org + '0.7 0 0' * targ.mins_x + '0 0.7 0' * targ.mins_y + '0 0 1' * targ.view_ofs_z;
808                                                 headmaxs = org + '0.7 0 0' * targ.maxs_x + '0 0.7 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
809                                                 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
810                                                 {
811                                                         damage *= 1 + damage_headshotbonus;
812                                                         headshot = 1;
813                                                         deathtype |= HITTYPE_HEADSHOT;
814                                                 }
815                                         }
816                                 }
817                         }
818                         else
819                         {
820                                 attacker.typehitsound += 1;
821                                 if(mirrordamage > 0)
822                                         if(time > attacker.teamkill_complain)
823                                         {
824                                                 attacker.teamkill_complain = time + 5;
825                                                 attacker.teamkill_soundtime = time + 0.4;
826                                                 attacker.teamkill_soundsource = targ;
827                                         }
828                         }
829                 }
830         }
831
832         // apply push
833         if (self.damageforcescale)
834         if (vlen(force))
835         {
836                 self.velocity = self.velocity + self.damageforcescale * force;
837                 self.flags &~= FL_ONGROUND;
838                 UpdateCSQCProjectile(self);
839         }
840         // apply damage
841         if (damage != 0 || (self.damageforcescale && vlen(force)))
842         if (self.event_damage)
843                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
844         self = oldself;
845
846         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
847         {
848                 // Savage: vampire mode
849                 if (g_vampire)
850                 if (!g_minstagib)
851                 if (time > self.spawnshieldtime)
852                 {
853                         attacker.health += damage;
854                 }
855                 if(g_runematch)
856                 {
857                         if (attacker.runes & RUNE_VAMPIRE)
858                         {
859                         // apply vampire rune
860                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
861                                 {
862                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
863                                         attacker.health = bound(
864                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
865                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
866                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
867                                 }
868                                 else
869                                 {
870                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
871                                         attacker.health = bound(
872                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
873                                                                                         // empathy won't let you gain health in the same way...
874                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
875                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
876                                         }
877                         }
878                         // apply empathy curse
879                         else if (attacker.runes & CURSE_EMPATHY)
880                         {
881                                 attacker.health = bound(
882                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
883                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
884                                         attacker.health);
885                         }
886                 }
887         }
888
889         // apply mirror damage if any
890         if(mirrordamage > 0 || mirrorforce > 0)
891         {
892                 attacker = attacker_save;
893                 if(g_minstagib)
894                         if(mirrordamage > 0)
895                         {
896                                 // just lose extra LIVES, don't kill the player for mirror damage
897                                 if(attacker.armorvalue > 0)
898                                 {
899                                         attacker.armorvalue = attacker.armorvalue - 1;
900                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
901                                         attacker.hitsound += 1;
902                                 }
903                                 mirrordamage = 0;
904                         }
905                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
906                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
907         }
908 }
909
910 vector NearestPointOnBox(entity box, vector org)
911 {
912         vector m1, m2, nearest;
913
914         m1 = box.mins + box.origin;
915         m2 = box.maxs + box.origin;
916
917         nearest_x = bound(m1_x, org_x, m2_x);
918         nearest_y = bound(m1_y, org_y, m2_y);
919         nearest_z = bound(m1_z, org_z, m2_z);
920
921         return nearest;
922 }
923
924 float RadiusDamage_running;
925 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
926 // Returns total damage applies to creatures
927 {
928         entity  targ;
929         float   finaldmg;
930         float   power;
931         vector  blastorigin;
932         vector  force;
933         vector  diff;
934         vector  center;
935         vector  nearest;
936         float   total_damage_to_creatures;
937         entity  next;
938
939         if(RadiusDamage_running)
940         {
941                 string save;
942                 print("RadiusDamage called recursively!\n");
943                 print("Expect stuff to go HORRIBLY wrong.\n");
944                 print("Causing a stack trace...\n");
945                 save = cvar_string("prvm_backtraceforwarnings");
946                 cvar_set("prvm_backtraceforwarnings", "1");
947                 fclose(-1); // calls VM_Warning
948                 cvar_set("prvm_backtraceforwarnings", save);
949                 return 0;
950         }
951
952
953         RadiusDamage_running = 1;
954
955         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
956         total_damage_to_creatures = 0;
957
958         if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
959         {
960                 force = inflictor.velocity;
961                 if(vlen(force) == 0)
962                         force = '0 0 -1';
963                 else
964                         force = normalize(force);
965                 if(forceintensity >= 0)
966                         Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype);
967                 else
968                         Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype);
969         }
970
971         targ = findradius (blastorigin, rad);
972         while (targ)
973         {
974                 next = targ.chain;
975                 if (targ != inflictor)
976                         if (ignore != targ)
977                         {
978                                 // LordHavoc: measure distance to nearest point on target (not origin)
979                                 // (this guarentees 100% damage on a touch impact)
980                                 nearest = NearestPointOnBox(targ, blastorigin);
981                                 diff = nearest - blastorigin;
982                                 // round up a little on the damage to ensure full damage on impacts
983                                 // and turn the distance into a fraction of the radius
984                                 power = 1 - ((vlen (diff) - 2) / rad);
985                                 //bprint(" ");
986                                 //bprint(ftos(power));
987                                 if (power > 0)
988                                 {
989                                         if (power > 1)
990                                                 power = 1;
991                                         finaldmg = coredamage * power + edgedamage * (1 - power);
992                                         if (finaldmg > 0)
993                                         {
994                                                 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
995                                                 // if it's a player, use the view origin as reference
996                                                 if (targ.classname == "player")
997                                                         center = targ.origin + targ.view_ofs;
998                                                 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
999                                                 // test line of sight to multiple positions on box,
1000                                                 // and do damage if any of them hit
1001                                                 local float c;
1002                                                 c = ceil(finaldmg / 10);
1003                                                 if (c > 20)
1004                                                         c = 20;
1005                                                 while (c > 0)
1006                                                 {
1007                                                         c = c - 1;
1008                                                         traceline(blastorigin, nearest, TRUE, inflictor);
1009                                                         if (trace_fraction == 1 || trace_ent == targ
1010                                                             || cvar("g_throughfloor"))
1011                                                         {
1012                                                                 if(targ.iscreature)
1013                                                                         total_damage_to_creatures += finaldmg;
1014                                                                 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1015                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1016                                                                 else
1017                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1018                                                                 break;
1019                                                         }
1020                                                         nearest_x = targ.mins_x + random() * targ.size_x;
1021                                                         nearest_y = targ.mins_y + random() * targ.size_y;
1022                                                         nearest_z = targ.mins_z + random() * targ.size_z;
1023                                                 }
1024                                         }
1025                                 }
1026                         }
1027                 targ = next;
1028         }
1029
1030         RadiusDamage_running = 0;
1031
1032         return total_damage_to_creatures;
1033 }