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")
239 a = attacker.netname;
241 if (targ == attacker)
243 if (deathtype == DEATH_TEAMCHANGE) {
244 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
245 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
246 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)));
248 } else if (deathtype == DEATH_CAMP) {
250 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
252 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
253 } else if (deathtype == DEATH_NOAMMO) {
255 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
257 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
258 } else if (deathtype == DEATH_ROT) {
260 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
262 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
263 } else if (deathtype == DEATH_MIRRORDAMAGE) {
265 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
267 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
270 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
272 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
276 if (deathtype == DEATH_CAMP)
277 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
278 else if (deathtype == DEATH_MIRRORDAMAGE)
279 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
281 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
283 if(deathtype != DEATH_TEAMCHANGE)
285 LogDeath("suicide", deathtype, targ, targ);
286 GiveFrags(attacker, targ, -1);
288 if (targ.killcount > 2)
289 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
291 w = DEATH_WEAPONOF(deathtype);
294 w_deathtypestring = "couldn't resist the urge to self-destruct";
295 w_deathtype = deathtype;
296 weapon_action(w, WR_SUICIDEMESSAGE);
297 bprint("^1", s, "^1 ", w_deathtypestring, "\n");
299 else if (deathtype == DEATH_KILL)
300 bprint ("^1",s, "^1 couldn't take it anymore\n");
301 else if (deathtype == DEATH_ROT)
302 bprint ("^1",s, "^1 died\n");
303 else if (deathtype == DEATH_NOAMMO)
304 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
305 else if (deathtype == DEATH_CAMP)
306 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
307 else if (deathtype == DEATH_MIRRORDAMAGE)
308 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
309 else if (deathtype == DEATH_CHEAT)
310 bprint ("^1",s, "^1 unfairly eliminated himself\n");
311 else if (deathtype == DEATH_FIRE)
312 bprint ("^1",s, "^1 burned to death\n");
313 else if (deathtype != DEATH_TEAMCHANGE)
314 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
316 if(deathtype != DEATH_TEAMCHANGE)
318 LogDeath("suicide", deathtype, targ, targ);
319 GiveFrags(attacker, targ, -1);
321 if (targ.killcount > 2)
322 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
325 else if (attacker.classname == "player" || attacker.classname == "gib")
327 if(teams_matter && attacker.team == targ.team)
330 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
331 bprint ("^1", a, "^1 took action against a team mate\n");
333 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
334 bprint ("^1", a, "^1 mows down a team mate\n");
336 GiveFrags(attacker, targ, -1);
337 if (targ.killcount > 2) {
339 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
341 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
343 if (attacker.killcount > 2) {
345 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
347 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
349 attacker.killcount = 0;
351 LogDeath("tk", deathtype, attacker, targ);
355 string blood_message, victim_message;
356 if (!checkrules_firstblood)
358 checkrules_firstblood = TRUE;
361 bprint("^1",a, "^1 was the first to score", "\n");
362 blood_message = "^1First point\n";
363 //victim_message = "^1First victim\n"; // or First casualty
367 bprint("^1",a, "^1 drew first blood", "\n");
368 blood_message = "^1First blood\n";
369 victim_message = "^1First victim\n"; // or First casualty
373 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You scored against ^7", s, GetAdvancedDeathReports(targ)));
374 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7", GetAdvancedDeathReports(attacker)));
376 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
377 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You ^1typefragged ^7", s, GetAdvancedDeathReports(targ)));
378 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typefragged by ^7", a, GetAdvancedDeathReports(attacker)));
380 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s, GetAdvancedDeathReports(targ)));
381 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a, GetAdvancedDeathReports(attacker)));
383 attacker.taunt_soundtime = time + 1;
387 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
389 w = DEATH_WEAPONOF(deathtype);
392 w_deathtypestring = "was blasted by";
393 w_deathtype = deathtype;
394 weapon_action(w, WR_KILLMESSAGE);
395 p = strstrofs(w_deathtypestring, "#", 0);
397 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
399 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
401 else if (deathtype == DEATH_TELEFRAG)
402 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
403 else if (deathtype == DEATH_DROWN)
404 bprint ("^1",s, "^1 was drowned by ", a, "\n");
405 else if (deathtype == DEATH_SLIME)
406 bprint ("^1",s, "^1 was slimed by ", a, "\n");
407 else if (deathtype == DEATH_LAVA)
408 bprint ("^1",s, "^1 was cooked by ", a, "\n");
409 else if (deathtype == DEATH_FALL)
410 bprint ("^1",s, "^1 was grounded by ", a, "\n");
411 else if (deathtype == DEATH_SHOOTING_STAR)
412 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
413 else if (deathtype == DEATH_SWAMP)
414 bprint ("^1",s, "^1 was conserved by ", a, "\n");
415 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
417 p = strstrofs(inflictor.message2, "#", 0);
419 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
421 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
423 else if(deathtype == DEATH_TURRET)
424 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
425 else if(deathtype == DEATH_TOUCHEXPLODE)
426 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
427 else if(deathtype == DEATH_CHEAT)
428 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
429 else if (deathtype == DEATH_FIRE)
430 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
432 bprint ("^1",s, "^1 was fragged by ", a, "\n");
435 if(g_ctf && targ.flagcarried)
437 UpdateFrags(attacker, ctf_score_value("score_kill"));
438 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
439 GiveFrags(attacker, targ, 0); // for logging
442 GiveFrags(attacker, targ, 1);
444 if (targ.killcount > 2) {
446 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
448 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
451 attacker.killcount = attacker.killcount + 1;
453 if (attacker.killcount > 2) {
455 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
457 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
460 LogDeath("frag", deathtype, attacker, targ);
462 if (attacker.killcount == 3)
465 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
467 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
468 announce(attacker, "announcer/male/03kills.wav");
471 else if (attacker.killcount == 5)
474 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
476 bprint (a,"^7 unleashes ^1RAGE\n");
477 announce(attacker, "announcer/male/05kills.wav");
480 else if (attacker.killcount == 10)
483 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
485 bprint (a,"^7 starts the ^1MASSACRE!\n");
486 announce(attacker, "announcer/male/10kills.wav");
489 else if (attacker.killcount == 15)
492 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
494 bprint (a,"^7 executes ^1MAYHEM!\n");
495 announce(attacker, "announcer/male/15kills.wav");
498 else if (attacker.killcount == 20)
501 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
503 bprint (a,"^7 is a ^1BERSERKER!\n");
504 announce(attacker, "announcer/male/20kills.wav");
507 else if (attacker.killcount == 25)
510 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
512 bprint (a,"^7 inflicts ^1CARNAGE!\n");
513 announce(attacker, "announcer/male/25kills.wav");
516 else if (attacker.killcount == 30)
519 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
521 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
522 announce(attacker, "announcer/male/30kills.wav");
529 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
530 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
531 bprint ("^1",s, "^1 ", inflictor.message, "\n");
532 else if (deathtype == DEATH_DROWN)
534 bprint ("^1",s, "^1 was in the water for too long\n");
536 bprint ("^1",s, "^1 drowned\n");
537 else if (deathtype == DEATH_SLIME)
538 bprint ("^1",s, "^1 was slimed\n");
539 else if (deathtype == DEATH_LAVA)
541 bprint ("^1",s, "^1 found a hot place\n");
543 bprint ("^1",s, "^1 turned into hot slag\n");
544 else if (deathtype == DEATH_FALL)
546 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
548 bprint ("^1",s, "^1 hit the ground with a crunch\n");
549 else if (deathtype == DEATH_SHOOTING_STAR)
550 bprint ("^1",s, "^1 became a shooting star\n");
551 else if (deathtype == DEATH_SWAMP)
553 bprint ("^1",s, "^1 discovered a swamp\n");
555 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
556 else if(deathtype == DEATH_TURRET)
557 bprint ("^1",s, "^1 was mowed down by a turret \n");
558 else if(deathtype == DEATH_TOUCHEXPLODE)
559 bprint ("^1",s, "^1 died in an accident\n");
560 else if(deathtype == DEATH_CHEAT)
561 bprint ("^1",s, "^1 was unfairly eliminated\n");
562 else if(deathtype == DEATH_FIRE)
564 bprint ("^1",s, "^1 felt a little hot\n");
566 bprint ("^1",s, "^1 burnt to death\n");
569 bprint ("^1",s, "^1 needs a restart\n");
571 bprint ("^1",s, "^1 died\n");
572 GiveFrags(targ, targ, -1);
573 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
574 announce(targ, "announcer/male/botlike.wav");
577 if (targ.killcount > 2)
579 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
581 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
583 LogDeath("accident", deathtype, targ, targ);
585 targ.death_origin = targ.origin;
587 targ.killer_origin = attacker.origin;
588 // FIXME: this should go in PutClientInServer
594 // these are updated by each Damage call for use in button triggering and such
596 entity damage_inflictor;
597 entity damage_attacker;
599 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
604 entity attacker_save;
608 if (gameover || targ.killcount == -666)
611 local entity oldself;
615 damage_inflictor = inflictor;
616 damage_attacker = attacker;
617 attacker_save = attacker;
619 if(targ.classname == "player")
622 if(targ.hook.aiment == attacker)
623 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
625 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
626 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
628 if(targ.classname == "player")
629 if not(IsDifferentTeam(targ, attacker))
636 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
638 // These are ALWAYS lethal
639 // No damage modification here
640 // Instead, prepare the victim for his death...
642 targ.spawnshieldtime = 0;
643 targ.health = 0.9; // this is < 1
644 targ.flags -= targ.flags & FL_GODMODE;
647 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
653 if (targ.classname == "player")
654 if (attacker.classname == "player")
657 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
659 // nullify damage if teamplay is on
660 if(deathtype != DEATH_TELEFRAG)
661 if(attacker.classname == "player")
663 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
668 else if(attacker.team == targ.team)
672 else if(attacker != targ)
676 else if(teamplay == 4)
678 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
680 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
681 attacker.dmg_team = attacker.dmg_team + damage;
682 if(attacker.dmg_team > teamdamage0)
683 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
684 mirrorforce = cvar("g_mirrordamage") * vlen(force);
687 if(cvar("g_friendlyfire") == 0)
691 damage = cvar("g_friendlyfire") * damage;
692 // mirrordamage will be used LATER
701 if(targ.classname == "player")
702 if(attacker.classname == "player")
705 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
706 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
709 if(targ.classname == "player")
712 if ((deathtype == DEATH_FALL) ||
713 (deathtype == DEATH_DROWN) ||
714 (deathtype == DEATH_SLIME) ||
715 (deathtype == DEATH_LAVA))
720 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
722 targ.armorvalue -= 1;
723 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
726 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
728 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
731 if (targ != attacker)
733 if (targ.classname == "player")
734 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
744 if not(DEATH_ISSPECIAL(deathtype))
746 damage *= g_weapondamagefactor;
747 mirrordamage *= g_weapondamagefactor;
748 force = force * g_weaponforcefactor;
749 mirrorforce *= g_weaponforcefactor;
752 // apply strength multiplier
753 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
757 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
758 force = force * cvar("g_balance_powerup_strength_selfforce");
762 damage = damage * cvar("g_balance_powerup_strength_damage");
763 force = force * cvar("g_balance_powerup_strength_force");
767 // apply invincibility multiplier
768 if (targ.items & IT_INVINCIBLE && !g_minstagib)
769 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
771 if (targ == attacker)
772 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
774 // CTF: reduce damage/force
779 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
780 force = force * cvar("g_ctf_flagcarrier_selfforce");
785 // apply strength rune
786 if (attacker.runes & RUNE_STRENGTH)
788 if(attacker.runes & CURSE_WEAK) // have both curse & rune
790 damage = damage * cvar("g_balance_rune_strength_combo_damage");
791 force = force * cvar("g_balance_rune_strength_combo_force");
795 damage = damage * cvar("g_balance_rune_strength_damage");
796 force = force * cvar("g_balance_rune_strength_force");
799 else if (attacker.runes & CURSE_WEAK)
801 damage = damage * cvar("g_balance_curse_weak_damage");
802 force = force * cvar("g_balance_curse_weak_force");
805 // apply defense rune
806 if (targ.runes & RUNE_DEFENSE)
808 if (targ.runes & CURSE_VULNER) // have both curse & rune
809 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
811 damage = damage * cvar("g_balance_rune_defense_takedamage");
813 else if (targ.runes & CURSE_VULNER)
814 damage = damage * cvar("g_balance_curse_vulner_takedamage");
820 if(targ.takedamage == DAMAGE_AIM)
823 if(targ.classname == "player")
826 // find height of hit on player axis
827 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
828 vector headmins, headmaxs, org;
829 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
830 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);
831 headmaxs = org + '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
832 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
834 deathtype |= HITTYPE_HEADSHOT;
837 else if(targ.classname == "turret_head")
839 deathtype |= HITTYPE_HEADSHOT;
841 if(deathtype & HITTYPE_HEADSHOT)
842 damage *= 1 + damage_headshotbonus;
844 if(targ.classname == "player")
846 if(IsDifferentTeam(targ, attacker))
851 attacker.typehitsound += 1;
853 attacker.hitsound += 1;
855 damage_goodhits += 1;
856 damage_gooddamage += damage;
858 if not(DEATH_ISSPECIAL(deathtype))
865 if(targ.items & IT_STRENGTH)
868 if(deathtype & HITTYPE_HEADSHOT)
875 if(deathtype != DEATH_FIRE)
876 attacker.typehitsound += 1;
878 if(time > attacker.teamkill_complain)
880 attacker.teamkill_complain = time + 5;
881 attacker.teamkill_soundtime = time + 0.4;
882 attacker.teamkill_soundsource = targ;
890 if (self.damageforcescale)
892 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
894 self.velocity = self.velocity + self.damageforcescale * force;
895 self.flags &~= FL_ONGROUND;
896 UpdateCSQCProjectile(self);
899 if (damage != 0 || (self.damageforcescale && vlen(force)))
900 if (self.event_damage)
901 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
904 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
906 // Savage: vampire mode
909 if (time >= self.spawnshieldtime)
911 attacker.health += damage;
915 if (attacker.runes & RUNE_VAMPIRE)
917 // apply vampire rune
918 if (attacker.runes & CURSE_EMPATHY) // have the curse too
920 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
921 attacker.health = bound(
922 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
923 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
924 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
928 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
929 attacker.health = bound(
930 attacker.health, // LA: was 3, but changed so that you can't lose health
931 // empathy won't let you gain health in the same way...
932 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
933 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
936 // apply empathy curse
937 else if (attacker.runes & CURSE_EMPATHY)
939 attacker.health = bound(
940 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
941 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
947 // apply mirror damage if any
948 if(mirrordamage > 0 || mirrorforce > 0)
950 attacker = attacker_save;
954 // just lose extra LIVES, don't kill the player for mirror damage
955 if(attacker.armorvalue > 0)
957 attacker.armorvalue = attacker.armorvalue - 1;
958 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
959 attacker.hitsound += 1;
963 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
964 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
968 vector NearestPointOnBox(entity box, vector org)
970 vector m1, m2, nearest;
972 m1 = box.mins + box.origin;
973 m2 = box.maxs + box.origin;
975 nearest_x = bound(m1_x, org_x, m2_x);
976 nearest_y = bound(m1_y, org_y, m2_y);
977 nearest_z = bound(m1_z, org_z, m2_z);
982 .float actual_damage[WEP_COUNT]; //amount of damage done
983 .float max_damage[WEP_COUNT]; //the maximum damage of the weapon
985 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(actual_damage);
986 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(max_damage);
988 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
991 weaponid = DEATH_WEAPONOF(deathtype);
992 if not(inWarmupStage)
994 if(clienttype(attacker) == CLIENTTYPE_REAL)
996 // Track damage done and update the stat to be sent later in g_world.qc
997 attacker.actual_damage[weaponid] += damage;
998 attacker.damage_hits = weaponid + 64 * rint(attacker.actual_damage[weaponid]);
1002 float RadiusDamage_running;
1003 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
1004 // Returns total damage applies to creatures
1014 float total_damage_to_creatures;
1019 float stat_damagedone;
1020 float stat_maxdamage;
1022 if(RadiusDamage_running)
1025 print("RadiusDamage called recursively!\n");
1026 print("Expect stuff to go HORRIBLY wrong.\n");
1027 print("Causing a stack trace...\n");
1028 save = cvar_string("prvm_backtraceforwarnings");
1029 cvar_set("prvm_backtraceforwarnings", "1");
1030 fclose(-1); // calls VM_Warning
1031 cvar_set("prvm_backtraceforwarnings", save);
1035 RadiusDamage_running = 1;
1037 tfloordmg = cvar("g_throughfloor_damage");
1038 tfloorforce = cvar("g_throughfloor_force");
1040 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1041 total_damage_to_creatures = 0;
1043 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1045 force = inflictor.velocity;
1046 if(vlen(force) == 0)
1049 force = normalize(force);
1050 if(forceintensity >= 0)
1051 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1053 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1056 stat_damagedone = 0;
1059 targ = findradius (blastorigin, rad);
1063 if (targ != inflictor)
1064 if (ignore != targ) if(targ.takedamage)
1066 // LordHavoc: measure distance to nearest point on target (not origin)
1067 // (this guarentees 100% damage on a touch impact)
1068 nearest = NearestPointOnBox(targ, blastorigin);
1069 diff = nearest - blastorigin;
1070 // round up a little on the damage to ensure full damage on impacts
1071 // and turn the distance into a fraction of the radius
1072 power = 1 - ((vlen (diff) - 2) / rad);
1074 //bprint(ftos(power));
1075 //if (targ == attacker)
1076 // print(ftos(power), "\n");
1081 finaldmg = coredamage * power + edgedamage * (1 - power);
1088 local float hitratio;
1089 local vector hitloc;
1090 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1091 // if it's a player, use the view origin as reference
1092 if (targ.classname == "player")
1093 center = targ.origin + targ.view_ofs;
1094 force = normalize(center - blastorigin);
1095 force = force * (finaldmg / coredamage) * forceintensity;
1096 // test line of sight to multiple positions on box,
1097 // and do damage if any of them hit
1099 if (targ.classname == "player")
1100 total = ceil(bound(1, finaldmg, 50));
1102 total = ceil(bound(1, finaldmg/10, 5));
1107 traceline(blastorigin, nearest, MOVE_NOMONSTERS, inflictor);
1108 if (trace_fraction == 1 || trace_ent == targ)
1112 hitloc = hitloc + nearest;
1116 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1117 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1118 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1121 nearest = hitloc * (1 / max(1, hits));
1122 hitratio = (hits / total);
1123 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1124 finaldmg = finaldmg * a;
1125 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1127 //if (targ == attacker)
1129 // print("hits ", ftos(hits), " / ", ftos(total));
1130 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1131 // print(" (", ftos(a), ")\n");
1133 if(hits || tfloordmg || tfloorforce)
1137 total_damage_to_creatures += finaldmg;
1139 if(targ.flags & FL_CLIENT)
1140 if(targ.deadflag == DEAD_NO)
1141 if(targ != attacker)
1142 if(!teamplay || targ.team != attacker.team)
1144 stat_damagedone += finaldmg;
1145 stat_maxdamage += coredamage;
1149 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1150 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1152 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1160 RadiusDamage_running = 0;
1162 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1164 return total_damage_to_creatures;
1167 .float fire_damagepersec;
1168 .float fire_endtime;
1169 .float fire_deathtype;
1171 .float fire_hitsound;
1172 .entity fire_burner;
1174 void fireburner_think();
1176 float Fire_IsBurning(entity e)
1178 return (time < e.fire_endtime);
1181 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1184 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1186 if(e.classname == "player")
1195 // print("adding a fire burner to ", e.classname, "\n");
1196 e.fire_burner = spawn();
1197 e.fire_burner.classname = "fireburner";
1198 e.fire_burner.think = fireburner_think;
1199 e.fire_burner.nextthink = time;
1200 e.fire_burner.owner = e;
1206 if(Fire_IsBurning(e))
1208 mintime = e.fire_endtime - time;
1209 maxtime = max(mintime, t);
1211 mindps = e.fire_damagepersec;
1212 maxdps = max(mindps, dps);
1214 if(maxtime > mintime || maxdps > mindps)
1216 mindamage = mindps * mintime;
1217 maxdamage = mindamage + d;
1219 // interval [mintime, maxtime] * [mindps, maxdps]
1221 // [mindamage, maxdamage]
1224 if(maxdamage >= maxtime * maxdps)
1226 totaltime = maxtime;
1227 totaldamage = maxtime * maxdps;
1229 // this branch increases totaldamage if either t > mintime, or dps > mindps
1233 // maxdamage is inside the interval!
1234 // first, try to use mindps; only if this fails, increase dps as needed
1235 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1236 totaldamage = maxdamage;
1237 // can totaldamage / totaltime be >= maxdps?
1238 // max(mindps, maxdamage / maxtime) >= maxdps?
1239 // we know maxdamage < maxtime * maxdps
1242 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1245 // total conditions for increasing:
1246 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1248 // if maxtime = mintime, maxdps = mindps
1250 // maxdamage = mindamage + d
1251 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1252 // so the last condition is not needed
1254 e.fire_damagepersec = totaldamage / totaltime;
1255 e.fire_endtime = time + totaltime;
1256 if(totaldamage > 1.2 * mindamage)
1258 e.fire_deathtype = dt;
1259 if(e.fire_owner != o)
1262 e.fire_hitsound = FALSE;
1265 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1272 e.fire_damagepersec = dps;
1273 e.fire_endtime = time + t;
1274 e.fire_deathtype = dt;
1276 e.fire_hitsound = FALSE;
1281 void Fire_ApplyDamage(entity e)
1285 if not(Fire_IsBurning(e))
1288 // water and slime stop fire
1290 if(e.watertype != CONTENT_LAVA)
1293 t = min(frametime, e.fire_endtime - time);
1294 d = e.fire_damagepersec * t;
1296 hi = e.fire_owner.hitsound;
1297 ty = e.fire_owner.typehitsound;
1298 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1299 if(e.fire_hitsound && e.fire_owner)
1301 e.fire_owner.hitsound = hi;
1302 e.fire_owner.typehitsound = ty;
1304 e.fire_hitsound = TRUE;
1306 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1308 if not(IS_INDEPENDENT_PLAYER(e))
1309 FOR_EACH_PLAYER(other) if(e != other)
1311 if(other.classname == "player")
1312 if(other.deadflag == DEAD_NO)
1313 if not(IS_INDEPENDENT_PLAYER(other))
1314 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1316 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1317 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1318 Fire_AddDamage(other, e, d, t, DEATH_FIRE);
1323 void Fire_ApplyEffect(entity e)
1325 if(Fire_IsBurning(e))
1326 e.effects |= EF_FLAME;
1328 e.effects &~= EF_FLAME;
1331 void fireburner_think()
1333 // for players, this is done in the regular loop
1334 if(wasfreed(self.owner))
1339 Fire_ApplyEffect(self.owner);
1340 if(!Fire_IsBurning(self.owner))
1342 self.owner.fire_burner = world;
1346 Fire_ApplyDamage(self.owner);
1347 self.nextthink = time;