1 float checkrules_firstblood;
5 float damage_gooddamage;
7 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
9 .float teamkill_complain;
10 .float teamkill_soundtime;
11 .entity teamkill_soundsource;
15 float IsDifferentTeam(entity a, entity b)
30 float IsFlying(entity a)
32 if(a.flags & FL_ONGROUND)
36 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
37 if(trace_fraction < 1)
42 void UpdateFrags(entity player, float f)
44 PlayerTeamScore_AddScore(player, f);
47 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
48 void GiveFrags (entity attacker, entity targ, float f)
50 // TODO route through PlayerScores instead
58 PlayerScore_Add(attacker, SP_SUICIDES, 1);
63 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
69 PlayerScore_Add(attacker, SP_KILLS, 1);
72 PlayerScore_Add(targ, SP_DEATHS, 1);
75 if(cvar("g_arena_roundbased"))
78 // FIXME fix the mess this is (we have REAL points now!)
81 f = RunematchHandleFrags(attacker, targ, f);
85 f = kh_HandleFrags(attacker, targ, f);
91 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
92 if(tl < lms_lowest_lives)
93 lms_lowest_lives = tl;
97 lms_next_place = player_count;
98 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
105 if(g_ctf_ignore_frags)
109 attacker.totalfrags += f;
112 UpdateFrags(attacker, f);
115 string AppendItemcodes(string s, entity player)
120 // w = player.switchweapon;
122 w = player.cnt; // previous weapon!
123 s = strcat(s, ftos(w));
124 if(time < player.strength_finished)
126 if(time < player.invincible_finished)
128 if(player.flagcarried != world)
130 if(player.BUTTON_CHAT)
135 s = strcat(s, "|", ftos(player.runes));
139 void LogDeath(string mode, float deathtype, entity killer, entity killed)
142 if(!cvar("sv_eventlog"))
144 s = strcat(":kill:", mode);
145 s = strcat(s, ":", ftos(killer.playerid));
146 s = strcat(s, ":", ftos(killed.playerid));
147 s = strcat(s, ":type=", ftos(deathtype));
148 s = strcat(s, ":items=");
149 s = AppendItemcodes(s, killer);
152 s = strcat(s, ":victimitems=");
153 s = AppendItemcodes(s, killed);
158 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
163 if (targ.classname == "player" || targ.classname == "corpse")
165 if (targ.classname == "corpse")
169 a = attacker.netname;
171 if (targ == attacker)
173 if (deathtype == DEATH_TEAMCHANGE) {
174 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
175 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
176 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
178 } else if (deathtype == DEATH_CAMP) {
180 centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
182 centerprint(targ, "^1Die camper!\n\n\n");
183 } else if (deathtype == DEATH_NOAMMO) {
185 centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
187 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
188 } else if (deathtype == DEATH_ROT) {
190 centerprint(targ, "^1You need to preserve your health\n\n\n");
192 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
193 } else if (deathtype == DEATH_MIRRORDAMAGE) {
195 centerprint(targ, "^1Don't go against team mates!\n\n\n");
197 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
200 centerprint(targ, "^1You need to be more careful!\n\n\n");
202 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
206 if (deathtype == DEATH_CAMP)
207 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
208 else if (deathtype == DEATH_MIRRORDAMAGE)
209 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
211 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
213 if(deathtype != DEATH_TEAMCHANGE)
215 LogDeath("suicide", deathtype, targ, targ);
216 GiveFrags(attacker, targ, -1);
218 if (targ.killcount > 2)
219 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
221 w = DEATH_WEAPONOF(deathtype);
224 w_deathtypestring = "couldn't resist the urge to self-destruct";
225 w_deathtype = deathtype;
226 weapon_action(w, WR_SUICIDEMESSAGE);
227 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
229 else if (deathtype == DEATH_KILL)
230 bprint ("^1",s, "^1 couldn't take it anymore\n");
231 else if (deathtype == DEATH_ROT)
232 bprint ("^1",s, "^1 died\n");
233 else if (deathtype == DEATH_NOAMMO)
235 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
237 else if (deathtype == DEATH_CAMP)
238 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
239 else if (deathtype == DEATH_MIRRORDAMAGE)
240 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
241 else if (deathtype != DEATH_TEAMCHANGE)
242 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
244 if(deathtype != DEATH_TEAMCHANGE)
246 LogDeath("suicide", deathtype, targ, targ);
247 GiveFrags(attacker, targ, -1);
249 if (targ.killcount > 2)
250 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
253 else if (attacker.classname == "player" || attacker.classname == "gib")
255 if(teamplay && attacker.team == targ.team)
258 centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
259 bprint ("^1", a, "^1 took action against a teammate\n");
261 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
262 bprint ("^1", a, "^1 mows down a teammate\n");
264 GiveFrags(attacker, targ, -1);
265 if (targ.killcount > 2) {
267 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
269 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
271 if (attacker.killcount > 2) {
273 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
275 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
277 attacker.killcount = 0;
279 LogDeath("tk", deathtype, attacker, targ);
283 if (!checkrules_firstblood)
285 checkrules_firstblood = TRUE;
287 bprint("^1",a, "^1 was the first to score", "\n");
289 bprint("^1",a, "^1 drew first blood", "\n");
293 centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
294 centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
296 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
297 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
301 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
303 w = DEATH_WEAPONOF(deathtype);
306 w_deathtypestring = "was blasted by";
307 w_deathtype = deathtype;
308 weapon_action(w, WR_KILLMESSAGE);
309 p = strstrofs(w_deathtypestring, "#", 0);
311 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
313 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
315 else if (deathtype == DEATH_TELEFRAG)
316 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
317 else if (deathtype == DEATH_DROWN)
318 bprint ("^1",s, "^1 was drowned by ", a, "\n");
319 else if (deathtype == DEATH_SLIME)
320 bprint ("^1",s, "^1 was slimed by ", a, "\n");
321 else if (deathtype == DEATH_LAVA)
322 bprint ("^1",s, "^1 was cooked by ", a, "\n");
323 else if (deathtype == DEATH_FALL)
324 bprint ("^1",s, "^1 was grounded by ", a, "\n");
325 else if (deathtype == DEATH_SHOOTING_STAR)
326 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
327 else if (deathtype == DEATH_SWAMP)
328 bprint ("^1",s, "^1 was conserved by ", a, "\n");
329 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
331 p = strstrofs(inflictor.message2, "#", 0);
333 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
335 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
337 else if(deathtype == DEATH_TURRET)
338 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
339 else if(deathtype == DEATH_TOUCHEXPLODE)
340 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
342 bprint ("^1",s, "^1 was fragged by ", a, "\n");
344 if(g_ctf && targ.flagcarried)
346 UpdateFrags(attacker, ctf_score_value("score_kill"));
347 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
348 GiveFrags(attacker, targ, 0); // for logging
351 GiveFrags(attacker, targ, 1);
352 if (targ.killcount > 2) {
354 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
356 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
358 attacker.killcount = attacker.killcount + 1;
359 if (attacker.killcount > 2) {
361 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
363 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
366 LogDeath("frag", deathtype, attacker, targ);
368 if (attacker.killcount == 3)
371 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
373 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
374 announce(attacker, "announcer/male/03kills.wav");
377 else if (attacker.killcount == 5)
380 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
382 bprint (a,"^7 unleashes ^1RAGE\n");
383 announce(attacker, "announcer/male/05kills.wav");
386 else if (attacker.killcount == 10)
389 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
391 bprint (a,"^7 starts the ^1MASSACRE!\n");
392 announce(attacker, "announcer/male/10kills.wav");
395 else if (attacker.killcount == 15)
398 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
400 bprint (a,"^7 executes ^1MAYHEM!\n");
401 announce(attacker, "announcer/male/15kills.wav");
404 else if (attacker.killcount == 20)
407 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
409 bprint (a,"^7 is a ^1BERSERKER!\n");
410 announce(attacker, "announcer/male/20kills.wav");
413 else if (attacker.killcount == 25)
416 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
418 bprint (a,"^7 inflicts ^1CARNAGE!\n");
419 announce(attacker, "announcer/male/25kills.wav");
422 else if (attacker.killcount == 30)
425 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
427 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
428 announce(attacker, "announcer/male/30kills.wav");
435 centerprint(targ, "^1Watch your step!\n\n\n");
436 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
437 bprint ("^1",s, "^1 ", inflictor.message, "\n");
438 else if (deathtype == DEATH_DROWN)
440 bprint ("^1",s, "^1 was in the water for too long\n");
442 bprint ("^1",s, "^1 drowned\n");
443 else if (deathtype == DEATH_SLIME)
444 bprint ("^1",s, "^1 was slimed\n");
445 else if (deathtype == DEATH_LAVA)
447 bprint ("^1",s, "^1 found a hot place\n");
449 bprint ("^1",s, "^1 turned into hot slag\n");
450 else if (deathtype == DEATH_FALL)
452 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
454 bprint ("^1",s, "^1 hit the ground with a crunch\n");
455 else if (deathtype == DEATH_SHOOTING_STAR)
456 bprint ("^1",s, "^1 became a shooting star\n");
457 else if (deathtype == DEATH_SWAMP)
459 bprint ("^1",s, "^1 discovered a swamp\n");
461 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
462 else if(deathtype == DEATH_TURRET)
463 bprint ("^1",s, "^1 was mowed down by a turret \n");
464 else if(deathtype == DEATH_TOUCHEXPLODE)
465 bprint ("^1",s, "^1 died in an accident\n");
468 bprint ("^1",s, "^1 needs a restart\n");
470 bprint ("^1",s, "^1 died\n");
471 GiveFrags(targ, targ, -1);
472 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
473 announce(targ, "announcer/male/botlike.wav");
476 if (targ.killcount > 2)
478 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
480 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
482 LogDeath("accident", deathtype, targ, targ);
484 targ.death_origin = targ.origin;
486 targ.killer_origin = attacker.origin;
487 // FIXME: this should go in PutClientInServer
493 // these are updated by each Damage call for use in button triggering and such
495 entity damage_inflictor;
496 entity damage_attacker;
498 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
502 entity attacker_save;
506 if (gameover || targ.killcount == -666)
509 local entity oldself;
513 damage_inflictor = inflictor;
514 damage_attacker = attacker;
515 attacker_save = attacker;
517 if(targ.classname == "player")
520 if(targ.hook.aiment == attacker)
521 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
523 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
524 if(DEATH_ISWEAPON(deathtype, WEP_HOOK))
526 if(targ.classname == "player")
527 if not(IsDifferentTeam(targ, attacker))
534 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
536 // These are ALWAYS lethal
537 // No damage modification here
538 // Instead, prepare the victim for his death...
540 targ.spawnshieldtime = 0;
541 targ.health = 0.9; // this is < 1
542 targ.flags -= targ.flags & FL_GODMODE;
545 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
551 if (targ.classname == "player")
552 if (attacker.classname == "player")
555 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
557 // nullify damage if teamplay is on
558 if(deathtype != DEATH_TELEFRAG)
559 if(attacker.classname == "player")
561 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
566 else if(attacker.team == targ.team)
570 else if(attacker != targ)
574 else if(teamplay == 4)
576 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
578 mirrordamage = cvar("g_mirrordamage") * damage;
579 mirrorforce = cvar("g_mirrordamage") * vlen(force);
582 if(cvar("g_friendlyfire") == 0)
586 damage = cvar("g_friendlyfire") * damage;
587 // mirrordamage will be used LATER
596 if(targ.classname == "player")
597 if(attacker.classname == "player")
600 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
601 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
606 if ((deathtype == DEATH_FALL) ||
607 (deathtype == DEATH_DROWN) ||
608 (deathtype == DEATH_SLIME) ||
609 (deathtype == DEATH_LAVA))
614 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
616 targ.armorvalue -= 1;
617 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
621 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
624 if (targ != attacker)
626 if (targ.classname == "player")
627 centerprint(attacker, "Secondary fire inflicts no damage!\n");
637 // apply strength multiplier
638 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
642 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
643 force = force * cvar("g_balance_powerup_strength_selfforce");
647 damage = damage * cvar("g_balance_powerup_strength_damage");
648 force = force * cvar("g_balance_powerup_strength_force");
652 // apply invincibility multiplier
653 if (targ.items & IT_INVINCIBLE && !g_minstagib)
654 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
656 if (targ == attacker)
657 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
659 // CTF: reduce damage/force
664 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
665 force = force * cvar("g_ctf_flagcarrier_selfforce");
670 // apply strength rune
671 if (attacker.runes & RUNE_STRENGTH)
673 if(attacker.runes & CURSE_WEAK) // have both curse & rune
675 damage = damage * cvar("g_balance_rune_strength_combo_damage");
676 force = force * cvar("g_balance_rune_strength_combo_force");
680 damage = damage * cvar("g_balance_rune_strength_damage");
681 force = force * cvar("g_balance_rune_strength_force");
684 else if (attacker.runes & CURSE_WEAK)
686 damage = damage * cvar("g_balance_curse_weak_damage");
687 force = force * cvar("g_balance_curse_weak_force");
690 // apply defense rune
691 if (targ.runes & RUNE_DEFENSE)
693 if (targ.runes & CURSE_VULNER) // have both curse & rune
694 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
696 damage = damage * cvar("g_balance_rune_defense_takedamage");
698 else if (targ.runes & CURSE_VULNER)
699 damage = damage * cvar("g_balance_curse_vulner_takedamage");
705 if(targ.takedamage == DAMAGE_AIM)
707 if(targ.classname == "player")
709 if(IsDifferentTeam(targ, attacker))
714 attacker.typehitsound += 1;
716 attacker.hitsound += 1;
718 damage_goodhits += 1;
719 damage_gooddamage += damage;
721 if not(DEATH_ISSPECIAL(deathtype))
728 if(targ.items & IT_STRENGTH)
732 // find height of hit on player axis
733 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
734 vector headmins, headmaxs, org;
735 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
736 headmins = org + '0.5 0 0' * targ.mins_x + '0 0.5 0' * targ.mins_y + '0 0 1' * targ.view_ofs_z;
737 headmaxs = org + '0.5 0 0' * targ.maxs_x + '0 0.5 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
738 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
740 damage *= 1 + damage_headshotbonus;
742 deathtype |= HITTYPE_HEADSHOT;
749 attacker.typehitsound += 1; // TODO possibly trigger teamkill complain sound!
750 if(time > attacker.teamkill_complain)
752 attacker.teamkill_complain = time + 5;
753 attacker.teamkill_soundtime = time + 0.4;
754 attacker.teamkill_soundsource = targ;
761 if (self.damageforcescale)
764 self.velocity = self.velocity + self.damageforcescale * force;
765 self.flags = self.flags - (self.flags & FL_ONGROUND);
769 if (self.event_damage)
770 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
773 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
775 // Savage: vampire mode
778 if (time > self.spawnshieldtime)
780 attacker.health += damage;
784 if (attacker.runes & RUNE_VAMPIRE)
786 // apply vampire rune
787 if (attacker.runes & CURSE_EMPATHY) // have the curse too
789 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
790 attacker.health = bound(
791 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
792 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
793 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
797 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
798 attacker.health = bound(
799 attacker.health, // LA: was 3, but changed so that you can't lose health
800 // empathy won't let you gain health in the same way...
801 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
802 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
805 // apply empathy curse
806 else if (attacker.runes & CURSE_EMPATHY)
808 attacker.health = bound(
809 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
810 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
816 // apply mirror damage if any
817 if(mirrordamage > 0 || mirrorforce > 0)
819 attacker = attacker_save;
823 // just lose extra LIVES, don't kill the player for mirror damage
824 if(attacker.armorvalue > 0)
826 attacker.armorvalue = attacker.armorvalue - 1;
827 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
828 attacker.hitsound += 1;
832 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
833 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
837 vector NearestPointOnBox(entity box, vector org)
839 vector m1, m2, nearest;
841 m1 = box.mins + box.origin;
842 m2 = box.maxs + box.origin;
844 nearest_x = bound(m1_x, org_x, m2_x);
845 nearest_y = bound(m1_y, org_y, m2_y);
846 nearest_z = bound(m1_z, org_z, m2_z);
851 float RadiusDamage_running;
852 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
853 // Returns total damage applies to creatures
863 float total_damage_to_creatures;
866 if(RadiusDamage_running)
869 print("RadiusDamage called recursively!\n");
870 print("Expect stuff to go HORRIBLY wrong.\n");
871 print("Causing a stack trace...\n");
872 save = cvar_string("prvm_backtraceforwarnings");
873 cvar_set("prvm_backtraceforwarnings", "1");
874 fclose(-1); // calls VM_Warning
875 cvar_set("prvm_backtraceforwarnings", save);
879 RadiusDamage_running = 1;
881 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
882 total_damage_to_creatures = 0;
884 targ = findradius (blastorigin, rad);
888 if (targ != inflictor)
891 // LordHavoc: measure distance to nearest point on target (not origin)
892 // (this guarentees 100% damage on a touch impact)
893 nearest = NearestPointOnBox(targ, blastorigin);
894 diff = nearest - blastorigin;
895 // round up a little on the damage to ensure full damage on impacts
896 // and turn the distance into a fraction of the radius
897 power = 1 - ((vlen (diff) - 2) / rad);
899 //bprint(ftos(power));
904 finaldmg = coredamage * power + edgedamage * (1 - power);
907 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
908 // if it's a player, use the view origin as reference
909 if (targ.classname == "player")
910 center = targ.origin + targ.view_ofs;
911 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
912 // test line of sight to multiple positions on box,
913 // and do damage if any of them hit
915 c = ceil(finaldmg / 10);
921 traceline(blastorigin, nearest, TRUE, inflictor);
922 if (trace_fraction == 1 || trace_ent == targ
923 || cvar("g_throughfloor"))
926 total_damage_to_creatures += finaldmg;
927 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
928 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
930 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
933 nearest_x = targ.mins_x + random() * targ.size_x;
934 nearest_y = targ.mins_y + random() * targ.size_y;
935 nearest_z = targ.mins_z + random() * targ.size_z;
943 RadiusDamage_running = 0;
945 return total_damage_to_creatures;