1 float checkrules_firstblood;
5 float damage_gooddamage;
7 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
10 .float teamkill_complain;
11 .float teamkill_soundtime;
12 .entity teamkill_soundsource;
14 .float taunt_soundtime;
17 float IsDifferentTeam(entity a, entity b)
32 float IsFlying(entity a)
34 if(a.flags & FL_ONGROUND)
38 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
39 if(trace_fraction < 1)
44 void UpdateFrags(entity player, float f)
46 PlayerTeamScore_AddScore(player, f);
49 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
50 void GiveFrags (entity attacker, entity targ, float f)
52 // TODO route through PlayerScores instead
60 PlayerScore_Add(attacker, SP_SUICIDES, 1);
65 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
71 PlayerScore_Add(attacker, SP_KILLS, 1);
74 PlayerScore_Add(targ, SP_DEATHS, 1);
77 if(cvar("g_arena_roundbased"))
80 // FIXME fix the mess this is (we have REAL points now!)
83 f = RunematchHandleFrags(attacker, targ, f);
87 f = kh_HandleFrags(attacker, targ, f);
93 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
94 if(tl < lms_lowest_lives)
95 lms_lowest_lives = tl;
99 lms_next_place = player_count;
100 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
107 if(g_ctf_ignore_frags)
111 attacker.totalfrags += f;
114 UpdateFrags(attacker, f);
117 string AppendItemcodes(string s, entity player)
122 // w = player.switchweapon;
124 w = player.cnt; // previous weapon!
125 s = strcat(s, ftos(w));
126 if(time < player.strength_finished)
128 if(time < player.invincible_finished)
130 if(player.flagcarried != world)
132 if(player.BUTTON_CHAT)
137 s = strcat(s, "|", ftos(player.runes));
141 void LogDeath(string mode, float deathtype, entity killer, entity killed)
144 if(!cvar("sv_eventlog"))
146 s = strcat(":kill:", mode);
147 s = strcat(s, ":", ftos(killer.playerid));
148 s = strcat(s, ":", ftos(killed.playerid));
149 s = strcat(s, ":type=", ftos(deathtype));
150 s = strcat(s, ":items=");
151 s = AppendItemcodes(s, killer);
154 s = strcat(s, ":victimitems=");
155 s = AppendItemcodes(s, killed);
160 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
165 if (targ.classname == "player" || targ.classname == "corpse")
167 if (targ.classname == "corpse")
171 a = attacker.netname;
173 if (targ == attacker)
175 if (deathtype == DEATH_TEAMCHANGE) {
176 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
177 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
178 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
180 } else if (deathtype == DEATH_CAMP) {
182 centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
184 centerprint(targ, "^1Die camper!\n\n\n");
185 } else if (deathtype == DEATH_NOAMMO) {
187 centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
189 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
190 } else if (deathtype == DEATH_ROT) {
192 centerprint(targ, "^1You need to preserve your health\n\n\n");
194 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
195 } else if (deathtype == DEATH_MIRRORDAMAGE) {
197 centerprint(targ, "^1Don't go against team mates!\n\n\n");
199 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
202 centerprint(targ, "^1You need to be more careful!\n\n\n");
204 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
208 if (deathtype == DEATH_CAMP)
209 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
210 else if (deathtype == DEATH_MIRRORDAMAGE)
211 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
213 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
215 if(deathtype != DEATH_TEAMCHANGE)
217 LogDeath("suicide", deathtype, targ, targ);
218 GiveFrags(attacker, targ, -1);
220 if (targ.killcount > 2)
221 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
223 w = DEATH_WEAPONOF(deathtype);
226 w_deathtypestring = "couldn't resist the urge to self-destruct";
227 w_deathtype = deathtype;
228 weapon_action(w, WR_SUICIDEMESSAGE);
229 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
231 else if (deathtype == DEATH_KILL)
232 bprint ("^1",s, "^1 couldn't take it anymore\n");
233 else if (deathtype == DEATH_ROT)
234 bprint ("^1",s, "^1 died\n");
235 else if (deathtype == DEATH_NOAMMO)
237 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
239 else if (deathtype == DEATH_CAMP)
240 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
241 else if (deathtype == DEATH_MIRRORDAMAGE)
242 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
243 else if (deathtype != DEATH_TEAMCHANGE)
244 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
246 if(deathtype != DEATH_TEAMCHANGE)
248 LogDeath("suicide", deathtype, targ, targ);
249 GiveFrags(attacker, targ, -1);
251 if (targ.killcount > 2)
252 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
255 else if (attacker.classname == "player" || attacker.classname == "gib")
257 if(teamplay && attacker.team == targ.team)
260 centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
261 bprint ("^1", a, "^1 took action against a teammate\n");
263 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
264 bprint ("^1", a, "^1 mows down a teammate\n");
266 GiveFrags(attacker, targ, -1);
267 if (targ.killcount > 2) {
269 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
271 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
273 if (attacker.killcount > 2) {
275 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
277 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
279 attacker.killcount = 0;
281 LogDeath("tk", deathtype, attacker, targ);
285 if (!checkrules_firstblood)
287 checkrules_firstblood = TRUE;
289 bprint("^1",a, "^1 was the first to score", "\n");
291 bprint("^1",a, "^1 drew first blood", "\n");
295 centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
296 centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
298 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
299 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
300 attacker.taunt_soundtime = time + 1;
304 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
306 w = DEATH_WEAPONOF(deathtype);
309 w_deathtypestring = "was blasted by";
310 w_deathtype = deathtype;
311 weapon_action(w, WR_KILLMESSAGE);
312 p = strstrofs(w_deathtypestring, "#", 0);
314 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
316 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
318 else if (deathtype == DEATH_TELEFRAG)
319 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
320 else if (deathtype == DEATH_DROWN)
321 bprint ("^1",s, "^1 was drowned by ", a, "\n");
322 else if (deathtype == DEATH_SLIME)
323 bprint ("^1",s, "^1 was slimed by ", a, "\n");
324 else if (deathtype == DEATH_LAVA)
325 bprint ("^1",s, "^1 was cooked by ", a, "\n");
326 else if (deathtype == DEATH_FALL)
327 bprint ("^1",s, "^1 was grounded by ", a, "\n");
328 else if (deathtype == DEATH_SHOOTING_STAR)
329 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
330 else if (deathtype == DEATH_SWAMP)
331 bprint ("^1",s, "^1 was conserved by ", a, "\n");
332 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
334 p = strstrofs(inflictor.message2, "#", 0);
336 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
338 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
340 else if(deathtype == DEATH_TURRET)
341 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
342 else if(deathtype == DEATH_TOUCHEXPLODE)
343 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
345 bprint ("^1",s, "^1 was fragged by ", a, "\n");
347 if(g_ctf && targ.flagcarried)
349 UpdateFrags(attacker, ctf_score_value("score_kill"));
350 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
351 GiveFrags(attacker, targ, 0); // for logging
354 GiveFrags(attacker, targ, 1);
355 if (targ.killcount > 2) {
357 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
359 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
361 attacker.killcount = attacker.killcount + 1;
362 if (attacker.killcount > 2) {
364 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
366 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
369 LogDeath("frag", deathtype, attacker, targ);
371 if (attacker.killcount == 3)
374 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
376 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
377 announce(attacker, "announcer/male/03kills.wav");
380 else if (attacker.killcount == 5)
383 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
385 bprint (a,"^7 unleashes ^1RAGE\n");
386 announce(attacker, "announcer/male/05kills.wav");
389 else if (attacker.killcount == 10)
392 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
394 bprint (a,"^7 starts the ^1MASSACRE!\n");
395 announce(attacker, "announcer/male/10kills.wav");
398 else if (attacker.killcount == 15)
401 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
403 bprint (a,"^7 executes ^1MAYHEM!\n");
404 announce(attacker, "announcer/male/15kills.wav");
407 else if (attacker.killcount == 20)
410 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
412 bprint (a,"^7 is a ^1BERSERKER!\n");
413 announce(attacker, "announcer/male/20kills.wav");
416 else if (attacker.killcount == 25)
419 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
421 bprint (a,"^7 inflicts ^1CARNAGE!\n");
422 announce(attacker, "announcer/male/25kills.wav");
425 else if (attacker.killcount == 30)
428 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
430 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
431 announce(attacker, "announcer/male/30kills.wav");
438 centerprint(targ, "^1Watch your step!\n\n\n");
439 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
440 bprint ("^1",s, "^1 ", inflictor.message, "\n");
441 else if (deathtype == DEATH_DROWN)
443 bprint ("^1",s, "^1 was in the water for too long\n");
445 bprint ("^1",s, "^1 drowned\n");
446 else if (deathtype == DEATH_SLIME)
447 bprint ("^1",s, "^1 was slimed\n");
448 else if (deathtype == DEATH_LAVA)
450 bprint ("^1",s, "^1 found a hot place\n");
452 bprint ("^1",s, "^1 turned into hot slag\n");
453 else if (deathtype == DEATH_FALL)
455 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
457 bprint ("^1",s, "^1 hit the ground with a crunch\n");
458 else if (deathtype == DEATH_SHOOTING_STAR)
459 bprint ("^1",s, "^1 became a shooting star\n");
460 else if (deathtype == DEATH_SWAMP)
462 bprint ("^1",s, "^1 discovered a swamp\n");
464 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
465 else if(deathtype == DEATH_TURRET)
466 bprint ("^1",s, "^1 was mowed down by a turret \n");
467 else if(deathtype == DEATH_TOUCHEXPLODE)
468 bprint ("^1",s, "^1 died in an accident\n");
471 bprint ("^1",s, "^1 needs a restart\n");
473 bprint ("^1",s, "^1 died\n");
474 GiveFrags(targ, targ, -1);
475 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
476 announce(targ, "announcer/male/botlike.wav");
479 if (targ.killcount > 2)
481 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
483 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
485 LogDeath("accident", deathtype, targ, targ);
487 targ.death_origin = targ.origin;
489 targ.killer_origin = attacker.origin;
490 // FIXME: this should go in PutClientInServer
496 // these are updated by each Damage call for use in button triggering and such
498 entity damage_inflictor;
499 entity damage_attacker;
501 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
506 entity attacker_save;
510 if (gameover || targ.killcount == -666)
513 local entity oldself;
517 damage_inflictor = inflictor;
518 damage_attacker = attacker;
519 attacker_save = attacker;
521 if(targ.classname == "player")
524 if(targ.hook.aiment == attacker)
525 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
527 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
528 if(DEATH_ISWEAPON(deathtype, WEP_HOOK))
530 if(targ.classname == "player")
531 if not(IsDifferentTeam(targ, attacker))
538 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
540 // These are ALWAYS lethal
541 // No damage modification here
542 // Instead, prepare the victim for his death...
544 targ.spawnshieldtime = 0;
545 targ.health = 0.9; // this is < 1
546 targ.flags -= targ.flags & FL_GODMODE;
549 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
555 if (targ.classname == "player")
556 if (attacker.classname == "player")
559 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
561 // nullify damage if teamplay is on
562 if(deathtype != DEATH_TELEFRAG)
563 if(attacker.classname == "player")
565 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
570 else if(attacker.team == targ.team)
574 else if(attacker != targ)
578 else if(teamplay == 4)
580 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
582 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
583 attacker.dmg_team = attacker.dmg_team + damage;
584 if(attacker.dmg_team > teamdamage0)
585 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
586 mirrorforce = cvar("g_mirrordamage") * vlen(force);
589 if(cvar("g_friendlyfire") == 0)
593 damage = cvar("g_friendlyfire") * damage;
594 // mirrordamage will be used LATER
603 if(targ.classname == "player")
604 if(attacker.classname == "player")
607 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
608 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
613 if ((deathtype == DEATH_FALL) ||
614 (deathtype == DEATH_DROWN) ||
615 (deathtype == DEATH_SLIME) ||
616 (deathtype == DEATH_LAVA))
621 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
623 targ.armorvalue -= 1;
624 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
628 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
631 if (targ != attacker)
633 if (targ.classname == "player")
634 centerprint(attacker, "Secondary fire inflicts no damage!\n");
644 // apply strength multiplier
645 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
649 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
650 force = force * cvar("g_balance_powerup_strength_selfforce");
654 damage = damage * cvar("g_balance_powerup_strength_damage");
655 force = force * cvar("g_balance_powerup_strength_force");
659 // apply invincibility multiplier
660 if (targ.items & IT_INVINCIBLE && !g_minstagib)
661 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
663 if (targ == attacker)
664 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
666 // CTF: reduce damage/force
671 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
672 force = force * cvar("g_ctf_flagcarrier_selfforce");
677 // apply strength rune
678 if (attacker.runes & RUNE_STRENGTH)
680 if(attacker.runes & CURSE_WEAK) // have both curse & rune
682 damage = damage * cvar("g_balance_rune_strength_combo_damage");
683 force = force * cvar("g_balance_rune_strength_combo_force");
687 damage = damage * cvar("g_balance_rune_strength_damage");
688 force = force * cvar("g_balance_rune_strength_force");
691 else if (attacker.runes & CURSE_WEAK)
693 damage = damage * cvar("g_balance_curse_weak_damage");
694 force = force * cvar("g_balance_curse_weak_force");
697 // apply defense rune
698 if (targ.runes & RUNE_DEFENSE)
700 if (targ.runes & CURSE_VULNER) // have both curse & rune
701 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
703 damage = damage * cvar("g_balance_rune_defense_takedamage");
705 else if (targ.runes & CURSE_VULNER)
706 damage = damage * cvar("g_balance_curse_vulner_takedamage");
712 if(targ.takedamage == DAMAGE_AIM)
714 if(targ.classname == "player")
716 if(IsDifferentTeam(targ, attacker))
721 attacker.typehitsound += 1;
723 attacker.hitsound += 1;
725 damage_goodhits += 1;
726 damage_gooddamage += damage;
728 if not(DEATH_ISSPECIAL(deathtype))
735 if(targ.items & IT_STRENGTH)
739 // find height of hit on player axis
740 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
741 vector headmins, headmaxs, org;
742 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
743 headmins = org + '0.7 0 0' * targ.mins_x + '0 0.7 0' * targ.mins_y + '0 0 1' * targ.view_ofs_z;
744 headmaxs = org + '0.7 0 0' * targ.maxs_x + '0 0.7 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
745 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
747 damage *= 1 + damage_headshotbonus;
749 deathtype |= HITTYPE_HEADSHOT;
756 attacker.typehitsound += 1;
758 if(time > attacker.teamkill_complain)
760 attacker.teamkill_complain = time + 5;
761 attacker.teamkill_soundtime = time + 0.4;
762 attacker.teamkill_soundsource = targ;
769 if (self.damageforcescale)
772 self.velocity = self.velocity + self.damageforcescale * force;
773 self.flags = self.flags - (self.flags & FL_ONGROUND);
777 if (self.event_damage)
778 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
781 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
783 // Savage: vampire mode
786 if (time > self.spawnshieldtime)
788 attacker.health += damage;
792 if (attacker.runes & RUNE_VAMPIRE)
794 // apply vampire rune
795 if (attacker.runes & CURSE_EMPATHY) // have the curse too
797 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
798 attacker.health = bound(
799 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
800 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
801 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
805 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
806 attacker.health = bound(
807 attacker.health, // LA: was 3, but changed so that you can't lose health
808 // empathy won't let you gain health in the same way...
809 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
810 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
813 // apply empathy curse
814 else if (attacker.runes & CURSE_EMPATHY)
816 attacker.health = bound(
817 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
818 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
824 // apply mirror damage if any
825 if(mirrordamage > 0 || mirrorforce > 0)
827 attacker = attacker_save;
831 // just lose extra LIVES, don't kill the player for mirror damage
832 if(attacker.armorvalue > 0)
834 attacker.armorvalue = attacker.armorvalue - 1;
835 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
836 attacker.hitsound += 1;
840 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
841 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
845 vector NearestPointOnBox(entity box, vector org)
847 vector m1, m2, nearest;
849 m1 = box.mins + box.origin;
850 m2 = box.maxs + box.origin;
852 nearest_x = bound(m1_x, org_x, m2_x);
853 nearest_y = bound(m1_y, org_y, m2_y);
854 nearest_z = bound(m1_z, org_z, m2_z);
859 float RadiusDamage_running;
860 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
861 // Returns total damage applies to creatures
871 float total_damage_to_creatures;
874 if(RadiusDamage_running)
877 print("RadiusDamage called recursively!\n");
878 print("Expect stuff to go HORRIBLY wrong.\n");
879 print("Causing a stack trace...\n");
880 save = cvar_string("prvm_backtraceforwarnings");
881 cvar_set("prvm_backtraceforwarnings", "1");
882 fclose(-1); // calls VM_Warning
883 cvar_set("prvm_backtraceforwarnings", save);
887 RadiusDamage_running = 1;
889 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
890 total_damage_to_creatures = 0;
892 targ = findradius (blastorigin, rad);
896 if (targ != inflictor)
899 // LordHavoc: measure distance to nearest point on target (not origin)
900 // (this guarentees 100% damage on a touch impact)
901 nearest = NearestPointOnBox(targ, blastorigin);
902 diff = nearest - blastorigin;
903 // round up a little on the damage to ensure full damage on impacts
904 // and turn the distance into a fraction of the radius
905 power = 1 - ((vlen (diff) - 2) / rad);
907 //bprint(ftos(power));
912 finaldmg = coredamage * power + edgedamage * (1 - power);
915 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
916 // if it's a player, use the view origin as reference
917 if (targ.classname == "player")
918 center = targ.origin + targ.view_ofs;
919 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
920 // test line of sight to multiple positions on box,
921 // and do damage if any of them hit
923 c = ceil(finaldmg / 10);
929 traceline(blastorigin, nearest, TRUE, inflictor);
930 if (trace_fraction == 1 || trace_ent == targ
931 || cvar("g_throughfloor"))
934 total_damage_to_creatures += finaldmg;
935 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
936 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
938 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
941 nearest_x = targ.mins_x + random() * targ.size_x;
942 nearest_y = targ.mins_y + random() * targ.size_y;
943 nearest_z = targ.mins_z + random() * targ.size_z;
951 RadiusDamage_running = 0;
953 return total_damage_to_creatures;