2 float checkrules_firstblood;
6 void announce(entity player, string msg)
8 if(time > player.announcetime)
10 player.announcetime = time + 0.3;
15 float IsDifferentTeam(entity a, entity b)
23 float IsFlying(entity a)
25 if(a.flags & FL_ONGROUND)
29 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
30 if(trace_fraction < 1)
35 void(entity player, float f) UpdateFrags =
38 player.totalfrags += f;
41 void GiveFrags (entity attacker, entity targ, float f)
46 if(cvar("g_arena_roundbased"))
51 if(cvar("g_domination_disable_frags"))
58 f = RunematchHandleFrags(attacker, targ, f);
62 f = kh_HandleFrags(attacker, targ, f);
66 // count remaining lives, not frags in lms
68 // keep track of the worst players lives
69 if(targ.frags < lms_lowest_lives)
70 lms_lowest_lives = targ.frags;
71 // player has no more lives left
75 lms_next_place = player_count;
76 targ.frags = -lms_next_place;
83 UpdateFrags(attacker, f);
86 string AppendItemcodes(string s, entity player)
91 // w = player.switchweapon;
93 w = player.cnt; // previous weapon!
94 s = strcat(s, ftos(W_ItemCode(w)));
95 if(time < player.strength_finished)
97 if(time < player.invincible_finished)
99 if(player.flagcarried != world)
101 if(player.buttonchat)
106 s = strcat(s, "|", ftos(player.runes));
110 void LogDeath(string mode, float deathtype, entity killer, entity killed)
113 if(!cvar("sv_eventlog"))
115 s = strcat(":kill:", mode);
116 s = strcat(s, ":", ftos(killer.playerid));
117 s = strcat(s, ":", ftos(killed.playerid));
118 s = strcat(s, ":type=", ftos(deathtype));
119 s = strcat(s, ":items=");
120 s = AppendItemcodes(s, killer);
123 s = strcat(s, ":victimitems=");
124 s = AppendItemcodes(s, killed);
126 GameLogEcho(s, FALSE);
129 void Obituary (entity attacker, entity targ, float deathtype)
133 if (targ.classname == "player" || targ.classname == "corpse")
135 if (targ.classname == "corpse")
139 a = attacker.netname;
141 if (targ == attacker)
143 if (deathtype == DEATH_TEAMCHANGE)
145 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
147 else if (deathtype == DEATH_AUTOTEAMCHANGE)
149 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
152 else if (deathtype == DEATH_CAMP)
153 centerprint(targ, "^1Die camper!\n\n\n");
154 else if (deathtype == DEATH_NOAMMO)
155 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
156 else if (deathtype == DEATH_ROT)
157 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
158 else if (deathtype == DEATH_MIRRORDAMAGE)
159 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
161 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
163 if (deathtype == IT_GRENADE_LAUNCHER)
164 bprint ("^1",s, "^1 detonated\n");
165 else if (deathtype == IT_ELECTRO)
166 bprint ("^1",s, "^1 played with plasma\n");
167 else if (deathtype == IT_ROCKET_LAUNCHER)
168 bprint ("^1",s, "^1 exploded\n");
169 else if (deathtype == DEATH_KILL)
170 bprint ("^1",s, "^1 couldn't take it anymore\n");
171 else if (deathtype == DEATH_ROT)
172 bprint ("^1",s, "^1 died\n");
173 else if (deathtype == DEATH_NOAMMO)
175 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
176 //sound (self, CHAN_BODY, "minstagib/mockery.wav", 1, ATTN_NONE);
178 else if (deathtype == DEATH_CAMP)
179 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
180 else if (deathtype == DEATH_MIRRORDAMAGE)
181 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
182 else if (deathtype != DEATH_TEAMCHANGE)
183 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
185 if(deathtype != DEATH_TEAMCHANGE)
187 LogDeath("suicide", deathtype, targ, targ);
188 GiveFrags(attacker, targ, -1);
190 if (targ.killcount > 2)
191 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
193 else if (attacker.classname == "player" || attacker.classname == "gib")
195 if(teamplay && attacker.team == targ.team)
197 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
198 bprint ("^1", a, "^1 mows down a teammate\n");
199 GiveFrags(attacker, targ, -1);
200 if (targ.killcount > 2)
201 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
202 if (attacker.killcount > 2)
203 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
204 attacker.killcount = 0;
206 LogDeath("tk", deathtype, attacker, targ);
210 if (!checkrules_firstblood)
212 checkrules_firstblood = TRUE;
213 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
215 //sound(world, CHAN_AUTO, "announce/male/mapkill1.wav", 1, ATTN_NONE);
216 bprint("^1",a, "^1 drew first blood", "\n");
219 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
220 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
222 if (deathtype == IT_LASER)
223 bprint ("^1",s, "^1 was blasted by ", a, "\n");
224 else if (deathtype == IT_UZI)
225 bprint ("^1",s, "^1 was riddled full of holes by ", a, "\n");
226 else if (deathtype == IT_SHOTGUN)
227 bprint ("^1",s, "^1 was gunned by ", a, "\n");
228 else if (deathtype == IT_GRENADE_LAUNCHER)
229 bprint ("^1", s, "^1 was blasted by ", a, "\n");
230 else if (deathtype == IT_ELECTRO)
231 bprint ("^1",s, "^1 was blasted by ", a, "\n");
232 else if (deathtype == IT_CRYLINK)
233 bprint ("^1",s, "^1 was blasted by ", a, "\n");
234 else if (deathtype == IT_NEX)
235 bprint ("^1",s, "^1 has been vaporized by ", a, "\n");
236 else if (deathtype == IT_HAGAR)
237 bprint ("^1",s, "^1 was pummeled by ", a, "\n");
238 else if (deathtype == IT_ROCKET_LAUNCHER)
239 bprint ("^1",s, "^1 was blasted by ", a, "\n");
240 else if (deathtype == DEATH_TELEFRAG)
241 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
242 else if (deathtype == DEATH_DROWN)
243 bprint ("^1",s, "^1 was drowned by ", a, "\n");
244 else if (deathtype == DEATH_SLIME)
245 bprint ("^1",s, "^1 was slimed by ", a, "\n");
246 else if (deathtype == DEATH_LAVA)
247 bprint ("^1",s, "^1 was cooked by ", a, "\n");
248 else if (deathtype == DEATH_FALL)
249 bprint ("^1",s, "^1 was grounded by ", a, "\n");
250 else if (deathtype == DEATH_SHOOTING_STAR)
251 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
252 else if (deathtype == DEATH_SWAMP)
253 bprint ("^1",s, "^1 was conserved by ", a, "\n");
254 else if (deathtype == DEATH_HURTTRIGGER)
255 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
257 bprint ("^1",s, "^1 was fragged by ", a, "\n");
259 GiveFrags(attacker, targ, 1);
260 if (targ.killcount > 2)
261 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
262 attacker.killcount = attacker.killcount + 1;
263 if (attacker.killcount > 2)
264 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
266 LogDeath("frag", deathtype, attacker, targ);
268 if (attacker.killcount == 3)
270 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
271 announce(attacker, "announcer/male/03kills.ogg");
273 else if (attacker.killcount == 5)
275 bprint (a,"^7 made a ^1FIVE FRAG COMBO\n");
276 announce(attacker, "announcer/male/05kills.ogg");
278 else if (attacker.killcount == 10)
280 bprint (a,"^7 is on a ^1RAGE\n");
281 announce(attacker, "announcer/male/10kills.ogg");
283 else if (attacker.killcount == 15)
285 bprint (a,"^7 has done a ^1MASSACRE!\n");
286 announce(attacker, "announcer/male/15kills.ogg");
288 else if (attacker.killcount == 20)
290 bprint (a,"^7 is ^1UNHUMAN!\n");
291 announce(attacker, "announcer/male/20kills.ogg");
293 else if (attacker.killcount == 25)
295 bprint (a,"^7 is a ^1DEATH INCARNATION!\n");
296 announce(attacker, "announcer/male/25kills.ogg");
298 else if (attacker.killcount == 30)
300 bprint (a,"^7 is maybe a ^1AIMBOTTER?!\n");
301 announce(attacker, "announcer/male/30kills.ogg");
307 centerprint(targ, "^1Watch your step!\n\n\n");
308 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
309 bprint ("^1",s, "^1 ", attacker.message, "\n");
310 else if (deathtype == DEATH_DROWN)
311 bprint ("^1",s, "^1 drowned\n");
312 else if (deathtype == DEATH_SLIME)
313 bprint ("^1",s, "^1 was slimed\n");
314 else if (deathtype == DEATH_LAVA)
315 bprint ("^1",s, "^1 turned into hot slag\n");
316 else if (deathtype == DEATH_FALL)
317 bprint ("^1",s, "^1 hit the ground with a crunch\n");
318 else if (deathtype == DEATH_SHOOTING_STAR)
319 bprint ("^1",s, "^1 became a shooting star\n");
320 else if (deathtype == DEATH_SWAMP)
321 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
323 bprint ("^1",s, "^1 died\n");
324 GiveFrags(targ, targ, -1);
325 if(targ.frags == -5) {
326 announce(targ, "announcer/male/botlike.ogg");
329 if (targ.killcount > 2)
330 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
332 LogDeath("accident", deathtype, targ, targ);
334 targ.death_origin = targ.origin;
336 targ.killer_origin = attacker.origin;
337 // FIXME: this should go in PutClientInServer
343 // these are updated by each Damage call for use in button triggering and such
345 entity damage_inflictor;
346 entity damage_attacker;
348 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
352 entity attacker_save;
356 if (gameover || targ.killcount == -666)
359 local entity oldself;
363 damage_inflictor = inflictor;
364 damage_attacker = attacker;
365 attacker_save = attacker;
367 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
369 // These are ALWAYS lethal
370 // No damage modification here
371 // Instead, prepare the victim for his death...
373 targ.spawnshieldtime = 0;
375 targ.flags -= targ.flags & FL_GODMODE;
380 if (targ.classname == "player")
381 if (attacker.classname == "player")
384 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
386 // nullify damage if teamplay is on
387 if(deathtype != DEATH_TELEFRAG)
388 if(attacker.team == targ.team)
389 if(attacker.classname == "player")
393 else if(attacker != targ)
397 else if(teamplay == 4)
399 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
401 mirrordamage = cvar("g_mirrordamage") * damage;
402 mirrorforce = cvar("g_mirrordamage") * vlen(force);
405 if(cvar("g_friendlyfire") == 0)
409 damage = cvar("g_friendlyfire") * damage;
410 // mirrordamage will be used LATER
419 if(targ.classname == "player")
420 if(attacker.classname == "player")
423 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
424 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
430 if(targ.classname == "player")
432 attacker.hitsound += 1;
436 if ((deathtype == DEATH_FALL) ||
437 (deathtype == DEATH_DROWN) ||
438 (deathtype == DEATH_SLIME) ||
439 (deathtype == DEATH_LAVA))
441 if (targ.armorvalue && (deathtype == IT_NEX) && damage)
443 targ.armorvalue -= 1;
444 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
448 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
450 if(clienttype(attacker) == CLIENTTYPE_REAL)
452 announce(attacker, "announcer/male/yoda.ogg");
455 if (deathtype == IT_LASER)
458 if (targ != attacker)
460 if (targ.classname == "player")
461 centerprint(attacker, "Secondary fire inflicts no damage!\n");
472 if(IsDifferentTeam(self, targ))
476 // apply strength multiplier
477 if (attacker.items & IT_STRENGTH && !g_minstagib)
479 damage = damage * cvar("g_balance_powerup_strength_damage");
480 force = force * cvar("g_balance_powerup_strength_force");
482 // apply invincibility multiplier
483 if (targ.items & IT_INVINCIBLE && !g_minstagib)
484 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
489 // apply strength rune
490 if (attacker.runes & RUNE_STRENGTH)
492 if(attacker.runes & CURSE_WEAK) // have both curse & rune
494 damage = damage * cvar("g_balance_rune_strength_combo_damage");
495 force = force * cvar("g_balance_rune_strength_combo_force");
499 damage = damage * cvar("g_balance_rune_strength_damage");
500 force = force * cvar("g_balance_rune_strength_force");
503 else if (attacker.runes & CURSE_WEAK)
505 damage = damage * cvar("g_balance_curse_weak_damage");
506 force = force * cvar("g_balance_curse_weak_force");
509 // apply defense rune
510 if (targ.runes & RUNE_DEFENSE)
512 if (targ.runes & CURSE_VULNER) // have both curse & rune
513 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
515 damage = damage * cvar("g_balance_rune_defense_takedamage");
517 else if (targ.runes & CURSE_VULNER)
518 damage = damage * cvar("g_balance_curse_vulner_takedamage");
523 if (self.damageforcescale)
525 self.velocity = self.velocity + self.damageforcescale * force;
526 self.flags = self.flags - (self.flags & FL_ONGROUND);
529 if (self.event_damage)
530 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
533 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
535 // Savage: vampire mode
536 if(g_vampire && !g_minstagib)
538 attacker.health += damage;
542 if (attacker.runes & RUNE_VAMPIRE)
544 // apply vampire rune
545 if (attacker.runes & CURSE_EMPATHY) // have the curse too
547 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
548 attacker.health = bound(
549 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
550 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
551 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
555 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
556 attacker.health = bound(
557 attacker.health, // LA: was 3, but changed so that you can't lose health
558 // empathy won't let you gain health in the same way...
559 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
560 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
563 // apply empathy curse
564 else if (attacker.runes & CURSE_EMPATHY)
566 attacker.health = bound(
567 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
568 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
574 // apply mirror damage if any
575 if(mirrordamage > 0 || mirrorforce > 0)
577 attacker = attacker_save;
581 // just lose extra LIVES, don't kill the player for mirror damage
582 if(attacker.armorvalue > 0)
584 attacker.armorvalue = attacker.armorvalue - 1;
585 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
586 attacker.hitsound += 1;
590 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
591 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
595 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
596 // Returns total damage applies to creatures
608 float total_damage_to_creatures;
610 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
611 total_damage_to_creatures = 0;
613 targ = findradius (blastorigin, rad);
616 if (targ != inflictor)
619 // LordHavoc: measure distance to nearest point on target (not origin)
620 // (this guarentees 100% damage on a touch impact)
621 nearest = blastorigin;
622 m1 = targ.origin + targ.mins;
623 m2 = targ.origin + targ.maxs;
624 if (nearest_x < m1_x) nearest_x = m1_x;
625 if (nearest_y < m1_y) nearest_y = m1_y;
626 if (nearest_z < m1_z) nearest_z = m1_z;
627 if (nearest_x > m2_x) nearest_x = m2_x;
628 if (nearest_y > m2_y) nearest_y = m2_y;
629 if (nearest_z > m2_z) nearest_z = m2_z;
630 diff = nearest - blastorigin;
631 // round up a little on the damage to ensure full damage on impacts
632 // and turn the distance into a fraction of the radius
633 power = 1 - ((vlen (diff) - 2) / rad);
635 //bprint(ftos(power));
640 finaldmg = coredamage * power + edgedamage * (1 - power);
643 center = (m1 + m2) * 0.5;
644 // if it's a player, use the view origin as reference
645 if (targ.classname == "player")
646 center = targ.origin + targ.view_ofs;
647 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
648 if (targ == attacker)
649 finaldmg = finaldmg * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
650 // test line of sight to multiple positions on box,
651 // and do damage if any of them hit
653 c = ceil(finaldmg / 10);
659 traceline(blastorigin, nearest, TRUE, inflictor);
660 if (trace_fraction == 1 || trace_ent == targ
661 || cvar("g_throughfloor"))
664 total_damage_to_creatures += finaldmg;
665 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
668 nearest_x = m1_x + random() * targ.size_x;
669 nearest_y = m1_y + random() * targ.size_y;
670 nearest_z = m1_z + random() * targ.size_z;
678 return total_damage_to_creatures;
686 void ClearMultiDamage (void)
690 multi_force = '0 0 0';
693 void ApplyMultiDamage (void)
698 Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
701 void AddMultiDamage (entity hit, float damage, vector force)
706 if (hit != multi_ent)
712 multi_damage = multi_damage + damage;
713 multi_force = multi_force + force;
716 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
723 makevectors (self.v_angle);
725 source = self.origin + v_forward * 10; // FIXME
726 source_x = self.absmin_z + self.size_z * 0.7; // ??? whaddabout view_ofs
728 // LordHavoc: better to use normal damage
729 //ClearMultiDamage ();
730 while (shotcount > 0)
732 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
734 traceline (source, source + direction * 2048, FALSE, self);
735 if (trace_fraction != 1.0)
737 vel = normalize (direction + v_up * crandom () + v_right * crandom ());
738 vel = vel + 2 * trace_plane_normal;
741 org = trace_endpos - direction * 4;
743 if (!trace_ent.takedamage)
745 // LordHavoc: better to use normal damage
746 //AddMultiDamage (trace_ent, 4, direction * 4);
747 Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
750 shotcount = shotcount + 1;
753 // LordHavoc: better to use normal damage
754 //ApplyMultiDamage ();