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.5 0 0' * PL_HEAD_x + '0 -0.5 0' * PL_HEAD_y + '0 0 1' * (targ.maxs_z - PL_HEAD_z);
93 vector GetHeadshotMaxs(entity targ)
95 return '0.5 0 0' * PL_HEAD_x + '0 0.5 0' * PL_HEAD_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 Send_KillNotification (string s1, string s2, string s3, float msg, float type)
250 WriteByte(MSG_ALL, SVC_TEMPENTITY);
251 WriteByte(MSG_ALL, TE_CSQC_NOTIFY);
252 WriteByte(MSG_ALL, CSQC_KILLNOTIFY);
253 WriteString(MSG_ALL, s1);
254 WriteString(MSG_ALL, s2);
255 WriteString(MSG_ALL, s3);
256 WriteShort(MSG_ALL, msg);
257 WriteByte(MSG_ALL, type);
260 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
261 void Send_CSQC_Centerprint(entity e, string s1, string s2, float msg, float type)
263 if (clienttype(e) == CLIENTTYPE_REAL)
266 WRITESPECTATABLE_MSG_ONE({
267 WriteByte(MSG_ONE, SVC_TEMPENTITY);
268 WriteByte(MSG_ONE, TE_CSQC_NOTIFY);
269 WriteByte(MSG_ONE, CSQC_CENTERPRINT);
270 WriteString(MSG_ONE, s1);
271 WriteString(MSG_ONE, s2);
272 WriteShort(MSG_ONE, msg);
273 WriteByte(MSG_ONE, type);
278 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
283 if (targ.classname == "player" || targ.classname == "corpse")
285 if (targ.classname == "corpse")
290 a = attacker.netname;
292 if (targ == attacker) // suicides
294 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
295 msg = ColoredTeamName(targ.team); // TODO: check if needed?
296 Send_CSQC_Centerprint(targ, msg, "", deathtype, MSG_SUICIDE);
298 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
300 LogDeath("suicide", deathtype, targ, targ);
301 GiveFrags(attacker, targ, -1);
304 if (targ.killcount > 2)
305 msg = ftos(targ.killcount);
306 if(teams_matter && deathtype == DEATH_MIRRORDAMAGE)
308 if(attacker.team == COLOR_TEAM1)
309 deathtype = KILL_TEAM_RED;
311 deathtype = KILL_TEAM_BLUE;
314 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
316 else if (attacker.classname == "player" || attacker.classname == "gib")
318 if(teams_matter && attacker.team == targ.team)
320 if(attacker.team == COLOR_TEAM1)
321 type = KILL_TEAM_RED;
323 type = KILL_TEAM_BLUE;
325 GiveFrags(attacker, targ, -1);
327 Send_CSQC_Centerprint(attacker, s, "", type, MSG_KILL);
329 if (targ.killcount > 2) {
330 msg = ftos(targ.killcount);
333 if (attacker.killcount > 2) {
334 msg = ftos(attacker.killcount);
335 type = KILL_TEAM_SPREE;
337 Send_KillNotification(a, s, msg, type, MSG_KILL);
339 attacker.killcount = 0;
341 LogDeath("tk", deathtype, attacker, targ);
345 if (!checkrules_firstblood)
347 checkrules_firstblood = TRUE;
348 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
349 // TODO: make these print a newline if they dont
350 Send_CSQC_Centerprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
351 Send_CSQC_Centerprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
354 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
355 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_TYPEFRAG, MSG_KILL);
356 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_TYPEFRAGGED, MSG_KILL);
358 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_FRAG, MSG_KILL);
359 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_FRAGGED, MSG_KILL);
362 attacker.taunt_soundtime = time + 1;
365 if (deathtype == DEATH_CUSTOM)
368 msg = inflictor.message2;
370 if(strstrofs(msg, "%", 0) < 0)
371 msg = strcat("%s ", msg, " by %s");
373 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
375 if(g_ctf && targ.flagcarried)
377 UpdateFrags(attacker, ctf_score_value("score_kill"));
378 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
379 GiveFrags(attacker, targ, 0); // for logging
382 GiveFrags(attacker, targ, 1);
384 if (targ.killcount > 2) {
385 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
388 attacker.killcount = attacker.killcount + 1;
390 if (attacker.killcount > 2) {
391 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
393 else if (attacker.killcount == 3)
395 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
396 AnnounceTo(attacker, "03kills");
398 else if (attacker.killcount == 5)
400 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
401 AnnounceTo(attacker, "05kills");
403 else if (attacker.killcount == 10)
405 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
406 AnnounceTo(attacker, "10kills");
408 else if (attacker.killcount == 15)
410 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
411 AnnounceTo(attacker, "15kills");
413 else if (attacker.killcount == 20)
415 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
416 AnnounceTo(attacker, "20kills");
418 else if (attacker.killcount == 25)
420 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
421 AnnounceTo(attacker, "25kills");
423 else if (attacker.killcount == 30)
425 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
426 AnnounceTo(attacker, "30kills");
428 LogDeath("frag", deathtype, attacker, targ);
433 Send_CSQC_Centerprint(targ, "", "", deathtype, MSG_KILL_ACTION);
434 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
435 msg = inflictor.message;
436 else if (deathtype == DEATH_CUSTOM)
438 if(strstrofs(msg, "%", 0) < 0)
439 msg = strcat("%s ", msg);
441 GiveFrags(targ, targ, -1);
442 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
443 AnnounceTo(targ, "botlike");
445 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
447 if (targ.killcount > 2)
448 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
450 LogDeath("accident", deathtype, targ, targ);
453 targ.death_origin = targ.origin;
455 targ.killer_origin = attacker.origin;
457 // FIXME: this should go in PutClientInServer
463 // these are updated by each Damage call for use in button triggering and such
465 entity damage_inflictor;
466 entity damage_attacker;
469 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
474 entity attacker_save;
478 if (gameover || targ.killcount == -666)
481 local entity oldself;
485 damage_inflictor = inflictor;
486 damage_attacker = attacker;
487 attacker_save = attacker;
489 if(targ.classname == "player")
492 if(targ.hook.aiment == attacker)
493 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
495 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
496 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
498 if(targ.classname == "player")
499 if not(IsDifferentTeam(targ, attacker))
506 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
508 // These are ALWAYS lethal
509 // No damage modification here
510 // Instead, prepare the victim for his death...
512 targ.spawnshieldtime = 0;
513 targ.health = 0.9; // this is < 1
514 targ.flags -= targ.flags & FL_GODMODE;
517 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
523 if (targ.classname == "player")
524 if (attacker.classname == "player")
527 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
531 if(targ.freezetag_frozen == 1)
534 force = force * cvar("g_freezetag_frozen_force");
538 // nullify damage if teamplay is on
539 if(deathtype != DEATH_TELEFRAG)
540 if(attacker.classname == "player")
542 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
547 else if(attacker.team == targ.team)
551 else if(attacker != targ)
555 else if(teamplay == 4)
557 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
559 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
560 attacker.dmg_team = attacker.dmg_team + damage;
561 if(attacker.dmg_team > teamdamage0 && !g_ca)
562 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
563 mirrorforce = cvar("g_mirrordamage") * vlen(force);
566 if(cvar("g_friendlyfire") == 0)
572 damage = cvar("g_friendlyfire") * damage;
573 // mirrordamage will be used LATER
582 if(targ.classname == "player")
583 if(attacker.classname == "player")
586 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
587 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
590 if(targ.classname == "player")
593 if ((deathtype == DEATH_FALL) ||
594 (deathtype == DEATH_DROWN) ||
595 (deathtype == DEATH_SLIME) ||
596 (deathtype == DEATH_LAVA) ||
597 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
604 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
606 targ.armorvalue -= 1;
607 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
610 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
612 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
615 if (targ != attacker)
617 if ((targ.health >= 1) && (targ.classname == "player"))
618 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
628 if not(DEATH_ISSPECIAL(deathtype))
630 damage *= g_weapondamagefactor;
631 mirrordamage *= g_weapondamagefactor;
632 force = force * g_weaponforcefactor;
633 mirrorforce *= g_weaponforcefactor;
636 // apply strength multiplier
637 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
641 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
642 force = force * cvar("g_balance_powerup_strength_selfforce");
646 damage = damage * cvar("g_balance_powerup_strength_damage");
647 force = force * cvar("g_balance_powerup_strength_force");
651 // apply invincibility multiplier
652 if (targ.items & IT_INVINCIBLE && !g_minstagib)
653 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
655 if (targ == attacker)
657 if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))
660 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
663 // CTF: reduce damage/force
668 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
669 force = force * cvar("g_ctf_flagcarrier_selfforce");
674 // apply strength rune
675 if (attacker.runes & RUNE_STRENGTH)
677 if(attacker.runes & CURSE_WEAK) // have both curse & rune
679 damage = damage * cvar("g_balance_rune_strength_combo_damage");
680 force = force * cvar("g_balance_rune_strength_combo_force");
684 damage = damage * cvar("g_balance_rune_strength_damage");
685 force = force * cvar("g_balance_rune_strength_force");
688 else if (attacker.runes & CURSE_WEAK)
690 damage = damage * cvar("g_balance_curse_weak_damage");
691 force = force * cvar("g_balance_curse_weak_force");
694 // apply defense rune
695 if (targ.runes & RUNE_DEFENSE)
697 if (targ.runes & CURSE_VULNER) // have both curse & rune
698 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
700 damage = damage * cvar("g_balance_rune_defense_takedamage");
702 else if (targ.runes & CURSE_VULNER)
703 damage = damage * cvar("g_balance_curse_vulner_takedamage");
709 if(targ.takedamage == DAMAGE_AIM)
712 if(targ.classname == "player")
715 // find height of hit on player axis
716 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
717 vector headmins, headmaxs, org;
718 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
719 headmins = org + GetHeadshotMins(targ);
720 headmaxs = org + GetHeadshotMaxs(targ);
721 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
723 deathtype |= HITTYPE_HEADSHOT;
726 else if(targ.classname == "turret_head")
728 deathtype |= HITTYPE_HEADSHOT;
730 if(deathtype & HITTYPE_HEADSHOT)
731 damage *= 1 + damage_headshotbonus;
733 if(targ.classname == "player")
735 if(IsDifferentTeam(targ, attacker))
739 if(attacker.weapon != WEP_ELECTRO && attacker.weapon != WEP_LASER || ((attacker.weapon == WEP_ELECTRO && cvar("g_balance_electro_lightning") || attacker.weapon == WEP_LASER) && attacker.prevhitsound + cvar("sv_hitsound_antispam_time") < time))
742 attacker.typehitsound += 1;
744 attacker.hitsound += 1;
745 attacker.prevhitsound = time;
748 damage_goodhits += 1;
749 damage_gooddamage += damage;
751 if not(DEATH_ISSPECIAL(deathtype))
758 if(targ.items & IT_STRENGTH)
761 if(deathtype & HITTYPE_HEADSHOT)
765 PlayerScore_Add(attacker, SP_SCORE, damage * cvar("g_ca_damage2score_multiplier"));
770 if(deathtype != DEATH_FIRE)
771 attacker.typehitsound += 1;
773 if(time > attacker.teamkill_complain)
775 attacker.teamkill_complain = time + 5;
776 attacker.teamkill_soundtime = time + 0.4;
777 attacker.teamkill_soundsource = targ;
785 if (self.damageforcescale)
787 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
789 self.velocity = self.velocity + self.damageforcescale * force;
790 self.flags &~= FL_ONGROUND;
791 UpdateCSQCProjectile(self);
794 if (damage != 0 || (self.damageforcescale && vlen(force)))
795 if (self.event_damage)
796 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
799 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
803 if (attacker.runes & RUNE_VAMPIRE)
805 // apply vampire rune
806 if (attacker.runes & CURSE_EMPATHY) // have the curse too
808 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
809 attacker.health = bound(
810 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
811 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
812 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
816 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
817 attacker.health = bound(
818 attacker.health, // LA: was 3, but changed so that you can't lose health
819 // empathy won't let you gain health in the same way...
820 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
821 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
824 // apply empathy curse
825 else if (attacker.runes & CURSE_EMPATHY)
827 attacker.health = bound(
828 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
829 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
835 // apply mirror damage if any
836 if(mirrordamage > 0 || mirrorforce > 0)
838 attacker = attacker_save;
842 // just lose extra LIVES, don't kill the player for mirror damage
843 if(attacker.armorvalue > 0)
845 attacker.armorvalue = attacker.armorvalue - 1;
846 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
847 attacker.hitsound += 1;
851 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
852 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
856 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
859 weaponid = DEATH_WEAPONOF(deathtype);
861 if not(inWarmupStage)
863 if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {
864 attacker.stats_hit[weaponid - 1] += damage;
865 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);
869 float RadiusDamage_running;
870 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
871 // Returns total damage applies to creatures
881 float total_damage_to_creatures;
886 float stat_damagedone;
887 float stat_maxdamage;
889 if(RadiusDamage_running)
892 print("RadiusDamage called recursively!\n");
893 print("Expect stuff to go HORRIBLY wrong.\n");
894 print("Causing a stack trace...\n");
895 save = cvar_string("prvm_backtraceforwarnings");
896 cvar_set("prvm_backtraceforwarnings", "1");
897 fclose(-1); // calls VM_Warning
898 cvar_set("prvm_backtraceforwarnings", save);
902 RadiusDamage_running = 1;
904 tfloordmg = cvar("g_throughfloor_damage");
905 tfloorforce = cvar("g_throughfloor_force");
907 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
908 total_damage_to_creatures = 0;
910 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
911 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
913 force = inflictor.velocity;
917 force = normalize(force);
918 if(forceintensity >= 0)
919 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
921 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
927 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
931 if (targ != inflictor)
932 if (ignore != targ) if(targ.takedamage)
934 // LordHavoc: measure distance to nearest point on target (not origin)
935 // (this guarentees 100% damage on a touch impact)
936 nearest = targ.WarpZone_findradius_nearest;
937 diff = targ.WarpZone_findradius_dist;
938 // round up a little on the damage to ensure full damage on impacts
939 // and turn the distance into a fraction of the radius
940 power = 1 - ((vlen (diff) - 2) / rad);
942 //bprint(ftos(power));
943 //if (targ == attacker)
944 // print(ftos(power), "\n");
949 finaldmg = coredamage * power + edgedamage * (1 - power);
956 local float hitratio;
958 local vector myblastorigin;
959 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
960 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
961 // if it's a player, use the view origin as reference
962 if (targ.classname == "player")
963 center = targ.origin + targ.view_ofs;
964 force = normalize(center - myblastorigin);
965 force = force * (finaldmg / coredamage) * forceintensity;
966 // test line of sight to multiple positions on box,
967 // and do damage if any of them hit
969 if (targ.classname == "player")
970 total = ceil(bound(1, finaldmg, 50));
972 total = ceil(bound(1, finaldmg/10, 5));
977 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
978 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
979 if (trace_fraction == 1 || trace_ent == targ)
983 hitloc = hitloc + nearest;
987 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
988 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
989 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
992 nearest = hitloc * (1 / max(1, hits));
993 hitratio = (hits / total);
994 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
995 finaldmg = finaldmg * a;
996 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
999 // laser force adjustments :P
1000 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1005 float force_velocitybiasramp;
1006 float force_velocitybias;
1008 force_velocitybiasramp = cvar("sv_maxspeed");
1009 if(deathtype & HITTYPE_SECONDARY)
1011 force_zscale = cvar("g_balance_laser_secondary_force_zscale");
1012 force_velocitybias = cvar("g_balance_laser_secondary_force_velocitybias");
1016 force_zscale = cvar("g_balance_laser_primary_force_zscale");
1017 force_velocitybias = cvar("g_balance_laser_primary_force_velocitybias");
1020 vel = targ.velocity;
1022 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1026 normalize(normalize(force) + vel);
1028 force_z *= force_zscale;
1031 //if (targ == attacker)
1033 // print("hits ", ftos(hits), " / ", ftos(total));
1034 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1035 // print(" (", ftos(a), ")\n");
1037 if(hits || tfloordmg || tfloorforce)
1041 total_damage_to_creatures += finaldmg;
1043 if(targ.flags & FL_CLIENT)
1044 if(targ.deadflag == DEAD_NO)
1045 if(targ != attacker)
1046 if(!teamplay || targ.team != attacker.team)
1048 stat_damagedone += finaldmg;
1049 stat_maxdamage += coredamage;
1053 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1054 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1056 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1064 RadiusDamage_running = 0;
1066 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1068 return total_damage_to_creatures;
1071 .float fire_damagepersec;
1072 .float fire_endtime;
1073 .float fire_deathtype;
1075 .float fire_hitsound;
1076 .entity fire_burner;
1078 void fireburner_think();
1080 float Fire_IsBurning(entity e)
1082 return (time < e.fire_endtime);
1085 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1088 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1090 if(e.classname == "player")
1099 // print("adding a fire burner to ", e.classname, "\n");
1100 e.fire_burner = spawn();
1101 e.fire_burner.classname = "fireburner";
1102 e.fire_burner.think = fireburner_think;
1103 e.fire_burner.nextthink = time;
1104 e.fire_burner.owner = e;
1110 if(Fire_IsBurning(e))
1112 mintime = e.fire_endtime - time;
1113 maxtime = max(mintime, t);
1115 mindps = e.fire_damagepersec;
1116 maxdps = max(mindps, dps);
1118 if(maxtime > mintime || maxdps > mindps)
1120 mindamage = mindps * mintime;
1121 maxdamage = mindamage + d;
1123 // interval [mintime, maxtime] * [mindps, maxdps]
1125 // [mindamage, maxdamage]
1128 if(maxdamage >= maxtime * maxdps)
1130 totaltime = maxtime;
1131 totaldamage = maxtime * maxdps;
1133 // this branch increases totaldamage if either t > mintime, or dps > mindps
1137 // maxdamage is inside the interval!
1138 // first, try to use mindps; only if this fails, increase dps as needed
1139 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1140 totaldamage = maxdamage;
1141 // can totaldamage / totaltime be >= maxdps?
1142 // max(mindps, maxdamage / maxtime) >= maxdps?
1143 // we know maxdamage < maxtime * maxdps
1146 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1149 // total conditions for increasing:
1150 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1152 // if maxtime = mintime, maxdps = mindps
1154 // maxdamage = mindamage + d
1155 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1156 // so the last condition is not needed
1158 e.fire_damagepersec = totaldamage / totaltime;
1159 e.fire_endtime = time + totaltime;
1160 if(totaldamage > 1.2 * mindamage)
1162 e.fire_deathtype = dt;
1163 if(e.fire_owner != o)
1166 e.fire_hitsound = FALSE;
1169 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1176 e.fire_damagepersec = dps;
1177 e.fire_endtime = time + t;
1178 e.fire_deathtype = dt;
1180 e.fire_hitsound = FALSE;
1185 void Fire_ApplyDamage(entity e)
1190 if not(Fire_IsBurning(e))
1193 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1194 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1197 // water and slime stop fire
1199 if(e.watertype != CONTENT_LAVA)
1202 t = min(frametime, e.fire_endtime - time);
1203 d = e.fire_damagepersec * t;
1205 hi = e.fire_owner.hitsound;
1206 ty = e.fire_owner.typehitsound;
1207 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1208 if(e.fire_hitsound && e.fire_owner)
1210 e.fire_owner.hitsound = hi;
1211 e.fire_owner.typehitsound = ty;
1213 e.fire_hitsound = TRUE;
1215 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1217 if not(IS_INDEPENDENT_PLAYER(e))
1218 FOR_EACH_PLAYER(other) if(e != other)
1220 if(other.classname == "player")
1221 if(other.deadflag == DEAD_NO)
1222 if not(IS_INDEPENDENT_PLAYER(other))
1223 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1225 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1226 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1227 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1232 void Fire_ApplyEffect(entity e)
1234 if(Fire_IsBurning(e))
1235 e.effects |= EF_FLAME;
1237 e.effects &~= EF_FLAME;
1240 void fireburner_think()
1242 // for players, this is done in the regular loop
1243 if(wasfreed(self.owner))
1248 Fire_ApplyEffect(self.owner);
1249 if(!Fire_IsBurning(self.owner))
1251 self.owner.fire_burner = world;
1255 Fire_ApplyDamage(self.owner);
1256 self.nextthink = time;