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 // FIXME fix the mess this is (we have REAL points now!)
128 f = RunematchHandleFrags(attacker, targ, f);
132 f = kh_HandleFrags(attacker, targ, f);
138 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
139 if(tl < lms_lowest_lives)
140 lms_lowest_lives = tl;
144 lms_next_place = player_count;
145 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
152 if(g_ctf_ignore_frags)
156 attacker.totalfrags += f;
159 UpdateFrags(attacker, f);
162 string AppendItemcodes(string s, entity player)
167 // w = player.switchweapon;
169 w = player.cnt; // previous weapon!
170 s = strcat(s, ftos(w));
171 if(time < player.strength_finished)
173 if(time < player.invincible_finished)
175 if(player.flagcarried != world)
177 if(player.BUTTON_CHAT)
182 s = strcat(s, "|", ftos(player.runes));
186 void LogDeath(string mode, float deathtype, entity killer, entity killed)
189 if(!cvar("sv_eventlog"))
191 s = strcat(":kill:", mode);
192 s = strcat(s, ":", ftos(killer.playerid));
193 s = strcat(s, ":", ftos(killed.playerid));
194 s = strcat(s, ":type=", ftos(deathtype));
195 s = strcat(s, ":items=");
196 s = AppendItemcodes(s, killer);
199 s = strcat(s, ":victimitems=");
200 s = AppendItemcodes(s, killed);
205 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
210 if (targ.classname == "player" || targ.classname == "corpse")
212 if (targ.classname == "corpse")
216 a = attacker.netname;
218 if (targ == attacker)
220 if (deathtype == DEATH_TEAMCHANGE) {
221 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
222 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
223 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)));
225 } else if (deathtype == DEATH_CAMP) {
227 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
229 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
230 } else if (deathtype == DEATH_NOAMMO) {
232 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
234 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
235 } else if (deathtype == DEATH_ROT) {
237 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
239 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
240 } else if (deathtype == DEATH_MIRRORDAMAGE) {
242 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
244 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
247 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
249 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
253 if (deathtype == DEATH_CAMP)
254 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
255 else if (deathtype == DEATH_MIRRORDAMAGE)
256 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
258 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
260 if(deathtype != DEATH_TEAMCHANGE)
262 LogDeath("suicide", deathtype, targ, targ);
263 GiveFrags(attacker, targ, -1);
265 if (targ.killcount > 2)
266 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
268 w = DEATH_WEAPONOF(deathtype);
271 w_deathtypestring = "couldn't resist the urge to self-destruct";
272 w_deathtype = deathtype;
273 weapon_action(w, WR_SUICIDEMESSAGE);
274 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
276 else if (deathtype == DEATH_KILL)
277 bprint ("^1",s, "^1 couldn't take it anymore\n");
278 else if (deathtype == DEATH_ROT)
279 bprint ("^1",s, "^1 died\n");
280 else if (deathtype == DEATH_NOAMMO)
281 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
282 else if (deathtype == DEATH_CAMP)
283 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
284 else if (deathtype == DEATH_MIRRORDAMAGE)
285 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
286 else if (deathtype == DEATH_CHEAT)
287 bprint ("^1",s, "^1 unfairly eliminated himself\n");
288 else if (deathtype == DEATH_FIRE)
289 bprint ("^1",s, "^1 burned to death\n");
290 else if (deathtype != DEATH_TEAMCHANGE)
291 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
293 if(deathtype != DEATH_TEAMCHANGE)
295 LogDeath("suicide", deathtype, targ, targ);
296 GiveFrags(attacker, targ, -1);
298 if (targ.killcount > 2)
299 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
302 else if (attacker.classname == "player" || attacker.classname == "gib")
304 if(teams_matter && attacker.team == targ.team)
307 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
308 bprint ("^1", a, "^1 took action against a team mate\n");
310 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
311 bprint ("^1", a, "^1 mows down a team mate\n");
313 GiveFrags(attacker, targ, -1);
314 if (targ.killcount > 2) {
316 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
318 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
320 if (attacker.killcount > 2) {
322 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
324 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
326 attacker.killcount = 0;
328 LogDeath("tk", deathtype, attacker, targ);
332 string blood_message, victim_message;
333 if (!checkrules_firstblood)
335 checkrules_firstblood = TRUE;
338 bprint("^1",a, "^1 was the first to score", "\n");
339 blood_message = "^1First point\n";
340 //victim_message = "^1First victim\n"; // or First casualty
344 bprint("^1",a, "^1 drew first blood", "\n");
345 blood_message = "^1First blood\n";
346 victim_message = "^1First victim\n"; // or First casualty
351 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s));
352 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7"));
354 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s));
355 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a));
356 attacker.taunt_soundtime = time + 1;
360 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
362 w = DEATH_WEAPONOF(deathtype);
365 w_deathtypestring = "was blasted by";
366 w_deathtype = deathtype;
367 weapon_action(w, WR_KILLMESSAGE);
368 p = strstrofs(w_deathtypestring, "#", 0);
370 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
372 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
374 else if (deathtype == DEATH_TELEFRAG)
375 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
376 else if (deathtype == DEATH_DROWN)
377 bprint ("^1",s, "^1 was drowned by ", a, "\n");
378 else if (deathtype == DEATH_SLIME)
379 bprint ("^1",s, "^1 was slimed by ", a, "\n");
380 else if (deathtype == DEATH_LAVA)
381 bprint ("^1",s, "^1 was cooked by ", a, "\n");
382 else if (deathtype == DEATH_FALL)
383 bprint ("^1",s, "^1 was grounded by ", a, "\n");
384 else if (deathtype == DEATH_SHOOTING_STAR)
385 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
386 else if (deathtype == DEATH_SWAMP)
387 bprint ("^1",s, "^1 was conserved by ", a, "\n");
388 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
390 p = strstrofs(inflictor.message2, "#", 0);
392 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
394 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
396 else if(deathtype == DEATH_TURRET)
397 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
398 else if(deathtype == DEATH_TOUCHEXPLODE)
399 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
400 else if(deathtype == DEATH_CHEAT)
401 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
402 else if (deathtype == DEATH_FIRE)
403 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
405 bprint ("^1",s, "^1 was fragged by ", a, "\n");
408 if(g_ctf && targ.flagcarried)
410 UpdateFrags(attacker, ctf_score_value("score_kill"));
411 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
412 GiveFrags(attacker, targ, 0); // for logging
415 GiveFrags(attacker, targ, 1);
417 if (targ.killcount > 2) {
419 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
421 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
424 attacker.killcount = attacker.killcount + 1;
426 if (attacker.killcount > 2) {
428 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
430 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
433 LogDeath("frag", deathtype, attacker, targ);
435 if (attacker.killcount == 3)
438 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
440 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
441 announce(attacker, "announcer/male/03kills.wav");
444 else if (attacker.killcount == 5)
447 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
449 bprint (a,"^7 unleashes ^1RAGE\n");
450 announce(attacker, "announcer/male/05kills.wav");
453 else if (attacker.killcount == 10)
456 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
458 bprint (a,"^7 starts the ^1MASSACRE!\n");
459 announce(attacker, "announcer/male/10kills.wav");
462 else if (attacker.killcount == 15)
465 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
467 bprint (a,"^7 executes ^1MAYHEM!\n");
468 announce(attacker, "announcer/male/15kills.wav");
471 else if (attacker.killcount == 20)
474 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
476 bprint (a,"^7 is a ^1BERSERKER!\n");
477 announce(attacker, "announcer/male/20kills.wav");
480 else if (attacker.killcount == 25)
483 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
485 bprint (a,"^7 inflicts ^1CARNAGE!\n");
486 announce(attacker, "announcer/male/25kills.wav");
489 else if (attacker.killcount == 30)
492 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
494 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
495 announce(attacker, "announcer/male/30kills.wav");
502 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
503 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
504 bprint ("^1",s, "^1 ", inflictor.message, "\n");
505 else if (deathtype == DEATH_DROWN)
507 bprint ("^1",s, "^1 was in the water for too long\n");
509 bprint ("^1",s, "^1 drowned\n");
510 else if (deathtype == DEATH_SLIME)
511 bprint ("^1",s, "^1 was slimed\n");
512 else if (deathtype == DEATH_LAVA)
514 bprint ("^1",s, "^1 found a hot place\n");
516 bprint ("^1",s, "^1 turned into hot slag\n");
517 else if (deathtype == DEATH_FALL)
519 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
521 bprint ("^1",s, "^1 hit the ground with a crunch\n");
522 else if (deathtype == DEATH_SHOOTING_STAR)
523 bprint ("^1",s, "^1 became a shooting star\n");
524 else if (deathtype == DEATH_SWAMP)
526 bprint ("^1",s, "^1 discovered a swamp\n");
528 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
529 else if(deathtype == DEATH_TURRET)
530 bprint ("^1",s, "^1 was mowed down by a turret \n");
531 else if(deathtype == DEATH_TOUCHEXPLODE)
532 bprint ("^1",s, "^1 died in an accident\n");
533 else if(deathtype == DEATH_CHEAT)
534 bprint ("^1",s, "^1 was unfairly eliminated\n");
535 else if(deathtype == DEATH_FIRE)
537 bprint ("^1",s, "^1 felt a little hot\n");
539 bprint ("^1",s, "^1 burnt to death\n");
542 bprint ("^1",s, "^1 needs a restart\n");
544 bprint ("^1",s, "^1 died\n");
545 GiveFrags(targ, targ, -1);
546 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
547 announce(targ, "announcer/male/botlike.wav");
550 if (targ.killcount > 2)
552 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
554 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
556 LogDeath("accident", deathtype, targ, targ);
558 targ.death_origin = targ.origin;
560 targ.killer_origin = attacker.origin;
561 // FIXME: this should go in PutClientInServer
567 // these are updated by each Damage call for use in button triggering and such
569 entity damage_inflictor;
570 entity damage_attacker;
572 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
577 entity attacker_save;
581 if (gameover || targ.killcount == -666)
584 local entity oldself;
588 damage_inflictor = inflictor;
589 damage_attacker = attacker;
590 attacker_save = attacker;
592 if(targ.classname == "player")
595 if(targ.hook.aiment == attacker)
596 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
598 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
599 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
601 if(targ.classname == "player")
602 if not(IsDifferentTeam(targ, attacker))
609 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
611 // These are ALWAYS lethal
612 // No damage modification here
613 // Instead, prepare the victim for his death...
615 targ.spawnshieldtime = 0;
616 targ.health = 0.9; // this is < 1
617 targ.flags -= targ.flags & FL_GODMODE;
620 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
626 if (targ.classname == "player")
627 if (attacker.classname == "player")
630 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
632 // nullify damage if teamplay is on
633 if(deathtype != DEATH_TELEFRAG)
634 if(attacker.classname == "player")
636 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
641 else if(attacker.team == targ.team)
645 else if(attacker != targ)
649 else if(teamplay == 4)
651 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
653 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
654 attacker.dmg_team = attacker.dmg_team + damage;
655 if(attacker.dmg_team > teamdamage0)
656 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
657 mirrorforce = cvar("g_mirrordamage") * vlen(force);
660 if(cvar("g_friendlyfire") == 0)
664 damage = cvar("g_friendlyfire") * damage;
665 // mirrordamage will be used LATER
674 if(targ.classname == "player")
675 if(attacker.classname == "player")
678 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
679 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
682 if(targ.classname == "player")
685 if ((deathtype == DEATH_FALL) ||
686 (deathtype == DEATH_DROWN) ||
687 (deathtype == DEATH_SLIME) ||
688 (deathtype == DEATH_LAVA))
693 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
695 targ.armorvalue -= 1;
696 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
699 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
701 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
704 if (targ != attacker)
706 if (targ.classname == "player")
707 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
717 if not(DEATH_ISSPECIAL(deathtype))
719 damage *= g_weapondamagefactor;
720 mirrordamage *= g_weapondamagefactor;
721 force = force * g_weaponforcefactor;
722 mirrorforce *= g_weaponforcefactor;
725 // apply strength multiplier
726 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
730 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
731 force = force * cvar("g_balance_powerup_strength_selfforce");
735 damage = damage * cvar("g_balance_powerup_strength_damage");
736 force = force * cvar("g_balance_powerup_strength_force");
740 // apply invincibility multiplier
741 if (targ.items & IT_INVINCIBLE && !g_minstagib)
742 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
744 if (targ == attacker)
745 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
747 // CTF: reduce damage/force
752 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
753 force = force * cvar("g_ctf_flagcarrier_selfforce");
758 // apply strength rune
759 if (attacker.runes & RUNE_STRENGTH)
761 if(attacker.runes & CURSE_WEAK) // have both curse & rune
763 damage = damage * cvar("g_balance_rune_strength_combo_damage");
764 force = force * cvar("g_balance_rune_strength_combo_force");
768 damage = damage * cvar("g_balance_rune_strength_damage");
769 force = force * cvar("g_balance_rune_strength_force");
772 else if (attacker.runes & CURSE_WEAK)
774 damage = damage * cvar("g_balance_curse_weak_damage");
775 force = force * cvar("g_balance_curse_weak_force");
778 // apply defense rune
779 if (targ.runes & RUNE_DEFENSE)
781 if (targ.runes & CURSE_VULNER) // have both curse & rune
782 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
784 damage = damage * cvar("g_balance_rune_defense_takedamage");
786 else if (targ.runes & CURSE_VULNER)
787 damage = damage * cvar("g_balance_curse_vulner_takedamage");
793 if(targ.takedamage == DAMAGE_AIM)
795 if(targ.classname == "player")
797 if(IsDifferentTeam(targ, attacker))
802 attacker.typehitsound += 1;
804 attacker.hitsound += 1;
806 damage_goodhits += 1;
807 damage_gooddamage += damage;
809 if not(DEATH_ISSPECIAL(deathtype))
816 if(targ.items & IT_STRENGTH)
820 // find height of hit on player axis
821 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
822 vector headmins, headmaxs, org;
823 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
824 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);
825 headmaxs = org + '0.7 0 0' * targ.maxs_x + '0 0.7 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
826 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
828 damage *= 1 + damage_headshotbonus;
830 deathtype |= HITTYPE_HEADSHOT;
837 if(deathtype != DEATH_FIRE)
838 attacker.typehitsound += 1;
840 if(time > attacker.teamkill_complain)
842 attacker.teamkill_complain = time + 5;
843 attacker.teamkill_soundtime = time + 0.4;
844 attacker.teamkill_soundsource = targ;
851 if (self.damageforcescale)
854 self.velocity = self.velocity + self.damageforcescale * force;
855 self.flags &~= FL_ONGROUND;
856 UpdateCSQCProjectile(self);
859 if (damage != 0 || (self.damageforcescale && vlen(force)))
860 if (self.event_damage)
861 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
864 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
866 // Savage: vampire mode
869 if (time > self.spawnshieldtime)
871 attacker.health += damage;
875 if (attacker.runes & RUNE_VAMPIRE)
877 // apply vampire rune
878 if (attacker.runes & CURSE_EMPATHY) // have the curse too
880 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
881 attacker.health = bound(
882 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
883 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
884 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
888 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
889 attacker.health = bound(
890 attacker.health, // LA: was 3, but changed so that you can't lose health
891 // empathy won't let you gain health in the same way...
892 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
893 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
896 // apply empathy curse
897 else if (attacker.runes & CURSE_EMPATHY)
899 attacker.health = bound(
900 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
901 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
907 // apply mirror damage if any
908 if(mirrordamage > 0 || mirrorforce > 0)
910 attacker = attacker_save;
914 // just lose extra LIVES, don't kill the player for mirror damage
915 if(attacker.armorvalue > 0)
917 attacker.armorvalue = attacker.armorvalue - 1;
918 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
919 attacker.hitsound += 1;
923 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
924 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
928 vector NearestPointOnBox(entity box, vector org)
930 vector m1, m2, nearest;
932 m1 = box.mins + box.origin;
933 m2 = box.maxs + box.origin;
935 nearest_x = bound(m1_x, org_x, m2_x);
936 nearest_y = bound(m1_y, org_y, m2_y);
937 nearest_z = bound(m1_z, org_z, m2_z);
942 .float actual_damage[WEP_COUNT]; //amount of damage done
943 .float max_damage[WEP_COUNT]; //the maximum damage of the weapon
945 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(actual_damage);
946 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(max_damage);
949 float RadiusDamage_running;
950 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
951 // Returns total damage applies to creatures
961 float total_damage_to_creatures;
965 float stat_damagedone;
966 float stat_maxdamage;
968 if(RadiusDamage_running)
971 print("RadiusDamage called recursively!\n");
972 print("Expect stuff to go HORRIBLY wrong.\n");
973 print("Causing a stack trace...\n");
974 save = cvar_string("prvm_backtraceforwarnings");
975 cvar_set("prvm_backtraceforwarnings", "1");
976 fclose(-1); // calls VM_Warning
977 cvar_set("prvm_backtraceforwarnings", save);
982 RadiusDamage_running = 1;
984 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
985 total_damage_to_creatures = 0;
987 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
989 force = inflictor.velocity;
993 force = normalize(force);
994 if(forceintensity >= 0)
995 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
997 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1000 stat_damagedone = 0;
1003 targ = findradius (blastorigin, rad);
1007 if (targ != inflictor)
1010 // LordHavoc: measure distance to nearest point on target (not origin)
1011 // (this guarentees 100% damage on a touch impact)
1012 nearest = NearestPointOnBox(targ, blastorigin);
1013 diff = nearest - blastorigin;
1014 // round up a little on the damage to ensure full damage on impacts
1015 // and turn the distance into a fraction of the radius
1016 power = 1 - ((vlen (diff) - 2) / rad);
1018 //bprint(ftos(power));
1023 finaldmg = coredamage * power + edgedamage * (1 - power);
1026 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1027 // if it's a player, use the view origin as reference
1028 if (targ.classname == "player")
1029 center = targ.origin + targ.view_ofs;
1030 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
1031 // test line of sight to multiple positions on box,
1032 // and do damage if any of them hit
1034 c = ceil(finaldmg / 10);
1040 traceline(blastorigin, nearest, TRUE, inflictor);
1041 if (trace_fraction == 1 || trace_ent == targ
1042 || cvar("g_throughfloor"))
1046 total_damage_to_creatures += finaldmg;
1048 if(targ.flags & FL_CLIENT)
1049 if(targ.deadflag == DEAD_NO)
1050 if(targ != attacker)
1051 if(!teamplay || targ.team != attacker.team)
1053 stat_damagedone += finaldmg;
1054 stat_maxdamage += coredamage;
1058 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1059 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1061 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1064 nearest_x = targ.mins_x + random() * targ.size_x;
1065 nearest_y = targ.mins_y + random() * targ.size_y;
1066 nearest_z = targ.mins_z + random() * targ.size_z;
1074 RadiusDamage_running = 0;
1076 weaponid = DEATH_WEAPONOF(deathtype);
1078 // Calculates stats for all RadiusDamage weapons
1079 if not(inWarmupStage)
1081 if(clienttype(attacker) == CLIENTTYPE_REAL)
1083 // Track damage done and update the stat to be sent later in g_world.qc
1084 float f = min(stat_maxdamage, stat_damagedone);
1085 attacker.actual_damage[weaponid] += f; // value temporarily stored in f due to a ftqecc bug
1086 attacker.damage_hits = weaponid + 64 * rint(attacker.actual_damage[weaponid]);
1089 return total_damage_to_creatures;
1092 .float fire_damagepersec;
1093 .float fire_endtime;
1094 .float fire_deathtype;
1096 .float fire_hitsound;
1098 float Fire_IsBurning(entity e)
1100 return (time < e.fire_endtime);
1103 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1108 if(Fire_IsBurning(e))
1110 float totaldamage, totaltime, maxdps, olddamage, oldtime;
1111 oldtime = e.fire_endtime - time;
1112 olddamage = e.fire_damagepersec * oldtime;
1113 if(t > oldtime + 0.1 || d > olddamage + 1 || dps > e.fire_damagepersec + 1) // some thresholds to prevent toggling due to roundoff errors
1115 maxdps = max(dps, e.fire_damagepersec);
1116 totaltime = max(oldtime, t);
1117 totaldamage = min(maxdps * totaltime, olddamage + d);
1118 e.fire_damagepersec = totaldamage / totaltime;
1119 e.fire_endtime = time + totaltime;
1120 e.fire_deathtype = dt;
1122 e.fire_hitsound = FALSE;
1123 return totaldamage - olddamage; // can never be negative
1130 e.fire_damagepersec = dps;
1131 e.fire_endtime = time + t;
1132 e.fire_deathtype = dt;
1134 e.fire_hitsound = FALSE;
1139 void Fire_ApplyDamage(entity e)
1143 if not(Fire_IsBurning(e))
1146 // water and slime stop fire
1148 if(e.watertype != CONTENT_LAVA)
1151 t = min(frametime, e.fire_endtime - time);
1152 d = e.fire_damagepersec * t;
1154 hi = e.fire_owner.hitsound;
1155 ty = e.fire_owner.typehitsound;
1156 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1157 if(e.fire_hitsound && e.fire_owner)
1159 e.fire_owner.hitsound = hi;
1160 e.fire_owner.typehitsound = ty;
1162 e.fire_hitsound = TRUE;
1164 if not(IS_INDEPENDENT_PLAYER(e))
1165 FOR_EACH_PLAYER(other) if(e != other)
1167 if(other.classname == "player")
1168 if(other.deadflag == DEAD_NO)
1169 if not(IS_INDEPENDENT_PLAYER(other))
1170 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1172 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1173 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1174 Fire_AddDamage(other, e, d, t, DEATH_FIRE);
1179 void Fire_ApplyEffect(entity e)
1181 if(Fire_IsBurning(e))
1182 e.effects |= EF_FLAME;
1184 e.effects &~= EF_FLAME;