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
94 attacker.totalfrags += f;
97 UpdateFrags(attacker, f);
100 string AppendItemcodes(string s, entity player)
105 // w = player.switchweapon;
107 w = player.cnt; // previous weapon!
108 s = strcat(s, ftos(w));
109 if(time < player.strength_finished)
111 if(time < player.invincible_finished)
113 if(player.flagcarried != world)
115 if(player.BUTTON_CHAT)
120 s = strcat(s, "|", ftos(player.runes));
124 void LogDeath(string mode, float deathtype, entity killer, entity killed)
127 if(!cvar("sv_eventlog"))
129 s = strcat(":kill:", mode);
130 s = strcat(s, ":", ftos(killer.playerid));
131 s = strcat(s, ":", ftos(killed.playerid));
132 s = strcat(s, ":type=", ftos(deathtype));
133 s = strcat(s, ":items=");
134 s = AppendItemcodes(s, killer);
137 s = strcat(s, ":victimitems=");
138 s = AppendItemcodes(s, killed);
143 void Obituary (entity attacker, entity targ, float deathtype)
147 if (targ.classname == "player" || targ.classname == "corpse")
149 if (targ.classname == "corpse")
153 a = attacker.netname;
155 if (targ == attacker)
157 if (deathtype == DEATH_TEAMCHANGE) {
158 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
159 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
160 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
162 } else if (deathtype == DEATH_CAMP) {
164 centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
166 centerprint(targ, "^1Die camper!\n\n\n");
167 } else if (deathtype == DEATH_NOAMMO) {
169 centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
171 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
172 } else if (deathtype == DEATH_ROT) {
174 centerprint(targ, "^1You need to preserve your health\n\n\n");
176 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
177 } else if (deathtype == DEATH_MIRRORDAMAGE) {
179 centerprint(targ, "^1Don't go against team mates!\n\n\n");
181 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
184 centerprint(targ, "^1You need to be more careful!\n\n\n");
186 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
190 if (deathtype == DEATH_CAMP)
191 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
192 else if (deathtype == DEATH_MIRRORDAMAGE)
193 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
195 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
197 if(deathtype != DEATH_TEAMCHANGE)
199 LogDeath("suicide", deathtype, targ, targ);
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 == WEP_GRENADE_LAUNCHER)
207 bprint ("^1",s, "^1 detonated\n");
208 else if (deathtype == WEP_ELECTRO)
209 bprint ("^1",s, "^1 played with plasma\n");
210 else if (deathtype == WEP_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");
220 else if (deathtype == DEATH_CAMP)
221 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
222 else if (deathtype == DEATH_MIRRORDAMAGE)
223 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
224 else if (deathtype != DEATH_TEAMCHANGE)
225 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
227 if(deathtype != DEATH_TEAMCHANGE)
229 LogDeath("suicide", deathtype, targ, targ);
230 GiveFrags(attacker, targ, -1);
232 if (targ.killcount > 2)
233 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
236 else if (attacker.classname == "player" || attacker.classname == "gib")
238 if(teamplay && attacker.team == targ.team)
241 centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
242 bprint ("^1", a, "^1 took action against a teammate\n");
244 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
245 bprint ("^1", a, "^1 mows down a teammate\n");
247 GiveFrags(attacker, targ, -1);
248 if (targ.killcount > 2) {
250 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
252 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
254 if (attacker.killcount > 2) {
256 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
258 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
260 attacker.killcount = 0;
262 LogDeath("tk", deathtype, attacker, targ);
266 if (!checkrules_firstblood)
268 checkrules_firstblood = TRUE;
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");
287 if (deathtype == WEP_LASER)
288 bprint ("^1",s, "^1 was blasted by ", a, "\n");
289 else if (deathtype == WEP_UZI)
290 bprint ("^1",s, "^1 was riddled full of holes by ", a, "\n");
291 else if (deathtype == WEP_SHOTGUN)
292 bprint ("^1",s, "^1 was gunned by ", a, "\n");
293 else if (deathtype == WEP_GRENADE_LAUNCHER)
294 bprint ("^1", s, "^1 was blasted by ", a, "\n");
295 else if (deathtype == WEP_ELECTRO)
296 bprint ("^1",s, "^1 was blasted by ", a, "\n");
297 else if (deathtype == WEP_CRYLINK)
298 bprint ("^1",s, "^1 was blasted by ", a, "\n");
299 else if (deathtype == WEP_NEX)
300 bprint ("^1",s, "^1 has been vaporized by ", a, "\n");
301 else if (deathtype == WEP_HAGAR)
302 bprint ("^1",s, "^1 was pummeled by ", a, "\n");
303 else if (deathtype == WEP_ROCKET_LAUNCHER)
304 bprint ("^1",s, "^1 was blasted by ", a, "\n");
305 else if (deathtype == DEATH_TELEFRAG)
306 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
307 else if (deathtype == DEATH_DROWN)
308 bprint ("^1",s, "^1 was drowned by ", a, "\n");
309 else if (deathtype == DEATH_SLIME)
310 bprint ("^1",s, "^1 was slimed by ", a, "\n");
311 else if (deathtype == DEATH_LAVA)
312 bprint ("^1",s, "^1 was cooked by ", a, "\n");
313 else if (deathtype == DEATH_FALL)
314 bprint ("^1",s, "^1 was grounded by ", a, "\n");
315 else if (deathtype == DEATH_SHOOTING_STAR)
316 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
317 else if (deathtype == DEATH_SWAMP)
318 bprint ("^1",s, "^1 was conserved by ", a, "\n");
319 else if (deathtype == DEATH_HURTTRIGGER)
320 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
321 else if(deathtype == DEATH_TURRET)
322 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
324 bprint ("^1",s, "^1 was fragged by ", a, "\n");
326 if(g_ctf && targ.flagcarried)
328 GiveFrags(attacker, targ, cvar("g_ctf_flagscore_kill"));
329 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
332 GiveFrags(attacker, targ, 1);
333 if (targ.killcount > 2) {
335 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
337 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
339 attacker.killcount = attacker.killcount + 1;
340 if (attacker.killcount > 2) {
342 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
344 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
347 LogDeath("frag", deathtype, attacker, targ);
349 if (attacker.killcount == 3)
352 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
354 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
355 announce(attacker, "announcer/male/03kills.ogg");
358 else if (attacker.killcount == 5)
361 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
363 bprint (a,"^7 unleashes ^1RAGE\n");
364 announce(attacker, "announcer/male/05kills.ogg");
367 else if (attacker.killcount == 10)
370 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
372 bprint (a,"^7 starts the ^1MASSACRE!\n");
373 announce(attacker, "announcer/male/10kills.ogg");
376 else if (attacker.killcount == 15)
379 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
381 bprint (a,"^7 executes ^1MAYHEM!\n");
382 announce(attacker, "announcer/male/15kills.ogg");
385 else if (attacker.killcount == 20)
388 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
390 bprint (a,"^7 is a ^1BERSERKER!\n");
391 announce(attacker, "announcer/male/20kills.ogg");
394 else if (attacker.killcount == 25)
397 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
399 bprint (a,"^7 inflicts ^1CARNAGE!\n");
400 announce(attacker, "announcer/male/25kills.ogg");
403 else if (attacker.killcount == 30)
406 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
408 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
409 announce(attacker, "announcer/male/30kills.ogg");
416 centerprint(targ, "^1Watch your step!\n\n\n");
417 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
418 bprint ("^1",s, "^1 ", attacker.message, "\n");
419 else if (deathtype == DEATH_DROWN)
421 bprint ("^1",s, "^1 was in the water for too long\n");
423 bprint ("^1",s, "^1 drowned\n");
424 else if (deathtype == DEATH_SLIME)
425 bprint ("^1",s, "^1 was slimed\n");
426 else if (deathtype == DEATH_LAVA)
428 bprint ("^1",s, "^1 found a hot place\n");
430 bprint ("^1",s, "^1 turned into hot slag\n");
431 else if (deathtype == DEATH_FALL)
433 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
435 bprint ("^1",s, "^1 hit the ground with a crunch\n");
436 else if (deathtype == DEATH_SHOOTING_STAR)
437 bprint ("^1",s, "^1 became a shooting star\n");
438 else if (deathtype == DEATH_SWAMP)
440 bprint ("^1",s, "^1 discovered a swamp\n");
442 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
443 else if(deathtype == DEATH_TURRET)
444 bprint ("^1",s, "^1 was mowed down by a turret \n");
447 bprint ("^1",s, "^1 needs a restart\n");
449 bprint ("^1",s, "^1 died\n");
450 GiveFrags(targ, targ, -1);
451 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
452 announce(targ, "announcer/male/botlike.ogg");
455 if (targ.killcount > 2)
457 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
459 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
461 LogDeath("accident", deathtype, targ, targ);
463 targ.death_origin = targ.origin;
465 targ.killer_origin = attacker.origin;
466 // FIXME: this should go in PutClientInServer
472 // these are updated by each Damage call for use in button triggering and such
474 entity damage_inflictor;
475 entity damage_attacker;
477 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
481 entity attacker_save;
485 if (gameover || targ.killcount == -666)
488 local entity oldself;
492 damage_inflictor = inflictor;
493 damage_attacker = attacker;
494 attacker_save = attacker;
496 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
498 // These are ALWAYS lethal
499 // No damage modification here
500 // Instead, prepare the victim for his death...
502 targ.spawnshieldtime = 0;
503 targ.health = 0.9; // this is < 1
504 targ.flags -= targ.flags & FL_GODMODE;
509 if (targ.classname == "player")
510 if (attacker.classname == "player")
513 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
515 // nullify damage if teamplay is on
516 if(deathtype != DEATH_TELEFRAG)
517 if(attacker.classname == "player")
519 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
524 else if(attacker.team == targ.team)
528 else if(attacker != targ)
532 else if(teamplay == 4)
534 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
536 mirrordamage = cvar("g_mirrordamage") * damage;
537 mirrorforce = cvar("g_mirrordamage") * vlen(force);
540 if(cvar("g_friendlyfire") == 0)
544 damage = cvar("g_friendlyfire") * damage;
545 // mirrordamage will be used LATER
554 if(targ.classname == "player")
555 if(attacker.classname == "player")
558 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
559 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
565 if(targ.classname == "player")
567 attacker.hitsound += 1;
571 if ((deathtype == DEATH_FALL) ||
572 (deathtype == DEATH_DROWN) ||
573 (deathtype == DEATH_SLIME) ||
574 (deathtype == DEATH_LAVA))
576 if (targ.armorvalue && (deathtype == WEP_NEX) && damage)
578 targ.armorvalue -= 1;
579 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
583 else if (deathtype == WEP_NEX && 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)
614 damage = damage * cvar("g_balance_powerup_strength_damage");
615 force = force * cvar("g_balance_powerup_strength_force");
617 // apply invincibility multiplier
618 if (targ.items & IT_INVINCIBLE && !g_minstagib)
619 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
624 // apply strength rune
625 if (attacker.runes & RUNE_STRENGTH)
627 if(attacker.runes & CURSE_WEAK) // have both curse & rune
629 damage = damage * cvar("g_balance_rune_strength_combo_damage");
630 force = force * cvar("g_balance_rune_strength_combo_force");
634 damage = damage * cvar("g_balance_rune_strength_damage");
635 force = force * cvar("g_balance_rune_strength_force");
638 else if (attacker.runes & CURSE_WEAK)
640 damage = damage * cvar("g_balance_curse_weak_damage");
641 force = force * cvar("g_balance_curse_weak_force");
644 // apply defense rune
645 if (targ.runes & RUNE_DEFENSE)
647 if (targ.runes & CURSE_VULNER) // have both curse & rune
648 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
650 damage = damage * cvar("g_balance_rune_defense_takedamage");
652 else if (targ.runes & CURSE_VULNER)
653 damage = damage * cvar("g_balance_curse_vulner_takedamage");
658 if (self.damageforcescale)
661 self.velocity = self.velocity + self.damageforcescale * force;
662 self.flags = self.flags - (self.flags & FL_ONGROUND);
666 if (self.event_damage)
667 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
670 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
672 // Savage: vampire mode
676 if (time > self.spawnshieldtime)
678 attacker.health += damage;
682 if (attacker.runes & RUNE_VAMPIRE)
684 // apply vampire rune
685 if (attacker.runes & CURSE_EMPATHY) // have the curse too
687 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
688 attacker.health = bound(
689 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
690 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
691 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
695 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
696 attacker.health = bound(
697 attacker.health, // LA: was 3, but changed so that you can't lose health
698 // empathy won't let you gain health in the same way...
699 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
700 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
703 // apply empathy curse
704 else if (attacker.runes & CURSE_EMPATHY)
706 attacker.health = bound(
707 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
708 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
714 // apply mirror damage if any
715 if(mirrordamage > 0 || mirrorforce > 0)
717 attacker = attacker_save;
721 // just lose extra LIVES, don't kill the player for mirror damage
722 if(attacker.armorvalue > 0)
724 attacker.armorvalue = attacker.armorvalue - 1;
725 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
726 attacker.hitsound += 1;
730 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
731 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
735 vector NearestPointOnBox(entity box, vector org)
737 vector m1, m2, nearest;
739 m1 = box.mins + box.origin;
740 m2 = box.maxs + box.origin;
742 nearest_x = bound(m1_x, org_x, m2_x);
743 nearest_y = bound(m1_y, org_y, m2_y);
744 nearest_z = bound(m1_z, org_z, m2_z);
749 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
750 // Returns total damage applies to creatures
760 float total_damage_to_creatures;
762 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
763 total_damage_to_creatures = 0;
765 targ = findradius (blastorigin, rad);
768 if (targ != inflictor)
771 // LordHavoc: measure distance to nearest point on target (not origin)
772 // (this guarentees 100% damage on a touch impact)
773 nearest = NearestPointOnBox(targ, blastorigin);
774 diff = nearest - blastorigin;
775 // round up a little on the damage to ensure full damage on impacts
776 // and turn the distance into a fraction of the radius
777 power = 1 - ((vlen (diff) - 2) / rad);
779 //bprint(ftos(power));
784 finaldmg = coredamage * power + edgedamage * (1 - power);
787 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
788 // if it's a player, use the view origin as reference
789 if (targ.classname == "player")
790 center = targ.origin + targ.view_ofs;
791 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
792 if (targ == attacker)
793 finaldmg = finaldmg * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
794 // test line of sight to multiple positions on box,
795 // and do damage if any of them hit
797 c = ceil(finaldmg / 10);
803 traceline(blastorigin, nearest, TRUE, inflictor);
804 if (trace_fraction == 1 || trace_ent == targ
805 || cvar("g_throughfloor"))
808 total_damage_to_creatures += finaldmg;
809 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
812 nearest_x = targ.mins_x + random() * targ.size_x;
813 nearest_y = targ.mins_y + random() * targ.size_y;
814 nearest_z = targ.mins_z + random() * targ.size_z;
822 return total_damage_to_creatures;