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 if(cvar("g_domination_disable_frags"))
87 f = RunematchHandleFrags(attacker, targ, f);
91 f = kh_HandleFrags(attacker, targ, f);
97 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
98 if(tl < lms_lowest_lives)
99 lms_lowest_lives = tl;
103 lms_next_place = player_count;
104 PlayerScore_Add(targ, SP_LMS_PLACE, lms_next_place); // won't ever spawn again
110 attacker.totalfrags += f;
113 UpdateFrags(attacker, f);
116 string AppendItemcodes(string s, entity player)
121 // w = player.switchweapon;
123 w = player.cnt; // previous weapon!
124 s = strcat(s, ftos(W_ItemCode(w)));
125 if(time < player.strength_finished)
127 if(time < player.invincible_finished)
129 if(player.flagcarried != world)
131 if(player.BUTTON_CHAT)
136 s = strcat(s, "|", ftos(player.runes));
140 void LogDeath(string mode, float deathtype, entity killer, entity killed)
143 if(!cvar("sv_eventlog"))
145 s = strcat(":kill:", mode);
146 s = strcat(s, ":", ftos(killer.playerid));
147 s = strcat(s, ":", ftos(killed.playerid));
148 s = strcat(s, ":type=", ftos(deathtype));
149 s = strcat(s, ":items=");
150 s = AppendItemcodes(s, killer);
153 s = strcat(s, ":victimitems=");
154 s = AppendItemcodes(s, killed);
156 GameLogEcho(s, FALSE);
159 void Obituary (entity attacker, entity targ, float deathtype)
163 if (targ.classname == "player" || targ.classname == "corpse")
165 if (targ.classname == "corpse")
169 a = attacker.netname;
171 if (targ == attacker)
173 if (deathtype == DEATH_TEAMCHANGE) {
174 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
175 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
176 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
178 } else if (deathtype == DEATH_CAMP) {
180 centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
182 centerprint(targ, "^1Die camper!\n\n\n");
183 } else if (deathtype == DEATH_NOAMMO) {
185 centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
187 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
188 } else if (deathtype == DEATH_ROT) {
190 centerprint(targ, "^1You need to preserve your health\n\n\n");
192 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
193 } else if (deathtype == DEATH_MIRRORDAMAGE) {
195 centerprint(targ, "^1Don't go against team mates!\n\n\n");
197 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
200 centerprint(targ, "^1You need to be more careful!\n\n\n");
202 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
206 if (deathtype == DEATH_CAMP)
207 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
208 else if (deathtype == DEATH_MIRRORDAMAGE)
209 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
211 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
213 if(deathtype != DEATH_TEAMCHANGE)
215 LogDeath("suicide", deathtype, targ, targ);
216 GiveFrags(attacker, targ, -1);
218 if (targ.killcount > 2)
219 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
222 if (deathtype == IT_GRENADE_LAUNCHER)
223 bprint ("^1",s, "^1 detonated\n");
224 else if (deathtype == IT_ELECTRO)
225 bprint ("^1",s, "^1 played with plasma\n");
226 else if (deathtype == IT_ROCKET_LAUNCHER)
227 bprint ("^1",s, "^1 exploded\n");
228 else if (deathtype == DEATH_KILL)
229 bprint ("^1",s, "^1 couldn't take it anymore\n");
230 else if (deathtype == DEATH_ROT)
231 bprint ("^1",s, "^1 died\n");
232 else if (deathtype == DEATH_NOAMMO)
234 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
235 //sound (self, CHAN_BODY, "minstagib/mockery.wav", 1, ATTN_NONE);
237 else if (deathtype == DEATH_CAMP)
238 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
239 else if (deathtype == DEATH_MIRRORDAMAGE)
240 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
241 else if (deathtype != DEATH_TEAMCHANGE)
242 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
244 if(deathtype != DEATH_TEAMCHANGE)
246 LogDeath("suicide", deathtype, targ, targ);
247 GiveFrags(attacker, targ, -1);
249 if (targ.killcount > 2)
250 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
253 else if (attacker.classname == "player" || attacker.classname == "gib")
255 if(teamplay && attacker.team == targ.team)
258 centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
259 bprint ("^1", a, "^1 took action against a teammate\n");
261 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
262 bprint ("^1", a, "^1 mows down a teammate\n");
264 GiveFrags(attacker, targ, -1);
265 if (targ.killcount > 2) {
267 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
269 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
271 if (attacker.killcount > 2) {
273 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
275 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
277 attacker.killcount = 0;
279 LogDeath("tk", deathtype, attacker, targ);
283 if (!checkrules_firstblood)
285 checkrules_firstblood = TRUE;
286 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
288 //sound(world, CHAN_AUTO, "announce/male/mapkill1.wav", 1, ATTN_NONE);
290 bprint("^1",a, "^1 was the first to score", "\n");
292 bprint("^1",a, "^1 drew first blood", "\n");
296 centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
297 centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
299 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
300 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
304 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
306 if (deathtype == IT_LASER)
307 bprint ("^1",s, "^1 was blasted by ", a, "\n");
308 else if (deathtype == IT_UZI)
309 bprint ("^1",s, "^1 was riddled full of holes by ", a, "\n");
310 else if (deathtype == IT_SHOTGUN)
311 bprint ("^1",s, "^1 was gunned by ", a, "\n");
312 else if (deathtype == IT_GRENADE_LAUNCHER)
313 bprint ("^1", s, "^1 was blasted by ", a, "\n");
314 else if (deathtype == IT_ELECTRO)
315 bprint ("^1",s, "^1 was blasted by ", a, "\n");
316 else if (deathtype == IT_CRYLINK)
317 bprint ("^1",s, "^1 was blasted by ", a, "\n");
318 else if (deathtype == IT_NEX)
319 bprint ("^1",s, "^1 has been vaporized by ", a, "\n");
320 else if (deathtype == IT_HAGAR)
321 bprint ("^1",s, "^1 was pummeled by ", a, "\n");
322 else if (deathtype == IT_ROCKET_LAUNCHER)
323 bprint ("^1",s, "^1 was blasted by ", a, "\n");
324 else if (deathtype == DEATH_TELEFRAG)
325 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
326 else if (deathtype == DEATH_DROWN)
327 bprint ("^1",s, "^1 was drowned by ", a, "\n");
328 else if (deathtype == DEATH_SLIME)
329 bprint ("^1",s, "^1 was slimed by ", a, "\n");
330 else if (deathtype == DEATH_LAVA)
331 bprint ("^1",s, "^1 was cooked by ", a, "\n");
332 else if (deathtype == DEATH_FALL)
333 bprint ("^1",s, "^1 was grounded by ", a, "\n");
334 else if (deathtype == DEATH_SHOOTING_STAR)
335 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
336 else if (deathtype == DEATH_SWAMP)
337 bprint ("^1",s, "^1 was conserved by ", a, "\n");
338 else if (deathtype == DEATH_HURTTRIGGER)
339 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
340 else if(deathtype == DEATH_TURRET)
341 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
343 bprint ("^1",s, "^1 was fragged by ", a, "\n");
345 if(g_ctf && targ.flagcarried)
347 GiveFrags(attacker, targ, cvar("g_ctf_flagscore_kill"));
348 PlayerScore_Add(attacker, SP_CTF_CARRIERKILLS, 1);
351 GiveFrags(attacker, targ, 1);
352 if (targ.killcount > 2) {
354 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
356 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
358 attacker.killcount = attacker.killcount + 1;
359 if (attacker.killcount > 2) {
361 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
363 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
366 LogDeath("frag", deathtype, attacker, targ);
368 if (attacker.killcount == 3)
371 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
373 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
374 announce(attacker, "announcer/male/03kills.ogg");
377 else if (attacker.killcount == 5)
380 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
382 bprint (a,"^7 unleashes ^1RAGE\n");
383 announce(attacker, "announcer/male/05kills.ogg");
386 else if (attacker.killcount == 10)
389 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
391 bprint (a,"^7 starts the ^1MASSACRE!\n");
392 announce(attacker, "announcer/male/10kills.ogg");
395 else if (attacker.killcount == 15)
398 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
400 bprint (a,"^7 executes ^1MAYHEM!\n");
401 announce(attacker, "announcer/male/15kills.ogg");
404 else if (attacker.killcount == 20)
407 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
409 bprint (a,"^7 is a ^1BERSERKER!\n");
410 announce(attacker, "announcer/male/20kills.ogg");
413 else if (attacker.killcount == 25)
416 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
418 bprint (a,"^7 inflicts ^1CARNAGE!\n");
419 announce(attacker, "announcer/male/25kills.ogg");
422 else if (attacker.killcount == 30)
425 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
427 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
428 announce(attacker, "announcer/male/30kills.ogg");
435 centerprint(targ, "^1Watch your step!\n\n\n");
436 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
437 bprint ("^1",s, "^1 ", attacker.message, "\n");
438 else if (deathtype == DEATH_DROWN)
440 bprint ("^1",s, "^1 was in the water for too long\n");
442 bprint ("^1",s, "^1 drowned\n");
443 else if (deathtype == DEATH_SLIME)
444 bprint ("^1",s, "^1 was slimed\n");
445 else if (deathtype == DEATH_LAVA)
447 bprint ("^1",s, "^1 found a hot place\n");
449 bprint ("^1",s, "^1 turned into hot slag\n");
450 else if (deathtype == DEATH_FALL)
452 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
454 bprint ("^1",s, "^1 hit the ground with a crunch\n");
455 else if (deathtype == DEATH_SHOOTING_STAR)
456 bprint ("^1",s, "^1 became a shooting star\n");
457 else if (deathtype == DEATH_SWAMP)
459 bprint ("^1",s, "^1 discovered a swamp\n");
461 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
462 else if(deathtype == DEATH_TURRET)
463 bprint ("^1",s, "^1 was mowed down by a turret \n");
466 bprint ("^1",s, "^1 needs a restart\n");
468 bprint ("^1",s, "^1 died\n");
469 GiveFrags(targ, targ, -1);
470 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
471 announce(targ, "announcer/male/botlike.ogg");
474 if (targ.killcount > 2)
476 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
478 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
480 LogDeath("accident", deathtype, targ, targ);
482 targ.death_origin = targ.origin;
484 targ.killer_origin = attacker.origin;
485 // FIXME: this should go in PutClientInServer
491 // these are updated by each Damage call for use in button triggering and such
493 entity damage_inflictor;
494 entity damage_attacker;
496 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
500 entity attacker_save;
504 if (gameover || targ.killcount == -666)
507 local entity oldself;
511 damage_inflictor = inflictor;
512 damage_attacker = attacker;
513 attacker_save = attacker;
515 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
517 // These are ALWAYS lethal
518 // No damage modification here
519 // Instead, prepare the victim for his death...
521 targ.spawnshieldtime = 0;
522 targ.health = 0.9; // this is < 1
523 targ.flags -= targ.flags & FL_GODMODE;
528 if (targ.classname == "player")
529 if (attacker.classname == "player")
532 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
534 // nullify damage if teamplay is on
535 if(deathtype != DEATH_TELEFRAG)
536 if(attacker.team == targ.team)
537 if(attacker.classname == "player")
541 else if(attacker != targ)
545 else if(teamplay == 4)
547 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
549 mirrordamage = cvar("g_mirrordamage") * damage;
550 mirrorforce = cvar("g_mirrordamage") * vlen(force);
553 if(cvar("g_friendlyfire") == 0)
557 damage = cvar("g_friendlyfire") * damage;
558 // mirrordamage will be used LATER
567 if(targ.classname == "player")
568 if(attacker.classname == "player")
571 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
572 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
578 if(targ.classname == "player")
580 attacker.hitsound += 1;
584 if ((deathtype == DEATH_FALL) ||
585 (deathtype == DEATH_DROWN) ||
586 (deathtype == DEATH_SLIME) ||
587 (deathtype == DEATH_LAVA))
589 if (targ.armorvalue && (deathtype == IT_NEX) && damage)
591 targ.armorvalue -= 1;
592 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
596 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
598 if(clienttype(attacker) == CLIENTTYPE_REAL)
599 if(IsDifferentTeam(targ, attacker))
602 if (deathtype == IT_LASER)
605 if (targ != attacker)
607 if (targ.classname == "player")
608 centerprint(attacker, "Secondary fire inflicts no damage!\n");
618 if(targ.takedamage == DAMAGE_AIM)
620 if(IsDifferentTeam(targ, attacker))
624 // apply strength multiplier
625 if (attacker.items & IT_STRENGTH && !g_minstagib)
627 damage = damage * cvar("g_balance_powerup_strength_damage");
628 force = force * cvar("g_balance_powerup_strength_force");
630 // apply invincibility multiplier
631 if (targ.items & IT_INVINCIBLE && !g_minstagib)
632 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
637 // apply strength rune
638 if (attacker.runes & RUNE_STRENGTH)
640 if(attacker.runes & CURSE_WEAK) // have both curse & rune
642 damage = damage * cvar("g_balance_rune_strength_combo_damage");
643 force = force * cvar("g_balance_rune_strength_combo_force");
647 damage = damage * cvar("g_balance_rune_strength_damage");
648 force = force * cvar("g_balance_rune_strength_force");
651 else if (attacker.runes & CURSE_WEAK)
653 damage = damage * cvar("g_balance_curse_weak_damage");
654 force = force * cvar("g_balance_curse_weak_force");
657 // apply defense rune
658 if (targ.runes & RUNE_DEFENSE)
660 if (targ.runes & CURSE_VULNER) // have both curse & rune
661 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
663 damage = damage * cvar("g_balance_rune_defense_takedamage");
665 else if (targ.runes & CURSE_VULNER)
666 damage = damage * cvar("g_balance_curse_vulner_takedamage");
671 if (self.damageforcescale)
674 self.velocity = self.velocity + self.damageforcescale * force;
675 self.flags = self.flags - (self.flags & FL_ONGROUND);
678 if (self.event_damage)
679 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
682 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
684 // Savage: vampire mode
688 if (time > self.spawnshieldtime)
690 attacker.health += damage;
694 if (attacker.runes & RUNE_VAMPIRE)
696 // apply vampire rune
697 if (attacker.runes & CURSE_EMPATHY) // have the curse too
699 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
700 attacker.health = bound(
701 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
702 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
703 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
707 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
708 attacker.health = bound(
709 attacker.health, // LA: was 3, but changed so that you can't lose health
710 // empathy won't let you gain health in the same way...
711 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
712 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
715 // apply empathy curse
716 else if (attacker.runes & CURSE_EMPATHY)
718 attacker.health = bound(
719 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
720 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
726 // apply mirror damage if any
727 if(mirrordamage > 0 || mirrorforce > 0)
729 attacker = attacker_save;
733 // just lose extra LIVES, don't kill the player for mirror damage
734 if(attacker.armorvalue > 0)
736 attacker.armorvalue = attacker.armorvalue - 1;
737 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
738 attacker.hitsound += 1;
742 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
743 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
747 vector NearestPointOnBox(entity box, vector org)
749 vector m1, m2, nearest;
751 m1 = box.mins + box.origin;
752 m2 = box.maxs + box.origin;
754 nearest_x = bound(m1_x, org_x, m2_x);
755 nearest_y = bound(m1_y, org_y, m2_y);
756 nearest_z = bound(m1_z, org_z, m2_z);
761 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
762 // Returns total damage applies to creatures
772 float total_damage_to_creatures;
774 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
775 total_damage_to_creatures = 0;
777 targ = findradius (blastorigin, rad);
780 if (targ != inflictor)
783 // LordHavoc: measure distance to nearest point on target (not origin)
784 // (this guarentees 100% damage on a touch impact)
785 nearest = NearestPointOnBox(targ, blastorigin);
786 diff = nearest - blastorigin;
787 // round up a little on the damage to ensure full damage on impacts
788 // and turn the distance into a fraction of the radius
789 power = 1 - ((vlen (diff) - 2) / rad);
791 //bprint(ftos(power));
796 finaldmg = coredamage * power + edgedamage * (1 - power);
799 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
800 // if it's a player, use the view origin as reference
801 if (targ.classname == "player")
802 center = targ.origin + targ.view_ofs;
803 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
804 if (targ == attacker)
805 finaldmg = finaldmg * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
806 // test line of sight to multiple positions on box,
807 // and do damage if any of them hit
809 c = ceil(finaldmg / 10);
815 traceline(blastorigin, nearest, TRUE, inflictor);
816 if (trace_fraction == 1 || trace_ent == targ
817 || cvar("g_throughfloor"))
820 total_damage_to_creatures += finaldmg;
821 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
824 nearest_x = targ.mins_x + random() * targ.size_x;
825 nearest_y = targ.mins_y + random() * targ.size_y;
826 nearest_z = targ.mins_z + random() * targ.size_z;
834 return total_damage_to_creatures;