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 PlayerTeamScore_AddScore(player, f);
48 void GiveFrags (entity attacker, entity targ, float f)
50 // TODO route through PlayerScores instead
54 if(cvar("g_arena_roundbased"))
62 PlayerScore_Add(attacker, SP_SUICIDES, 1);
67 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
73 PlayerScore_Add(attacker, SP_KILLS, 1);
76 PlayerScore_Add(targ, SP_DEATHS, 1);
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
104 attacker.totalfrags += f;
107 UpdateFrags(attacker, f);
110 string AppendItemcodes(string s, entity player)
115 // w = player.switchweapon;
117 w = player.cnt; // previous weapon!
118 s = strcat(s, ftos(W_ItemCode(w)));
119 if(time < player.strength_finished)
121 if(time < player.invincible_finished)
123 if(player.flagcarried != world)
125 if(player.BUTTON_CHAT)
130 s = strcat(s, "|", ftos(player.runes));
134 void LogDeath(string mode, float deathtype, entity killer, entity killed)
137 if(!cvar("sv_eventlog"))
139 s = strcat(":kill:", mode);
140 s = strcat(s, ":", ftos(killer.playerid));
141 s = strcat(s, ":", ftos(killed.playerid));
142 s = strcat(s, ":type=", ftos(deathtype));
143 s = strcat(s, ":items=");
144 s = AppendItemcodes(s, killer);
147 s = strcat(s, ":victimitems=");
148 s = AppendItemcodes(s, killed);
150 GameLogEcho(s, FALSE);
153 void Obituary (entity attacker, entity targ, float deathtype)
157 if (targ.classname == "player" || targ.classname == "corpse")
159 if (targ.classname == "corpse")
163 a = attacker.netname;
165 if (targ == attacker)
167 if (deathtype == DEATH_TEAMCHANGE) {
168 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
169 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
170 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
172 } else if (deathtype == DEATH_CAMP) {
174 centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
176 centerprint(targ, "^1Die camper!\n\n\n");
177 } else if (deathtype == DEATH_NOAMMO) {
179 centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
181 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
182 } else if (deathtype == DEATH_ROT) {
184 centerprint(targ, "^1You need to preserve your health\n\n\n");
186 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
187 } else if (deathtype == DEATH_MIRRORDAMAGE) {
189 centerprint(targ, "^1Don't go against team mates!\n\n\n");
191 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
194 centerprint(targ, "^1You need to be more careful!\n\n\n");
196 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
200 if (deathtype == DEATH_CAMP)
201 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
202 else if (deathtype == DEATH_MIRRORDAMAGE)
203 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
205 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
207 if(deathtype != DEATH_TEAMCHANGE)
209 LogDeath("suicide", deathtype, targ, targ);
210 GiveFrags(attacker, targ, -1);
212 if (targ.killcount > 2)
213 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
216 if (deathtype == IT_GRENADE_LAUNCHER)
217 bprint ("^1",s, "^1 detonated\n");
218 else if (deathtype == IT_ELECTRO)
219 bprint ("^1",s, "^1 played with plasma\n");
220 else if (deathtype == IT_ROCKET_LAUNCHER)
221 bprint ("^1",s, "^1 exploded\n");
222 else if (deathtype == DEATH_KILL)
223 bprint ("^1",s, "^1 couldn't take it anymore\n");
224 else if (deathtype == DEATH_ROT)
225 bprint ("^1",s, "^1 died\n");
226 else if (deathtype == DEATH_NOAMMO)
228 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
229 //sound (self, CHAN_BODY, "minstagib/mockery.wav", 1, ATTN_NONE);
231 else if (deathtype == DEATH_CAMP)
232 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
233 else if (deathtype == DEATH_MIRRORDAMAGE)
234 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
235 else if (deathtype != DEATH_TEAMCHANGE)
236 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
238 if(deathtype != DEATH_TEAMCHANGE)
240 LogDeath("suicide", deathtype, targ, targ);
241 GiveFrags(attacker, targ, -1);
243 if (targ.killcount > 2)
244 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
247 else if (attacker.classname == "player" || attacker.classname == "gib")
249 if(teamplay && attacker.team == targ.team)
252 centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
253 bprint ("^1", a, "^1 took action against a teammate\n");
255 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
256 bprint ("^1", a, "^1 mows down a teammate\n");
258 GiveFrags(attacker, targ, -1);
259 if (targ.killcount > 2) {
261 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
263 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
265 if (attacker.killcount > 2) {
267 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
269 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
271 attacker.killcount = 0;
273 LogDeath("tk", deathtype, attacker, targ);
277 if (!checkrules_firstblood)
279 checkrules_firstblood = TRUE;
280 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
282 //sound(world, CHAN_AUTO, "announce/male/mapkill1.wav", 1, ATTN_NONE);
284 bprint("^1",a, "^1 was the first to score", "\n");
286 bprint("^1",a, "^1 drew first blood", "\n");
290 centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
291 centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
293 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
294 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
298 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
300 if (deathtype == IT_LASER)
301 bprint ("^1",s, "^1 was blasted by ", a, "\n");
302 else if (deathtype == IT_UZI)
303 bprint ("^1",s, "^1 was riddled full of holes by ", a, "\n");
304 else if (deathtype == IT_SHOTGUN)
305 bprint ("^1",s, "^1 was gunned by ", a, "\n");
306 else if (deathtype == IT_GRENADE_LAUNCHER)
307 bprint ("^1", s, "^1 was blasted by ", a, "\n");
308 else if (deathtype == IT_ELECTRO)
309 bprint ("^1",s, "^1 was blasted by ", a, "\n");
310 else if (deathtype == IT_CRYLINK)
311 bprint ("^1",s, "^1 was blasted by ", a, "\n");
312 else if (deathtype == IT_NEX)
313 bprint ("^1",s, "^1 has been vaporized by ", a, "\n");
314 else if (deathtype == IT_HAGAR)
315 bprint ("^1",s, "^1 was pummeled by ", a, "\n");
316 else if (deathtype == IT_ROCKET_LAUNCHER)
317 bprint ("^1",s, "^1 was blasted by ", a, "\n");
318 else if (deathtype == DEATH_TELEFRAG)
319 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
320 else if (deathtype == DEATH_DROWN)
321 bprint ("^1",s, "^1 was drowned by ", a, "\n");
322 else if (deathtype == DEATH_SLIME)
323 bprint ("^1",s, "^1 was slimed by ", a, "\n");
324 else if (deathtype == DEATH_LAVA)
325 bprint ("^1",s, "^1 was cooked by ", a, "\n");
326 else if (deathtype == DEATH_FALL)
327 bprint ("^1",s, "^1 was grounded by ", a, "\n");
328 else if (deathtype == DEATH_SHOOTING_STAR)
329 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
330 else if (deathtype == DEATH_SWAMP)
331 bprint ("^1",s, "^1 was conserved by ", a, "\n");
332 else if (deathtype == DEATH_HURTTRIGGER)
333 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
334 else if(deathtype == DEATH_TURRET)
335 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
337 bprint ("^1",s, "^1 was fragged by ", a, "\n");
339 if(g_ctf && targ.flagcarried)
341 GiveFrags(attacker, targ, cvar("g_ctf_flagscore_kill"));
342 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
345 GiveFrags(attacker, targ, 1);
346 if (targ.killcount > 2) {
348 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
350 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
352 attacker.killcount = attacker.killcount + 1;
353 if (attacker.killcount > 2) {
355 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
357 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
360 LogDeath("frag", deathtype, attacker, targ);
362 if (attacker.killcount == 3)
365 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
367 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
368 announce(attacker, "announcer/male/03kills.ogg");
371 else if (attacker.killcount == 5)
374 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
376 bprint (a,"^7 unleashes ^1RAGE\n");
377 announce(attacker, "announcer/male/05kills.ogg");
380 else if (attacker.killcount == 10)
383 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
385 bprint (a,"^7 starts the ^1MASSACRE!\n");
386 announce(attacker, "announcer/male/10kills.ogg");
389 else if (attacker.killcount == 15)
392 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
394 bprint (a,"^7 executes ^1MAYHEM!\n");
395 announce(attacker, "announcer/male/15kills.ogg");
398 else if (attacker.killcount == 20)
401 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
403 bprint (a,"^7 is a ^1BERSERKER!\n");
404 announce(attacker, "announcer/male/20kills.ogg");
407 else if (attacker.killcount == 25)
410 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
412 bprint (a,"^7 inflicts ^1CARNAGE!\n");
413 announce(attacker, "announcer/male/25kills.ogg");
416 else if (attacker.killcount == 30)
419 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
421 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
422 announce(attacker, "announcer/male/30kills.ogg");
429 centerprint(targ, "^1Watch your step!\n\n\n");
430 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
431 bprint ("^1",s, "^1 ", attacker.message, "\n");
432 else if (deathtype == DEATH_DROWN)
434 bprint ("^1",s, "^1 was in the water for too long\n");
436 bprint ("^1",s, "^1 drowned\n");
437 else if (deathtype == DEATH_SLIME)
438 bprint ("^1",s, "^1 was slimed\n");
439 else if (deathtype == DEATH_LAVA)
441 bprint ("^1",s, "^1 found a hot place\n");
443 bprint ("^1",s, "^1 turned into hot slag\n");
444 else if (deathtype == DEATH_FALL)
446 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
448 bprint ("^1",s, "^1 hit the ground with a crunch\n");
449 else if (deathtype == DEATH_SHOOTING_STAR)
450 bprint ("^1",s, "^1 became a shooting star\n");
451 else if (deathtype == DEATH_SWAMP)
453 bprint ("^1",s, "^1 discovered a swamp\n");
455 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
456 else if(deathtype == DEATH_TURRET)
457 bprint ("^1",s, "^1 was mowed down by a turret \n");
460 bprint ("^1",s, "^1 needs a restart\n");
462 bprint ("^1",s, "^1 died\n");
463 GiveFrags(targ, targ, -1);
464 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
465 announce(targ, "announcer/male/botlike.ogg");
468 if (targ.killcount > 2)
470 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
472 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
474 LogDeath("accident", deathtype, targ, targ);
476 targ.death_origin = targ.origin;
478 targ.killer_origin = attacker.origin;
479 // FIXME: this should go in PutClientInServer
485 // these are updated by each Damage call for use in button triggering and such
487 entity damage_inflictor;
488 entity damage_attacker;
490 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
494 entity attacker_save;
498 if (gameover || targ.killcount == -666)
501 local entity oldself;
505 damage_inflictor = inflictor;
506 damage_attacker = attacker;
507 attacker_save = attacker;
509 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
511 // These are ALWAYS lethal
512 // No damage modification here
513 // Instead, prepare the victim for his death...
515 targ.spawnshieldtime = 0;
516 targ.health = 0.9; // this is < 1
517 targ.flags -= targ.flags & FL_GODMODE;
522 if (targ.classname == "player")
523 if (attacker.classname == "player")
526 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
528 // nullify damage if teamplay is on
529 if(deathtype != DEATH_TELEFRAG)
530 if(attacker.team == targ.team)
531 if(attacker.classname == "player")
535 else if(attacker != targ)
539 else if(teamplay == 4)
541 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
543 mirrordamage = cvar("g_mirrordamage") * damage;
544 mirrorforce = cvar("g_mirrordamage") * vlen(force);
547 if(cvar("g_friendlyfire") == 0)
551 damage = cvar("g_friendlyfire") * damage;
552 // mirrordamage will be used LATER
561 if(targ.classname == "player")
562 if(attacker.classname == "player")
565 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
566 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
572 if(targ.classname == "player")
574 attacker.hitsound += 1;
578 if ((deathtype == DEATH_FALL) ||
579 (deathtype == DEATH_DROWN) ||
580 (deathtype == DEATH_SLIME) ||
581 (deathtype == DEATH_LAVA))
583 if (targ.armorvalue && (deathtype == IT_NEX) && damage)
585 targ.armorvalue -= 1;
586 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
590 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
592 if(clienttype(attacker) == CLIENTTYPE_REAL)
593 if(IsDifferentTeam(targ, attacker))
596 if (deathtype == IT_LASER)
599 if (targ != attacker)
601 if (targ.classname == "player")
602 centerprint(attacker, "Secondary fire inflicts no damage!\n");
612 if(targ.takedamage == DAMAGE_AIM)
614 if(IsDifferentTeam(targ, attacker))
618 // apply strength multiplier
619 if (attacker.items & IT_STRENGTH && !g_minstagib)
621 damage = damage * cvar("g_balance_powerup_strength_damage");
622 force = force * cvar("g_balance_powerup_strength_force");
624 // apply invincibility multiplier
625 if (targ.items & IT_INVINCIBLE && !g_minstagib)
626 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
631 // apply strength rune
632 if (attacker.runes & RUNE_STRENGTH)
634 if(attacker.runes & CURSE_WEAK) // have both curse & rune
636 damage = damage * cvar("g_balance_rune_strength_combo_damage");
637 force = force * cvar("g_balance_rune_strength_combo_force");
641 damage = damage * cvar("g_balance_rune_strength_damage");
642 force = force * cvar("g_balance_rune_strength_force");
645 else if (attacker.runes & CURSE_WEAK)
647 damage = damage * cvar("g_balance_curse_weak_damage");
648 force = force * cvar("g_balance_curse_weak_force");
651 // apply defense rune
652 if (targ.runes & RUNE_DEFENSE)
654 if (targ.runes & CURSE_VULNER) // have both curse & rune
655 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
657 damage = damage * cvar("g_balance_rune_defense_takedamage");
659 else if (targ.runes & CURSE_VULNER)
660 damage = damage * cvar("g_balance_curse_vulner_takedamage");
665 if (self.damageforcescale)
668 self.velocity = self.velocity + self.damageforcescale * force;
669 self.flags = self.flags - (self.flags & FL_ONGROUND);
672 if (self.event_damage)
673 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
676 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
678 // Savage: vampire mode
682 if (time > self.spawnshieldtime)
684 attacker.health += damage;
688 if (attacker.runes & RUNE_VAMPIRE)
690 // apply vampire rune
691 if (attacker.runes & CURSE_EMPATHY) // have the curse too
693 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
694 attacker.health = bound(
695 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
696 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
697 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
701 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
702 attacker.health = bound(
703 attacker.health, // LA: was 3, but changed so that you can't lose health
704 // empathy won't let you gain health in the same way...
705 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
706 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
709 // apply empathy curse
710 else if (attacker.runes & CURSE_EMPATHY)
712 attacker.health = bound(
713 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
714 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
720 // apply mirror damage if any
721 if(mirrordamage > 0 || mirrorforce > 0)
723 attacker = attacker_save;
727 // just lose extra LIVES, don't kill the player for mirror damage
728 if(attacker.armorvalue > 0)
730 attacker.armorvalue = attacker.armorvalue - 1;
731 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
732 attacker.hitsound += 1;
736 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
737 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
741 vector NearestPointOnBox(entity box, vector org)
743 vector m1, m2, nearest;
745 m1 = box.mins + box.origin;
746 m2 = box.maxs + box.origin;
748 nearest_x = bound(m1_x, org_x, m2_x);
749 nearest_y = bound(m1_y, org_y, m2_y);
750 nearest_z = bound(m1_z, org_z, m2_z);
755 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
756 // Returns total damage applies to creatures
766 float total_damage_to_creatures;
768 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
769 total_damage_to_creatures = 0;
771 targ = findradius (blastorigin, rad);
774 if (targ != inflictor)
777 // LordHavoc: measure distance to nearest point on target (not origin)
778 // (this guarentees 100% damage on a touch impact)
779 nearest = NearestPointOnBox(targ, blastorigin);
780 diff = nearest - blastorigin;
781 // round up a little on the damage to ensure full damage on impacts
782 // and turn the distance into a fraction of the radius
783 power = 1 - ((vlen (diff) - 2) / rad);
785 //bprint(ftos(power));
790 finaldmg = coredamage * power + edgedamage * (1 - power);
793 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
794 // if it's a player, use the view origin as reference
795 if (targ.classname == "player")
796 center = targ.origin + targ.view_ofs;
797 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
798 if (targ == attacker)
799 finaldmg = finaldmg * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
800 // test line of sight to multiple positions on box,
801 // and do damage if any of them hit
803 c = ceil(finaldmg / 10);
809 traceline(blastorigin, nearest, TRUE, inflictor);
810 if (trace_fraction == 1 || trace_ent == targ
811 || cvar("g_throughfloor"))
814 total_damage_to_creatures += finaldmg;
815 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
818 nearest_x = targ.mins_x + random() * targ.size_x;
819 nearest_y = targ.mins_y + random() * targ.size_y;
820 nearest_z = targ.mins_z + random() * targ.size_z;
828 return total_damage_to_creatures;