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)
46 // TODO remove this, make callers route through PlayerScores instead
48 player.totalfrags += f;
50 PlayerTeamScore_AddScore(player, f);
53 void GiveFrags (entity attacker, entity targ, float f)
55 // TODO route through PlayerScores instead
59 if(cvar("g_arena_roundbased"))
64 if(cvar("g_domination_disable_frags"))
71 f = RunematchHandleFrags(attacker, targ, f);
75 f = kh_HandleFrags(attacker, targ, f);
79 // count remaining lives, not frags in lms
81 // keep track of the worst players lives
82 if(targ.frags < lms_lowest_lives)
83 lms_lowest_lives = targ.frags;
84 // player has no more lives left
88 lms_next_place = player_count;
89 targ.frags = -lms_next_place;
96 UpdateFrags(attacker, f);
99 string AppendItemcodes(string s, entity player)
104 // w = player.switchweapon;
106 w = player.cnt; // previous weapon!
107 s = strcat(s, ftos(W_ItemCode(w)));
108 if(time < player.strength_finished)
110 if(time < player.invincible_finished)
112 if(player.flagcarried != world)
114 if(player.BUTTON_CHAT)
119 s = strcat(s, "|", ftos(player.runes));
123 void LogDeath(string mode, float deathtype, entity killer, entity killed)
126 if(!cvar("sv_eventlog"))
128 s = strcat(":kill:", mode);
129 s = strcat(s, ":", ftos(killer.playerid));
130 s = strcat(s, ":", ftos(killed.playerid));
131 s = strcat(s, ":type=", ftos(deathtype));
132 s = strcat(s, ":items=");
133 s = AppendItemcodes(s, killer);
136 s = strcat(s, ":victimitems=");
137 s = AppendItemcodes(s, killed);
139 GameLogEcho(s, FALSE);
142 void Obituary (entity attacker, entity targ, float deathtype)
146 if (targ.classname == "player" || targ.classname == "corpse")
148 if (targ.classname == "corpse")
152 a = attacker.netname;
154 if (targ == attacker)
156 if (deathtype == DEATH_TEAMCHANGE) {
157 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
158 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
159 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
161 } else if (deathtype == DEATH_CAMP) {
163 centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
165 centerprint(targ, "^1Die camper!\n\n\n");
166 } else if (deathtype == DEATH_NOAMMO) {
168 centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
170 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
171 } else if (deathtype == DEATH_ROT) {
173 centerprint(targ, "^1You need to preserve your health\n\n\n");
175 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
176 } else if (deathtype == DEATH_MIRRORDAMAGE) {
178 centerprint(targ, "^1Don't go against team mates!\n\n\n");
180 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
183 centerprint(targ, "^1You need to be more careful!\n\n\n");
185 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
189 if (deathtype == DEATH_CAMP)
190 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
191 else if (deathtype == DEATH_MIRRORDAMAGE)
192 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
194 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
196 if(deathtype != DEATH_TEAMCHANGE)
198 LogDeath("suicide", deathtype, targ, targ);
199 PlayerScore_Add(attacker, SP_SUICIDES, 1);
200 GiveFrags(attacker, targ, -1);
202 if (targ.killcount > 2)
203 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
206 if (deathtype == IT_GRENADE_LAUNCHER)
207 bprint ("^1",s, "^1 detonated\n");
208 else if (deathtype == IT_ELECTRO)
209 bprint ("^1",s, "^1 played with plasma\n");
210 else if (deathtype == IT_ROCKET_LAUNCHER)
211 bprint ("^1",s, "^1 exploded\n");
212 else if (deathtype == DEATH_KILL)
213 bprint ("^1",s, "^1 couldn't take it anymore\n");
214 else if (deathtype == DEATH_ROT)
215 bprint ("^1",s, "^1 died\n");
216 else if (deathtype == DEATH_NOAMMO)
218 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
219 //sound (self, CHAN_BODY, "minstagib/mockery.wav", 1, ATTN_NONE);
221 else if (deathtype == DEATH_CAMP)
222 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
223 else if (deathtype == DEATH_MIRRORDAMAGE)
224 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
225 else if (deathtype != DEATH_TEAMCHANGE)
226 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
228 if(deathtype != DEATH_TEAMCHANGE)
230 LogDeath("suicide", deathtype, targ, targ);
231 PlayerScore_Add(attacker, SP_SUICIDES, 1);
232 GiveFrags(attacker, targ, -1);
234 if (targ.killcount > 2)
235 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
238 else if (attacker.classname == "player" || attacker.classname == "gib")
240 if(teamplay && attacker.team == targ.team)
243 centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
244 bprint ("^1", a, "^1 took action against a teammate\n");
246 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
247 bprint ("^1", a, "^1 mows down a teammate\n");
249 GiveFrags(attacker, targ, -1);
250 PlayerScore_Add(attacker, SP_KILLS, -1); // teamkills DO cound as -1 kill right?
251 if (targ.killcount > 2) {
253 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
255 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
257 if (attacker.killcount > 2) {
259 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
261 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
263 attacker.killcount = 0;
265 LogDeath("tk", deathtype, attacker, targ);
269 if (!checkrules_firstblood)
271 checkrules_firstblood = TRUE;
272 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
274 //sound(world, CHAN_AUTO, "announce/male/mapkill1.wav", 1, ATTN_NONE);
276 bprint("^1",a, "^1 was the first to score", "\n");
278 bprint("^1",a, "^1 drew first blood", "\n");
282 centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
283 centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
285 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
286 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
290 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
292 if (deathtype == IT_LASER)
293 bprint ("^1",s, "^1 was blasted by ", a, "\n");
294 else if (deathtype == IT_UZI)
295 bprint ("^1",s, "^1 was riddled full of holes by ", a, "\n");
296 else if (deathtype == IT_SHOTGUN)
297 bprint ("^1",s, "^1 was gunned by ", a, "\n");
298 else if (deathtype == IT_GRENADE_LAUNCHER)
299 bprint ("^1", s, "^1 was blasted by ", a, "\n");
300 else if (deathtype == IT_ELECTRO)
301 bprint ("^1",s, "^1 was blasted by ", a, "\n");
302 else if (deathtype == IT_CRYLINK)
303 bprint ("^1",s, "^1 was blasted by ", a, "\n");
304 else if (deathtype == IT_NEX)
305 bprint ("^1",s, "^1 has been vaporized by ", a, "\n");
306 else if (deathtype == IT_HAGAR)
307 bprint ("^1",s, "^1 was pummeled by ", a, "\n");
308 else if (deathtype == IT_ROCKET_LAUNCHER)
309 bprint ("^1",s, "^1 was blasted by ", a, "\n");
310 else if (deathtype == DEATH_TELEFRAG)
311 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
312 else if (deathtype == DEATH_DROWN)
313 bprint ("^1",s, "^1 was drowned by ", a, "\n");
314 else if (deathtype == DEATH_SLIME)
315 bprint ("^1",s, "^1 was slimed by ", a, "\n");
316 else if (deathtype == DEATH_LAVA)
317 bprint ("^1",s, "^1 was cooked by ", a, "\n");
318 else if (deathtype == DEATH_FALL)
319 bprint ("^1",s, "^1 was grounded by ", a, "\n");
320 else if (deathtype == DEATH_SHOOTING_STAR)
321 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
322 else if (deathtype == DEATH_SWAMP)
323 bprint ("^1",s, "^1 was conserved by ", a, "\n");
324 else if (deathtype == DEATH_HURTTRIGGER)
325 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
326 else if(deathtype == DEATH_TURRET)
327 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
329 bprint ("^1",s, "^1 was fragged by ", a, "\n");
331 if(g_ctf && targ.flagcarried)
332 GiveFrags(attacker, targ, cvar("g_ctf_flagscore_kill"));
334 GiveFrags(attacker, targ, 1);
335 if (targ.killcount > 2) {
337 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
339 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
341 attacker.killcount = attacker.killcount + 1;
342 if (attacker.killcount > 2) {
344 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
346 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
349 LogDeath("frag", deathtype, attacker, targ);
351 if (attacker.killcount == 3)
354 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
356 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
357 announce(attacker, "announcer/male/03kills.ogg");
360 else if (attacker.killcount == 5)
363 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
365 bprint (a,"^7 unleashes ^1RAGE\n");
366 announce(attacker, "announcer/male/05kills.ogg");
369 else if (attacker.killcount == 10)
372 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
374 bprint (a,"^7 starts the ^1MASSACRE!\n");
375 announce(attacker, "announcer/male/10kills.ogg");
378 else if (attacker.killcount == 15)
381 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
383 bprint (a,"^7 executes ^1MAYHEM!\n");
384 announce(attacker, "announcer/male/15kills.ogg");
387 else if (attacker.killcount == 20)
390 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
392 bprint (a,"^7 is a ^1BERSERKER!\n");
393 announce(attacker, "announcer/male/20kills.ogg");
396 else if (attacker.killcount == 25)
399 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
401 bprint (a,"^7 inflicts ^1CARNAGE!\n");
402 announce(attacker, "announcer/male/25kills.ogg");
405 else if (attacker.killcount == 30)
408 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
410 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
411 announce(attacker, "announcer/male/30kills.ogg");
418 centerprint(targ, "^1Watch your step!\n\n\n");
419 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
420 bprint ("^1",s, "^1 ", attacker.message, "\n");
421 else if (deathtype == DEATH_DROWN)
423 bprint ("^1",s, "^1 was in the water for too long\n");
425 bprint ("^1",s, "^1 drowned\n");
426 else if (deathtype == DEATH_SLIME)
427 bprint ("^1",s, "^1 was slimed\n");
428 else if (deathtype == DEATH_LAVA)
430 bprint ("^1",s, "^1 found a hot place\n");
432 bprint ("^1",s, "^1 turned into hot slag\n");
433 else if (deathtype == DEATH_FALL)
435 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
437 bprint ("^1",s, "^1 hit the ground with a crunch\n");
438 else if (deathtype == DEATH_SHOOTING_STAR)
439 bprint ("^1",s, "^1 became a shooting star\n");
440 else if (deathtype == DEATH_SWAMP)
442 bprint ("^1",s, "^1 discovered a swamp\n");
444 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
445 else if(deathtype == DEATH_TURRET)
446 bprint ("^1",s, "^1 was mowed down by a turret \n");
449 bprint ("^1",s, "^1 needs a restart\n");
451 bprint ("^1",s, "^1 died\n");
452 GiveFrags(targ, targ, -1);
453 PlayerScore_Add(targ, SP_DEATHS, 1);
454 if(targ.frags == -5) {
455 announce(targ, "announcer/male/botlike.ogg");
458 if (targ.killcount > 2)
460 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
462 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
464 LogDeath("accident", deathtype, targ, targ);
466 targ.death_origin = targ.origin;
468 targ.killer_origin = attacker.origin;
469 // FIXME: this should go in PutClientInServer
475 // these are updated by each Damage call for use in button triggering and such
477 entity damage_inflictor;
478 entity damage_attacker;
480 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
484 entity attacker_save;
488 if (gameover || targ.killcount == -666)
491 local entity oldself;
495 damage_inflictor = inflictor;
496 damage_attacker = attacker;
497 attacker_save = attacker;
499 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
501 // These are ALWAYS lethal
502 // No damage modification here
503 // Instead, prepare the victim for his death...
505 targ.spawnshieldtime = 0;
506 targ.health = 0.9; // this is < 1
507 targ.flags -= targ.flags & FL_GODMODE;
512 if (targ.classname == "player")
513 if (attacker.classname == "player")
516 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
518 // nullify damage if teamplay is on
519 if(deathtype != DEATH_TELEFRAG)
520 if(attacker.team == targ.team)
521 if(attacker.classname == "player")
525 else if(attacker != targ)
529 else if(teamplay == 4)
531 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
533 mirrordamage = cvar("g_mirrordamage") * damage;
534 mirrorforce = cvar("g_mirrordamage") * vlen(force);
537 if(cvar("g_friendlyfire") == 0)
541 damage = cvar("g_friendlyfire") * damage;
542 // mirrordamage will be used LATER
551 if(targ.classname == "player")
552 if(attacker.classname == "player")
555 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
556 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
562 if(targ.classname == "player")
564 attacker.hitsound += 1;
568 if ((deathtype == DEATH_FALL) ||
569 (deathtype == DEATH_DROWN) ||
570 (deathtype == DEATH_SLIME) ||
571 (deathtype == DEATH_LAVA))
573 if (targ.armorvalue && (deathtype == IT_NEX) && damage)
575 targ.armorvalue -= 1;
576 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
580 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
582 if(clienttype(attacker) == CLIENTTYPE_REAL)
583 if(IsDifferentTeam(targ, attacker))
586 if (deathtype == IT_LASER)
589 if (targ != attacker)
591 if (targ.classname == "player")
592 centerprint(attacker, "Secondary fire inflicts no damage!\n");
602 if(targ.takedamage == DAMAGE_AIM)
604 if(IsDifferentTeam(targ, attacker))
608 // apply strength multiplier
609 if (attacker.items & IT_STRENGTH && !g_minstagib)
611 damage = damage * cvar("g_balance_powerup_strength_damage");
612 force = force * cvar("g_balance_powerup_strength_force");
614 // apply invincibility multiplier
615 if (targ.items & IT_INVINCIBLE && !g_minstagib)
616 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
621 // apply strength rune
622 if (attacker.runes & RUNE_STRENGTH)
624 if(attacker.runes & CURSE_WEAK) // have both curse & rune
626 damage = damage * cvar("g_balance_rune_strength_combo_damage");
627 force = force * cvar("g_balance_rune_strength_combo_force");
631 damage = damage * cvar("g_balance_rune_strength_damage");
632 force = force * cvar("g_balance_rune_strength_force");
635 else if (attacker.runes & CURSE_WEAK)
637 damage = damage * cvar("g_balance_curse_weak_damage");
638 force = force * cvar("g_balance_curse_weak_force");
641 // apply defense rune
642 if (targ.runes & RUNE_DEFENSE)
644 if (targ.runes & CURSE_VULNER) // have both curse & rune
645 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
647 damage = damage * cvar("g_balance_rune_defense_takedamage");
649 else if (targ.runes & CURSE_VULNER)
650 damage = damage * cvar("g_balance_curse_vulner_takedamage");
655 if (self.damageforcescale)
658 self.velocity = self.velocity + self.damageforcescale * force;
659 self.flags = self.flags - (self.flags & FL_ONGROUND);
662 if (self.event_damage)
663 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
666 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
668 // Savage: vampire mode
672 if (time > self.spawnshieldtime)
674 attacker.health += damage;
678 if (attacker.runes & RUNE_VAMPIRE)
680 // apply vampire rune
681 if (attacker.runes & CURSE_EMPATHY) // have the curse too
683 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
684 attacker.health = bound(
685 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
686 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
687 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
691 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
692 attacker.health = bound(
693 attacker.health, // LA: was 3, but changed so that you can't lose health
694 // empathy won't let you gain health in the same way...
695 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
696 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
699 // apply empathy curse
700 else if (attacker.runes & CURSE_EMPATHY)
702 attacker.health = bound(
703 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
704 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
710 // apply mirror damage if any
711 if(mirrordamage > 0 || mirrorforce > 0)
713 attacker = attacker_save;
717 // just lose extra LIVES, don't kill the player for mirror damage
718 if(attacker.armorvalue > 0)
720 attacker.armorvalue = attacker.armorvalue - 1;
721 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
722 attacker.hitsound += 1;
726 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
727 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
731 vector NearestPointOnBox(entity box, vector org)
733 vector m1, m2, nearest;
735 m1 = box.mins + box.origin;
736 m2 = box.maxs + box.origin;
738 nearest_x = bound(m1_x, org_x, m2_x);
739 nearest_y = bound(m1_y, org_y, m2_y);
740 nearest_z = bound(m1_z, org_z, m2_z);
745 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
746 // Returns total damage applies to creatures
756 float total_damage_to_creatures;
758 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
759 total_damage_to_creatures = 0;
761 targ = findradius (blastorigin, rad);
764 if (targ != inflictor)
767 // LordHavoc: measure distance to nearest point on target (not origin)
768 // (this guarentees 100% damage on a touch impact)
769 nearest = NearestPointOnBox(targ, blastorigin);
770 diff = nearest - blastorigin;
771 // round up a little on the damage to ensure full damage on impacts
772 // and turn the distance into a fraction of the radius
773 power = 1 - ((vlen (diff) - 2) / rad);
775 //bprint(ftos(power));
780 finaldmg = coredamage * power + edgedamage * (1 - power);
783 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
784 // if it's a player, use the view origin as reference
785 if (targ.classname == "player")
786 center = targ.origin + targ.view_ofs;
787 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
788 if (targ == attacker)
789 finaldmg = finaldmg * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
790 // test line of sight to multiple positions on box,
791 // and do damage if any of them hit
793 c = ceil(finaldmg / 10);
799 traceline(blastorigin, nearest, TRUE, inflictor);
800 if (trace_fraction == 1 || trace_ent == targ
801 || cvar("g_throughfloor"))
804 total_damage_to_creatures += finaldmg;
805 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
808 nearest_x = targ.mins_x + random() * targ.size_x;
809 nearest_y = targ.mins_y + random() * targ.size_y;
810 nearest_z = targ.mins_z + random() * targ.size_z;
818 return total_damage_to_creatures;