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)
148 if (targ.classname == "player" || targ.classname == "corpse")
150 if (targ.classname == "corpse")
154 a = attacker.netname;
156 if (targ == attacker)
158 if (deathtype == DEATH_TEAMCHANGE) {
159 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
160 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
161 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
163 } else if (deathtype == DEATH_CAMP) {
165 centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
167 centerprint(targ, "^1Die camper!\n\n\n");
168 } else if (deathtype == DEATH_NOAMMO) {
170 centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
172 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
173 } else if (deathtype == DEATH_ROT) {
175 centerprint(targ, "^1You need to preserve your health\n\n\n");
177 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
178 } else if (deathtype == DEATH_MIRRORDAMAGE) {
180 centerprint(targ, "^1Don't go against team mates!\n\n\n");
182 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
185 centerprint(targ, "^1You need to be more careful!\n\n\n");
187 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
191 if (deathtype == DEATH_CAMP)
192 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
193 else if (deathtype == DEATH_MIRRORDAMAGE)
194 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
196 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
198 if(deathtype != DEATH_TEAMCHANGE)
200 LogDeath("suicide", deathtype, targ, targ);
201 GiveFrags(attacker, targ, -1);
203 if (targ.killcount > 2)
204 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
206 if(deathtype >= WEP_FIRST && deathtype <= WEP_LAST)
208 w_deathtypestring = "couldn't resist the urge to self-destruct";
209 weapon_action(deathtype, WR_SUICIDEMESSAGE);
210 bprint("^1", s, "^1 ", w_deathtypestring, "\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");
286 if(deathtype >= WEP_FIRST && deathtype <= WEP_LAST)
288 w_deathtypestring = "was blasted by";
289 weapon_action(deathtype, WR_KILLMESSAGE);
290 p = strstrofs(w_deathtypestring, "#", 0);
292 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
294 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
296 else if (deathtype == DEATH_TELEFRAG)
297 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
298 else if (deathtype == DEATH_DROWN)
299 bprint ("^1",s, "^1 was drowned by ", a, "\n");
300 else if (deathtype == DEATH_SLIME)
301 bprint ("^1",s, "^1 was slimed by ", a, "\n");
302 else if (deathtype == DEATH_LAVA)
303 bprint ("^1",s, "^1 was cooked by ", a, "\n");
304 else if (deathtype == DEATH_FALL)
305 bprint ("^1",s, "^1 was grounded by ", a, "\n");
306 else if (deathtype == DEATH_SHOOTING_STAR)
307 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
308 else if (deathtype == DEATH_SWAMP)
309 bprint ("^1",s, "^1 was conserved by ", a, "\n");
310 else if (deathtype == DEATH_HURTTRIGGER)
311 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
312 else if(deathtype == DEATH_TURRET)
313 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
315 bprint ("^1",s, "^1 was fragged by ", a, "\n");
317 if(g_ctf && targ.flagcarried)
319 GiveFrags(attacker, targ, cvar("g_ctf_flagscore_kill"));
320 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
323 GiveFrags(attacker, targ, 1);
324 if (targ.killcount > 2) {
326 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
328 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
330 attacker.killcount = attacker.killcount + 1;
331 if (attacker.killcount > 2) {
333 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
335 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
338 LogDeath("frag", deathtype, attacker, targ);
340 if (attacker.killcount == 3)
343 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
345 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
346 announce(attacker, "announcer/male/03kills.ogg");
349 else if (attacker.killcount == 5)
352 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
354 bprint (a,"^7 unleashes ^1RAGE\n");
355 announce(attacker, "announcer/male/05kills.ogg");
358 else if (attacker.killcount == 10)
361 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
363 bprint (a,"^7 starts the ^1MASSACRE!\n");
364 announce(attacker, "announcer/male/10kills.ogg");
367 else if (attacker.killcount == 15)
370 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
372 bprint (a,"^7 executes ^1MAYHEM!\n");
373 announce(attacker, "announcer/male/15kills.ogg");
376 else if (attacker.killcount == 20)
379 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
381 bprint (a,"^7 is a ^1BERSERKER!\n");
382 announce(attacker, "announcer/male/20kills.ogg");
385 else if (attacker.killcount == 25)
388 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
390 bprint (a,"^7 inflicts ^1CARNAGE!\n");
391 announce(attacker, "announcer/male/25kills.ogg");
394 else if (attacker.killcount == 30)
397 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
399 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
400 announce(attacker, "announcer/male/30kills.ogg");
407 centerprint(targ, "^1Watch your step!\n\n\n");
408 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
409 bprint ("^1",s, "^1 ", attacker.message, "\n");
410 else if (deathtype == DEATH_DROWN)
412 bprint ("^1",s, "^1 was in the water for too long\n");
414 bprint ("^1",s, "^1 drowned\n");
415 else if (deathtype == DEATH_SLIME)
416 bprint ("^1",s, "^1 was slimed\n");
417 else if (deathtype == DEATH_LAVA)
419 bprint ("^1",s, "^1 found a hot place\n");
421 bprint ("^1",s, "^1 turned into hot slag\n");
422 else if (deathtype == DEATH_FALL)
424 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
426 bprint ("^1",s, "^1 hit the ground with a crunch\n");
427 else if (deathtype == DEATH_SHOOTING_STAR)
428 bprint ("^1",s, "^1 became a shooting star\n");
429 else if (deathtype == DEATH_SWAMP)
431 bprint ("^1",s, "^1 discovered a swamp\n");
433 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
434 else if(deathtype == DEATH_TURRET)
435 bprint ("^1",s, "^1 was mowed down by a turret \n");
438 bprint ("^1",s, "^1 needs a restart\n");
440 bprint ("^1",s, "^1 died\n");
441 GiveFrags(targ, targ, -1);
442 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
443 announce(targ, "announcer/male/botlike.ogg");
446 if (targ.killcount > 2)
448 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
450 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
452 LogDeath("accident", deathtype, targ, targ);
454 targ.death_origin = targ.origin;
456 targ.killer_origin = attacker.origin;
457 // FIXME: this should go in PutClientInServer
463 // these are updated by each Damage call for use in button triggering and such
465 entity damage_inflictor;
466 entity damage_attacker;
468 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
472 entity attacker_save;
476 if (gameover || targ.killcount == -666)
479 local entity oldself;
483 damage_inflictor = inflictor;
484 damage_attacker = attacker;
485 attacker_save = attacker;
487 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
489 // These are ALWAYS lethal
490 // No damage modification here
491 // Instead, prepare the victim for his death...
493 targ.spawnshieldtime = 0;
494 targ.health = 0.9; // this is < 1
495 targ.flags -= targ.flags & FL_GODMODE;
500 if (targ.classname == "player")
501 if (attacker.classname == "player")
504 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
506 // nullify damage if teamplay is on
507 if(deathtype != DEATH_TELEFRAG)
508 if(attacker.classname == "player")
510 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
515 else if(attacker.team == targ.team)
519 else if(attacker != targ)
523 else if(teamplay == 4)
525 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
527 mirrordamage = cvar("g_mirrordamage") * damage;
528 mirrorforce = cvar("g_mirrordamage") * vlen(force);
531 if(cvar("g_friendlyfire") == 0)
535 damage = cvar("g_friendlyfire") * damage;
536 // mirrordamage will be used LATER
545 if(targ.classname == "player")
546 if(attacker.classname == "player")
549 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
550 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
556 if(targ.classname == "player")
558 attacker.hitsound += 1;
562 if ((deathtype == DEATH_FALL) ||
563 (deathtype == DEATH_DROWN) ||
564 (deathtype == DEATH_SLIME) ||
565 (deathtype == DEATH_LAVA))
570 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
572 targ.armorvalue -= 1;
573 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
577 else if (deathtype == WEP_MINSTANEX && targ.items & IT_STRENGTH)
579 if(clienttype(attacker) == CLIENTTYPE_REAL)
580 if(IsDifferentTeam(targ, attacker))
583 if (deathtype == WEP_LASER)
586 if (targ != attacker)
588 if (targ.classname == "player")
589 centerprint(attacker, "Secondary fire inflicts no damage!\n");
599 if(targ.takedamage == DAMAGE_AIM)
601 if(IsDifferentTeam(targ, attacker))
605 // apply strength multiplier
606 if (attacker.items & IT_STRENGTH && !g_minstagib)
610 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
611 force = force * cvar("g_balance_powerup_strength_selfforce");
615 damage = damage * cvar("g_balance_powerup_strength_damage");
616 force = force * cvar("g_balance_powerup_strength_force");
620 // apply invincibility multiplier
621 if (targ.items & IT_INVINCIBLE && !g_minstagib)
622 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
624 if (targ == attacker)
625 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
627 // CTF: reduce damage/force
632 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
633 force = force * cvar("g_ctf_flagcarrier_selfforce");
638 // apply strength rune
639 if (attacker.runes & RUNE_STRENGTH)
641 if(attacker.runes & CURSE_WEAK) // have both curse & rune
643 damage = damage * cvar("g_balance_rune_strength_combo_damage");
644 force = force * cvar("g_balance_rune_strength_combo_force");
648 damage = damage * cvar("g_balance_rune_strength_damage");
649 force = force * cvar("g_balance_rune_strength_force");
652 else if (attacker.runes & CURSE_WEAK)
654 damage = damage * cvar("g_balance_curse_weak_damage");
655 force = force * cvar("g_balance_curse_weak_force");
658 // apply defense rune
659 if (targ.runes & RUNE_DEFENSE)
661 if (targ.runes & CURSE_VULNER) // have both curse & rune
662 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
664 damage = damage * cvar("g_balance_rune_defense_takedamage");
666 else if (targ.runes & CURSE_VULNER)
667 damage = damage * cvar("g_balance_curse_vulner_takedamage");
672 if (self.damageforcescale)
675 self.velocity = self.velocity + self.damageforcescale * force;
676 self.flags = self.flags - (self.flags & FL_ONGROUND);
680 if (self.event_damage)
681 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
684 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
686 // Savage: vampire mode
689 if (time > self.spawnshieldtime)
691 attacker.health += damage;
695 if (attacker.runes & RUNE_VAMPIRE)
697 // apply vampire rune
698 if (attacker.runes & CURSE_EMPATHY) // have the curse too
700 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
701 attacker.health = bound(
702 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
703 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
704 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
708 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
709 attacker.health = bound(
710 attacker.health, // LA: was 3, but changed so that you can't lose health
711 // empathy won't let you gain health in the same way...
712 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
713 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
716 // apply empathy curse
717 else if (attacker.runes & CURSE_EMPATHY)
719 attacker.health = bound(
720 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
721 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
727 // apply mirror damage if any
728 if(mirrordamage > 0 || mirrorforce > 0)
730 attacker = attacker_save;
734 // just lose extra LIVES, don't kill the player for mirror damage
735 if(attacker.armorvalue > 0)
737 attacker.armorvalue = attacker.armorvalue - 1;
738 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
739 attacker.hitsound += 1;
743 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
744 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
748 vector NearestPointOnBox(entity box, vector org)
750 vector m1, m2, nearest;
752 m1 = box.mins + box.origin;
753 m2 = box.maxs + box.origin;
755 nearest_x = bound(m1_x, org_x, m2_x);
756 nearest_y = bound(m1_y, org_y, m2_y);
757 nearest_z = bound(m1_z, org_z, m2_z);
762 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
763 // Returns total damage applies to creatures
773 float total_damage_to_creatures;
775 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
776 total_damage_to_creatures = 0;
778 targ = findradius (blastorigin, rad);
781 if (targ != inflictor)
784 // LordHavoc: measure distance to nearest point on target (not origin)
785 // (this guarentees 100% damage on a touch impact)
786 nearest = NearestPointOnBox(targ, blastorigin);
787 diff = nearest - blastorigin;
788 // round up a little on the damage to ensure full damage on impacts
789 // and turn the distance into a fraction of the radius
790 power = 1 - ((vlen (diff) - 2) / rad);
792 //bprint(ftos(power));
797 finaldmg = coredamage * power + edgedamage * (1 - power);
800 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
801 // if it's a player, use the view origin as reference
802 if (targ.classname == "player")
803 center = targ.origin + targ.view_ofs;
804 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
805 // test line of sight to multiple positions on box,
806 // and do damage if any of them hit
808 c = ceil(finaldmg / 10);
814 traceline(blastorigin, nearest, TRUE, inflictor);
815 if (trace_fraction == 1 || trace_ent == targ
816 || cvar("g_throughfloor"))
819 total_damage_to_creatures += finaldmg;
820 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
823 nearest_x = targ.mins_x + random() * targ.size_x;
824 nearest_y = targ.mins_y + random() * targ.size_y;
825 nearest_z = targ.mins_z + random() * targ.size_z;
833 return total_damage_to_creatures;