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"));
302 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
304 w = DEATH_WEAPONOF(deathtype);
307 w_deathtypestring = "was blasted by";
308 w_deathtype = deathtype;
309 weapon_action(w, WR_KILLMESSAGE);
310 p = strstrofs(w_deathtypestring, "#", 0);
312 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
314 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
316 else if (deathtype == DEATH_TELEFRAG)
317 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
318 else if (deathtype == DEATH_DROWN)
319 bprint ("^1",s, "^1 was drowned by ", a, "\n");
320 else if (deathtype == DEATH_SLIME)
321 bprint ("^1",s, "^1 was slimed by ", a, "\n");
322 else if (deathtype == DEATH_LAVA)
323 bprint ("^1",s, "^1 was cooked by ", a, "\n");
324 else if (deathtype == DEATH_FALL)
325 bprint ("^1",s, "^1 was grounded by ", a, "\n");
326 else if (deathtype == DEATH_SHOOTING_STAR)
327 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
328 else if (deathtype == DEATH_SWAMP)
329 bprint ("^1",s, "^1 was conserved by ", a, "\n");
330 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
332 p = strstrofs(inflictor.message2, "#", 0);
334 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
336 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
338 else if(deathtype == DEATH_TURRET)
339 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
340 else if(deathtype == DEATH_TOUCHEXPLODE)
341 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
343 bprint ("^1",s, "^1 was fragged by ", a, "\n");
345 if(g_ctf && targ.flagcarried)
347 UpdateFrags(attacker, ctf_score_value("score_kill"));
348 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
349 GiveFrags(attacker, targ, 0); // for logging
352 GiveFrags(attacker, targ, 1);
353 if (targ.killcount > 2) {
355 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
357 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
359 attacker.killcount = attacker.killcount + 1;
360 if (attacker.killcount > 2) {
362 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
364 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
367 LogDeath("frag", deathtype, attacker, targ);
369 if (attacker.killcount == 3)
372 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
374 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
375 announce(attacker, "announcer/male/03kills.wav");
378 else if (attacker.killcount == 5)
381 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
383 bprint (a,"^7 unleashes ^1RAGE\n");
384 announce(attacker, "announcer/male/05kills.wav");
387 else if (attacker.killcount == 10)
390 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
392 bprint (a,"^7 starts the ^1MASSACRE!\n");
393 announce(attacker, "announcer/male/10kills.wav");
396 else if (attacker.killcount == 15)
399 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
401 bprint (a,"^7 executes ^1MAYHEM!\n");
402 announce(attacker, "announcer/male/15kills.wav");
405 else if (attacker.killcount == 20)
408 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
410 bprint (a,"^7 is a ^1BERSERKER!\n");
411 announce(attacker, "announcer/male/20kills.wav");
414 else if (attacker.killcount == 25)
417 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
419 bprint (a,"^7 inflicts ^1CARNAGE!\n");
420 announce(attacker, "announcer/male/25kills.wav");
423 else if (attacker.killcount == 30)
426 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
428 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
429 announce(attacker, "announcer/male/30kills.wav");
436 centerprint(targ, "^1Watch your step!\n\n\n");
437 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
438 bprint ("^1",s, "^1 ", inflictor.message, "\n");
439 else if (deathtype == DEATH_DROWN)
441 bprint ("^1",s, "^1 was in the water for too long\n");
443 bprint ("^1",s, "^1 drowned\n");
444 else if (deathtype == DEATH_SLIME)
445 bprint ("^1",s, "^1 was slimed\n");
446 else if (deathtype == DEATH_LAVA)
448 bprint ("^1",s, "^1 found a hot place\n");
450 bprint ("^1",s, "^1 turned into hot slag\n");
451 else if (deathtype == DEATH_FALL)
453 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
455 bprint ("^1",s, "^1 hit the ground with a crunch\n");
456 else if (deathtype == DEATH_SHOOTING_STAR)
457 bprint ("^1",s, "^1 became a shooting star\n");
458 else if (deathtype == DEATH_SWAMP)
460 bprint ("^1",s, "^1 discovered a swamp\n");
462 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
463 else if(deathtype == DEATH_TURRET)
464 bprint ("^1",s, "^1 was mowed down by a turret \n");
465 else if(deathtype == DEATH_TOUCHEXPLODE)
466 bprint ("^1",s, "^1 died in an accident\n");
469 bprint ("^1",s, "^1 needs a restart\n");
471 bprint ("^1",s, "^1 died\n");
472 GiveFrags(targ, targ, -1);
473 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
474 announce(targ, "announcer/male/botlike.wav");
477 if (targ.killcount > 2)
479 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
481 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
483 LogDeath("accident", deathtype, targ, targ);
485 targ.death_origin = targ.origin;
487 targ.killer_origin = attacker.origin;
488 // FIXME: this should go in PutClientInServer
494 // these are updated by each Damage call for use in button triggering and such
496 entity damage_inflictor;
497 entity damage_attacker;
499 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
504 entity attacker_save;
508 if (gameover || targ.killcount == -666)
511 local entity oldself;
515 damage_inflictor = inflictor;
516 damage_attacker = attacker;
517 attacker_save = attacker;
519 if(targ.classname == "player")
522 if(targ.hook.aiment == attacker)
523 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
525 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
526 if(DEATH_ISWEAPON(deathtype, WEP_HOOK))
528 if(targ.classname == "player")
529 if not(IsDifferentTeam(targ, attacker))
536 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
538 // These are ALWAYS lethal
539 // No damage modification here
540 // Instead, prepare the victim for his death...
542 targ.spawnshieldtime = 0;
543 targ.health = 0.9; // this is < 1
544 targ.flags -= targ.flags & FL_GODMODE;
547 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
553 if (targ.classname == "player")
554 if (attacker.classname == "player")
557 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
559 // nullify damage if teamplay is on
560 if(deathtype != DEATH_TELEFRAG)
561 if(attacker.classname == "player")
563 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
568 else if(attacker.team == targ.team)
572 else if(attacker != targ)
576 else if(teamplay == 4)
578 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
580 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
581 attacker.dmg_team = attacker.dmg_team + damage;
582 if(attacker.dmg_team > teamdamage0)
583 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
584 mirrorforce = cvar("g_mirrordamage") * vlen(force);
587 if(cvar("g_friendlyfire") == 0)
591 damage = cvar("g_friendlyfire") * damage;
592 // mirrordamage will be used LATER
601 if(targ.classname == "player")
602 if(attacker.classname == "player")
605 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
606 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
611 if ((deathtype == DEATH_FALL) ||
612 (deathtype == DEATH_DROWN) ||
613 (deathtype == DEATH_SLIME) ||
614 (deathtype == DEATH_LAVA))
619 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
621 targ.armorvalue -= 1;
622 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
626 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
629 if (targ != attacker)
631 if (targ.classname == "player")
632 centerprint(attacker, "Secondary fire inflicts no damage!\n");
642 // apply strength multiplier
643 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
647 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
648 force = force * cvar("g_balance_powerup_strength_selfforce");
652 damage = damage * cvar("g_balance_powerup_strength_damage");
653 force = force * cvar("g_balance_powerup_strength_force");
657 // apply invincibility multiplier
658 if (targ.items & IT_INVINCIBLE && !g_minstagib)
659 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
661 if (targ == attacker)
662 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
664 // CTF: reduce damage/force
669 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
670 force = force * cvar("g_ctf_flagcarrier_selfforce");
675 // apply strength rune
676 if (attacker.runes & RUNE_STRENGTH)
678 if(attacker.runes & CURSE_WEAK) // have both curse & rune
680 damage = damage * cvar("g_balance_rune_strength_combo_damage");
681 force = force * cvar("g_balance_rune_strength_combo_force");
685 damage = damage * cvar("g_balance_rune_strength_damage");
686 force = force * cvar("g_balance_rune_strength_force");
689 else if (attacker.runes & CURSE_WEAK)
691 damage = damage * cvar("g_balance_curse_weak_damage");
692 force = force * cvar("g_balance_curse_weak_force");
695 // apply defense rune
696 if (targ.runes & RUNE_DEFENSE)
698 if (targ.runes & CURSE_VULNER) // have both curse & rune
699 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
701 damage = damage * cvar("g_balance_rune_defense_takedamage");
703 else if (targ.runes & CURSE_VULNER)
704 damage = damage * cvar("g_balance_curse_vulner_takedamage");
710 if(targ.takedamage == DAMAGE_AIM)
712 if(targ.classname == "player")
714 if(IsDifferentTeam(targ, attacker))
719 attacker.typehitsound += 1;
721 attacker.hitsound += 1;
723 damage_goodhits += 1;
724 damage_gooddamage += damage;
726 if not(DEATH_ISSPECIAL(deathtype))
733 if(targ.items & IT_STRENGTH)
737 // find height of hit on player axis
738 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
739 vector headmins, headmaxs, org;
740 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
741 headmins = org + '0.7 0 0' * targ.mins_x + '0 0.7 0' * targ.mins_y + '0 0 1' * targ.view_ofs_z;
742 headmaxs = org + '0.7 0 0' * targ.maxs_x + '0 0.7 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
743 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
745 damage *= 1 + damage_headshotbonus;
747 deathtype |= HITTYPE_HEADSHOT;
754 attacker.typehitsound += 1;
756 if(time > attacker.teamkill_complain)
758 attacker.teamkill_complain = time + 5;
759 attacker.teamkill_soundtime = time + 0.4;
760 attacker.teamkill_soundsource = targ;
767 if (self.damageforcescale)
770 self.velocity = self.velocity + self.damageforcescale * force;
771 self.flags = self.flags - (self.flags & FL_ONGROUND);
775 if (self.event_damage)
776 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
779 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
781 // Savage: vampire mode
784 if (time > self.spawnshieldtime)
786 attacker.health += damage;
790 if (attacker.runes & RUNE_VAMPIRE)
792 // apply vampire rune
793 if (attacker.runes & CURSE_EMPATHY) // have the curse too
795 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
796 attacker.health = bound(
797 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
798 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
799 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
803 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
804 attacker.health = bound(
805 attacker.health, // LA: was 3, but changed so that you can't lose health
806 // empathy won't let you gain health in the same way...
807 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
808 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
811 // apply empathy curse
812 else if (attacker.runes & CURSE_EMPATHY)
814 attacker.health = bound(
815 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
816 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
822 // apply mirror damage if any
823 if(mirrordamage > 0 || mirrorforce > 0)
825 attacker = attacker_save;
829 // just lose extra LIVES, don't kill the player for mirror damage
830 if(attacker.armorvalue > 0)
832 attacker.armorvalue = attacker.armorvalue - 1;
833 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
834 attacker.hitsound += 1;
838 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
839 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
843 vector NearestPointOnBox(entity box, vector org)
845 vector m1, m2, nearest;
847 m1 = box.mins + box.origin;
848 m2 = box.maxs + box.origin;
850 nearest_x = bound(m1_x, org_x, m2_x);
851 nearest_y = bound(m1_y, org_y, m2_y);
852 nearest_z = bound(m1_z, org_z, m2_z);
857 float RadiusDamage_running;
858 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
859 // Returns total damage applies to creatures
869 float total_damage_to_creatures;
872 if(RadiusDamage_running)
875 print("RadiusDamage called recursively!\n");
876 print("Expect stuff to go HORRIBLY wrong.\n");
877 print("Causing a stack trace...\n");
878 save = cvar_string("prvm_backtraceforwarnings");
879 cvar_set("prvm_backtraceforwarnings", "1");
880 fclose(-1); // calls VM_Warning
881 cvar_set("prvm_backtraceforwarnings", save);
885 RadiusDamage_running = 1;
887 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
888 total_damage_to_creatures = 0;
890 targ = findradius (blastorigin, rad);
894 if (targ != inflictor)
897 // LordHavoc: measure distance to nearest point on target (not origin)
898 // (this guarentees 100% damage on a touch impact)
899 nearest = NearestPointOnBox(targ, blastorigin);
900 diff = nearest - blastorigin;
901 // round up a little on the damage to ensure full damage on impacts
902 // and turn the distance into a fraction of the radius
903 power = 1 - ((vlen (diff) - 2) / rad);
905 //bprint(ftos(power));
910 finaldmg = coredamage * power + edgedamage * (1 - power);
913 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
914 // if it's a player, use the view origin as reference
915 if (targ.classname == "player")
916 center = targ.origin + targ.view_ofs;
917 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
918 // test line of sight to multiple positions on box,
919 // and do damage if any of them hit
921 c = ceil(finaldmg / 10);
927 traceline(blastorigin, nearest, TRUE, inflictor);
928 if (trace_fraction == 1 || trace_ent == targ
929 || cvar("g_throughfloor"))
932 total_damage_to_creatures += finaldmg;
933 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
934 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
936 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
939 nearest_x = targ.mins_x + random() * targ.size_x;
940 nearest_y = targ.mins_y + random() * targ.size_y;
941 nearest_z = targ.mins_z + random() * targ.size_z;
949 RadiusDamage_running = 0;
951 return total_damage_to_creatures;