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;
16 float IsDifferentTeam(entity a, entity b)
31 float IsFlying(entity a)
33 if(a.flags & FL_ONGROUND)
37 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
38 if(trace_fraction < 1)
43 void UpdateFrags(entity player, float f)
45 PlayerTeamScore_AddScore(player, f);
48 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
49 void GiveFrags (entity attacker, entity targ, float f)
51 // TODO route through PlayerScores instead
59 PlayerScore_Add(attacker, SP_SUICIDES, 1);
64 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
70 PlayerScore_Add(attacker, SP_KILLS, 1);
73 PlayerScore_Add(targ, SP_DEATHS, 1);
76 if(cvar("g_arena_roundbased"))
79 // FIXME fix the mess this is (we have REAL points now!)
82 f = RunematchHandleFrags(attacker, targ, f);
86 f = kh_HandleFrags(attacker, targ, f);
92 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
93 if(tl < lms_lowest_lives)
94 lms_lowest_lives = tl;
98 lms_next_place = player_count;
99 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
106 if(g_ctf_ignore_frags)
110 attacker.totalfrags += f;
113 UpdateFrags(attacker, f);
116 string AppendItemcodes(string s, entity player)
121 // w = player.switchweapon;
123 w = player.cnt; // previous weapon!
124 s = strcat(s, ftos(w));
125 if(time < player.strength_finished)
127 if(time < player.invincible_finished)
129 if(player.flagcarried != world)
131 if(player.BUTTON_CHAT)
136 s = strcat(s, "|", ftos(player.runes));
140 void LogDeath(string mode, float deathtype, entity killer, entity killed)
143 if(!cvar("sv_eventlog"))
145 s = strcat(":kill:", mode);
146 s = strcat(s, ":", ftos(killer.playerid));
147 s = strcat(s, ":", ftos(killed.playerid));
148 s = strcat(s, ":type=", ftos(deathtype));
149 s = strcat(s, ":items=");
150 s = AppendItemcodes(s, killer);
153 s = strcat(s, ":victimitems=");
154 s = AppendItemcodes(s, killed);
159 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
164 if (targ.classname == "player" || targ.classname == "corpse")
166 if (targ.classname == "corpse")
170 a = attacker.netname;
172 if (targ == attacker)
174 if (deathtype == DEATH_TEAMCHANGE) {
175 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
176 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
177 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
179 } else if (deathtype == DEATH_CAMP) {
181 centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
183 centerprint(targ, "^1Die camper!\n\n\n");
184 } else if (deathtype == DEATH_NOAMMO) {
186 centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
188 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
189 } else if (deathtype == DEATH_ROT) {
191 centerprint(targ, "^1You need to preserve your health\n\n\n");
193 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
194 } else if (deathtype == DEATH_MIRRORDAMAGE) {
196 centerprint(targ, "^1Don't go against team mates!\n\n\n");
198 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
201 centerprint(targ, "^1You need to be more careful!\n\n\n");
203 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
207 if (deathtype == DEATH_CAMP)
208 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
209 else if (deathtype == DEATH_MIRRORDAMAGE)
210 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
212 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
214 if(deathtype != DEATH_TEAMCHANGE)
216 LogDeath("suicide", deathtype, targ, targ);
217 GiveFrags(attacker, targ, -1);
219 if (targ.killcount > 2)
220 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
222 w = DEATH_WEAPONOF(deathtype);
225 w_deathtypestring = "couldn't resist the urge to self-destruct";
226 w_deathtype = deathtype;
227 weapon_action(w, WR_SUICIDEMESSAGE);
228 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
230 else if (deathtype == DEATH_KILL)
231 bprint ("^1",s, "^1 couldn't take it anymore\n");
232 else if (deathtype == DEATH_ROT)
233 bprint ("^1",s, "^1 died\n");
234 else if (deathtype == DEATH_NOAMMO)
236 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
238 else if (deathtype == DEATH_CAMP)
239 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
240 else if (deathtype == DEATH_MIRRORDAMAGE)
241 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
242 else if (deathtype != DEATH_TEAMCHANGE)
243 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
245 if(deathtype != DEATH_TEAMCHANGE)
247 LogDeath("suicide", deathtype, targ, targ);
248 GiveFrags(attacker, targ, -1);
250 if (targ.killcount > 2)
251 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
254 else if (attacker.classname == "player" || attacker.classname == "gib")
256 if(teamplay && attacker.team == targ.team)
259 centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
260 bprint ("^1", a, "^1 took action against a teammate\n");
262 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
263 bprint ("^1", a, "^1 mows down a teammate\n");
265 GiveFrags(attacker, targ, -1);
266 if (targ.killcount > 2) {
268 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
270 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
272 if (attacker.killcount > 2) {
274 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
276 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
278 attacker.killcount = 0;
280 LogDeath("tk", deathtype, attacker, targ);
284 if (!checkrules_firstblood)
286 checkrules_firstblood = TRUE;
288 bprint("^1",a, "^1 was the first to score", "\n");
290 bprint("^1",a, "^1 drew first blood", "\n");
294 centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
295 centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
297 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
298 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
299 entity oldself = self; // Hackish way to fix taunts, otherwise they play the other way around
301 PlayerSound(playersound_taunt, CHAN_VOICE, 4);
306 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
308 w = DEATH_WEAPONOF(deathtype);
311 w_deathtypestring = "was blasted by";
312 w_deathtype = deathtype;
313 weapon_action(w, WR_KILLMESSAGE);
314 p = strstrofs(w_deathtypestring, "#", 0);
316 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
318 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
320 else if (deathtype == DEATH_TELEFRAG)
321 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
322 else if (deathtype == DEATH_DROWN)
323 bprint ("^1",s, "^1 was drowned by ", a, "\n");
324 else if (deathtype == DEATH_SLIME)
325 bprint ("^1",s, "^1 was slimed by ", a, "\n");
326 else if (deathtype == DEATH_LAVA)
327 bprint ("^1",s, "^1 was cooked by ", a, "\n");
328 else if (deathtype == DEATH_FALL)
329 bprint ("^1",s, "^1 was grounded by ", a, "\n");
330 else if (deathtype == DEATH_SHOOTING_STAR)
331 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
332 else if (deathtype == DEATH_SWAMP)
333 bprint ("^1",s, "^1 was conserved by ", a, "\n");
334 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
336 p = strstrofs(inflictor.message2, "#", 0);
338 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
340 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
342 else if(deathtype == DEATH_TURRET)
343 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
344 else if(deathtype == DEATH_TOUCHEXPLODE)
345 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
347 bprint ("^1",s, "^1 was fragged by ", a, "\n");
349 if(g_ctf && targ.flagcarried)
351 UpdateFrags(attacker, ctf_score_value("score_kill"));
352 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
353 GiveFrags(attacker, targ, 0); // for logging
356 GiveFrags(attacker, targ, 1);
357 if (targ.killcount > 2) {
359 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
361 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
363 attacker.killcount = attacker.killcount + 1;
364 if (attacker.killcount > 2) {
366 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
368 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
371 LogDeath("frag", deathtype, attacker, targ);
373 if (attacker.killcount == 3)
376 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
378 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
379 announce(attacker, "announcer/male/03kills.wav");
382 else if (attacker.killcount == 5)
385 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
387 bprint (a,"^7 unleashes ^1RAGE\n");
388 announce(attacker, "announcer/male/05kills.wav");
391 else if (attacker.killcount == 10)
394 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
396 bprint (a,"^7 starts the ^1MASSACRE!\n");
397 announce(attacker, "announcer/male/10kills.wav");
400 else if (attacker.killcount == 15)
403 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
405 bprint (a,"^7 executes ^1MAYHEM!\n");
406 announce(attacker, "announcer/male/15kills.wav");
409 else if (attacker.killcount == 20)
412 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
414 bprint (a,"^7 is a ^1BERSERKER!\n");
415 announce(attacker, "announcer/male/20kills.wav");
418 else if (attacker.killcount == 25)
421 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
423 bprint (a,"^7 inflicts ^1CARNAGE!\n");
424 announce(attacker, "announcer/male/25kills.wav");
427 else if (attacker.killcount == 30)
430 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
432 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
433 announce(attacker, "announcer/male/30kills.wav");
440 centerprint(targ, "^1Watch your step!\n\n\n");
441 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
442 bprint ("^1",s, "^1 ", inflictor.message, "\n");
443 else if (deathtype == DEATH_DROWN)
445 bprint ("^1",s, "^1 was in the water for too long\n");
447 bprint ("^1",s, "^1 drowned\n");
448 else if (deathtype == DEATH_SLIME)
449 bprint ("^1",s, "^1 was slimed\n");
450 else if (deathtype == DEATH_LAVA)
452 bprint ("^1",s, "^1 found a hot place\n");
454 bprint ("^1",s, "^1 turned into hot slag\n");
455 else if (deathtype == DEATH_FALL)
457 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
459 bprint ("^1",s, "^1 hit the ground with a crunch\n");
460 else if (deathtype == DEATH_SHOOTING_STAR)
461 bprint ("^1",s, "^1 became a shooting star\n");
462 else if (deathtype == DEATH_SWAMP)
464 bprint ("^1",s, "^1 discovered a swamp\n");
466 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
467 else if(deathtype == DEATH_TURRET)
468 bprint ("^1",s, "^1 was mowed down by a turret \n");
469 else if(deathtype == DEATH_TOUCHEXPLODE)
470 bprint ("^1",s, "^1 died in an accident\n");
473 bprint ("^1",s, "^1 needs a restart\n");
475 bprint ("^1",s, "^1 died\n");
476 GiveFrags(targ, targ, -1);
477 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
478 announce(targ, "announcer/male/botlike.wav");
481 if (targ.killcount > 2)
483 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
485 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
487 LogDeath("accident", deathtype, targ, targ);
489 targ.death_origin = targ.origin;
491 targ.killer_origin = attacker.origin;
492 // FIXME: this should go in PutClientInServer
498 // these are updated by each Damage call for use in button triggering and such
500 entity damage_inflictor;
501 entity damage_attacker;
503 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
508 entity attacker_save;
512 if (gameover || targ.killcount == -666)
515 local entity oldself;
519 damage_inflictor = inflictor;
520 damage_attacker = attacker;
521 attacker_save = attacker;
523 if(targ.classname == "player")
526 if(targ.hook.aiment == attacker)
527 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
529 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
530 if(DEATH_ISWEAPON(deathtype, WEP_HOOK))
532 if(targ.classname == "player")
533 if not(IsDifferentTeam(targ, attacker))
540 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
542 // These are ALWAYS lethal
543 // No damage modification here
544 // Instead, prepare the victim for his death...
546 targ.spawnshieldtime = 0;
547 targ.health = 0.9; // this is < 1
548 targ.flags -= targ.flags & FL_GODMODE;
551 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
557 if (targ.classname == "player")
558 if (attacker.classname == "player")
561 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
563 // nullify damage if teamplay is on
564 if(deathtype != DEATH_TELEFRAG)
565 if(attacker.classname == "player")
567 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
572 else if(attacker.team == targ.team)
576 else if(attacker != targ)
580 else if(teamplay == 4)
582 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
584 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
585 attacker.dmg_team = attacker.dmg_team + damage;
586 if(attacker.dmg_team > teamdamage0)
587 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
588 mirrorforce = cvar("g_mirrordamage") * vlen(force);
591 if(cvar("g_friendlyfire") == 0)
595 damage = cvar("g_friendlyfire") * damage;
596 // mirrordamage will be used LATER
605 if(targ.classname == "player")
606 if(attacker.classname == "player")
609 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
610 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
615 if ((deathtype == DEATH_FALL) ||
616 (deathtype == DEATH_DROWN) ||
617 (deathtype == DEATH_SLIME) ||
618 (deathtype == DEATH_LAVA))
623 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
625 targ.armorvalue -= 1;
626 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
630 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
633 if (targ != attacker)
635 if (targ.classname == "player")
636 centerprint(attacker, "Secondary fire inflicts no damage!\n");
646 // apply strength multiplier
647 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
651 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
652 force = force * cvar("g_balance_powerup_strength_selfforce");
656 damage = damage * cvar("g_balance_powerup_strength_damage");
657 force = force * cvar("g_balance_powerup_strength_force");
661 // apply invincibility multiplier
662 if (targ.items & IT_INVINCIBLE && !g_minstagib)
663 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
665 if (targ == attacker)
666 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
668 // CTF: reduce damage/force
673 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
674 force = force * cvar("g_ctf_flagcarrier_selfforce");
679 // apply strength rune
680 if (attacker.runes & RUNE_STRENGTH)
682 if(attacker.runes & CURSE_WEAK) // have both curse & rune
684 damage = damage * cvar("g_balance_rune_strength_combo_damage");
685 force = force * cvar("g_balance_rune_strength_combo_force");
689 damage = damage * cvar("g_balance_rune_strength_damage");
690 force = force * cvar("g_balance_rune_strength_force");
693 else if (attacker.runes & CURSE_WEAK)
695 damage = damage * cvar("g_balance_curse_weak_damage");
696 force = force * cvar("g_balance_curse_weak_force");
699 // apply defense rune
700 if (targ.runes & RUNE_DEFENSE)
702 if (targ.runes & CURSE_VULNER) // have both curse & rune
703 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
705 damage = damage * cvar("g_balance_rune_defense_takedamage");
707 else if (targ.runes & CURSE_VULNER)
708 damage = damage * cvar("g_balance_curse_vulner_takedamage");
714 if(targ.takedamage == DAMAGE_AIM)
716 if(targ.classname == "player")
718 if(IsDifferentTeam(targ, attacker))
723 attacker.typehitsound += 1;
725 attacker.hitsound += 1;
727 damage_goodhits += 1;
728 damage_gooddamage += damage;
730 if not(DEATH_ISSPECIAL(deathtype))
737 if(targ.items & IT_STRENGTH)
741 // find height of hit on player axis
742 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
743 vector headmins, headmaxs, org;
744 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
745 headmins = org + '0.7 0 0' * targ.mins_x + '0 0.7 0' * targ.mins_y + '0 0 1' * targ.view_ofs_z;
746 headmaxs = org + '0.7 0 0' * targ.maxs_x + '0 0.7 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
747 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
749 damage *= 1 + damage_headshotbonus;
751 deathtype |= HITTYPE_HEADSHOT;
758 attacker.typehitsound += 1;
760 if(time > attacker.teamkill_complain)
762 attacker.teamkill_complain = time + 5;
763 attacker.teamkill_soundtime = time + 0.4;
764 attacker.teamkill_soundsource = targ;
771 if (self.damageforcescale)
774 self.velocity = self.velocity + self.damageforcescale * force;
775 self.flags = self.flags - (self.flags & FL_ONGROUND);
779 if (self.event_damage)
780 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
783 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
785 // Savage: vampire mode
788 if (time > self.spawnshieldtime)
790 attacker.health += damage;
794 if (attacker.runes & RUNE_VAMPIRE)
796 // apply vampire rune
797 if (attacker.runes & CURSE_EMPATHY) // have the curse too
799 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
800 attacker.health = bound(
801 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
802 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
803 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
807 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
808 attacker.health = bound(
809 attacker.health, // LA: was 3, but changed so that you can't lose health
810 // empathy won't let you gain health in the same way...
811 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
812 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
815 // apply empathy curse
816 else if (attacker.runes & CURSE_EMPATHY)
818 attacker.health = bound(
819 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
820 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
826 // apply mirror damage if any
827 if(mirrordamage > 0 || mirrorforce > 0)
829 attacker = attacker_save;
833 // just lose extra LIVES, don't kill the player for mirror damage
834 if(attacker.armorvalue > 0)
836 attacker.armorvalue = attacker.armorvalue - 1;
837 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
838 attacker.hitsound += 1;
842 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
843 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
847 vector NearestPointOnBox(entity box, vector org)
849 vector m1, m2, nearest;
851 m1 = box.mins + box.origin;
852 m2 = box.maxs + box.origin;
854 nearest_x = bound(m1_x, org_x, m2_x);
855 nearest_y = bound(m1_y, org_y, m2_y);
856 nearest_z = bound(m1_z, org_z, m2_z);
861 float RadiusDamage_running;
862 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
863 // Returns total damage applies to creatures
873 float total_damage_to_creatures;
876 if(RadiusDamage_running)
879 print("RadiusDamage called recursively!\n");
880 print("Expect stuff to go HORRIBLY wrong.\n");
881 print("Causing a stack trace...\n");
882 save = cvar_string("prvm_backtraceforwarnings");
883 cvar_set("prvm_backtraceforwarnings", "1");
884 fclose(-1); // calls VM_Warning
885 cvar_set("prvm_backtraceforwarnings", save);
889 RadiusDamage_running = 1;
891 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
892 total_damage_to_creatures = 0;
894 targ = findradius (blastorigin, rad);
898 if (targ != inflictor)
901 // LordHavoc: measure distance to nearest point on target (not origin)
902 // (this guarentees 100% damage on a touch impact)
903 nearest = NearestPointOnBox(targ, blastorigin);
904 diff = nearest - blastorigin;
905 // round up a little on the damage to ensure full damage on impacts
906 // and turn the distance into a fraction of the radius
907 power = 1 - ((vlen (diff) - 2) / rad);
909 //bprint(ftos(power));
914 finaldmg = coredamage * power + edgedamage * (1 - power);
917 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
918 // if it's a player, use the view origin as reference
919 if (targ.classname == "player")
920 center = targ.origin + targ.view_ofs;
921 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
922 // test line of sight to multiple positions on box,
923 // and do damage if any of them hit
925 c = ceil(finaldmg / 10);
931 traceline(blastorigin, nearest, TRUE, inflictor);
932 if (trace_fraction == 1 || trace_ent == targ
933 || cvar("g_throughfloor"))
936 total_damage_to_creatures += finaldmg;
937 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
938 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
940 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
943 nearest_x = targ.mins_x + random() * targ.size_x;
944 nearest_y = targ.mins_y + random() * targ.size_y;
945 nearest_z = targ.mins_z + random() * targ.size_z;
953 RadiusDamage_running = 0;
955 return total_damage_to_creatures;