2 float checkrules_firstblood;
6 float IsDifferentTeam(entity a, entity b)
21 float IsFlying(entity a)
23 if(a.flags & FL_ONGROUND)
27 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
28 if(trace_fraction < 1)
33 void UpdateFrags(entity player, float f)
35 PlayerTeamScore_AddScore(player, f);
38 void GiveFrags (entity attacker, entity targ, float f)
40 // TODO route through PlayerScores instead
48 PlayerScore_Add(attacker, SP_SUICIDES, 1);
53 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
59 PlayerScore_Add(attacker, SP_KILLS, 1);
62 PlayerScore_Add(targ, SP_DEATHS, 1);
65 if(cvar("g_arena_roundbased"))
68 // FIXME fix the mess this is (we have REAL points now!)
71 f = RunematchHandleFrags(attacker, targ, f);
75 f = kh_HandleFrags(attacker, targ, f);
81 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
82 if(tl < lms_lowest_lives)
83 lms_lowest_lives = tl;
87 lms_next_place = player_count;
88 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
95 if(g_ctf_win_mode == 3)
99 attacker.totalfrags += f;
102 UpdateFrags(attacker, f);
105 string AppendItemcodes(string s, entity player)
110 // w = player.switchweapon;
112 w = player.cnt; // previous weapon!
113 s = strcat(s, ftos(w));
114 if(time < player.strength_finished)
116 if(time < player.invincible_finished)
118 if(player.flagcarried != world)
120 if(player.BUTTON_CHAT)
125 s = strcat(s, "|", ftos(player.runes));
129 void LogDeath(string mode, float deathtype, entity killer, entity killed)
132 if(!cvar("sv_eventlog"))
134 s = strcat(":kill:", mode);
135 s = strcat(s, ":", ftos(killer.playerid));
136 s = strcat(s, ":", ftos(killed.playerid));
137 s = strcat(s, ":type=", ftos(deathtype));
138 s = strcat(s, ":items=");
139 s = AppendItemcodes(s, killer);
142 s = strcat(s, ":victimitems=");
143 s = AppendItemcodes(s, killed);
148 void Obituary (entity attacker, entity targ, float deathtype)
153 if (targ.classname == "player" || targ.classname == "corpse")
155 if (targ.classname == "corpse")
159 a = attacker.netname;
161 if (targ == attacker)
163 if (deathtype == DEATH_TEAMCHANGE) {
164 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
165 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
166 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
168 } else if (deathtype == DEATH_CAMP) {
170 centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
172 centerprint(targ, "^1Die camper!\n\n\n");
173 } else if (deathtype == DEATH_NOAMMO) {
175 centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
177 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
178 } else if (deathtype == DEATH_ROT) {
180 centerprint(targ, "^1You need to preserve your health\n\n\n");
182 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
183 } else if (deathtype == DEATH_MIRRORDAMAGE) {
185 centerprint(targ, "^1Don't go against team mates!\n\n\n");
187 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
190 centerprint(targ, "^1You need to be more careful!\n\n\n");
192 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
196 if (deathtype == DEATH_CAMP)
197 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
198 else if (deathtype == DEATH_MIRRORDAMAGE)
199 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
201 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
203 if(deathtype != DEATH_TEAMCHANGE)
205 LogDeath("suicide", deathtype, targ, targ);
206 GiveFrags(attacker, targ, -1);
208 if (targ.killcount > 2)
209 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
211 if(deathtype >= WEP_FIRST && deathtype <= WEP_LAST)
213 w_deathtypestring = "couldn't resist the urge to self-destruct";
214 weapon_action(deathtype, WR_SUICIDEMESSAGE);
215 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
217 else if (deathtype == DEATH_KILL)
218 bprint ("^1",s, "^1 couldn't take it anymore\n");
219 else if (deathtype == DEATH_ROT)
220 bprint ("^1",s, "^1 died\n");
221 else if (deathtype == DEATH_NOAMMO)
223 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
225 else if (deathtype == DEATH_CAMP)
226 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
227 else if (deathtype == DEATH_MIRRORDAMAGE)
228 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
229 else if (deathtype != DEATH_TEAMCHANGE)
230 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
232 if(deathtype != DEATH_TEAMCHANGE)
234 LogDeath("suicide", deathtype, targ, targ);
235 GiveFrags(attacker, targ, -1);
237 if (targ.killcount > 2)
238 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
241 else if (attacker.classname == "player" || attacker.classname == "gib")
243 if(teamplay && attacker.team == targ.team)
246 centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
247 bprint ("^1", a, "^1 took action against a teammate\n");
249 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
250 bprint ("^1", a, "^1 mows down a teammate\n");
252 GiveFrags(attacker, targ, -1);
253 if (targ.killcount > 2) {
255 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
257 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
259 if (attacker.killcount > 2) {
261 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
263 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
265 attacker.killcount = 0;
267 LogDeath("tk", deathtype, attacker, targ);
271 if (!checkrules_firstblood)
273 checkrules_firstblood = TRUE;
275 bprint("^1",a, "^1 was the first to score", "\n");
277 bprint("^1",a, "^1 drew first blood", "\n");
281 centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
282 centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
284 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
285 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
289 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
291 if(deathtype >= WEP_FIRST && deathtype <= WEP_LAST)
293 w_deathtypestring = "was blasted by";
294 weapon_action(deathtype, WR_KILLMESSAGE);
295 p = strstrofs(w_deathtypestring, "#", 0);
297 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
299 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
301 else if (deathtype == DEATH_TELEFRAG)
302 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
303 else if (deathtype == DEATH_DROWN)
304 bprint ("^1",s, "^1 was drowned by ", a, "\n");
305 else if (deathtype == DEATH_SLIME)
306 bprint ("^1",s, "^1 was slimed by ", a, "\n");
307 else if (deathtype == DEATH_LAVA)
308 bprint ("^1",s, "^1 was cooked by ", a, "\n");
309 else if (deathtype == DEATH_FALL)
310 bprint ("^1",s, "^1 was grounded by ", a, "\n");
311 else if (deathtype == DEATH_SHOOTING_STAR)
312 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
313 else if (deathtype == DEATH_SWAMP)
314 bprint ("^1",s, "^1 was conserved by ", a, "\n");
315 else if (deathtype == DEATH_HURTTRIGGER)
316 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
317 else if(deathtype == DEATH_TURRET)
318 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
320 bprint ("^1",s, "^1 was fragged by ", a, "\n");
322 if(g_ctf && targ.flagcarried)
324 //GiveFrags(attacker, targ, 0);
325 UpdateFrags(attacker, cvar("g_ctf_flagscore_kill"));
326 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
329 GiveFrags(attacker, targ, 1);
330 if (targ.killcount > 2) {
332 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
334 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
336 attacker.killcount = attacker.killcount + 1;
337 if (attacker.killcount > 2) {
339 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
341 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
344 LogDeath("frag", deathtype, attacker, targ);
346 if (attacker.killcount == 3)
349 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
351 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
352 announce(attacker, "announcer/male/03kills.ogg");
355 else if (attacker.killcount == 5)
358 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
360 bprint (a,"^7 unleashes ^1RAGE\n");
361 announce(attacker, "announcer/male/05kills.ogg");
364 else if (attacker.killcount == 10)
367 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
369 bprint (a,"^7 starts the ^1MASSACRE!\n");
370 announce(attacker, "announcer/male/10kills.ogg");
373 else if (attacker.killcount == 15)
376 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
378 bprint (a,"^7 executes ^1MAYHEM!\n");
379 announce(attacker, "announcer/male/15kills.ogg");
382 else if (attacker.killcount == 20)
385 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
387 bprint (a,"^7 is a ^1BERSERKER!\n");
388 announce(attacker, "announcer/male/20kills.ogg");
391 else if (attacker.killcount == 25)
394 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
396 bprint (a,"^7 inflicts ^1CARNAGE!\n");
397 announce(attacker, "announcer/male/25kills.ogg");
400 else if (attacker.killcount == 30)
403 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
405 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
406 announce(attacker, "announcer/male/30kills.ogg");
413 centerprint(targ, "^1Watch your step!\n\n\n");
414 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
415 bprint ("^1",s, "^1 ", attacker.message, "\n");
416 else if (deathtype == DEATH_DROWN)
418 bprint ("^1",s, "^1 was in the water for too long\n");
420 bprint ("^1",s, "^1 drowned\n");
421 else if (deathtype == DEATH_SLIME)
422 bprint ("^1",s, "^1 was slimed\n");
423 else if (deathtype == DEATH_LAVA)
425 bprint ("^1",s, "^1 found a hot place\n");
427 bprint ("^1",s, "^1 turned into hot slag\n");
428 else if (deathtype == DEATH_FALL)
430 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
432 bprint ("^1",s, "^1 hit the ground with a crunch\n");
433 else if (deathtype == DEATH_SHOOTING_STAR)
434 bprint ("^1",s, "^1 became a shooting star\n");
435 else if (deathtype == DEATH_SWAMP)
437 bprint ("^1",s, "^1 discovered a swamp\n");
439 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
440 else if(deathtype == DEATH_TURRET)
441 bprint ("^1",s, "^1 was mowed down by a turret \n");
444 bprint ("^1",s, "^1 needs a restart\n");
446 bprint ("^1",s, "^1 died\n");
447 GiveFrags(targ, targ, -1);
448 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
449 announce(targ, "announcer/male/botlike.ogg");
452 if (targ.killcount > 2)
454 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
456 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
458 LogDeath("accident", deathtype, targ, targ);
460 targ.death_origin = targ.origin;
462 targ.killer_origin = attacker.origin;
463 // FIXME: this should go in PutClientInServer
469 // these are updated by each Damage call for use in button triggering and such
471 entity damage_inflictor;
472 entity damage_attacker;
474 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
478 entity attacker_save;
482 if (gameover || targ.killcount == -666)
485 local entity oldself;
489 damage_inflictor = inflictor;
490 damage_attacker = attacker;
491 attacker_save = attacker;
493 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
495 // These are ALWAYS lethal
496 // No damage modification here
497 // Instead, prepare the victim for his death...
499 targ.spawnshieldtime = 0;
500 targ.health = 0.9; // this is < 1
501 targ.flags -= targ.flags & FL_GODMODE;
506 if (targ.classname == "player")
507 if (attacker.classname == "player")
510 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
512 // nullify damage if teamplay is on
513 if(deathtype != DEATH_TELEFRAG)
514 if(attacker.classname == "player")
516 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
521 else if(attacker.team == targ.team)
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))
576 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
578 targ.armorvalue -= 1;
579 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
583 else if (deathtype == WEP_MINSTANEX && targ.items & IT_STRENGTH)
585 if(clienttype(attacker) == CLIENTTYPE_REAL)
586 if(IsDifferentTeam(targ, attacker))
589 if (deathtype == WEP_LASER)
592 if (targ != attacker)
594 if (targ.classname == "player")
595 centerprint(attacker, "Secondary fire inflicts no damage!\n");
605 if(targ.takedamage == DAMAGE_AIM)
607 if(IsDifferentTeam(targ, attacker))
611 // apply strength multiplier
612 if (attacker.items & IT_STRENGTH && !g_minstagib)
616 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
617 force = force * cvar("g_balance_powerup_strength_selfforce");
621 damage = damage * cvar("g_balance_powerup_strength_damage");
622 force = force * cvar("g_balance_powerup_strength_force");
626 // apply invincibility multiplier
627 if (targ.items & IT_INVINCIBLE && !g_minstagib)
628 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
630 if (targ == attacker)
631 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
633 // CTF: reduce damage/force
638 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
639 force = force * cvar("g_ctf_flagcarrier_selfforce");
644 // apply strength rune
645 if (attacker.runes & RUNE_STRENGTH)
647 if(attacker.runes & CURSE_WEAK) // have both curse & rune
649 damage = damage * cvar("g_balance_rune_strength_combo_damage");
650 force = force * cvar("g_balance_rune_strength_combo_force");
654 damage = damage * cvar("g_balance_rune_strength_damage");
655 force = force * cvar("g_balance_rune_strength_force");
658 else if (attacker.runes & CURSE_WEAK)
660 damage = damage * cvar("g_balance_curse_weak_damage");
661 force = force * cvar("g_balance_curse_weak_force");
664 // apply defense rune
665 if (targ.runes & RUNE_DEFENSE)
667 if (targ.runes & CURSE_VULNER) // have both curse & rune
668 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
670 damage = damage * cvar("g_balance_rune_defense_takedamage");
672 else if (targ.runes & CURSE_VULNER)
673 damage = damage * cvar("g_balance_curse_vulner_takedamage");
678 if (self.damageforcescale)
681 self.velocity = self.velocity + self.damageforcescale * force;
682 self.flags = self.flags - (self.flags & FL_ONGROUND);
686 if (self.event_damage)
687 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
690 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
692 // Savage: vampire mode
695 if (time > self.spawnshieldtime)
697 attacker.health += damage;
701 if (attacker.runes & RUNE_VAMPIRE)
703 // apply vampire rune
704 if (attacker.runes & CURSE_EMPATHY) // have the curse too
706 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
707 attacker.health = bound(
708 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
709 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
710 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
714 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
715 attacker.health = bound(
716 attacker.health, // LA: was 3, but changed so that you can't lose health
717 // empathy won't let you gain health in the same way...
718 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
719 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
722 // apply empathy curse
723 else if (attacker.runes & CURSE_EMPATHY)
725 attacker.health = bound(
726 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
727 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
733 // apply mirror damage if any
734 if(mirrordamage > 0 || mirrorforce > 0)
736 attacker = attacker_save;
740 // just lose extra LIVES, don't kill the player for mirror damage
741 if(attacker.armorvalue > 0)
743 attacker.armorvalue = attacker.armorvalue - 1;
744 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
745 attacker.hitsound += 1;
749 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
750 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
754 vector NearestPointOnBox(entity box, vector org)
756 vector m1, m2, nearest;
758 m1 = box.mins + box.origin;
759 m2 = box.maxs + box.origin;
761 nearest_x = bound(m1_x, org_x, m2_x);
762 nearest_y = bound(m1_y, org_y, m2_y);
763 nearest_z = bound(m1_z, org_z, m2_z);
768 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
769 // Returns total damage applies to creatures
779 float total_damage_to_creatures;
781 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
782 total_damage_to_creatures = 0;
784 targ = findradius (blastorigin, rad);
787 if (targ != inflictor)
790 // LordHavoc: measure distance to nearest point on target (not origin)
791 // (this guarentees 100% damage on a touch impact)
792 nearest = NearestPointOnBox(targ, blastorigin);
793 diff = nearest - blastorigin;
794 // round up a little on the damage to ensure full damage on impacts
795 // and turn the distance into a fraction of the radius
796 power = 1 - ((vlen (diff) - 2) / rad);
798 //bprint(ftos(power));
803 finaldmg = coredamage * power + edgedamage * (1 - power);
806 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
807 // if it's a player, use the view origin as reference
808 if (targ.classname == "player")
809 center = targ.origin + targ.view_ofs;
810 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
811 // test line of sight to multiple positions on box,
812 // and do damage if any of them hit
814 c = ceil(finaldmg / 10);
820 traceline(blastorigin, nearest, TRUE, inflictor);
821 if (trace_fraction == 1 || trace_ent == targ
822 || cvar("g_throughfloor"))
825 total_damage_to_creatures += finaldmg;
826 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
829 nearest_x = targ.mins_x + random() * targ.size_x;
830 nearest_y = targ.mins_y + random() * targ.size_y;
831 nearest_z = targ.mins_z + random() * targ.size_z;
839 return total_damage_to_creatures;