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 float checkrules_firstblood;
47 float damage_goodhits;
48 float damage_gooddamage;
50 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
53 .float teamkill_complain;
54 .float teamkill_soundtime;
55 .entity teamkill_soundsource;
57 .float taunt_soundtime;
60 float IsDifferentTeam(entity a, entity b)
75 float IsFlying(entity a)
77 if(a.flags & FL_ONGROUND)
79 if(a.waterlevel >= WATERLEVEL_SWIMMING)
81 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
82 if(trace_fraction < 1)
87 vector GetHeadshotMins(entity targ)
89 return '-0.5 0 0' * PL_HEAD_x + '0 -0.5 0' * PL_HEAD_y + '0 0 1' * (targ.maxs_z - PL_HEAD_z);
91 vector GetHeadshotMaxs(entity targ)
93 return '0.5 0 0' * PL_HEAD_x + '0 0.5 0' * PL_HEAD_y + '0 0 1' * targ.maxs_z;
96 void UpdateFrags(entity player, float f)
98 PlayerTeamScore_AddScore(player, f);
101 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
102 void W_SwitchWeapon_Force(entity e, float w);
103 void GiveFrags (entity attacker, entity targ, float f, float deathtype)
107 // TODO route through PlayerScores instead
115 PlayerScore_Add(attacker, SP_SUICIDES, 1);
120 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
126 PlayerScore_Add(attacker, SP_KILLS, 1);
129 PlayerScore_Add(targ, SP_DEATHS, 1);
132 if(autocvar_g_arena_roundbased)
135 if(targ != attacker) // not for suicides
136 if(g_weaponarena_random)
138 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
140 culprit = DEATH_WEAPONOF(deathtype);
141 if(!culprit || !(attacker.weapons & W_WeaponBit(culprit)))
142 culprit = attacker.weapon;
144 if(g_weaponarena_random_with_laser && culprit == WEPBIT_LASER)
151 w = warmup_start_weapons;
155 // all others (including the culprit): remove
156 w &~= attacker.weapons;
158 // among the remaining ones, choose one by random
159 w = randombits(w, 1, FALSE);
162 attacker.weapons |= w;
163 attacker.weapons &~= W_WeaponBit(culprit);
167 // after a frag, choose another random weapon set
168 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
169 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
172 // FIXME fix the mess this is (we have REAL points now!)
176 frag_attacker = attacker;
179 if(MUTATOR_CALLHOOK(GiveFragsForKill))
189 f = RunematchHandleFrags(attacker, targ, f);
195 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
196 if(tl < lms_lowest_lives)
197 lms_lowest_lives = tl;
201 lms_next_place = player_count;
203 lms_next_place = min(lms_next_place, player_count);
204 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
211 if(g_ctf_ignore_frags)
216 attacker.totalfrags += f;
219 UpdateFrags(attacker, f);
222 string AppendItemcodes(string s, entity player)
227 // w = player.switchweapon;
229 w = player.cnt; // previous weapon!
230 s = strcat(s, ftos(w));
231 if(time < player.strength_finished)
233 if(time < player.invincible_finished)
235 if(player.flagcarried != world)
237 if(player.BUTTON_CHAT)
242 s = strcat(s, "|", ftos(player.runes));
246 void LogDeath(string mode, float deathtype, entity killer, entity killed)
249 if(!autocvar_sv_eventlog)
251 s = strcat(":kill:", mode);
252 s = strcat(s, ":", ftos(killer.playerid));
253 s = strcat(s, ":", ftos(killed.playerid));
254 s = strcat(s, ":type=", ftos(deathtype));
255 s = strcat(s, ":items=");
256 s = AppendItemcodes(s, killer);
259 s = strcat(s, ":victimitems=");
260 s = AppendItemcodes(s, killed);
265 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
267 WriteByte(MSG_ALL, SVC_TEMPENTITY);
268 WriteByte(MSG_ALL, TE_CSQC_NOTIFY);
269 WriteByte(MSG_ALL, CSQC_KILLNOTIFY);
270 WriteString(MSG_ALL, s1);
271 WriteString(MSG_ALL, s2);
272 WriteString(MSG_ALL, s3);
273 WriteShort(MSG_ALL, msg);
274 WriteByte(MSG_ALL, type);
277 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
278 void Send_CSQC_Centerprint(entity e, string s1, string s2, float msg, float type)
280 if (clienttype(e) == CLIENTTYPE_REAL)
283 WRITESPECTATABLE_MSG_ONE({
284 WriteByte(MSG_ONE, SVC_TEMPENTITY);
285 WriteByte(MSG_ONE, TE_CSQC_NOTIFY);
286 WriteByte(MSG_ONE, CSQC_CENTERPRINT);
287 WriteString(MSG_ONE, s1);
288 WriteString(MSG_ONE, s2);
289 WriteShort(MSG_ONE, msg);
290 WriteByte(MSG_ONE, type);
295 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
300 if (targ.classname == "player" || targ.classname == "corpse")
302 if (targ.classname == "corpse")
307 a = attacker.netname;
309 if (targ == attacker) // suicides
311 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
312 msg = ColoredTeamName(targ.team); // TODO: check if needed?
313 if(!g_cts) // no "killed your own dumb self" message in CTS
314 Send_CSQC_Centerprint(targ, msg, "", deathtype, MSG_SUICIDE);
316 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
318 LogDeath("suicide", deathtype, targ, targ);
319 GiveFrags(attacker, targ, -1, deathtype);
322 if (targ.killcount > 2)
323 msg = ftos(targ.killcount);
324 if(teams_matter && deathtype == DEATH_MIRRORDAMAGE)
326 if(attacker.team == COLOR_TEAM1)
327 deathtype = KILL_TEAM_RED;
329 deathtype = KILL_TEAM_BLUE;
332 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
334 else if (attacker.classname == "player" || attacker.classname == "gib")
336 if(teams_matter && attacker.team == targ.team)
338 if(attacker.team == COLOR_TEAM1)
339 type = KILL_TEAM_RED;
341 type = KILL_TEAM_BLUE;
343 GiveFrags(attacker, targ, -1, deathtype);
345 Send_CSQC_Centerprint(attacker, s, "", type, MSG_KILL);
347 if (targ.killcount > 2) {
348 msg = ftos(targ.killcount);
351 if (attacker.killcount > 2) {
352 msg = ftos(attacker.killcount);
353 type = KILL_TEAM_SPREE;
355 Send_KillNotification(a, s, msg, type, MSG_KILL);
357 attacker.killcount = 0;
359 LogDeath("tk", deathtype, attacker, targ);
363 if (!checkrules_firstblood)
365 checkrules_firstblood = TRUE;
366 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
367 // TODO: make these print a newline if they dont
368 Send_CSQC_Centerprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
369 Send_CSQC_Centerprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
370 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
371 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
374 if((autocvar_sv_fragmessage_information_typefrag) && (targ.BUTTON_CHAT)) {
375 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_TYPEFRAG, MSG_KILL);
376 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_TYPEFRAGGED, MSG_KILL);
378 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_FRAG, MSG_KILL);
379 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_FRAGGED, MSG_KILL);
382 attacker.taunt_soundtime = time + 1;
385 if (deathtype == DEATH_CUSTOM)
388 msg = inflictor.message2;
390 if(strstrofs(msg, "%", 0) < 0)
391 msg = strcat("%s ", msg, " by %s");
393 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
395 if(g_ctf && targ.flagcarried)
397 UpdateFrags(attacker, ctf_score_value("score_kill"));
398 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
399 GiveFrags(attacker, targ, 0, deathtype); // for logging
402 GiveFrags(attacker, targ, 1, deathtype);
404 if (targ.killcount > 2) {
405 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
408 attacker.killcount = attacker.killcount + 1;
410 if (attacker.killcount > 2) {
411 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
413 else if (attacker.killcount == 3)
415 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
416 AnnounceTo(attacker, "03kills");
417 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
419 else if (attacker.killcount == 5)
421 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
422 AnnounceTo(attacker, "05kills");
423 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
425 else if (attacker.killcount == 10)
427 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
428 AnnounceTo(attacker, "10kills");
429 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
431 else if (attacker.killcount == 15)
433 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
434 AnnounceTo(attacker, "15kills");
435 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
437 else if (attacker.killcount == 20)
439 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
440 AnnounceTo(attacker, "20kills");
441 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
443 else if (attacker.killcount == 25)
445 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
446 AnnounceTo(attacker, "25kills");
447 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
449 else if (attacker.killcount == 30)
451 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
452 AnnounceTo(attacker, "30kills");
453 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
455 LogDeath("frag", deathtype, attacker, targ);
460 Send_CSQC_Centerprint(targ, "", "", deathtype, MSG_KILL_ACTION);
461 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
462 msg = inflictor.message;
463 else if (deathtype == DEATH_CUSTOM)
465 if(strstrofs(msg, "%", 0) < 0)
466 msg = strcat("%s ", msg);
468 GiveFrags(targ, targ, -1, deathtype);
469 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
470 AnnounceTo(targ, "botlike");
471 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
473 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
475 if (targ.killcount > 2)
476 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
478 LogDeath("accident", deathtype, targ, targ);
481 targ.death_origin = targ.origin;
483 targ.killer_origin = attacker.origin;
485 // FIXME: this should go in PutClientInServer
491 // these are updated by each Damage call for use in button triggering and such
493 entity damage_inflictor;
494 entity damage_attacker;
496 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
501 entity attacker_save;
505 if (gameover || targ.killcount == -666)
508 local entity oldself;
512 damage_inflictor = inflictor;
513 damage_attacker = attacker;
514 attacker_save = attacker;
516 if(targ.classname == "player")
519 if(targ.hook.aiment == attacker)
520 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
522 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
523 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
525 if(targ.classname == "player")
526 if not(IsDifferentTeam(targ, attacker))
533 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
535 // These are ALWAYS lethal
536 // No damage modification here
537 // Instead, prepare the victim for his death...
539 targ.spawnshieldtime = 0;
540 targ.health = 0.9; // this is < 1
541 targ.flags -= targ.flags & FL_GODMODE;
544 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
550 if (targ.classname == "player")
551 if (attacker.classname == "player")
554 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
556 // nullify damage if teamplay is on
557 if(deathtype != DEATH_TELEFRAG)
558 if(attacker.classname == "player")
560 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
565 else if(teams_matter && attacker.team == targ.team)
567 if(autocvar_teamplay_mode == 1)
569 else if(attacker != targ)
571 if(autocvar_teamplay_mode == 3)
573 else if(autocvar_teamplay_mode == 4)
575 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
577 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
578 attacker.dmg_team = attacker.dmg_team + damage;
579 if(attacker.dmg_team > teamdamage0 && !g_ca)
580 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
581 mirrorforce = autocvar_g_mirrordamage * vlen(force);
584 if(autocvar_g_friendlyfire == 0)
590 damage = autocvar_g_friendlyfire * damage;
591 // mirrordamage will be used LATER
593 if(autocvar_g_mirrordamage_virtual)
596 v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
597 attacker.dmg_take += v_x;
598 attacker.dmg_save += v_y;
599 attacker.dmg_inflictor = inflictor;
604 if(autocvar_g_friendlyfire_virtual)
607 v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
608 targ.dmg_take += v_x;
609 targ.dmg_save += v_y;
610 targ.dmg_inflictor = inflictor;
612 if(!autocvar_g_friendlyfire_virtual_force)
623 if(targ.classname == "player")
624 if(attacker.classname == "player")
627 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
628 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
631 if(targ.classname == "player")
634 if ((deathtype == DEATH_FALL) ||
635 (deathtype == DEATH_DROWN) ||
636 (deathtype == DEATH_SLIME) ||
637 (deathtype == DEATH_LAVA) ||
638 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
645 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
647 targ.armorvalue -= 1;
648 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
651 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
653 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
657 if (targ != attacker)
659 if ((targ.health >= 1) && (targ.classname == "player"))
660 centerprint(attacker, "Secondary fire inflicts no damage!");
668 if not(DEATH_ISSPECIAL(deathtype))
670 damage *= g_weapondamagefactor;
671 mirrordamage *= g_weapondamagefactor;
672 force = force * g_weaponforcefactor;
673 mirrorforce *= g_weaponforcefactor;
676 // should this be changed at all? If so, in what way?
677 frag_attacker = attacker;
679 frag_damage = damage;
681 frag_deathtype = deathtype;
682 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
683 damage = frag_damage;
686 // apply strength multiplier
687 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
691 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
692 force = force * autocvar_g_balance_powerup_strength_selfforce;
696 damage = damage * autocvar_g_balance_powerup_strength_damage;
697 force = force * autocvar_g_balance_powerup_strength_force;
701 // apply invincibility multiplier
702 if (targ.items & IT_INVINCIBLE && !g_minstagib)
703 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
705 if (targ == attacker)
707 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
710 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
713 // CTF: reduce damage/force
718 damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
719 force = force * autocvar_g_ctf_flagcarrier_selfforce;
724 // apply strength rune
725 if (attacker.runes & RUNE_STRENGTH)
727 if(attacker.runes & CURSE_WEAK) // have both curse & rune
729 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
730 force = force * autocvar_g_balance_rune_strength_combo_force;
734 damage = damage * autocvar_g_balance_rune_strength_damage;
735 force = force * autocvar_g_balance_rune_strength_force;
738 else if (attacker.runes & CURSE_WEAK)
740 damage = damage * autocvar_g_balance_curse_weak_damage;
741 force = force * autocvar_g_balance_curse_weak_force;
744 // apply defense rune
745 if (targ.runes & RUNE_DEFENSE)
747 if (targ.runes & CURSE_VULNER) // have both curse & rune
748 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
750 damage = damage * autocvar_g_balance_rune_defense_takedamage;
752 else if (targ.runes & CURSE_VULNER)
753 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
759 if(targ.takedamage == DAMAGE_AIM)
762 if(targ.classname == "player")
765 // find height of hit on player axis
766 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
767 vector headmins, headmaxs, org;
768 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
769 headmins = org + GetHeadshotMins(targ);
770 headmaxs = org + GetHeadshotMaxs(targ);
771 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
773 deathtype |= HITTYPE_HEADSHOT;
776 else if(targ.classname == "turret_head")
778 deathtype |= HITTYPE_HEADSHOT;
780 if(deathtype & HITTYPE_HEADSHOT)
781 damage *= 1 + damage_headshotbonus;
783 if(targ.classname == "player")
785 if(IsDifferentTeam(targ, attacker))
789 if(deathtype != DEATH_FIRE)
792 attacker.typehitsound += 1;
794 attacker.hitsound += 1;
797 damage_goodhits += 1;
798 damage_gooddamage += damage;
800 if not(DEATH_ISSPECIAL(deathtype))
807 if(targ.items & IT_STRENGTH)
810 if(deathtype & HITTYPE_HEADSHOT)
814 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
819 if(deathtype != DEATH_FIRE)
821 attacker.typehitsound += 1;
824 if(time > attacker.teamkill_complain)
826 attacker.teamkill_complain = time + 5;
827 attacker.teamkill_soundtime = time + 0.4;
828 attacker.teamkill_soundsource = targ;
836 if (self.damageforcescale)
838 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
840 self.velocity = self.velocity + damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
841 self.flags &~= FL_ONGROUND;
842 UpdateCSQCProjectile(self);
845 if (damage != 0 || (self.damageforcescale && vlen(force)))
846 if (self.event_damage)
847 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
850 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
854 if (attacker.runes & RUNE_VAMPIRE)
856 // apply vampire rune
857 if (attacker.runes & CURSE_EMPATHY) // have the curse too
859 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
860 attacker.health = bound(
861 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
862 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
863 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
867 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
868 attacker.health = bound(
869 attacker.health, // LA: was 3, but changed so that you can't lose health
870 // empathy won't let you gain health in the same way...
871 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
872 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
875 // apply empathy curse
876 else if (attacker.runes & CURSE_EMPATHY)
878 attacker.health = bound(
879 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
880 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
886 // apply mirror damage if any
887 if(mirrordamage > 0 || mirrorforce > 0)
889 attacker = attacker_save;
893 // just lose extra LIVES, don't kill the player for mirror damage
894 if(attacker.armorvalue > 0)
896 attacker.armorvalue = attacker.armorvalue - 1;
897 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
898 attacker.hitsound += 1;
903 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
904 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
908 float RadiusDamage_running;
909 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
910 // Returns total damage applies to creatures
920 float total_damage_to_creatures;
925 float stat_damagedone;
927 if(RadiusDamage_running)
929 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
933 RadiusDamage_running = 1;
935 tfloordmg = autocvar_g_throughfloor_damage;
936 tfloorforce = autocvar_g_throughfloor_force;
938 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
939 total_damage_to_creatures = 0;
941 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
942 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
944 force = inflictor.velocity;
948 force = normalize(force);
949 if(forceintensity >= 0)
950 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
952 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
957 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
961 if (targ != inflictor)
962 if (ignore != targ) if(targ.takedamage)
964 // LordHavoc: measure distance to nearest point on target (not origin)
965 // (this guarentees 100% damage on a touch impact)
966 nearest = targ.WarpZone_findradius_nearest;
967 diff = targ.WarpZone_findradius_dist;
968 // round up a little on the damage to ensure full damage on impacts
969 // and turn the distance into a fraction of the radius
970 power = 1 - ((vlen (diff) - 2) / rad);
972 //bprint(ftos(power));
973 //if (targ == attacker)
974 // print(ftos(power), "\n");
979 finaldmg = coredamage * power + edgedamage * (1 - power);
986 local float hitratio;
988 local vector myblastorigin;
989 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
990 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
991 // if it's a player, use the view origin as reference
992 if (targ.classname == "player")
993 center = targ.origin + targ.view_ofs;
994 force = normalize(center - myblastorigin);
995 force = force * (finaldmg / coredamage) * forceintensity;
996 // test line of sight to multiple positions on box,
997 // and do damage if any of them hit
999 if (targ.classname == "player")
1000 total = ceil(bound(1, finaldmg, 50));
1002 total = ceil(bound(1, finaldmg/10, 5));
1007 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1008 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1009 if (trace_fraction == 1 || trace_ent == targ)
1013 hitloc = hitloc + nearest;
1017 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1018 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1019 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1022 nearest = hitloc * (1 / max(1, hits));
1023 hitratio = (hits / total);
1024 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1025 finaldmg = finaldmg * a;
1026 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1029 // laser force adjustments :P
1030 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1032 if (targ == attacker)
1037 float force_velocitybiasramp;
1038 float force_velocitybias;
1040 force_velocitybiasramp = autocvar_sv_maxspeed;
1041 if(deathtype & HITTYPE_SECONDARY)
1043 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1044 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1048 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1049 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1052 vel = targ.velocity;
1054 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1058 normalize(normalize(force) + vel);
1060 force_z *= force_zscale;
1064 if(deathtype & HITTYPE_SECONDARY)
1066 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1070 force *= autocvar_g_balance_laser_primary_force_other_scale;
1075 //if (targ == attacker)
1077 // print("hits ", ftos(hits), " / ", ftos(total));
1078 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1079 // print(" (", ftos(a), ")\n");
1081 if(hits || tfloordmg || tfloorforce)
1085 total_damage_to_creatures += finaldmg;
1087 if(accuracy_isgooddamage(attacker, targ))
1088 stat_damagedone += finaldmg;
1091 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1092 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1094 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1102 RadiusDamage_running = 0;
1104 if(!DEATH_ISSPECIAL(deathtype))
1105 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1107 return total_damage_to_creatures;
1110 .float fire_damagepersec;
1111 .float fire_endtime;
1112 .float fire_deathtype;
1114 .float fire_hitsound;
1115 .entity fire_burner;
1117 void fireburner_think();
1119 float Fire_IsBurning(entity e)
1121 return (time < e.fire_endtime);
1124 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1127 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1129 if(e.classname == "player")
1138 // print("adding a fire burner to ", e.classname, "\n");
1139 e.fire_burner = spawn();
1140 e.fire_burner.classname = "fireburner";
1141 e.fire_burner.think = fireburner_think;
1142 e.fire_burner.nextthink = time;
1143 e.fire_burner.owner = e;
1149 if(Fire_IsBurning(e))
1151 mintime = e.fire_endtime - time;
1152 maxtime = max(mintime, t);
1154 mindps = e.fire_damagepersec;
1155 maxdps = max(mindps, dps);
1157 if(maxtime > mintime || maxdps > mindps)
1159 mindamage = mindps * mintime;
1160 maxdamage = mindamage + d;
1162 // interval [mintime, maxtime] * [mindps, maxdps]
1164 // [mindamage, maxdamage]
1167 if(maxdamage >= maxtime * maxdps)
1169 totaltime = maxtime;
1170 totaldamage = maxtime * maxdps;
1172 // this branch increases totaldamage if either t > mintime, or dps > mindps
1176 // maxdamage is inside the interval!
1177 // first, try to use mindps; only if this fails, increase dps as needed
1178 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1179 totaldamage = maxdamage;
1180 // can totaldamage / totaltime be >= maxdps?
1181 // max(mindps, maxdamage / maxtime) >= maxdps?
1182 // we know maxdamage < maxtime * maxdps
1185 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1188 // total conditions for increasing:
1189 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1191 // if maxtime = mintime, maxdps = mindps
1193 // maxdamage = mindamage + d
1194 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1195 // so the last condition is not needed
1197 e.fire_damagepersec = totaldamage / totaltime;
1198 e.fire_endtime = time + totaltime;
1199 if(totaldamage > 1.2 * mindamage)
1201 e.fire_deathtype = dt;
1202 if(e.fire_owner != o)
1205 e.fire_hitsound = FALSE;
1208 if(accuracy_isgooddamage(o, e))
1209 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1210 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1217 e.fire_damagepersec = dps;
1218 e.fire_endtime = time + t;
1219 e.fire_deathtype = dt;
1221 e.fire_hitsound = FALSE;
1222 if(accuracy_isgooddamage(o, e))
1223 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1228 void Fire_ApplyDamage(entity e)
1233 if not(Fire_IsBurning(e))
1236 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1237 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1240 // water and slime stop fire
1242 if(e.watertype != CONTENT_LAVA)
1246 if(e.freezetag_frozen)
1249 t = min(frametime, e.fire_endtime - time);
1250 d = e.fire_damagepersec * t;
1252 hi = e.fire_owner.hitsound;
1253 ty = e.fire_owner.typehitsound;
1254 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1255 if(e.fire_hitsound && e.fire_owner)
1257 e.fire_owner.hitsound = hi;
1258 e.fire_owner.typehitsound = ty;
1260 e.fire_hitsound = TRUE;
1262 if not(IS_INDEPENDENT_PLAYER(e))
1263 FOR_EACH_PLAYER(other) if(e != other)
1265 if(other.classname == "player")
1266 if(other.deadflag == DEAD_NO)
1267 if not(IS_INDEPENDENT_PLAYER(other))
1268 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1270 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1271 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1272 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1277 void Fire_ApplyEffect(entity e)
1279 if(Fire_IsBurning(e))
1280 e.effects |= EF_FLAME;
1282 e.effects &~= EF_FLAME;
1285 void fireburner_think()
1287 // for players, this is done in the regular loop
1288 if(wasfreed(self.owner))
1293 Fire_ApplyEffect(self.owner);
1294 if(!Fire_IsBurning(self.owner))
1296 self.owner.fire_burner = world;
1300 Fire_ApplyDamage(self.owner);
1301 self.nextthink = time;