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 vector GetHeadshotMins(entity targ)
91 return '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);
93 vector GetHeadshotMaxs(entity targ)
95 return '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
98 void UpdateFrags(entity player, float f)
100 PlayerTeamScore_AddScore(player, f);
103 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
104 void W_SwitchWeapon_Force(entity e, float w);
105 void GiveFrags (entity attacker, entity targ, float f)
109 // TODO route through PlayerScores instead
117 PlayerScore_Add(attacker, SP_SUICIDES, 1);
122 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
128 PlayerScore_Add(attacker, SP_KILLS, 1);
131 PlayerScore_Add(targ, SP_DEATHS, 1);
134 if(cvar("g_arena_roundbased"))
137 if(targ != attacker) // not for suicides
138 if(g_weaponarena_random)
140 // after a frag, choose another random weapon set
142 w = warmup_start_weapons;
146 attacker.weapons = randombits(w - (w & W_WeaponBit(attacker.weapon)), g_weaponarena_random, TRUE);
147 if(attacker.weapons < 0)
149 // error from randombits: no weapon available
150 // this means we can just give ALL weapons
151 attacker.weapons = w;
153 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
154 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
157 // FIXME fix the mess this is (we have REAL points now!)
161 frag_attacker = attacker;
164 if(MUTATOR_CALLHOOK(GiveFragsForKill))
174 f = RunematchHandleFrags(attacker, targ, f);
180 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
181 if(tl < lms_lowest_lives)
182 lms_lowest_lives = tl;
186 lms_next_place = player_count;
187 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
194 if(g_ctf_ignore_frags)
199 attacker.totalfrags += f;
202 UpdateFrags(attacker, f);
205 string AppendItemcodes(string s, entity player)
210 // w = player.switchweapon;
212 w = player.cnt; // previous weapon!
213 s = strcat(s, ftos(w));
214 if(time < player.strength_finished)
216 if(time < player.invincible_finished)
218 if(player.flagcarried != world)
220 if(player.BUTTON_CHAT)
225 s = strcat(s, "|", ftos(player.runes));
229 void LogDeath(string mode, float deathtype, entity killer, entity killed)
232 if(!cvar("sv_eventlog"))
234 s = strcat(":kill:", mode);
235 s = strcat(s, ":", ftos(killer.playerid));
236 s = strcat(s, ":", ftos(killed.playerid));
237 s = strcat(s, ":type=", ftos(deathtype));
238 s = strcat(s, ":items=");
239 s = AppendItemcodes(s, killer);
242 s = strcat(s, ":victimitems=");
243 s = AppendItemcodes(s, killed);
248 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
253 if (targ.classname == "player" || targ.classname == "corpse")
255 if (targ.classname == "corpse")
260 a = attacker.netname;
262 if (targ == attacker)
264 if (deathtype == DEATH_TEAMCHANGE) {
265 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
266 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
267 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)));
269 } else if (deathtype == DEATH_CAMP) {
271 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
273 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
274 } else if (deathtype == DEATH_NOAMMO) {
276 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
278 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
279 } else if (deathtype == DEATH_ROT) {
281 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
283 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
284 } else if (deathtype == DEATH_MIRRORDAMAGE) {
286 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
288 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
289 } else if (deathtype == DEATH_QUIET) {
293 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
295 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
298 if (deathtype == DEATH_CAMP)
299 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
300 else if (deathtype == DEATH_MIRRORDAMAGE)
301 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
303 bprint ("^1",s, "^1 will be reinserted into the game due to their own actions\n");
305 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
307 LogDeath("suicide", deathtype, targ, targ);
308 GiveFrags(attacker, targ, -1);
310 if (targ.killcount > 2)
311 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
313 w = DEATH_WEAPONOF(deathtype);
316 w_deathtypestring = "couldn't resist the urge to self-destruct";
317 w_deathtype = deathtype;
318 weapon_action(w, WR_SUICIDEMESSAGE);
319 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
321 else if (deathtype == DEATH_KILL)
322 bprint ("^1",s, "^1 couldn't take it anymore\n");
323 else if (deathtype == DEATH_ROT)
324 bprint ("^1",s, "^1 died\n");
325 else if (deathtype == DEATH_NOAMMO)
326 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
327 else if (deathtype == DEATH_CAMP)
328 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
329 else if (deathtype == DEATH_MIRRORDAMAGE)
330 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
331 else if (deathtype == DEATH_CHEAT)
332 bprint ("^1",s, "^1 unfairly eliminated themself\n");
333 else if (deathtype == DEATH_FIRE)
334 bprint ("^1",s, "^1 burned to death\n");
335 else if (deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
336 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
338 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
340 LogDeath("suicide", deathtype, targ, targ);
341 GiveFrags(attacker, targ, -1);
343 if (targ.killcount > 2)
344 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
347 else if (attacker.classname == "player" || attacker.classname == "gib")
349 if(teams_matter && attacker.team == targ.team)
352 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
353 bprint ("^1", a, "^1 took action against a team mate\n");
355 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
356 bprint ("^1", a, "^1 mows down a team mate\n");
358 GiveFrags(attacker, targ, -1);
359 if (targ.killcount > 2) {
361 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
363 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
365 if (attacker.killcount > 2) {
367 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
369 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
371 attacker.killcount = 0;
373 LogDeath("tk", deathtype, attacker, targ);
377 string blood_message, victim_message;
378 if (!checkrules_firstblood)
380 checkrules_firstblood = TRUE;
383 bprint("^1",a, "^1 was the first to score", "\n");
384 blood_message = "^1First point\n";
385 //victim_message = "^1First victim\n"; // or First casualty
389 bprint("^1",a, "^1 drew first blood", "\n");
390 blood_message = "^1First blood\n";
391 victim_message = "^1First victim\n"; // or First casualty
395 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You scored against ^7", s, GetAdvancedDeathReports(targ)));
396 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7", GetAdvancedDeathReports(attacker)));
398 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
399 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^1You typefragged ^7", s, GetAdvancedDeathReports(targ)));
400 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typefragged by ^7", a, GetAdvancedDeathReports(attacker)));
402 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s, GetAdvancedDeathReports(targ)));
403 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a, GetAdvancedDeathReports(attacker)));
405 attacker.taunt_soundtime = time + 1;
409 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
411 w = DEATH_WEAPONOF(deathtype);
414 w_deathtypestring = "was blasted by";
415 w_deathtype = deathtype;
416 weapon_action(w, WR_KILLMESSAGE);
417 p = strstrofs(w_deathtypestring, "#", 0);
419 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
421 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
423 else if (deathtype == DEATH_TELEFRAG)
424 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
425 else if (deathtype == DEATH_DROWN)
426 bprint ("^1",s, "^1 was drowned by ", a, "\n");
427 else if (deathtype == DEATH_SLIME)
428 bprint ("^1",s, "^1 was slimed by ", a, "\n");
429 else if (deathtype == DEATH_LAVA)
430 bprint ("^1",s, "^1 was cooked by ", a, "\n");
431 else if (deathtype == DEATH_FALL)
432 bprint ("^1",s, "^1 was grounded by ", a, "\n");
433 else if (deathtype == DEATH_SHOOTING_STAR)
434 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
435 else if (deathtype == DEATH_SWAMP)
436 bprint ("^1",s, "^1 was conserved by ", a, "\n");
437 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
439 p = strstrofs(inflictor.message2, "#", 0);
441 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
443 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
445 else if(deathtype == DEATH_SBCRUSH)
446 bprint ("^1",s, "^1 was crushed by ^1", a, "\n");
447 else if(deathtype == DEATH_SBMINIGUN)
448 bprint ("^1",s, "^1 got shredded by ^1", a, "\n");
449 else if(deathtype == DEATH_SBROCKET)
450 bprint ("^1",s, "^1 was blased to bits by ^1", a, "\n");
451 else if(deathtype == DEATH_SBBLOWUP)
452 bprint ("^1",s, "^1 got cought in the destruction of ^1", a, "'s vehicle\n");
454 else if(deathtype == DEATH_WAKIGUN)
455 bprint ("^1",s, "^1 was bolted down by ^1", a, "\n");
456 else if(deathtype == DEATH_WAKIROCKET)
457 bprint ("^1",s, "^1 could find no shelter from ^1", a, "'s rockets\n");
458 else if(deathtype == DEATH_WAKIBLOWUP)
459 bprint ("^1",s, "^1 dies when ^1", a, "'s wakizashi dies.\n");
461 else if(deathtype == DEATH_TURRET)
462 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
463 else if(deathtype == DEATH_TOUCHEXPLODE)
464 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
465 else if(deathtype == DEATH_CHEAT)
466 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
467 else if (deathtype == DEATH_FIRE)
468 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
469 else if (deathtype == DEATH_CUSTOM)
470 bprint ("^1",s, "^1 ", deathmessage, " by ^1", a, "\n");
472 bprint ("^1",s, "^1 was fragged by ", a, "\n");
475 if(g_ctf && targ.flagcarried)
477 UpdateFrags(attacker, ctf_score_value("score_kill"));
478 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
479 GiveFrags(attacker, targ, 0); // for logging
482 GiveFrags(attacker, targ, 1);
484 if (targ.killcount > 2) {
486 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
488 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
491 attacker.killcount = attacker.killcount + 1;
493 if (attacker.killcount > 2) {
495 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
497 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
500 LogDeath("frag", deathtype, attacker, targ);
502 if (attacker.killcount == 3)
505 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
507 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
508 AnnounceTo(attacker, "03kills");
511 else if (attacker.killcount == 5)
514 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
516 bprint (a,"^7 unleashes ^1RAGE\n");
517 AnnounceTo(attacker, "05kills");
520 else if (attacker.killcount == 10)
523 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
525 bprint (a,"^7 starts the ^1MASSACRE!\n");
526 AnnounceTo(attacker, "10kills");
529 else if (attacker.killcount == 15)
532 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
534 bprint (a,"^7 executes ^1MAYHEM!\n");
535 AnnounceTo(attacker, "15kills");
538 else if (attacker.killcount == 20)
541 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
543 bprint (a,"^7 is a ^1BERSERKER!\n");
544 AnnounceTo(attacker, "20kills");
547 else if (attacker.killcount == 25)
550 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
552 bprint (a,"^7 inflicts ^1CARNAGE!\n");
553 AnnounceTo(attacker, "25kills");
556 else if (attacker.killcount == 30)
559 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
561 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
562 AnnounceTo(attacker, "30kills");
569 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
570 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
571 bprint ("^1",s, "^1 ", inflictor.message, "\n");
572 else if (deathtype == DEATH_DROWN)
574 bprint ("^1",s, "^1 was in the water for too long\n");
576 bprint ("^1",s, "^1 drowned\n");
577 else if (deathtype == DEATH_SLIME)
578 bprint ("^1",s, "^1 was slimed\n");
579 else if (deathtype == DEATH_LAVA)
581 bprint ("^1",s, "^1 found a hot place\n");
583 bprint ("^1",s, "^1 turned into hot slag\n");
584 else if (deathtype == DEATH_FALL)
586 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
588 bprint ("^1",s, "^1 hit the ground with a crunch\n");
589 else if (deathtype == DEATH_SHOOTING_STAR)
590 bprint ("^1",s, "^1 became a shooting star\n");
591 else if (deathtype == DEATH_SWAMP)
593 bprint ("^1",s, "^1 discovered a swamp\n");
595 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
596 else if(deathtype == DEATH_TURRET)
597 bprint ("^1",s, "^1 was mowed down by a turret \n");
598 else if (deathtype == DEATH_CUSTOM)
599 bprint ("^1",s, "^1 ", deathmessage, "\n");
600 else if(deathtype == DEATH_TOUCHEXPLODE)
601 bprint ("^1",s, "^1 died in an accident\n");
602 else if(deathtype == DEATH_CHEAT)
603 bprint ("^1",s, "^1 was unfairly eliminated\n");
604 else if(deathtype == DEATH_FIRE)
606 bprint ("^1",s, "^1 felt a little hot\n");
608 bprint ("^1",s, "^1 burnt to death\n");
611 bprint ("^1",s, "^1 needs a restart\n");
613 bprint ("^1",s, "^1 died\n");
614 GiveFrags(targ, targ, -1);
615 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
616 AnnounceTo(targ, "botlike");
619 if (targ.killcount > 2)
621 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
623 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
625 LogDeath("accident", deathtype, targ, targ);
628 targ.death_origin = targ.origin;
630 targ.killer_origin = attacker.origin;
632 // FIXME: this should go in PutClientInServer
638 // these are updated by each Damage call for use in button triggering and such
640 entity damage_inflictor;
641 entity damage_attacker;
643 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
648 entity attacker_save;
652 if (gameover || targ.killcount == -666)
655 local entity oldself;
659 damage_inflictor = inflictor;
660 damage_attacker = attacker;
661 attacker_save = attacker;
663 if(targ.classname == "player")
666 if(targ.hook.aiment == attacker)
667 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
669 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
670 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
672 if(targ.classname == "player")
673 if not(IsDifferentTeam(targ, attacker))
680 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
682 // These are ALWAYS lethal
683 // No damage modification here
684 // Instead, prepare the victim for his death...
686 targ.spawnshieldtime = 0;
687 targ.health = 0.9; // this is < 1
688 targ.flags -= targ.flags & FL_GODMODE;
691 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
697 if (targ.classname == "player")
698 if (attacker.classname == "player")
701 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
703 // nullify damage if teamplay is on
704 if(deathtype != DEATH_TELEFRAG)
705 if(attacker.classname == "player")
707 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
712 else if(attacker.team == targ.team)
716 else if(attacker != targ)
720 else if(teamplay == 4)
722 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
724 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
725 attacker.dmg_team = attacker.dmg_team + damage;
726 if(attacker.dmg_team > teamdamage0 && !g_ca)
727 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
728 mirrorforce = cvar("g_mirrordamage") * vlen(force);
731 if(cvar("g_friendlyfire") == 0)
737 damage = cvar("g_friendlyfire") * damage;
738 // mirrordamage will be used LATER
747 if(targ.classname == "player")
748 if(attacker.classname == "player")
751 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
752 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
755 if(targ.classname == "player")
758 if ((deathtype == DEATH_FALL) ||
759 (deathtype == DEATH_DROWN) ||
760 (deathtype == DEATH_SLIME) ||
761 (deathtype == DEATH_LAVA) ||
762 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
769 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
771 targ.armorvalue -= 1;
772 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
775 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
777 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
780 if (targ != attacker)
782 if ((targ.health >= 1) && (targ.classname == "player"))
783 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
793 if not(DEATH_ISSPECIAL(deathtype))
795 damage *= g_weapondamagefactor;
796 mirrordamage *= g_weapondamagefactor;
797 force = force * g_weaponforcefactor;
798 mirrorforce *= g_weaponforcefactor;
801 // apply strength multiplier
802 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
806 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
807 force = force * cvar("g_balance_powerup_strength_selfforce");
811 damage = damage * cvar("g_balance_powerup_strength_damage");
812 force = force * cvar("g_balance_powerup_strength_force");
816 // apply invincibility multiplier
817 if (targ.items & IT_INVINCIBLE && !g_minstagib)
818 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
820 if (targ == attacker)
822 if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))
825 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
828 // CTF: reduce damage/force
833 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
834 force = force * cvar("g_ctf_flagcarrier_selfforce");
839 // apply strength rune
840 if (attacker.runes & RUNE_STRENGTH)
842 if(attacker.runes & CURSE_WEAK) // have both curse & rune
844 damage = damage * cvar("g_balance_rune_strength_combo_damage");
845 force = force * cvar("g_balance_rune_strength_combo_force");
849 damage = damage * cvar("g_balance_rune_strength_damage");
850 force = force * cvar("g_balance_rune_strength_force");
853 else if (attacker.runes & CURSE_WEAK)
855 damage = damage * cvar("g_balance_curse_weak_damage");
856 force = force * cvar("g_balance_curse_weak_force");
859 // apply defense rune
860 if (targ.runes & RUNE_DEFENSE)
862 if (targ.runes & CURSE_VULNER) // have both curse & rune
863 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
865 damage = damage * cvar("g_balance_rune_defense_takedamage");
867 else if (targ.runes & CURSE_VULNER)
868 damage = damage * cvar("g_balance_curse_vulner_takedamage");
874 if(targ.takedamage == DAMAGE_AIM)
877 if(targ.classname == "player")
880 // find height of hit on player axis
881 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
882 vector headmins, headmaxs, org;
883 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
884 headmins = org + GetHeadshotMins(targ);
885 headmaxs = org + GetHeadshotMaxs(targ);
886 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
888 deathtype |= HITTYPE_HEADSHOT;
891 else if(targ.classname == "turret_head")
893 deathtype |= HITTYPE_HEADSHOT;
895 if(deathtype & HITTYPE_HEADSHOT)
896 damage *= 1 + damage_headshotbonus;
898 if(targ.classname == "player")
900 if(IsDifferentTeam(targ, attacker))
905 attacker.typehitsound += 1;
907 attacker.hitsound += 1;
909 damage_goodhits += 1;
910 damage_gooddamage += damage;
912 if not(DEATH_ISSPECIAL(deathtype))
919 if(targ.items & IT_STRENGTH)
922 if(deathtype & HITTYPE_HEADSHOT)
929 if(deathtype != DEATH_FIRE)
930 attacker.typehitsound += 1;
932 if(time > attacker.teamkill_complain)
934 attacker.teamkill_complain = time + 5;
935 attacker.teamkill_soundtime = time + 0.4;
936 attacker.teamkill_soundsource = targ;
944 if (self.damageforcescale)
946 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
948 self.velocity = self.velocity + self.damageforcescale * force;
949 self.flags &~= FL_ONGROUND;
950 UpdateCSQCProjectile(self);
953 if (damage != 0 || (self.damageforcescale && vlen(force)))
954 if (self.event_damage)
955 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
958 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
960 // Savage: vampire mode
963 if (time >= self.spawnshieldtime)
965 attacker.health += damage;
969 if (attacker.runes & RUNE_VAMPIRE)
971 // apply vampire rune
972 if (attacker.runes & CURSE_EMPATHY) // have the curse too
974 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
975 attacker.health = bound(
976 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
977 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
978 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
982 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
983 attacker.health = bound(
984 attacker.health, // LA: was 3, but changed so that you can't lose health
985 // empathy won't let you gain health in the same way...
986 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
987 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
990 // apply empathy curse
991 else if (attacker.runes & CURSE_EMPATHY)
993 attacker.health = bound(
994 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
995 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
1001 // apply mirror damage if any
1002 if(mirrordamage > 0 || mirrorforce > 0)
1004 attacker = attacker_save;
1006 if(mirrordamage > 0)
1008 // just lose extra LIVES, don't kill the player for mirror damage
1009 if(attacker.armorvalue > 0)
1011 attacker.armorvalue = attacker.armorvalue - 1;
1012 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
1013 attacker.hitsound += 1;
1017 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
1018 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
1022 vector NearestPointOnBox(entity box, vector org)
1024 vector m1, m2, nearest;
1026 m1 = box.mins + box.origin;
1027 m2 = box.maxs + box.origin;
1029 nearest_x = bound(m1_x, org_x, m2_x);
1030 nearest_y = bound(m1_y, org_y, m2_y);
1031 nearest_z = bound(m1_z, org_z, m2_z);
1036 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
1039 weaponid = DEATH_WEAPONOF(deathtype);
1041 if not(inWarmupStage)
1043 if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {
1044 attacker.stats_hit[weaponid - 1] += damage;
1045 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);
1049 float RadiusDamage_running;
1050 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
1051 // Returns total damage applies to creatures
1061 float total_damage_to_creatures;
1066 float stat_damagedone;
1067 float stat_maxdamage;
1069 if(RadiusDamage_running)
1072 print("RadiusDamage called recursively!\n");
1073 print("Expect stuff to go HORRIBLY wrong.\n");
1074 print("Causing a stack trace...\n");
1075 save = cvar_string("prvm_backtraceforwarnings");
1076 cvar_set("prvm_backtraceforwarnings", "1");
1077 fclose(-1); // calls VM_Warning
1078 cvar_set("prvm_backtraceforwarnings", save);
1082 RadiusDamage_running = 1;
1084 tfloordmg = cvar("g_throughfloor_damage");
1085 tfloorforce = cvar("g_throughfloor_force");
1087 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1088 total_damage_to_creatures = 0;
1090 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1091 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
1093 force = inflictor.velocity;
1094 if(vlen(force) == 0)
1097 force = normalize(force);
1098 if(forceintensity >= 0)
1099 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1101 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1104 stat_damagedone = 0;
1107 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
1111 if (targ != inflictor)
1112 if (ignore != targ) if(targ.takedamage)
1114 // LordHavoc: measure distance to nearest point on target (not origin)
1115 // (this guarentees 100% damage on a touch impact)
1116 nearest = targ.WarpZone_findradius_nearest;
1117 diff = targ.WarpZone_findradius_dist;
1118 // round up a little on the damage to ensure full damage on impacts
1119 // and turn the distance into a fraction of the radius
1120 power = 1 - ((vlen (diff) - 2) / rad);
1122 //bprint(ftos(power));
1123 //if (targ == attacker)
1124 // print(ftos(power), "\n");
1129 finaldmg = coredamage * power + edgedamage * (1 - power);
1136 local float hitratio;
1137 local vector hitloc;
1138 local vector myblastorigin;
1139 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1140 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1141 // if it's a player, use the view origin as reference
1142 if (targ.classname == "player")
1143 center = targ.origin + targ.view_ofs;
1144 force = normalize(center - myblastorigin);
1145 force = force * (finaldmg / coredamage) * forceintensity;
1146 // test line of sight to multiple positions on box,
1147 // and do damage if any of them hit
1149 if (targ.classname == "player")
1150 total = ceil(bound(1, finaldmg, 50));
1152 total = ceil(bound(1, finaldmg/10, 5));
1157 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1158 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1159 if (trace_fraction == 1 || trace_ent == targ)
1163 hitloc = hitloc + nearest;
1167 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1168 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1169 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1172 nearest = hitloc * (1 / max(1, hits));
1173 hitratio = (hits / total);
1174 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1175 finaldmg = finaldmg * a;
1176 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1178 //if (targ == attacker)
1180 // print("hits ", ftos(hits), " / ", ftos(total));
1181 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1182 // print(" (", ftos(a), ")\n");
1184 if(hits || tfloordmg || tfloorforce)
1188 total_damage_to_creatures += finaldmg;
1190 if(targ.flags & FL_CLIENT)
1191 if(targ.deadflag == DEAD_NO)
1192 if(targ != attacker)
1193 if(!teamplay || targ.team != attacker.team)
1195 stat_damagedone += finaldmg;
1196 stat_maxdamage += coredamage;
1200 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1201 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1203 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1211 RadiusDamage_running = 0;
1213 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1215 return total_damage_to_creatures;
1218 .float fire_damagepersec;
1219 .float fire_endtime;
1220 .float fire_deathtype;
1222 .float fire_hitsound;
1223 .entity fire_burner;
1225 void fireburner_think();
1227 float Fire_IsBurning(entity e)
1229 return (time < e.fire_endtime);
1232 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1235 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1237 if(e.classname == "player")
1246 // print("adding a fire burner to ", e.classname, "\n");
1247 e.fire_burner = spawn();
1248 e.fire_burner.classname = "fireburner";
1249 e.fire_burner.think = fireburner_think;
1250 e.fire_burner.nextthink = time;
1251 e.fire_burner.owner = e;
1257 if(Fire_IsBurning(e))
1259 mintime = e.fire_endtime - time;
1260 maxtime = max(mintime, t);
1262 mindps = e.fire_damagepersec;
1263 maxdps = max(mindps, dps);
1265 if(maxtime > mintime || maxdps > mindps)
1267 mindamage = mindps * mintime;
1268 maxdamage = mindamage + d;
1270 // interval [mintime, maxtime] * [mindps, maxdps]
1272 // [mindamage, maxdamage]
1275 if(maxdamage >= maxtime * maxdps)
1277 totaltime = maxtime;
1278 totaldamage = maxtime * maxdps;
1280 // this branch increases totaldamage if either t > mintime, or dps > mindps
1284 // maxdamage is inside the interval!
1285 // first, try to use mindps; only if this fails, increase dps as needed
1286 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1287 totaldamage = maxdamage;
1288 // can totaldamage / totaltime be >= maxdps?
1289 // max(mindps, maxdamage / maxtime) >= maxdps?
1290 // we know maxdamage < maxtime * maxdps
1293 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1296 // total conditions for increasing:
1297 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1299 // if maxtime = mintime, maxdps = mindps
1301 // maxdamage = mindamage + d
1302 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1303 // so the last condition is not needed
1305 e.fire_damagepersec = totaldamage / totaltime;
1306 e.fire_endtime = time + totaltime;
1307 if(totaldamage > 1.2 * mindamage)
1309 e.fire_deathtype = dt;
1310 if(e.fire_owner != o)
1313 e.fire_hitsound = FALSE;
1316 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1323 e.fire_damagepersec = dps;
1324 e.fire_endtime = time + t;
1325 e.fire_deathtype = dt;
1327 e.fire_hitsound = FALSE;
1332 void Fire_ApplyDamage(entity e)
1337 if not(Fire_IsBurning(e))
1343 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1346 // water and slime stop fire
1348 if(e.watertype != CONTENT_LAVA)
1351 t = min(frametime, e.fire_endtime - time);
1352 d = e.fire_damagepersec * t;
1354 hi = e.fire_owner.hitsound;
1355 ty = e.fire_owner.typehitsound;
1356 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1357 if(e.fire_hitsound && e.fire_owner)
1359 e.fire_owner.hitsound = hi;
1360 e.fire_owner.typehitsound = ty;
1362 e.fire_hitsound = TRUE;
1364 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1366 if not(IS_INDEPENDENT_PLAYER(e))
1367 FOR_EACH_PLAYER(other) if(e != other)
1369 if(other.classname == "player")
1370 if(other.deadflag == DEAD_NO)
1371 if not(IS_INDEPENDENT_PLAYER(other))
1372 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1374 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1375 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1376 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1381 void Fire_ApplyEffect(entity e)
1383 if(Fire_IsBurning(e))
1384 e.effects |= EF_FLAME;
1386 e.effects &~= EF_FLAME;
1389 void fireburner_think()
1391 // for players, this is done in the regular loop
1392 if(wasfreed(self.owner))
1397 Fire_ApplyEffect(self.owner);
1398 if(!Fire_IsBurning(self.owner))
1400 self.owner.fire_burner = world;
1404 Fire_ApplyDamage(self.owner);
1405 self.nextthink = time;