5 #include "mutators/all.qh"
7 #include "spawnpoints.qh"
9 #include "../common/vehicles/all.qh"
10 #include "../common/items/all.qc"
11 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
12 #include "weapons/accuracy.qh"
13 #include "weapons/csqcprojectile.qh"
14 #include "weapons/selection.qh"
15 #include "../common/buffs/all.qh"
16 #include "../common/constants.qh"
17 #include "../common/deathtypes/all.qh"
18 #include "../common/notifications.qh"
19 #include "../common/movetypes/movetypes.qh"
20 #include "../common/playerstats.qh"
21 #include "../common/teams.qh"
22 #include "../common/util.qh"
23 #include "../common/weapons/all.qh"
24 #include "../lib/csqcmodel/sv_model.qh"
25 #include "../lib/warpzone/common.qh"
27 void UpdateFrags(entity player, float f)
29 PlayerTeamScore_AddScore(player, f);
32 void GiveFrags (entity attacker, entity targ, float f, int deathtype)
34 // TODO route through PlayerScores instead
42 PlayerScore_Add(attacker, SP_SUICIDES, 1);
47 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
53 PlayerScore_Add(attacker, SP_KILLS, 1);
55 PS_GR_P_ADDVAL(attacker, sprintf("kills-%d", targ.playerid), 1);
58 PlayerScore_Add(targ, SP_DEATHS, 1);
60 if(targ != attacker) // not for suicides
61 if(g_weaponarena_random)
63 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
64 Weapon culprit = DEATH_WEAPONOF(deathtype);
66 culprit = get_weaponinfo(attacker.weapon);
67 else if(!(attacker.weapons & WepSet_FromWeapon(culprit.m_id)))
68 culprit = get_weaponinfo(attacker.weapon);
70 if(g_weaponarena_random_with_blaster && culprit == WEP_BLASTER) // WEAPONTODO: Shouldn't this be in a mutator?
76 if(!GiveFrags_randomweapons)
78 GiveFrags_randomweapons = new(GiveFrags_randomweapons);
82 GiveFrags_randomweapons.weapons = WARMUP_START_WEAPONS;
84 GiveFrags_randomweapons.weapons = start_weapons;
86 // all others (including the culprit): remove
87 GiveFrags_randomweapons.weapons &= ~attacker.weapons;
88 GiveFrags_randomweapons.weapons &= ~WepSet_FromWeapon(culprit.m_id);
90 // among the remaining ones, choose one by random
91 W_RandomWeapons(GiveFrags_randomweapons, 1);
93 if(GiveFrags_randomweapons.weapons)
95 attacker.weapons |= GiveFrags_randomweapons.weapons;
96 attacker.weapons &= ~WepSet_FromWeapon(culprit.m_id);
100 // after a frag, choose another random weapon set
101 if (!(attacker.weapons & WepSet_FromWeapon(attacker.weapon)))
102 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
105 // FIXME fix the mess this is (we have REAL points now!)
106 if(MUTATOR_CALLHOOK(GiveFragsForKill, self, attacker, targ, f))
111 attacker.totalfrags += f;
114 UpdateFrags(attacker, f);
117 string AppendItemcodes(string s, entity player)
122 // w = player.switchweapon;
124 w = player.cnt; // previous weapon!
125 s = strcat(s, ftos(w));
126 if(time < player.strength_finished)
128 if(time < player.invincible_finished)
130 if(player.flagcarried != world)
132 if(player.BUTTON_CHAT)
139 void LogDeath(string mode, int deathtype, entity killer, entity killed)
142 if(!autocvar_sv_eventlog)
144 s = strcat(":kill:", mode);
145 s = strcat(s, ":", ftos(killer.playerid));
146 s = strcat(s, ":", ftos(killed.playerid));
147 s = strcat(s, ":type=", Deathtype_Name(deathtype));
148 s = strcat(s, ":items=");
149 s = AppendItemcodes(s, killer);
152 s = strcat(s, ":victimitems=");
153 s = AppendItemcodes(s, killed);
158 void Obituary_SpecialDeath(
162 string s1, string s2, string s3,
163 float f1, float f2, float f3)
165 if(DEATH_ISSPECIAL(deathtype))
167 entity deathent = Deathtypes_from(deathtype - DT_FIRST);
168 if (!deathent) { backtrace("Obituary_SpecialDeath: Could not find deathtype entity!\n"); return; }
172 if(deathent.death_msgmurder)
174 Send_Notification_WOCOVA(
178 deathent.death_msgmurder.nent_id,
182 Send_Notification_WOCOVA(
186 deathent.death_msgmurder.nent_msginfo.nent_id,
194 if(deathent.death_msgself)
196 Send_Notification_WOCOVA(
200 deathent.death_msgself.nent_id,
204 Send_Notification_WOCOVA(
208 deathent.death_msgself.nent_msginfo.nent_id,
215 else { backtrace("Obituary_SpecialDeath called without a special deathtype?\n"); return; }
218 float Obituary_WeaponDeath(
222 string s1, string s2, string s3,
225 Weapon death_weapon = DEATH_WEAPONOF(deathtype);
226 if (death_weapon != WEP_Null)
228 w_deathtype = deathtype;
229 int death_message = ((murder) ? death_weapon.wr_killmessage(death_weapon) : death_weapon.wr_suicidemessage(death_weapon));
234 Send_Notification_WOCOVA(
242 Send_Notification_WOCOVA(
246 msg_multi_notifs[death_message - 1].nent_msginfo.nent_id,
254 "Obituary_WeaponDeath(): ^1Deathtype ^7(%d)^1 has no notification for weapon %d!\n",
265 void Obituary(entity attacker, entity inflictor, entity targ, int deathtype)
268 if (!IS_PLAYER(targ)) { backtrace("Obituary called on non-player?!\n"); return; }
271 float notif_firstblood = false;
272 float kill_count_to_attacker, kill_count_to_target;
274 // Set final information for the death
275 targ.death_origin = targ.origin;
276 if(targ != attacker) { targ.killer_origin = attacker.origin; }
277 string deathlocation = (autocvar_notification_server_allows_location ? NearestLocation(targ.death_origin) : "");
279 #ifdef NOTIFICATIONS_DEBUG
282 "Obituary(%s, %s, %s, %s = %d);\n",
286 Deathtype_Name(deathtype),
297 if(DEATH_ISSPECIAL(deathtype))
299 if(deathtype == DEATH_TEAMCHANGE.m_id || deathtype == DEATH_AUTOTEAMCHANGE.m_id)
301 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.team, 0, 0);
305 switch(DEATH_ENT(deathtype))
307 case DEATH_MIRRORDAMAGE:
309 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
315 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
321 else if (!Obituary_WeaponDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0))
323 backtrace("SUICIDE: what the hell happened here?\n");
326 LogDeath("suicide", deathtype, targ, targ);
327 GiveFrags(attacker, targ, -1, deathtype);
333 else if(IS_PLAYER(attacker))
335 if(SAME_TEAM(attacker, targ))
337 LogDeath("tk", deathtype, attacker, targ);
338 GiveFrags(attacker, targ, -1, deathtype);
340 attacker.killcount = 0;
342 Send_Notification(NOTIF_ONE, attacker, MSG_CENTER, CENTER_DEATH_TEAMKILL_FRAG, targ.netname);
343 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_DEATH_TEAMKILL_FRAGGED, attacker.netname);
344 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(targ.team, INFO_DEATH_TEAMKILL_), targ.netname, attacker.netname, deathlocation, targ.killcount);
346 // In this case, the death message will ALWAYS be "foo was betrayed by bar"
347 // No need for specific death/weapon messages...
351 LogDeath("frag", deathtype, attacker, targ);
352 GiveFrags(attacker, targ, 1, deathtype);
354 attacker.taunt_soundtime = time + 1;
355 attacker.killcount = attacker.killcount + 1;
357 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
360 Send_Notification(NOTIF_ONE, attacker, MSG_ANNCE, ANNCE_KILLSTREAK_##countb); \
361 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_##counta, 1); \
364 switch(attacker.killcount)
371 if(!checkrules_firstblood)
373 checkrules_firstblood = true;
374 notif_firstblood = true; // modify the current messages so that they too show firstblood information
375 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
376 PS_GR_P_ADDVAL(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
378 // tell spree_inf and spree_cen that this is a first-blood and first-victim event
379 kill_count_to_attacker = -1;
380 kill_count_to_target = -2;
384 kill_count_to_attacker = attacker.killcount;
385 kill_count_to_target = 0;
396 kill_count_to_attacker,
397 (IS_BOT_CLIENT(targ) ? NO_MSG : targ.ping)
405 kill_count_to_target,
408 (IS_BOT_CLIENT(attacker) ? NO_MSG : attacker.ping)
419 kill_count_to_attacker,
420 (IS_BOT_CLIENT(targ) ? NO_MSG : targ.ping)
428 kill_count_to_target,
431 (IS_BOT_CLIENT(attacker) ? NO_MSG : attacker.ping)
436 if(deathtype == DEATH_BUFF.m_id)
439 if (!Obituary_WeaponDeath(targ, true, deathtype, targ.netname, attacker.netname, deathlocation, targ.killcount, kill_count_to_attacker))
440 Obituary_SpecialDeath(targ, true, deathtype, targ.netname, attacker.netname, deathlocation, targ.killcount, kill_count_to_attacker, f3);
449 switch(DEATH_ENT(deathtype))
451 // For now, we're just forcing HURTTRIGGER to behave as "DEATH_VOID" and giving it no special options...
452 // Later on you will only be able to make custom messages using DEATH_CUSTOM,
453 // and there will be a REAL DEATH_VOID implementation which mappers will use.
454 case DEATH_HURTTRIGGER:
456 Obituary_SpecialDeath(targ, false, deathtype,
468 Obituary_SpecialDeath(targ, false, deathtype,
470 ((strstrofs(deathmessage, "%", 0) < 0) ? strcat("%s ", deathmessage) : deathmessage),
480 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
485 LogDeath("accident", deathtype, targ, targ);
486 GiveFrags(targ, targ, -1, deathtype);
488 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5)
490 Send_Notification(NOTIF_ONE, targ, MSG_ANNCE, ANNCE_ACHIEVEMENT_BOTLIKE);
491 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
495 // reset target kill count
496 if(targ.killcount) { targ.killcount = 0; }
501 if(!self.owner.frozen || self.owner.iceblock != self)
506 setorigin(self, self.owner.origin - '0 0 16');
507 self.nextthink = time;
510 void Freeze (entity targ, float freeze_time, float frozen_type, float show_waypoint)
512 if(!IS_PLAYER(targ) && !IS_MONSTER(targ)) // only specified entities can be freezed
518 float targ_maxhealth = ((IS_MONSTER(targ)) ? targ.max_health : start_health);
520 targ.frozen = frozen_type;
521 targ.revive_progress = ((frozen_type == 3) ? 1 : 0);
522 targ.health = ((frozen_type == 3) ? targ_maxhealth : 1);
523 targ.revive_speed = freeze_time;
524 self.bot_attack = false;
526 entity ice = new(ice);
528 ice.scale = targ.scale;
529 ice.think = Ice_Think;
530 ice.nextthink = time;
531 ice.frame = floor(random() * 21); // ice model has 20 different looking frames
532 setmodel(ice, MDL_ICE);
534 ice.colormod = Team_ColorRGB(targ.team);
535 ice.glowmod = ice.colormod;
537 targ.revival_time = 0;
539 WITH(entity, self, ice, Ice_Think());
541 RemoveGrapplingHook(targ);
544 FOR_EACH_PLAYER(head)
545 if(head.hook.aiment == targ)
546 RemoveGrapplingHook(head);
550 WaypointSprite_Spawn(WP_Frozen, 0, 0, targ, '0 0 64', world, targ.team, targ, waypointsprite_attached, true, RADARICON_WAYPOINT);
553 void Unfreeze (entity targ)
558 if(targ.frozen && targ.frozen != 3) // only reset health if target was frozen
559 targ.health = ((IS_PLAYER(targ)) ? start_health : targ.max_health);
563 targ.revive_progress = 0;
564 targ.revival_time = time;
565 self.bot_attack = true;
567 WaypointSprite_Kill(targ.waypointsprite_attached);
569 FOR_EACH_PLAYER(head)
570 if(head.hook.aiment == targ)
571 RemoveGrapplingHook(head);
573 // remove the ice block
575 remove(targ.iceblock);
576 targ.iceblock = world;
579 void Damage (entity targ, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
583 float complainteamdamage = 0;
584 entity attacker_save;
588 if (gameover || targ.killcount == FRAGS_SPECTATOR)
593 damage_inflictor = inflictor;
594 damage_attacker = attacker;
595 attacker_save = attacker;
600 if(targ.hook.aiment == attacker)
601 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
603 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
604 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
607 if(SAME_TEAM(targ, attacker))
614 if(deathtype == DEATH_KILL.m_id || deathtype == DEATH_TEAMCHANGE.m_id || deathtype == DEATH_AUTOTEAMCHANGE.m_id)
616 // exit the vehicle before killing (fixes a crash)
617 if(IS_PLAYER(targ) && targ.vehicle)
618 vehicles_exit(VHEF_RELEASE);
620 // These are ALWAYS lethal
621 // No damage modification here
622 // Instead, prepare the victim for his death...
624 targ.spawnshieldtime = 0;
625 targ.health = 0.9; // this is < 1
626 targ.flags -= targ.flags & FL_GODMODE;
629 else if(deathtype == DEATH_MIRRORDAMAGE.m_id || deathtype == DEATH_NOAMMO.m_id)
635 // nullify damage if teamplay is on
636 if(deathtype != DEATH_TELEFRAG.m_id)
637 if(IS_PLAYER(attacker))
639 if(IS_PLAYER(targ) && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
644 else if(SAME_TEAM(attacker, targ))
646 if(autocvar_teamplay_mode == 1)
648 else if(attacker != targ)
650 if(autocvar_teamplay_mode == 3)
652 else if(autocvar_teamplay_mode == 4)
654 if(IS_PLAYER(targ) && targ.deadflag == DEAD_NO)
656 attacker.dmg_team = attacker.dmg_team + damage;
657 complainteamdamage = attacker.dmg_team - autocvar_g_teamdamage_threshold;
658 if(complainteamdamage > 0)
659 mirrordamage = autocvar_g_mirrordamage * complainteamdamage;
660 mirrorforce = autocvar_g_mirrordamage * vlen(force);
661 damage = autocvar_g_friendlyfire * damage;
662 // mirrordamage will be used LATER
664 if(autocvar_g_mirrordamage_virtual)
666 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, mirrordamage);
667 attacker.dmg_take += v.x;
668 attacker.dmg_save += v.y;
669 attacker.dmg_inflictor = inflictor;
674 if(autocvar_g_friendlyfire_virtual)
676 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
677 targ.dmg_take += v.x;
678 targ.dmg_save += v.y;
679 targ.dmg_inflictor = inflictor;
681 if(!autocvar_g_friendlyfire_virtual_force)
692 if (!DEATH_ISSPECIAL(deathtype))
694 damage *= g_weapondamagefactor;
695 mirrordamage *= g_weapondamagefactor;
696 complainteamdamage *= g_weapondamagefactor;
697 force = force * g_weaponforcefactor;
698 mirrorforce *= g_weaponforcefactor;
701 // should this be changed at all? If so, in what way?
702 MUTATOR_CALLHOOK(PlayerDamage_Calculate, inflictor, attacker, targ, deathtype, damage, mirrordamage, force);
703 damage = frag_damage;
704 mirrordamage = frag_mirrordamage;
708 if(deathtype != DEATH_HURTTRIGGER.m_id && deathtype != DEATH_TEAMCHANGE.m_id && deathtype != DEATH_AUTOTEAMCHANGE.m_id)
710 if(autocvar_g_frozen_revive_falldamage > 0)
711 if(deathtype == DEATH_FALL.m_id)
712 if(damage >= autocvar_g_frozen_revive_falldamage)
715 targ.health = autocvar_g_frozen_revive_falldamage_health;
716 Send_Effect(EFFECT_ICEORGLASS, targ.origin, '0 0 0', 3);
717 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_FALL, targ.netname);
718 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
722 force *= autocvar_g_frozen_force;
725 if(targ.frozen && deathtype == DEATH_HURTTRIGGER.m_id && !autocvar_g_frozen_damage_trigger)
727 Send_Effect(EFFECT_TELEPORT, targ.origin, '0 0 0', 1);
730 entity spot = SelectSpawnPoint (false);
735 self.deadflag = DEAD_NO;
737 self.angles = spot.angles;
740 self.effects |= EF_TELEPORT_BIT;
742 self.angles_z = 0; // never spawn tilted even if the spot says to
743 self.fixangle = true; // turn this way immediately
744 self.velocity = '0 0 0';
745 self.avelocity = '0 0 0';
746 self.punchangle = '0 0 0';
747 self.punchvector = '0 0 0';
748 self.oldvelocity = self.velocity;
750 self.spawnorigin = spot.origin;
751 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins.z - 24));
752 // don't reset back to last position, even if new position is stuck in solid
753 self.oldorigin = self.origin;
754 self.prevorigin = self.origin;
756 Send_Effect(EFFECT_TELEPORT, self.origin, '0 0 0', 1);
764 // apply strength multiplier
765 if (attacker.items & ITEM_Strength.m_itemid)
769 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
770 force = force * autocvar_g_balance_powerup_strength_selfforce;
774 damage = damage * autocvar_g_balance_powerup_strength_damage;
775 force = force * autocvar_g_balance_powerup_strength_force;
779 // apply invincibility multiplier
780 if (targ.items & ITEM_Shield.m_itemid)
781 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
784 if (targ == attacker)
785 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
790 if(deathtype != DEATH_BUFF.m_id)
791 if(targ.takedamage == DAMAGE_AIM)
795 if(IS_VEHICLE(targ) && targ.owner)
800 if(IS_PLAYER(victim) || (IS_TURRET(victim) && victim.active == ACTIVE_ACTIVE) || IS_MONSTER(victim) || MUTATOR_CALLHOOK(PlayHitsound, victim))
802 if(DIFF_TEAM(victim, attacker) && !victim.frozen)
806 if(deathtype != DEATH_FIRE.m_id)
808 if(victim.BUTTON_CHAT)
809 attacker.typehitsound += 1;
811 attacker.damage_dealt += damage;
814 damage_goodhits += 1;
815 damage_gooddamage += damage;
817 if (!DEATH_ISSPECIAL(deathtype))
819 if(IS_PLAYER(targ)) // don't do this for vehicles
827 if(deathtype != DEATH_FIRE.m_id)
829 attacker.typehitsound += 1;
831 if(complainteamdamage > 0)
832 if(time > attacker.teamkill_complain)
834 attacker.teamkill_complain = time + 5;
835 attacker.teamkill_soundtime = time + 0.4;
836 attacker.teamkill_soundsource = targ;
844 if (self.damageforcescale)
846 if (!IS_PLAYER(self) || time >= self.spawnshieldtime || self == attacker)
848 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
849 if(self.movetype == MOVETYPE_PHYSICS)
851 entity farcent = new(farce);
852 farcent.enemy = self;
853 farcent.movedir = farce * 10;
855 farcent.movedir = farcent.movedir * self.mass;
856 farcent.origin = hitloc;
857 farcent.forcetype = FORCETYPE_FORCEATPOS;
858 farcent.nextthink = time + 0.1;
859 farcent.think = SUB_Remove;
863 self.velocity = self.velocity + farce;
864 self.move_velocity = self.velocity;
866 self.flags &= ~FL_ONGROUND;
867 self.move_flags &= ~FL_ONGROUND;
868 UpdateCSQCProjectile(self);
871 if (damage != 0 || (self.damageforcescale && vlen(force)))
872 if (self.event_damage)
873 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
876 // apply mirror damage if any
877 if(mirrordamage > 0 || mirrorforce > 0)
879 attacker = attacker_save;
881 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
882 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE.m_id, attacker.origin, force);
886 float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector inflictorvelocity, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float inflictorselfdamage, float forceintensity, int deathtype, entity directhitentity)
887 // Returns total damage applies to creatures
891 float total_damage_to_creatures;
896 float stat_damagedone;
898 if(RadiusDamage_running)
900 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
904 RadiusDamage_running = 1;
906 tfloordmg = autocvar_g_throughfloor_damage;
907 tfloorforce = autocvar_g_throughfloor_force;
909 total_damage_to_creatures = 0;
911 if(deathtype != (WEP_HOOK.m_id | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
912 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
914 force = inflictorvelocity;
918 force = normalize(force);
919 if(forceintensity >= 0)
920 Damage_DamageInfo(inflictororigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
922 Damage_DamageInfo(inflictororigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
927 targ = WarpZone_FindRadius (inflictororigin, rad + MAX_DAMAGEEXTRARADIUS, false);
931 if ((targ != inflictor) || inflictorselfdamage)
932 if (((cantbe != targ) && !mustbe) || (mustbe == targ))
939 // LordHavoc: measure distance to nearest point on target (not origin)
940 // (this guarentees 100% damage on a touch impact)
941 nearest = targ.WarpZone_findradius_nearest;
942 diff = targ.WarpZone_findradius_dist;
943 // round up a little on the damage to ensure full damage on impacts
944 // and turn the distance into a fraction of the radius
945 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
947 //bprint(ftos(power));
948 //if (targ == attacker)
949 // print(ftos(power), "\n");
955 finaldmg = coredamage * power + edgedamage * (1 - power);
961 vector myblastorigin;
964 myblastorigin = WarpZone_TransformOrigin(targ, inflictororigin);
966 // if it's a player, use the view origin as reference
967 center = CENTER_OR_VIEWOFS(targ);
969 force = normalize(center - myblastorigin);
970 force = force * (finaldmg / coredamage) * forceintensity;
973 if(deathtype & WEP_BLASTER.m_id)
974 force *= WEP_CVAR_BOTH(blaster, !(deathtype & HITTYPE_SECONDARY), force_zscale);
976 if(targ != directhitentity)
981 float mininv_f, mininv_d;
983 // test line of sight to multiple positions on box,
984 // and do damage if any of them hit
987 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
988 // so for a given max stddev:
989 // n = (1 / (2 * max stddev of hitratio))^2
991 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
992 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
994 if(autocvar_g_throughfloor_debug)
995 LOG_INFOF("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f);
998 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
1000 if(autocvar_g_throughfloor_debug)
1001 LOG_INFOF(" steps=%f", total);
1004 if (IS_PLAYER(targ))
1005 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
1007 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1009 if(autocvar_g_throughfloor_debug)
1010 LOG_INFOF(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total)));
1012 for(c = 0; c < total; ++c)
1014 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1015 WarpZone_TraceLine(inflictororigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1016 if (trace_fraction == 1 || trace_ent == targ)
1020 hitloc = hitloc + nearest;
1024 nearest.x = targ.origin.x + targ.mins.x + random() * targ.size.x;
1025 nearest.y = targ.origin.y + targ.mins.y + random() * targ.size.y;
1026 nearest.z = targ.origin.z + targ.mins.z + random() * targ.size.z;
1029 nearest = hitloc * (1 / max(1, hits));
1030 hitratio = (hits / total);
1031 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1032 finaldmg = finaldmg * a;
1033 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1036 if(autocvar_g_throughfloor_debug)
1037 LOG_INFOF(" D=%f F=%f\n", finaldmg, vlen(force));
1040 //if (targ == attacker)
1042 // print("hits ", ftos(hits), " / ", ftos(total));
1043 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1044 // print(" (", ftos(a), ")\n");
1046 if(finaldmg || vlen(force))
1050 total_damage_to_creatures += finaldmg;
1052 if(accuracy_isgooddamage(attacker, targ))
1053 stat_damagedone += finaldmg;
1056 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1057 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1059 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1067 RadiusDamage_running = 0;
1069 if(!DEATH_ISSPECIAL(deathtype))
1070 accuracy_add(attacker, DEATH_WEAPONOF(deathtype).m_id, 0, min(coredamage, stat_damagedone));
1072 return total_damage_to_creatures;
1075 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, int deathtype, entity directhitentity)
1077 return RadiusDamageForSource (inflictor, (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5), inflictor.velocity, attacker, coredamage, edgedamage, rad, cantbe, mustbe, false, forceintensity, deathtype, directhitentity);
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;
1099 // print("adding a fire burner to ", e.classname, "\n");
1100 e.fire_burner = new(fireburner);
1101 e.fire_burner.think = fireburner_think;
1102 e.fire_burner.nextthink = time;
1103 e.fire_burner.owner = e;
1109 if(Fire_IsBurning(e))
1111 mintime = e.fire_endtime - time;
1112 maxtime = max(mintime, t);
1114 mindps = e.fire_damagepersec;
1115 maxdps = max(mindps, dps);
1117 if(maxtime > mintime || maxdps > mindps)
1121 // damage we have right now
1122 mindamage = mindps * mintime;
1124 // damage we want to get
1125 maxdamage = mindamage + d;
1127 // but we can't exceed maxtime * maxdps!
1128 totaldamage = min(maxdamage, maxtime * maxdps);
1132 // totaldamage = min(mindamage + d, maxtime * maxdps)
1134 // totaldamage <= maxtime * maxdps
1135 // ==> totaldamage / maxdps <= maxtime.
1137 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1138 // >= min(mintime, maxtime)
1139 // ==> totaldamage / maxdps >= mintime.
1142 // how long do we damage then?
1143 // at least as long as before
1144 // but, never exceed maxdps
1145 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1149 // at most as long as maximum allowed
1150 // but, never below mindps
1151 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1153 // assuming t > mintime, dps > mindps:
1154 // we get d = t * dps = maxtime * maxdps
1155 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1156 // totaldamage / maxdps = maxtime
1157 // totaldamage / mindps > totaldamage / maxdps = maxtime
1159 // a) totaltime = max(mintime, maxtime) = maxtime
1160 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1162 // assuming t <= mintime:
1163 // we get maxtime = mintime
1164 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1165 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1167 // assuming dps <= mindps:
1168 // we get mindps = maxdps.
1169 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1170 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1171 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1173 e.fire_damagepersec = totaldamage / totaltime;
1174 e.fire_endtime = time + totaltime;
1175 if(totaldamage > 1.2 * mindamage)
1177 e.fire_deathtype = dt;
1178 if(e.fire_owner != o)
1181 e.fire_hitsound = false;
1184 if(accuracy_isgooddamage(o, e))
1185 accuracy_add(o, DEATH_WEAPONOF(dt).m_id, 0, max(0, totaldamage - mindamage));
1186 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1193 e.fire_damagepersec = dps;
1194 e.fire_endtime = time + t;
1195 e.fire_deathtype = dt;
1197 e.fire_hitsound = false;
1198 if(accuracy_isgooddamage(o, e))
1199 accuracy_add(o, DEATH_WEAPONOF(dt).m_id, 0, d);
1204 void Fire_ApplyDamage(entity e)
1209 if (!Fire_IsBurning(e))
1212 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1213 if(IS_NOT_A_CLIENT(o))
1216 // water and slime stop fire
1218 if(e.watertype != CONTENT_LAVA)
1225 t = min(frametime, e.fire_endtime - time);
1226 d = e.fire_damagepersec * t;
1228 hi = e.fire_owner.damage_dealt;
1229 ty = e.fire_owner.typehitsound;
1230 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1231 if(e.fire_hitsound && e.fire_owner)
1233 e.fire_owner.damage_dealt = hi;
1234 e.fire_owner.typehitsound = ty;
1236 e.fire_hitsound = true;
1238 if (!IS_INDEPENDENT_PLAYER(e))
1240 FOR_EACH_PLAYER(other) if(e != other)
1242 if(IS_PLAYER(other))
1243 if(other.deadflag == DEAD_NO)
1244 if (!IS_INDEPENDENT_PLAYER(other))
1245 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1247 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1248 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1249 Fire_AddDamage(other, o, d, t, DEATH_FIRE.m_id);
1254 void Fire_ApplyEffect(entity e)
1256 if(Fire_IsBurning(e))
1257 e.effects |= EF_FLAME;
1259 e.effects &= ~EF_FLAME;
1262 void fireburner_think()
1264 // for players, this is done in the regular loop
1265 if(wasfreed(self.owner))
1270 Fire_ApplyEffect(self.owner);
1271 if(!Fire_IsBurning(self.owner))
1273 self.owner.fire_burner = world;
1277 Fire_ApplyDamage(self.owner);
1278 self.nextthink = time;