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 GiveFrags (entity attacker, entity targ, float f)
97 // TODO route through PlayerScores instead
105 PlayerScore_Add(attacker, SP_SUICIDES, 1);
110 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
116 PlayerScore_Add(attacker, SP_KILLS, 1);
119 PlayerScore_Add(targ, SP_DEATHS, 1);
122 if(cvar("g_arena_roundbased"))
125 if(g_weaponarena_random)
127 // after a frag, choose another random weapon set
128 attacker.weapons = randombits(attacker.weapons, (inWarmupStage ? warmup_start_weapons : start_weapons));
129 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
130 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
133 // FIXME fix the mess this is (we have REAL points now!)
136 f = RunematchHandleFrags(attacker, targ, f);
140 f = kh_HandleFrags(attacker, targ, f);
146 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
147 if(tl < lms_lowest_lives)
148 lms_lowest_lives = tl;
152 lms_next_place = player_count;
153 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
160 if(g_ctf_ignore_frags)
164 attacker.totalfrags += f;
167 UpdateFrags(attacker, f);
170 string AppendItemcodes(string s, entity player)
175 // w = player.switchweapon;
177 w = player.cnt; // previous weapon!
178 s = strcat(s, ftos(w));
179 if(time < player.strength_finished)
181 if(time < player.invincible_finished)
183 if(player.flagcarried != world)
185 if(player.BUTTON_CHAT)
190 s = strcat(s, "|", ftos(player.runes));
194 void LogDeath(string mode, float deathtype, entity killer, entity killed)
197 if(!cvar("sv_eventlog"))
199 s = strcat(":kill:", mode);
200 s = strcat(s, ":", ftos(killer.playerid));
201 s = strcat(s, ":", ftos(killed.playerid));
202 s = strcat(s, ":type=", ftos(deathtype));
203 s = strcat(s, ":items=");
204 s = AppendItemcodes(s, killer);
207 s = strcat(s, ":victimitems=");
208 s = AppendItemcodes(s, killed);
213 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
218 if (targ.classname == "player" || targ.classname == "corpse")
220 if (targ.classname == "corpse")
224 a = attacker.netname;
226 if (targ == attacker)
228 if (deathtype == DEATH_TEAMCHANGE) {
229 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
230 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
231 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)));
233 } else if (deathtype == DEATH_CAMP) {
235 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
237 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
238 } else if (deathtype == DEATH_NOAMMO) {
240 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
242 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
243 } else if (deathtype == DEATH_ROT) {
245 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
247 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
248 } else if (deathtype == DEATH_MIRRORDAMAGE) {
250 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
252 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
255 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
257 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
261 if (deathtype == DEATH_CAMP)
262 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
263 else if (deathtype == DEATH_MIRRORDAMAGE)
264 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
266 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
268 if(deathtype != DEATH_TEAMCHANGE)
270 LogDeath("suicide", deathtype, targ, targ);
271 GiveFrags(attacker, targ, -1);
273 if (targ.killcount > 2)
274 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
276 w = DEATH_WEAPONOF(deathtype);
279 w_deathtypestring = "couldn't resist the urge to self-destruct";
280 w_deathtype = deathtype;
281 weapon_action(w, WR_SUICIDEMESSAGE);
282 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
284 else if (deathtype == DEATH_KILL)
285 bprint ("^1",s, "^1 couldn't take it anymore\n");
286 else if (deathtype == DEATH_ROT)
287 bprint ("^1",s, "^1 died\n");
288 else if (deathtype == DEATH_NOAMMO)
289 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
290 else if (deathtype == DEATH_CAMP)
291 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
292 else if (deathtype == DEATH_MIRRORDAMAGE)
293 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
294 else if (deathtype == DEATH_CHEAT)
295 bprint ("^1",s, "^1 unfairly eliminated himself\n");
296 else if (deathtype == DEATH_FIRE)
297 bprint ("^1",s, "^1 burned to death\n");
298 else if (deathtype != DEATH_TEAMCHANGE)
299 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
301 if(deathtype != DEATH_TEAMCHANGE)
303 LogDeath("suicide", deathtype, targ, targ);
304 GiveFrags(attacker, targ, -1);
306 if (targ.killcount > 2)
307 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
310 else if (attacker.classname == "player" || attacker.classname == "gib")
312 if(teams_matter && attacker.team == targ.team)
315 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
316 bprint ("^1", a, "^1 took action against a team mate\n");
318 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
319 bprint ("^1", a, "^1 mows down a team mate\n");
321 GiveFrags(attacker, targ, -1);
322 if (targ.killcount > 2) {
324 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
326 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
328 if (attacker.killcount > 2) {
330 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
332 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
334 attacker.killcount = 0;
336 LogDeath("tk", deathtype, attacker, targ);
340 string blood_message, victim_message;
341 if (!checkrules_firstblood)
343 checkrules_firstblood = TRUE;
346 bprint("^1",a, "^1 was the first to score", "\n");
347 blood_message = "^1First point\n";
348 //victim_message = "^1First victim\n"; // or First casualty
352 bprint("^1",a, "^1 drew first blood", "\n");
353 blood_message = "^1First blood\n";
354 victim_message = "^1First victim\n"; // or First casualty
359 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s));
360 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7"));
362 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s));
363 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a));
364 attacker.taunt_soundtime = time + 1;
368 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
370 w = DEATH_WEAPONOF(deathtype);
373 w_deathtypestring = "was blasted by";
374 w_deathtype = deathtype;
375 weapon_action(w, WR_KILLMESSAGE);
376 p = strstrofs(w_deathtypestring, "#", 0);
378 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
380 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
382 else if (deathtype == DEATH_TELEFRAG)
383 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
384 else if (deathtype == DEATH_DROWN)
385 bprint ("^1",s, "^1 was drowned by ", a, "\n");
386 else if (deathtype == DEATH_SLIME)
387 bprint ("^1",s, "^1 was slimed by ", a, "\n");
388 else if (deathtype == DEATH_LAVA)
389 bprint ("^1",s, "^1 was cooked by ", a, "\n");
390 else if (deathtype == DEATH_FALL)
391 bprint ("^1",s, "^1 was grounded by ", a, "\n");
392 else if (deathtype == DEATH_SHOOTING_STAR)
393 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
394 else if (deathtype == DEATH_SWAMP)
395 bprint ("^1",s, "^1 was conserved by ", a, "\n");
396 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
398 p = strstrofs(inflictor.message2, "#", 0);
400 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
402 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
404 else if(deathtype == DEATH_TURRET)
405 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
406 else if(deathtype == DEATH_TOUCHEXPLODE)
407 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
408 else if(deathtype == DEATH_CHEAT)
409 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
410 else if (deathtype == DEATH_FIRE)
411 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
413 bprint ("^1",s, "^1 was fragged by ", a, "\n");
416 if(g_ctf && targ.flagcarried)
418 UpdateFrags(attacker, ctf_score_value("score_kill"));
419 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
420 GiveFrags(attacker, targ, 0); // for logging
423 GiveFrags(attacker, targ, 1);
425 if (targ.killcount > 2) {
427 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
429 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
432 attacker.killcount = attacker.killcount + 1;
434 if (attacker.killcount > 2) {
436 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
438 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
441 LogDeath("frag", deathtype, attacker, targ);
443 if (attacker.killcount == 3)
446 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
448 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
449 announce(attacker, "announcer/male/03kills.wav");
452 else if (attacker.killcount == 5)
455 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
457 bprint (a,"^7 unleashes ^1RAGE\n");
458 announce(attacker, "announcer/male/05kills.wav");
461 else if (attacker.killcount == 10)
464 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
466 bprint (a,"^7 starts the ^1MASSACRE!\n");
467 announce(attacker, "announcer/male/10kills.wav");
470 else if (attacker.killcount == 15)
473 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
475 bprint (a,"^7 executes ^1MAYHEM!\n");
476 announce(attacker, "announcer/male/15kills.wav");
479 else if (attacker.killcount == 20)
482 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
484 bprint (a,"^7 is a ^1BERSERKER!\n");
485 announce(attacker, "announcer/male/20kills.wav");
488 else if (attacker.killcount == 25)
491 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
493 bprint (a,"^7 inflicts ^1CARNAGE!\n");
494 announce(attacker, "announcer/male/25kills.wav");
497 else if (attacker.killcount == 30)
500 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
502 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
503 announce(attacker, "announcer/male/30kills.wav");
510 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
511 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
512 bprint ("^1",s, "^1 ", inflictor.message, "\n");
513 else if (deathtype == DEATH_DROWN)
515 bprint ("^1",s, "^1 was in the water for too long\n");
517 bprint ("^1",s, "^1 drowned\n");
518 else if (deathtype == DEATH_SLIME)
519 bprint ("^1",s, "^1 was slimed\n");
520 else if (deathtype == DEATH_LAVA)
522 bprint ("^1",s, "^1 found a hot place\n");
524 bprint ("^1",s, "^1 turned into hot slag\n");
525 else if (deathtype == DEATH_FALL)
527 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
529 bprint ("^1",s, "^1 hit the ground with a crunch\n");
530 else if (deathtype == DEATH_SHOOTING_STAR)
531 bprint ("^1",s, "^1 became a shooting star\n");
532 else if (deathtype == DEATH_SWAMP)
534 bprint ("^1",s, "^1 discovered a swamp\n");
536 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
537 else if(deathtype == DEATH_TURRET)
538 bprint ("^1",s, "^1 was mowed down by a turret \n");
539 else if(deathtype == DEATH_TOUCHEXPLODE)
540 bprint ("^1",s, "^1 died in an accident\n");
541 else if(deathtype == DEATH_CHEAT)
542 bprint ("^1",s, "^1 was unfairly eliminated\n");
543 else if(deathtype == DEATH_FIRE)
545 bprint ("^1",s, "^1 felt a little hot\n");
547 bprint ("^1",s, "^1 burnt to death\n");
550 bprint ("^1",s, "^1 needs a restart\n");
552 bprint ("^1",s, "^1 died\n");
553 GiveFrags(targ, targ, -1);
554 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
555 announce(targ, "announcer/male/botlike.wav");
558 if (targ.killcount > 2)
560 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
562 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
564 LogDeath("accident", deathtype, targ, targ);
566 targ.death_origin = targ.origin;
568 targ.killer_origin = attacker.origin;
569 // FIXME: this should go in PutClientInServer
575 // these are updated by each Damage call for use in button triggering and such
577 entity damage_inflictor;
578 entity damage_attacker;
580 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
585 entity attacker_save;
589 if (gameover || targ.killcount == -666)
592 local entity oldself;
596 damage_inflictor = inflictor;
597 damage_attacker = attacker;
598 attacker_save = attacker;
600 if(targ.classname == "player")
603 if(targ.hook.aiment == attacker)
604 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
606 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
607 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
609 if(targ.classname == "player")
610 if not(IsDifferentTeam(targ, attacker))
617 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
619 // These are ALWAYS lethal
620 // No damage modification here
621 // Instead, prepare the victim for his death...
623 targ.spawnshieldtime = 0;
624 targ.health = 0.9; // this is < 1
625 targ.flags -= targ.flags & FL_GODMODE;
628 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
634 if (targ.classname == "player")
635 if (attacker.classname == "player")
638 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
640 // nullify damage if teamplay is on
641 if(deathtype != DEATH_TELEFRAG)
642 if(attacker.classname == "player")
644 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
649 else if(attacker.team == targ.team)
653 else if(attacker != targ)
657 else if(teamplay == 4)
659 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
661 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
662 attacker.dmg_team = attacker.dmg_team + damage;
663 if(attacker.dmg_team > teamdamage0)
664 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
665 mirrorforce = cvar("g_mirrordamage") * vlen(force);
668 if(cvar("g_friendlyfire") == 0)
672 damage = cvar("g_friendlyfire") * damage;
673 // mirrordamage will be used LATER
682 if(targ.classname == "player")
683 if(attacker.classname == "player")
686 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
687 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
690 if(targ.classname == "player")
693 if ((deathtype == DEATH_FALL) ||
694 (deathtype == DEATH_DROWN) ||
695 (deathtype == DEATH_SLIME) ||
696 (deathtype == DEATH_LAVA))
701 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
703 targ.armorvalue -= 1;
704 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
707 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
709 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
712 if (targ != attacker)
714 if (targ.classname == "player")
715 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
725 if not(DEATH_ISSPECIAL(deathtype))
727 damage *= g_weapondamagefactor;
728 mirrordamage *= g_weapondamagefactor;
729 force = force * g_weaponforcefactor;
730 mirrorforce *= g_weaponforcefactor;
733 // apply strength multiplier
734 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
738 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
739 force = force * cvar("g_balance_powerup_strength_selfforce");
743 damage = damage * cvar("g_balance_powerup_strength_damage");
744 force = force * cvar("g_balance_powerup_strength_force");
748 // apply invincibility multiplier
749 if (targ.items & IT_INVINCIBLE && !g_minstagib)
750 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
752 if (targ == attacker)
753 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
755 // CTF: reduce damage/force
760 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
761 force = force * cvar("g_ctf_flagcarrier_selfforce");
766 // apply strength rune
767 if (attacker.runes & RUNE_STRENGTH)
769 if(attacker.runes & CURSE_WEAK) // have both curse & rune
771 damage = damage * cvar("g_balance_rune_strength_combo_damage");
772 force = force * cvar("g_balance_rune_strength_combo_force");
776 damage = damage * cvar("g_balance_rune_strength_damage");
777 force = force * cvar("g_balance_rune_strength_force");
780 else if (attacker.runes & CURSE_WEAK)
782 damage = damage * cvar("g_balance_curse_weak_damage");
783 force = force * cvar("g_balance_curse_weak_force");
786 // apply defense rune
787 if (targ.runes & RUNE_DEFENSE)
789 if (targ.runes & CURSE_VULNER) // have both curse & rune
790 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
792 damage = damage * cvar("g_balance_rune_defense_takedamage");
794 else if (targ.runes & CURSE_VULNER)
795 damage = damage * cvar("g_balance_curse_vulner_takedamage");
801 if(targ.takedamage == DAMAGE_AIM)
803 if(targ.classname == "player")
805 if(IsDifferentTeam(targ, attacker))
810 attacker.typehitsound += 1;
812 attacker.hitsound += 1;
814 damage_goodhits += 1;
815 damage_gooddamage += damage;
817 if not(DEATH_ISSPECIAL(deathtype))
824 if(targ.items & IT_STRENGTH)
828 // find height of hit on player axis
829 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
830 vector headmins, headmaxs, org;
831 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
832 headmins = org + '0.7 0 0' * targ.mins_x + '0 0.7 0' * targ.mins_y + '0 0 1' * (1.5 * targ.view_ofs_z - 0.5 * targ.maxs_z);
833 headmaxs = org + '0.7 0 0' * targ.maxs_x + '0 0.7 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
834 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
836 damage *= 1 + damage_headshotbonus;
838 deathtype |= HITTYPE_HEADSHOT;
845 if(deathtype != DEATH_FIRE)
846 attacker.typehitsound += 1;
848 if(time > attacker.teamkill_complain)
850 attacker.teamkill_complain = time + 5;
851 attacker.teamkill_soundtime = time + 0.4;
852 attacker.teamkill_soundsource = targ;
859 if (self.damageforcescale)
862 self.velocity = self.velocity + self.damageforcescale * force;
863 self.flags &~= FL_ONGROUND;
864 UpdateCSQCProjectile(self);
867 if (damage != 0 || (self.damageforcescale && vlen(force)))
868 if (self.event_damage)
869 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
872 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
874 // Savage: vampire mode
877 if (time > self.spawnshieldtime)
879 attacker.health += damage;
883 if (attacker.runes & RUNE_VAMPIRE)
885 // apply vampire rune
886 if (attacker.runes & CURSE_EMPATHY) // have the curse too
888 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
889 attacker.health = bound(
890 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
891 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
892 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
896 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
897 attacker.health = bound(
898 attacker.health, // LA: was 3, but changed so that you can't lose health
899 // empathy won't let you gain health in the same way...
900 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
901 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
904 // apply empathy curse
905 else if (attacker.runes & CURSE_EMPATHY)
907 attacker.health = bound(
908 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
909 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
915 // apply mirror damage if any
916 if(mirrordamage > 0 || mirrorforce > 0)
918 attacker = attacker_save;
922 // just lose extra LIVES, don't kill the player for mirror damage
923 if(attacker.armorvalue > 0)
925 attacker.armorvalue = attacker.armorvalue - 1;
926 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
927 attacker.hitsound += 1;
931 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
932 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
936 vector NearestPointOnBox(entity box, vector org)
938 vector m1, m2, nearest;
940 m1 = box.mins + box.origin;
941 m2 = box.maxs + box.origin;
943 nearest_x = bound(m1_x, org_x, m2_x);
944 nearest_y = bound(m1_y, org_y, m2_y);
945 nearest_z = bound(m1_z, org_z, m2_z);
950 .float actual_damage[WEP_COUNT]; //amount of damage done
951 .float max_damage[WEP_COUNT]; //the maximum damage of the weapon
953 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(actual_damage);
954 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(max_damage);
956 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
959 weaponid = DEATH_WEAPONOF(deathtype);
960 if not(inWarmupStage)
962 if(clienttype(attacker) == CLIENTTYPE_REAL)
964 // Track damage done and update the stat to be sent later in g_world.qc
965 attacker.actual_damage[weaponid] += damage;
966 attacker.damage_hits = weaponid + 64 * rint(attacker.actual_damage[weaponid]);
970 float RadiusDamage_running;
971 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
972 // Returns total damage applies to creatures
982 float total_damage_to_creatures;
985 float stat_damagedone;
986 float stat_maxdamage;
988 if(RadiusDamage_running)
991 print("RadiusDamage called recursively!\n");
992 print("Expect stuff to go HORRIBLY wrong.\n");
993 print("Causing a stack trace...\n");
994 save = cvar_string("prvm_backtraceforwarnings");
995 cvar_set("prvm_backtraceforwarnings", "1");
996 fclose(-1); // calls VM_Warning
997 cvar_set("prvm_backtraceforwarnings", save);
1002 RadiusDamage_running = 1;
1004 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1005 total_damage_to_creatures = 0;
1007 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1009 force = inflictor.velocity;
1010 if(vlen(force) == 0)
1013 force = normalize(force);
1014 if(forceintensity >= 0)
1015 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1017 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1020 stat_damagedone = 0;
1023 targ = findradius (blastorigin, rad);
1027 if (targ != inflictor)
1030 // LordHavoc: measure distance to nearest point on target (not origin)
1031 // (this guarentees 100% damage on a touch impact)
1032 nearest = NearestPointOnBox(targ, blastorigin);
1033 diff = nearest - blastorigin;
1034 // round up a little on the damage to ensure full damage on impacts
1035 // and turn the distance into a fraction of the radius
1036 power = 1 - ((vlen (diff) - 2) / rad);
1038 //bprint(ftos(power));
1043 finaldmg = coredamage * power + edgedamage * (1 - power);
1046 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1047 // if it's a player, use the view origin as reference
1048 if (targ.classname == "player")
1049 center = targ.origin + targ.view_ofs;
1050 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
1051 // test line of sight to multiple positions on box,
1052 // and do damage if any of them hit
1054 c = ceil(finaldmg / 10);
1060 traceline(blastorigin, nearest, TRUE, inflictor);
1061 if (trace_fraction == 1 || trace_ent == targ
1062 || cvar("g_throughfloor"))
1066 total_damage_to_creatures += finaldmg;
1068 if(targ.flags & FL_CLIENT)
1069 if(targ.deadflag == DEAD_NO)
1070 if(targ != attacker)
1071 if(!teamplay || targ.team != attacker.team)
1073 stat_damagedone += finaldmg;
1074 stat_maxdamage += coredamage;
1078 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1079 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1081 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1084 nearest_x = targ.mins_x + random() * targ.size_x;
1085 nearest_y = targ.mins_y + random() * targ.size_y;
1086 nearest_z = targ.mins_z + random() * targ.size_z;
1094 RadiusDamage_running = 0;
1096 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1098 return total_damage_to_creatures;
1101 .float fire_damagepersec;
1102 .float fire_endtime;
1103 .float fire_deathtype;
1105 .float fire_hitsound;
1106 .entity fire_burner;
1108 void fireburner_think();
1110 float Fire_IsBurning(entity e)
1112 return (time < e.fire_endtime);
1115 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1118 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1120 if(e.classname != "player")
1123 // print("adding a fire burner to ", e.classname, "\n");
1124 e.fire_burner = spawn();
1125 e.fire_burner.classname = "fireburner";
1126 e.fire_burner.think = fireburner_think;
1127 e.fire_burner.nextthink = time;
1128 e.fire_burner.owner = e;
1133 if(Fire_IsBurning(e))
1135 mintime = e.fire_endtime - time;
1136 maxtime = max(mintime, t);
1138 mindps = e.fire_damagepersec;
1139 maxdps = max(mindps, dps);
1141 if(maxtime > mintime || maxdps > mindps)
1143 mindamage = mindps * mintime;
1144 maxdamage = mindamage + d;
1146 // interval [mintime, maxtime] * [mindps, maxdps]
1148 // [mindamage, maxdamage]
1151 if(maxdamage >= maxtime * maxdps)
1153 totaltime = maxtime;
1154 totaldamage = maxtime * maxdps;
1156 // this branch increases totaldamage if either t > mintime, or dps > mindps
1160 // maxdamage is inside the interval!
1161 // first, try to use mindps; only if this fails, increase dps as needed
1162 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1163 totaldamage = maxdamage;
1164 // can totaldamage / totaltime be >= maxdps?
1165 // max(mindps, maxdamage / maxtime) >= maxdps?
1166 // we know maxdamage < maxtime * maxdps
1169 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1172 // total conditions for increasing:
1173 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1175 // if maxtime = mintime, maxdps = mindps
1177 // maxdamage = mindamage + d
1178 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1179 // so the last condition is not needed
1181 e.fire_damagepersec = totaldamage / totaltime;
1182 e.fire_endtime = time + totaltime;
1183 if(totaldamage > 1.2 * mindamage)
1184 if(e.fire_owner != o)
1186 e.fire_deathtype = dt;
1188 e.fire_hitsound = FALSE;
1190 return totaldamage - mindamage; // can never be negative
1197 e.fire_damagepersec = dps;
1198 e.fire_endtime = time + t;
1199 e.fire_deathtype = dt;
1201 e.fire_hitsound = FALSE;
1206 void Fire_ApplyDamage(entity e)
1210 if not(Fire_IsBurning(e))
1213 // water and slime stop fire
1215 if(e.watertype != CONTENT_LAVA)
1218 t = min(frametime, e.fire_endtime - time);
1219 d = e.fire_damagepersec * t;
1221 hi = e.fire_owner.hitsound;
1222 ty = e.fire_owner.typehitsound;
1223 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1224 if(e.fire_hitsound && e.fire_owner)
1226 e.fire_owner.hitsound = hi;
1227 e.fire_owner.typehitsound = ty;
1229 e.fire_hitsound = TRUE;
1231 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1233 if not(IS_INDEPENDENT_PLAYER(e))
1234 FOR_EACH_PLAYER(other) if(e != other)
1236 if(other.classname == "player")
1237 if(other.deadflag == DEAD_NO)
1238 if not(IS_INDEPENDENT_PLAYER(other))
1239 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1241 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1242 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1243 Fire_AddDamage(other, e, d, t, DEATH_FIRE);
1248 void Fire_ApplyEffect(entity e)
1250 if(Fire_IsBurning(e))
1251 e.effects |= EF_FLAME;
1253 e.effects &~= EF_FLAME;
1256 void fireburner_think()
1258 // for players, this is done in the regular loop
1259 if(wasfreed(self.owner))
1264 Fire_ApplyEffect(self.owner);
1265 if(!Fire_IsBurning(self.owner))
1267 self.owner.fire_burner = world;
1271 Fire_ApplyDamage(self.owner);
1272 self.nextthink = time;