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(entity player, float f) UpdateFrags =
46 player.totalfrags += f;
49 void GiveFrags (entity attacker, entity targ, float f)
54 if(cvar("g_arena_roundbased"))
59 if(cvar("g_domination_disable_frags"))
66 f = RunematchHandleFrags(attacker, targ, f);
70 f = kh_HandleFrags(attacker, targ, f);
74 // count remaining lives, not frags in lms
76 // keep track of the worst players lives
77 if(targ.frags < lms_lowest_lives)
78 lms_lowest_lives = targ.frags;
79 // player has no more lives left
83 lms_next_place = player_count;
84 targ.frags = -lms_next_place;
91 UpdateFrags(attacker, f);
94 string AppendItemcodes(string s, entity player)
99 // w = player.switchweapon;
101 w = player.cnt; // previous weapon!
102 s = strcat(s, ftos(W_ItemCode(w)));
103 if(time < player.strength_finished)
105 if(time < player.invincible_finished)
107 if(player.flagcarried != world)
109 if(player.buttonchat)
114 s = strcat(s, "|", ftos(player.runes));
118 void LogDeath(string mode, float deathtype, entity killer, entity killed)
121 if(!cvar("sv_eventlog"))
123 s = strcat(":kill:", mode);
124 s = strcat(s, ":", ftos(killer.playerid));
125 s = strcat(s, ":", ftos(killed.playerid));
126 s = strcat(s, ":type=", ftos(deathtype));
127 s = strcat(s, ":items=");
128 s = AppendItemcodes(s, killer);
131 s = strcat(s, ":victimitems=");
132 s = AppendItemcodes(s, killed);
134 GameLogEcho(s, FALSE);
137 void Obituary (entity attacker, entity targ, float deathtype)
141 if (targ.classname == "player" || targ.classname == "corpse")
143 if (targ.classname == "corpse")
147 a = attacker.netname;
149 if (targ == attacker)
151 if (deathtype == DEATH_TEAMCHANGE)
153 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
155 else if (deathtype == DEATH_AUTOTEAMCHANGE)
157 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
160 else if (deathtype == DEATH_CAMP)
161 centerprint(targ, "^1Die camper!\n\n\n");
162 else if (deathtype == DEATH_NOAMMO)
163 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
164 else if (deathtype == DEATH_ROT)
165 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
166 else if (deathtype == DEATH_MIRRORDAMAGE)
167 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
169 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
171 if (deathtype == IT_GRENADE_LAUNCHER)
172 bprint ("^1",s, "^1 detonated\n");
173 else if (deathtype == IT_ELECTRO)
174 bprint ("^1",s, "^1 played with plasma\n");
175 else if (deathtype == IT_ROCKET_LAUNCHER)
176 bprint ("^1",s, "^1 exploded\n");
177 else if (deathtype == DEATH_KILL)
178 bprint ("^1",s, "^1 couldn't take it anymore\n");
179 else if (deathtype == DEATH_ROT)
180 bprint ("^1",s, "^1 died\n");
181 else if (deathtype == DEATH_NOAMMO)
183 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
184 //sound (self, CHAN_BODY, "minstagib/mockery.wav", 1, ATTN_NONE);
186 else if (deathtype == DEATH_CAMP)
187 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
188 else if (deathtype == DEATH_MIRRORDAMAGE)
189 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
190 else if (deathtype != DEATH_TEAMCHANGE)
191 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
193 if(deathtype != DEATH_TEAMCHANGE)
195 LogDeath("suicide", deathtype, targ, targ);
196 GiveFrags(attacker, targ, -1);
198 if (targ.killcount > 2)
199 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
201 else if (attacker.classname == "player" || attacker.classname == "gib")
203 if(teamplay && attacker.team == targ.team)
205 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
206 bprint ("^1", a, "^1 mows down a teammate\n");
207 GiveFrags(attacker, targ, -1);
208 if (targ.killcount > 2)
209 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
210 if (attacker.killcount > 2)
211 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
212 attacker.killcount = 0;
214 LogDeath("tk", deathtype, attacker, targ);
218 if (!checkrules_firstblood)
220 checkrules_firstblood = TRUE;
221 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
223 //sound(world, CHAN_AUTO, "announce/male/mapkill1.wav", 1, ATTN_NONE);
224 bprint("^1",a, "^1 drew first blood", "\n");
227 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
228 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
230 if (deathtype == IT_LASER)
231 bprint ("^1",s, "^1 was blasted by ", a, "\n");
232 else if (deathtype == IT_UZI)
233 bprint ("^1",s, "^1 was riddled full of holes by ", a, "\n");
234 else if (deathtype == IT_SHOTGUN)
235 bprint ("^1",s, "^1 was gunned by ", a, "\n");
236 else if (deathtype == IT_GRENADE_LAUNCHER)
237 bprint ("^1", s, "^1 was blasted by ", a, "\n");
238 else if (deathtype == IT_ELECTRO)
239 bprint ("^1",s, "^1 was blasted by ", a, "\n");
240 else if (deathtype == IT_CRYLINK)
241 bprint ("^1",s, "^1 was blasted by ", a, "\n");
242 else if (deathtype == IT_NEX)
243 bprint ("^1",s, "^1 has been vaporized by ", a, "\n");
244 else if (deathtype == IT_HAGAR)
245 bprint ("^1",s, "^1 was pummeled by ", a, "\n");
246 else if (deathtype == IT_ROCKET_LAUNCHER)
247 bprint ("^1",s, "^1 was blasted by ", a, "\n");
248 else if (deathtype == DEATH_TELEFRAG)
249 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
250 else if (deathtype == DEATH_DROWN)
251 bprint ("^1",s, "^1 was drowned by ", a, "\n");
252 else if (deathtype == DEATH_SLIME)
253 bprint ("^1",s, "^1 was slimed by ", a, "\n");
254 else if (deathtype == DEATH_LAVA)
255 bprint ("^1",s, "^1 was cooked by ", a, "\n");
256 else if (deathtype == DEATH_FALL)
257 bprint ("^1",s, "^1 was grounded by ", a, "\n");
258 else if (deathtype == DEATH_SHOOTING_STAR)
259 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
260 else if (deathtype == DEATH_SWAMP)
261 bprint ("^1",s, "^1 was conserved by ", a, "\n");
262 else if (deathtype == DEATH_HURTTRIGGER)
263 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
265 bprint ("^1",s, "^1 was fragged by ", a, "\n");
267 GiveFrags(attacker, targ, 1);
268 if (targ.killcount > 2)
269 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
270 attacker.killcount = attacker.killcount + 1;
271 if (attacker.killcount > 2)
272 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
274 LogDeath("frag", deathtype, attacker, targ);
276 if (attacker.killcount == 3)
278 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
279 announce(attacker, "announcer/male/03kills.ogg");
281 else if (attacker.killcount == 5)
283 bprint (a,"^7 unleashes ^1RAGE\n");
284 announce(attacker, "announcer/male/05kills.ogg");
286 else if (attacker.killcount == 10)
288 bprint (a,"^7 starts the ^1MASSACRE!\n");
289 announce(attacker, "announcer/male/10kills.ogg");
291 else if (attacker.killcount == 15)
293 bprint (a,"^7 executes ^1MAYHEM!\n");
294 announce(attacker, "announcer/male/15kills.ogg");
296 else if (attacker.killcount == 20)
298 bprint (a,"^7 is a ^1BERSERKER!\n");
299 announce(attacker, "announcer/male/20kills.ogg");
301 else if (attacker.killcount == 25)
303 bprint (a,"^7 inflicts ^1CARNAGE!\n");
304 announce(attacker, "announcer/male/25kills.ogg");
306 else if (attacker.killcount == 30)
308 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
309 announce(attacker, "announcer/male/30kills.ogg");
315 centerprint(targ, "^1Watch your step!\n\n\n");
316 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
317 bprint ("^1",s, "^1 ", attacker.message, "\n");
318 else if (deathtype == DEATH_DROWN)
319 bprint ("^1",s, "^1 drowned\n");
320 else if (deathtype == DEATH_SLIME)
321 bprint ("^1",s, "^1 was slimed\n");
322 else if (deathtype == DEATH_LAVA)
323 bprint ("^1",s, "^1 turned into hot slag\n");
324 else if (deathtype == DEATH_FALL)
325 bprint ("^1",s, "^1 hit the ground with a crunch\n");
326 else if (deathtype == DEATH_SHOOTING_STAR)
327 bprint ("^1",s, "^1 became a shooting star\n");
328 else if (deathtype == DEATH_SWAMP)
329 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
331 bprint ("^1",s, "^1 died\n");
332 GiveFrags(targ, targ, -1);
333 if(targ.frags == -5) {
334 announce(targ, "announcer/male/botlike.ogg");
337 if (targ.killcount > 2)
338 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
340 LogDeath("accident", deathtype, targ, targ);
342 targ.death_origin = targ.origin;
344 targ.killer_origin = attacker.origin;
345 // FIXME: this should go in PutClientInServer
351 // these are updated by each Damage call for use in button triggering and such
353 entity damage_inflictor;
354 entity damage_attacker;
356 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
360 entity attacker_save;
364 if (gameover || targ.killcount == -666)
367 local entity oldself;
371 damage_inflictor = inflictor;
372 damage_attacker = attacker;
373 attacker_save = attacker;
375 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
377 // These are ALWAYS lethal
378 // No damage modification here
379 // Instead, prepare the victim for his death...
381 targ.spawnshieldtime = 0;
383 targ.flags -= targ.flags & FL_GODMODE;
388 if (targ.classname == "player")
389 if (attacker.classname == "player")
392 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
394 // nullify damage if teamplay is on
395 if(deathtype != DEATH_TELEFRAG)
396 if(attacker.team == targ.team)
397 if(attacker.classname == "player")
401 else if(attacker != targ)
405 else if(teamplay == 4)
407 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
409 mirrordamage = cvar("g_mirrordamage") * damage;
410 mirrorforce = cvar("g_mirrordamage") * vlen(force);
413 if(cvar("g_friendlyfire") == 0)
417 damage = cvar("g_friendlyfire") * damage;
418 // mirrordamage will be used LATER
427 if(targ.classname == "player")
428 if(attacker.classname == "player")
431 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
432 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
438 if(targ.classname == "player")
440 attacker.hitsound += 1;
444 if ((deathtype == DEATH_FALL) ||
445 (deathtype == DEATH_DROWN) ||
446 (deathtype == DEATH_SLIME) ||
447 (deathtype == DEATH_LAVA))
449 if (targ.armorvalue && (deathtype == IT_NEX) && damage)
451 targ.armorvalue -= 1;
452 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
456 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
458 if(clienttype(attacker) == CLIENTTYPE_REAL)
459 if(IsDifferentTeam(targ, attacker))
462 if (deathtype == IT_LASER)
465 if (targ != attacker)
467 if (targ.classname == "player")
468 centerprint(attacker, "Secondary fire inflicts no damage!\n");
478 if(targ.takedamage == DAMAGE_AIM)
480 if(IsDifferentTeam(targ, attacker))
484 // apply strength multiplier
485 if (attacker.items & IT_STRENGTH && !g_minstagib)
487 damage = damage * cvar("g_balance_powerup_strength_damage");
488 force = force * cvar("g_balance_powerup_strength_force");
490 // apply invincibility multiplier
491 if (targ.items & IT_INVINCIBLE && !g_minstagib)
492 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
497 // apply strength rune
498 if (attacker.runes & RUNE_STRENGTH)
500 if(attacker.runes & CURSE_WEAK) // have both curse & rune
502 damage = damage * cvar("g_balance_rune_strength_combo_damage");
503 force = force * cvar("g_balance_rune_strength_combo_force");
507 damage = damage * cvar("g_balance_rune_strength_damage");
508 force = force * cvar("g_balance_rune_strength_force");
511 else if (attacker.runes & CURSE_WEAK)
513 damage = damage * cvar("g_balance_curse_weak_damage");
514 force = force * cvar("g_balance_curse_weak_force");
517 // apply defense rune
518 if (targ.runes & RUNE_DEFENSE)
520 if (targ.runes & CURSE_VULNER) // have both curse & rune
521 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
523 damage = damage * cvar("g_balance_rune_defense_takedamage");
525 else if (targ.runes & CURSE_VULNER)
526 damage = damage * cvar("g_balance_curse_vulner_takedamage");
531 if (self.damageforcescale)
534 self.velocity = self.velocity + self.damageforcescale * force;
535 self.flags = self.flags - (self.flags & FL_ONGROUND);
538 if (self.event_damage)
539 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
542 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
544 // Savage: vampire mode
548 if (time > self.spawnshieldtime)
550 attacker.health += damage;
554 if (attacker.runes & RUNE_VAMPIRE)
556 // apply vampire rune
557 if (attacker.runes & CURSE_EMPATHY) // have the curse too
559 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
560 attacker.health = bound(
561 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
562 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
563 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
567 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
568 attacker.health = bound(
569 attacker.health, // LA: was 3, but changed so that you can't lose health
570 // empathy won't let you gain health in the same way...
571 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
572 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
575 // apply empathy curse
576 else if (attacker.runes & CURSE_EMPATHY)
578 attacker.health = bound(
579 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
580 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
586 // apply mirror damage if any
587 if(mirrordamage > 0 || mirrorforce > 0)
589 attacker = attacker_save;
593 // just lose extra LIVES, don't kill the player for mirror damage
594 if(attacker.armorvalue > 0)
596 attacker.armorvalue = attacker.armorvalue - 1;
597 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
598 attacker.hitsound += 1;
602 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
603 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
607 vector NearestPointOnBox(entity box, vector org)
609 vector m1, m2, nearest;
611 m1 = box.mins + box.origin;
612 m2 = box.maxs + box.origin;
614 nearest_x = bound(m1_x, org_x, m2_x);
615 nearest_y = bound(m1_y, org_y, m2_y);
616 nearest_z = bound(m1_z, org_z, m2_z);
621 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
622 // Returns total damage applies to creatures
632 float total_damage_to_creatures;
634 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
635 total_damage_to_creatures = 0;
637 targ = findradius (blastorigin, rad);
640 if (targ != inflictor)
643 // LordHavoc: measure distance to nearest point on target (not origin)
644 // (this guarentees 100% damage on a touch impact)
645 nearest = NearestPointOnBox(targ, blastorigin);
646 diff = nearest - blastorigin;
647 // round up a little on the damage to ensure full damage on impacts
648 // and turn the distance into a fraction of the radius
649 power = 1 - ((vlen (diff) - 2) / rad);
651 //bprint(ftos(power));
656 finaldmg = coredamage * power + edgedamage * (1 - power);
659 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
660 // if it's a player, use the view origin as reference
661 if (targ.classname == "player")
662 center = targ.origin + targ.view_ofs;
663 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
664 if (targ == attacker)
665 finaldmg = finaldmg * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
666 // test line of sight to multiple positions on box,
667 // and do damage if any of them hit
669 c = ceil(finaldmg / 10);
675 traceline(blastorigin, nearest, TRUE, inflictor);
676 if (trace_fraction == 1 || trace_ent == targ
677 || cvar("g_throughfloor"))
680 total_damage_to_creatures += finaldmg;
681 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
684 nearest_x = targ.mins_x + random() * targ.size_x;
685 nearest_y = targ.mins_y + random() * targ.size_y;
686 nearest_z = targ.mins_z + random() * targ.size_z;
694 return total_damage_to_creatures;