6 float Damage_DamageInfo_SendEntity(entity to, float sf)
8 WriteByte(MSG_ENTITY, ENT_CLIENT_DAMAGEINFO);
9 WriteShort(MSG_ENTITY, self.projectiledeathtype);
10 WriteCoord(MSG_ENTITY, floor(self.origin_x));
11 WriteCoord(MSG_ENTITY, floor(self.origin_y));
12 WriteCoord(MSG_ENTITY, floor(self.origin_z));
13 WriteByte(MSG_ENTITY, bound(1, self.dmg, 255));
14 WriteByte(MSG_ENTITY, bound(0, self.dmg_radius, 255));
15 WriteByte(MSG_ENTITY, bound(1, self.dmg_edge, 255));
16 WriteShort(MSG_ENTITY, self.oldorigin_x);
20 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, entity dmgowner)
22 // TODO maybe call this from non-edgedamage too?
23 // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
27 if(!sound_allowed(MSG_BROADCAST, dmgowner))
32 e.projectiledeathtype = deathtype;
34 e.dmg_edge = edgedamage;
36 e.dmg_force = vlen(force);
39 e.oldorigin_x = compressShortVector(e.velocity);
41 Net_LinkEntity(e, FALSE, 0.2, Damage_DamageInfo_SendEntity);
44 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
46 float checkrules_firstblood;
49 float damage_goodhits;
50 float damage_gooddamage;
52 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
55 .float teamkill_complain;
56 .float teamkill_soundtime;
57 .entity teamkill_soundsource;
59 .float taunt_soundtime;
62 float IsDifferentTeam(entity a, entity b)
77 float IsFlying(entity a)
79 if(a.flags & FL_ONGROUND)
81 if(a.waterlevel >= WATERLEVEL_SWIMMING)
83 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
84 if(trace_fraction < 1)
89 void UpdateFrags(entity player, float f)
91 PlayerTeamScore_AddScore(player, f);
94 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
95 void W_SwitchWeapon_Force(entity e, float w);
96 void GiveFrags (entity attacker, entity targ, float f)
100 // TODO route through PlayerScores instead
108 PlayerScore_Add(attacker, SP_SUICIDES, 1);
113 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
119 PlayerScore_Add(attacker, SP_KILLS, 1);
122 PlayerScore_Add(targ, SP_DEATHS, 1);
125 if(cvar("g_arena_roundbased"))
128 if(targ != attacker) // not for suicides
129 if(g_weaponarena_random)
131 // after a frag, choose another random weapon set
133 w = warmup_start_weapons;
137 attacker.weapons = randombits(w - (w & W_WeaponBit(attacker.weapon)), g_weaponarena_random, TRUE);
138 if(attacker.weapons < 0)
140 // error from randombits: no weapon available
141 // this means we can just give ALL weapons
142 attacker.weapons = w;
144 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
145 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
148 // FIXME fix the mess this is (we have REAL points now!)
151 f = RunematchHandleFrags(attacker, targ, f);
155 f = kh_HandleFrags(attacker, targ, f);
161 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
162 if(tl < lms_lowest_lives)
163 lms_lowest_lives = tl;
167 lms_next_place = player_count;
168 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
175 if(g_ctf_ignore_frags)
179 attacker.totalfrags += f;
182 UpdateFrags(attacker, f);
185 string AppendItemcodes(string s, entity player)
190 // w = player.switchweapon;
192 w = player.cnt; // previous weapon!
193 s = strcat(s, ftos(w));
194 if(time < player.strength_finished)
196 if(time < player.invincible_finished)
198 if(player.flagcarried != world)
200 if(player.BUTTON_CHAT)
205 s = strcat(s, "|", ftos(player.runes));
209 void LogDeath(string mode, float deathtype, entity killer, entity killed)
212 if(!cvar("sv_eventlog"))
214 s = strcat(":kill:", mode);
215 s = strcat(s, ":", ftos(killer.playerid));
216 s = strcat(s, ":", ftos(killed.playerid));
217 s = strcat(s, ":type=", ftos(deathtype));
218 s = strcat(s, ":items=");
219 s = AppendItemcodes(s, killer);
222 s = strcat(s, ":victimitems=");
223 s = AppendItemcodes(s, killed);
228 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
233 if (targ.classname == "player" || targ.classname == "corpse")
235 if (targ.classname == "corpse")
239 a = attacker.netname;
241 if (targ == attacker)
243 if (deathtype == DEATH_TEAMCHANGE) {
244 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
245 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
246 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)));
248 } else if (deathtype == DEATH_CAMP) {
250 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
252 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
253 } else if (deathtype == DEATH_NOAMMO) {
255 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
257 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
258 } else if (deathtype == DEATH_ROT) {
260 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
262 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
263 } else if (deathtype == DEATH_MIRRORDAMAGE) {
265 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
267 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
270 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
272 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
276 if (deathtype == DEATH_CAMP)
277 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
278 else if (deathtype == DEATH_MIRRORDAMAGE)
279 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
281 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
283 if(deathtype != DEATH_TEAMCHANGE)
285 LogDeath("suicide", deathtype, targ, targ);
286 GiveFrags(attacker, targ, -1);
288 if (targ.killcount > 2)
289 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
291 w = DEATH_WEAPONOF(deathtype);
294 w_deathtypestring = "couldn't resist the urge to self-destruct";
295 w_deathtype = deathtype;
296 weapon_action(w, WR_SUICIDEMESSAGE);
297 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
299 else if (deathtype == DEATH_KILL)
300 bprint ("^1",s, "^1 couldn't take it anymore\n");
301 else if (deathtype == DEATH_ROT)
302 bprint ("^1",s, "^1 died\n");
303 else if (deathtype == DEATH_NOAMMO)
304 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
305 else if (deathtype == DEATH_CAMP)
306 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
307 else if (deathtype == DEATH_MIRRORDAMAGE)
308 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
309 else if (deathtype == DEATH_CHEAT)
310 bprint ("^1",s, "^1 unfairly eliminated himself\n");
311 else if (deathtype == DEATH_FIRE)
312 bprint ("^1",s, "^1 burned to death\n");
313 else if (deathtype != DEATH_TEAMCHANGE)
314 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
316 if(deathtype != DEATH_TEAMCHANGE)
318 LogDeath("suicide", deathtype, targ, targ);
319 GiveFrags(attacker, targ, -1);
321 if (targ.killcount > 2)
322 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
325 else if (attacker.classname == "player" || attacker.classname == "gib")
327 if(teams_matter && attacker.team == targ.team)
330 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
331 bprint ("^1", a, "^1 took action against a team mate\n");
333 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
334 bprint ("^1", a, "^1 mows down a team mate\n");
336 GiveFrags(attacker, targ, -1);
337 if (targ.killcount > 2) {
339 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
341 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
343 if (attacker.killcount > 2) {
345 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
347 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
349 attacker.killcount = 0;
351 LogDeath("tk", deathtype, attacker, targ);
355 string blood_message, victim_message;
356 if (!checkrules_firstblood)
358 checkrules_firstblood = TRUE;
361 bprint("^1",a, "^1 was the first to score", "\n");
362 blood_message = "^1First point\n";
363 //victim_message = "^1First victim\n"; // or First casualty
367 bprint("^1",a, "^1 drew first blood", "\n");
368 blood_message = "^1First blood\n";
369 victim_message = "^1First victim\n"; // or First casualty
374 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s));
375 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7"));
377 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s));
378 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a));
379 attacker.taunt_soundtime = time + 1;
383 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
385 w = DEATH_WEAPONOF(deathtype);
388 w_deathtypestring = "was blasted by";
389 w_deathtype = deathtype;
390 weapon_action(w, WR_KILLMESSAGE);
391 p = strstrofs(w_deathtypestring, "#", 0);
393 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
395 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
397 else if (deathtype == DEATH_TELEFRAG)
398 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
399 else if (deathtype == DEATH_DROWN)
400 bprint ("^1",s, "^1 was drowned by ", a, "\n");
401 else if (deathtype == DEATH_SLIME)
402 bprint ("^1",s, "^1 was slimed by ", a, "\n");
403 else if (deathtype == DEATH_LAVA)
404 bprint ("^1",s, "^1 was cooked by ", a, "\n");
405 else if (deathtype == DEATH_FALL)
406 bprint ("^1",s, "^1 was grounded by ", a, "\n");
407 else if (deathtype == DEATH_SHOOTING_STAR)
408 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
409 else if (deathtype == DEATH_SWAMP)
410 bprint ("^1",s, "^1 was conserved by ", a, "\n");
411 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
413 p = strstrofs(inflictor.message2, "#", 0);
415 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
417 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
419 else if(deathtype == DEATH_TURRET)
420 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
421 else if(deathtype == DEATH_TOUCHEXPLODE)
422 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
423 else if(deathtype == DEATH_CHEAT)
424 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
425 else if (deathtype == DEATH_FIRE)
426 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
428 bprint ("^1",s, "^1 was fragged by ", a, "\n");
431 if(g_ctf && targ.flagcarried)
433 UpdateFrags(attacker, ctf_score_value("score_kill"));
434 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
435 GiveFrags(attacker, targ, 0); // for logging
438 GiveFrags(attacker, targ, 1);
440 if (targ.killcount > 2) {
442 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
444 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
447 attacker.killcount = attacker.killcount + 1;
449 if (attacker.killcount > 2) {
451 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
453 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
456 LogDeath("frag", deathtype, attacker, targ);
458 if (attacker.killcount == 3)
461 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
463 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
464 announce(attacker, "announcer/male/03kills.wav");
467 else if (attacker.killcount == 5)
470 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
472 bprint (a,"^7 unleashes ^1RAGE\n");
473 announce(attacker, "announcer/male/05kills.wav");
476 else if (attacker.killcount == 10)
479 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
481 bprint (a,"^7 starts the ^1MASSACRE!\n");
482 announce(attacker, "announcer/male/10kills.wav");
485 else if (attacker.killcount == 15)
488 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
490 bprint (a,"^7 executes ^1MAYHEM!\n");
491 announce(attacker, "announcer/male/15kills.wav");
494 else if (attacker.killcount == 20)
497 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
499 bprint (a,"^7 is a ^1BERSERKER!\n");
500 announce(attacker, "announcer/male/20kills.wav");
503 else if (attacker.killcount == 25)
506 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
508 bprint (a,"^7 inflicts ^1CARNAGE!\n");
509 announce(attacker, "announcer/male/25kills.wav");
512 else if (attacker.killcount == 30)
515 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
517 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
518 announce(attacker, "announcer/male/30kills.wav");
525 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
526 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
527 bprint ("^1",s, "^1 ", inflictor.message, "\n");
528 else if (deathtype == DEATH_DROWN)
530 bprint ("^1",s, "^1 was in the water for too long\n");
532 bprint ("^1",s, "^1 drowned\n");
533 else if (deathtype == DEATH_SLIME)
534 bprint ("^1",s, "^1 was slimed\n");
535 else if (deathtype == DEATH_LAVA)
537 bprint ("^1",s, "^1 found a hot place\n");
539 bprint ("^1",s, "^1 turned into hot slag\n");
540 else if (deathtype == DEATH_FALL)
542 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
544 bprint ("^1",s, "^1 hit the ground with a crunch\n");
545 else if (deathtype == DEATH_SHOOTING_STAR)
546 bprint ("^1",s, "^1 became a shooting star\n");
547 else if (deathtype == DEATH_SWAMP)
549 bprint ("^1",s, "^1 discovered a swamp\n");
551 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
552 else if(deathtype == DEATH_TURRET)
553 bprint ("^1",s, "^1 was mowed down by a turret \n");
554 else if(deathtype == DEATH_TOUCHEXPLODE)
555 bprint ("^1",s, "^1 died in an accident\n");
556 else if(deathtype == DEATH_CHEAT)
557 bprint ("^1",s, "^1 was unfairly eliminated\n");
558 else if(deathtype == DEATH_FIRE)
560 bprint ("^1",s, "^1 felt a little hot\n");
562 bprint ("^1",s, "^1 burnt to death\n");
565 bprint ("^1",s, "^1 needs a restart\n");
567 bprint ("^1",s, "^1 died\n");
568 GiveFrags(targ, targ, -1);
569 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
570 announce(targ, "announcer/male/botlike.wav");
573 if (targ.killcount > 2)
575 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
577 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
579 LogDeath("accident", deathtype, targ, targ);
581 targ.death_origin = targ.origin;
583 targ.killer_origin = attacker.origin;
584 // FIXME: this should go in PutClientInServer
590 // these are updated by each Damage call for use in button triggering and such
592 entity damage_inflictor;
593 entity damage_attacker;
595 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
600 entity attacker_save;
604 if (gameover || targ.killcount == -666)
607 local entity oldself;
611 damage_inflictor = inflictor;
612 damage_attacker = attacker;
613 attacker_save = attacker;
615 if(targ.classname == "player")
618 if(targ.hook.aiment == attacker)
619 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
621 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
622 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
624 if(targ.classname == "player")
625 if not(IsDifferentTeam(targ, attacker))
632 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
634 // These are ALWAYS lethal
635 // No damage modification here
636 // Instead, prepare the victim for his death...
638 targ.spawnshieldtime = 0;
639 targ.health = 0.9; // this is < 1
640 targ.flags -= targ.flags & FL_GODMODE;
643 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
649 if (targ.classname == "player")
650 if (attacker.classname == "player")
653 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
655 // nullify damage if teamplay is on
656 if(deathtype != DEATH_TELEFRAG)
657 if(attacker.classname == "player")
659 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
664 else if(attacker.team == targ.team)
668 else if(attacker != targ)
672 else if(teamplay == 4)
674 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
676 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
677 attacker.dmg_team = attacker.dmg_team + damage;
678 if(attacker.dmg_team > teamdamage0)
679 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
680 mirrorforce = cvar("g_mirrordamage") * vlen(force);
683 if(cvar("g_friendlyfire") == 0)
687 damage = cvar("g_friendlyfire") * damage;
688 // mirrordamage will be used LATER
697 if(targ.classname == "player")
698 if(attacker.classname == "player")
701 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
702 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
705 if(targ.classname == "player")
708 if ((deathtype == DEATH_FALL) ||
709 (deathtype == DEATH_DROWN) ||
710 (deathtype == DEATH_SLIME) ||
711 (deathtype == DEATH_LAVA))
716 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
718 targ.armorvalue -= 1;
719 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
722 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
724 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
727 if (targ != attacker)
729 if (targ.classname == "player")
730 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
740 if not(DEATH_ISSPECIAL(deathtype))
742 damage *= g_weapondamagefactor;
743 mirrordamage *= g_weapondamagefactor;
744 force = force * g_weaponforcefactor;
745 mirrorforce *= g_weaponforcefactor;
748 // apply strength multiplier
749 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
753 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
754 force = force * cvar("g_balance_powerup_strength_selfforce");
758 damage = damage * cvar("g_balance_powerup_strength_damage");
759 force = force * cvar("g_balance_powerup_strength_force");
763 // apply invincibility multiplier
764 if (targ.items & IT_INVINCIBLE && !g_minstagib)
765 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
767 if (targ == attacker)
768 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
770 // CTF: reduce damage/force
775 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
776 force = force * cvar("g_ctf_flagcarrier_selfforce");
781 // apply strength rune
782 if (attacker.runes & RUNE_STRENGTH)
784 if(attacker.runes & CURSE_WEAK) // have both curse & rune
786 damage = damage * cvar("g_balance_rune_strength_combo_damage");
787 force = force * cvar("g_balance_rune_strength_combo_force");
791 damage = damage * cvar("g_balance_rune_strength_damage");
792 force = force * cvar("g_balance_rune_strength_force");
795 else if (attacker.runes & CURSE_WEAK)
797 damage = damage * cvar("g_balance_curse_weak_damage");
798 force = force * cvar("g_balance_curse_weak_force");
801 // apply defense rune
802 if (targ.runes & RUNE_DEFENSE)
804 if (targ.runes & CURSE_VULNER) // have both curse & rune
805 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
807 damage = damage * cvar("g_balance_rune_defense_takedamage");
809 else if (targ.runes & CURSE_VULNER)
810 damage = damage * cvar("g_balance_curse_vulner_takedamage");
816 if(targ.takedamage == DAMAGE_AIM)
819 if(targ.classname == "player")
822 // find height of hit on player axis
823 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
824 vector headmins, headmaxs, org;
825 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
826 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);
827 headmaxs = org + '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
828 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
830 deathtype |= HITTYPE_HEADSHOT;
833 else if(targ.classname == "turret_head")
835 deathtype |= HITTYPE_HEADSHOT;
837 if(deathtype & HITTYPE_HEADSHOT)
838 damage *= 1 + damage_headshotbonus;
840 if(targ.classname == "player")
842 if(IsDifferentTeam(targ, attacker))
847 attacker.typehitsound += 1;
849 attacker.hitsound += 1;
851 damage_goodhits += 1;
852 damage_gooddamage += damage;
854 if not(DEATH_ISSPECIAL(deathtype))
861 if(targ.items & IT_STRENGTH)
864 if(deathtype & HITTYPE_HEADSHOT)
871 if(deathtype != DEATH_FIRE)
872 attacker.typehitsound += 1;
874 if(time > attacker.teamkill_complain)
876 attacker.teamkill_complain = time + 5;
877 attacker.teamkill_soundtime = time + 0.4;
878 attacker.teamkill_soundsource = targ;
886 if (self.damageforcescale)
889 self.velocity = self.velocity + self.damageforcescale * force;
890 self.flags &~= FL_ONGROUND;
891 UpdateCSQCProjectile(self);
894 if (damage != 0 || (self.damageforcescale && vlen(force)))
895 if (self.event_damage)
896 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
899 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
901 // Savage: vampire mode
904 if (time > self.spawnshieldtime)
906 attacker.health += damage;
910 if (attacker.runes & RUNE_VAMPIRE)
912 // apply vampire rune
913 if (attacker.runes & CURSE_EMPATHY) // have the curse too
915 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
916 attacker.health = bound(
917 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
918 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
919 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
923 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
924 attacker.health = bound(
925 attacker.health, // LA: was 3, but changed so that you can't lose health
926 // empathy won't let you gain health in the same way...
927 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
928 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
931 // apply empathy curse
932 else if (attacker.runes & CURSE_EMPATHY)
934 attacker.health = bound(
935 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
936 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
942 // apply mirror damage if any
943 if(mirrordamage > 0 || mirrorforce > 0)
945 attacker = attacker_save;
949 // just lose extra LIVES, don't kill the player for mirror damage
950 if(attacker.armorvalue > 0)
952 attacker.armorvalue = attacker.armorvalue - 1;
953 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
954 attacker.hitsound += 1;
958 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
959 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
963 vector NearestPointOnBox(entity box, vector org)
965 vector m1, m2, nearest;
967 m1 = box.mins + box.origin;
968 m2 = box.maxs + box.origin;
970 nearest_x = bound(m1_x, org_x, m2_x);
971 nearest_y = bound(m1_y, org_y, m2_y);
972 nearest_z = bound(m1_z, org_z, m2_z);
977 .float actual_damage[WEP_COUNT]; //amount of damage done
978 .float max_damage[WEP_COUNT]; //the maximum damage of the weapon
980 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(actual_damage);
981 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(max_damage);
983 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
986 weaponid = DEATH_WEAPONOF(deathtype);
987 if not(inWarmupStage)
989 if(clienttype(attacker) == CLIENTTYPE_REAL)
991 // Track damage done and update the stat to be sent later in g_world.qc
992 attacker.actual_damage[weaponid] += damage;
993 attacker.damage_hits = weaponid + 64 * rint(attacker.actual_damage[weaponid]);
997 float RadiusDamage_running;
998 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
999 // Returns total damage applies to creatures
1009 float total_damage_to_creatures;
1014 float stat_damagedone;
1015 float stat_maxdamage;
1017 if(RadiusDamage_running)
1020 print("RadiusDamage called recursively!\n");
1021 print("Expect stuff to go HORRIBLY wrong.\n");
1022 print("Causing a stack trace...\n");
1023 save = cvar_string("prvm_backtraceforwarnings");
1024 cvar_set("prvm_backtraceforwarnings", "1");
1025 fclose(-1); // calls VM_Warning
1026 cvar_set("prvm_backtraceforwarnings", save);
1030 RadiusDamage_running = 1;
1032 tfloordmg = cvar("g_throughfloor_damage");
1033 tfloorforce = cvar("g_throughfloor_force");
1035 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1036 total_damage_to_creatures = 0;
1038 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1040 force = inflictor.velocity;
1041 if(vlen(force) == 0)
1044 force = normalize(force);
1045 if(forceintensity >= 0)
1046 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1048 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1051 stat_damagedone = 0;
1054 targ = findradius (blastorigin, rad);
1058 if (targ != inflictor)
1059 if (ignore != targ) if(targ.takedamage)
1061 // LordHavoc: measure distance to nearest point on target (not origin)
1062 // (this guarentees 100% damage on a touch impact)
1063 nearest = NearestPointOnBox(targ, blastorigin);
1064 diff = nearest - blastorigin;
1065 // round up a little on the damage to ensure full damage on impacts
1066 // and turn the distance into a fraction of the radius
1067 power = 1 - ((vlen (diff) - 2) / rad);
1069 //bprint(ftos(power));
1070 //if (targ == attacker)
1071 // print(ftos(power), "\n");
1076 finaldmg = coredamage * power + edgedamage * (1 - power);
1083 local float hitratio;
1084 local vector hitloc;
1085 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1086 // if it's a player, use the view origin as reference
1087 if (targ.classname == "player")
1088 center = targ.origin + targ.view_ofs;
1089 force = normalize(center - blastorigin);
1090 force = force * (finaldmg / coredamage) * forceintensity;
1091 // test line of sight to multiple positions on box,
1092 // and do damage if any of them hit
1094 if (targ.classname == "player")
1095 total = ceil(bound(1, finaldmg, 50));
1097 total = ceil(bound(1, finaldmg/10, 5));
1102 traceline(blastorigin, nearest, MOVE_NOMONSTERS, inflictor);
1103 if (trace_fraction == 1 || trace_ent == targ)
1107 hitloc = hitloc + nearest;
1111 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1112 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1113 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1116 nearest = hitloc * (1 / max(1, hits));
1117 hitratio = (hits / total);
1118 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1119 finaldmg = finaldmg * a;
1120 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1122 //if (targ == attacker)
1124 // print("hits ", ftos(hits), " / ", ftos(total));
1125 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1126 // print(" (", ftos(a), ")\n");
1128 if(hits || tfloordmg || tfloorforce)
1132 total_damage_to_creatures += finaldmg;
1134 if(targ.flags & FL_CLIENT)
1135 if(targ.deadflag == DEAD_NO)
1136 if(targ != attacker)
1137 if(!teamplay || targ.team != attacker.team)
1139 stat_damagedone += finaldmg;
1140 stat_maxdamage += coredamage;
1144 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1145 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1147 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1155 RadiusDamage_running = 0;
1157 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1159 return total_damage_to_creatures;
1162 .float fire_damagepersec;
1163 .float fire_endtime;
1164 .float fire_deathtype;
1166 .float fire_hitsound;
1167 .entity fire_burner;
1169 void fireburner_think();
1171 float Fire_IsBurning(entity e)
1173 return (time < e.fire_endtime);
1176 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1179 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1181 if(e.classname == "player")
1190 // print("adding a fire burner to ", e.classname, "\n");
1191 e.fire_burner = spawn();
1192 e.fire_burner.classname = "fireburner";
1193 e.fire_burner.think = fireburner_think;
1194 e.fire_burner.nextthink = time;
1195 e.fire_burner.owner = e;
1201 if(Fire_IsBurning(e))
1203 mintime = e.fire_endtime - time;
1204 maxtime = max(mintime, t);
1206 mindps = e.fire_damagepersec;
1207 maxdps = max(mindps, dps);
1209 if(maxtime > mintime || maxdps > mindps)
1211 mindamage = mindps * mintime;
1212 maxdamage = mindamage + d;
1214 // interval [mintime, maxtime] * [mindps, maxdps]
1216 // [mindamage, maxdamage]
1219 if(maxdamage >= maxtime * maxdps)
1221 totaltime = maxtime;
1222 totaldamage = maxtime * maxdps;
1224 // this branch increases totaldamage if either t > mintime, or dps > mindps
1228 // maxdamage is inside the interval!
1229 // first, try to use mindps; only if this fails, increase dps as needed
1230 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1231 totaldamage = maxdamage;
1232 // can totaldamage / totaltime be >= maxdps?
1233 // max(mindps, maxdamage / maxtime) >= maxdps?
1234 // we know maxdamage < maxtime * maxdps
1237 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1240 // total conditions for increasing:
1241 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1243 // if maxtime = mintime, maxdps = mindps
1245 // maxdamage = mindamage + d
1246 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1247 // so the last condition is not needed
1249 e.fire_damagepersec = totaldamage / totaltime;
1250 e.fire_endtime = time + totaltime;
1251 if(totaldamage > 1.2 * mindamage)
1253 e.fire_deathtype = dt;
1254 if(e.fire_owner != o)
1257 e.fire_hitsound = FALSE;
1260 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1267 e.fire_damagepersec = dps;
1268 e.fire_endtime = time + t;
1269 e.fire_deathtype = dt;
1271 e.fire_hitsound = FALSE;
1276 void Fire_ApplyDamage(entity e)
1280 if not(Fire_IsBurning(e))
1283 // water and slime stop fire
1285 if(e.watertype != CONTENT_LAVA)
1288 t = min(frametime, e.fire_endtime - time);
1289 d = e.fire_damagepersec * t;
1291 hi = e.fire_owner.hitsound;
1292 ty = e.fire_owner.typehitsound;
1293 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1294 if(e.fire_hitsound && e.fire_owner)
1296 e.fire_owner.hitsound = hi;
1297 e.fire_owner.typehitsound = ty;
1299 e.fire_hitsound = TRUE;
1301 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1303 if not(IS_INDEPENDENT_PLAYER(e))
1304 FOR_EACH_PLAYER(other) if(e != other)
1306 if(other.classname == "player")
1307 if(other.deadflag == DEAD_NO)
1308 if not(IS_INDEPENDENT_PLAYER(other))
1309 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1311 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1312 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1313 Fire_AddDamage(other, e, d, t, DEATH_FIRE);
1318 void Fire_ApplyEffect(entity e)
1320 if(Fire_IsBurning(e))
1321 e.effects |= EF_FLAME;
1323 e.effects &~= EF_FLAME;
1326 void fireburner_think()
1328 // for players, this is done in the regular loop
1329 if(wasfreed(self.owner))
1334 Fire_ApplyEffect(self.owner);
1335 if(!Fire_IsBurning(self.owner))
1337 self.owner.fire_burner = world;
1341 Fire_ApplyDamage(self.owner);
1342 self.nextthink = time;