6 #include "../warpzonelib/common.qh"
7 #include "../common/constants.qh"
8 #include "../common/teams.qh"
9 #include "../common/util.qh"
10 #include "../common/weapons/weapons.qh"
11 #include "weapons/accuracy.qh"
12 #include "weapons/csqcprojectile.qh"
13 #include "weapons/selection.qh"
15 #include "autocvars.qh"
16 #include "constants.qh"
18 #include "../common/notifications.qh"
19 #include "../common/deathtypes.qh"
20 #include "mutators/mutators_include.qh"
21 #include "../common/turrets/turrets.qh"
22 #include "../common/turrets/sv_turrets.qh"
23 #include "vehicles/vehicles_def.qh"
24 #include "../csqcmodellib/sv_model.qh"
25 #include "../common/playerstats.qh"
28 #include "spawnpoints.qh"
31 float Damage_DamageInfo_SendEntity(entity to, float sf)
33 WriteByte(MSG_ENTITY, ENT_CLIENT_DAMAGEINFO);
34 WriteShort(MSG_ENTITY, self.projectiledeathtype);
35 WriteCoord(MSG_ENTITY, floor(self.origin.x));
36 WriteCoord(MSG_ENTITY, floor(self.origin.y));
37 WriteCoord(MSG_ENTITY, floor(self.origin.z));
38 WriteByte(MSG_ENTITY, bound(1, self.dmg, 255));
39 WriteByte(MSG_ENTITY, bound(0, self.dmg_radius, 255));
40 WriteByte(MSG_ENTITY, bound(1, self.dmg_edge, 255));
41 WriteShort(MSG_ENTITY, self.oldorigin.x);
42 WriteByte(MSG_ENTITY, self.species);
46 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, float bloodtype, entity dmgowner)
48 // TODO maybe call this from non-edgedamage too?
49 // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
53 if(!sound_allowed(MSG_BROADCAST, dmgowner))
58 e.projectiledeathtype = deathtype;
60 e.dmg_edge = edgedamage;
62 e.dmg_force = vlen(force);
64 e.oldorigin_x = compressShortVector(e.velocity);
65 e.species = bloodtype;
67 Net_LinkEntity(e, false, 0.2, Damage_DamageInfo_SendEntity);
70 float IsFlying(entity a)
72 if(a.flags & FL_ONGROUND)
74 if(a.waterlevel >= WATERLEVEL_SWIMMING)
76 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
77 if(trace_fraction < 1)
82 void UpdateFrags(entity player, float f)
84 PlayerTeamScore_AddScore(player, f);
87 void GiveFrags (entity attacker, entity targ, float f, float deathtype)
89 // TODO route through PlayerScores instead
97 PlayerScore_Add(attacker, SP_SUICIDES, 1);
102 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
108 PlayerScore_Add(attacker, SP_KILLS, 1);
110 PS_GR_P_ADDVAL(attacker, sprintf("kills-%d", targ.playerid), 1);
113 PlayerScore_Add(targ, SP_DEATHS, 1);
115 if(targ != attacker) // not for suicides
116 if(g_weaponarena_random)
118 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
120 culprit = DEATH_WEAPONOF(deathtype);
122 culprit = attacker.weapon;
123 else if(!(attacker.weapons & WepSet_FromWeapon(culprit)))
124 culprit = attacker.weapon;
126 if(g_weaponarena_random_with_blaster && culprit == WEP_BLASTER) // WEAPONTODO: Shouldn't this be in a mutator?
132 if(!GiveFrags_randomweapons)
134 GiveFrags_randomweapons = spawn();
135 GiveFrags_randomweapons.classname = "GiveFrags_randomweapons";
139 GiveFrags_randomweapons.weapons = WARMUP_START_WEAPONS;
141 GiveFrags_randomweapons.weapons = start_weapons;
143 // all others (including the culprit): remove
144 GiveFrags_randomweapons.weapons &= ~attacker.weapons;
145 GiveFrags_randomweapons.weapons &= ~WepSet_FromWeapon(culprit);
147 // among the remaining ones, choose one by random
148 W_RandomWeapons(GiveFrags_randomweapons, 1);
150 if(GiveFrags_randomweapons.weapons)
152 attacker.weapons |= GiveFrags_randomweapons.weapons;
153 attacker.weapons &= ~WepSet_FromWeapon(culprit);
157 // after a frag, choose another random weapon set
158 if (!(attacker.weapons & WepSet_FromWeapon(attacker.weapon)))
159 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
162 // FIXME fix the mess this is (we have REAL points now!)
166 frag_attacker = attacker;
169 if(MUTATOR_CALLHOOK(GiveFragsForKill))
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)
207 void LogDeath(string mode, float deathtype, entity killer, entity killed)
210 if(!autocvar_sv_eventlog)
212 s = strcat(":kill:", mode);
213 s = strcat(s, ":", ftos(killer.playerid));
214 s = strcat(s, ":", ftos(killed.playerid));
215 s = strcat(s, ":type=", Deathtype_Name(deathtype));
216 s = strcat(s, ":items=");
217 s = AppendItemcodes(s, killer);
220 s = strcat(s, ":victimitems=");
221 s = AppendItemcodes(s, killed);
226 void Obituary_SpecialDeath(
230 string s1, string s2, string s3,
231 float f1, float f2, float f3)
233 if(DEATH_ISSPECIAL(deathtype))
235 entity deathent = deathtypes[(deathtype - DT_FIRST)];
236 if (!deathent) { backtrace("Obituary_SpecialDeath: Could not find deathtype entity!\n"); return; }
240 if(deathent.death_msgmurder)
242 Send_Notification_WOCOVA(
246 deathent.death_msgmurder.nent_id,
250 Send_Notification_WOCOVA(
254 deathent.death_msgmurder.nent_msginfo.nent_id,
262 if(deathent.death_msgself)
264 Send_Notification_WOCOVA(
268 deathent.death_msgself.nent_id,
272 Send_Notification_WOCOVA(
276 deathent.death_msgself.nent_msginfo.nent_id,
283 else { backtrace("Obituary_SpecialDeath called without a special deathtype?\n"); return; }
286 float Obituary_WeaponDeath(
290 string s1, string s2, string s3,
293 float death_weapon = DEATH_WEAPONOF(deathtype);
296 w_deathtype = deathtype;
297 float death_message = WEP_ACTION(death_weapon, ((murder) ? WR_KILLMESSAGE : WR_SUICIDEMESSAGE));
302 Send_Notification_WOCOVA(
310 Send_Notification_WOCOVA(
314 msg_multi_notifs[death_message - 1].nent_msginfo.nent_id,
322 "Obituary_WeaponDeath(): ^1Deathtype ^7(%d)^1 has no notification for weapon %d!\n",
333 void Obituary(entity attacker, entity inflictor, entity targ, float deathtype)
336 if (!IS_PLAYER(targ)) { backtrace("Obituary called on non-player?!\n"); return; }
339 float notif_firstblood = false;
340 float kill_count_to_attacker, kill_count_to_target;
342 // Set final information for the death
343 targ.death_origin = targ.origin;
344 if(targ != attacker) { targ.killer_origin = attacker.origin; }
345 string deathlocation = (autocvar_notification_server_allows_location ? NearestLocation(targ.death_origin) : "");
347 #ifdef NOTIFICATIONS_DEBUG
350 "Obituary(%s, %s, %s, %s = %d);\n",
354 Deathtype_Name(deathtype),
365 if(DEATH_ISSPECIAL(deathtype))
367 if(deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
369 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.team, 0, 0);
375 case DEATH_MIRRORDAMAGE:
377 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
383 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
389 else if (!Obituary_WeaponDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0))
391 backtrace("SUICIDE: what the hell happened here?\n");
394 LogDeath("suicide", deathtype, targ, targ);
395 GiveFrags(attacker, targ, -1, deathtype);
401 else if(IS_PLAYER(attacker))
403 if(SAME_TEAM(attacker, targ))
405 LogDeath("tk", deathtype, attacker, targ);
406 GiveFrags(attacker, targ, -1, deathtype);
408 attacker.killcount = 0;
410 Send_Notification(NOTIF_ONE, attacker, MSG_CENTER, CENTER_DEATH_TEAMKILL_FRAG, targ.netname);
411 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_DEATH_TEAMKILL_FRAGGED, attacker.netname);
412 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(targ.team, INFO_DEATH_TEAMKILL_), targ.netname, attacker.netname, deathlocation, targ.killcount);
414 // In this case, the death message will ALWAYS be "foo was betrayed by bar"
415 // No need for specific death/weapon messages...
419 LogDeath("frag", deathtype, attacker, targ);
420 GiveFrags(attacker, targ, 1, deathtype);
422 attacker.taunt_soundtime = time + 1;
423 attacker.killcount = attacker.killcount + 1;
425 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
428 Send_Notification(NOTIF_ONE, attacker, MSG_ANNCE, ANNCE_KILLSTREAK_##countb); \
429 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_##counta, 1); \
432 switch(attacker.killcount)
439 if(!checkrules_firstblood)
441 checkrules_firstblood = true;
442 notif_firstblood = true; // modify the current messages so that they too show firstblood information
443 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
444 PS_GR_P_ADDVAL(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
446 // tell spree_inf and spree_cen that this is a first-blood and first-victim event
447 kill_count_to_attacker = -1;
448 kill_count_to_target = -2;
452 kill_count_to_attacker = attacker.killcount;
453 kill_count_to_target = 0;
464 kill_count_to_attacker,
465 (IS_BOT_CLIENT(targ) ? NO_MSG : targ.ping)
473 kill_count_to_target,
476 (IS_BOT_CLIENT(attacker) ? NO_MSG : attacker.ping)
487 kill_count_to_attacker,
488 (IS_BOT_CLIENT(targ) ? NO_MSG : targ.ping)
496 kill_count_to_target,
499 (IS_BOT_CLIENT(attacker) ? NO_MSG : attacker.ping)
503 if (!Obituary_WeaponDeath(targ, true, deathtype, targ.netname, attacker.netname, deathlocation, targ.killcount, kill_count_to_attacker))
504 Obituary_SpecialDeath(targ, true, deathtype, targ.netname, attacker.netname, deathlocation, targ.killcount, kill_count_to_attacker, 0);
515 // For now, we're just forcing HURTTRIGGER to behave as "DEATH_VOID" and giving it no special options...
516 // Later on you will only be able to make custom messages using DEATH_CUSTOM,
517 // and there will be a REAL DEATH_VOID implementation which mappers will use.
518 /*case DEATH_HURTTRIGGER:
521 s2 = inflictor.message;
522 if(strstrofs(s2, "%", 0) < 0) { s2 = strcat("%s ", s2); }
528 Obituary_SpecialDeath(targ, false, deathtype,
530 ((strstrofs(deathmessage, "%", 0) < 0) ? strcat("%s ", deathmessage) : deathmessage),
540 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
545 LogDeath("accident", deathtype, targ, targ);
546 GiveFrags(targ, targ, -1, deathtype);
548 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5)
550 Send_Notification(NOTIF_ONE, targ, MSG_ANNCE, ANNCE_ACHIEVEMENT_BOTLIKE);
551 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
555 // reset target kill count
556 if(targ.killcount) { targ.killcount = 0; }
561 if(!self.owner.frozen || self.owner.iceblock != self)
566 setorigin(self, self.owner.origin - '0 0 16');
567 self.nextthink = time;
570 void Freeze (entity targ, float freeze_time, float frozen_type, float show_waypoint)
572 if(!IS_PLAYER(targ) && !(targ.flags & FL_MONSTER)) // only specified entities can be freezed
578 float targ_maxhealth = ((targ.flags & FL_MONSTER) ? targ.max_health : start_health);
580 targ.frozen = frozen_type;
581 targ.revive_progress = ((frozen_type == 3) ? 1 : 0);
582 targ.health = ((frozen_type == 3) ? targ_maxhealth : 1);
583 targ.revive_speed = freeze_time;
588 ice.classname = "ice";
589 ice.scale = targ.scale;
590 ice.think = Ice_Think;
591 ice.nextthink = time;
592 ice.frame = floor(random() * 21); // ice model has 20 different looking frames
593 setmodel(ice, "models/ice/ice.md3");
595 ice.colormod = Team_ColorRGB(targ.team);
596 ice.glowmod = ice.colormod;
598 targ.revival_time = 0;
606 RemoveGrapplingHook(targ);
608 FOR_EACH_PLAYER(head)
609 if(head.hook.aiment == targ)
610 RemoveGrapplingHook(head);
614 WaypointSprite_Spawn("frozen", 0, 0, targ, '0 0 64', world, targ.team, targ, waypointsprite_attached, true, RADARICON_WAYPOINT, '0.25 0.90 1');
617 void Unfreeze (entity targ)
619 if(targ.frozen && targ.frozen != 3) // only reset health if target was frozen
620 targ.health = ((IS_PLAYER(targ)) ? start_health : targ.max_health);
624 targ.revive_progress = 0;
625 targ.revival_time = time;
627 WaypointSprite_Kill(targ.waypointsprite_attached);
629 FOR_EACH_PLAYER(head)
630 if(head.hook.aiment == targ)
631 RemoveGrapplingHook(head);
633 // remove the ice block
635 remove(targ.iceblock);
636 targ.iceblock = world;
639 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
643 float complainteamdamage = 0;
644 entity attacker_save;
648 if (gameover || targ.killcount == -666)
655 damage_inflictor = inflictor;
656 damage_attacker = attacker;
657 attacker_save = attacker;
662 if(targ.hook.aiment == attacker)
663 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
665 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
666 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
669 if(SAME_TEAM(targ, attacker))
676 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
678 // exit the vehicle before killing (fixes a crash)
679 if(IS_PLAYER(targ) && targ.vehicle)
680 vehicles_exit(VHEF_RELESE);
682 // These are ALWAYS lethal
683 // No damage modification here
684 // Instead, prepare the victim for his death...
686 targ.spawnshieldtime = 0;
687 targ.health = 0.9; // this is < 1
688 targ.flags -= targ.flags & FL_GODMODE;
691 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
697 // nullify damage if teamplay is on
698 if(deathtype != DEATH_TELEFRAG)
699 if(IS_PLAYER(attacker))
701 if(IS_PLAYER(targ) && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
706 else if(SAME_TEAM(attacker, targ))
708 if(autocvar_teamplay_mode == 1)
710 else if(attacker != targ)
712 if(autocvar_teamplay_mode == 3)
714 else if(autocvar_teamplay_mode == 4)
716 if(IS_PLAYER(targ) && targ.deadflag == DEAD_NO)
718 attacker.dmg_team = attacker.dmg_team + damage;
719 complainteamdamage = attacker.dmg_team - autocvar_g_teamdamage_threshold;
720 if(complainteamdamage > 0)
721 mirrordamage = autocvar_g_mirrordamage * complainteamdamage;
722 mirrorforce = autocvar_g_mirrordamage * vlen(force);
723 damage = autocvar_g_friendlyfire * damage;
724 // mirrordamage will be used LATER
726 if(autocvar_g_mirrordamage_virtual)
728 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, mirrordamage);
729 attacker.dmg_take += v.x;
730 attacker.dmg_save += v.y;
731 attacker.dmg_inflictor = inflictor;
736 if(autocvar_g_friendlyfire_virtual)
738 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
739 targ.dmg_take += v.x;
740 targ.dmg_save += v.y;
741 targ.dmg_inflictor = inflictor;
743 if(!autocvar_g_friendlyfire_virtual_force)
754 if (!DEATH_ISSPECIAL(deathtype))
756 damage *= g_weapondamagefactor;
757 mirrordamage *= g_weapondamagefactor;
758 complainteamdamage *= g_weapondamagefactor;
759 force = force * g_weaponforcefactor;
760 mirrorforce *= g_weaponforcefactor;
763 // should this be changed at all? If so, in what way?
764 frag_attacker = attacker;
766 frag_damage = damage;
768 frag_deathtype = deathtype;
769 frag_mirrordamage = mirrordamage;
770 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
771 damage = frag_damage;
772 mirrordamage = frag_mirrordamage;
776 if(deathtype != DEATH_HURTTRIGGER && deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_AUTOTEAMCHANGE)
778 if(autocvar_g_freezetag_revive_falldamage > 0)
779 if(deathtype == DEATH_FALL)
780 if(damage >= autocvar_g_freezetag_revive_falldamage)
783 targ.health = autocvar_g_freezetag_revive_falldamage_health;
784 pointparticles(particleeffectnum("iceorglass"), targ.origin, '0 0 0', 3);
785 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_FALL, targ.netname);
786 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
790 force *= autocvar_g_freezetag_frozen_force;
793 if(targ.frozen && deathtype == DEATH_HURTTRIGGER && !autocvar_g_freezetag_frozen_damage_trigger)
795 pointparticles(particleeffectnum("teleport"), targ.origin, '0 0 0', 1);
797 entity oldself = self;
799 entity spot = SelectSpawnPoint (false);
804 self.deadflag = DEAD_NO;
806 self.angles = spot.angles;
809 self.effects |= EF_TELEPORT_BIT;
811 self.angles_z = 0; // never spawn tilted even if the spot says to
812 self.fixangle = true; // turn this way immediately
813 self.velocity = '0 0 0';
814 self.avelocity = '0 0 0';
815 self.punchangle = '0 0 0';
816 self.punchvector = '0 0 0';
817 self.oldvelocity = self.velocity;
819 self.spawnorigin = spot.origin;
820 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins.z - 24));
821 // don't reset back to last position, even if new position is stuck in solid
822 self.oldorigin = self.origin;
823 self.prevorigin = self.origin;
825 pointparticles(particleeffectnum("teleport"), self.origin, '0 0 0', 1);
833 // apply strength multiplier
834 if (attacker.items & IT_STRENGTH)
838 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
839 force = force * autocvar_g_balance_powerup_strength_selfforce;
843 damage = damage * autocvar_g_balance_powerup_strength_damage;
844 force = force * autocvar_g_balance_powerup_strength_force;
848 // apply invincibility multiplier
849 if (targ.items & IT_INVINCIBLE)
850 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
853 if (targ == attacker)
854 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
859 if(deathtype != DEATH_BUFF_VENGEANCE)
860 if(targ.takedamage == DAMAGE_AIM)
864 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
869 if(IS_PLAYER(victim) || ((victim.turret_flags & TUR_FLAG_ISTURRET) && victim.active == ACTIVE_ACTIVE) || (victim.flags & FL_MONSTER))
871 if(DIFF_TEAM(victim, attacker) && !victim.frozen)
875 if(deathtype != DEATH_FIRE)
877 if(victim.BUTTON_CHAT)
878 attacker.typehitsound += 1;
880 attacker.damage_dealt += damage;
883 damage_goodhits += 1;
884 damage_gooddamage += damage;
886 if (!DEATH_ISSPECIAL(deathtype))
888 if(IS_PLAYER(targ)) // don't do this for vehicles
896 if(deathtype != DEATH_FIRE)
898 attacker.typehitsound += 1;
900 if(complainteamdamage > 0)
901 if(time > attacker.teamkill_complain)
903 attacker.teamkill_complain = time + 5;
904 attacker.teamkill_soundtime = time + 0.4;
905 attacker.teamkill_soundsource = targ;
913 if (self.damageforcescale)
915 if (!IS_PLAYER(self) || time >= self.spawnshieldtime || self == attacker)
917 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
918 if(self.movetype == MOVETYPE_PHYSICS)
922 farcent.classname = "farce";
923 farcent.enemy = self;
924 farcent.movedir = farce * 10;
926 farcent.movedir = farcent.movedir * self.mass;
927 farcent.origin = hitloc;
928 farcent.forcetype = FORCETYPE_FORCEATPOS;
929 farcent.nextthink = time + 0.1;
930 farcent.think = SUB_Remove;
933 self.velocity = self.velocity + farce;
934 self.flags &= ~FL_ONGROUND;
935 UpdateCSQCProjectile(self);
938 if (damage != 0 || (self.damageforcescale && vlen(force)))
939 if (self.event_damage)
940 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
943 // apply mirror damage if any
944 if(mirrordamage > 0 || mirrorforce > 0)
946 attacker = attacker_save;
948 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
949 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
953 float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector inflictorvelocity, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float inflictorselfdamage, float forceintensity, float deathtype, entity directhitentity)
954 // Returns total damage applies to creatures
958 float total_damage_to_creatures;
963 float stat_damagedone;
965 if(RadiusDamage_running)
967 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
971 RadiusDamage_running = 1;
973 tfloordmg = autocvar_g_throughfloor_damage;
974 tfloorforce = autocvar_g_throughfloor_force;
976 total_damage_to_creatures = 0;
978 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
979 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
981 force = inflictorvelocity;
985 force = normalize(force);
986 if(forceintensity >= 0)
987 Damage_DamageInfo(inflictororigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
989 Damage_DamageInfo(inflictororigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
994 targ = WarpZone_FindRadius (inflictororigin, rad + MAX_DAMAGEEXTRARADIUS, false);
998 if ((targ != inflictor) || inflictorselfdamage)
999 if (((cantbe != targ) && !mustbe) || (mustbe == targ))
1000 if (targ.takedamage)
1006 // LordHavoc: measure distance to nearest point on target (not origin)
1007 // (this guarentees 100% damage on a touch impact)
1008 nearest = targ.WarpZone_findradius_nearest;
1009 diff = targ.WarpZone_findradius_dist;
1010 // round up a little on the damage to ensure full damage on impacts
1011 // and turn the distance into a fraction of the radius
1012 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
1014 //bprint(ftos(power));
1015 //if (targ == attacker)
1016 // print(ftos(power), "\n");
1022 finaldmg = coredamage * power + edgedamage * (1 - power);
1028 vector myblastorigin;
1031 myblastorigin = WarpZone_TransformOrigin(targ, inflictororigin);
1033 // if it's a player, use the view origin as reference
1034 center = CENTER_OR_VIEWOFS(targ);
1036 force = normalize(center - myblastorigin);
1037 force = force * (finaldmg / coredamage) * forceintensity;
1040 if(deathtype & WEP_BLASTER)
1041 force *= WEP_CVAR_BOTH(blaster, !(deathtype & HITTYPE_SECONDARY), force_zscale);
1043 if(targ != directhitentity)
1048 float mininv_f, mininv_d;
1050 // test line of sight to multiple positions on box,
1051 // and do damage if any of them hit
1054 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
1055 // so for a given max stddev:
1056 // n = (1 / (2 * max stddev of hitratio))^2
1058 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
1059 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
1061 if(autocvar_g_throughfloor_debug)
1062 printf("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f);
1065 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
1067 if(autocvar_g_throughfloor_debug)
1068 printf(" steps=%f", total);
1071 if (IS_PLAYER(targ))
1072 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
1074 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1076 if(autocvar_g_throughfloor_debug)
1077 printf(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total)));
1079 for(c = 0; c < total; ++c)
1081 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1082 WarpZone_TraceLine(inflictororigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1083 if (trace_fraction == 1 || trace_ent == targ)
1087 hitloc = hitloc + nearest;
1091 nearest.x = targ.origin.x + targ.mins.x + random() * targ.size.x;
1092 nearest.y = targ.origin.y + targ.mins.y + random() * targ.size.y;
1093 nearest.z = targ.origin.z + targ.mins.z + random() * targ.size.z;
1096 nearest = hitloc * (1 / max(1, hits));
1097 hitratio = (hits / total);
1098 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1099 finaldmg = finaldmg * a;
1100 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1103 if(autocvar_g_throughfloor_debug)
1104 printf(" D=%f F=%f\n", finaldmg, vlen(force));
1107 //if (targ == attacker)
1109 // print("hits ", ftos(hits), " / ", ftos(total));
1110 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1111 // print(" (", ftos(a), ")\n");
1113 if(finaldmg || vlen(force))
1117 total_damage_to_creatures += finaldmg;
1119 if(accuracy_isgooddamage(attacker, targ))
1120 stat_damagedone += finaldmg;
1123 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1124 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1126 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1134 RadiusDamage_running = 0;
1136 if(!DEATH_ISSPECIAL(deathtype))
1137 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1139 return total_damage_to_creatures;
1142 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, float deathtype, entity directhitentity)
1144 return RadiusDamageForSource (inflictor, (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5), inflictor.velocity, attacker, coredamage, edgedamage, rad, cantbe, mustbe, false, forceintensity, deathtype, directhitentity);
1147 float Fire_IsBurning(entity e)
1149 return (time < e.fire_endtime);
1152 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1155 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1166 // print("adding a fire burner to ", e.classname, "\n");
1167 e.fire_burner = spawn();
1168 e.fire_burner.classname = "fireburner";
1169 e.fire_burner.think = fireburner_think;
1170 e.fire_burner.nextthink = time;
1171 e.fire_burner.owner = e;
1177 if(Fire_IsBurning(e))
1179 mintime = e.fire_endtime - time;
1180 maxtime = max(mintime, t);
1182 mindps = e.fire_damagepersec;
1183 maxdps = max(mindps, dps);
1185 if(maxtime > mintime || maxdps > mindps)
1189 // damage we have right now
1190 mindamage = mindps * mintime;
1192 // damage we want to get
1193 maxdamage = mindamage + d;
1195 // but we can't exceed maxtime * maxdps!
1196 totaldamage = min(maxdamage, maxtime * maxdps);
1200 // totaldamage = min(mindamage + d, maxtime * maxdps)
1202 // totaldamage <= maxtime * maxdps
1203 // ==> totaldamage / maxdps <= maxtime.
1205 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1206 // >= min(mintime, maxtime)
1207 // ==> totaldamage / maxdps >= mintime.
1210 // how long do we damage then?
1211 // at least as long as before
1212 // but, never exceed maxdps
1213 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1217 // at most as long as maximum allowed
1218 // but, never below mindps
1219 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1221 // assuming t > mintime, dps > mindps:
1222 // we get d = t * dps = maxtime * maxdps
1223 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1224 // totaldamage / maxdps = maxtime
1225 // totaldamage / mindps > totaldamage / maxdps = maxtime
1227 // a) totaltime = max(mintime, maxtime) = maxtime
1228 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1230 // assuming t <= mintime:
1231 // we get maxtime = mintime
1232 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1233 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1235 // assuming dps <= mindps:
1236 // we get mindps = maxdps.
1237 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1238 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1239 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1241 e.fire_damagepersec = totaldamage / totaltime;
1242 e.fire_endtime = time + totaltime;
1243 if(totaldamage > 1.2 * mindamage)
1245 e.fire_deathtype = dt;
1246 if(e.fire_owner != o)
1249 e.fire_hitsound = false;
1252 if(accuracy_isgooddamage(o, e))
1253 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1254 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1261 e.fire_damagepersec = dps;
1262 e.fire_endtime = time + t;
1263 e.fire_deathtype = dt;
1265 e.fire_hitsound = false;
1266 if(accuracy_isgooddamage(o, e))
1267 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1272 void Fire_ApplyDamage(entity e)
1277 if (!Fire_IsBurning(e))
1280 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1281 if(IS_NOT_A_CLIENT(o))
1284 // water and slime stop fire
1286 if(e.watertype != CONTENT_LAVA)
1293 t = min(frametime, e.fire_endtime - time);
1294 d = e.fire_damagepersec * t;
1296 hi = e.fire_owner.damage_dealt;
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.damage_dealt = hi;
1302 e.fire_owner.typehitsound = ty;
1304 e.fire_hitsound = true;
1306 if (!IS_INDEPENDENT_PLAYER(e))
1308 FOR_EACH_PLAYER(other) if(e != other)
1310 if(IS_PLAYER(other))
1311 if(other.deadflag == DEAD_NO)
1312 if (!IS_INDEPENDENT_PLAYER(other))
1313 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1315 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1316 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1317 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1322 void Fire_ApplyEffect(entity e)
1324 if(Fire_IsBurning(e))
1325 e.effects |= EF_FLAME;
1327 e.effects &= ~EF_FLAME;
1330 void fireburner_think()
1332 // for players, this is done in the regular loop
1333 if(wasfreed(self.owner))
1338 Fire_ApplyEffect(self.owner);
1339 if(!Fire_IsBurning(self.owner))
1341 self.owner.fire_burner = world;
1345 Fire_ApplyDamage(self.owner);
1346 self.nextthink = time;