6 float Damage_DamageInfo_SendEntity(entity to, float sf)
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);
20 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, entity dmgowner)
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?
27 if(!sound_allowed(MSG_BROADCAST, dmgowner))
32 e.projectiledeathtype = deathtype;
34 e.dmg_edge = edgedamage;
36 e.dmg_force = vlen(force);
39 e.oldorigin_x = compressShortVector(e.velocity);
41 Net_LinkEntity(e, FALSE, 0.2, Damage_DamageInfo_SendEntity);
44 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
46 float checkrules_firstblood;
49 float damage_goodhits;
50 float damage_gooddamage;
52 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
55 .float teamkill_complain;
56 .float teamkill_soundtime;
57 .entity teamkill_soundsource;
59 .float taunt_soundtime;
62 float IsDifferentTeam(entity a, entity b)
77 float IsFlying(entity a)
79 if(a.flags & FL_ONGROUND)
81 if(a.waterlevel >= WATERLEVEL_SWIMMING)
83 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
84 if(trace_fraction < 1)
89 void UpdateFrags(entity player, float f)
91 PlayerTeamScore_AddScore(player, f);
94 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
95 void W_SwitchWeapon_Force(entity e, float w);
96 void GiveFrags (entity attacker, entity targ, float f)
100 // TODO route through PlayerScores instead
108 PlayerScore_Add(attacker, SP_SUICIDES, 1);
113 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
119 PlayerScore_Add(attacker, SP_KILLS, 1);
122 PlayerScore_Add(targ, SP_DEATHS, 1);
125 if(cvar("g_arena_roundbased"))
128 if(targ != attacker) // not for suicides
129 if(g_weaponarena_random)
131 // after a frag, choose another random weapon set
133 w = warmup_start_weapons;
137 attacker.weapons = randombits(w - (w & W_WeaponBit(attacker.weapon)), g_weaponarena_random, TRUE);
138 if(attacker.weapons < 0)
140 // error from randombits: no weapon available
141 // this means we can just give ALL weapons
142 attacker.weapons = w;
144 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
145 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
148 // FIXME fix the mess this is (we have REAL points now!)
149 frag_attacker = attacker;
152 if(MUTATOR_CALLHOOK(GiveFragsForKill))
158 f = RunematchHandleFrags(attacker, targ, f);
162 f = kh_HandleFrags(attacker, targ, f);
168 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
169 if(tl < lms_lowest_lives)
170 lms_lowest_lives = tl;
174 lms_next_place = player_count;
175 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
182 if(g_ctf_ignore_frags)
186 attacker.totalfrags += f;
189 UpdateFrags(attacker, f);
192 string AppendItemcodes(string s, entity player)
197 // w = player.switchweapon;
199 w = player.cnt; // previous weapon!
200 s = strcat(s, ftos(w));
201 if(time < player.strength_finished)
203 if(time < player.invincible_finished)
205 if(player.flagcarried != world)
207 if(player.BUTTON_CHAT)
212 s = strcat(s, "|", ftos(player.runes));
216 void LogDeath(string mode, float deathtype, entity killer, entity killed)
219 if(!cvar("sv_eventlog"))
221 s = strcat(":kill:", mode);
222 s = strcat(s, ":", ftos(killer.playerid));
223 s = strcat(s, ":", ftos(killed.playerid));
224 s = strcat(s, ":type=", ftos(deathtype));
225 s = strcat(s, ":items=");
226 s = AppendItemcodes(s, killer);
229 s = strcat(s, ":victimitems=");
230 s = AppendItemcodes(s, killed);
235 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
240 if (targ.classname == "player" || targ.classname == "corpse")
242 if (targ.classname == "corpse")
247 a = attacker.netname;
249 if (targ == attacker)
251 if (deathtype == DEATH_TEAMCHANGE) {
252 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
253 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
254 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)));
256 } else if (deathtype == DEATH_CAMP) {
258 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
260 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
261 } else if (deathtype == DEATH_NOAMMO) {
263 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
265 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
266 } else if (deathtype == DEATH_ROT) {
268 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
270 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
271 } else if (deathtype == DEATH_MIRRORDAMAGE) {
273 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
275 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
276 } else if (deathtype == DEATH_QUIET) {
280 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
282 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
285 if (deathtype == DEATH_CAMP)
286 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
287 else if (deathtype == DEATH_MIRRORDAMAGE)
288 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
290 bprint ("^1",s, "^1 will be reinserted into the game due to their own actions\n");
292 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
294 LogDeath("suicide", deathtype, targ, targ);
295 GiveFrags(attacker, targ, -1);
297 if (targ.killcount > 2)
298 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
300 w = DEATH_WEAPONOF(deathtype);
303 w_deathtypestring = "couldn't resist the urge to self-destruct";
304 w_deathtype = deathtype;
305 weapon_action(w, WR_SUICIDEMESSAGE);
306 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
308 else if (deathtype == DEATH_KILL)
309 bprint ("^1",s, "^1 couldn't take it anymore\n");
310 else if (deathtype == DEATH_ROT)
311 bprint ("^1",s, "^1 died\n");
312 else if (deathtype == DEATH_NOAMMO)
313 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
314 else if (deathtype == DEATH_CAMP)
315 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
316 else if (deathtype == DEATH_MIRRORDAMAGE)
317 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
318 else if (deathtype == DEATH_CHEAT)
319 bprint ("^1",s, "^1 unfairly eliminated themself\n");
320 else if (deathtype == DEATH_FIRE)
321 bprint ("^1",s, "^1 burned to death\n");
322 else if (deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
323 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
325 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
327 LogDeath("suicide", deathtype, targ, targ);
328 GiveFrags(attacker, targ, -1);
330 if (targ.killcount > 2)
331 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
334 else if (attacker.classname == "player" || attacker.classname == "gib")
336 if(teams_matter && attacker.team == targ.team)
339 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
340 bprint ("^1", a, "^1 took action against a team mate\n");
342 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
343 bprint ("^1", a, "^1 mows down a team mate\n");
345 GiveFrags(attacker, targ, -1);
346 if (targ.killcount > 2) {
348 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
350 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
352 if (attacker.killcount > 2) {
354 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
356 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
358 attacker.killcount = 0;
360 LogDeath("tk", deathtype, attacker, targ);
364 string blood_message, victim_message;
365 if (!checkrules_firstblood)
367 checkrules_firstblood = TRUE;
370 bprint("^1",a, "^1 was the first to score", "\n");
371 blood_message = "^1First point\n";
372 //victim_message = "^1First victim\n"; // or First casualty
376 bprint("^1",a, "^1 drew first blood", "\n");
377 blood_message = "^1First blood\n";
378 victim_message = "^1First victim\n"; // or First casualty
382 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You scored against ^7", s, GetAdvancedDeathReports(targ)));
383 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7", GetAdvancedDeathReports(attacker)));
385 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
386 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^1You typefragged ^7", s, GetAdvancedDeathReports(targ)));
387 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typefragged by ^7", a, GetAdvancedDeathReports(attacker)));
389 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s, GetAdvancedDeathReports(targ)));
390 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a, GetAdvancedDeathReports(attacker)));
392 attacker.taunt_soundtime = time + 1;
396 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
398 w = DEATH_WEAPONOF(deathtype);
401 w_deathtypestring = "was blasted by";
402 w_deathtype = deathtype;
403 weapon_action(w, WR_KILLMESSAGE);
404 p = strstrofs(w_deathtypestring, "#", 0);
406 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
408 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
410 else if (deathtype == DEATH_TELEFRAG)
411 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
412 else if (deathtype == DEATH_DROWN)
413 bprint ("^1",s, "^1 was drowned by ", a, "\n");
414 else if (deathtype == DEATH_SLIME)
415 bprint ("^1",s, "^1 was slimed by ", a, "\n");
416 else if (deathtype == DEATH_LAVA)
417 bprint ("^1",s, "^1 was cooked by ", a, "\n");
418 else if (deathtype == DEATH_FALL)
419 bprint ("^1",s, "^1 was grounded by ", a, "\n");
420 else if (deathtype == DEATH_SHOOTING_STAR)
421 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
422 else if (deathtype == DEATH_SWAMP)
423 bprint ("^1",s, "^1 was conserved by ", a, "\n");
424 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
426 p = strstrofs(inflictor.message2, "#", 0);
428 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
430 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
432 else if(deathtype == DEATH_SBCRUSH)
433 bprint ("^1",s, "^1 was crushed by ^1", a, "\n");
434 else if(deathtype == DEATH_SBMINIGUN)
435 bprint ("^1",s, "^1 got shredded by ^1", a, "\n");
436 else if(deathtype == DEATH_SBROCKET)
437 bprint ("^1",s, "^1 was blased to bits by ^1", a, "\n");
438 else if(deathtype == DEATH_SBBLOWUP)
439 bprint ("^1",s, "^1 got cought in the destruction of ^1", a, "'s vehicle\n");
441 else if(deathtype == DEATH_WAKIGUN)
442 bprint ("^1",s, "^1 was bolted down by ^1", a, "\n");
443 else if(deathtype == DEATH_WAKIROCKET)
444 bprint ("^1",s, "^1 could find no shelter from ^1", a, "'s rockets\n");
445 else if(deathtype == DEATH_WAKIBLOWUP)
446 bprint ("^1",s, "^1 dies when ^1", a, "'s wakizashi dies.\n");
448 else if(deathtype == DEATH_TURRET)
449 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
450 else if(deathtype == DEATH_TOUCHEXPLODE)
451 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
452 else if(deathtype == DEATH_CHEAT)
453 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
454 else if (deathtype == DEATH_FIRE)
455 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
456 else if (deathtype == DEATH_CUSTOM)
457 bprint ("^1",s, "^1 ", deathmessage, " by ^1", a, "\n");
459 bprint ("^1",s, "^1 was fragged by ", a, "\n");
462 if(g_ctf && targ.flagcarried)
464 UpdateFrags(attacker, ctf_score_value("score_kill"));
465 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
466 GiveFrags(attacker, targ, 0); // for logging
469 GiveFrags(attacker, targ, 1);
471 if (targ.killcount > 2) {
473 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
475 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
478 attacker.killcount = attacker.killcount + 1;
480 if (attacker.killcount > 2) {
482 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
484 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
487 LogDeath("frag", deathtype, attacker, targ);
489 if (attacker.killcount == 3)
492 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
494 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
495 AnnounceTo(attacker, "03kills");
498 else if (attacker.killcount == 5)
501 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
503 bprint (a,"^7 unleashes ^1RAGE\n");
504 AnnounceTo(attacker, "05kills");
507 else if (attacker.killcount == 10)
510 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
512 bprint (a,"^7 starts the ^1MASSACRE!\n");
513 AnnounceTo(attacker, "10kills");
516 else if (attacker.killcount == 15)
519 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
521 bprint (a,"^7 executes ^1MAYHEM!\n");
522 AnnounceTo(attacker, "15kills");
525 else if (attacker.killcount == 20)
528 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
530 bprint (a,"^7 is a ^1BERSERKER!\n");
531 AnnounceTo(attacker, "20kills");
534 else if (attacker.killcount == 25)
537 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
539 bprint (a,"^7 inflicts ^1CARNAGE!\n");
540 AnnounceTo(attacker, "25kills");
543 else if (attacker.killcount == 30)
546 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
548 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
549 AnnounceTo(attacker, "30kills");
556 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
557 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
558 bprint ("^1",s, "^1 ", inflictor.message, "\n");
559 else if (deathtype == DEATH_DROWN)
561 bprint ("^1",s, "^1 was in the water for too long\n");
563 bprint ("^1",s, "^1 drowned\n");
564 else if (deathtype == DEATH_SLIME)
565 bprint ("^1",s, "^1 was slimed\n");
566 else if (deathtype == DEATH_LAVA)
568 bprint ("^1",s, "^1 found a hot place\n");
570 bprint ("^1",s, "^1 turned into hot slag\n");
571 else if (deathtype == DEATH_FALL)
573 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
575 bprint ("^1",s, "^1 hit the ground with a crunch\n");
576 else if (deathtype == DEATH_SHOOTING_STAR)
577 bprint ("^1",s, "^1 became a shooting star\n");
578 else if (deathtype == DEATH_SWAMP)
580 bprint ("^1",s, "^1 discovered a swamp\n");
582 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
583 else if(deathtype == DEATH_TURRET)
584 bprint ("^1",s, "^1 was mowed down by a turret \n");
585 else if (deathtype == DEATH_CUSTOM)
586 bprint ("^1",s, "^1 ", deathmessage, "\n");
587 else if(deathtype == DEATH_TOUCHEXPLODE)
588 bprint ("^1",s, "^1 died in an accident\n");
589 else if(deathtype == DEATH_CHEAT)
590 bprint ("^1",s, "^1 was unfairly eliminated\n");
591 else if(deathtype == DEATH_FIRE)
593 bprint ("^1",s, "^1 felt a little hot\n");
595 bprint ("^1",s, "^1 burnt to death\n");
598 bprint ("^1",s, "^1 needs a restart\n");
600 bprint ("^1",s, "^1 died\n");
601 GiveFrags(targ, targ, -1);
602 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
603 AnnounceTo(targ, "botlike");
606 if (targ.killcount > 2)
608 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
610 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
612 LogDeath("accident", deathtype, targ, targ);
615 targ.death_origin = targ.origin;
617 targ.killer_origin = attacker.origin;
619 // FIXME: this should go in PutClientInServer
625 // these are updated by each Damage call for use in button triggering and such
627 entity damage_inflictor;
628 entity damage_attacker;
630 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
635 entity attacker_save;
639 if (gameover || targ.killcount == -666)
642 local entity oldself;
646 damage_inflictor = inflictor;
647 damage_attacker = attacker;
648 attacker_save = attacker;
650 if(targ.classname == "player")
653 if(targ.hook.aiment == attacker)
654 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
656 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
657 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
659 if(targ.classname == "player")
660 if not(IsDifferentTeam(targ, attacker))
667 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
669 // These are ALWAYS lethal
670 // No damage modification here
671 // Instead, prepare the victim for his death...
673 targ.spawnshieldtime = 0;
674 targ.health = 0.9; // this is < 1
675 targ.flags -= targ.flags & FL_GODMODE;
678 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
684 if (targ.classname == "player")
685 if (attacker.classname == "player")
688 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
690 // nullify damage if teamplay is on
691 if(deathtype != DEATH_TELEFRAG)
692 if(attacker.classname == "player")
694 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
699 else if(attacker.team == targ.team)
703 else if(attacker != targ)
707 else if(teamplay == 4)
709 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
711 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
712 attacker.dmg_team = attacker.dmg_team + damage;
713 if(attacker.dmg_team > teamdamage0 && !g_ca)
714 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
715 mirrorforce = cvar("g_mirrordamage") * vlen(force);
718 if(cvar("g_friendlyfire") == 0)
724 damage = cvar("g_friendlyfire") * damage;
725 // mirrordamage will be used LATER
734 if(targ.classname == "player")
735 if(attacker.classname == "player")
738 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
739 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
742 if(targ.classname == "player")
745 if ((deathtype == DEATH_FALL) ||
746 (deathtype == DEATH_DROWN) ||
747 (deathtype == DEATH_SLIME) ||
748 (deathtype == DEATH_LAVA) ||
749 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
756 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
758 targ.armorvalue -= 1;
759 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
762 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
764 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
767 if (targ != attacker)
769 if ((targ.health >= 1) && (targ.classname == "player"))
770 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
780 if not(DEATH_ISSPECIAL(deathtype))
782 damage *= g_weapondamagefactor;
783 mirrordamage *= g_weapondamagefactor;
784 force = force * g_weaponforcefactor;
785 mirrorforce *= g_weaponforcefactor;
788 // apply strength multiplier
789 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
793 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
794 force = force * cvar("g_balance_powerup_strength_selfforce");
798 damage = damage * cvar("g_balance_powerup_strength_damage");
799 force = force * cvar("g_balance_powerup_strength_force");
803 // apply invincibility multiplier
804 if (targ.items & IT_INVINCIBLE && !g_minstagib)
805 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
807 if (targ == attacker)
809 if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))
812 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
815 // CTF: reduce damage/force
820 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
821 force = force * cvar("g_ctf_flagcarrier_selfforce");
826 // apply strength rune
827 if (attacker.runes & RUNE_STRENGTH)
829 if(attacker.runes & CURSE_WEAK) // have both curse & rune
831 damage = damage * cvar("g_balance_rune_strength_combo_damage");
832 force = force * cvar("g_balance_rune_strength_combo_force");
836 damage = damage * cvar("g_balance_rune_strength_damage");
837 force = force * cvar("g_balance_rune_strength_force");
840 else if (attacker.runes & CURSE_WEAK)
842 damage = damage * cvar("g_balance_curse_weak_damage");
843 force = force * cvar("g_balance_curse_weak_force");
846 // apply defense rune
847 if (targ.runes & RUNE_DEFENSE)
849 if (targ.runes & CURSE_VULNER) // have both curse & rune
850 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
852 damage = damage * cvar("g_balance_rune_defense_takedamage");
854 else if (targ.runes & CURSE_VULNER)
855 damage = damage * cvar("g_balance_curse_vulner_takedamage");
861 if(targ.takedamage == DAMAGE_AIM)
864 if(targ.classname == "player")
867 // find height of hit on player axis
868 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
869 vector headmins, headmaxs, org;
870 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
871 headmins = org + '0.6 0 0' * targ.mins_x + '0 0.6 0' * targ.mins_y + '0 0 1' * (1.3 * targ.view_ofs_z - 0.3 * targ.maxs_z);
872 headmaxs = org + '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
873 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
875 deathtype |= HITTYPE_HEADSHOT;
878 else if(targ.classname == "turret_head")
880 deathtype |= HITTYPE_HEADSHOT;
882 if(deathtype & HITTYPE_HEADSHOT)
883 damage *= 1 + damage_headshotbonus;
885 if(targ.classname == "player")
887 if(IsDifferentTeam(targ, attacker))
892 attacker.typehitsound += 1;
894 attacker.hitsound += 1;
896 damage_goodhits += 1;
897 damage_gooddamage += damage;
899 if not(DEATH_ISSPECIAL(deathtype))
906 if(targ.items & IT_STRENGTH)
909 if(deathtype & HITTYPE_HEADSHOT)
916 if(deathtype != DEATH_FIRE)
917 attacker.typehitsound += 1;
919 if(time > attacker.teamkill_complain)
921 attacker.teamkill_complain = time + 5;
922 attacker.teamkill_soundtime = time + 0.4;
923 attacker.teamkill_soundsource = targ;
931 if (self.damageforcescale)
933 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
935 self.velocity = self.velocity + self.damageforcescale * force;
936 self.flags &~= FL_ONGROUND;
937 UpdateCSQCProjectile(self);
940 if (damage != 0 || (self.damageforcescale && vlen(force)))
941 if (self.event_damage)
942 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
945 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
947 // Savage: vampire mode
950 if (time >= self.spawnshieldtime)
952 attacker.health += damage;
956 if (attacker.runes & RUNE_VAMPIRE)
958 // apply vampire rune
959 if (attacker.runes & CURSE_EMPATHY) // have the curse too
961 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
962 attacker.health = bound(
963 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
964 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
965 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
969 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
970 attacker.health = bound(
971 attacker.health, // LA: was 3, but changed so that you can't lose health
972 // empathy won't let you gain health in the same way...
973 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
974 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
977 // apply empathy curse
978 else if (attacker.runes & CURSE_EMPATHY)
980 attacker.health = bound(
981 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
982 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
988 // apply mirror damage if any
989 if(mirrordamage > 0 || mirrorforce > 0)
991 attacker = attacker_save;
995 // just lose extra LIVES, don't kill the player for mirror damage
996 if(attacker.armorvalue > 0)
998 attacker.armorvalue = attacker.armorvalue - 1;
999 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
1000 attacker.hitsound += 1;
1004 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
1005 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
1009 vector NearestPointOnBox(entity box, vector org)
1011 vector m1, m2, nearest;
1013 m1 = box.mins + box.origin;
1014 m2 = box.maxs + box.origin;
1016 nearest_x = bound(m1_x, org_x, m2_x);
1017 nearest_y = bound(m1_y, org_y, m2_y);
1018 nearest_z = bound(m1_z, org_z, m2_z);
1023 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
1026 weaponid = DEATH_WEAPONOF(deathtype);
1028 if not(inWarmupStage)
1030 if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {
1031 attacker.stats_hit[weaponid - 1] += damage;
1032 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);
1036 float RadiusDamage_running;
1037 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
1038 // Returns total damage applies to creatures
1048 float total_damage_to_creatures;
1053 float stat_damagedone;
1054 float stat_maxdamage;
1056 if(RadiusDamage_running)
1059 print("RadiusDamage called recursively!\n");
1060 print("Expect stuff to go HORRIBLY wrong.\n");
1061 print("Causing a stack trace...\n");
1062 save = cvar_string("prvm_backtraceforwarnings");
1063 cvar_set("prvm_backtraceforwarnings", "1");
1064 fclose(-1); // calls VM_Warning
1065 cvar_set("prvm_backtraceforwarnings", save);
1069 RadiusDamage_running = 1;
1071 tfloordmg = cvar("g_throughfloor_damage");
1072 tfloorforce = cvar("g_throughfloor_force");
1074 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1075 total_damage_to_creatures = 0;
1077 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1078 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
1080 force = inflictor.velocity;
1081 if(vlen(force) == 0)
1084 force = normalize(force);
1085 if(forceintensity >= 0)
1086 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1088 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1091 stat_damagedone = 0;
1094 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
1098 if (targ != inflictor)
1099 if (ignore != targ) if(targ.takedamage)
1101 // LordHavoc: measure distance to nearest point on target (not origin)
1102 // (this guarentees 100% damage on a touch impact)
1103 nearest = targ.WarpZone_findradius_nearest;
1104 diff = targ.WarpZone_findradius_dist;
1105 // round up a little on the damage to ensure full damage on impacts
1106 // and turn the distance into a fraction of the radius
1107 power = 1 - ((vlen (diff) - 2) / rad);
1109 //bprint(ftos(power));
1110 //if (targ == attacker)
1111 // print(ftos(power), "\n");
1116 finaldmg = coredamage * power + edgedamage * (1 - power);
1123 local float hitratio;
1124 local vector hitloc;
1125 local vector myblastorigin;
1126 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1127 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1128 // if it's a player, use the view origin as reference
1129 if (targ.classname == "player")
1130 center = targ.origin + targ.view_ofs;
1131 force = normalize(center - myblastorigin);
1132 force = force * (finaldmg / coredamage) * forceintensity;
1133 // test line of sight to multiple positions on box,
1134 // and do damage if any of them hit
1136 if (targ.classname == "player")
1137 total = ceil(bound(1, finaldmg, 50));
1139 total = ceil(bound(1, finaldmg/10, 5));
1144 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1145 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1146 if (trace_fraction == 1 || trace_ent == targ)
1150 hitloc = hitloc + nearest;
1154 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1155 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1156 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1159 nearest = hitloc * (1 / max(1, hits));
1160 hitratio = (hits / total);
1161 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1162 finaldmg = finaldmg * a;
1163 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1165 //if (targ == attacker)
1167 // print("hits ", ftos(hits), " / ", ftos(total));
1168 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1169 // print(" (", ftos(a), ")\n");
1171 if(hits || tfloordmg || tfloorforce)
1175 total_damage_to_creatures += finaldmg;
1177 if(targ.flags & FL_CLIENT)
1178 if(targ.deadflag == DEAD_NO)
1179 if(targ != attacker)
1180 if(!teamplay || targ.team != attacker.team)
1182 stat_damagedone += finaldmg;
1183 stat_maxdamage += coredamage;
1187 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1188 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1190 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1198 RadiusDamage_running = 0;
1200 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1202 return total_damage_to_creatures;
1205 .float fire_damagepersec;
1206 .float fire_endtime;
1207 .float fire_deathtype;
1209 .float fire_hitsound;
1210 .entity fire_burner;
1212 void fireburner_think();
1214 float Fire_IsBurning(entity e)
1216 return (time < e.fire_endtime);
1219 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1222 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1224 if(e.classname == "player")
1233 // print("adding a fire burner to ", e.classname, "\n");
1234 e.fire_burner = spawn();
1235 e.fire_burner.classname = "fireburner";
1236 e.fire_burner.think = fireburner_think;
1237 e.fire_burner.nextthink = time;
1238 e.fire_burner.owner = e;
1244 if(Fire_IsBurning(e))
1246 mintime = e.fire_endtime - time;
1247 maxtime = max(mintime, t);
1249 mindps = e.fire_damagepersec;
1250 maxdps = max(mindps, dps);
1252 if(maxtime > mintime || maxdps > mindps)
1254 mindamage = mindps * mintime;
1255 maxdamage = mindamage + d;
1257 // interval [mintime, maxtime] * [mindps, maxdps]
1259 // [mindamage, maxdamage]
1262 if(maxdamage >= maxtime * maxdps)
1264 totaltime = maxtime;
1265 totaldamage = maxtime * maxdps;
1267 // this branch increases totaldamage if either t > mintime, or dps > mindps
1271 // maxdamage is inside the interval!
1272 // first, try to use mindps; only if this fails, increase dps as needed
1273 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1274 totaldamage = maxdamage;
1275 // can totaldamage / totaltime be >= maxdps?
1276 // max(mindps, maxdamage / maxtime) >= maxdps?
1277 // we know maxdamage < maxtime * maxdps
1280 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1283 // total conditions for increasing:
1284 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1286 // if maxtime = mintime, maxdps = mindps
1288 // maxdamage = mindamage + d
1289 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1290 // so the last condition is not needed
1292 e.fire_damagepersec = totaldamage / totaltime;
1293 e.fire_endtime = time + totaltime;
1294 if(totaldamage > 1.2 * mindamage)
1296 e.fire_deathtype = dt;
1297 if(e.fire_owner != o)
1300 e.fire_hitsound = FALSE;
1303 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1310 e.fire_damagepersec = dps;
1311 e.fire_endtime = time + t;
1312 e.fire_deathtype = dt;
1314 e.fire_hitsound = FALSE;
1319 void Fire_ApplyDamage(entity e)
1324 if not(Fire_IsBurning(e))
1330 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1333 // water and slime stop fire
1335 if(e.watertype != CONTENT_LAVA)
1338 t = min(frametime, e.fire_endtime - time);
1339 d = e.fire_damagepersec * t;
1341 hi = e.fire_owner.hitsound;
1342 ty = e.fire_owner.typehitsound;
1343 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1344 if(e.fire_hitsound && e.fire_owner)
1346 e.fire_owner.hitsound = hi;
1347 e.fire_owner.typehitsound = ty;
1349 e.fire_hitsound = TRUE;
1351 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1353 if not(IS_INDEPENDENT_PLAYER(e))
1354 FOR_EACH_PLAYER(other) if(e != other)
1356 if(other.classname == "player")
1357 if(other.deadflag == DEAD_NO)
1358 if not(IS_INDEPENDENT_PLAYER(other))
1359 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1361 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1362 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1363 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1368 void Fire_ApplyEffect(entity e)
1370 if(Fire_IsBurning(e))
1371 e.effects |= EF_FLAME;
1373 e.effects &~= EF_FLAME;
1376 void fireburner_think()
1378 // for players, this is done in the regular loop
1379 if(wasfreed(self.owner))
1384 Fire_ApplyEffect(self.owner);
1385 if(!Fire_IsBurning(self.owner))
1387 self.owner.fire_burner = world;
1391 Fire_ApplyDamage(self.owner);
1392 self.nextthink = time;