6 float Damage_DamageInfo_SendEntity(entity to, float sf)
8 WriteByte(MSG_ENTITY, ENT_CLIENT_DAMAGEINFO);
9 WriteShort(MSG_ENTITY, self.projectiledeathtype);
10 WriteCoord(MSG_ENTITY, floor(self.origin_x));
11 WriteCoord(MSG_ENTITY, floor(self.origin_y));
12 WriteCoord(MSG_ENTITY, floor(self.origin_z));
13 WriteByte(MSG_ENTITY, bound(1, self.dmg, 255));
14 WriteByte(MSG_ENTITY, bound(0, self.dmg_radius, 255));
15 WriteByte(MSG_ENTITY, bound(1, self.dmg_edge, 255));
16 WriteShort(MSG_ENTITY, self.oldorigin_x);
20 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, entity dmgowner)
22 // TODO maybe call this from non-edgedamage too?
23 // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
27 if(!sound_allowed(MSG_BROADCAST, dmgowner))
32 e.projectiledeathtype = deathtype;
34 e.dmg_edge = edgedamage;
36 e.dmg_force = vlen(force);
39 e.oldorigin_x = compressShortVector(e.velocity);
41 Net_LinkEntity(e, FALSE, 0.2, Damage_DamageInfo_SendEntity);
44 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
46 float checkrules_firstblood;
49 float damage_goodhits;
50 float damage_gooddamage;
52 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
55 .float teamkill_complain;
56 .float teamkill_soundtime;
57 .entity teamkill_soundsource;
59 .float taunt_soundtime;
62 float IsDifferentTeam(entity a, entity b)
77 float IsFlying(entity a)
79 if(a.flags & FL_ONGROUND)
81 if(a.waterlevel >= WATERLEVEL_SWIMMING)
83 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
84 if(trace_fraction < 1)
89 void UpdateFrags(entity player, float f)
91 PlayerTeamScore_AddScore(player, f);
94 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
95 void W_SwitchWeapon_Force(entity e, float w);
96 void GiveFrags (entity attacker, entity targ, float f)
100 // TODO route through PlayerScores instead
108 PlayerScore_Add(attacker, SP_SUICIDES, 1);
113 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
119 PlayerScore_Add(attacker, SP_KILLS, 1);
122 PlayerScore_Add(targ, SP_DEATHS, 1);
125 if(cvar("g_arena_roundbased"))
128 if(targ != attacker) // not for suicides
129 if(g_weaponarena_random)
131 // after a frag, choose another random weapon set
133 w = warmup_start_weapons;
137 attacker.weapons = randombits(w - (w & W_WeaponBit(attacker.weapon)), g_weaponarena_random, TRUE);
138 if(attacker.weapons < 0)
140 // error from randombits: no weapon available
141 // this means we can just give ALL weapons
142 attacker.weapons = w;
144 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
145 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
148 // FIXME fix the mess this is (we have REAL points now!)
149 frag_attacker = attacker;
152 if(MUTATOR_CALLHOOK(GiveFragsForKill))
158 f = RunematchHandleFrags(attacker, targ, f);
164 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
165 if(tl < lms_lowest_lives)
166 lms_lowest_lives = tl;
170 lms_next_place = player_count;
171 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
178 if(g_ctf_ignore_frags)
182 attacker.totalfrags += f;
185 UpdateFrags(attacker, f);
188 string AppendItemcodes(string s, entity player)
193 // w = player.switchweapon;
195 w = player.cnt; // previous weapon!
196 s = strcat(s, ftos(w));
197 if(time < player.strength_finished)
199 if(time < player.invincible_finished)
201 if(player.flagcarried != world)
203 if(player.BUTTON_CHAT)
208 s = strcat(s, "|", ftos(player.runes));
212 void LogDeath(string mode, float deathtype, entity killer, entity killed)
215 if(!cvar("sv_eventlog"))
217 s = strcat(":kill:", mode);
218 s = strcat(s, ":", ftos(killer.playerid));
219 s = strcat(s, ":", ftos(killed.playerid));
220 s = strcat(s, ":type=", ftos(deathtype));
221 s = strcat(s, ":items=");
222 s = AppendItemcodes(s, killer);
225 s = strcat(s, ":victimitems=");
226 s = AppendItemcodes(s, killed);
231 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
236 if (targ.classname == "player" || targ.classname == "corpse")
238 if (targ.classname == "corpse")
243 a = attacker.netname;
245 if (targ == attacker)
247 if (deathtype == DEATH_TEAMCHANGE) {
248 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
249 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
250 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
252 } else if (deathtype == DEATH_CAMP) {
254 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
256 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
257 } else if (deathtype == DEATH_NOAMMO) {
259 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
261 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
262 } else if (deathtype == DEATH_ROT) {
264 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
266 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
267 } else if (deathtype == DEATH_MIRRORDAMAGE) {
269 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
271 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
272 } else if (deathtype == DEATH_QUIET) {
276 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
278 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
281 if (deathtype == DEATH_CAMP)
282 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
283 else if (deathtype == DEATH_MIRRORDAMAGE)
284 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
286 bprint ("^1",s, "^1 will be reinserted into the game due to their own actions\n");
288 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
290 LogDeath("suicide", deathtype, targ, targ);
291 GiveFrags(attacker, targ, -1);
293 if (targ.killcount > 2)
294 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
296 w = DEATH_WEAPONOF(deathtype);
299 w_deathtypestring = "couldn't resist the urge to self-destruct";
300 w_deathtype = deathtype;
301 weapon_action(w, WR_SUICIDEMESSAGE);
302 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
304 else if (deathtype == DEATH_KILL)
305 bprint ("^1",s, "^1 couldn't take it anymore\n");
306 else if (deathtype == DEATH_ROT)
307 bprint ("^1",s, "^1 died\n");
308 else if (deathtype == DEATH_NOAMMO)
309 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
310 else if (deathtype == DEATH_CAMP)
311 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
312 else if (deathtype == DEATH_MIRRORDAMAGE)
313 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
314 else if (deathtype == DEATH_CHEAT)
315 bprint ("^1",s, "^1 unfairly eliminated themself\n");
316 else if (deathtype == DEATH_FIRE)
317 bprint ("^1",s, "^1 burned to death\n");
318 else if (deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
319 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
321 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
323 LogDeath("suicide", deathtype, targ, targ);
324 GiveFrags(attacker, targ, -1);
326 if (targ.killcount > 2)
327 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
330 else if (attacker.classname == "player" || attacker.classname == "gib")
332 if(teams_matter && attacker.team == targ.team)
335 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
336 bprint ("^1", a, "^1 took action against a team mate\n");
338 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
339 bprint ("^1", a, "^1 mows down a team mate\n");
341 GiveFrags(attacker, targ, -1);
342 if (targ.killcount > 2) {
344 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
346 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
348 if (attacker.killcount > 2) {
350 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
352 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
354 attacker.killcount = 0;
356 LogDeath("tk", deathtype, attacker, targ);
360 string blood_message, victim_message;
361 if (!checkrules_firstblood)
363 checkrules_firstblood = TRUE;
366 bprint("^1",a, "^1 was the first to score", "\n");
367 blood_message = "^1First point\n";
368 //victim_message = "^1First victim\n"; // or First casualty
372 bprint("^1",a, "^1 drew first blood", "\n");
373 blood_message = "^1First blood\n";
374 victim_message = "^1First victim\n"; // or First casualty
378 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You scored against ^7", s, GetAdvancedDeathReports(targ)));
379 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7", GetAdvancedDeathReports(attacker)));
381 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
382 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^1You typefragged ^7", s, GetAdvancedDeathReports(targ)));
383 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typefragged by ^7", a, GetAdvancedDeathReports(attacker)));
385 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s, GetAdvancedDeathReports(targ)));
386 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a, GetAdvancedDeathReports(attacker)));
388 attacker.taunt_soundtime = time + 1;
392 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
394 w = DEATH_WEAPONOF(deathtype);
397 w_deathtypestring = "was blasted by";
398 w_deathtype = deathtype;
399 weapon_action(w, WR_KILLMESSAGE);
400 p = strstrofs(w_deathtypestring, "#", 0);
402 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
404 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
406 else if (deathtype == DEATH_TELEFRAG)
407 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
408 else if (deathtype == DEATH_DROWN)
409 bprint ("^1",s, "^1 was drowned by ", a, "\n");
410 else if (deathtype == DEATH_SLIME)
411 bprint ("^1",s, "^1 was slimed by ", a, "\n");
412 else if (deathtype == DEATH_LAVA)
413 bprint ("^1",s, "^1 was cooked by ", a, "\n");
414 else if (deathtype == DEATH_FALL)
415 bprint ("^1",s, "^1 was grounded by ", a, "\n");
416 else if (deathtype == DEATH_SHOOTING_STAR)
417 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
418 else if (deathtype == DEATH_SWAMP)
419 bprint ("^1",s, "^1 was conserved by ", a, "\n");
420 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
422 p = strstrofs(inflictor.message2, "#", 0);
424 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
426 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
428 else if(deathtype == DEATH_SBCRUSH)
429 bprint ("^1",s, "^1 was crushed by ^1", a, "\n");
430 else if(deathtype == DEATH_SBMINIGUN)
431 bprint ("^1",s, "^1 got shredded by ^1", a, "\n");
432 else if(deathtype == DEATH_SBROCKET)
433 bprint ("^1",s, "^1 was blased to bits by ^1", a, "\n");
434 else if(deathtype == DEATH_SBBLOWUP)
435 bprint ("^1",s, "^1 got cought in the destruction of ^1", a, "'s vehicle\n");
437 else if(deathtype == DEATH_WAKIGUN)
438 bprint ("^1",s, "^1 was bolted down by ^1", a, "\n");
439 else if(deathtype == DEATH_WAKIROCKET)
440 bprint ("^1",s, "^1 could find no shelter from ^1", a, "'s rockets\n");
441 else if(deathtype == DEATH_WAKIBLOWUP)
442 bprint ("^1",s, "^1 dies when ^1", a, "'s wakizashi dies.\n");
444 else if(deathtype == DEATH_TURRET)
445 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
446 else if(deathtype == DEATH_TOUCHEXPLODE)
447 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
448 else if(deathtype == DEATH_CHEAT)
449 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
450 else if (deathtype == DEATH_FIRE)
451 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
452 else if (deathtype == DEATH_CUSTOM)
453 bprint ("^1",s, "^1 ", deathmessage, " by ^1", a, "\n");
455 bprint ("^1",s, "^1 was fragged by ", a, "\n");
458 if(g_ctf && targ.flagcarried)
460 UpdateFrags(attacker, ctf_score_value("score_kill"));
461 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
462 GiveFrags(attacker, targ, 0); // for logging
465 GiveFrags(attacker, targ, 1);
467 if (targ.killcount > 2) {
469 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
471 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
474 attacker.killcount = attacker.killcount + 1;
476 if (attacker.killcount > 2) {
478 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
480 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
483 LogDeath("frag", deathtype, attacker, targ);
485 if (attacker.killcount == 3)
488 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
490 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
491 AnnounceTo(attacker, "03kills");
494 else if (attacker.killcount == 5)
497 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
499 bprint (a,"^7 unleashes ^1RAGE\n");
500 AnnounceTo(attacker, "05kills");
503 else if (attacker.killcount == 10)
506 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
508 bprint (a,"^7 starts the ^1MASSACRE!\n");
509 AnnounceTo(attacker, "10kills");
512 else if (attacker.killcount == 15)
515 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
517 bprint (a,"^7 executes ^1MAYHEM!\n");
518 AnnounceTo(attacker, "15kills");
521 else if (attacker.killcount == 20)
524 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
526 bprint (a,"^7 is a ^1BERSERKER!\n");
527 AnnounceTo(attacker, "20kills");
530 else if (attacker.killcount == 25)
533 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
535 bprint (a,"^7 inflicts ^1CARNAGE!\n");
536 AnnounceTo(attacker, "25kills");
539 else if (attacker.killcount == 30)
542 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
544 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
545 AnnounceTo(attacker, "30kills");
552 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
553 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
554 bprint ("^1",s, "^1 ", inflictor.message, "\n");
555 else if (deathtype == DEATH_DROWN)
557 bprint ("^1",s, "^1 was in the water for too long\n");
559 bprint ("^1",s, "^1 drowned\n");
560 else if (deathtype == DEATH_SLIME)
561 bprint ("^1",s, "^1 was slimed\n");
562 else if (deathtype == DEATH_LAVA)
564 bprint ("^1",s, "^1 found a hot place\n");
566 bprint ("^1",s, "^1 turned into hot slag\n");
567 else if (deathtype == DEATH_FALL)
569 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
571 bprint ("^1",s, "^1 hit the ground with a crunch\n");
572 else if (deathtype == DEATH_SHOOTING_STAR)
573 bprint ("^1",s, "^1 became a shooting star\n");
574 else if (deathtype == DEATH_SWAMP)
576 bprint ("^1",s, "^1 discovered a swamp\n");
578 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
579 else if(deathtype == DEATH_TURRET)
580 bprint ("^1",s, "^1 was mowed down by a turret \n");
581 else if (deathtype == DEATH_CUSTOM)
582 bprint ("^1",s, "^1 ", deathmessage, "\n");
583 else if(deathtype == DEATH_TOUCHEXPLODE)
584 bprint ("^1",s, "^1 died in an accident\n");
585 else if(deathtype == DEATH_CHEAT)
586 bprint ("^1",s, "^1 was unfairly eliminated\n");
587 else if(deathtype == DEATH_FIRE)
589 bprint ("^1",s, "^1 felt a little hot\n");
591 bprint ("^1",s, "^1 burnt to death\n");
594 bprint ("^1",s, "^1 needs a restart\n");
596 bprint ("^1",s, "^1 died\n");
597 GiveFrags(targ, targ, -1);
598 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
599 AnnounceTo(targ, "botlike");
602 if (targ.killcount > 2)
604 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
606 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
608 LogDeath("accident", deathtype, targ, targ);
611 targ.death_origin = targ.origin;
613 targ.killer_origin = attacker.origin;
615 // FIXME: this should go in PutClientInServer
621 // these are updated by each Damage call for use in button triggering and such
623 entity damage_inflictor;
624 entity damage_attacker;
626 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
631 entity attacker_save;
635 if (gameover || targ.killcount == -666)
638 local entity oldself;
642 damage_inflictor = inflictor;
643 damage_attacker = attacker;
644 attacker_save = attacker;
646 if(targ.classname == "player")
649 if(targ.hook.aiment == attacker)
650 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
652 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
653 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
655 if(targ.classname == "player")
656 if not(IsDifferentTeam(targ, attacker))
663 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
665 // These are ALWAYS lethal
666 // No damage modification here
667 // Instead, prepare the victim for his death...
669 targ.spawnshieldtime = 0;
670 targ.health = 0.9; // this is < 1
671 targ.flags -= targ.flags & FL_GODMODE;
674 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
680 if (targ.classname == "player")
681 if (attacker.classname == "player")
684 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
686 // nullify damage if teamplay is on
687 if(deathtype != DEATH_TELEFRAG)
688 if(attacker.classname == "player")
690 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
695 else if(attacker.team == targ.team)
699 else if(attacker != targ)
703 else if(teamplay == 4)
705 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
707 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
708 attacker.dmg_team = attacker.dmg_team + damage;
709 if(attacker.dmg_team > teamdamage0 && !g_ca)
710 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
711 mirrorforce = cvar("g_mirrordamage") * vlen(force);
714 if(cvar("g_friendlyfire") == 0)
720 damage = cvar("g_friendlyfire") * damage;
721 // mirrordamage will be used LATER
730 if(targ.classname == "player")
731 if(attacker.classname == "player")
734 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
735 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
738 if(targ.classname == "player")
741 if ((deathtype == DEATH_FALL) ||
742 (deathtype == DEATH_DROWN) ||
743 (deathtype == DEATH_SLIME) ||
744 (deathtype == DEATH_LAVA) ||
745 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
752 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
754 targ.armorvalue -= 1;
755 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
758 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
760 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
763 if (targ != attacker)
765 if ((targ.health >= 1) && (targ.classname == "player"))
766 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
776 if not(DEATH_ISSPECIAL(deathtype))
778 damage *= g_weapondamagefactor;
779 mirrordamage *= g_weapondamagefactor;
780 force = force * g_weaponforcefactor;
781 mirrorforce *= g_weaponforcefactor;
784 // apply strength multiplier
785 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
789 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
790 force = force * cvar("g_balance_powerup_strength_selfforce");
794 damage = damage * cvar("g_balance_powerup_strength_damage");
795 force = force * cvar("g_balance_powerup_strength_force");
799 // apply invincibility multiplier
800 if (targ.items & IT_INVINCIBLE && !g_minstagib)
801 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
803 if (targ == attacker)
805 if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))
808 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
811 // CTF: reduce damage/force
816 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
817 force = force * cvar("g_ctf_flagcarrier_selfforce");
822 // apply strength rune
823 if (attacker.runes & RUNE_STRENGTH)
825 if(attacker.runes & CURSE_WEAK) // have both curse & rune
827 damage = damage * cvar("g_balance_rune_strength_combo_damage");
828 force = force * cvar("g_balance_rune_strength_combo_force");
832 damage = damage * cvar("g_balance_rune_strength_damage");
833 force = force * cvar("g_balance_rune_strength_force");
836 else if (attacker.runes & CURSE_WEAK)
838 damage = damage * cvar("g_balance_curse_weak_damage");
839 force = force * cvar("g_balance_curse_weak_force");
842 // apply defense rune
843 if (targ.runes & RUNE_DEFENSE)
845 if (targ.runes & CURSE_VULNER) // have both curse & rune
846 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
848 damage = damage * cvar("g_balance_rune_defense_takedamage");
850 else if (targ.runes & CURSE_VULNER)
851 damage = damage * cvar("g_balance_curse_vulner_takedamage");
857 if(targ.takedamage == DAMAGE_AIM)
860 if(targ.classname == "player")
863 // find height of hit on player axis
864 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
865 vector headmins, headmaxs, org;
866 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
867 headmins = org + '0.6 0 0' * targ.mins_x + '0 0.6 0' * targ.mins_y + '0 0 1' * (1.3 * targ.view_ofs_z - 0.3 * targ.maxs_z);
868 headmaxs = org + '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
869 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
871 deathtype |= HITTYPE_HEADSHOT;
874 else if(targ.classname == "turret_head")
876 deathtype |= HITTYPE_HEADSHOT;
878 if(deathtype & HITTYPE_HEADSHOT)
879 damage *= 1 + damage_headshotbonus;
881 if(targ.classname == "player")
883 if(IsDifferentTeam(targ, attacker))
888 attacker.typehitsound += 1;
890 attacker.hitsound += 1;
892 damage_goodhits += 1;
893 damage_gooddamage += damage;
895 if not(DEATH_ISSPECIAL(deathtype))
902 if(targ.items & IT_STRENGTH)
905 if(deathtype & HITTYPE_HEADSHOT)
912 if(deathtype != DEATH_FIRE)
913 attacker.typehitsound += 1;
915 if(time > attacker.teamkill_complain)
917 attacker.teamkill_complain = time + 5;
918 attacker.teamkill_soundtime = time + 0.4;
919 attacker.teamkill_soundsource = targ;
927 if (self.damageforcescale)
929 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
931 self.velocity = self.velocity + self.damageforcescale * force;
932 self.flags &~= FL_ONGROUND;
933 UpdateCSQCProjectile(self);
936 if (damage != 0 || (self.damageforcescale && vlen(force)))
937 if (self.event_damage)
938 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
941 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
943 // Savage: vampire mode
946 if (time >= self.spawnshieldtime)
948 attacker.health += damage;
952 if (attacker.runes & RUNE_VAMPIRE)
954 // apply vampire rune
955 if (attacker.runes & CURSE_EMPATHY) // have the curse too
957 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
958 attacker.health = bound(
959 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
960 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
961 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
965 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
966 attacker.health = bound(
967 attacker.health, // LA: was 3, but changed so that you can't lose health
968 // empathy won't let you gain health in the same way...
969 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
970 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
973 // apply empathy curse
974 else if (attacker.runes & CURSE_EMPATHY)
976 attacker.health = bound(
977 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
978 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
984 // apply mirror damage if any
985 if(mirrordamage > 0 || mirrorforce > 0)
987 attacker = attacker_save;
991 // just lose extra LIVES, don't kill the player for mirror damage
992 if(attacker.armorvalue > 0)
994 attacker.armorvalue = attacker.armorvalue - 1;
995 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
996 attacker.hitsound += 1;
1000 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
1001 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
1005 vector NearestPointOnBox(entity box, vector org)
1007 vector m1, m2, nearest;
1009 m1 = box.mins + box.origin;
1010 m2 = box.maxs + box.origin;
1012 nearest_x = bound(m1_x, org_x, m2_x);
1013 nearest_y = bound(m1_y, org_y, m2_y);
1014 nearest_z = bound(m1_z, org_z, m2_z);
1019 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
1022 weaponid = DEATH_WEAPONOF(deathtype);
1024 if not(inWarmupStage)
1026 if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {
1027 attacker.stats_hit[weaponid - 1] += damage;
1028 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);
1032 float RadiusDamage_running;
1033 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
1034 // Returns total damage applies to creatures
1044 float total_damage_to_creatures;
1049 float stat_damagedone;
1050 float stat_maxdamage;
1052 if(RadiusDamage_running)
1055 print("RadiusDamage called recursively!\n");
1056 print("Expect stuff to go HORRIBLY wrong.\n");
1057 print("Causing a stack trace...\n");
1058 save = cvar_string("prvm_backtraceforwarnings");
1059 cvar_set("prvm_backtraceforwarnings", "1");
1060 fclose(-1); // calls VM_Warning
1061 cvar_set("prvm_backtraceforwarnings", save);
1065 RadiusDamage_running = 1;
1067 tfloordmg = cvar("g_throughfloor_damage");
1068 tfloorforce = cvar("g_throughfloor_force");
1070 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1071 total_damage_to_creatures = 0;
1073 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1074 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
1076 force = inflictor.velocity;
1077 if(vlen(force) == 0)
1080 force = normalize(force);
1081 if(forceintensity >= 0)
1082 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1084 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1087 stat_damagedone = 0;
1090 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
1094 if (targ != inflictor)
1095 if (ignore != targ) if(targ.takedamage)
1097 // LordHavoc: measure distance to nearest point on target (not origin)
1098 // (this guarentees 100% damage on a touch impact)
1099 nearest = targ.WarpZone_findradius_nearest;
1100 diff = targ.WarpZone_findradius_dist;
1101 // round up a little on the damage to ensure full damage on impacts
1102 // and turn the distance into a fraction of the radius
1103 power = 1 - ((vlen (diff) - 2) / rad);
1105 //bprint(ftos(power));
1106 //if (targ == attacker)
1107 // print(ftos(power), "\n");
1112 finaldmg = coredamage * power + edgedamage * (1 - power);
1119 local float hitratio;
1120 local vector hitloc;
1121 local vector myblastorigin;
1122 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1123 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1124 // if it's a player, use the view origin as reference
1125 if (targ.classname == "player")
1126 center = targ.origin + targ.view_ofs;
1127 force = normalize(center - myblastorigin);
1128 force = force * (finaldmg / coredamage) * forceintensity;
1129 // test line of sight to multiple positions on box,
1130 // and do damage if any of them hit
1132 if (targ.classname == "player")
1133 total = ceil(bound(1, finaldmg, 50));
1135 total = ceil(bound(1, finaldmg/10, 5));
1140 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1141 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1142 if (trace_fraction == 1 || trace_ent == targ)
1146 hitloc = hitloc + nearest;
1150 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1151 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1152 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1155 nearest = hitloc * (1 / max(1, hits));
1156 hitratio = (hits / total);
1157 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1158 finaldmg = finaldmg * a;
1159 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1161 //if (targ == attacker)
1163 // print("hits ", ftos(hits), " / ", ftos(total));
1164 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1165 // print(" (", ftos(a), ")\n");
1167 if(hits || tfloordmg || tfloorforce)
1171 total_damage_to_creatures += finaldmg;
1173 if(targ.flags & FL_CLIENT)
1174 if(targ.deadflag == DEAD_NO)
1175 if(targ != attacker)
1176 if(!teamplay || targ.team != attacker.team)
1178 stat_damagedone += finaldmg;
1179 stat_maxdamage += coredamage;
1183 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1184 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1186 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1194 RadiusDamage_running = 0;
1196 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1198 return total_damage_to_creatures;
1201 .float fire_damagepersec;
1202 .float fire_endtime;
1203 .float fire_deathtype;
1205 .float fire_hitsound;
1206 .entity fire_burner;
1208 void fireburner_think();
1210 float Fire_IsBurning(entity e)
1212 return (time < e.fire_endtime);
1215 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1218 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1220 if(e.classname == "player")
1229 // print("adding a fire burner to ", e.classname, "\n");
1230 e.fire_burner = spawn();
1231 e.fire_burner.classname = "fireburner";
1232 e.fire_burner.think = fireburner_think;
1233 e.fire_burner.nextthink = time;
1234 e.fire_burner.owner = e;
1240 if(Fire_IsBurning(e))
1242 mintime = e.fire_endtime - time;
1243 maxtime = max(mintime, t);
1245 mindps = e.fire_damagepersec;
1246 maxdps = max(mindps, dps);
1248 if(maxtime > mintime || maxdps > mindps)
1250 mindamage = mindps * mintime;
1251 maxdamage = mindamage + d;
1253 // interval [mintime, maxtime] * [mindps, maxdps]
1255 // [mindamage, maxdamage]
1258 if(maxdamage >= maxtime * maxdps)
1260 totaltime = maxtime;
1261 totaldamage = maxtime * maxdps;
1263 // this branch increases totaldamage if either t > mintime, or dps > mindps
1267 // maxdamage is inside the interval!
1268 // first, try to use mindps; only if this fails, increase dps as needed
1269 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1270 totaldamage = maxdamage;
1271 // can totaldamage / totaltime be >= maxdps?
1272 // max(mindps, maxdamage / maxtime) >= maxdps?
1273 // we know maxdamage < maxtime * maxdps
1276 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1279 // total conditions for increasing:
1280 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1282 // if maxtime = mintime, maxdps = mindps
1284 // maxdamage = mindamage + d
1285 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1286 // so the last condition is not needed
1288 e.fire_damagepersec = totaldamage / totaltime;
1289 e.fire_endtime = time + totaltime;
1290 if(totaldamage > 1.2 * mindamage)
1292 e.fire_deathtype = dt;
1293 if(e.fire_owner != o)
1296 e.fire_hitsound = FALSE;
1299 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1306 e.fire_damagepersec = dps;
1307 e.fire_endtime = time + t;
1308 e.fire_deathtype = dt;
1310 e.fire_hitsound = FALSE;
1315 void Fire_ApplyDamage(entity e)
1320 if not(Fire_IsBurning(e))
1326 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1329 // water and slime stop fire
1331 if(e.watertype != CONTENT_LAVA)
1334 t = min(frametime, e.fire_endtime - time);
1335 d = e.fire_damagepersec * t;
1337 hi = e.fire_owner.hitsound;
1338 ty = e.fire_owner.typehitsound;
1339 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1340 if(e.fire_hitsound && e.fire_owner)
1342 e.fire_owner.hitsound = hi;
1343 e.fire_owner.typehitsound = ty;
1345 e.fire_hitsound = TRUE;
1347 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1349 if not(IS_INDEPENDENT_PLAYER(e))
1350 FOR_EACH_PLAYER(other) if(e != other)
1352 if(other.classname == "player")
1353 if(other.deadflag == DEAD_NO)
1354 if not(IS_INDEPENDENT_PLAYER(other))
1355 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1357 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1358 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1359 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1364 void Fire_ApplyEffect(entity e)
1366 if(Fire_IsBurning(e))
1367 e.effects |= EF_FLAME;
1369 e.effects &~= EF_FLAME;
1372 void fireburner_think()
1374 // for players, this is done in the regular loop
1375 if(wasfreed(self.owner))
1380 Fire_ApplyEffect(self.owner);
1381 if(!Fire_IsBurning(self.owner))
1383 self.owner.fire_burner = world;
1387 Fire_ApplyDamage(self.owner);
1388 self.nextthink = time;