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 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 string blood_message, victim_message;
346 if (!checkrules_firstblood)
348 checkrules_firstblood = TRUE;
349 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
350 // TODO: make these print a newline if they dont
351 Send_CSQC_Centerprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
352 Send_CSQC_Centerprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
355 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
356 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_TYPEFRAG, MSG_KILL);
357 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_TYPEFRAGGED, MSG_KILL);
359 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_FRAG, MSG_KILL);
360 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_FRAGGED, MSG_KILL);
363 attacker.taunt_soundtime = time + 1;
366 if (deathtype == DEATH_CUSTOM)
367 msg = strcat(deathmessage, " by ^1", msg);
368 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
370 msg = ftos(strstrofs(inflictor.message2, "#", 0));
372 Send_KillNotification(s, a, msg, deathtype, MSG_KILL);
374 if(g_ctf && targ.flagcarried)
376 UpdateFrags(attacker, ctf_score_value("score_kill"));
377 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
378 GiveFrags(attacker, targ, 0); // for logging
381 GiveFrags(attacker, targ, 1);
383 if (targ.killcount > 2) {
384 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
387 attacker.killcount = attacker.killcount + 1;
389 if (attacker.killcount > 2) {
390 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
393 LogDeath("frag", deathtype, attacker, targ);
395 if (attacker.killcount == 3)
397 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
398 AnnounceTo(attacker, "03kills");
400 else if (attacker.killcount == 5)
402 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
403 AnnounceTo(attacker, "05kills");
405 else if (attacker.killcount == 10)
407 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
408 AnnounceTo(attacker, "10kills");
410 else if (attacker.killcount == 15)
412 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
413 AnnounceTo(attacker, "15kills");
415 else if (attacker.killcount == 20)
417 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
418 AnnounceTo(attacker, "20kills");
420 else if (attacker.killcount == 25)
422 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
423 AnnounceTo(attacker, "25kills");
425 else if (attacker.killcount == 30)
427 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
428 AnnounceTo(attacker, "30kills");
434 Send_CSQC_Centerprint(targ, "", "", deathtype, MSG_KILL_ACTION);
435 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
436 msg = inflictor.message;
437 else if (deathtype == DEATH_CUSTOM)
440 GiveFrags(targ, targ, -1);
441 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
442 AnnounceTo(targ, "botlike");
444 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
446 if (targ.killcount > 2)
447 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
449 LogDeath("accident", deathtype, targ, targ);
452 targ.death_origin = targ.origin;
454 targ.killer_origin = attacker.origin;
456 // FIXME: this should go in PutClientInServer
462 // these are updated by each Damage call for use in button triggering and such
464 entity damage_inflictor;
465 entity damage_attacker;
468 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
473 entity attacker_save;
477 if (gameover || targ.killcount == -666)
480 local entity oldself;
484 damage_inflictor = inflictor;
485 damage_attacker = attacker;
486 attacker_save = attacker;
488 if(targ.classname == "player")
491 if(targ.hook.aiment == attacker)
492 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
494 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
495 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
497 if(targ.classname == "player")
498 if not(IsDifferentTeam(targ, attacker))
505 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
507 // These are ALWAYS lethal
508 // No damage modification here
509 // Instead, prepare the victim for his death...
511 targ.spawnshieldtime = 0;
512 targ.health = 0.9; // this is < 1
513 targ.flags -= targ.flags & FL_GODMODE;
516 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
522 if (targ.classname == "player")
523 if (attacker.classname == "player")
526 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
528 // nullify damage if teamplay is on
529 if(deathtype != DEATH_TELEFRAG)
530 if(attacker.classname == "player")
532 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
537 else if(attacker.team == targ.team)
541 else if(attacker != targ)
545 else if(teamplay == 4)
547 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
549 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
550 attacker.dmg_team = attacker.dmg_team + damage;
551 if(attacker.dmg_team > teamdamage0 && !g_ca)
552 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
553 mirrorforce = cvar("g_mirrordamage") * vlen(force);
556 if(cvar("g_friendlyfire") == 0)
562 damage = cvar("g_friendlyfire") * damage;
563 // mirrordamage will be used LATER
572 if(targ.classname == "player")
573 if(attacker.classname == "player")
576 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
577 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
580 if(targ.classname == "player")
583 if ((deathtype == DEATH_FALL) ||
584 (deathtype == DEATH_DROWN) ||
585 (deathtype == DEATH_SLIME) ||
586 (deathtype == DEATH_LAVA) ||
587 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
594 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
596 targ.armorvalue -= 1;
597 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
600 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
602 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
605 if (targ != attacker)
607 if ((targ.health >= 1) && (targ.classname == "player"))
608 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
618 if not(DEATH_ISSPECIAL(deathtype))
620 damage *= g_weapondamagefactor;
621 mirrordamage *= g_weapondamagefactor;
622 force = force * g_weaponforcefactor;
623 mirrorforce *= g_weaponforcefactor;
626 // apply strength multiplier
627 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
631 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
632 force = force * cvar("g_balance_powerup_strength_selfforce");
636 damage = damage * cvar("g_balance_powerup_strength_damage");
637 force = force * cvar("g_balance_powerup_strength_force");
641 // apply invincibility multiplier
642 if (targ.items & IT_INVINCIBLE && !g_minstagib)
643 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
645 if (targ == attacker)
647 if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))
650 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
653 // CTF: reduce damage/force
658 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
659 force = force * cvar("g_ctf_flagcarrier_selfforce");
664 // apply strength rune
665 if (attacker.runes & RUNE_STRENGTH)
667 if(attacker.runes & CURSE_WEAK) // have both curse & rune
669 damage = damage * cvar("g_balance_rune_strength_combo_damage");
670 force = force * cvar("g_balance_rune_strength_combo_force");
674 damage = damage * cvar("g_balance_rune_strength_damage");
675 force = force * cvar("g_balance_rune_strength_force");
678 else if (attacker.runes & CURSE_WEAK)
680 damage = damage * cvar("g_balance_curse_weak_damage");
681 force = force * cvar("g_balance_curse_weak_force");
684 // apply defense rune
685 if (targ.runes & RUNE_DEFENSE)
687 if (targ.runes & CURSE_VULNER) // have both curse & rune
688 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
690 damage = damage * cvar("g_balance_rune_defense_takedamage");
692 else if (targ.runes & CURSE_VULNER)
693 damage = damage * cvar("g_balance_curse_vulner_takedamage");
699 if(targ.takedamage == DAMAGE_AIM)
702 if(targ.classname == "player")
705 // find height of hit on player axis
706 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
707 vector headmins, headmaxs, org;
708 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
709 headmins = org + GetHeadshotMins(targ);
710 headmaxs = org + GetHeadshotMaxs(targ);
711 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
713 deathtype |= HITTYPE_HEADSHOT;
716 else if(targ.classname == "turret_head")
718 deathtype |= HITTYPE_HEADSHOT;
720 if(deathtype & HITTYPE_HEADSHOT)
721 damage *= 1 + damage_headshotbonus;
723 if(targ.classname == "player")
725 if(IsDifferentTeam(targ, attacker))
729 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))
732 attacker.typehitsound += 1;
734 attacker.hitsound += 1;
735 attacker.prevhitsound = time;
738 damage_goodhits += 1;
739 damage_gooddamage += damage;
741 if not(DEATH_ISSPECIAL(deathtype))
748 if(targ.items & IT_STRENGTH)
751 if(deathtype & HITTYPE_HEADSHOT)
758 if(deathtype != DEATH_FIRE)
759 attacker.typehitsound += 1;
761 if(time > attacker.teamkill_complain)
763 attacker.teamkill_complain = time + 5;
764 attacker.teamkill_soundtime = time + 0.4;
765 attacker.teamkill_soundsource = targ;
773 if (self.damageforcescale)
775 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
777 self.velocity = self.velocity + self.damageforcescale * force;
778 self.flags &~= FL_ONGROUND;
779 UpdateCSQCProjectile(self);
782 if (damage != 0 || (self.damageforcescale && vlen(force)))
783 if (self.event_damage)
784 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
787 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
789 // Savage: vampire mode
792 if (time >= self.spawnshieldtime)
794 attacker.health += damage;
798 if (attacker.runes & RUNE_VAMPIRE)
800 // apply vampire rune
801 if (attacker.runes & CURSE_EMPATHY) // have the curse too
803 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
804 attacker.health = bound(
805 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
806 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
807 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
811 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
812 attacker.health = bound(
813 attacker.health, // LA: was 3, but changed so that you can't lose health
814 // empathy won't let you gain health in the same way...
815 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
816 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
819 // apply empathy curse
820 else if (attacker.runes & CURSE_EMPATHY)
822 attacker.health = bound(
823 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
824 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
830 // apply mirror damage if any
831 if(mirrordamage > 0 || mirrorforce > 0)
833 attacker = attacker_save;
837 // just lose extra LIVES, don't kill the player for mirror damage
838 if(attacker.armorvalue > 0)
840 attacker.armorvalue = attacker.armorvalue - 1;
841 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
842 attacker.hitsound += 1;
846 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
847 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
851 vector NearestPointOnBox(entity box, vector org)
853 vector m1, m2, nearest;
855 m1 = box.mins + box.origin;
856 m2 = box.maxs + box.origin;
858 nearest_x = bound(m1_x, org_x, m2_x);
859 nearest_y = bound(m1_y, org_y, m2_y);
860 nearest_z = bound(m1_z, org_z, m2_z);
865 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
868 weaponid = DEATH_WEAPONOF(deathtype);
870 if not(inWarmupStage)
872 if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {
873 attacker.stats_hit[weaponid - 1] += damage;
874 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);
878 float RadiusDamage_running;
879 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
880 // Returns total damage applies to creatures
890 float total_damage_to_creatures;
895 float stat_damagedone;
896 float stat_maxdamage;
898 if(RadiusDamage_running)
901 print("RadiusDamage called recursively!\n");
902 print("Expect stuff to go HORRIBLY wrong.\n");
903 print("Causing a stack trace...\n");
904 save = cvar_string("prvm_backtraceforwarnings");
905 cvar_set("prvm_backtraceforwarnings", "1");
906 fclose(-1); // calls VM_Warning
907 cvar_set("prvm_backtraceforwarnings", save);
911 RadiusDamage_running = 1;
913 tfloordmg = cvar("g_throughfloor_damage");
914 tfloorforce = cvar("g_throughfloor_force");
916 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
917 total_damage_to_creatures = 0;
919 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
920 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
922 force = inflictor.velocity;
926 force = normalize(force);
927 if(forceintensity >= 0)
928 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
930 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
936 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
940 if (targ != inflictor)
941 if (ignore != targ) if(targ.takedamage)
943 // LordHavoc: measure distance to nearest point on target (not origin)
944 // (this guarentees 100% damage on a touch impact)
945 nearest = targ.WarpZone_findradius_nearest;
946 diff = targ.WarpZone_findradius_dist;
947 // round up a little on the damage to ensure full damage on impacts
948 // and turn the distance into a fraction of the radius
949 power = 1 - ((vlen (diff) - 2) / rad);
951 //bprint(ftos(power));
952 //if (targ == attacker)
953 // print(ftos(power), "\n");
958 finaldmg = coredamage * power + edgedamage * (1 - power);
965 local float hitratio;
967 local vector myblastorigin;
968 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
969 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
970 // if it's a player, use the view origin as reference
971 if (targ.classname == "player")
972 center = targ.origin + targ.view_ofs;
973 force = normalize(center - myblastorigin);
974 force = force * (finaldmg / coredamage) * forceintensity;
975 // test line of sight to multiple positions on box,
976 // and do damage if any of them hit
978 if (targ.classname == "player")
979 total = ceil(bound(1, finaldmg, 50));
981 total = ceil(bound(1, finaldmg/10, 5));
986 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
987 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
988 if (trace_fraction == 1 || trace_ent == targ)
992 hitloc = hitloc + nearest;
996 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
997 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
998 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1001 nearest = hitloc * (1 / max(1, hits));
1002 hitratio = (hits / total);
1003 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1004 finaldmg = finaldmg * a;
1005 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1007 //if (targ == attacker)
1009 // print("hits ", ftos(hits), " / ", ftos(total));
1010 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1011 // print(" (", ftos(a), ")\n");
1013 if(hits || tfloordmg || tfloorforce)
1017 total_damage_to_creatures += finaldmg;
1019 if(targ.flags & FL_CLIENT)
1020 if(targ.deadflag == DEAD_NO)
1021 if(targ != attacker)
1022 if(!teamplay || targ.team != attacker.team)
1024 stat_damagedone += finaldmg;
1025 stat_maxdamage += coredamage;
1029 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1030 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1032 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1040 RadiusDamage_running = 0;
1042 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1044 return total_damage_to_creatures;
1047 .float fire_damagepersec;
1048 .float fire_endtime;
1049 .float fire_deathtype;
1051 .float fire_hitsound;
1052 .entity fire_burner;
1054 void fireburner_think();
1056 float Fire_IsBurning(entity e)
1058 return (time < e.fire_endtime);
1061 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1064 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1066 if(e.classname == "player")
1075 // print("adding a fire burner to ", e.classname, "\n");
1076 e.fire_burner = spawn();
1077 e.fire_burner.classname = "fireburner";
1078 e.fire_burner.think = fireburner_think;
1079 e.fire_burner.nextthink = time;
1080 e.fire_burner.owner = e;
1086 if(Fire_IsBurning(e))
1088 mintime = e.fire_endtime - time;
1089 maxtime = max(mintime, t);
1091 mindps = e.fire_damagepersec;
1092 maxdps = max(mindps, dps);
1094 if(maxtime > mintime || maxdps > mindps)
1096 mindamage = mindps * mintime;
1097 maxdamage = mindamage + d;
1099 // interval [mintime, maxtime] * [mindps, maxdps]
1101 // [mindamage, maxdamage]
1104 if(maxdamage >= maxtime * maxdps)
1106 totaltime = maxtime;
1107 totaldamage = maxtime * maxdps;
1109 // this branch increases totaldamage if either t > mintime, or dps > mindps
1113 // maxdamage is inside the interval!
1114 // first, try to use mindps; only if this fails, increase dps as needed
1115 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1116 totaldamage = maxdamage;
1117 // can totaldamage / totaltime be >= maxdps?
1118 // max(mindps, maxdamage / maxtime) >= maxdps?
1119 // we know maxdamage < maxtime * maxdps
1122 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1125 // total conditions for increasing:
1126 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1128 // if maxtime = mintime, maxdps = mindps
1130 // maxdamage = mindamage + d
1131 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1132 // so the last condition is not needed
1134 e.fire_damagepersec = totaldamage / totaltime;
1135 e.fire_endtime = time + totaltime;
1136 if(totaldamage > 1.2 * mindamage)
1138 e.fire_deathtype = dt;
1139 if(e.fire_owner != o)
1142 e.fire_hitsound = FALSE;
1145 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1152 e.fire_damagepersec = dps;
1153 e.fire_endtime = time + t;
1154 e.fire_deathtype = dt;
1156 e.fire_hitsound = FALSE;
1161 void Fire_ApplyDamage(entity e)
1166 if not(Fire_IsBurning(e))
1172 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1175 // water and slime stop fire
1177 if(e.watertype != CONTENT_LAVA)
1180 t = min(frametime, e.fire_endtime - time);
1181 d = e.fire_damagepersec * t;
1183 hi = e.fire_owner.hitsound;
1184 ty = e.fire_owner.typehitsound;
1185 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1186 if(e.fire_hitsound && e.fire_owner)
1188 e.fire_owner.hitsound = hi;
1189 e.fire_owner.typehitsound = ty;
1191 e.fire_hitsound = TRUE;
1193 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1195 if not(IS_INDEPENDENT_PLAYER(e))
1196 FOR_EACH_PLAYER(other) if(e != other)
1198 if(other.classname == "player")
1199 if(other.deadflag == DEAD_NO)
1200 if not(IS_INDEPENDENT_PLAYER(other))
1201 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1203 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1204 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1205 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1210 void Fire_ApplyEffect(entity e)
1212 if(Fire_IsBurning(e))
1213 e.effects |= EF_FLAME;
1215 e.effects &~= EF_FLAME;
1218 void fireburner_think()
1220 // for players, this is done in the regular loop
1221 if(wasfreed(self.owner))
1226 Fire_ApplyEffect(self.owner);
1227 if(!Fire_IsBurning(self.owner))
1229 self.owner.fire_burner = world;
1233 Fire_ApplyDamage(self.owner);
1234 self.nextthink = time;