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!)
151 f = RunematchHandleFrags(attacker, targ, f);
155 f = kh_HandleFrags(attacker, targ, f);
161 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
162 if(tl < lms_lowest_lives)
163 lms_lowest_lives = tl;
167 lms_next_place = player_count;
168 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
175 if(g_ctf_ignore_frags)
179 attacker.totalfrags += f;
182 UpdateFrags(attacker, f);
185 string AppendItemcodes(string s, entity player)
190 // w = player.switchweapon;
192 w = player.cnt; // previous weapon!
193 s = strcat(s, ftos(w));
194 if(time < player.strength_finished)
196 if(time < player.invincible_finished)
198 if(player.flagcarried != world)
200 if(player.BUTTON_CHAT)
205 s = strcat(s, "|", ftos(player.runes));
209 void LogDeath(string mode, float deathtype, entity killer, entity killed)
212 if(!cvar("sv_eventlog"))
214 s = strcat(":kill:", mode);
215 s = strcat(s, ":", ftos(killer.playerid));
216 s = strcat(s, ":", ftos(killed.playerid));
217 s = strcat(s, ":type=", ftos(deathtype));
218 s = strcat(s, ":items=");
219 s = AppendItemcodes(s, killer);
222 s = strcat(s, ":victimitems=");
223 s = AppendItemcodes(s, killed);
228 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
233 if (targ.classname == "player" || targ.classname == "corpse")
235 if (targ.classname == "corpse")
240 a = attacker.netname;
242 if (targ == attacker)
244 if (deathtype == DEATH_TEAMCHANGE) {
245 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
246 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
247 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)));
249 } else if (deathtype == DEATH_CAMP) {
251 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
253 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
254 } else if (deathtype == DEATH_NOAMMO) {
256 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
258 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
259 } else if (deathtype == DEATH_ROT) {
261 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
263 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
264 } else if (deathtype == DEATH_MIRRORDAMAGE) {
266 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
268 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
271 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
273 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
277 if (deathtype == DEATH_CAMP)
278 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
279 else if (deathtype == DEATH_MIRRORDAMAGE)
280 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
282 bprint ("^1",s, "^1 will be reinserted into the game due to their own actions\n");
284 if(deathtype != DEATH_TEAMCHANGE)
286 LogDeath("suicide", deathtype, targ, targ);
287 GiveFrags(attacker, targ, -1);
289 if (targ.killcount > 2)
290 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
292 w = DEATH_WEAPONOF(deathtype);
295 w_deathtypestring = "couldn't resist the urge to self-destruct";
296 w_deathtype = deathtype;
297 weapon_action(w, WR_SUICIDEMESSAGE);
298 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
300 else if (deathtype == DEATH_KILL)
301 bprint ("^1",s, "^1 couldn't take it anymore\n");
302 else if (deathtype == DEATH_ROT)
303 bprint ("^1",s, "^1 died\n");
304 else if (deathtype == DEATH_NOAMMO)
305 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
306 else if (deathtype == DEATH_CAMP)
307 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
308 else if (deathtype == DEATH_MIRRORDAMAGE)
309 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
310 else if (deathtype == DEATH_CHEAT)
311 bprint ("^1",s, "^1 unfairly eliminated themself\n");
312 else if (deathtype == DEATH_FIRE)
313 bprint ("^1",s, "^1 burned to death\n");
314 else if (deathtype != DEATH_TEAMCHANGE)
315 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
317 if(deathtype != DEATH_TEAMCHANGE)
319 LogDeath("suicide", deathtype, targ, targ);
320 GiveFrags(attacker, targ, -1);
322 if (targ.killcount > 2)
323 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
326 else if (attacker.classname == "player" || attacker.classname == "gib")
328 if(teams_matter && attacker.team == targ.team)
331 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
332 bprint ("^1", a, "^1 took action against a team mate\n");
334 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
335 bprint ("^1", a, "^1 mows down a team mate\n");
337 GiveFrags(attacker, targ, -1);
338 if (targ.killcount > 2) {
340 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
342 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
344 if (attacker.killcount > 2) {
346 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
348 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
350 attacker.killcount = 0;
352 LogDeath("tk", deathtype, attacker, targ);
356 string blood_message, victim_message;
357 if (!checkrules_firstblood)
359 checkrules_firstblood = TRUE;
362 bprint("^1",a, "^1 was the first to score", "\n");
363 blood_message = "^1First point\n";
364 //victim_message = "^1First victim\n"; // or First casualty
368 bprint("^1",a, "^1 drew first blood", "\n");
369 blood_message = "^1First blood\n";
370 victim_message = "^1First victim\n"; // or First casualty
374 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You scored against ^7", s, GetAdvancedDeathReports(targ)));
375 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7", GetAdvancedDeathReports(attacker)));
377 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
378 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^1You typefragged ^7", s, GetAdvancedDeathReports(targ)));
379 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typefragged by ^7", a, GetAdvancedDeathReports(attacker)));
381 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s, GetAdvancedDeathReports(targ)));
382 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a, GetAdvancedDeathReports(attacker)));
384 attacker.taunt_soundtime = time + 1;
388 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
390 w = DEATH_WEAPONOF(deathtype);
393 w_deathtypestring = "was blasted by";
394 w_deathtype = deathtype;
395 weapon_action(w, WR_KILLMESSAGE);
396 p = strstrofs(w_deathtypestring, "#", 0);
398 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
400 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
402 else if (deathtype == DEATH_TELEFRAG)
403 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
404 else if (deathtype == DEATH_DROWN)
405 bprint ("^1",s, "^1 was drowned by ", a, "\n");
406 else if (deathtype == DEATH_SLIME)
407 bprint ("^1",s, "^1 was slimed by ", a, "\n");
408 else if (deathtype == DEATH_LAVA)
409 bprint ("^1",s, "^1 was cooked by ", a, "\n");
410 else if (deathtype == DEATH_FALL)
411 bprint ("^1",s, "^1 was grounded by ", a, "\n");
412 else if (deathtype == DEATH_SHOOTING_STAR)
413 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
414 else if (deathtype == DEATH_SWAMP)
415 bprint ("^1",s, "^1 was conserved by ", a, "\n");
416 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
418 p = strstrofs(inflictor.message2, "#", 0);
420 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
422 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
424 else if(deathtype == DEATH_SBCRUSH)
425 bprint ("^1",s, "^1 was crushed by ^1", a, "\n");
426 else if(deathtype == DEATH_SBMINIGUN)
427 bprint ("^1",s, "^1 got shredded by ^1", a, "\n");
428 else if(deathtype == DEATH_SBROCKET)
429 bprint ("^1",s, "^1 was blased to bits by ^1", a, "\n");
430 else if(deathtype == DEATH_SBBLOWUP)
431 bprint ("^1",s, "^1 got cought in the destruction of ^1", a, "'s vehicle\n");
433 else if(deathtype == DEATH_WAKIGUN)
434 bprint ("^1",s, "^1 was bolted down by ^1", a, "\n");
435 else if(deathtype == DEATH_WAKIROCKET)
436 bprint ("^1",s, "^1 could find no shelter from ^1", a, "'s rockets\n");
437 else if(deathtype == DEATH_WAKIBLOWUP)
438 bprint ("^1",s, "^1 dies when ^1", a, "'s wakizashi dies.\n");
440 else if(deathtype == DEATH_TURRET)
441 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
442 else if(deathtype == DEATH_TOUCHEXPLODE)
443 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
444 else if(deathtype == DEATH_CHEAT)
445 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
446 else if (deathtype == DEATH_FIRE)
447 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
448 else if (deathtype == DEATH_CUSTOM)
449 bprint ("^1",s, "^1 ", deathmessage, " by ^1", a, "\n");
451 bprint ("^1",s, "^1 was fragged by ", a, "\n");
454 if(g_ctf && targ.flagcarried)
456 UpdateFrags(attacker, ctf_score_value("score_kill"));
457 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
458 GiveFrags(attacker, targ, 0); // for logging
461 GiveFrags(attacker, targ, 1);
463 if (targ.killcount > 2) {
465 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
467 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
470 attacker.killcount = attacker.killcount + 1;
472 if (attacker.killcount > 2) {
474 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
476 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
479 LogDeath("frag", deathtype, attacker, targ);
481 if (attacker.killcount == 3)
484 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
486 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
487 announce(attacker, "announcer/male/03kills.wav");
490 else if (attacker.killcount == 5)
493 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
495 bprint (a,"^7 unleashes ^1RAGE\n");
496 announce(attacker, "announcer/male/05kills.wav");
499 else if (attacker.killcount == 10)
502 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
504 bprint (a,"^7 starts the ^1MASSACRE!\n");
505 announce(attacker, "announcer/male/10kills.wav");
508 else if (attacker.killcount == 15)
511 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
513 bprint (a,"^7 executes ^1MAYHEM!\n");
514 announce(attacker, "announcer/male/15kills.wav");
517 else if (attacker.killcount == 20)
520 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
522 bprint (a,"^7 is a ^1BERSERKER!\n");
523 announce(attacker, "announcer/male/20kills.wav");
526 else if (attacker.killcount == 25)
529 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
531 bprint (a,"^7 inflicts ^1CARNAGE!\n");
532 announce(attacker, "announcer/male/25kills.wav");
535 else if (attacker.killcount == 30)
538 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
540 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
541 announce(attacker, "announcer/male/30kills.wav");
548 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
549 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
550 bprint ("^1",s, "^1 ", inflictor.message, "\n");
551 else if (deathtype == DEATH_DROWN)
553 bprint ("^1",s, "^1 was in the water for too long\n");
555 bprint ("^1",s, "^1 drowned\n");
556 else if (deathtype == DEATH_SLIME)
557 bprint ("^1",s, "^1 was slimed\n");
558 else if (deathtype == DEATH_LAVA)
560 bprint ("^1",s, "^1 found a hot place\n");
562 bprint ("^1",s, "^1 turned into hot slag\n");
563 else if (deathtype == DEATH_FALL)
565 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
567 bprint ("^1",s, "^1 hit the ground with a crunch\n");
568 else if (deathtype == DEATH_SHOOTING_STAR)
569 bprint ("^1",s, "^1 became a shooting star\n");
570 else if (deathtype == DEATH_SWAMP)
572 bprint ("^1",s, "^1 discovered a swamp\n");
574 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
575 else if(deathtype == DEATH_TURRET)
576 bprint ("^1",s, "^1 was mowed down by a turret \n");
577 else if (deathtype == DEATH_CUSTOM)
578 bprint ("^1",s, "^1 ", deathmessage, "\n");
579 else if(deathtype == DEATH_TOUCHEXPLODE)
580 bprint ("^1",s, "^1 died in an accident\n");
581 else if(deathtype == DEATH_CHEAT)
582 bprint ("^1",s, "^1 was unfairly eliminated\n");
583 else if(deathtype == DEATH_FIRE)
585 bprint ("^1",s, "^1 felt a little hot\n");
587 bprint ("^1",s, "^1 burnt to death\n");
590 bprint ("^1",s, "^1 needs a restart\n");
592 bprint ("^1",s, "^1 died\n");
593 GiveFrags(targ, targ, -1);
594 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
595 announce(targ, "announcer/male/botlike.wav");
598 if (targ.killcount > 2)
600 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
602 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
604 LogDeath("accident", deathtype, targ, targ);
607 targ.death_origin = targ.origin;
609 targ.killer_origin = attacker.origin;
611 // FIXME: this should go in PutClientInServer
617 // these are updated by each Damage call for use in button triggering and such
619 entity damage_inflictor;
620 entity damage_attacker;
622 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
627 entity attacker_save;
631 if (gameover || targ.killcount == -666)
634 local entity oldself;
638 damage_inflictor = inflictor;
639 damage_attacker = attacker;
640 attacker_save = attacker;
642 if(targ.classname == "player")
645 if(targ.hook.aiment == attacker)
646 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
648 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
649 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
651 if(targ.classname == "player")
652 if not(IsDifferentTeam(targ, attacker))
659 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
661 // These are ALWAYS lethal
662 // No damage modification here
663 // Instead, prepare the victim for his death...
665 targ.spawnshieldtime = 0;
666 targ.health = 0.9; // this is < 1
667 targ.flags -= targ.flags & FL_GODMODE;
670 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
676 if (targ.classname == "player")
677 if (attacker.classname == "player")
680 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
682 // nullify damage if teamplay is on
683 if(deathtype != DEATH_TELEFRAG)
684 if(attacker.classname == "player")
686 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
691 else if(attacker.team == targ.team)
695 else if(attacker != targ)
699 else if(teamplay == 4)
701 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
703 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
704 attacker.dmg_team = attacker.dmg_team + damage;
705 if(attacker.dmg_team > teamdamage0 && !g_ca)
706 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
707 mirrorforce = cvar("g_mirrordamage") * vlen(force);
710 if(cvar("g_friendlyfire") == 0)
716 damage = cvar("g_friendlyfire") * damage;
717 // mirrordamage will be used LATER
726 if(targ.classname == "player")
727 if(attacker.classname == "player")
730 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
731 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
734 if(targ.classname == "player")
737 if ((deathtype == DEATH_FALL) ||
738 (deathtype == DEATH_DROWN) ||
739 (deathtype == DEATH_SLIME) ||
740 (deathtype == DEATH_LAVA))
745 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
747 targ.armorvalue -= 1;
748 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
751 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
753 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
756 if (targ != attacker)
758 if (targ.classname == "player")
759 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
769 if not(DEATH_ISSPECIAL(deathtype))
771 damage *= g_weapondamagefactor;
772 mirrordamage *= g_weapondamagefactor;
773 force = force * g_weaponforcefactor;
774 mirrorforce *= g_weaponforcefactor;
777 // apply strength multiplier
778 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
782 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
783 force = force * cvar("g_balance_powerup_strength_selfforce");
787 damage = damage * cvar("g_balance_powerup_strength_damage");
788 force = force * cvar("g_balance_powerup_strength_force");
792 // apply invincibility multiplier
793 if (targ.items & IT_INVINCIBLE && !g_minstagib)
794 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
796 if (targ == attacker)
801 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
804 // CTF: reduce damage/force
809 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
810 force = force * cvar("g_ctf_flagcarrier_selfforce");
815 // apply strength rune
816 if (attacker.runes & RUNE_STRENGTH)
818 if(attacker.runes & CURSE_WEAK) // have both curse & rune
820 damage = damage * cvar("g_balance_rune_strength_combo_damage");
821 force = force * cvar("g_balance_rune_strength_combo_force");
825 damage = damage * cvar("g_balance_rune_strength_damage");
826 force = force * cvar("g_balance_rune_strength_force");
829 else if (attacker.runes & CURSE_WEAK)
831 damage = damage * cvar("g_balance_curse_weak_damage");
832 force = force * cvar("g_balance_curse_weak_force");
835 // apply defense rune
836 if (targ.runes & RUNE_DEFENSE)
838 if (targ.runes & CURSE_VULNER) // have both curse & rune
839 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
841 damage = damage * cvar("g_balance_rune_defense_takedamage");
843 else if (targ.runes & CURSE_VULNER)
844 damage = damage * cvar("g_balance_curse_vulner_takedamage");
850 if(targ.takedamage == DAMAGE_AIM)
853 if(targ.classname == "player")
856 // find height of hit on player axis
857 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
858 vector headmins, headmaxs, org;
859 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
860 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);
861 headmaxs = org + '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
862 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
864 deathtype |= HITTYPE_HEADSHOT;
867 else if(targ.classname == "turret_head")
869 deathtype |= HITTYPE_HEADSHOT;
871 if(deathtype & HITTYPE_HEADSHOT)
872 damage *= 1 + damage_headshotbonus;
874 if(targ.classname == "player")
876 if(IsDifferentTeam(targ, attacker))
881 attacker.typehitsound += 1;
883 attacker.hitsound += 1;
885 damage_goodhits += 1;
886 damage_gooddamage += damage;
888 if not(DEATH_ISSPECIAL(deathtype))
895 if(targ.items & IT_STRENGTH)
898 if(deathtype & HITTYPE_HEADSHOT)
905 if(deathtype != DEATH_FIRE)
906 attacker.typehitsound += 1;
908 if(time > attacker.teamkill_complain)
910 attacker.teamkill_complain = time + 5;
911 attacker.teamkill_soundtime = time + 0.4;
912 attacker.teamkill_soundsource = targ;
920 if (self.damageforcescale)
922 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
924 self.velocity = self.velocity + self.damageforcescale * force;
925 self.flags &~= FL_ONGROUND;
926 UpdateCSQCProjectile(self);
929 if (damage != 0 || (self.damageforcescale && vlen(force)))
930 if (self.event_damage)
931 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
934 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
936 // Savage: vampire mode
939 if (time >= self.spawnshieldtime)
941 attacker.health += damage;
945 if (attacker.runes & RUNE_VAMPIRE)
947 // apply vampire rune
948 if (attacker.runes & CURSE_EMPATHY) // have the curse too
950 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
951 attacker.health = bound(
952 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
953 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
954 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
958 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
959 attacker.health = bound(
960 attacker.health, // LA: was 3, but changed so that you can't lose health
961 // empathy won't let you gain health in the same way...
962 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
963 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
966 // apply empathy curse
967 else if (attacker.runes & CURSE_EMPATHY)
969 attacker.health = bound(
970 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
971 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
977 // apply mirror damage if any
978 if(mirrordamage > 0 || mirrorforce > 0)
980 attacker = attacker_save;
984 // just lose extra LIVES, don't kill the player for mirror damage
985 if(attacker.armorvalue > 0)
987 attacker.armorvalue = attacker.armorvalue - 1;
988 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
989 attacker.hitsound += 1;
993 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
994 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
998 vector NearestPointOnBox(entity box, vector org)
1000 vector m1, m2, nearest;
1002 m1 = box.mins + box.origin;
1003 m2 = box.maxs + box.origin;
1005 nearest_x = bound(m1_x, org_x, m2_x);
1006 nearest_y = bound(m1_y, org_y, m2_y);
1007 nearest_z = bound(m1_z, org_z, m2_z);
1012 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
1015 weaponid = DEATH_WEAPONOF(deathtype);
1017 if not(inWarmupStage)
1019 if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {
1020 attacker.stats_hit[weaponid - 1] += damage;
1021 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);
1025 float RadiusDamage_running;
1026 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
1027 // Returns total damage applies to creatures
1037 float total_damage_to_creatures;
1042 float stat_damagedone;
1043 float stat_maxdamage;
1045 if(RadiusDamage_running)
1048 print("RadiusDamage called recursively!\n");
1049 print("Expect stuff to go HORRIBLY wrong.\n");
1050 print("Causing a stack trace...\n");
1051 save = cvar_string("prvm_backtraceforwarnings");
1052 cvar_set("prvm_backtraceforwarnings", "1");
1053 fclose(-1); // calls VM_Warning
1054 cvar_set("prvm_backtraceforwarnings", save);
1058 RadiusDamage_running = 1;
1060 tfloordmg = cvar("g_throughfloor_damage");
1061 tfloorforce = cvar("g_throughfloor_force");
1063 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1064 total_damage_to_creatures = 0;
1066 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1068 force = inflictor.velocity;
1069 if(vlen(force) == 0)
1072 force = normalize(force);
1073 if(forceintensity >= 0)
1074 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1076 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1079 stat_damagedone = 0;
1082 targ = findradius (blastorigin, rad);
1086 if (targ != inflictor)
1087 if (ignore != targ) if(targ.takedamage)
1089 // LordHavoc: measure distance to nearest point on target (not origin)
1090 // (this guarentees 100% damage on a touch impact)
1091 nearest = NearestPointOnBox(targ, blastorigin);
1092 diff = nearest - blastorigin;
1093 // round up a little on the damage to ensure full damage on impacts
1094 // and turn the distance into a fraction of the radius
1095 power = 1 - ((vlen (diff) - 2) / rad);
1097 //bprint(ftos(power));
1098 //if (targ == attacker)
1099 // print(ftos(power), "\n");
1104 finaldmg = coredamage * power + edgedamage * (1 - power);
1111 local float hitratio;
1112 local vector hitloc;
1113 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1114 // if it's a player, use the view origin as reference
1115 if (targ.classname == "player")
1116 center = targ.origin + targ.view_ofs;
1117 force = normalize(center - blastorigin);
1118 force = force * (finaldmg / coredamage) * forceintensity;
1119 // test line of sight to multiple positions on box,
1120 // and do damage if any of them hit
1122 if (targ.classname == "player")
1123 total = ceil(bound(1, finaldmg, 50));
1125 total = ceil(bound(1, finaldmg/10, 5));
1130 traceline(blastorigin, nearest, MOVE_NOMONSTERS, inflictor);
1131 if (trace_fraction == 1 || trace_ent == targ)
1135 hitloc = hitloc + nearest;
1139 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1140 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1141 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1144 nearest = hitloc * (1 / max(1, hits));
1145 hitratio = (hits / total);
1146 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1147 finaldmg = finaldmg * a;
1148 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1150 //if (targ == attacker)
1152 // print("hits ", ftos(hits), " / ", ftos(total));
1153 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1154 // print(" (", ftos(a), ")\n");
1156 if(hits || tfloordmg || tfloorforce)
1160 total_damage_to_creatures += finaldmg;
1162 if(targ.flags & FL_CLIENT)
1163 if(targ.deadflag == DEAD_NO)
1164 if(targ != attacker)
1165 if(!teamplay || targ.team != attacker.team)
1167 stat_damagedone += finaldmg;
1168 stat_maxdamage += coredamage;
1172 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1173 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1175 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1183 RadiusDamage_running = 0;
1185 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1187 return total_damage_to_creatures;
1190 .float fire_damagepersec;
1191 .float fire_endtime;
1192 .float fire_deathtype;
1194 .float fire_hitsound;
1195 .entity fire_burner;
1197 void fireburner_think();
1199 float Fire_IsBurning(entity e)
1201 return (time < e.fire_endtime);
1204 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1207 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1209 if(e.classname == "player")
1218 // print("adding a fire burner to ", e.classname, "\n");
1219 e.fire_burner = spawn();
1220 e.fire_burner.classname = "fireburner";
1221 e.fire_burner.think = fireburner_think;
1222 e.fire_burner.nextthink = time;
1223 e.fire_burner.owner = e;
1229 if(Fire_IsBurning(e))
1231 mintime = e.fire_endtime - time;
1232 maxtime = max(mintime, t);
1234 mindps = e.fire_damagepersec;
1235 maxdps = max(mindps, dps);
1237 if(maxtime > mintime || maxdps > mindps)
1239 mindamage = mindps * mintime;
1240 maxdamage = mindamage + d;
1242 // interval [mintime, maxtime] * [mindps, maxdps]
1244 // [mindamage, maxdamage]
1247 if(maxdamage >= maxtime * maxdps)
1249 totaltime = maxtime;
1250 totaldamage = maxtime * maxdps;
1252 // this branch increases totaldamage if either t > mintime, or dps > mindps
1256 // maxdamage is inside the interval!
1257 // first, try to use mindps; only if this fails, increase dps as needed
1258 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1259 totaldamage = maxdamage;
1260 // can totaldamage / totaltime be >= maxdps?
1261 // max(mindps, maxdamage / maxtime) >= maxdps?
1262 // we know maxdamage < maxtime * maxdps
1265 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1268 // total conditions for increasing:
1269 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1271 // if maxtime = mintime, maxdps = mindps
1273 // maxdamage = mindamage + d
1274 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1275 // so the last condition is not needed
1277 e.fire_damagepersec = totaldamage / totaltime;
1278 e.fire_endtime = time + totaltime;
1279 if(totaldamage > 1.2 * mindamage)
1281 e.fire_deathtype = dt;
1282 if(e.fire_owner != o)
1285 e.fire_hitsound = FALSE;
1288 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1295 e.fire_damagepersec = dps;
1296 e.fire_endtime = time + t;
1297 e.fire_deathtype = dt;
1299 e.fire_hitsound = FALSE;
1304 void Fire_ApplyDamage(entity e)
1308 if not(Fire_IsBurning(e))
1311 // water and slime stop fire
1313 if(e.watertype != CONTENT_LAVA)
1316 t = min(frametime, e.fire_endtime - time);
1317 d = e.fire_damagepersec * t;
1319 hi = e.fire_owner.hitsound;
1320 ty = e.fire_owner.typehitsound;
1321 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1322 if(e.fire_hitsound && e.fire_owner)
1324 e.fire_owner.hitsound = hi;
1325 e.fire_owner.typehitsound = ty;
1327 e.fire_hitsound = TRUE;
1329 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1331 if not(IS_INDEPENDENT_PLAYER(e))
1332 FOR_EACH_PLAYER(other) if(e != other)
1334 if(other.classname == "player")
1335 if(other.deadflag == DEAD_NO)
1336 if not(IS_INDEPENDENT_PLAYER(other))
1337 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1339 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1340 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1341 Fire_AddDamage(other, e, d, t, DEATH_FIRE);
1346 void Fire_ApplyEffect(entity e)
1348 if(Fire_IsBurning(e))
1349 e.effects |= EF_FLAME;
1351 e.effects &~= EF_FLAME;
1354 void fireburner_think()
1356 // for players, this is done in the regular loop
1357 if(wasfreed(self.owner))
1362 Fire_ApplyEffect(self.owner);
1363 if(!Fire_IsBurning(self.owner))
1365 self.owner.fire_burner = world;
1369 Fire_ApplyDamage(self.owner);
1370 self.nextthink = time;