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!)
151 f = RunematchHandleFrags(attacker, targ, f);
155 f = kh_HandleFrags(attacker, targ, f);
161 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
162 if(tl < lms_lowest_lives)
163 lms_lowest_lives = tl;
167 lms_next_place = player_count;
168 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
175 if(g_ctf_ignore_frags)
179 attacker.totalfrags += f;
182 UpdateFrags(attacker, f);
185 string AppendItemcodes(string s, entity player)
190 // w = player.switchweapon;
192 w = player.cnt; // previous weapon!
193 s = strcat(s, ftos(w));
194 if(time < player.strength_finished)
196 if(time < player.invincible_finished)
198 if(player.flagcarried != world)
200 if(player.BUTTON_CHAT)
205 s = strcat(s, "|", ftos(player.runes));
209 void LogDeath(string mode, float deathtype, entity killer, entity killed)
212 if(!cvar("sv_eventlog"))
214 s = strcat(":kill:", mode);
215 s = strcat(s, ":", ftos(killer.playerid));
216 s = strcat(s, ":", ftos(killed.playerid));
217 s = strcat(s, ":type=", ftos(deathtype));
218 s = strcat(s, ":items=");
219 s = AppendItemcodes(s, killer);
222 s = strcat(s, ":victimitems=");
223 s = AppendItemcodes(s, killed);
228 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
233 if (targ.classname == "player" || targ.classname == "corpse")
235 if (targ.classname == "corpse")
240 a = attacker.netname;
242 if (targ == attacker)
244 if (deathtype == DEATH_TEAMCHANGE) {
245 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
246 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
247 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)));
249 } else if (deathtype == DEATH_CAMP) {
251 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
253 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
254 } else if (deathtype == DEATH_NOAMMO) {
256 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
258 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
259 } else if (deathtype == DEATH_ROT) {
261 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
263 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
264 } else if (deathtype == DEATH_MIRRORDAMAGE) {
266 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
268 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
269 } else if (deathtype == DEATH_QUIET) {
273 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
275 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
278 if (deathtype == DEATH_CAMP)
279 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
280 else if (deathtype == DEATH_MIRRORDAMAGE)
281 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
283 bprint ("^1",s, "^1 will be reinserted into the game due to their own actions\n");
285 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
287 LogDeath("suicide", deathtype, targ, targ);
288 GiveFrags(attacker, targ, -1);
290 if (targ.killcount > 2)
291 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
293 w = DEATH_WEAPONOF(deathtype);
296 w_deathtypestring = "couldn't resist the urge to self-destruct";
297 w_deathtype = deathtype;
298 weapon_action(w, WR_SUICIDEMESSAGE);
299 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
301 else if (deathtype == DEATH_KILL)
302 bprint ("^1",s, "^1 couldn't take it anymore\n");
303 else if (deathtype == DEATH_ROT)
304 bprint ("^1",s, "^1 died\n");
305 else if (deathtype == DEATH_NOAMMO)
306 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
307 else if (deathtype == DEATH_CAMP)
308 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
309 else if (deathtype == DEATH_MIRRORDAMAGE)
310 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
311 else if (deathtype == DEATH_CHEAT)
312 bprint ("^1",s, "^1 unfairly eliminated themself\n");
313 else if (deathtype == DEATH_FIRE)
314 bprint ("^1",s, "^1 burned to death\n");
315 else if (deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
316 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
318 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
320 LogDeath("suicide", deathtype, targ, targ);
321 GiveFrags(attacker, targ, -1);
323 if (targ.killcount > 2)
324 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
327 else if (attacker.classname == "player" || attacker.classname == "gib")
329 if(teams_matter && attacker.team == targ.team)
332 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
333 bprint ("^1", a, "^1 took action against a team mate\n");
335 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
336 bprint ("^1", a, "^1 mows down a team mate\n");
338 GiveFrags(attacker, targ, -1);
339 if (targ.killcount > 2) {
341 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
343 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
345 if (attacker.killcount > 2) {
347 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
349 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
351 attacker.killcount = 0;
353 LogDeath("tk", deathtype, attacker, targ);
357 string blood_message, victim_message;
358 if (!checkrules_firstblood)
360 checkrules_firstblood = TRUE;
363 bprint("^1",a, "^1 was the first to score", "\n");
364 blood_message = "^1First point\n";
365 //victim_message = "^1First victim\n"; // or First casualty
369 bprint("^1",a, "^1 drew first blood", "\n");
370 blood_message = "^1First blood\n";
371 victim_message = "^1First victim\n"; // or First casualty
375 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You scored against ^7", s, GetAdvancedDeathReports(targ)));
376 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7", GetAdvancedDeathReports(attacker)));
378 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
379 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^1You typefragged ^7", s, GetAdvancedDeathReports(targ)));
380 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typefragged by ^7", a, GetAdvancedDeathReports(attacker)));
382 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s, GetAdvancedDeathReports(targ)));
383 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a, GetAdvancedDeathReports(attacker)));
385 attacker.taunt_soundtime = time + 1;
389 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
391 w = DEATH_WEAPONOF(deathtype);
394 w_deathtypestring = "was blasted by";
395 w_deathtype = deathtype;
396 weapon_action(w, WR_KILLMESSAGE);
397 p = strstrofs(w_deathtypestring, "#", 0);
399 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
401 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
403 else if (deathtype == DEATH_TELEFRAG)
404 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
405 else if (deathtype == DEATH_DROWN)
406 bprint ("^1",s, "^1 was drowned by ", a, "\n");
407 else if (deathtype == DEATH_SLIME)
408 bprint ("^1",s, "^1 was slimed by ", a, "\n");
409 else if (deathtype == DEATH_LAVA)
410 bprint ("^1",s, "^1 was cooked by ", a, "\n");
411 else if (deathtype == DEATH_FALL)
412 bprint ("^1",s, "^1 was grounded by ", a, "\n");
413 else if (deathtype == DEATH_SHOOTING_STAR)
414 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
415 else if (deathtype == DEATH_SWAMP)
416 bprint ("^1",s, "^1 was conserved by ", a, "\n");
417 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
419 p = strstrofs(inflictor.message2, "#", 0);
421 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
423 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
425 else if(deathtype == DEATH_SBCRUSH)
426 bprint ("^1",s, "^1 was crushed by ^1", a, "\n");
427 else if(deathtype == DEATH_SBMINIGUN)
428 bprint ("^1",s, "^1 got shredded by ^1", a, "\n");
429 else if(deathtype == DEATH_SBROCKET)
430 bprint ("^1",s, "^1 was blased to bits by ^1", a, "\n");
431 else if(deathtype == DEATH_SBBLOWUP)
432 bprint ("^1",s, "^1 got cought in the destruction of ^1", a, "'s vehicle\n");
434 else if(deathtype == DEATH_WAKIGUN)
435 bprint ("^1",s, "^1 was bolted down by ^1", a, "\n");
436 else if(deathtype == DEATH_WAKIROCKET)
437 bprint ("^1",s, "^1 could find no shelter from ^1", a, "'s rockets\n");
438 else if(deathtype == DEATH_WAKIBLOWUP)
439 bprint ("^1",s, "^1 dies when ^1", a, "'s wakizashi dies.\n");
441 else if(deathtype == DEATH_TURRET)
442 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
443 else if(deathtype == DEATH_TOUCHEXPLODE)
444 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
445 else if(deathtype == DEATH_CHEAT)
446 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
447 else if (deathtype == DEATH_FIRE)
448 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
449 else if (deathtype == DEATH_CUSTOM)
450 bprint ("^1",s, "^1 ", deathmessage, " by ^1", a, "\n");
452 bprint ("^1",s, "^1 was fragged by ", a, "\n");
455 if(g_ctf && targ.flagcarried)
457 UpdateFrags(attacker, ctf_score_value("score_kill"));
458 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
459 GiveFrags(attacker, targ, 0); // for logging
462 GiveFrags(attacker, targ, 1);
464 if (targ.killcount > 2) {
466 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
468 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
471 attacker.killcount = attacker.killcount + 1;
473 if (attacker.killcount > 2) {
475 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
477 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
480 LogDeath("frag", deathtype, attacker, targ);
482 if (attacker.killcount == 3)
485 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
487 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
488 announce(attacker, "announcer/male/03kills.wav");
491 else if (attacker.killcount == 5)
494 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
496 bprint (a,"^7 unleashes ^1RAGE\n");
497 announce(attacker, "announcer/male/05kills.wav");
500 else if (attacker.killcount == 10)
503 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
505 bprint (a,"^7 starts the ^1MASSACRE!\n");
506 announce(attacker, "announcer/male/10kills.wav");
509 else if (attacker.killcount == 15)
512 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
514 bprint (a,"^7 executes ^1MAYHEM!\n");
515 announce(attacker, "announcer/male/15kills.wav");
518 else if (attacker.killcount == 20)
521 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
523 bprint (a,"^7 is a ^1BERSERKER!\n");
524 announce(attacker, "announcer/male/20kills.wav");
527 else if (attacker.killcount == 25)
530 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
532 bprint (a,"^7 inflicts ^1CARNAGE!\n");
533 announce(attacker, "announcer/male/25kills.wav");
536 else if (attacker.killcount == 30)
539 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
541 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
542 announce(attacker, "announcer/male/30kills.wav");
549 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
550 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
551 bprint ("^1",s, "^1 ", inflictor.message, "\n");
552 else if (deathtype == DEATH_DROWN)
554 bprint ("^1",s, "^1 was in the water for too long\n");
556 bprint ("^1",s, "^1 drowned\n");
557 else if (deathtype == DEATH_SLIME)
558 bprint ("^1",s, "^1 was slimed\n");
559 else if (deathtype == DEATH_LAVA)
561 bprint ("^1",s, "^1 found a hot place\n");
563 bprint ("^1",s, "^1 turned into hot slag\n");
564 else if (deathtype == DEATH_FALL)
566 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
568 bprint ("^1",s, "^1 hit the ground with a crunch\n");
569 else if (deathtype == DEATH_SHOOTING_STAR)
570 bprint ("^1",s, "^1 became a shooting star\n");
571 else if (deathtype == DEATH_SWAMP)
573 bprint ("^1",s, "^1 discovered a swamp\n");
575 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
576 else if(deathtype == DEATH_TURRET)
577 bprint ("^1",s, "^1 was mowed down by a turret \n");
578 else if (deathtype == DEATH_CUSTOM)
579 bprint ("^1",s, "^1 ", deathmessage, "\n");
580 else if(deathtype == DEATH_TOUCHEXPLODE)
581 bprint ("^1",s, "^1 died in an accident\n");
582 else if(deathtype == DEATH_CHEAT)
583 bprint ("^1",s, "^1 was unfairly eliminated\n");
584 else if(deathtype == DEATH_FIRE)
586 bprint ("^1",s, "^1 felt a little hot\n");
588 bprint ("^1",s, "^1 burnt to death\n");
591 bprint ("^1",s, "^1 needs a restart\n");
593 bprint ("^1",s, "^1 died\n");
594 GiveFrags(targ, targ, -1);
595 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
596 announce(targ, "announcer/male/botlike.wav");
599 if (targ.killcount > 2)
601 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
603 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
605 LogDeath("accident", deathtype, targ, targ);
608 targ.death_origin = targ.origin;
610 targ.killer_origin = attacker.origin;
612 // FIXME: this should go in PutClientInServer
618 // these are updated by each Damage call for use in button triggering and such
620 entity damage_inflictor;
621 entity damage_attacker;
623 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
628 entity attacker_save;
632 if (gameover || targ.killcount == -666)
635 local entity oldself;
639 damage_inflictor = inflictor;
640 damage_attacker = attacker;
641 attacker_save = attacker;
643 if(targ.classname == "player")
646 if(targ.hook.aiment == attacker)
647 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
649 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
650 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
652 if(targ.classname == "player")
653 if not(IsDifferentTeam(targ, attacker))
660 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
662 // These are ALWAYS lethal
663 // No damage modification here
664 // Instead, prepare the victim for his death...
666 targ.spawnshieldtime = 0;
667 targ.health = 0.9; // this is < 1
668 targ.flags -= targ.flags & FL_GODMODE;
671 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
677 if (targ.classname == "player")
678 if (attacker.classname == "player")
681 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
683 // nullify damage if teamplay is on
684 if(deathtype != DEATH_TELEFRAG)
685 if(attacker.classname == "player")
687 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
692 else if(attacker.team == targ.team)
696 else if(attacker != targ)
700 else if(teamplay == 4)
702 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
704 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
705 attacker.dmg_team = attacker.dmg_team + damage;
706 if(attacker.dmg_team > teamdamage0 && !g_ca)
707 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
708 mirrorforce = cvar("g_mirrordamage") * vlen(force);
711 if(cvar("g_friendlyfire") == 0)
717 damage = cvar("g_friendlyfire") * damage;
718 // mirrordamage will be used LATER
727 if(targ.classname == "player")
728 if(attacker.classname == "player")
731 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
732 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
735 if(targ.classname == "player")
738 if ((deathtype == DEATH_FALL) ||
739 (deathtype == DEATH_DROWN) ||
740 (deathtype == DEATH_SLIME) ||
741 (deathtype == DEATH_LAVA) ||
742 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
749 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
751 targ.armorvalue -= 1;
752 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
755 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
757 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
760 if (targ != attacker)
762 if (targ.classname == "player")
763 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
773 if not(DEATH_ISSPECIAL(deathtype))
775 damage *= g_weapondamagefactor;
776 mirrordamage *= g_weapondamagefactor;
777 force = force * g_weaponforcefactor;
778 mirrorforce *= g_weaponforcefactor;
781 // apply strength multiplier
782 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
786 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
787 force = force * cvar("g_balance_powerup_strength_selfforce");
791 damage = damage * cvar("g_balance_powerup_strength_damage");
792 force = force * cvar("g_balance_powerup_strength_force");
796 // apply invincibility multiplier
797 if (targ.items & IT_INVINCIBLE && !g_minstagib)
798 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
800 if (targ == attacker)
802 if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))
805 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
808 // CTF: reduce damage/force
813 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
814 force = force * cvar("g_ctf_flagcarrier_selfforce");
819 // apply strength rune
820 if (attacker.runes & RUNE_STRENGTH)
822 if(attacker.runes & CURSE_WEAK) // have both curse & rune
824 damage = damage * cvar("g_balance_rune_strength_combo_damage");
825 force = force * cvar("g_balance_rune_strength_combo_force");
829 damage = damage * cvar("g_balance_rune_strength_damage");
830 force = force * cvar("g_balance_rune_strength_force");
833 else if (attacker.runes & CURSE_WEAK)
835 damage = damage * cvar("g_balance_curse_weak_damage");
836 force = force * cvar("g_balance_curse_weak_force");
839 // apply defense rune
840 if (targ.runes & RUNE_DEFENSE)
842 if (targ.runes & CURSE_VULNER) // have both curse & rune
843 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
845 damage = damage * cvar("g_balance_rune_defense_takedamage");
847 else if (targ.runes & CURSE_VULNER)
848 damage = damage * cvar("g_balance_curse_vulner_takedamage");
854 if(targ.takedamage == DAMAGE_AIM)
857 if(targ.classname == "player")
860 // find height of hit on player axis
861 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
862 vector headmins, headmaxs, org;
863 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
864 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);
865 headmaxs = org + '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
866 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
868 deathtype |= HITTYPE_HEADSHOT;
871 else if(targ.classname == "turret_head")
873 deathtype |= HITTYPE_HEADSHOT;
875 if(deathtype & HITTYPE_HEADSHOT)
876 damage *= 1 + damage_headshotbonus;
878 if(targ.classname == "player")
880 if(IsDifferentTeam(targ, attacker))
885 attacker.typehitsound += 1;
887 attacker.hitsound += 1;
889 damage_goodhits += 1;
890 damage_gooddamage += damage;
892 if not(DEATH_ISSPECIAL(deathtype))
899 if(targ.items & IT_STRENGTH)
902 if(deathtype & HITTYPE_HEADSHOT)
909 if(deathtype != DEATH_FIRE)
910 attacker.typehitsound += 1;
912 if(time > attacker.teamkill_complain)
914 attacker.teamkill_complain = time + 5;
915 attacker.teamkill_soundtime = time + 0.4;
916 attacker.teamkill_soundsource = targ;
924 if (self.damageforcescale)
926 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
928 self.velocity = self.velocity + self.damageforcescale * force;
929 self.flags &~= FL_ONGROUND;
930 UpdateCSQCProjectile(self);
933 if (damage != 0 || (self.damageforcescale && vlen(force)))
934 if (self.event_damage)
935 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
938 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
940 // Savage: vampire mode
943 if (time >= self.spawnshieldtime)
945 attacker.health += damage;
949 if (attacker.runes & RUNE_VAMPIRE)
951 // apply vampire rune
952 if (attacker.runes & CURSE_EMPATHY) // have the curse too
954 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
955 attacker.health = bound(
956 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
957 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
958 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
962 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
963 attacker.health = bound(
964 attacker.health, // LA: was 3, but changed so that you can't lose health
965 // empathy won't let you gain health in the same way...
966 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
967 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
970 // apply empathy curse
971 else if (attacker.runes & CURSE_EMPATHY)
973 attacker.health = bound(
974 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
975 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
981 // apply mirror damage if any
982 if(mirrordamage > 0 || mirrorforce > 0)
984 attacker = attacker_save;
988 // just lose extra LIVES, don't kill the player for mirror damage
989 if(attacker.armorvalue > 0)
991 attacker.armorvalue = attacker.armorvalue - 1;
992 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
993 attacker.hitsound += 1;
997 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
998 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
1002 vector NearestPointOnBox(entity box, vector org)
1004 vector m1, m2, nearest;
1006 m1 = box.mins + box.origin;
1007 m2 = box.maxs + box.origin;
1009 nearest_x = bound(m1_x, org_x, m2_x);
1010 nearest_y = bound(m1_y, org_y, m2_y);
1011 nearest_z = bound(m1_z, org_z, m2_z);
1016 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
1019 weaponid = DEATH_WEAPONOF(deathtype);
1021 if not(inWarmupStage)
1023 if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {
1024 attacker.stats_hit[weaponid - 1] += damage;
1025 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);
1029 float RadiusDamage_running;
1030 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
1031 // Returns total damage applies to creatures
1041 float total_damage_to_creatures;
1046 float stat_damagedone;
1047 float stat_maxdamage;
1049 if(RadiusDamage_running)
1052 print("RadiusDamage called recursively!\n");
1053 print("Expect stuff to go HORRIBLY wrong.\n");
1054 print("Causing a stack trace...\n");
1055 save = cvar_string("prvm_backtraceforwarnings");
1056 cvar_set("prvm_backtraceforwarnings", "1");
1057 fclose(-1); // calls VM_Warning
1058 cvar_set("prvm_backtraceforwarnings", save);
1062 RadiusDamage_running = 1;
1064 tfloordmg = cvar("g_throughfloor_damage");
1065 tfloorforce = cvar("g_throughfloor_force");
1067 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1068 total_damage_to_creatures = 0;
1070 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1071 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
1073 force = inflictor.velocity;
1074 if(vlen(force) == 0)
1077 force = normalize(force);
1078 if(forceintensity >= 0)
1079 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1081 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1084 stat_damagedone = 0;
1087 targ = findradius (blastorigin, rad);
1091 if (targ != inflictor)
1092 if (ignore != targ) if(targ.takedamage)
1094 // LordHavoc: measure distance to nearest point on target (not origin)
1095 // (this guarentees 100% damage on a touch impact)
1096 nearest = NearestPointOnBox(targ, blastorigin);
1097 diff = nearest - blastorigin;
1098 // round up a little on the damage to ensure full damage on impacts
1099 // and turn the distance into a fraction of the radius
1100 power = 1 - ((vlen (diff) - 2) / rad);
1102 //bprint(ftos(power));
1103 //if (targ == attacker)
1104 // print(ftos(power), "\n");
1109 finaldmg = coredamage * power + edgedamage * (1 - power);
1116 local float hitratio;
1117 local vector hitloc;
1118 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1119 // if it's a player, use the view origin as reference
1120 if (targ.classname == "player")
1121 center = targ.origin + targ.view_ofs;
1122 force = normalize(center - blastorigin);
1123 force = force * (finaldmg / coredamage) * forceintensity;
1124 // test line of sight to multiple positions on box,
1125 // and do damage if any of them hit
1127 if (targ.classname == "player")
1128 total = ceil(bound(1, finaldmg, 50));
1130 total = ceil(bound(1, finaldmg/10, 5));
1135 traceline(blastorigin, nearest, MOVE_NOMONSTERS, inflictor);
1136 if (trace_fraction == 1 || trace_ent == targ)
1140 hitloc = hitloc + nearest;
1144 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1145 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1146 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1149 nearest = hitloc * (1 / max(1, hits));
1150 hitratio = (hits / total);
1151 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1152 finaldmg = finaldmg * a;
1153 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1155 //if (targ == attacker)
1157 // print("hits ", ftos(hits), " / ", ftos(total));
1158 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1159 // print(" (", ftos(a), ")\n");
1161 if(hits || tfloordmg || tfloorforce)
1165 total_damage_to_creatures += finaldmg;
1167 if(targ.flags & FL_CLIENT)
1168 if(targ.deadflag == DEAD_NO)
1169 if(targ != attacker)
1170 if(!teamplay || targ.team != attacker.team)
1172 stat_damagedone += finaldmg;
1173 stat_maxdamage += coredamage;
1177 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1178 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1180 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1188 RadiusDamage_running = 0;
1190 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1192 return total_damage_to_creatures;
1195 .float fire_damagepersec;
1196 .float fire_endtime;
1197 .float fire_deathtype;
1199 .float fire_hitsound;
1200 .entity fire_burner;
1202 void fireburner_think();
1204 float Fire_IsBurning(entity e)
1206 return (time < e.fire_endtime);
1209 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1212 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1214 if(e.classname == "player")
1223 // print("adding a fire burner to ", e.classname, "\n");
1224 e.fire_burner = spawn();
1225 e.fire_burner.classname = "fireburner";
1226 e.fire_burner.think = fireburner_think;
1227 e.fire_burner.nextthink = time;
1228 e.fire_burner.owner = e;
1234 if(Fire_IsBurning(e))
1236 mintime = e.fire_endtime - time;
1237 maxtime = max(mintime, t);
1239 mindps = e.fire_damagepersec;
1240 maxdps = max(mindps, dps);
1242 if(maxtime > mintime || maxdps > mindps)
1244 mindamage = mindps * mintime;
1245 maxdamage = mindamage + d;
1247 // interval [mintime, maxtime] * [mindps, maxdps]
1249 // [mindamage, maxdamage]
1252 if(maxdamage >= maxtime * maxdps)
1254 totaltime = maxtime;
1255 totaldamage = maxtime * maxdps;
1257 // this branch increases totaldamage if either t > mintime, or dps > mindps
1261 // maxdamage is inside the interval!
1262 // first, try to use mindps; only if this fails, increase dps as needed
1263 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1264 totaldamage = maxdamage;
1265 // can totaldamage / totaltime be >= maxdps?
1266 // max(mindps, maxdamage / maxtime) >= maxdps?
1267 // we know maxdamage < maxtime * maxdps
1270 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1273 // total conditions for increasing:
1274 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1276 // if maxtime = mintime, maxdps = mindps
1278 // maxdamage = mindamage + d
1279 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1280 // so the last condition is not needed
1282 e.fire_damagepersec = totaldamage / totaltime;
1283 e.fire_endtime = time + totaltime;
1284 if(totaldamage > 1.2 * mindamage)
1286 e.fire_deathtype = dt;
1287 if(e.fire_owner != o)
1290 e.fire_hitsound = FALSE;
1293 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1300 e.fire_damagepersec = dps;
1301 e.fire_endtime = time + t;
1302 e.fire_deathtype = dt;
1304 e.fire_hitsound = FALSE;
1309 void Fire_ApplyDamage(entity e)
1313 if not(Fire_IsBurning(e))
1316 // water and slime stop fire
1318 if(e.watertype != CONTENT_LAVA)
1321 t = min(frametime, e.fire_endtime - time);
1322 d = e.fire_damagepersec * t;
1324 hi = e.fire_owner.hitsound;
1325 ty = e.fire_owner.typehitsound;
1326 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1327 if(e.fire_hitsound && e.fire_owner)
1329 e.fire_owner.hitsound = hi;
1330 e.fire_owner.typehitsound = ty;
1332 e.fire_hitsound = TRUE;
1334 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1336 if not(IS_INDEPENDENT_PLAYER(e))
1337 FOR_EACH_PLAYER(other) if(e != other)
1339 if(other.classname == "player")
1340 if(other.deadflag == DEAD_NO)
1341 if not(IS_INDEPENDENT_PLAYER(other))
1342 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1344 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1345 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1346 Fire_AddDamage(other, e, d, t, DEATH_FIRE);
1351 void Fire_ApplyEffect(entity e)
1353 if(Fire_IsBurning(e))
1354 e.effects |= EF_FLAME;
1356 e.effects &~= EF_FLAME;
1359 void fireburner_think()
1361 // for players, this is done in the regular loop
1362 if(wasfreed(self.owner))
1367 Fire_ApplyEffect(self.owner);
1368 if(!Fire_IsBurning(self.owner))
1370 self.owner.fire_burner = world;
1374 Fire_ApplyDamage(self.owner);
1375 self.nextthink = time;