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 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
39 void GiveFrags (entity attacker, entity targ, float f)
41 // TODO route through PlayerScores instead
49 PlayerScore_Add(attacker, SP_SUICIDES, 1);
54 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
60 PlayerScore_Add(attacker, SP_KILLS, 1);
63 PlayerScore_Add(targ, SP_DEATHS, 1);
66 if(cvar("g_arena_roundbased"))
69 // FIXME fix the mess this is (we have REAL points now!)
72 f = RunematchHandleFrags(attacker, targ, f);
76 f = kh_HandleFrags(attacker, targ, f);
82 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
83 if(tl < lms_lowest_lives)
84 lms_lowest_lives = tl;
88 lms_next_place = player_count;
89 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
96 if(g_ctf_win_mode == 3)
100 attacker.totalfrags += f;
103 UpdateFrags(attacker, f);
106 string AppendItemcodes(string s, entity player)
111 // w = player.switchweapon;
113 w = player.cnt; // previous weapon!
114 s = strcat(s, ftos(w));
115 if(time < player.strength_finished)
117 if(time < player.invincible_finished)
119 if(player.flagcarried != world)
121 if(player.BUTTON_CHAT)
126 s = strcat(s, "|", ftos(player.runes));
130 void LogDeath(string mode, float deathtype, entity killer, entity killed)
133 if(!cvar("sv_eventlog"))
135 s = strcat(":kill:", mode);
136 s = strcat(s, ":", ftos(killer.playerid));
137 s = strcat(s, ":", ftos(killed.playerid));
138 s = strcat(s, ":type=", ftos(deathtype));
139 s = strcat(s, ":items=");
140 s = AppendItemcodes(s, killer);
143 s = strcat(s, ":victimitems=");
144 s = AppendItemcodes(s, killed);
149 void Obituary (entity attacker, entity targ, float deathtype)
154 if (targ.classname == "player" || targ.classname == "corpse")
156 if (targ.classname == "corpse")
160 a = attacker.netname;
162 if (targ == attacker)
164 if (deathtype == DEATH_TEAMCHANGE) {
165 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
166 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
167 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
169 } else if (deathtype == DEATH_CAMP) {
171 centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
173 centerprint(targ, "^1Die camper!\n\n\n");
174 } else if (deathtype == DEATH_NOAMMO) {
176 centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
178 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
179 } else if (deathtype == DEATH_ROT) {
181 centerprint(targ, "^1You need to preserve your health\n\n\n");
183 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
184 } else if (deathtype == DEATH_MIRRORDAMAGE) {
186 centerprint(targ, "^1Don't go against team mates!\n\n\n");
188 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
191 centerprint(targ, "^1You need to be more careful!\n\n\n");
193 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
197 if (deathtype == DEATH_CAMP)
198 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
199 else if (deathtype == DEATH_MIRRORDAMAGE)
200 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
202 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
204 if(deathtype != DEATH_TEAMCHANGE)
206 LogDeath("suicide", deathtype, targ, targ);
207 GiveFrags(attacker, targ, -1);
209 if (targ.killcount > 2)
210 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
212 if(deathtype < DEATH_SPECIAL_START && deathtype & DEATH_WEAPONMASK >= WEP_FIRST && deathtype & DEATH_WEAPONMASK <= WEP_LAST)
214 w_deathtypestring = "couldn't resist the urge to self-destruct";
215 w_deathtype = deathtype;
216 weapon_action(deathtype & DEATH_WEAPONMASK, WR_SUICIDEMESSAGE);
217 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
219 else if (deathtype == DEATH_KILL)
220 bprint ("^1",s, "^1 couldn't take it anymore\n");
221 else if (deathtype == DEATH_ROT)
222 bprint ("^1",s, "^1 died\n");
223 else if (deathtype == DEATH_NOAMMO)
225 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
227 else if (deathtype == DEATH_CAMP)
228 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
229 else if (deathtype == DEATH_MIRRORDAMAGE)
230 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
231 else if (deathtype != DEATH_TEAMCHANGE)
232 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
234 if(deathtype != DEATH_TEAMCHANGE)
236 LogDeath("suicide", deathtype, targ, targ);
237 GiveFrags(attacker, targ, -1);
239 if (targ.killcount > 2)
240 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
243 else if (attacker.classname == "player" || attacker.classname == "gib")
245 if(teamplay && attacker.team == targ.team)
248 centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
249 bprint ("^1", a, "^1 took action against a teammate\n");
251 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
252 bprint ("^1", a, "^1 mows down a teammate\n");
254 GiveFrags(attacker, targ, -1);
255 if (targ.killcount > 2) {
257 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
259 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
261 if (attacker.killcount > 2) {
263 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
265 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
267 attacker.killcount = 0;
269 LogDeath("tk", deathtype, attacker, targ);
273 if (!checkrules_firstblood)
275 checkrules_firstblood = TRUE;
277 bprint("^1",a, "^1 was the first to score", "\n");
279 bprint("^1",a, "^1 drew first blood", "\n");
283 centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
284 centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
286 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
287 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
291 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
293 if(deathtype < DEATH_SPECIAL_START && deathtype & DEATH_WEAPONMASK >= WEP_FIRST && deathtype & DEATH_WEAPONMASK <= WEP_LAST)
295 w_deathtypestring = "was blasted by";
296 w_deathtype = deathtype;
297 weapon_action(deathtype & DEATH_WEAPONMASK, WR_KILLMESSAGE);
298 p = strstrofs(w_deathtypestring, "#", 0);
300 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
302 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\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)
327 //GiveFrags(attacker, targ, cvar("g_ctf_flagscore_kill"));
328 UpdateFrags(attacker, cvar("g_ctf_flagscore_kill"));
329 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
330 GiveFrags(attacker, targ, 0);
333 GiveFrags(attacker, targ, 1);
334 if (targ.killcount > 2) {
336 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
338 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
340 attacker.killcount = attacker.killcount + 1;
341 if (attacker.killcount > 2) {
343 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
345 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
348 LogDeath("frag", deathtype, attacker, targ);
350 if (attacker.killcount == 3)
353 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
355 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
356 announce(attacker, "announcer/male/03kills.ogg");
359 else if (attacker.killcount == 5)
362 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
364 bprint (a,"^7 unleashes ^1RAGE\n");
365 announce(attacker, "announcer/male/05kills.ogg");
368 else if (attacker.killcount == 10)
371 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
373 bprint (a,"^7 starts the ^1MASSACRE!\n");
374 announce(attacker, "announcer/male/10kills.ogg");
377 else if (attacker.killcount == 15)
380 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
382 bprint (a,"^7 executes ^1MAYHEM!\n");
383 announce(attacker, "announcer/male/15kills.ogg");
386 else if (attacker.killcount == 20)
389 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
391 bprint (a,"^7 is a ^1BERSERKER!\n");
392 announce(attacker, "announcer/male/20kills.ogg");
395 else if (attacker.killcount == 25)
398 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
400 bprint (a,"^7 inflicts ^1CARNAGE!\n");
401 announce(attacker, "announcer/male/25kills.ogg");
404 else if (attacker.killcount == 30)
407 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
409 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
410 announce(attacker, "announcer/male/30kills.ogg");
417 centerprint(targ, "^1Watch your step!\n\n\n");
418 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
419 bprint ("^1",s, "^1 ", attacker.message, "\n");
420 else if (deathtype == DEATH_DROWN)
422 bprint ("^1",s, "^1 was in the water for too long\n");
424 bprint ("^1",s, "^1 drowned\n");
425 else if (deathtype == DEATH_SLIME)
426 bprint ("^1",s, "^1 was slimed\n");
427 else if (deathtype == DEATH_LAVA)
429 bprint ("^1",s, "^1 found a hot place\n");
431 bprint ("^1",s, "^1 turned into hot slag\n");
432 else if (deathtype == DEATH_FALL)
434 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
436 bprint ("^1",s, "^1 hit the ground with a crunch\n");
437 else if (deathtype == DEATH_SHOOTING_STAR)
438 bprint ("^1",s, "^1 became a shooting star\n");
439 else if (deathtype == DEATH_SWAMP)
441 bprint ("^1",s, "^1 discovered a swamp\n");
443 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
444 else if(deathtype == DEATH_TURRET)
445 bprint ("^1",s, "^1 was mowed down by a turret \n");
448 bprint ("^1",s, "^1 needs a restart\n");
450 bprint ("^1",s, "^1 died\n");
451 GiveFrags(targ, targ, -1);
452 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
453 announce(targ, "announcer/male/botlike.ogg");
456 if (targ.killcount > 2)
458 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
460 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
462 LogDeath("accident", deathtype, targ, targ);
464 targ.death_origin = targ.origin;
466 targ.killer_origin = attacker.origin;
467 // FIXME: this should go in PutClientInServer
473 // these are updated by each Damage call for use in button triggering and such
475 entity damage_inflictor;
476 entity damage_attacker;
478 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
482 entity attacker_save;
486 if (gameover || targ.killcount == -666)
489 local entity oldself;
493 damage_inflictor = inflictor;
494 damage_attacker = attacker;
495 attacker_save = attacker;
497 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
499 // These are ALWAYS lethal
500 // No damage modification here
501 // Instead, prepare the victim for his death...
503 targ.spawnshieldtime = 0;
504 targ.health = 0.9; // this is < 1
505 targ.flags -= targ.flags & FL_GODMODE;
508 else if(deathtype == DEATH_MIRRORDAMAGE)
514 if (targ.classname == "player")
515 if (attacker.classname == "player")
518 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
520 // nullify damage if teamplay is on
521 if(deathtype != DEATH_TELEFRAG)
522 if(attacker.classname == "player")
524 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
529 else if(attacker.team == targ.team)
533 else if(attacker != targ)
537 else if(teamplay == 4)
539 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
541 mirrordamage = cvar("g_mirrordamage") * damage;
542 mirrorforce = cvar("g_mirrordamage") * vlen(force);
545 if(cvar("g_friendlyfire") == 0)
549 damage = cvar("g_friendlyfire") * damage;
550 // mirrordamage will be used LATER
559 if(targ.classname == "player")
560 if(attacker.classname == "player")
563 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
564 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
570 if(targ.classname == "player")
572 attacker.hitsound += 1;
576 if ((deathtype == DEATH_FALL) ||
577 (deathtype == DEATH_DROWN) ||
578 (deathtype == DEATH_SLIME) ||
579 (deathtype == DEATH_LAVA))
584 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
586 targ.armorvalue -= 1;
587 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
591 else if (deathtype == WEP_MINSTANEX && targ.items & IT_STRENGTH)
593 if(clienttype(attacker) == CLIENTTYPE_REAL)
594 if(IsDifferentTeam(targ, attacker))
597 if (deathtype == WEP_LASER)
600 if (targ != attacker)
602 if (targ.classname == "player")
603 centerprint(attacker, "Secondary fire inflicts no damage!\n");
613 if(targ.takedamage == DAMAGE_AIM)
615 if(IsDifferentTeam(targ, attacker))
619 // apply strength multiplier
620 if (attacker.items & IT_STRENGTH && !g_minstagib)
624 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
625 force = force * cvar("g_balance_powerup_strength_selfforce");
629 damage = damage * cvar("g_balance_powerup_strength_damage");
630 force = force * cvar("g_balance_powerup_strength_force");
634 // apply invincibility multiplier
635 if (targ.items & IT_INVINCIBLE && !g_minstagib)
636 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
638 if (targ == attacker)
639 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
641 // CTF: reduce damage/force
646 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
647 force = force * cvar("g_ctf_flagcarrier_selfforce");
652 // apply strength rune
653 if (attacker.runes & RUNE_STRENGTH)
655 if(attacker.runes & CURSE_WEAK) // have both curse & rune
657 damage = damage * cvar("g_balance_rune_strength_combo_damage");
658 force = force * cvar("g_balance_rune_strength_combo_force");
662 damage = damage * cvar("g_balance_rune_strength_damage");
663 force = force * cvar("g_balance_rune_strength_force");
666 else if (attacker.runes & CURSE_WEAK)
668 damage = damage * cvar("g_balance_curse_weak_damage");
669 force = force * cvar("g_balance_curse_weak_force");
672 // apply defense rune
673 if (targ.runes & RUNE_DEFENSE)
675 if (targ.runes & CURSE_VULNER) // have both curse & rune
676 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
678 damage = damage * cvar("g_balance_rune_defense_takedamage");
680 else if (targ.runes & CURSE_VULNER)
681 damage = damage * cvar("g_balance_curse_vulner_takedamage");
686 if (self.damageforcescale)
689 self.velocity = self.velocity + self.damageforcescale * force;
690 self.flags = self.flags - (self.flags & FL_ONGROUND);
694 if (self.event_damage)
695 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
698 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
700 // Savage: vampire mode
703 if (time > self.spawnshieldtime)
705 attacker.health += damage;
709 if (attacker.runes & RUNE_VAMPIRE)
711 // apply vampire rune
712 if (attacker.runes & CURSE_EMPATHY) // have the curse too
714 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
715 attacker.health = bound(
716 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
717 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
718 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
722 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
723 attacker.health = bound(
724 attacker.health, // LA: was 3, but changed so that you can't lose health
725 // empathy won't let you gain health in the same way...
726 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
727 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
730 // apply empathy curse
731 else if (attacker.runes & CURSE_EMPATHY)
733 attacker.health = bound(
734 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
735 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
741 // apply mirror damage if any
742 if(mirrordamage > 0 || mirrorforce > 0)
744 attacker = attacker_save;
748 // just lose extra LIVES, don't kill the player for mirror damage
749 if(attacker.armorvalue > 0)
751 attacker.armorvalue = attacker.armorvalue - 1;
752 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
753 attacker.hitsound += 1;
757 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
758 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
762 vector NearestPointOnBox(entity box, vector org)
764 vector m1, m2, nearest;
766 m1 = box.mins + box.origin;
767 m2 = box.maxs + box.origin;
769 nearest_x = bound(m1_x, org_x, m2_x);
770 nearest_y = bound(m1_y, org_y, m2_y);
771 nearest_z = bound(m1_z, org_z, m2_z);
776 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
777 // Returns total damage applies to creatures
787 float total_damage_to_creatures;
789 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
790 total_damage_to_creatures = 0;
792 targ = findradius (blastorigin, rad);
795 if (targ != inflictor)
798 // LordHavoc: measure distance to nearest point on target (not origin)
799 // (this guarentees 100% damage on a touch impact)
800 nearest = NearestPointOnBox(targ, blastorigin);
801 diff = nearest - blastorigin;
802 // round up a little on the damage to ensure full damage on impacts
803 // and turn the distance into a fraction of the radius
804 power = 1 - ((vlen (diff) - 2) / rad);
806 //bprint(ftos(power));
811 finaldmg = coredamage * power + edgedamage * (1 - power);
814 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
815 // if it's a player, use the view origin as reference
816 if (targ.classname == "player")
817 center = targ.origin + targ.view_ofs;
818 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
819 // test line of sight to multiple positions on box,
820 // and do damage if any of them hit
822 c = ceil(finaldmg / 10);
828 traceline(blastorigin, nearest, TRUE, inflictor);
829 if (trace_fraction == 1 || trace_ent == targ
830 || cvar("g_throughfloor"))
833 total_damage_to_creatures += finaldmg;
834 if(targ == directhitentity)
835 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
837 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
840 nearest_x = targ.mins_x + random() * targ.size_x;
841 nearest_y = targ.mins_y + random() * targ.size_y;
842 nearest_z = targ.mins_z + random() * targ.size_z;
850 return total_damage_to_creatures;