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)
24 float IsFlying(entity a)
26 if(a.flags & FL_ONGROUND)
30 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
31 if(trace_fraction < 1)
36 void(entity player, float f) UpdateFrags =
39 player.totalfrags += f;
42 void GiveFrags (entity attacker, entity targ, float f)
47 if(cvar("g_arena_roundbased"))
52 if(cvar("g_domination_disable_frags"))
59 f = RunematchHandleFrags(attacker, targ, f);
63 f = kh_HandleFrags(attacker, targ, f);
67 // count remaining lives, not frags in lms
69 // keep track of the worst players lives
70 if(targ.frags < lms_lowest_lives)
71 lms_lowest_lives = targ.frags;
72 // player has no more lives left
76 lms_next_place = player_count;
77 targ.frags = -lms_next_place;
84 UpdateFrags(attacker, f);
87 string AppendItemcodes(string s, entity player)
92 // w = player.switchweapon;
94 w = player.cnt; // previous weapon!
95 s = strcat(s, ftos(W_ItemCode(w)));
96 if(time < player.strength_finished)
98 if(time < player.invincible_finished)
100 if(player.flagcarried != world)
102 if(player.buttonchat)
107 s = strcat(s, "|", ftos(player.runes));
111 void LogDeath(string mode, float deathtype, entity killer, entity killed)
114 if(!cvar("sv_eventlog"))
116 s = strcat(":kill:", mode);
117 s = strcat(s, ":", ftos(killer.playerid));
118 s = strcat(s, ":", ftos(killed.playerid));
119 s = strcat(s, ":type=", ftos(deathtype));
120 s = strcat(s, ":items=");
121 s = AppendItemcodes(s, killer);
124 s = strcat(s, ":victimitems=");
125 s = AppendItemcodes(s, killed);
127 GameLogEcho(s, FALSE);
130 void Obituary (entity attacker, entity targ, float deathtype)
134 if (targ.classname == "player" || targ.classname == "corpse")
136 if (targ.classname == "corpse")
140 a = attacker.netname;
142 if (targ == attacker)
144 if (deathtype == DEATH_TEAMCHANGE)
146 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
148 else if (deathtype == DEATH_AUTOTEAMCHANGE)
150 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
153 else if (deathtype == DEATH_CAMP)
154 centerprint(targ, "^1Die camper!\n\n\n");
155 else if (deathtype == DEATH_NOAMMO)
156 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
157 else if (deathtype == DEATH_ROT)
158 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
159 else if (deathtype == DEATH_MIRRORDAMAGE)
160 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
162 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
164 if (deathtype == IT_GRENADE_LAUNCHER)
165 bprint ("^1",s, "^1 detonated\n");
166 else if (deathtype == IT_ELECTRO)
167 bprint ("^1",s, "^1 played with plasma\n");
168 else if (deathtype == IT_ROCKET_LAUNCHER)
169 bprint ("^1",s, "^1 exploded\n");
170 else if (deathtype == DEATH_KILL)
171 bprint ("^1",s, "^1 couldn't take it anymore\n");
172 else if (deathtype == DEATH_ROT)
173 bprint ("^1",s, "^1 died\n");
174 else if (deathtype == DEATH_NOAMMO)
176 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
177 //sound (self, CHAN_BODY, "minstagib/mockery.wav", 1, ATTN_NONE);
179 else if (deathtype == DEATH_CAMP)
180 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
181 else if (deathtype == DEATH_MIRRORDAMAGE)
182 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
183 else if (deathtype != DEATH_TEAMCHANGE)
184 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
186 if(deathtype != DEATH_TEAMCHANGE)
188 LogDeath("suicide", deathtype, targ, targ);
189 GiveFrags(attacker, targ, -1);
191 if (targ.killcount > 2)
192 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
194 else if (attacker.classname == "player" || attacker.classname == "gib")
196 if(teamplay && attacker.team == targ.team)
198 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
199 bprint ("^1", a, "^1 mows down a teammate\n");
200 GiveFrags(attacker, targ, -1);
201 if (targ.killcount > 2)
202 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
203 if (attacker.killcount > 2)
204 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
205 attacker.killcount = 0;
207 LogDeath("tk", deathtype, attacker, targ);
211 if (!checkrules_firstblood)
213 checkrules_firstblood = TRUE;
214 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
216 //sound(world, CHAN_AUTO, "announce/male/mapkill1.wav", 1, ATTN_NONE);
217 bprint("^1",a, "^1 drew first blood", "\n");
220 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
221 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
223 if (deathtype == IT_LASER)
224 bprint ("^1",s, "^1 was blasted by ", a, "\n");
225 else if (deathtype == IT_UZI)
226 bprint ("^1",s, "^1 was riddled full of holes by ", a, "\n");
227 else if (deathtype == IT_SHOTGUN)
228 bprint ("^1",s, "^1 was gunned by ", a, "\n");
229 else if (deathtype == IT_GRENADE_LAUNCHER)
230 bprint ("^1", s, "^1 was blasted by ", a, "\n");
231 else if (deathtype == IT_ELECTRO)
232 bprint ("^1",s, "^1 was blasted by ", a, "\n");
233 else if (deathtype == IT_CRYLINK)
234 bprint ("^1",s, "^1 was blasted by ", a, "\n");
235 else if (deathtype == IT_NEX)
236 bprint ("^1",s, "^1 has been vaporized by ", a, "\n");
237 else if (deathtype == IT_HAGAR)
238 bprint ("^1",s, "^1 was pummeled by ", a, "\n");
239 else if (deathtype == IT_ROCKET_LAUNCHER)
240 bprint ("^1",s, "^1 was blasted by ", a, "\n");
241 else if (deathtype == DEATH_TELEFRAG)
242 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
243 else if (deathtype == DEATH_DROWN)
244 bprint ("^1",s, "^1 was drowned by ", a, "\n");
245 else if (deathtype == DEATH_SLIME)
246 bprint ("^1",s, "^1 was slimed by ", a, "\n");
247 else if (deathtype == DEATH_LAVA)
248 bprint ("^1",s, "^1 was cooked by ", a, "\n");
249 else if (deathtype == DEATH_FALL)
250 bprint ("^1",s, "^1 was grounded by ", a, "\n");
251 else if (deathtype == DEATH_SHOOTING_STAR)
252 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
253 else if (deathtype == DEATH_SWAMP)
254 bprint ("^1",s, "^1 was conserved by ", a, "\n");
255 else if (deathtype == DEATH_HURTTRIGGER)
256 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
258 bprint ("^1",s, "^1 was fragged by ", a, "\n");
260 GiveFrags(attacker, targ, 1);
261 if (targ.killcount > 2)
262 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
263 attacker.killcount = attacker.killcount + 1;
264 if (attacker.killcount > 2)
265 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
267 LogDeath("frag", deathtype, attacker, targ);
269 if (attacker.killcount == 3)
271 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
272 announce(attacker, "announcer/male/03kills.ogg");
274 else if (attacker.killcount == 5)
276 bprint (a,"^7 made a ^1FIVE FRAG COMBO\n");
277 announce(attacker, "announcer/male/05kills.ogg");
279 else if (attacker.killcount == 10)
281 bprint (a,"^7 is on a ^1RAGE\n");
282 announce(attacker, "announcer/male/10kills.ogg");
284 else if (attacker.killcount == 15)
286 bprint (a,"^7 has done a ^1MASSACRE!\n");
287 announce(attacker, "announcer/male/15kills.ogg");
289 else if (attacker.killcount == 20)
291 bprint (a,"^7 is ^1UNHUMAN!\n");
292 announce(attacker, "announcer/male/20kills.ogg");
294 else if (attacker.killcount == 25)
296 bprint (a,"^7 is a ^1DEATH INCARNATION!\n");
297 announce(attacker, "announcer/male/25kills.ogg");
299 else if (attacker.killcount == 30)
301 bprint (a,"^7 is maybe a ^1AIMBOTTER?!\n");
302 announce(attacker, "announcer/male/30kills.ogg");
308 centerprint(targ, "^1Watch your step!\n\n\n");
309 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
310 bprint ("^1",s, "^1 ", attacker.message, "\n");
311 else if (deathtype == DEATH_DROWN)
312 bprint ("^1",s, "^1 drowned\n");
313 else if (deathtype == DEATH_SLIME)
314 bprint ("^1",s, "^1 was slimed\n");
315 else if (deathtype == DEATH_LAVA)
316 bprint ("^1",s, "^1 turned into hot slag\n");
317 else if (deathtype == DEATH_FALL)
318 bprint ("^1",s, "^1 hit the ground with a crunch\n");
319 else if (deathtype == DEATH_SHOOTING_STAR)
320 bprint ("^1",s, "^1 became a shooting star\n");
321 else if (deathtype == DEATH_SWAMP)
322 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
324 bprint ("^1",s, "^1 died\n");
325 GiveFrags(targ, targ, -1);
326 if(targ.frags == -5) {
327 announce(targ, "announcer/male/botlike.ogg");
330 if (targ.killcount > 2)
331 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
333 LogDeath("accident", deathtype, targ, targ);
335 targ.death_origin = targ.origin;
337 targ.killer_origin = attacker.origin;
338 // FIXME: this should go in PutClientInServer
344 // these are updated by each Damage call for use in button triggering and such
346 entity damage_inflictor;
347 entity damage_attacker;
349 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
353 entity attacker_save;
357 if (gameover || targ.killcount == -666)
360 local entity oldself;
364 damage_inflictor = inflictor;
365 damage_attacker = attacker;
366 attacker_save = attacker;
368 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
370 // These are ALWAYS lethal
371 // No damage modification here
372 // Instead, prepare the victim for his death...
374 targ.spawnshieldtime = 0;
376 targ.flags -= targ.flags & FL_GODMODE;
381 if (targ.classname == "player")
382 if (attacker.classname == "player")
385 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
387 // nullify damage if teamplay is on
388 if(deathtype != DEATH_TELEFRAG)
389 if(attacker.team == targ.team)
390 if(attacker.classname == "player")
394 else if(attacker != targ)
398 else if(teamplay == 4)
400 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
402 mirrordamage = cvar("g_mirrordamage") * damage;
403 mirrorforce = cvar("g_mirrordamage") * vlen(force);
406 if(cvar("g_friendlyfire") == 0)
410 damage = cvar("g_friendlyfire") * damage;
411 // mirrordamage will be used LATER
420 if(targ.classname == "player")
421 if(attacker.classname == "player")
424 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
425 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
431 if(targ.classname == "player")
433 attacker.hitsound += 1;
437 if ((deathtype == DEATH_FALL) ||
438 (deathtype == DEATH_DROWN) ||
439 (deathtype == DEATH_SLIME) ||
440 (deathtype == DEATH_LAVA))
442 if (targ.armorvalue && (deathtype == IT_NEX) && damage)
444 targ.armorvalue -= 1;
445 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
449 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
451 if(clienttype(attacker) == CLIENTTYPE_REAL)
452 if(IsDifferentTeam(self, attacker))
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 ();