]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_damage.qc
fix some uses of the flags field; should fix turret aiming bug
[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, TRUE, 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 >= 2)
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_TEAMCHANGE)
284                                         bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
285
286                                 if(deathtype != DEATH_TEAMCHANGE)
287                                 {
288                                         LogDeath("suicide", deathtype, targ, targ);
289                                         GiveFrags(attacker, targ, -1);
290                                 }
291                                 if (targ.killcount > 2)
292                                         bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
293                         }
294                 }
295                 else if (attacker.classname == "player" || attacker.classname == "gib")
296                 {
297                         if(teamplay && attacker.team == targ.team)
298                         {
299                                 if(sv_gentle) {
300                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
301                                         bprint ("^1", a, "^1 took action against a team mate\n");
302                                 } else {
303                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
304                                         bprint ("^1", a, "^1 mows down a team mate\n");
305                                 }
306                                 GiveFrags(attacker, targ, -1);
307                                 if (targ.killcount > 2) {
308                                         if(sv_gentle)
309                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
310                                         else
311                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
312                                 }
313                                 if (attacker.killcount > 2) {
314                                         if(sv_gentle)
315                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
316                                         else
317                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
318                                 }
319                                 attacker.killcount = 0;
320
321                                 LogDeath("tk", deathtype, attacker, targ);
322                         }
323                         else
324                         {
325                                 string blood_message, victim_message;
326                                 if (!checkrules_firstblood)
327                                 {
328                                         checkrules_firstblood = TRUE;
329                                         if(sv_gentle)
330                                         {
331                                                 bprint("^1",a, "^1 was the first to score", "\n");
332                                                 blood_message = "^1First point\n";
333                                                 //victim_message = "^1First victim\n";  // or First casualty
334                                         }
335                                         else
336                                         {
337                                                 bprint("^1",a, "^1 drew first blood", "\n");
338                                                 blood_message = "^1First blood\n";
339                                                 victim_message = "^1First victim\n";  // or First casualty
340                                         }
341                                 }
342
343                                 if(sv_gentle > 0) {
344                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s));
345                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7"));
346                                 } else {
347                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s));
348                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a));
349                                         attacker.taunt_soundtime = time + 1;
350                                 }
351
352                                 if(sv_gentle) {
353                                         bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
354                                 } else {
355                                         w = DEATH_WEAPONOF(deathtype);
356                                         if(WEP_VALID(w))
357                                         {
358                                                 w_deathtypestring = "was blasted by";
359                                                 w_deathtype = deathtype;
360                                                 weapon_action(w, WR_KILLMESSAGE);
361                                                 p = strstrofs(w_deathtypestring, "#", 0);
362                                                 if(p < 0)
363                                                         bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
364                                                 else
365                                                         bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
366                                         }
367                                         else if (deathtype == DEATH_TELEFRAG)
368                                                 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
369                                         else if (deathtype == DEATH_DROWN)
370                                                 bprint ("^1",s, "^1 was drowned by ", a, "\n");
371                                         else if (deathtype == DEATH_SLIME)
372                                                 bprint ("^1",s, "^1 was slimed by ", a, "\n");
373                                         else if (deathtype == DEATH_LAVA)
374                                                 bprint ("^1",s, "^1 was cooked by ", a, "\n");
375                                         else if (deathtype == DEATH_FALL)
376                                                 bprint ("^1",s, "^1 was grounded by ", a, "\n");
377                                         else if (deathtype == DEATH_SHOOTING_STAR)
378                                                 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
379                                         else if (deathtype == DEATH_SWAMP)
380                                                 bprint ("^1",s, "^1 was conserved by ", a, "\n");
381                                         else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
382                                         {
383                                                 p = strstrofs(inflictor.message2, "#", 0);
384                                                 if(p < 0)
385                                                         bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
386                                                 else
387                                                         bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
388                                         }
389                                         else if(deathtype == DEATH_TURRET)
390                                                 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
391                                         else if(deathtype == DEATH_TOUCHEXPLODE)
392                                                 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
393                                         else
394                                                 bprint ("^1",s, "^1 was fragged by ", a, "\n");
395                                 }
396
397                                 if(g_ctf && targ.flagcarried)
398                                 {
399                                         UpdateFrags(attacker, ctf_score_value("score_kill"));
400                                         PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
401                                         GiveFrags(attacker, targ, 0); // for logging
402                                 }
403                                 else
404                                         GiveFrags(attacker, targ, 1);
405
406                                 if (targ.killcount > 2) {
407                                         if(sv_gentle)
408                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
409                                         else
410                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
411                                 }
412
413                                 attacker.killcount = attacker.killcount + 1;
414
415                                 if (attacker.killcount > 2) {
416                                         if(sv_gentle)
417                                                 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
418                                         else
419                                                 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
420                                 }
421
422                                 LogDeath("frag", deathtype, attacker, targ);
423
424                                 if (attacker.killcount == 3)
425                                 {
426                                         if(sv_gentle) {
427                                                 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
428                                         } else {
429                                                 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
430                                                 announce(attacker, "announcer/male/03kills.wav");
431                                         }
432                                 }
433                                 else if (attacker.killcount == 5)
434                                 {
435                                         if(sv_gentle) {
436                                                 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
437                                         } else {
438                                                 bprint (a,"^7 unleashes ^1RAGE\n");
439                                                 announce(attacker, "announcer/male/05kills.wav");
440                                         }
441                                 }
442                                 else if (attacker.killcount == 10)
443                                 {
444                                         if(sv_gentle) {
445                                                 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
446                                         } else {
447                                                 bprint (a,"^7 starts the ^1MASSACRE!\n");
448                                                 announce(attacker, "announcer/male/10kills.wav");
449                                         }
450                                 }
451                                 else if (attacker.killcount == 15)
452                                 {
453                                         if(sv_gentle) {
454                                                 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
455                                         } else {
456                                                 bprint (a,"^7 executes ^1MAYHEM!\n");
457                                                 announce(attacker, "announcer/male/15kills.wav");
458                                         }
459                                 }
460                                 else if (attacker.killcount == 20)
461                                 {
462                                         if(sv_gentle) {
463                                                 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
464                                         } else {
465                                                 bprint (a,"^7 is a ^1BERSERKER!\n");
466                                                 announce(attacker, "announcer/male/20kills.wav");
467                                         }
468                                 }
469                                 else if (attacker.killcount == 25)
470                                 {
471                                         if(sv_gentle) {
472                                                 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
473                                         } else {
474                                                 bprint (a,"^7 inflicts ^1CARNAGE!\n");
475                                                 announce(attacker, "announcer/male/25kills.wav");
476                                         }
477                                 }
478                                 else if (attacker.killcount == 30)
479                                 {
480                                         if(sv_gentle) {
481                                                 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
482                                         } else {
483                                                 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
484                                                 announce(attacker, "announcer/male/30kills.wav");
485                                         }
486                                 }
487                         }
488                 }
489                 else
490                 {
491                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
492                         if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
493                                 bprint ("^1",s, "^1 ", inflictor.message, "\n");
494                         else if (deathtype == DEATH_DROWN)
495                                 if(sv_gentle)
496                                         bprint ("^1",s, "^1 was in the water for too long\n");
497                                 else
498                                         bprint ("^1",s, "^1 drowned\n");
499                         else if (deathtype == DEATH_SLIME)
500                                 bprint ("^1",s, "^1 was slimed\n");
501                         else if (deathtype == DEATH_LAVA)
502                                 if(sv_gentle)
503                                         bprint ("^1",s, "^1 found a hot place\n");
504                                 else
505                                         bprint ("^1",s, "^1 turned into hot slag\n");
506                         else if (deathtype == DEATH_FALL)
507                                 if(sv_gentle)
508                                         bprint ("^1",s, "^1 tested gravity (and it worked)\n");
509                                 else
510                                         bprint ("^1",s, "^1 hit the ground with a crunch\n");
511                         else if (deathtype == DEATH_SHOOTING_STAR)
512                                 bprint ("^1",s, "^1 became a shooting star\n");
513                         else if (deathtype == DEATH_SWAMP)
514                                 if(sv_gentle)
515                                         bprint ("^1",s, "^1 discovered a swamp\n");
516                                 else
517                                         bprint ("^1",s, "^1 is now conserved for centuries to come\n");
518                         else if(deathtype == DEATH_TURRET)
519                                 bprint ("^1",s, "^1 was mowed down by a turret \n");
520                         else if(deathtype == DEATH_TOUCHEXPLODE)
521                                 bprint ("^1",s, "^1 died in an accident\n");
522                         else
523                                 if(sv_gentle)
524                                         bprint ("^1",s, "^1 needs a restart\n");
525                                 else
526                                         bprint ("^1",s, "^1 died\n");
527                         GiveFrags(targ, targ, -1);
528                         if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
529                                 announce(targ, "announcer/male/botlike.wav");
530                         }
531
532                         if (targ.killcount > 2)
533                                 if(sv_gentle)
534                                         bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
535                                 else
536                                         bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
537
538                         LogDeath("accident", deathtype, targ, targ);
539                 }
540                 targ.death_origin = targ.origin;
541                 if(targ != attacker)
542                         targ.killer_origin = attacker.origin;
543                 // FIXME: this should go in PutClientInServer
544                 if (targ.killcount)
545                         targ.killcount = 0;
546         }
547 }
548
549 // these are updated by each Damage call for use in button triggering and such
550 entity damage_targ;
551 entity damage_inflictor;
552 entity damage_attacker;
553
554 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
555 {
556         float mirrordamage;
557         float mirrorforce;
558         float teamdamage0;
559         entity attacker_save;
560         mirrordamage = 0;
561         mirrorforce = 0;
562
563         if (gameover || targ.killcount == -666)
564                 return;
565
566         local entity oldself;
567         oldself = self;
568         self = targ;
569         damage_targ = targ;
570         damage_inflictor = inflictor;
571         damage_attacker = attacker;
572                 attacker_save = attacker;
573         
574         if(targ.classname == "player")
575                 if(targ.hook)
576                         if(targ.hook.aiment)
577                                 if(targ.hook.aiment == attacker)
578                                         RemoveGrapplingHook(targ); // STOP THAT, you parasite!
579
580         // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
581         if(DEATH_ISWEAPON(deathtype, WEP_HOOK))
582         {
583                 if(targ.classname == "player")
584                         if not(IsDifferentTeam(targ, attacker))
585                         {
586                                 self = oldself;
587                                 return;
588                         }
589         }
590
591         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
592         {
593                 // These are ALWAYS lethal
594                 // No damage modification here
595                 // Instead, prepare the victim for his death...
596                 targ.armorvalue = 0;
597                 targ.spawnshieldtime = 0;
598                 targ.health = 0.9; // this is < 1
599                 targ.flags -= targ.flags & FL_GODMODE;
600                 damage = 100000;
601         }
602         else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
603         {
604                 // no processing
605         }
606         else
607         {
608                 if (targ.classname == "player")
609                 if (attacker.classname == "player")
610                 if (!targ.isbot)
611                 if (attacker.isbot)
612                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
613
614                 // nullify damage if teamplay is on
615                 if(deathtype != DEATH_TELEFRAG)
616                 if(attacker.classname == "player")
617                 {
618                         if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
619                         {
620                                 damage = 0;
621                                 force = '0 0 0';
622                         }
623                         else if(attacker.team == targ.team)
624                         {
625                                 if(teamplay == 1)
626                                         damage = 0;
627                                 else if(attacker != targ)
628                                 {
629                                         if(teamplay == 3)
630                                                 damage = 0;
631                                         else if(teamplay == 4)
632                                         {
633                                                 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
634                                                 {
635                                                         teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
636                                                         attacker.dmg_team = attacker.dmg_team + damage;
637                                                         if(attacker.dmg_team > teamdamage0)
638                                                                 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
639                                                         mirrorforce = cvar("g_mirrordamage") * vlen(force);
640                                                         if(g_minstagib)
641                                                         {
642                                                                 if(cvar("g_friendlyfire") == 0)
643                                                                         damage = 0;
644                                                         }
645                                                         else
646                                                                 damage = cvar("g_friendlyfire") * damage;
647                                                         // mirrordamage will be used LATER
648                                                 }
649                                                 else
650                                                         damage = 0;
651                                         }
652                                 }
653                         }
654                 }
655
656                 if(targ.classname == "player")
657                 if(attacker.classname == "player")
658                 if(attacker != targ)
659                 {
660                         targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
661                         attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
662                 }
663
664                 if (g_minstagib)
665                 {
666                         if ((deathtype == DEATH_FALL)  ||
667                                 (deathtype == DEATH_DROWN) ||
668                                 (deathtype == DEATH_SLIME) ||
669                                 (deathtype == DEATH_LAVA))
670                         {
671                                 self = oldself;
672                                 return;
673                         }
674                         if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
675                         {
676                                 targ.armorvalue -= 1;
677                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
678                                 damage = 0;
679                                 targ.hitsound += 1;
680                         }
681                         if (DEATH_ISWEAPON(deathtype, WEP_LASER))
682                         {
683                                 damage = 0;
684                                 if (targ != attacker)
685                                 {
686                                         if (targ.classname == "player")
687                                                 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
688                                         damage = 0;
689                                         mirrordamage = 0;
690                                         force = '0 0 0';
691                                         // keep mirrorforce
692                                         attacker = targ;
693                                 }
694                         }
695                 }
696
697                 // apply strength multiplier
698                 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
699                 {
700                         if(targ == attacker)
701                         {
702                                 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
703                                 force = force * cvar("g_balance_powerup_strength_selfforce");
704                         }
705                         else
706                         {
707                                 damage = damage * cvar("g_balance_powerup_strength_damage");
708                                 force = force * cvar("g_balance_powerup_strength_force");
709                         }
710                 }
711
712                 // apply invincibility multiplier
713                 if (targ.items & IT_INVINCIBLE && !g_minstagib)
714                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");
715
716                 if (targ == attacker)
717                         damage = damage * cvar("g_balance_selfdamagepercent");  // Partial damage if the attacker hits himself
718
719                 // CTF: reduce damage/force
720                 if(g_ctf)
721                 if(targ == attacker)
722                 if(targ.flagcarried)
723                 {
724                         damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
725                         force = force * cvar("g_ctf_flagcarrier_selfforce");
726                 }
727
728                 if(g_runematch)
729                 {
730                         // apply strength rune
731                         if (attacker.runes & RUNE_STRENGTH)
732                         {
733                                 if(attacker.runes & CURSE_WEAK) // have both curse & rune
734                                 {
735                                         damage = damage * cvar("g_balance_rune_strength_combo_damage");
736                                         force = force * cvar("g_balance_rune_strength_combo_force");
737                                 }
738                                 else
739                                 {
740                                         damage = damage * cvar("g_balance_rune_strength_damage");
741                                         force = force * cvar("g_balance_rune_strength_force");
742                                 }
743                         }
744                         else if (attacker.runes & CURSE_WEAK)
745                         {
746                                 damage = damage * cvar("g_balance_curse_weak_damage");
747                                 force = force * cvar("g_balance_curse_weak_force");
748                         }
749
750                         // apply defense rune
751                         if (targ.runes & RUNE_DEFENSE)
752                         {
753                                 if (targ.runes & CURSE_VULNER) // have both curse & rune
754                                         damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
755                                 else
756                                         damage = damage * cvar("g_balance_rune_defense_takedamage");
757                         }
758                         else if (targ.runes & CURSE_VULNER)
759                                 damage = damage * cvar("g_balance_curse_vulner_takedamage");
760                 }
761
762                 // count the damage
763                 if(attacker)
764                 if(!targ.deadflag)
765                 if(targ.takedamage == DAMAGE_AIM)
766                 if(targ != attacker)
767                 if(targ.classname == "player")
768                 {
769                         if(IsDifferentTeam(targ, attacker))
770                         {
771                                 if(damage > 0)
772                                 {
773                                         if(targ.BUTTON_CHAT)
774                                                 attacker.typehitsound += 1;
775                                         else
776                                                 attacker.hitsound += 1;
777
778                                         damage_goodhits += 1;
779                                         damage_gooddamage += damage;
780
781                                         if not(DEATH_ISSPECIAL(deathtype))
782                                         {
783                                                 if(!g_minstagib)
784                                                 if(IsFlying(targ))
785                                                         yoda = 1;
786
787                                                 if(g_minstagib)
788                                                 if(targ.items & IT_STRENGTH)
789                                                         yoda = 1;
790
791                                                 // HEAD SHOT:
792                                                 // find height of hit on player axis
793                                                 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
794                                                 vector headmins, headmaxs, org;
795                                                 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
796                                                 headmins = org + '0.7 0 0' * targ.mins_x + '0 0.7 0' * targ.mins_y + '0 0 1' * targ.view_ofs_z;
797                                                 headmaxs = org + '0.7 0 0' * targ.maxs_x + '0 0.7 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
798                                                 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
799                                                 {
800                                                         damage *= 1 + damage_headshotbonus;
801                                                         headshot = 1;
802                                                         deathtype |= HITTYPE_HEADSHOT;
803                                                 }
804                                         }
805                                 }
806                         }
807                         else
808                         {
809                                 attacker.typehitsound += 1;
810                                 if(mirrordamage > 0)
811                                         if(time > attacker.teamkill_complain)
812                                         {
813                                                 attacker.teamkill_complain = time + 5;
814                                                 attacker.teamkill_soundtime = time + 0.4;
815                                                 attacker.teamkill_soundsource = targ;
816                                         }
817                         }
818                 }
819         }
820
821         // apply push
822         if (self.damageforcescale)
823         if (vlen(force))
824         {
825                 self.velocity = self.velocity + self.damageforcescale * force;
826                 self.flags &~= FL_ONGROUND;
827                 UpdateCSQCProjectile(self);
828         }
829         // apply damage
830         if (damage != 0)
831         if (self.event_damage)
832                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
833         self = oldself;
834
835         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
836         {
837                 // Savage: vampire mode
838                 if (g_vampire)
839                 if (!g_minstagib)
840                 if (time > self.spawnshieldtime)
841                 {
842                         attacker.health += damage;
843                 }
844                 if(g_runematch)
845                 {
846                         if (attacker.runes & RUNE_VAMPIRE)
847                         {
848                         // apply vampire rune
849                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
850                                 {
851                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
852                                         attacker.health = bound(
853                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
854                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
855                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
856                                 }
857                                 else
858                                 {
859                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
860                                         attacker.health = bound(
861                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
862                                                                                         // empathy won't let you gain health in the same way...
863                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
864                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
865                                         }
866                         }
867                         // apply empathy curse
868                         else if (attacker.runes & CURSE_EMPATHY)
869                         {
870                                 attacker.health = bound(
871                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
872                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
873                                         attacker.health);
874                         }
875                 }
876         }
877
878         // apply mirror damage if any
879         if(mirrordamage > 0 || mirrorforce > 0)
880         {
881                 attacker = attacker_save;
882                 if(g_minstagib)
883                         if(mirrordamage > 0)
884                         {
885                                 // just lose extra LIVES, don't kill the player for mirror damage
886                                 if(attacker.armorvalue > 0)
887                                 {
888                                         attacker.armorvalue = attacker.armorvalue - 1;
889                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
890                                         attacker.hitsound += 1;
891                                 }
892                                 mirrordamage = 0;
893                         }
894                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
895                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
896         }
897 }
898
899 vector NearestPointOnBox(entity box, vector org)
900 {
901         vector m1, m2, nearest;
902
903         m1 = box.mins + box.origin;
904         m2 = box.maxs + box.origin;
905
906         nearest_x = bound(m1_x, org_x, m2_x);
907         nearest_y = bound(m1_y, org_y, m2_y);
908         nearest_z = bound(m1_z, org_z, m2_z);
909
910         return nearest;
911 }
912
913 float RadiusDamage_running;
914 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
915 // Returns total damage applies to creatures
916 {
917         entity  targ;
918         float   finaldmg;
919         float   power;
920         vector  blastorigin;
921         vector  force;
922         vector  diff;
923         vector  center;
924         vector  nearest;
925         float   total_damage_to_creatures;
926         entity  next;
927
928         if(RadiusDamage_running)
929         {
930                 string save;
931                 print("RadiusDamage called recursively!\n");
932                 print("Expect stuff to go HORRIBLY wrong.\n");
933                 print("Causing a stack trace...\n");
934                 save = cvar_string("prvm_backtraceforwarnings");
935                 cvar_set("prvm_backtraceforwarnings", "1");
936                 fclose(-1); // calls VM_Warning
937                 cvar_set("prvm_backtraceforwarnings", save);
938                 return 0;
939         }
940
941
942         RadiusDamage_running = 1;
943
944         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
945         total_damage_to_creatures = 0;
946
947         if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
948         {
949                 force = inflictor.velocity;
950                 if(vlen(force) == 0)
951                         force = '0 0 -1';
952                 else
953                         force = normalize(force);
954                 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype);
955         }
956
957         targ = findradius (blastorigin, rad);
958         while (targ)
959         {
960                 next = targ.chain;
961                 if (targ != inflictor)
962                         if (ignore != targ)
963                         {
964                                 // LordHavoc: measure distance to nearest point on target (not origin)
965                                 // (this guarentees 100% damage on a touch impact)
966                                 nearest = NearestPointOnBox(targ, blastorigin);
967                                 diff = nearest - blastorigin;
968                                 // round up a little on the damage to ensure full damage on impacts
969                                 // and turn the distance into a fraction of the radius
970                                 power = 1 - ((vlen (diff) - 2) / rad);
971                                 //bprint(" ");
972                                 //bprint(ftos(power));
973                                 if (power > 0)
974                                 {
975                                         if (power > 1)
976                                                 power = 1;
977                                         finaldmg = coredamage * power + edgedamage * (1 - power);
978                                         if (finaldmg > 0)
979                                         {
980                                                 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
981                                                 // if it's a player, use the view origin as reference
982                                                 if (targ.classname == "player")
983                                                         center = targ.origin + targ.view_ofs;
984                                                 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
985                                                 // test line of sight to multiple positions on box,
986                                                 // and do damage if any of them hit
987                                                 local float c;
988                                                 c = ceil(finaldmg / 10);
989                                                 if (c > 20)
990                                                         c = 20;
991                                                 while (c > 0)
992                                                 {
993                                                         c = c - 1;
994                                                         traceline(blastorigin, nearest, TRUE, inflictor);
995                                                         if (trace_fraction == 1 || trace_ent == targ
996                                                             || cvar("g_throughfloor"))
997                                                         {
998                                                                 if(targ.iscreature)
999                                                                         total_damage_to_creatures += finaldmg;
1000                                                                 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1001                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1002                                                                 else
1003                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1004                                                                 break;
1005                                                         }
1006                                                         nearest_x = targ.mins_x + random() * targ.size_x;
1007                                                         nearest_y = targ.mins_y + random() * targ.size_y;
1008                                                         nearest_z = targ.mins_z + random() * targ.size_z;
1009                                                 }
1010                                         }
1011                                 }
1012                         }
1013                 targ = next;
1014         }
1015
1016         RadiusDamage_running = 0;
1017
1018         return total_damage_to_creatures;
1019 }