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)
98 // TODO route through PlayerScores instead
106 PlayerScore_Add(attacker, SP_SUICIDES, 1);
111 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
117 PlayerScore_Add(attacker, SP_KILLS, 1);
120 PlayerScore_Add(targ, SP_DEATHS, 1);
123 if(cvar("g_arena_roundbased"))
126 if(targ != attacker) // not for suicides
127 if(g_weaponarena_random)
129 // after a frag, choose another random weapon set
130 attacker.weapons = randombits((inWarmupStage ? warmup_start_weapons : start_weapons), g_weaponarena_random);
131 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
132 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
135 // FIXME fix the mess this is (we have REAL points now!)
138 f = RunematchHandleFrags(attacker, targ, f);
142 f = kh_HandleFrags(attacker, targ, f);
148 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
149 if(tl < lms_lowest_lives)
150 lms_lowest_lives = tl;
154 lms_next_place = player_count;
155 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
162 if(g_ctf_ignore_frags)
166 attacker.totalfrags += f;
169 UpdateFrags(attacker, f);
172 string AppendItemcodes(string s, entity player)
177 // w = player.switchweapon;
179 w = player.cnt; // previous weapon!
180 s = strcat(s, ftos(w));
181 if(time < player.strength_finished)
183 if(time < player.invincible_finished)
185 if(player.flagcarried != world)
187 if(player.BUTTON_CHAT)
192 s = strcat(s, "|", ftos(player.runes));
196 void LogDeath(string mode, float deathtype, entity killer, entity killed)
199 if(!cvar("sv_eventlog"))
201 s = strcat(":kill:", mode);
202 s = strcat(s, ":", ftos(killer.playerid));
203 s = strcat(s, ":", ftos(killed.playerid));
204 s = strcat(s, ":type=", ftos(deathtype));
205 s = strcat(s, ":items=");
206 s = AppendItemcodes(s, killer);
209 s = strcat(s, ":victimitems=");
210 s = AppendItemcodes(s, killed);
215 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
220 if (targ.classname == "player" || targ.classname == "corpse")
222 if (targ.classname == "corpse")
226 a = attacker.netname;
228 if (targ == attacker)
230 if (deathtype == DEATH_TEAMCHANGE) {
231 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
232 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
233 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)));
235 } else if (deathtype == DEATH_CAMP) {
237 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
239 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
240 } else if (deathtype == DEATH_NOAMMO) {
242 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
244 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
245 } else if (deathtype == DEATH_ROT) {
247 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
249 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
250 } else if (deathtype == DEATH_MIRRORDAMAGE) {
252 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
254 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
257 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
259 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
263 if (deathtype == DEATH_CAMP)
264 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
265 else if (deathtype == DEATH_MIRRORDAMAGE)
266 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
268 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
270 if(deathtype != DEATH_TEAMCHANGE)
272 LogDeath("suicide", deathtype, targ, targ);
273 GiveFrags(attacker, targ, -1);
275 if (targ.killcount > 2)
276 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
278 w = DEATH_WEAPONOF(deathtype);
281 w_deathtypestring = "couldn't resist the urge to self-destruct";
282 w_deathtype = deathtype;
283 weapon_action(w, WR_SUICIDEMESSAGE);
284 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
286 else if (deathtype == DEATH_KILL)
287 bprint ("^1",s, "^1 couldn't take it anymore\n");
288 else if (deathtype == DEATH_ROT)
289 bprint ("^1",s, "^1 died\n");
290 else if (deathtype == DEATH_NOAMMO)
291 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
292 else if (deathtype == DEATH_CAMP)
293 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
294 else if (deathtype == DEATH_MIRRORDAMAGE)
295 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
296 else if (deathtype == DEATH_CHEAT)
297 bprint ("^1",s, "^1 unfairly eliminated himself\n");
298 else if (deathtype == DEATH_FIRE)
299 bprint ("^1",s, "^1 burned to death\n");
300 else if (deathtype != DEATH_TEAMCHANGE)
301 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
303 if(deathtype != DEATH_TEAMCHANGE)
305 LogDeath("suicide", deathtype, targ, targ);
306 GiveFrags(attacker, targ, -1);
308 if (targ.killcount > 2)
309 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
312 else if (attacker.classname == "player" || attacker.classname == "gib")
314 if(teams_matter && attacker.team == targ.team)
317 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
318 bprint ("^1", a, "^1 took action against a team mate\n");
320 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
321 bprint ("^1", a, "^1 mows down a team mate\n");
323 GiveFrags(attacker, targ, -1);
324 if (targ.killcount > 2) {
326 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
328 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
330 if (attacker.killcount > 2) {
332 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
334 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
336 attacker.killcount = 0;
338 LogDeath("tk", deathtype, attacker, targ);
342 string blood_message, victim_message;
343 if (!checkrules_firstblood)
345 checkrules_firstblood = TRUE;
348 bprint("^1",a, "^1 was the first to score", "\n");
349 blood_message = "^1First point\n";
350 //victim_message = "^1First victim\n"; // or First casualty
354 bprint("^1",a, "^1 drew first blood", "\n");
355 blood_message = "^1First blood\n";
356 victim_message = "^1First victim\n"; // or First casualty
361 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s));
362 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7"));
364 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s));
365 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a));
366 attacker.taunt_soundtime = time + 1;
370 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
372 w = DEATH_WEAPONOF(deathtype);
375 w_deathtypestring = "was blasted by";
376 w_deathtype = deathtype;
377 weapon_action(w, WR_KILLMESSAGE);
378 p = strstrofs(w_deathtypestring, "#", 0);
380 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
382 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
384 else if (deathtype == DEATH_TELEFRAG)
385 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
386 else if (deathtype == DEATH_DROWN)
387 bprint ("^1",s, "^1 was drowned by ", a, "\n");
388 else if (deathtype == DEATH_SLIME)
389 bprint ("^1",s, "^1 was slimed by ", a, "\n");
390 else if (deathtype == DEATH_LAVA)
391 bprint ("^1",s, "^1 was cooked by ", a, "\n");
392 else if (deathtype == DEATH_FALL)
393 bprint ("^1",s, "^1 was grounded by ", a, "\n");
394 else if (deathtype == DEATH_SHOOTING_STAR)
395 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
396 else if (deathtype == DEATH_SWAMP)
397 bprint ("^1",s, "^1 was conserved by ", a, "\n");
398 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
400 p = strstrofs(inflictor.message2, "#", 0);
402 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
404 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
406 else if(deathtype == DEATH_TURRET)
407 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
408 else if(deathtype == DEATH_TOUCHEXPLODE)
409 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
410 else if(deathtype == DEATH_CHEAT)
411 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
412 else if (deathtype == DEATH_FIRE)
413 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
415 bprint ("^1",s, "^1 was fragged by ", a, "\n");
418 if(g_ctf && targ.flagcarried)
420 UpdateFrags(attacker, ctf_score_value("score_kill"));
421 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
422 GiveFrags(attacker, targ, 0); // for logging
425 GiveFrags(attacker, targ, 1);
427 if (targ.killcount > 2) {
429 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
431 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
434 attacker.killcount = attacker.killcount + 1;
436 if (attacker.killcount > 2) {
438 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
440 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
443 LogDeath("frag", deathtype, attacker, targ);
445 if (attacker.killcount == 3)
448 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
450 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
451 announce(attacker, "announcer/male/03kills.wav");
454 else if (attacker.killcount == 5)
457 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
459 bprint (a,"^7 unleashes ^1RAGE\n");
460 announce(attacker, "announcer/male/05kills.wav");
463 else if (attacker.killcount == 10)
466 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
468 bprint (a,"^7 starts the ^1MASSACRE!\n");
469 announce(attacker, "announcer/male/10kills.wav");
472 else if (attacker.killcount == 15)
475 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
477 bprint (a,"^7 executes ^1MAYHEM!\n");
478 announce(attacker, "announcer/male/15kills.wav");
481 else if (attacker.killcount == 20)
484 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
486 bprint (a,"^7 is a ^1BERSERKER!\n");
487 announce(attacker, "announcer/male/20kills.wav");
490 else if (attacker.killcount == 25)
493 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
495 bprint (a,"^7 inflicts ^1CARNAGE!\n");
496 announce(attacker, "announcer/male/25kills.wav");
499 else if (attacker.killcount == 30)
502 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
504 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
505 announce(attacker, "announcer/male/30kills.wav");
512 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
513 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
514 bprint ("^1",s, "^1 ", inflictor.message, "\n");
515 else if (deathtype == DEATH_DROWN)
517 bprint ("^1",s, "^1 was in the water for too long\n");
519 bprint ("^1",s, "^1 drowned\n");
520 else if (deathtype == DEATH_SLIME)
521 bprint ("^1",s, "^1 was slimed\n");
522 else if (deathtype == DEATH_LAVA)
524 bprint ("^1",s, "^1 found a hot place\n");
526 bprint ("^1",s, "^1 turned into hot slag\n");
527 else if (deathtype == DEATH_FALL)
529 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
531 bprint ("^1",s, "^1 hit the ground with a crunch\n");
532 else if (deathtype == DEATH_SHOOTING_STAR)
533 bprint ("^1",s, "^1 became a shooting star\n");
534 else if (deathtype == DEATH_SWAMP)
536 bprint ("^1",s, "^1 discovered a swamp\n");
538 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
539 else if(deathtype == DEATH_TURRET)
540 bprint ("^1",s, "^1 was mowed down by a turret \n");
541 else if(deathtype == DEATH_TOUCHEXPLODE)
542 bprint ("^1",s, "^1 died in an accident\n");
543 else if(deathtype == DEATH_CHEAT)
544 bprint ("^1",s, "^1 was unfairly eliminated\n");
545 else if(deathtype == DEATH_FIRE)
547 bprint ("^1",s, "^1 felt a little hot\n");
549 bprint ("^1",s, "^1 burnt to death\n");
552 bprint ("^1",s, "^1 needs a restart\n");
554 bprint ("^1",s, "^1 died\n");
555 GiveFrags(targ, targ, -1);
556 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
557 announce(targ, "announcer/male/botlike.wav");
560 if (targ.killcount > 2)
562 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
564 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
566 LogDeath("accident", deathtype, targ, targ);
568 targ.death_origin = targ.origin;
570 targ.killer_origin = attacker.origin;
571 // FIXME: this should go in PutClientInServer
577 // these are updated by each Damage call for use in button triggering and such
579 entity damage_inflictor;
580 entity damage_attacker;
582 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
587 entity attacker_save;
591 if (gameover || targ.killcount == -666)
594 local entity oldself;
598 damage_inflictor = inflictor;
599 damage_attacker = attacker;
600 attacker_save = attacker;
602 if(targ.classname == "player")
605 if(targ.hook.aiment == attacker)
606 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
608 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
609 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
611 if(targ.classname == "player")
612 if not(IsDifferentTeam(targ, attacker))
619 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
621 // These are ALWAYS lethal
622 // No damage modification here
623 // Instead, prepare the victim for his death...
625 targ.spawnshieldtime = 0;
626 targ.health = 0.9; // this is < 1
627 targ.flags -= targ.flags & FL_GODMODE;
630 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
636 if (targ.classname == "player")
637 if (attacker.classname == "player")
640 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
642 // nullify damage if teamplay is on
643 if(deathtype != DEATH_TELEFRAG)
644 if(attacker.classname == "player")
646 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
651 else if(attacker.team == targ.team)
655 else if(attacker != targ)
659 else if(teamplay == 4)
661 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
663 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
664 attacker.dmg_team = attacker.dmg_team + damage;
665 if(attacker.dmg_team > teamdamage0)
666 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
667 mirrorforce = cvar("g_mirrordamage") * vlen(force);
670 if(cvar("g_friendlyfire") == 0)
674 damage = cvar("g_friendlyfire") * damage;
675 // mirrordamage will be used LATER
684 if(targ.classname == "player")
685 if(attacker.classname == "player")
688 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
689 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
692 if(targ.classname == "player")
695 if ((deathtype == DEATH_FALL) ||
696 (deathtype == DEATH_DROWN) ||
697 (deathtype == DEATH_SLIME) ||
698 (deathtype == DEATH_LAVA))
703 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
705 targ.armorvalue -= 1;
706 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
709 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
711 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
714 if (targ != attacker)
716 if (targ.classname == "player")
717 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
727 if not(DEATH_ISSPECIAL(deathtype))
729 damage *= g_weapondamagefactor;
730 mirrordamage *= g_weapondamagefactor;
731 force = force * g_weaponforcefactor;
732 mirrorforce *= g_weaponforcefactor;
735 // apply strength multiplier
736 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
740 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
741 force = force * cvar("g_balance_powerup_strength_selfforce");
745 damage = damage * cvar("g_balance_powerup_strength_damage");
746 force = force * cvar("g_balance_powerup_strength_force");
750 // apply invincibility multiplier
751 if (targ.items & IT_INVINCIBLE && !g_minstagib)
752 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
754 if (targ == attacker)
755 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
757 // CTF: reduce damage/force
762 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
763 force = force * cvar("g_ctf_flagcarrier_selfforce");
768 // apply strength rune
769 if (attacker.runes & RUNE_STRENGTH)
771 if(attacker.runes & CURSE_WEAK) // have both curse & rune
773 damage = damage * cvar("g_balance_rune_strength_combo_damage");
774 force = force * cvar("g_balance_rune_strength_combo_force");
778 damage = damage * cvar("g_balance_rune_strength_damage");
779 force = force * cvar("g_balance_rune_strength_force");
782 else if (attacker.runes & CURSE_WEAK)
784 damage = damage * cvar("g_balance_curse_weak_damage");
785 force = force * cvar("g_balance_curse_weak_force");
788 // apply defense rune
789 if (targ.runes & RUNE_DEFENSE)
791 if (targ.runes & CURSE_VULNER) // have both curse & rune
792 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
794 damage = damage * cvar("g_balance_rune_defense_takedamage");
796 else if (targ.runes & CURSE_VULNER)
797 damage = damage * cvar("g_balance_curse_vulner_takedamage");
803 if(targ.takedamage == DAMAGE_AIM)
805 if(targ.classname == "player")
807 if(IsDifferentTeam(targ, attacker))
812 attacker.typehitsound += 1;
814 attacker.hitsound += 1;
816 damage_goodhits += 1;
817 damage_gooddamage += damage;
819 if not(DEATH_ISSPECIAL(deathtype))
826 if(targ.items & IT_STRENGTH)
830 // find height of hit on player axis
831 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
832 vector headmins, headmaxs, org;
833 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
834 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);
835 headmaxs = org + '0.7 0 0' * targ.maxs_x + '0 0.7 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
836 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
838 damage *= 1 + damage_headshotbonus;
840 deathtype |= HITTYPE_HEADSHOT;
847 if(deathtype != DEATH_FIRE)
848 attacker.typehitsound += 1;
850 if(time > attacker.teamkill_complain)
852 attacker.teamkill_complain = time + 5;
853 attacker.teamkill_soundtime = time + 0.4;
854 attacker.teamkill_soundsource = targ;
861 if (self.damageforcescale)
864 self.velocity = self.velocity + self.damageforcescale * force;
865 self.flags &~= FL_ONGROUND;
866 UpdateCSQCProjectile(self);
869 if (damage != 0 || (self.damageforcescale && vlen(force)))
870 if (self.event_damage)
871 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
874 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
876 // Savage: vampire mode
879 if (time > self.spawnshieldtime)
881 attacker.health += damage;
885 if (attacker.runes & RUNE_VAMPIRE)
887 // apply vampire rune
888 if (attacker.runes & CURSE_EMPATHY) // have the curse too
890 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
891 attacker.health = bound(
892 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
893 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
894 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
898 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
899 attacker.health = bound(
900 attacker.health, // LA: was 3, but changed so that you can't lose health
901 // empathy won't let you gain health in the same way...
902 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
903 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
906 // apply empathy curse
907 else if (attacker.runes & CURSE_EMPATHY)
909 attacker.health = bound(
910 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
911 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
917 // apply mirror damage if any
918 if(mirrordamage > 0 || mirrorforce > 0)
920 attacker = attacker_save;
924 // just lose extra LIVES, don't kill the player for mirror damage
925 if(attacker.armorvalue > 0)
927 attacker.armorvalue = attacker.armorvalue - 1;
928 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
929 attacker.hitsound += 1;
933 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
934 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
938 vector NearestPointOnBox(entity box, vector org)
940 vector m1, m2, nearest;
942 m1 = box.mins + box.origin;
943 m2 = box.maxs + box.origin;
945 nearest_x = bound(m1_x, org_x, m2_x);
946 nearest_y = bound(m1_y, org_y, m2_y);
947 nearest_z = bound(m1_z, org_z, m2_z);
952 .float actual_damage[WEP_COUNT]; //amount of damage done
953 .float max_damage[WEP_COUNT]; //the maximum damage of the weapon
955 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(actual_damage);
956 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(max_damage);
958 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
961 weaponid = DEATH_WEAPONOF(deathtype);
962 if not(inWarmupStage)
964 if(clienttype(attacker) == CLIENTTYPE_REAL)
966 // Track damage done and update the stat to be sent later in g_world.qc
967 attacker.actual_damage[weaponid] += damage;
968 attacker.damage_hits = weaponid + 64 * rint(attacker.actual_damage[weaponid]);
972 float RadiusDamage_running;
973 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
974 // Returns total damage applies to creatures
984 float total_damage_to_creatures;
987 float stat_damagedone;
988 float stat_maxdamage;
990 if(RadiusDamage_running)
993 print("RadiusDamage called recursively!\n");
994 print("Expect stuff to go HORRIBLY wrong.\n");
995 print("Causing a stack trace...\n");
996 save = cvar_string("prvm_backtraceforwarnings");
997 cvar_set("prvm_backtraceforwarnings", "1");
998 fclose(-1); // calls VM_Warning
999 cvar_set("prvm_backtraceforwarnings", save);
1004 RadiusDamage_running = 1;
1006 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1007 total_damage_to_creatures = 0;
1009 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1011 force = inflictor.velocity;
1012 if(vlen(force) == 0)
1015 force = normalize(force);
1016 if(forceintensity >= 0)
1017 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1019 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1022 stat_damagedone = 0;
1025 targ = findradius (blastorigin, rad);
1029 if (targ != inflictor)
1032 // LordHavoc: measure distance to nearest point on target (not origin)
1033 // (this guarentees 100% damage on a touch impact)
1034 nearest = NearestPointOnBox(targ, blastorigin);
1035 diff = nearest - blastorigin;
1036 // round up a little on the damage to ensure full damage on impacts
1037 // and turn the distance into a fraction of the radius
1038 power = 1 - ((vlen (diff) - 2) / rad);
1040 //bprint(ftos(power));
1045 finaldmg = coredamage * power + edgedamage * (1 - power);
1048 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1049 // if it's a player, use the view origin as reference
1050 if (targ.classname == "player")
1051 center = targ.origin + targ.view_ofs;
1052 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
1053 // test line of sight to multiple positions on box,
1054 // and do damage if any of them hit
1056 c = ceil(finaldmg / 10);
1062 traceline(blastorigin, nearest, TRUE, inflictor);
1063 if (trace_fraction == 1 || trace_ent == targ
1064 || cvar("g_throughfloor"))
1068 total_damage_to_creatures += finaldmg;
1070 if(targ.flags & FL_CLIENT)
1071 if(targ.deadflag == DEAD_NO)
1072 if(targ != attacker)
1073 if(!teamplay || targ.team != attacker.team)
1075 stat_damagedone += finaldmg;
1076 stat_maxdamage += coredamage;
1080 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1081 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1083 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1086 nearest_x = targ.mins_x + random() * targ.size_x;
1087 nearest_y = targ.mins_y + random() * targ.size_y;
1088 nearest_z = targ.mins_z + random() * targ.size_z;
1096 RadiusDamage_running = 0;
1098 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1100 return total_damage_to_creatures;
1103 .float fire_damagepersec;
1104 .float fire_endtime;
1105 .float fire_deathtype;
1107 .float fire_hitsound;
1108 .entity fire_burner;
1110 void fireburner_think();
1112 float Fire_IsBurning(entity e)
1114 return (time < e.fire_endtime);
1117 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1120 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1122 if(e.classname != "player")
1125 // print("adding a fire burner to ", e.classname, "\n");
1126 e.fire_burner = spawn();
1127 e.fire_burner.classname = "fireburner";
1128 e.fire_burner.think = fireburner_think;
1129 e.fire_burner.nextthink = time;
1130 e.fire_burner.owner = e;
1135 if(Fire_IsBurning(e))
1137 mintime = e.fire_endtime - time;
1138 maxtime = max(mintime, t);
1140 mindps = e.fire_damagepersec;
1141 maxdps = max(mindps, dps);
1143 if(maxtime > mintime || maxdps > mindps)
1145 mindamage = mindps * mintime;
1146 maxdamage = mindamage + d;
1148 // interval [mintime, maxtime] * [mindps, maxdps]
1150 // [mindamage, maxdamage]
1153 if(maxdamage >= maxtime * maxdps)
1155 totaltime = maxtime;
1156 totaldamage = maxtime * maxdps;
1158 // this branch increases totaldamage if either t > mintime, or dps > mindps
1162 // maxdamage is inside the interval!
1163 // first, try to use mindps; only if this fails, increase dps as needed
1164 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1165 totaldamage = maxdamage;
1166 // can totaldamage / totaltime be >= maxdps?
1167 // max(mindps, maxdamage / maxtime) >= maxdps?
1168 // we know maxdamage < maxtime * maxdps
1171 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1174 // total conditions for increasing:
1175 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1177 // if maxtime = mintime, maxdps = mindps
1179 // maxdamage = mindamage + d
1180 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1181 // so the last condition is not needed
1183 e.fire_damagepersec = totaldamage / totaltime;
1184 e.fire_endtime = time + totaltime;
1185 if(totaldamage > 1.2 * mindamage)
1186 if(e.fire_owner != o)
1188 e.fire_deathtype = dt;
1190 e.fire_hitsound = FALSE;
1192 return totaldamage - mindamage; // can never be negative
1199 e.fire_damagepersec = dps;
1200 e.fire_endtime = time + t;
1201 e.fire_deathtype = dt;
1203 e.fire_hitsound = FALSE;
1208 void Fire_ApplyDamage(entity e)
1212 if not(Fire_IsBurning(e))
1215 // water and slime stop fire
1217 if(e.watertype != CONTENT_LAVA)
1220 t = min(frametime, e.fire_endtime - time);
1221 d = e.fire_damagepersec * t;
1223 hi = e.fire_owner.hitsound;
1224 ty = e.fire_owner.typehitsound;
1225 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1226 if(e.fire_hitsound && e.fire_owner)
1228 e.fire_owner.hitsound = hi;
1229 e.fire_owner.typehitsound = ty;
1231 e.fire_hitsound = TRUE;
1233 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1235 if not(IS_INDEPENDENT_PLAYER(e))
1236 FOR_EACH_PLAYER(other) if(e != other)
1238 if(other.classname == "player")
1239 if(other.deadflag == DEAD_NO)
1240 if not(IS_INDEPENDENT_PLAYER(other))
1241 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1243 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1244 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1245 Fire_AddDamage(other, e, d, t, DEATH_FIRE);
1250 void Fire_ApplyEffect(entity e)
1252 if(Fire_IsBurning(e))
1253 e.effects |= EF_FLAME;
1255 e.effects &~= EF_FLAME;
1258 void fireburner_think()
1260 // for players, this is done in the regular loop
1261 if(wasfreed(self.owner))
1266 Fire_ApplyEffect(self.owner);
1267 if(!Fire_IsBurning(self.owner))
1269 self.owner.fire_burner = world;
1273 Fire_ApplyDamage(self.owner);
1274 self.nextthink = time;