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!)
152 frag_attacker = attacker;
155 if(MUTATOR_CALLHOOK(GiveFragsForKill))
165 f = RunematchHandleFrags(attacker, targ, f);
171 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
172 if(tl < lms_lowest_lives)
173 lms_lowest_lives = tl;
177 lms_next_place = player_count;
178 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
185 if(g_ctf_ignore_frags)
190 attacker.totalfrags += f;
193 UpdateFrags(attacker, f);
196 string AppendItemcodes(string s, entity player)
201 // w = player.switchweapon;
203 w = player.cnt; // previous weapon!
204 s = strcat(s, ftos(w));
205 if(time < player.strength_finished)
207 if(time < player.invincible_finished)
209 if(player.flagcarried != world)
211 if(player.BUTTON_CHAT)
216 s = strcat(s, "|", ftos(player.runes));
220 void LogDeath(string mode, float deathtype, entity killer, entity killed)
223 if(!cvar("sv_eventlog"))
225 s = strcat(":kill:", mode);
226 s = strcat(s, ":", ftos(killer.playerid));
227 s = strcat(s, ":", ftos(killed.playerid));
228 s = strcat(s, ":type=", ftos(deathtype));
229 s = strcat(s, ":items=");
230 s = AppendItemcodes(s, killer);
233 s = strcat(s, ":victimitems=");
234 s = AppendItemcodes(s, killed);
239 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
244 if (targ.classname == "player" || targ.classname == "corpse")
246 if (targ.classname == "corpse")
251 a = attacker.netname;
253 if (targ == attacker)
255 if (deathtype == DEATH_TEAMCHANGE) {
256 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
257 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
258 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)));
260 } else if (deathtype == DEATH_CAMP) {
262 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
264 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
265 } else if (deathtype == DEATH_NOAMMO) {
267 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
269 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
270 } else if (deathtype == DEATH_ROT) {
272 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
274 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
275 } else if (deathtype == DEATH_MIRRORDAMAGE) {
277 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
279 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
280 } else if (deathtype == DEATH_QUIET) {
284 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
286 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
289 if (deathtype == DEATH_CAMP)
290 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
291 else if (deathtype == DEATH_MIRRORDAMAGE)
292 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
294 bprint ("^1",s, "^1 will be reinserted into the game due to their own actions\n");
296 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
298 LogDeath("suicide", deathtype, targ, targ);
299 GiveFrags(attacker, targ, -1);
301 if (targ.killcount > 2)
302 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
304 w = DEATH_WEAPONOF(deathtype);
307 w_deathtypestring = "couldn't resist the urge to self-destruct";
308 w_deathtype = deathtype;
309 weapon_action(w, WR_SUICIDEMESSAGE);
310 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
312 else if (deathtype == DEATH_KILL)
313 bprint ("^1",s, "^1 couldn't take it anymore\n");
314 else if (deathtype == DEATH_ROT)
315 bprint ("^1",s, "^1 died\n");
316 else if (deathtype == DEATH_NOAMMO)
317 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
318 else if (deathtype == DEATH_CAMP)
319 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
320 else if (deathtype == DEATH_MIRRORDAMAGE)
321 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
322 else if (deathtype == DEATH_CHEAT)
323 bprint ("^1",s, "^1 unfairly eliminated themself\n");
324 else if (deathtype == DEATH_FIRE)
325 bprint ("^1",s, "^1 burned to death\n");
326 else if (deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
327 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
329 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
331 LogDeath("suicide", deathtype, targ, targ);
332 GiveFrags(attacker, targ, -1);
334 if (targ.killcount > 2)
335 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
338 else if (attacker.classname == "player" || attacker.classname == "gib")
340 if(teams_matter && attacker.team == targ.team)
343 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
344 bprint ("^1", a, "^1 took action against a team mate\n");
346 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
347 bprint ("^1", a, "^1 mows down a team mate\n");
349 GiveFrags(attacker, targ, -1);
350 if (targ.killcount > 2) {
352 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
354 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
356 if (attacker.killcount > 2) {
358 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
360 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
362 attacker.killcount = 0;
364 LogDeath("tk", deathtype, attacker, targ);
368 string blood_message, victim_message;
369 if (!checkrules_firstblood)
371 checkrules_firstblood = TRUE;
374 bprint("^1",a, "^1 was the first to score", "\n");
375 blood_message = "^1First point\n";
376 //victim_message = "^1First victim\n"; // or First casualty
380 bprint("^1",a, "^1 drew first blood", "\n");
381 blood_message = "^1First blood\n";
382 victim_message = "^1First victim\n"; // or First casualty
386 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You scored against ^7", s, GetAdvancedDeathReports(targ)));
387 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7", GetAdvancedDeathReports(attacker)));
389 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
390 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^1You typefragged ^7", s, GetAdvancedDeathReports(targ)));
391 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typefragged by ^7", a, GetAdvancedDeathReports(attacker)));
393 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s, GetAdvancedDeathReports(targ)));
394 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a, GetAdvancedDeathReports(attacker)));
396 attacker.taunt_soundtime = time + 1;
400 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
402 w = DEATH_WEAPONOF(deathtype);
405 w_deathtypestring = "was blasted by";
406 w_deathtype = deathtype;
407 weapon_action(w, WR_KILLMESSAGE);
408 p = strstrofs(w_deathtypestring, "#", 0);
410 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
412 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
414 else if (deathtype == DEATH_TELEFRAG)
415 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
416 else if (deathtype == DEATH_DROWN)
417 bprint ("^1",s, "^1 was drowned by ", a, "\n");
418 else if (deathtype == DEATH_SLIME)
419 bprint ("^1",s, "^1 was slimed by ", a, "\n");
420 else if (deathtype == DEATH_LAVA)
421 bprint ("^1",s, "^1 was cooked by ", a, "\n");
422 else if (deathtype == DEATH_FALL)
423 bprint ("^1",s, "^1 was grounded by ", a, "\n");
424 else if (deathtype == DEATH_SHOOTING_STAR)
425 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
426 else if (deathtype == DEATH_SWAMP)
427 bprint ("^1",s, "^1 was conserved by ", a, "\n");
428 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
430 p = strstrofs(inflictor.message2, "#", 0);
432 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
434 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
436 else if(deathtype == DEATH_SBCRUSH)
437 bprint ("^1",s, "^1 was crushed by ^1", a, "\n");
438 else if(deathtype == DEATH_SBMINIGUN)
439 bprint ("^1",s, "^1 got shredded by ^1", a, "\n");
440 else if(deathtype == DEATH_SBROCKET)
441 bprint ("^1",s, "^1 was blased to bits by ^1", a, "\n");
442 else if(deathtype == DEATH_SBBLOWUP)
443 bprint ("^1",s, "^1 got cought in the destruction of ^1", a, "'s vehicle\n");
445 else if(deathtype == DEATH_WAKIGUN)
446 bprint ("^1",s, "^1 was bolted down by ^1", a, "\n");
447 else if(deathtype == DEATH_WAKIROCKET)
448 bprint ("^1",s, "^1 could find no shelter from ^1", a, "'s rockets\n");
449 else if(deathtype == DEATH_WAKIBLOWUP)
450 bprint ("^1",s, "^1 dies when ^1", a, "'s wakizashi dies.\n");
452 else if(deathtype == DEATH_TURRET)
453 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
454 else if(deathtype == DEATH_TOUCHEXPLODE)
455 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
456 else if(deathtype == DEATH_CHEAT)
457 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
458 else if (deathtype == DEATH_FIRE)
459 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
460 else if (deathtype == DEATH_CUSTOM)
461 bprint ("^1",s, "^1 ", deathmessage, " by ^1", a, "\n");
463 bprint ("^1",s, "^1 was fragged by ", a, "\n");
466 if(g_ctf && targ.flagcarried)
468 UpdateFrags(attacker, ctf_score_value("score_kill"));
469 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
470 GiveFrags(attacker, targ, 0); // for logging
473 GiveFrags(attacker, targ, 1);
475 if (targ.killcount > 2) {
477 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
479 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
482 attacker.killcount = attacker.killcount + 1;
484 if (attacker.killcount > 2) {
486 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
488 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
491 LogDeath("frag", deathtype, attacker, targ);
493 if (attacker.killcount == 3)
496 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
498 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
499 AnnounceTo(attacker, "03kills");
502 else if (attacker.killcount == 5)
505 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
507 bprint (a,"^7 unleashes ^1RAGE\n");
508 AnnounceTo(attacker, "05kills");
511 else if (attacker.killcount == 10)
514 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
516 bprint (a,"^7 starts the ^1MASSACRE!\n");
517 AnnounceTo(attacker, "10kills");
520 else if (attacker.killcount == 15)
523 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
525 bprint (a,"^7 executes ^1MAYHEM!\n");
526 AnnounceTo(attacker, "15kills");
529 else if (attacker.killcount == 20)
532 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
534 bprint (a,"^7 is a ^1BERSERKER!\n");
535 AnnounceTo(attacker, "20kills");
538 else if (attacker.killcount == 25)
541 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
543 bprint (a,"^7 inflicts ^1CARNAGE!\n");
544 AnnounceTo(attacker, "25kills");
547 else if (attacker.killcount == 30)
550 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
552 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
553 AnnounceTo(attacker, "30kills");
560 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
561 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
562 bprint ("^1",s, "^1 ", inflictor.message, "\n");
563 else if (deathtype == DEATH_DROWN)
565 bprint ("^1",s, "^1 was in the water for too long\n");
567 bprint ("^1",s, "^1 drowned\n");
568 else if (deathtype == DEATH_SLIME)
569 bprint ("^1",s, "^1 was slimed\n");
570 else if (deathtype == DEATH_LAVA)
572 bprint ("^1",s, "^1 found a hot place\n");
574 bprint ("^1",s, "^1 turned into hot slag\n");
575 else if (deathtype == DEATH_FALL)
577 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
579 bprint ("^1",s, "^1 hit the ground with a crunch\n");
580 else if (deathtype == DEATH_SHOOTING_STAR)
581 bprint ("^1",s, "^1 became a shooting star\n");
582 else if (deathtype == DEATH_SWAMP)
584 bprint ("^1",s, "^1 discovered a swamp\n");
586 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
587 else if(deathtype == DEATH_TURRET)
588 bprint ("^1",s, "^1 was mowed down by a turret \n");
589 else if (deathtype == DEATH_CUSTOM)
590 bprint ("^1",s, "^1 ", deathmessage, "\n");
591 else if(deathtype == DEATH_TOUCHEXPLODE)
592 bprint ("^1",s, "^1 died in an accident\n");
593 else if(deathtype == DEATH_CHEAT)
594 bprint ("^1",s, "^1 was unfairly eliminated\n");
595 else if(deathtype == DEATH_FIRE)
597 bprint ("^1",s, "^1 felt a little hot\n");
599 bprint ("^1",s, "^1 burnt to death\n");
602 bprint ("^1",s, "^1 needs a restart\n");
604 bprint ("^1",s, "^1 died\n");
605 GiveFrags(targ, targ, -1);
606 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
607 AnnounceTo(targ, "botlike");
610 if (targ.killcount > 2)
612 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
614 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
616 LogDeath("accident", deathtype, targ, targ);
619 targ.death_origin = targ.origin;
621 targ.killer_origin = attacker.origin;
623 // FIXME: this should go in PutClientInServer
629 // these are updated by each Damage call for use in button triggering and such
631 entity damage_inflictor;
632 entity damage_attacker;
634 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
639 entity attacker_save;
643 if (gameover || targ.killcount == -666)
646 local entity oldself;
650 damage_inflictor = inflictor;
651 damage_attacker = attacker;
652 attacker_save = attacker;
654 if(targ.classname == "player")
657 if(targ.hook.aiment == attacker)
658 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
660 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
661 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
663 if(targ.classname == "player")
664 if not(IsDifferentTeam(targ, attacker))
671 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
673 // These are ALWAYS lethal
674 // No damage modification here
675 // Instead, prepare the victim for his death...
677 targ.spawnshieldtime = 0;
678 targ.health = 0.9; // this is < 1
679 targ.flags -= targ.flags & FL_GODMODE;
682 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
688 if (targ.classname == "player")
689 if (attacker.classname == "player")
692 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
694 // nullify damage if teamplay is on
695 if(deathtype != DEATH_TELEFRAG)
696 if(attacker.classname == "player")
698 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
703 else if(attacker.team == targ.team)
707 else if(attacker != targ)
711 else if(teamplay == 4)
713 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
715 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
716 attacker.dmg_team = attacker.dmg_team + damage;
717 if(attacker.dmg_team > teamdamage0 && !g_ca)
718 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
719 mirrorforce = cvar("g_mirrordamage") * vlen(force);
722 if(cvar("g_friendlyfire") == 0)
728 damage = cvar("g_friendlyfire") * damage;
729 // mirrordamage will be used LATER
738 if(targ.classname == "player")
739 if(attacker.classname == "player")
742 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
743 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
746 if(targ.classname == "player")
749 if ((deathtype == DEATH_FALL) ||
750 (deathtype == DEATH_DROWN) ||
751 (deathtype == DEATH_SLIME) ||
752 (deathtype == DEATH_LAVA) ||
753 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
760 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
762 targ.armorvalue -= 1;
763 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
766 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
768 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
771 if (targ != attacker)
773 if ((targ.health >= 1) && (targ.classname == "player"))
774 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
784 if not(DEATH_ISSPECIAL(deathtype))
786 damage *= g_weapondamagefactor;
787 mirrordamage *= g_weapondamagefactor;
788 force = force * g_weaponforcefactor;
789 mirrorforce *= g_weaponforcefactor;
792 // apply strength multiplier
793 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
797 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
798 force = force * cvar("g_balance_powerup_strength_selfforce");
802 damage = damage * cvar("g_balance_powerup_strength_damage");
803 force = force * cvar("g_balance_powerup_strength_force");
807 // apply invincibility multiplier
808 if (targ.items & IT_INVINCIBLE && !g_minstagib)
809 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
811 if (targ == attacker)
813 if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))
816 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
819 // CTF: reduce damage/force
824 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
825 force = force * cvar("g_ctf_flagcarrier_selfforce");
830 // apply strength rune
831 if (attacker.runes & RUNE_STRENGTH)
833 if(attacker.runes & CURSE_WEAK) // have both curse & rune
835 damage = damage * cvar("g_balance_rune_strength_combo_damage");
836 force = force * cvar("g_balance_rune_strength_combo_force");
840 damage = damage * cvar("g_balance_rune_strength_damage");
841 force = force * cvar("g_balance_rune_strength_force");
844 else if (attacker.runes & CURSE_WEAK)
846 damage = damage * cvar("g_balance_curse_weak_damage");
847 force = force * cvar("g_balance_curse_weak_force");
850 // apply defense rune
851 if (targ.runes & RUNE_DEFENSE)
853 if (targ.runes & CURSE_VULNER) // have both curse & rune
854 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
856 damage = damage * cvar("g_balance_rune_defense_takedamage");
858 else if (targ.runes & CURSE_VULNER)
859 damage = damage * cvar("g_balance_curse_vulner_takedamage");
865 if(targ.takedamage == DAMAGE_AIM)
868 if(targ.classname == "player")
871 // find height of hit on player axis
872 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
873 vector headmins, headmaxs, org;
874 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
875 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);
876 headmaxs = org + '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
877 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
879 deathtype |= HITTYPE_HEADSHOT;
882 else if(targ.classname == "turret_head")
884 deathtype |= HITTYPE_HEADSHOT;
886 if(deathtype & HITTYPE_HEADSHOT)
887 damage *= 1 + damage_headshotbonus;
889 if(targ.classname == "player")
891 if(IsDifferentTeam(targ, attacker))
896 attacker.typehitsound += 1;
898 attacker.hitsound += 1;
900 damage_goodhits += 1;
901 damage_gooddamage += damage;
903 if not(DEATH_ISSPECIAL(deathtype))
910 if(targ.items & IT_STRENGTH)
913 if(deathtype & HITTYPE_HEADSHOT)
920 if(deathtype != DEATH_FIRE)
921 attacker.typehitsound += 1;
923 if(time > attacker.teamkill_complain)
925 attacker.teamkill_complain = time + 5;
926 attacker.teamkill_soundtime = time + 0.4;
927 attacker.teamkill_soundsource = targ;
935 if (self.damageforcescale)
937 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
939 self.velocity = self.velocity + self.damageforcescale * force;
940 self.flags &~= FL_ONGROUND;
941 UpdateCSQCProjectile(self);
944 if (damage != 0 || (self.damageforcescale && vlen(force)))
945 if (self.event_damage)
946 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
949 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
951 // Savage: vampire mode
954 if (time >= self.spawnshieldtime)
956 attacker.health += damage;
960 if (attacker.runes & RUNE_VAMPIRE)
962 // apply vampire rune
963 if (attacker.runes & CURSE_EMPATHY) // have the curse too
965 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
966 attacker.health = bound(
967 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
968 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
969 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
973 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
974 attacker.health = bound(
975 attacker.health, // LA: was 3, but changed so that you can't lose health
976 // empathy won't let you gain health in the same way...
977 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
978 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
981 // apply empathy curse
982 else if (attacker.runes & CURSE_EMPATHY)
984 attacker.health = bound(
985 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
986 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
992 // apply mirror damage if any
993 if(mirrordamage > 0 || mirrorforce > 0)
995 attacker = attacker_save;
999 // just lose extra LIVES, don't kill the player for mirror damage
1000 if(attacker.armorvalue > 0)
1002 attacker.armorvalue = attacker.armorvalue - 1;
1003 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
1004 attacker.hitsound += 1;
1008 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
1009 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
1013 vector NearestPointOnBox(entity box, vector org)
1015 vector m1, m2, nearest;
1017 m1 = box.mins + box.origin;
1018 m2 = box.maxs + box.origin;
1020 nearest_x = bound(m1_x, org_x, m2_x);
1021 nearest_y = bound(m1_y, org_y, m2_y);
1022 nearest_z = bound(m1_z, org_z, m2_z);
1027 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
1030 weaponid = DEATH_WEAPONOF(deathtype);
1032 if not(inWarmupStage)
1034 if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {
1035 attacker.stats_hit[weaponid - 1] += damage;
1036 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);
1040 float RadiusDamage_running;
1041 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
1042 // Returns total damage applies to creatures
1052 float total_damage_to_creatures;
1057 float stat_damagedone;
1058 float stat_maxdamage;
1060 if(RadiusDamage_running)
1063 print("RadiusDamage called recursively!\n");
1064 print("Expect stuff to go HORRIBLY wrong.\n");
1065 print("Causing a stack trace...\n");
1066 save = cvar_string("prvm_backtraceforwarnings");
1067 cvar_set("prvm_backtraceforwarnings", "1");
1068 fclose(-1); // calls VM_Warning
1069 cvar_set("prvm_backtraceforwarnings", save);
1073 RadiusDamage_running = 1;
1075 tfloordmg = cvar("g_throughfloor_damage");
1076 tfloorforce = cvar("g_throughfloor_force");
1078 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1079 total_damage_to_creatures = 0;
1081 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1082 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
1084 force = inflictor.velocity;
1085 if(vlen(force) == 0)
1088 force = normalize(force);
1089 if(forceintensity >= 0)
1090 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1092 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1095 stat_damagedone = 0;
1098 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
1102 if (targ != inflictor)
1103 if (ignore != targ) if(targ.takedamage)
1105 // LordHavoc: measure distance to nearest point on target (not origin)
1106 // (this guarentees 100% damage on a touch impact)
1107 nearest = targ.WarpZone_findradius_nearest;
1108 diff = targ.WarpZone_findradius_dist;
1109 // round up a little on the damage to ensure full damage on impacts
1110 // and turn the distance into a fraction of the radius
1111 power = 1 - ((vlen (diff) - 2) / rad);
1113 //bprint(ftos(power));
1114 //if (targ == attacker)
1115 // print(ftos(power), "\n");
1120 finaldmg = coredamage * power + edgedamage * (1 - power);
1127 local float hitratio;
1128 local vector hitloc;
1129 local vector myblastorigin;
1130 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1131 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1132 // if it's a player, use the view origin as reference
1133 if (targ.classname == "player")
1134 center = targ.origin + targ.view_ofs;
1135 force = normalize(center - myblastorigin);
1136 force = force * (finaldmg / coredamage) * forceintensity;
1137 // test line of sight to multiple positions on box,
1138 // and do damage if any of them hit
1140 if (targ.classname == "player")
1141 total = ceil(bound(1, finaldmg, 50));
1143 total = ceil(bound(1, finaldmg/10, 5));
1148 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1149 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1150 if (trace_fraction == 1 || trace_ent == targ)
1154 hitloc = hitloc + nearest;
1158 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1159 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1160 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1163 nearest = hitloc * (1 / max(1, hits));
1164 hitratio = (hits / total);
1165 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1166 finaldmg = finaldmg * a;
1167 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1169 //if (targ == attacker)
1171 // print("hits ", ftos(hits), " / ", ftos(total));
1172 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1173 // print(" (", ftos(a), ")\n");
1175 if(hits || tfloordmg || tfloorforce)
1179 total_damage_to_creatures += finaldmg;
1181 if(targ.flags & FL_CLIENT)
1182 if(targ.deadflag == DEAD_NO)
1183 if(targ != attacker)
1184 if(!teamplay || targ.team != attacker.team)
1186 stat_damagedone += finaldmg;
1187 stat_maxdamage += coredamage;
1191 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1192 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1194 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1202 RadiusDamage_running = 0;
1204 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1206 return total_damage_to_creatures;
1209 .float fire_damagepersec;
1210 .float fire_endtime;
1211 .float fire_deathtype;
1213 .float fire_hitsound;
1214 .entity fire_burner;
1216 void fireburner_think();
1218 float Fire_IsBurning(entity e)
1220 return (time < e.fire_endtime);
1223 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1226 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1228 if(e.classname == "player")
1237 // print("adding a fire burner to ", e.classname, "\n");
1238 e.fire_burner = spawn();
1239 e.fire_burner.classname = "fireburner";
1240 e.fire_burner.think = fireburner_think;
1241 e.fire_burner.nextthink = time;
1242 e.fire_burner.owner = e;
1248 if(Fire_IsBurning(e))
1250 mintime = e.fire_endtime - time;
1251 maxtime = max(mintime, t);
1253 mindps = e.fire_damagepersec;
1254 maxdps = max(mindps, dps);
1256 if(maxtime > mintime || maxdps > mindps)
1258 mindamage = mindps * mintime;
1259 maxdamage = mindamage + d;
1261 // interval [mintime, maxtime] * [mindps, maxdps]
1263 // [mindamage, maxdamage]
1266 if(maxdamage >= maxtime * maxdps)
1268 totaltime = maxtime;
1269 totaldamage = maxtime * maxdps;
1271 // this branch increases totaldamage if either t > mintime, or dps > mindps
1275 // maxdamage is inside the interval!
1276 // first, try to use mindps; only if this fails, increase dps as needed
1277 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1278 totaldamage = maxdamage;
1279 // can totaldamage / totaltime be >= maxdps?
1280 // max(mindps, maxdamage / maxtime) >= maxdps?
1281 // we know maxdamage < maxtime * maxdps
1284 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1287 // total conditions for increasing:
1288 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1290 // if maxtime = mintime, maxdps = mindps
1292 // maxdamage = mindamage + d
1293 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1294 // so the last condition is not needed
1296 e.fire_damagepersec = totaldamage / totaltime;
1297 e.fire_endtime = time + totaltime;
1298 if(totaldamage > 1.2 * mindamage)
1300 e.fire_deathtype = dt;
1301 if(e.fire_owner != o)
1304 e.fire_hitsound = FALSE;
1307 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1314 e.fire_damagepersec = dps;
1315 e.fire_endtime = time + t;
1316 e.fire_deathtype = dt;
1318 e.fire_hitsound = FALSE;
1323 void Fire_ApplyDamage(entity e)
1328 if not(Fire_IsBurning(e))
1334 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1337 // water and slime stop fire
1339 if(e.watertype != CONTENT_LAVA)
1342 t = min(frametime, e.fire_endtime - time);
1343 d = e.fire_damagepersec * t;
1345 hi = e.fire_owner.hitsound;
1346 ty = e.fire_owner.typehitsound;
1347 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1348 if(e.fire_hitsound && e.fire_owner)
1350 e.fire_owner.hitsound = hi;
1351 e.fire_owner.typehitsound = ty;
1353 e.fire_hitsound = TRUE;
1355 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1357 if not(IS_INDEPENDENT_PLAYER(e))
1358 FOR_EACH_PLAYER(other) if(e != other)
1360 if(other.classname == "player")
1361 if(other.deadflag == DEAD_NO)
1362 if not(IS_INDEPENDENT_PLAYER(other))
1363 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1365 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1366 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1367 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1372 void Fire_ApplyEffect(entity e)
1374 if(Fire_IsBurning(e))
1375 e.effects |= EF_FLAME;
1377 e.effects &~= EF_FLAME;
1380 void fireburner_think()
1382 // for players, this is done in the regular loop
1383 if(wasfreed(self.owner))
1388 Fire_ApplyEffect(self.owner);
1389 if(!Fire_IsBurning(self.owner))
1391 self.owner.fire_burner = world;
1395 Fire_ApplyDamage(self.owner);
1396 self.nextthink = time;