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)
98 // TODO route through PlayerScores instead
106 PlayerScore_Add(attacker, SP_SUICIDES, 1);
111 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
117 PlayerScore_Add(attacker, SP_KILLS, 1);
120 PlayerScore_Add(targ, SP_DEATHS, 1);
123 if(cvar("g_arena_roundbased"))
126 if(g_weaponarena_random)
128 // after a frag, choose another random weapon set
129 attacker.weapons = randombits(attacker.weapons, (inWarmupStage ? warmup_start_weapons : start_weapons));
130 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
131 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
134 // FIXME fix the mess this is (we have REAL points now!)
137 f = RunematchHandleFrags(attacker, targ, f);
141 f = kh_HandleFrags(attacker, targ, f);
147 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
148 if(tl < lms_lowest_lives)
149 lms_lowest_lives = tl;
153 lms_next_place = player_count;
154 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
161 if(g_ctf_ignore_frags)
165 attacker.totalfrags += f;
168 UpdateFrags(attacker, f);
171 string AppendItemcodes(string s, entity player)
176 // w = player.switchweapon;
178 w = player.cnt; // previous weapon!
179 s = strcat(s, ftos(w));
180 if(time < player.strength_finished)
182 if(time < player.invincible_finished)
184 if(player.flagcarried != world)
186 if(player.BUTTON_CHAT)
191 s = strcat(s, "|", ftos(player.runes));
195 void LogDeath(string mode, float deathtype, entity killer, entity killed)
198 if(!cvar("sv_eventlog"))
200 s = strcat(":kill:", mode);
201 s = strcat(s, ":", ftos(killer.playerid));
202 s = strcat(s, ":", ftos(killed.playerid));
203 s = strcat(s, ":type=", ftos(deathtype));
204 s = strcat(s, ":items=");
205 s = AppendItemcodes(s, killer);
208 s = strcat(s, ":victimitems=");
209 s = AppendItemcodes(s, killed);
214 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
219 if (targ.classname == "player" || targ.classname == "corpse")
221 if (targ.classname == "corpse")
225 a = attacker.netname;
227 if (targ == attacker)
229 if (deathtype == DEATH_TEAMCHANGE) {
230 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
231 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
232 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)));
234 } else if (deathtype == DEATH_CAMP) {
236 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
238 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
239 } else if (deathtype == DEATH_NOAMMO) {
241 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
243 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
244 } else if (deathtype == DEATH_ROT) {
246 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
248 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
249 } else if (deathtype == DEATH_MIRRORDAMAGE) {
251 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
253 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
256 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
258 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
262 if (deathtype == DEATH_CAMP)
263 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
264 else if (deathtype == DEATH_MIRRORDAMAGE)
265 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
267 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
269 if(deathtype != DEATH_TEAMCHANGE)
271 LogDeath("suicide", deathtype, targ, targ);
272 GiveFrags(attacker, targ, -1);
274 if (targ.killcount > 2)
275 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
277 w = DEATH_WEAPONOF(deathtype);
280 w_deathtypestring = "couldn't resist the urge to self-destruct";
281 w_deathtype = deathtype;
282 weapon_action(w, WR_SUICIDEMESSAGE);
283 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
285 else if (deathtype == DEATH_KILL)
286 bprint ("^1",s, "^1 couldn't take it anymore\n");
287 else if (deathtype == DEATH_ROT)
288 bprint ("^1",s, "^1 died\n");
289 else if (deathtype == DEATH_NOAMMO)
290 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
291 else if (deathtype == DEATH_CAMP)
292 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
293 else if (deathtype == DEATH_MIRRORDAMAGE)
294 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
295 else if (deathtype == DEATH_CHEAT)
296 bprint ("^1",s, "^1 unfairly eliminated himself\n");
297 else if (deathtype == DEATH_FIRE)
298 bprint ("^1",s, "^1 burned to death\n");
299 else if (deathtype != DEATH_TEAMCHANGE)
300 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
302 if(deathtype != DEATH_TEAMCHANGE)
304 LogDeath("suicide", deathtype, targ, targ);
305 GiveFrags(attacker, targ, -1);
307 if (targ.killcount > 2)
308 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
311 else if (attacker.classname == "player" || attacker.classname == "gib")
313 if(teams_matter && attacker.team == targ.team)
316 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
317 bprint ("^1", a, "^1 took action against a team mate\n");
319 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
320 bprint ("^1", a, "^1 mows down a team mate\n");
322 GiveFrags(attacker, targ, -1);
323 if (targ.killcount > 2) {
325 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
327 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
329 if (attacker.killcount > 2) {
331 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
333 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
335 attacker.killcount = 0;
337 LogDeath("tk", deathtype, attacker, targ);
341 string blood_message, victim_message;
342 if (!checkrules_firstblood)
344 checkrules_firstblood = TRUE;
347 bprint("^1",a, "^1 was the first to score", "\n");
348 blood_message = "^1First point\n";
349 //victim_message = "^1First victim\n"; // or First casualty
353 bprint("^1",a, "^1 drew first blood", "\n");
354 blood_message = "^1First blood\n";
355 victim_message = "^1First victim\n"; // or First casualty
360 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s));
361 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7"));
363 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s));
364 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a));
365 attacker.taunt_soundtime = time + 1;
369 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
371 w = DEATH_WEAPONOF(deathtype);
374 w_deathtypestring = "was blasted by";
375 w_deathtype = deathtype;
376 weapon_action(w, WR_KILLMESSAGE);
377 p = strstrofs(w_deathtypestring, "#", 0);
379 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
381 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
383 else if (deathtype == DEATH_TELEFRAG)
384 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
385 else if (deathtype == DEATH_DROWN)
386 bprint ("^1",s, "^1 was drowned by ", a, "\n");
387 else if (deathtype == DEATH_SLIME)
388 bprint ("^1",s, "^1 was slimed by ", a, "\n");
389 else if (deathtype == DEATH_LAVA)
390 bprint ("^1",s, "^1 was cooked by ", a, "\n");
391 else if (deathtype == DEATH_FALL)
392 bprint ("^1",s, "^1 was grounded by ", a, "\n");
393 else if (deathtype == DEATH_SHOOTING_STAR)
394 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
395 else if (deathtype == DEATH_SWAMP)
396 bprint ("^1",s, "^1 was conserved by ", a, "\n");
397 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
399 p = strstrofs(inflictor.message2, "#", 0);
401 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
403 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
405 else if(deathtype == DEATH_TURRET)
406 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
407 else if(deathtype == DEATH_TOUCHEXPLODE)
408 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
409 else if(deathtype == DEATH_CHEAT)
410 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
411 else if (deathtype == DEATH_FIRE)
412 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
414 bprint ("^1",s, "^1 was fragged by ", a, "\n");
417 if(g_ctf && targ.flagcarried)
419 UpdateFrags(attacker, ctf_score_value("score_kill"));
420 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
421 GiveFrags(attacker, targ, 0); // for logging
424 GiveFrags(attacker, targ, 1);
426 if (targ.killcount > 2) {
428 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
430 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
433 attacker.killcount = attacker.killcount + 1;
435 if (attacker.killcount > 2) {
437 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
439 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
442 LogDeath("frag", deathtype, attacker, targ);
444 if (attacker.killcount == 3)
447 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
449 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
450 announce(attacker, "announcer/male/03kills.wav");
453 else if (attacker.killcount == 5)
456 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
458 bprint (a,"^7 unleashes ^1RAGE\n");
459 announce(attacker, "announcer/male/05kills.wav");
462 else if (attacker.killcount == 10)
465 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
467 bprint (a,"^7 starts the ^1MASSACRE!\n");
468 announce(attacker, "announcer/male/10kills.wav");
471 else if (attacker.killcount == 15)
474 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
476 bprint (a,"^7 executes ^1MAYHEM!\n");
477 announce(attacker, "announcer/male/15kills.wav");
480 else if (attacker.killcount == 20)
483 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
485 bprint (a,"^7 is a ^1BERSERKER!\n");
486 announce(attacker, "announcer/male/20kills.wav");
489 else if (attacker.killcount == 25)
492 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
494 bprint (a,"^7 inflicts ^1CARNAGE!\n");
495 announce(attacker, "announcer/male/25kills.wav");
498 else if (attacker.killcount == 30)
501 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
503 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
504 announce(attacker, "announcer/male/30kills.wav");
511 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
512 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
513 bprint ("^1",s, "^1 ", inflictor.message, "\n");
514 else if (deathtype == DEATH_DROWN)
516 bprint ("^1",s, "^1 was in the water for too long\n");
518 bprint ("^1",s, "^1 drowned\n");
519 else if (deathtype == DEATH_SLIME)
520 bprint ("^1",s, "^1 was slimed\n");
521 else if (deathtype == DEATH_LAVA)
523 bprint ("^1",s, "^1 found a hot place\n");
525 bprint ("^1",s, "^1 turned into hot slag\n");
526 else if (deathtype == DEATH_FALL)
528 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
530 bprint ("^1",s, "^1 hit the ground with a crunch\n");
531 else if (deathtype == DEATH_SHOOTING_STAR)
532 bprint ("^1",s, "^1 became a shooting star\n");
533 else if (deathtype == DEATH_SWAMP)
535 bprint ("^1",s, "^1 discovered a swamp\n");
537 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
538 else if(deathtype == DEATH_TURRET)
539 bprint ("^1",s, "^1 was mowed down by a turret \n");
540 else if(deathtype == DEATH_TOUCHEXPLODE)
541 bprint ("^1",s, "^1 died in an accident\n");
542 else if(deathtype == DEATH_CHEAT)
543 bprint ("^1",s, "^1 was unfairly eliminated\n");
544 else if(deathtype == DEATH_FIRE)
546 bprint ("^1",s, "^1 felt a little hot\n");
548 bprint ("^1",s, "^1 burnt to death\n");
551 bprint ("^1",s, "^1 needs a restart\n");
553 bprint ("^1",s, "^1 died\n");
554 GiveFrags(targ, targ, -1);
555 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
556 announce(targ, "announcer/male/botlike.wav");
559 if (targ.killcount > 2)
561 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
563 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
565 LogDeath("accident", deathtype, targ, targ);
567 targ.death_origin = targ.origin;
569 targ.killer_origin = attacker.origin;
570 // FIXME: this should go in PutClientInServer
576 // these are updated by each Damage call for use in button triggering and such
578 entity damage_inflictor;
579 entity damage_attacker;
581 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
586 entity attacker_save;
590 if (gameover || targ.killcount == -666)
593 local entity oldself;
597 damage_inflictor = inflictor;
598 damage_attacker = attacker;
599 attacker_save = attacker;
601 if(targ.classname == "player")
604 if(targ.hook.aiment == attacker)
605 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
607 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
608 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
610 if(targ.classname == "player")
611 if not(IsDifferentTeam(targ, attacker))
618 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
620 // These are ALWAYS lethal
621 // No damage modification here
622 // Instead, prepare the victim for his death...
624 targ.spawnshieldtime = 0;
625 targ.health = 0.9; // this is < 1
626 targ.flags -= targ.flags & FL_GODMODE;
629 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
635 if (targ.classname == "player")
636 if (attacker.classname == "player")
639 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
641 // nullify damage if teamplay is on
642 if(deathtype != DEATH_TELEFRAG)
643 if(attacker.classname == "player")
645 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
650 else if(attacker.team == targ.team)
654 else if(attacker != targ)
658 else if(teamplay == 4)
660 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
662 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
663 attacker.dmg_team = attacker.dmg_team + damage;
664 if(attacker.dmg_team > teamdamage0)
665 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
666 mirrorforce = cvar("g_mirrordamage") * vlen(force);
669 if(cvar("g_friendlyfire") == 0)
673 damage = cvar("g_friendlyfire") * damage;
674 // mirrordamage will be used LATER
683 if(targ.classname == "player")
684 if(attacker.classname == "player")
687 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
688 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
691 if(targ.classname == "player")
694 if ((deathtype == DEATH_FALL) ||
695 (deathtype == DEATH_DROWN) ||
696 (deathtype == DEATH_SLIME) ||
697 (deathtype == DEATH_LAVA))
702 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
704 targ.armorvalue -= 1;
705 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
708 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
710 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
713 if (targ != attacker)
715 if (targ.classname == "player")
716 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
726 if not(DEATH_ISSPECIAL(deathtype))
728 damage *= g_weapondamagefactor;
729 mirrordamage *= g_weapondamagefactor;
730 force = force * g_weaponforcefactor;
731 mirrorforce *= g_weaponforcefactor;
734 // apply strength multiplier
735 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
739 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
740 force = force * cvar("g_balance_powerup_strength_selfforce");
744 damage = damage * cvar("g_balance_powerup_strength_damage");
745 force = force * cvar("g_balance_powerup_strength_force");
749 // apply invincibility multiplier
750 if (targ.items & IT_INVINCIBLE && !g_minstagib)
751 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
753 if (targ == attacker)
754 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
756 // CTF: reduce damage/force
761 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
762 force = force * cvar("g_ctf_flagcarrier_selfforce");
767 // apply strength rune
768 if (attacker.runes & RUNE_STRENGTH)
770 if(attacker.runes & CURSE_WEAK) // have both curse & rune
772 damage = damage * cvar("g_balance_rune_strength_combo_damage");
773 force = force * cvar("g_balance_rune_strength_combo_force");
777 damage = damage * cvar("g_balance_rune_strength_damage");
778 force = force * cvar("g_balance_rune_strength_force");
781 else if (attacker.runes & CURSE_WEAK)
783 damage = damage * cvar("g_balance_curse_weak_damage");
784 force = force * cvar("g_balance_curse_weak_force");
787 // apply defense rune
788 if (targ.runes & RUNE_DEFENSE)
790 if (targ.runes & CURSE_VULNER) // have both curse & rune
791 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
793 damage = damage * cvar("g_balance_rune_defense_takedamage");
795 else if (targ.runes & CURSE_VULNER)
796 damage = damage * cvar("g_balance_curse_vulner_takedamage");
802 if(targ.takedamage == DAMAGE_AIM)
804 if(targ.classname == "player")
806 if(IsDifferentTeam(targ, attacker))
811 attacker.typehitsound += 1;
813 attacker.hitsound += 1;
815 damage_goodhits += 1;
816 damage_gooddamage += damage;
818 if not(DEATH_ISSPECIAL(deathtype))
825 if(targ.items & IT_STRENGTH)
829 // find height of hit on player axis
830 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
831 vector headmins, headmaxs, org;
832 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
833 headmins = org + '0.7 0 0' * targ.mins_x + '0 0.7 0' * targ.mins_y + '0 0 1' * (1.5 * targ.view_ofs_z - 0.5 * targ.maxs_z);
834 headmaxs = org + '0.7 0 0' * targ.maxs_x + '0 0.7 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
835 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
837 damage *= 1 + damage_headshotbonus;
839 deathtype |= HITTYPE_HEADSHOT;
846 if(deathtype != DEATH_FIRE)
847 attacker.typehitsound += 1;
849 if(time > attacker.teamkill_complain)
851 attacker.teamkill_complain = time + 5;
852 attacker.teamkill_soundtime = time + 0.4;
853 attacker.teamkill_soundsource = targ;
860 if (self.damageforcescale)
863 self.velocity = self.velocity + self.damageforcescale * force;
864 self.flags &~= FL_ONGROUND;
865 UpdateCSQCProjectile(self);
868 if (damage != 0 || (self.damageforcescale && vlen(force)))
869 if (self.event_damage)
870 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
873 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
875 // Savage: vampire mode
878 if (time > self.spawnshieldtime)
880 attacker.health += damage;
884 if (attacker.runes & RUNE_VAMPIRE)
886 // apply vampire rune
887 if (attacker.runes & CURSE_EMPATHY) // have the curse too
889 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
890 attacker.health = bound(
891 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
892 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
893 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
897 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
898 attacker.health = bound(
899 attacker.health, // LA: was 3, but changed so that you can't lose health
900 // empathy won't let you gain health in the same way...
901 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
902 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
905 // apply empathy curse
906 else if (attacker.runes & CURSE_EMPATHY)
908 attacker.health = bound(
909 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
910 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
916 // apply mirror damage if any
917 if(mirrordamage > 0 || mirrorforce > 0)
919 attacker = attacker_save;
923 // just lose extra LIVES, don't kill the player for mirror damage
924 if(attacker.armorvalue > 0)
926 attacker.armorvalue = attacker.armorvalue - 1;
927 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
928 attacker.hitsound += 1;
932 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
933 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
937 vector NearestPointOnBox(entity box, vector org)
939 vector m1, m2, nearest;
941 m1 = box.mins + box.origin;
942 m2 = box.maxs + box.origin;
944 nearest_x = bound(m1_x, org_x, m2_x);
945 nearest_y = bound(m1_y, org_y, m2_y);
946 nearest_z = bound(m1_z, org_z, m2_z);
951 .float actual_damage[WEP_COUNT]; //amount of damage done
952 .float max_damage[WEP_COUNT]; //the maximum damage of the weapon
954 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(actual_damage);
955 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(max_damage);
957 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
960 weaponid = DEATH_WEAPONOF(deathtype);
961 if not(inWarmupStage)
963 if(clienttype(attacker) == CLIENTTYPE_REAL)
965 // Track damage done and update the stat to be sent later in g_world.qc
966 attacker.actual_damage[weaponid] += damage;
967 attacker.damage_hits = weaponid + 64 * rint(attacker.actual_damage[weaponid]);
971 float RadiusDamage_running;
972 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
973 // Returns total damage applies to creatures
983 float total_damage_to_creatures;
986 float stat_damagedone;
987 float stat_maxdamage;
989 if(RadiusDamage_running)
992 print("RadiusDamage called recursively!\n");
993 print("Expect stuff to go HORRIBLY wrong.\n");
994 print("Causing a stack trace...\n");
995 save = cvar_string("prvm_backtraceforwarnings");
996 cvar_set("prvm_backtraceforwarnings", "1");
997 fclose(-1); // calls VM_Warning
998 cvar_set("prvm_backtraceforwarnings", save);
1003 RadiusDamage_running = 1;
1005 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1006 total_damage_to_creatures = 0;
1008 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1010 force = inflictor.velocity;
1011 if(vlen(force) == 0)
1014 force = normalize(force);
1015 if(forceintensity >= 0)
1016 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1018 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1021 stat_damagedone = 0;
1024 targ = findradius (blastorigin, rad);
1028 if (targ != inflictor)
1031 // LordHavoc: measure distance to nearest point on target (not origin)
1032 // (this guarentees 100% damage on a touch impact)
1033 nearest = NearestPointOnBox(targ, blastorigin);
1034 diff = nearest - blastorigin;
1035 // round up a little on the damage to ensure full damage on impacts
1036 // and turn the distance into a fraction of the radius
1037 power = 1 - ((vlen (diff) - 2) / rad);
1039 //bprint(ftos(power));
1044 finaldmg = coredamage * power + edgedamage * (1 - power);
1047 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1048 // if it's a player, use the view origin as reference
1049 if (targ.classname == "player")
1050 center = targ.origin + targ.view_ofs;
1051 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
1052 // test line of sight to multiple positions on box,
1053 // and do damage if any of them hit
1055 c = ceil(finaldmg / 10);
1061 traceline(blastorigin, nearest, TRUE, inflictor);
1062 if (trace_fraction == 1 || trace_ent == targ
1063 || cvar("g_throughfloor"))
1067 total_damage_to_creatures += finaldmg;
1069 if(targ.flags & FL_CLIENT)
1070 if(targ.deadflag == DEAD_NO)
1071 if(targ != attacker)
1072 if(!teamplay || targ.team != attacker.team)
1074 stat_damagedone += finaldmg;
1075 stat_maxdamage += coredamage;
1079 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1080 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1082 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1085 nearest_x = targ.mins_x + random() * targ.size_x;
1086 nearest_y = targ.mins_y + random() * targ.size_y;
1087 nearest_z = targ.mins_z + random() * targ.size_z;
1095 RadiusDamage_running = 0;
1097 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1099 return total_damage_to_creatures;
1102 .float fire_damagepersec;
1103 .float fire_endtime;
1104 .float fire_deathtype;
1106 .float fire_hitsound;
1107 .entity fire_burner;
1109 void fireburner_think();
1111 float Fire_IsBurning(entity e)
1113 return (time < e.fire_endtime);
1116 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1119 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1121 if(e.classname != "player")
1124 // print("adding a fire burner to ", e.classname, "\n");
1125 e.fire_burner = spawn();
1126 e.fire_burner.classname = "fireburner";
1127 e.fire_burner.think = fireburner_think;
1128 e.fire_burner.nextthink = time;
1129 e.fire_burner.owner = e;
1134 if(Fire_IsBurning(e))
1136 mintime = e.fire_endtime - time;
1137 maxtime = max(mintime, t);
1139 mindps = e.fire_damagepersec;
1140 maxdps = max(mindps, dps);
1142 if(maxtime > mintime || maxdps > mindps)
1144 mindamage = mindps * mintime;
1145 maxdamage = mindamage + d;
1147 // interval [mintime, maxtime] * [mindps, maxdps]
1149 // [mindamage, maxdamage]
1152 if(maxdamage >= maxtime * maxdps)
1154 totaltime = maxtime;
1155 totaldamage = maxtime * maxdps;
1157 // this branch increases totaldamage if either t > mintime, or dps > mindps
1161 // maxdamage is inside the interval!
1162 // first, try to use mindps; only if this fails, increase dps as needed
1163 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1164 totaldamage = maxdamage;
1165 // can totaldamage / totaltime be >= maxdps?
1166 // max(mindps, maxdamage / maxtime) >= maxdps?
1167 // we know maxdamage < maxtime * maxdps
1170 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1173 // total conditions for increasing:
1174 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1176 // if maxtime = mintime, maxdps = mindps
1178 // maxdamage = mindamage + d
1179 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1180 // so the last condition is not needed
1182 e.fire_damagepersec = totaldamage / totaltime;
1183 e.fire_endtime = time + totaltime;
1184 if(totaldamage > 1.2 * mindamage)
1185 if(e.fire_owner != o)
1187 e.fire_deathtype = dt;
1189 e.fire_hitsound = FALSE;
1191 return totaldamage - mindamage; // can never be negative
1198 e.fire_damagepersec = dps;
1199 e.fire_endtime = time + t;
1200 e.fire_deathtype = dt;
1202 e.fire_hitsound = FALSE;
1207 void Fire_ApplyDamage(entity e)
1211 if not(Fire_IsBurning(e))
1214 // water and slime stop fire
1216 if(e.watertype != CONTENT_LAVA)
1219 t = min(frametime, e.fire_endtime - time);
1220 d = e.fire_damagepersec * t;
1222 hi = e.fire_owner.hitsound;
1223 ty = e.fire_owner.typehitsound;
1224 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1225 if(e.fire_hitsound && e.fire_owner)
1227 e.fire_owner.hitsound = hi;
1228 e.fire_owner.typehitsound = ty;
1230 e.fire_hitsound = TRUE;
1232 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1234 if not(IS_INDEPENDENT_PLAYER(e))
1235 FOR_EACH_PLAYER(other) if(e != other)
1237 if(other.classname == "player")
1238 if(other.deadflag == DEAD_NO)
1239 if not(IS_INDEPENDENT_PLAYER(other))
1240 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1242 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1243 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1244 Fire_AddDamage(other, e, d, t, DEATH_FIRE);
1249 void Fire_ApplyEffect(entity e)
1251 if(Fire_IsBurning(e))
1252 e.effects |= EF_FLAME;
1254 e.effects &~= EF_FLAME;
1257 void fireburner_think()
1259 // for players, this is done in the regular loop
1260 if(wasfreed(self.owner))
1265 Fire_ApplyEffect(self.owner);
1266 if(!Fire_IsBurning(self.owner))
1268 self.owner.fire_burner = world;
1272 Fire_ApplyDamage(self.owner);
1273 self.nextthink = time;