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!)
154 if(MUTATOR_CALLHOOK(GiveFragsForKill))
164 f = RunematchHandleFrags(attacker, targ, f);
170 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
171 if(tl < lms_lowest_lives)
172 lms_lowest_lives = tl;
176 lms_next_place = player_count;
177 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
184 if(g_ctf_ignore_frags)
189 attacker.totalfrags += f;
192 UpdateFrags(attacker, f);
195 string AppendItemcodes(string s, entity player)
200 // w = player.switchweapon;
202 w = player.cnt; // previous weapon!
203 s = strcat(s, ftos(w));
204 if(time < player.strength_finished)
206 if(time < player.invincible_finished)
208 if(player.flagcarried != world)
210 if(player.BUTTON_CHAT)
215 s = strcat(s, "|", ftos(player.runes));
219 void LogDeath(string mode, float deathtype, entity killer, entity killed)
222 if(!cvar("sv_eventlog"))
224 s = strcat(":kill:", mode);
225 s = strcat(s, ":", ftos(killer.playerid));
226 s = strcat(s, ":", ftos(killed.playerid));
227 s = strcat(s, ":type=", ftos(deathtype));
228 s = strcat(s, ":items=");
229 s = AppendItemcodes(s, killer);
232 s = strcat(s, ":victimitems=");
233 s = AppendItemcodes(s, killed);
238 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
243 if (targ.classname == "player" || targ.classname == "corpse")
245 if (targ.classname == "corpse")
250 a = attacker.netname;
252 if (targ == attacker)
254 if (deathtype == DEATH_TEAMCHANGE) {
255 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
256 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
257 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)));
259 } else if (deathtype == DEATH_CAMP) {
261 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
263 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
264 } else if (deathtype == DEATH_NOAMMO) {
266 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
268 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
269 } else if (deathtype == DEATH_ROT) {
271 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
273 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
274 } else if (deathtype == DEATH_MIRRORDAMAGE) {
276 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
278 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
279 } else if (deathtype == DEATH_QUIET) {
283 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
285 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
288 if (deathtype == DEATH_CAMP)
289 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
290 else if (deathtype == DEATH_MIRRORDAMAGE)
291 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
293 bprint ("^1",s, "^1 will be reinserted into the game due to their own actions\n");
295 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
297 LogDeath("suicide", deathtype, targ, targ);
298 GiveFrags(attacker, targ, -1);
300 if (targ.killcount > 2)
301 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
303 w = DEATH_WEAPONOF(deathtype);
306 w_deathtypestring = "couldn't resist the urge to self-destruct";
307 w_deathtype = deathtype;
308 weapon_action(w, WR_SUICIDEMESSAGE);
309 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
311 else if (deathtype == DEATH_KILL)
312 bprint ("^1",s, "^1 couldn't take it anymore\n");
313 else if (deathtype == DEATH_ROT)
314 bprint ("^1",s, "^1 died\n");
315 else if (deathtype == DEATH_NOAMMO)
316 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
317 else if (deathtype == DEATH_CAMP)
318 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
319 else if (deathtype == DEATH_MIRRORDAMAGE)
320 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
321 else if (deathtype == DEATH_CHEAT)
322 bprint ("^1",s, "^1 unfairly eliminated themself\n");
323 else if (deathtype == DEATH_FIRE)
324 bprint ("^1",s, "^1 burned to death\n");
325 else if (deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
326 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
328 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
330 LogDeath("suicide", deathtype, targ, targ);
331 GiveFrags(attacker, targ, -1);
333 if (targ.killcount > 2)
334 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
337 else if (attacker.classname == "player" || attacker.classname == "gib")
339 if(teams_matter && attacker.team == targ.team)
342 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
343 bprint ("^1", a, "^1 took action against a team mate\n");
345 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
346 bprint ("^1", a, "^1 mows down a team mate\n");
348 GiveFrags(attacker, targ, -1);
349 if (targ.killcount > 2) {
351 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
353 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
355 if (attacker.killcount > 2) {
357 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
359 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
361 attacker.killcount = 0;
363 LogDeath("tk", deathtype, attacker, targ);
367 string blood_message, victim_message;
368 if (!checkrules_firstblood)
370 checkrules_firstblood = TRUE;
373 bprint("^1",a, "^1 was the first to score", "\n");
374 blood_message = "^1First point\n";
375 //victim_message = "^1First victim\n"; // or First casualty
379 bprint("^1",a, "^1 drew first blood", "\n");
380 blood_message = "^1First blood\n";
381 victim_message = "^1First victim\n"; // or First casualty
385 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You scored against ^7", s, GetAdvancedDeathReports(targ)));
386 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7", GetAdvancedDeathReports(attacker)));
388 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
389 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^1You typefragged ^7", s, GetAdvancedDeathReports(targ)));
390 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typefragged by ^7", a, GetAdvancedDeathReports(attacker)));
392 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s, GetAdvancedDeathReports(targ)));
393 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a, GetAdvancedDeathReports(attacker)));
395 attacker.taunt_soundtime = time + 1;
399 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
401 w = DEATH_WEAPONOF(deathtype);
404 w_deathtypestring = "was blasted by";
405 w_deathtype = deathtype;
406 weapon_action(w, WR_KILLMESSAGE);
407 p = strstrofs(w_deathtypestring, "#", 0);
409 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
411 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
413 else if (deathtype == DEATH_TELEFRAG)
414 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
415 else if (deathtype == DEATH_DROWN)
416 bprint ("^1",s, "^1 was drowned by ", a, "\n");
417 else if (deathtype == DEATH_SLIME)
418 bprint ("^1",s, "^1 was slimed by ", a, "\n");
419 else if (deathtype == DEATH_LAVA)
420 bprint ("^1",s, "^1 was cooked by ", a, "\n");
421 else if (deathtype == DEATH_FALL)
422 bprint ("^1",s, "^1 was grounded by ", a, "\n");
423 else if (deathtype == DEATH_SHOOTING_STAR)
424 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
425 else if (deathtype == DEATH_SWAMP)
426 bprint ("^1",s, "^1 was conserved by ", a, "\n");
427 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
429 p = strstrofs(inflictor.message2, "#", 0);
431 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
433 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
435 else if(deathtype == DEATH_SBCRUSH)
436 bprint ("^1",s, "^1 was crushed by ^1", a, "\n");
437 else if(deathtype == DEATH_SBMINIGUN)
438 bprint ("^1",s, "^1 got shredded by ^1", a, "\n");
439 else if(deathtype == DEATH_SBROCKET)
440 bprint ("^1",s, "^1 was blased to bits by ^1", a, "\n");
441 else if(deathtype == DEATH_SBBLOWUP)
442 bprint ("^1",s, "^1 got cought in the destruction of ^1", a, "'s vehicle\n");
444 else if(deathtype == DEATH_WAKIGUN)
445 bprint ("^1",s, "^1 was bolted down by ^1", a, "\n");
446 else if(deathtype == DEATH_WAKIROCKET)
447 bprint ("^1",s, "^1 could find no shelter from ^1", a, "'s rockets\n");
448 else if(deathtype == DEATH_WAKIBLOWUP)
449 bprint ("^1",s, "^1 dies when ^1", a, "'s wakizashi dies.\n");
451 else if(deathtype == DEATH_TURRET)
452 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
453 else if(deathtype == DEATH_TOUCHEXPLODE)
454 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
455 else if(deathtype == DEATH_CHEAT)
456 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
457 else if (deathtype == DEATH_FIRE)
458 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
459 else if (deathtype == DEATH_CUSTOM)
460 bprint ("^1",s, "^1 ", deathmessage, " by ^1", a, "\n");
462 bprint ("^1",s, "^1 was fragged by ", a, "\n");
465 if(g_ctf && targ.flagcarried)
467 UpdateFrags(attacker, ctf_score_value("score_kill"));
468 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
469 GiveFrags(attacker, targ, 0); // for logging
472 GiveFrags(attacker, targ, 1);
474 if (targ.killcount > 2) {
476 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
478 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
481 attacker.killcount = attacker.killcount + 1;
483 if (attacker.killcount > 2) {
485 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
487 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
490 LogDeath("frag", deathtype, attacker, targ);
492 if (attacker.killcount == 3)
495 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
497 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
498 AnnounceTo(attacker, "03kills");
501 else if (attacker.killcount == 5)
504 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
506 bprint (a,"^7 unleashes ^1RAGE\n");
507 AnnounceTo(attacker, "05kills");
510 else if (attacker.killcount == 10)
513 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
515 bprint (a,"^7 starts the ^1MASSACRE!\n");
516 AnnounceTo(attacker, "10kills");
519 else if (attacker.killcount == 15)
522 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
524 bprint (a,"^7 executes ^1MAYHEM!\n");
525 AnnounceTo(attacker, "15kills");
528 else if (attacker.killcount == 20)
531 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
533 bprint (a,"^7 is a ^1BERSERKER!\n");
534 AnnounceTo(attacker, "20kills");
537 else if (attacker.killcount == 25)
540 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
542 bprint (a,"^7 inflicts ^1CARNAGE!\n");
543 AnnounceTo(attacker, "25kills");
546 else if (attacker.killcount == 30)
549 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
551 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
552 AnnounceTo(attacker, "30kills");
559 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
560 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
561 bprint ("^1",s, "^1 ", inflictor.message, "\n");
562 else if (deathtype == DEATH_DROWN)
564 bprint ("^1",s, "^1 was in the water for too long\n");
566 bprint ("^1",s, "^1 drowned\n");
567 else if (deathtype == DEATH_SLIME)
568 bprint ("^1",s, "^1 was slimed\n");
569 else if (deathtype == DEATH_LAVA)
571 bprint ("^1",s, "^1 found a hot place\n");
573 bprint ("^1",s, "^1 turned into hot slag\n");
574 else if (deathtype == DEATH_FALL)
576 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
578 bprint ("^1",s, "^1 hit the ground with a crunch\n");
579 else if (deathtype == DEATH_SHOOTING_STAR)
580 bprint ("^1",s, "^1 became a shooting star\n");
581 else if (deathtype == DEATH_SWAMP)
583 bprint ("^1",s, "^1 discovered a swamp\n");
585 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
586 else if(deathtype == DEATH_TURRET)
587 bprint ("^1",s, "^1 was mowed down by a turret \n");
588 else if (deathtype == DEATH_CUSTOM)
589 bprint ("^1",s, "^1 ", deathmessage, "\n");
590 else if(deathtype == DEATH_TOUCHEXPLODE)
591 bprint ("^1",s, "^1 died in an accident\n");
592 else if(deathtype == DEATH_CHEAT)
593 bprint ("^1",s, "^1 was unfairly eliminated\n");
594 else if(deathtype == DEATH_FIRE)
596 bprint ("^1",s, "^1 felt a little hot\n");
598 bprint ("^1",s, "^1 burnt to death\n");
601 bprint ("^1",s, "^1 needs a restart\n");
603 bprint ("^1",s, "^1 died\n");
604 GiveFrags(targ, targ, -1);
605 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
606 AnnounceTo(targ, "botlike");
609 if (targ.killcount > 2)
611 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
613 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
615 LogDeath("accident", deathtype, targ, targ);
618 targ.death_origin = targ.origin;
620 targ.killer_origin = attacker.origin;
622 // FIXME: this should go in PutClientInServer
628 // these are updated by each Damage call for use in button triggering and such
630 entity damage_inflictor;
631 entity damage_attacker;
633 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
638 entity attacker_save;
642 if (gameover || targ.killcount == -666)
645 local entity oldself;
649 damage_inflictor = inflictor;
650 damage_attacker = attacker;
651 attacker_save = attacker;
653 if(targ.classname == "player")
656 if(targ.hook.aiment == attacker)
657 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
659 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
660 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
662 if(targ.classname == "player")
663 if not(IsDifferentTeam(targ, attacker))
670 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
672 // These are ALWAYS lethal
673 // No damage modification here
674 // Instead, prepare the victim for his death...
676 targ.spawnshieldtime = 0;
677 targ.health = 0.9; // this is < 1
678 targ.flags -= targ.flags & FL_GODMODE;
681 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
687 if (targ.classname == "player")
688 if (attacker.classname == "player")
691 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
693 // nullify damage if teamplay is on
694 if(deathtype != DEATH_TELEFRAG)
695 if(attacker.classname == "player")
697 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
702 else if(attacker.team == targ.team)
706 else if(attacker != targ)
710 else if(teamplay == 4)
712 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
714 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
715 attacker.dmg_team = attacker.dmg_team + damage;
716 if(attacker.dmg_team > teamdamage0 && !g_ca)
717 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
718 mirrorforce = cvar("g_mirrordamage") * vlen(force);
721 if(cvar("g_friendlyfire") == 0)
727 damage = cvar("g_friendlyfire") * damage;
728 // mirrordamage will be used LATER
737 if(targ.classname == "player")
738 if(attacker.classname == "player")
741 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
742 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
745 if(targ.classname == "player")
748 if ((deathtype == DEATH_FALL) ||
749 (deathtype == DEATH_DROWN) ||
750 (deathtype == DEATH_SLIME) ||
751 (deathtype == DEATH_LAVA) ||
752 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
759 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
761 targ.armorvalue -= 1;
762 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
765 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
767 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
770 if (targ != attacker)
772 if ((targ.health >= 1) && (targ.classname == "player"))
773 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
783 if not(DEATH_ISSPECIAL(deathtype))
785 damage *= g_weapondamagefactor;
786 mirrordamage *= g_weapondamagefactor;
787 force = force * g_weaponforcefactor;
788 mirrorforce *= g_weaponforcefactor;
791 // apply strength multiplier
792 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
796 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
797 force = force * cvar("g_balance_powerup_strength_selfforce");
801 damage = damage * cvar("g_balance_powerup_strength_damage");
802 force = force * cvar("g_balance_powerup_strength_force");
806 // apply invincibility multiplier
807 if (targ.items & IT_INVINCIBLE && !g_minstagib)
808 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
810 if (targ == attacker)
812 if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))
815 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
818 // CTF: reduce damage/force
823 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
824 force = force * cvar("g_ctf_flagcarrier_selfforce");
829 // apply strength rune
830 if (attacker.runes & RUNE_STRENGTH)
832 if(attacker.runes & CURSE_WEAK) // have both curse & rune
834 damage = damage * cvar("g_balance_rune_strength_combo_damage");
835 force = force * cvar("g_balance_rune_strength_combo_force");
839 damage = damage * cvar("g_balance_rune_strength_damage");
840 force = force * cvar("g_balance_rune_strength_force");
843 else if (attacker.runes & CURSE_WEAK)
845 damage = damage * cvar("g_balance_curse_weak_damage");
846 force = force * cvar("g_balance_curse_weak_force");
849 // apply defense rune
850 if (targ.runes & RUNE_DEFENSE)
852 if (targ.runes & CURSE_VULNER) // have both curse & rune
853 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
855 damage = damage * cvar("g_balance_rune_defense_takedamage");
857 else if (targ.runes & CURSE_VULNER)
858 damage = damage * cvar("g_balance_curse_vulner_takedamage");
864 if(targ.takedamage == DAMAGE_AIM)
867 if(targ.classname == "player")
870 // find height of hit on player axis
871 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
872 vector headmins, headmaxs, org;
873 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
874 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);
875 headmaxs = org + '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
876 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
878 deathtype |= HITTYPE_HEADSHOT;
881 else if(targ.classname == "turret_head")
883 deathtype |= HITTYPE_HEADSHOT;
885 if(deathtype & HITTYPE_HEADSHOT)
886 damage *= 1 + damage_headshotbonus;
888 if(targ.classname == "player")
890 if(IsDifferentTeam(targ, attacker))
895 attacker.typehitsound += 1;
897 attacker.hitsound += 1;
899 damage_goodhits += 1;
900 damage_gooddamage += damage;
902 if not(DEATH_ISSPECIAL(deathtype))
909 if(targ.items & IT_STRENGTH)
912 if(deathtype & HITTYPE_HEADSHOT)
919 if(deathtype != DEATH_FIRE)
920 attacker.typehitsound += 1;
922 if(time > attacker.teamkill_complain)
924 attacker.teamkill_complain = time + 5;
925 attacker.teamkill_soundtime = time + 0.4;
926 attacker.teamkill_soundsource = targ;
934 if (self.damageforcescale)
936 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
938 self.velocity = self.velocity + self.damageforcescale * force;
939 self.flags &~= FL_ONGROUND;
940 UpdateCSQCProjectile(self);
943 if (damage != 0 || (self.damageforcescale && vlen(force)))
944 if (self.event_damage)
945 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
948 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
950 // Savage: vampire mode
953 if (time >= self.spawnshieldtime)
955 attacker.health += damage;
959 if (attacker.runes & RUNE_VAMPIRE)
961 // apply vampire rune
962 if (attacker.runes & CURSE_EMPATHY) // have the curse too
964 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
965 attacker.health = bound(
966 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
967 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
968 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
972 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
973 attacker.health = bound(
974 attacker.health, // LA: was 3, but changed so that you can't lose health
975 // empathy won't let you gain health in the same way...
976 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
977 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
980 // apply empathy curse
981 else if (attacker.runes & CURSE_EMPATHY)
983 attacker.health = bound(
984 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
985 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
991 // apply mirror damage if any
992 if(mirrordamage > 0 || mirrorforce > 0)
994 attacker = attacker_save;
998 // just lose extra LIVES, don't kill the player for mirror damage
999 if(attacker.armorvalue > 0)
1001 attacker.armorvalue = attacker.armorvalue - 1;
1002 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
1003 attacker.hitsound += 1;
1007 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
1008 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
1012 vector NearestPointOnBox(entity box, vector org)
1014 vector m1, m2, nearest;
1016 m1 = box.mins + box.origin;
1017 m2 = box.maxs + box.origin;
1019 nearest_x = bound(m1_x, org_x, m2_x);
1020 nearest_y = bound(m1_y, org_y, m2_y);
1021 nearest_z = bound(m1_z, org_z, m2_z);
1026 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
1029 weaponid = DEATH_WEAPONOF(deathtype);
1031 if not(inWarmupStage)
1033 if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {
1034 attacker.stats_hit[weaponid - 1] += damage;
1035 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);
1039 float RadiusDamage_running;
1040 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
1041 // Returns total damage applies to creatures
1051 float total_damage_to_creatures;
1056 float stat_damagedone;
1057 float stat_maxdamage;
1059 if(RadiusDamage_running)
1062 print("RadiusDamage called recursively!\n");
1063 print("Expect stuff to go HORRIBLY wrong.\n");
1064 print("Causing a stack trace...\n");
1065 save = cvar_string("prvm_backtraceforwarnings");
1066 cvar_set("prvm_backtraceforwarnings", "1");
1067 fclose(-1); // calls VM_Warning
1068 cvar_set("prvm_backtraceforwarnings", save);
1072 RadiusDamage_running = 1;
1074 tfloordmg = cvar("g_throughfloor_damage");
1075 tfloorforce = cvar("g_throughfloor_force");
1077 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1078 total_damage_to_creatures = 0;
1080 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1081 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
1083 force = inflictor.velocity;
1084 if(vlen(force) == 0)
1087 force = normalize(force);
1088 if(forceintensity >= 0)
1089 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1091 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1094 stat_damagedone = 0;
1097 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
1101 if (targ != inflictor)
1102 if (ignore != targ) if(targ.takedamage)
1104 // LordHavoc: measure distance to nearest point on target (not origin)
1105 // (this guarentees 100% damage on a touch impact)
1106 nearest = targ.WarpZone_findradius_nearest;
1107 diff = targ.WarpZone_findradius_dist;
1108 // round up a little on the damage to ensure full damage on impacts
1109 // and turn the distance into a fraction of the radius
1110 power = 1 - ((vlen (diff) - 2) / rad);
1112 //bprint(ftos(power));
1113 //if (targ == attacker)
1114 // print(ftos(power), "\n");
1119 finaldmg = coredamage * power + edgedamage * (1 - power);
1126 local float hitratio;
1127 local vector hitloc;
1128 local vector myblastorigin;
1129 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1130 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1131 // if it's a player, use the view origin as reference
1132 if (targ.classname == "player")
1133 center = targ.origin + targ.view_ofs;
1134 force = normalize(center - myblastorigin);
1135 force = force * (finaldmg / coredamage) * forceintensity;
1136 // test line of sight to multiple positions on box,
1137 // and do damage if any of them hit
1139 if (targ.classname == "player")
1140 total = ceil(bound(1, finaldmg, 50));
1142 total = ceil(bound(1, finaldmg/10, 5));
1147 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1148 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1149 if (trace_fraction == 1 || trace_ent == targ)
1153 hitloc = hitloc + nearest;
1157 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1158 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1159 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1162 nearest = hitloc * (1 / max(1, hits));
1163 hitratio = (hits / total);
1164 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1165 finaldmg = finaldmg * a;
1166 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1168 //if (targ == attacker)
1170 // print("hits ", ftos(hits), " / ", ftos(total));
1171 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1172 // print(" (", ftos(a), ")\n");
1174 if(hits || tfloordmg || tfloorforce)
1178 total_damage_to_creatures += finaldmg;
1180 if(targ.flags & FL_CLIENT)
1181 if(targ.deadflag == DEAD_NO)
1182 if(targ != attacker)
1183 if(!teamplay || targ.team != attacker.team)
1185 stat_damagedone += finaldmg;
1186 stat_maxdamage += coredamage;
1190 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1191 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1193 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1201 RadiusDamage_running = 0;
1203 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1205 return total_damage_to_creatures;
1208 .float fire_damagepersec;
1209 .float fire_endtime;
1210 .float fire_deathtype;
1212 .float fire_hitsound;
1213 .entity fire_burner;
1215 void fireburner_think();
1217 float Fire_IsBurning(entity e)
1219 return (time < e.fire_endtime);
1222 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1225 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1227 if(e.classname == "player")
1236 // print("adding a fire burner to ", e.classname, "\n");
1237 e.fire_burner = spawn();
1238 e.fire_burner.classname = "fireburner";
1239 e.fire_burner.think = fireburner_think;
1240 e.fire_burner.nextthink = time;
1241 e.fire_burner.owner = e;
1247 if(Fire_IsBurning(e))
1249 mintime = e.fire_endtime - time;
1250 maxtime = max(mintime, t);
1252 mindps = e.fire_damagepersec;
1253 maxdps = max(mindps, dps);
1255 if(maxtime > mintime || maxdps > mindps)
1257 mindamage = mindps * mintime;
1258 maxdamage = mindamage + d;
1260 // interval [mintime, maxtime] * [mindps, maxdps]
1262 // [mindamage, maxdamage]
1265 if(maxdamage >= maxtime * maxdps)
1267 totaltime = maxtime;
1268 totaldamage = maxtime * maxdps;
1270 // this branch increases totaldamage if either t > mintime, or dps > mindps
1274 // maxdamage is inside the interval!
1275 // first, try to use mindps; only if this fails, increase dps as needed
1276 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1277 totaldamage = maxdamage;
1278 // can totaldamage / totaltime be >= maxdps?
1279 // max(mindps, maxdamage / maxtime) >= maxdps?
1280 // we know maxdamage < maxtime * maxdps
1283 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1286 // total conditions for increasing:
1287 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1289 // if maxtime = mintime, maxdps = mindps
1291 // maxdamage = mindamage + d
1292 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1293 // so the last condition is not needed
1295 e.fire_damagepersec = totaldamage / totaltime;
1296 e.fire_endtime = time + totaltime;
1297 if(totaldamage > 1.2 * mindamage)
1299 e.fire_deathtype = dt;
1300 if(e.fire_owner != o)
1303 e.fire_hitsound = FALSE;
1306 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1313 e.fire_damagepersec = dps;
1314 e.fire_endtime = time + t;
1315 e.fire_deathtype = dt;
1317 e.fire_hitsound = FALSE;
1322 void Fire_ApplyDamage(entity e)
1327 if not(Fire_IsBurning(e))
1333 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1336 // water and slime stop fire
1338 if(e.watertype != CONTENT_LAVA)
1341 t = min(frametime, e.fire_endtime - time);
1342 d = e.fire_damagepersec * t;
1344 hi = e.fire_owner.hitsound;
1345 ty = e.fire_owner.typehitsound;
1346 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1347 if(e.fire_hitsound && e.fire_owner)
1349 e.fire_owner.hitsound = hi;
1350 e.fire_owner.typehitsound = ty;
1352 e.fire_hitsound = TRUE;
1354 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1356 if not(IS_INDEPENDENT_PLAYER(e))
1357 FOR_EACH_PLAYER(other) if(e != other)
1359 if(other.classname == "player")
1360 if(other.deadflag == DEAD_NO)
1361 if not(IS_INDEPENDENT_PLAYER(other))
1362 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1364 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1365 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1366 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1371 void Fire_ApplyEffect(entity e)
1373 if(Fire_IsBurning(e))
1374 e.effects |= EF_FLAME;
1376 e.effects &~= EF_FLAME;
1379 void fireburner_think()
1381 // for players, this is done in the regular loop
1382 if(wasfreed(self.owner))
1387 Fire_ApplyEffect(self.owner);
1388 if(!Fire_IsBurning(self.owner))
1390 self.owner.fire_burner = world;
1394 Fire_ApplyDamage(self.owner);
1395 self.nextthink = time;