2 float checkrules_firstblood;
6 void announce(entity player, string msg)
8 if(time > player.announcetime)
9 if(clienttype(player) == CLIENTTYPE_REAL)
11 player.announcetime = time + 0.3;
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 // TODO remove this, make callers route through PlayerScores instead
47 player.totalfrags += f;
50 void GiveFrags (entity attacker, entity targ, float f)
52 // TODO route through PlayerScores instead
56 if(cvar("g_arena_roundbased"))
61 if(cvar("g_domination_disable_frags"))
68 f = RunematchHandleFrags(attacker, targ, f);
72 f = kh_HandleFrags(attacker, targ, f);
76 // count remaining lives, not frags in lms
78 // keep track of the worst players lives
79 if(targ.frags < lms_lowest_lives)
80 lms_lowest_lives = targ.frags;
81 // player has no more lives left
85 lms_next_place = player_count;
86 targ.frags = -lms_next_place;
93 UpdateFrags(attacker, f);
96 string AppendItemcodes(string s, entity player)
101 // w = player.switchweapon;
103 w = player.cnt; // previous weapon!
104 s = strcat(s, ftos(W_ItemCode(w)));
105 if(time < player.strength_finished)
107 if(time < player.invincible_finished)
109 if(player.flagcarried != world)
111 if(player.BUTTON_CHAT)
116 s = strcat(s, "|", ftos(player.runes));
120 void LogDeath(string mode, float deathtype, entity killer, entity killed)
123 if(!cvar("sv_eventlog"))
125 s = strcat(":kill:", mode);
126 s = strcat(s, ":", ftos(killer.playerid));
127 s = strcat(s, ":", ftos(killed.playerid));
128 s = strcat(s, ":type=", ftos(deathtype));
129 s = strcat(s, ":items=");
130 s = AppendItemcodes(s, killer);
133 s = strcat(s, ":victimitems=");
134 s = AppendItemcodes(s, killed);
136 GameLogEcho(s, FALSE);
139 void Obituary (entity attacker, entity targ, float deathtype)
143 if (targ.classname == "player" || targ.classname == "corpse")
145 if (targ.classname == "corpse")
149 a = attacker.netname;
151 if (targ == attacker)
153 if (deathtype == DEATH_TEAMCHANGE) {
154 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
155 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
156 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
158 } else if (deathtype == DEATH_CAMP) {
160 centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
162 centerprint(targ, "^1Die camper!\n\n\n");
163 } else if (deathtype == DEATH_NOAMMO) {
165 centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
167 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
168 } else if (deathtype == DEATH_ROT) {
170 centerprint(targ, "^1You need to preserve your health\n\n\n");
172 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
173 } else if (deathtype == DEATH_MIRRORDAMAGE) {
175 centerprint(targ, "^1Don't go against team mates!\n\n\n");
177 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
180 centerprint(targ, "^1You need to be more careful!\n\n\n");
182 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
186 if (deathtype == DEATH_CAMP)
187 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
188 else if (deathtype == DEATH_MIRRORDAMAGE)
189 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
191 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
193 if(deathtype != DEATH_TEAMCHANGE)
195 LogDeath("suicide", deathtype, targ, targ);
196 GiveFrags(attacker, targ, -1);
198 if (targ.killcount > 2)
199 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
202 if (deathtype == IT_GRENADE_LAUNCHER)
203 bprint ("^1",s, "^1 detonated\n");
204 else if (deathtype == IT_ELECTRO)
205 bprint ("^1",s, "^1 played with plasma\n");
206 else if (deathtype == IT_ROCKET_LAUNCHER)
207 bprint ("^1",s, "^1 exploded\n");
208 else if (deathtype == DEATH_KILL)
209 bprint ("^1",s, "^1 couldn't take it anymore\n");
210 else if (deathtype == DEATH_ROT)
211 bprint ("^1",s, "^1 died\n");
212 else if (deathtype == DEATH_NOAMMO)
214 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
215 //sound (self, CHAN_BODY, "minstagib/mockery.wav", 1, ATTN_NONE);
217 else if (deathtype == DEATH_CAMP)
218 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
219 else if (deathtype == DEATH_MIRRORDAMAGE)
220 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
221 else if (deathtype != DEATH_TEAMCHANGE)
222 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
224 if(deathtype != DEATH_TEAMCHANGE)
226 LogDeath("suicide", deathtype, targ, targ);
227 GiveFrags(attacker, targ, -1);
229 if (targ.killcount > 2)
230 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
233 else if (attacker.classname == "player" || attacker.classname == "gib")
235 if(teamplay && attacker.team == targ.team)
238 centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
239 bprint ("^1", a, "^1 took action against a teammate\n");
241 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
242 bprint ("^1", a, "^1 mows down a teammate\n");
244 GiveFrags(attacker, targ, -1);
245 if (targ.killcount > 2) {
247 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
249 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
251 if (attacker.killcount > 2) {
253 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
255 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
257 attacker.killcount = 0;
259 LogDeath("tk", deathtype, attacker, targ);
263 if (!checkrules_firstblood)
265 checkrules_firstblood = TRUE;
266 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
268 //sound(world, CHAN_AUTO, "announce/male/mapkill1.wav", 1, ATTN_NONE);
270 bprint("^1",a, "^1 was the first to score", "\n");
272 bprint("^1",a, "^1 drew first blood", "\n");
276 centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
277 centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
279 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
280 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
284 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
286 if (deathtype == IT_LASER)
287 bprint ("^1",s, "^1 was blasted by ", a, "\n");
288 else if (deathtype == IT_UZI)
289 bprint ("^1",s, "^1 was riddled full of holes by ", a, "\n");
290 else if (deathtype == IT_SHOTGUN)
291 bprint ("^1",s, "^1 was gunned by ", a, "\n");
292 else if (deathtype == IT_GRENADE_LAUNCHER)
293 bprint ("^1", s, "^1 was blasted by ", a, "\n");
294 else if (deathtype == IT_ELECTRO)
295 bprint ("^1",s, "^1 was blasted by ", a, "\n");
296 else if (deathtype == IT_CRYLINK)
297 bprint ("^1",s, "^1 was blasted by ", a, "\n");
298 else if (deathtype == IT_NEX)
299 bprint ("^1",s, "^1 has been vaporized by ", a, "\n");
300 else if (deathtype == IT_HAGAR)
301 bprint ("^1",s, "^1 was pummeled by ", a, "\n");
302 else if (deathtype == IT_ROCKET_LAUNCHER)
303 bprint ("^1",s, "^1 was blasted by ", a, "\n");
304 else if (deathtype == DEATH_TELEFRAG)
305 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
306 else if (deathtype == DEATH_DROWN)
307 bprint ("^1",s, "^1 was drowned by ", a, "\n");
308 else if (deathtype == DEATH_SLIME)
309 bprint ("^1",s, "^1 was slimed by ", a, "\n");
310 else if (deathtype == DEATH_LAVA)
311 bprint ("^1",s, "^1 was cooked by ", a, "\n");
312 else if (deathtype == DEATH_FALL)
313 bprint ("^1",s, "^1 was grounded by ", a, "\n");
314 else if (deathtype == DEATH_SHOOTING_STAR)
315 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
316 else if (deathtype == DEATH_SWAMP)
317 bprint ("^1",s, "^1 was conserved by ", a, "\n");
318 else if (deathtype == DEATH_HURTTRIGGER)
319 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
320 else if(deathtype == DEATH_TURRET)
321 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
323 bprint ("^1",s, "^1 was fragged by ", a, "\n");
325 if(g_ctf && targ.flagcarried)
326 GiveFrags(attacker, targ, cvar("g_ctf_flagscore_kill"));
328 GiveFrags(attacker, targ, 1);
329 if (targ.killcount > 2) {
331 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
333 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
335 attacker.killcount = attacker.killcount + 1;
336 if (attacker.killcount > 2) {
338 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
340 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
343 LogDeath("frag", deathtype, attacker, targ);
345 if (attacker.killcount == 3)
348 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
350 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
351 announce(attacker, "announcer/male/03kills.ogg");
354 else if (attacker.killcount == 5)
357 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
359 bprint (a,"^7 unleashes ^1RAGE\n");
360 announce(attacker, "announcer/male/05kills.ogg");
363 else if (attacker.killcount == 10)
366 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
368 bprint (a,"^7 starts the ^1MASSACRE!\n");
369 announce(attacker, "announcer/male/10kills.ogg");
372 else if (attacker.killcount == 15)
375 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
377 bprint (a,"^7 executes ^1MAYHEM!\n");
378 announce(attacker, "announcer/male/15kills.ogg");
381 else if (attacker.killcount == 20)
384 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
386 bprint (a,"^7 is a ^1BERSERKER!\n");
387 announce(attacker, "announcer/male/20kills.ogg");
390 else if (attacker.killcount == 25)
393 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
395 bprint (a,"^7 inflicts ^1CARNAGE!\n");
396 announce(attacker, "announcer/male/25kills.ogg");
399 else if (attacker.killcount == 30)
402 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
404 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
405 announce(attacker, "announcer/male/30kills.ogg");
412 centerprint(targ, "^1Watch your step!\n\n\n");
413 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
414 bprint ("^1",s, "^1 ", attacker.message, "\n");
415 else if (deathtype == DEATH_DROWN)
417 bprint ("^1",s, "^1 was in the water for too long\n");
419 bprint ("^1",s, "^1 drowned\n");
420 else if (deathtype == DEATH_SLIME)
421 bprint ("^1",s, "^1 was slimed\n");
422 else if (deathtype == DEATH_LAVA)
424 bprint ("^1",s, "^1 found a hot place\n");
426 bprint ("^1",s, "^1 turned into hot slag\n");
427 else if (deathtype == DEATH_FALL)
429 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
431 bprint ("^1",s, "^1 hit the ground with a crunch\n");
432 else if (deathtype == DEATH_SHOOTING_STAR)
433 bprint ("^1",s, "^1 became a shooting star\n");
434 else if (deathtype == DEATH_SWAMP)
436 bprint ("^1",s, "^1 discovered a swamp\n");
438 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
439 else if(deathtype == DEATH_TURRET)
440 bprint ("^1",s, "^1 was mowed down by a turret \n");
443 bprint ("^1",s, "^1 needs a restart\n");
445 bprint ("^1",s, "^1 died\n");
446 GiveFrags(targ, targ, -1);
447 if(targ.frags == -5) {
448 announce(targ, "announcer/male/botlike.ogg");
451 if (targ.killcount > 2)
453 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
455 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
457 LogDeath("accident", deathtype, targ, targ);
459 targ.death_origin = targ.origin;
461 targ.killer_origin = attacker.origin;
462 // FIXME: this should go in PutClientInServer
468 // these are updated by each Damage call for use in button triggering and such
470 entity damage_inflictor;
471 entity damage_attacker;
473 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
477 entity attacker_save;
481 if (gameover || targ.killcount == -666)
484 local entity oldself;
488 damage_inflictor = inflictor;
489 damage_attacker = attacker;
490 attacker_save = attacker;
492 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
494 // These are ALWAYS lethal
495 // No damage modification here
496 // Instead, prepare the victim for his death...
498 targ.spawnshieldtime = 0;
499 targ.health = 0.9; // this is < 1
500 targ.flags -= targ.flags & FL_GODMODE;
505 if (targ.classname == "player")
506 if (attacker.classname == "player")
509 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
511 // nullify damage if teamplay is on
512 if(deathtype != DEATH_TELEFRAG)
513 if(attacker.team == targ.team)
514 if(attacker.classname == "player")
518 else if(attacker != targ)
522 else if(teamplay == 4)
524 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
526 mirrordamage = cvar("g_mirrordamage") * damage;
527 mirrorforce = cvar("g_mirrordamage") * vlen(force);
530 if(cvar("g_friendlyfire") == 0)
534 damage = cvar("g_friendlyfire") * damage;
535 // mirrordamage will be used LATER
544 if(targ.classname == "player")
545 if(attacker.classname == "player")
548 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
549 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
555 if(targ.classname == "player")
557 attacker.hitsound += 1;
561 if ((deathtype == DEATH_FALL) ||
562 (deathtype == DEATH_DROWN) ||
563 (deathtype == DEATH_SLIME) ||
564 (deathtype == DEATH_LAVA))
566 if (targ.armorvalue && (deathtype == IT_NEX) && damage)
568 targ.armorvalue -= 1;
569 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
573 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
575 if(clienttype(attacker) == CLIENTTYPE_REAL)
576 if(IsDifferentTeam(targ, attacker))
579 if (deathtype == IT_LASER)
582 if (targ != attacker)
584 if (targ.classname == "player")
585 centerprint(attacker, "Secondary fire inflicts no damage!\n");
595 if(targ.takedamage == DAMAGE_AIM)
597 if(IsDifferentTeam(targ, attacker))
601 // apply strength multiplier
602 if (attacker.items & IT_STRENGTH && !g_minstagib)
604 damage = damage * cvar("g_balance_powerup_strength_damage");
605 force = force * cvar("g_balance_powerup_strength_force");
607 // apply invincibility multiplier
608 if (targ.items & IT_INVINCIBLE && !g_minstagib)
609 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
614 // apply strength rune
615 if (attacker.runes & RUNE_STRENGTH)
617 if(attacker.runes & CURSE_WEAK) // have both curse & rune
619 damage = damage * cvar("g_balance_rune_strength_combo_damage");
620 force = force * cvar("g_balance_rune_strength_combo_force");
624 damage = damage * cvar("g_balance_rune_strength_damage");
625 force = force * cvar("g_balance_rune_strength_force");
628 else if (attacker.runes & CURSE_WEAK)
630 damage = damage * cvar("g_balance_curse_weak_damage");
631 force = force * cvar("g_balance_curse_weak_force");
634 // apply defense rune
635 if (targ.runes & RUNE_DEFENSE)
637 if (targ.runes & CURSE_VULNER) // have both curse & rune
638 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
640 damage = damage * cvar("g_balance_rune_defense_takedamage");
642 else if (targ.runes & CURSE_VULNER)
643 damage = damage * cvar("g_balance_curse_vulner_takedamage");
648 if (self.damageforcescale)
651 self.velocity = self.velocity + self.damageforcescale * force;
652 self.flags = self.flags - (self.flags & FL_ONGROUND);
655 if (self.event_damage)
656 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
659 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
661 // Savage: vampire mode
665 if (time > self.spawnshieldtime)
667 attacker.health += damage;
671 if (attacker.runes & RUNE_VAMPIRE)
673 // apply vampire rune
674 if (attacker.runes & CURSE_EMPATHY) // have the curse too
676 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
677 attacker.health = bound(
678 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
679 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
680 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
684 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
685 attacker.health = bound(
686 attacker.health, // LA: was 3, but changed so that you can't lose health
687 // empathy won't let you gain health in the same way...
688 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
689 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
692 // apply empathy curse
693 else if (attacker.runes & CURSE_EMPATHY)
695 attacker.health = bound(
696 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
697 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
703 // apply mirror damage if any
704 if(mirrordamage > 0 || mirrorforce > 0)
706 attacker = attacker_save;
710 // just lose extra LIVES, don't kill the player for mirror damage
711 if(attacker.armorvalue > 0)
713 attacker.armorvalue = attacker.armorvalue - 1;
714 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
715 attacker.hitsound += 1;
719 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
720 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
724 vector NearestPointOnBox(entity box, vector org)
726 vector m1, m2, nearest;
728 m1 = box.mins + box.origin;
729 m2 = box.maxs + box.origin;
731 nearest_x = bound(m1_x, org_x, m2_x);
732 nearest_y = bound(m1_y, org_y, m2_y);
733 nearest_z = bound(m1_z, org_z, m2_z);
738 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
739 // Returns total damage applies to creatures
749 float total_damage_to_creatures;
751 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
752 total_damage_to_creatures = 0;
754 targ = findradius (blastorigin, rad);
757 if (targ != inflictor)
760 // LordHavoc: measure distance to nearest point on target (not origin)
761 // (this guarentees 100% damage on a touch impact)
762 nearest = NearestPointOnBox(targ, blastorigin);
763 diff = nearest - blastorigin;
764 // round up a little on the damage to ensure full damage on impacts
765 // and turn the distance into a fraction of the radius
766 power = 1 - ((vlen (diff) - 2) / rad);
768 //bprint(ftos(power));
773 finaldmg = coredamage * power + edgedamage * (1 - power);
776 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
777 // if it's a player, use the view origin as reference
778 if (targ.classname == "player")
779 center = targ.origin + targ.view_ofs;
780 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
781 if (targ == attacker)
782 finaldmg = finaldmg * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
783 // test line of sight to multiple positions on box,
784 // and do damage if any of them hit
786 c = ceil(finaldmg / 10);
792 traceline(blastorigin, nearest, TRUE, inflictor);
793 if (trace_fraction == 1 || trace_ent == targ
794 || cvar("g_throughfloor"))
797 total_damage_to_creatures += finaldmg;
798 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
801 nearest_x = targ.mins_x + random() * targ.size_x;
802 nearest_y = targ.mins_y + random() * targ.size_y;
803 nearest_z = targ.mins_z + random() * targ.size_z;
811 return total_damage_to_creatures;