5 #include "mutators/all.qh"
7 #include "spawnpoints.qh"
8 #include "../common/t_items.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/constants.qh"
16 #include "../common/deathtypes/all.qh"
17 #include "../common/notifications.qh"
18 #include "../common/physics/movetypes/movetypes.qh"
19 #include "../common/playerstats.qh"
20 #include "../common/teams.qh"
21 #include "../common/util.qh"
22 #include "../common/weapons/all.qh"
23 #include "../lib/csqcmodel/sv_model.qh"
24 #include "../lib/warpzone/common.qh"
26 void UpdateFrags(entity player, float f)
28 PlayerTeamScore_AddScore(player, f);
31 void GiveFrags (entity attacker, entity targ, float f, int deathtype)
33 // TODO route through PlayerScores instead
41 PlayerScore_Add(attacker, SP_SUICIDES, 1);
46 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
52 PlayerScore_Add(attacker, SP_KILLS, 1);
54 PS_GR_P_ADDVAL(attacker, sprintf("kills-%d", targ.playerid), 1);
57 PlayerScore_Add(targ, SP_DEATHS, 1);
59 if(targ != attacker) // not for suicides
60 if(g_weaponarena_random)
62 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
63 Weapon culprit = DEATH_WEAPONOF(deathtype);
64 if(!culprit) culprit = PS(attacker).m_weapon;
65 else if(!(attacker.weapons & (culprit.m_wepset))) culprit = PS(attacker).m_weapon;
67 if(g_weaponarena_random_with_blaster && culprit == WEP_BLASTER) // WEAPONTODO: Shouldn't this be in a mutator?
73 if(!GiveFrags_randomweapons)
75 GiveFrags_randomweapons = new(GiveFrags_randomweapons);
79 GiveFrags_randomweapons.weapons = WARMUP_START_WEAPONS;
81 GiveFrags_randomweapons.weapons = start_weapons;
83 // all others (including the culprit): remove
84 GiveFrags_randomweapons.weapons &= ~attacker.weapons;
85 GiveFrags_randomweapons.weapons &= ~(culprit.m_wepset);
87 // among the remaining ones, choose one by random
88 W_RandomWeapons(GiveFrags_randomweapons, 1);
90 if(GiveFrags_randomweapons.weapons)
92 attacker.weapons |= GiveFrags_randomweapons.weapons;
93 attacker.weapons &= ~(culprit.m_wepset);
97 // after a frag, choose another random weapon set
98 if (!(attacker.weapons & WepSet_FromWeapon(PS(attacker).m_weapon)))
99 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
102 // FIXME fix the mess this is (we have REAL points now!)
103 if(MUTATOR_CALLHOOK(GiveFragsForKill, self, attacker, targ, f))
108 attacker.totalfrags += f;
111 UpdateFrags(attacker, f);
114 string AppendItemcodes(string s, entity player)
116 int w = PS(player).m_weapon.m_id;
118 // w = player.switchweapon;
120 w = player.cnt; // previous weapon!
121 s = strcat(s, ftos(w));
122 if(time < player.strength_finished)
124 if(time < player.invincible_finished)
126 if(player.flagcarried != world)
128 if(player.BUTTON_CHAT)
135 void LogDeath(string mode, int deathtype, entity killer, entity killed)
138 if(!autocvar_sv_eventlog)
140 s = strcat(":kill:", mode);
141 s = strcat(s, ":", ftos(killer.playerid));
142 s = strcat(s, ":", ftos(killed.playerid));
143 s = strcat(s, ":type=", Deathtype_Name(deathtype));
144 s = strcat(s, ":items=");
145 s = AppendItemcodes(s, killer);
148 s = strcat(s, ":victimitems=");
149 s = AppendItemcodes(s, killed);
154 void Obituary_SpecialDeath(
158 string s1, string s2, string s3,
159 float f1, float f2, float f3)
161 if(DEATH_ISSPECIAL(deathtype))
163 entity deathent = Deathtypes_from(deathtype - DT_FIRST);
164 if (!deathent) { backtrace("Obituary_SpecialDeath: Could not find deathtype entity!\n"); return; }
168 if(deathent.death_msgmurder)
170 Send_Notification_WOCOVA(
174 deathent.death_msgmurder.nent_id,
178 Send_Notification_WOCOVA(
182 deathent.death_msgmurder.nent_msginfo.nent_id,
190 if(deathent.death_msgself)
192 Send_Notification_WOCOVA(
196 deathent.death_msgself.nent_id,
200 Send_Notification_WOCOVA(
204 deathent.death_msgself.nent_msginfo.nent_id,
211 else { backtrace("Obituary_SpecialDeath called without a special deathtype?\n"); return; }
214 float Obituary_WeaponDeath(
218 string s1, string s2, string s3,
221 Weapon death_weapon = DEATH_WEAPONOF(deathtype);
222 if (death_weapon != WEP_Null)
224 w_deathtype = deathtype;
225 int death_message = ((murder) ? death_weapon.wr_killmessage(death_weapon) : death_weapon.wr_suicidemessage(death_weapon));
230 Send_Notification_WOCOVA(
238 Send_Notification_WOCOVA(
242 msg_multi_notifs[death_message - 1].nent_msginfo.nent_id,
250 "Obituary_WeaponDeath(): ^1Deathtype ^7(%d)^1 has no notification for weapon %d!\n",
261 .int buffs = _STAT(BUFFS); // TODO: remove
263 void Obituary(entity attacker, entity inflictor, entity targ, int deathtype)
266 if (!IS_PLAYER(targ)) { backtrace("Obituary called on non-player?!\n"); return; }
269 float notif_firstblood = false;
270 float kill_count_to_attacker, kill_count_to_target;
272 // Set final information for the death
273 targ.death_origin = targ.origin;
274 if(targ != attacker) { targ.killer_origin = attacker.origin; }
275 string deathlocation = (autocvar_notification_server_allows_location ? NearestLocation(targ.death_origin) : "");
277 #ifdef NOTIFICATIONS_DEBUG
280 "Obituary(%s, %s, %s, %s = %d);\n",
284 Deathtype_Name(deathtype),
295 if(DEATH_ISSPECIAL(deathtype))
297 if(deathtype == DEATH_TEAMCHANGE.m_id || deathtype == DEATH_AUTOTEAMCHANGE.m_id)
299 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.team, 0, 0);
303 switch(DEATH_ENT(deathtype))
305 case DEATH_MIRRORDAMAGE:
307 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
313 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
319 else if (!Obituary_WeaponDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0))
321 backtrace("SUICIDE: what the hell happened here?\n");
324 LogDeath("suicide", deathtype, targ, targ);
325 GiveFrags(attacker, targ, -1, deathtype);
331 else if(IS_PLAYER(attacker))
333 if(SAME_TEAM(attacker, targ))
335 LogDeath("tk", deathtype, attacker, targ);
336 GiveFrags(attacker, targ, -1, deathtype);
338 attacker.killcount = 0;
340 Send_Notification(NOTIF_ONE, attacker, MSG_CENTER, CENTER_DEATH_TEAMKILL_FRAG, targ.netname);
341 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_DEATH_TEAMKILL_FRAGGED, attacker.netname);
342 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(targ.team, INFO_DEATH_TEAMKILL_), targ.netname, attacker.netname, deathlocation, targ.killcount);
344 // In this case, the death message will ALWAYS be "foo was betrayed by bar"
345 // No need for specific death/weapon messages...
349 LogDeath("frag", deathtype, attacker, targ);
350 GiveFrags(attacker, targ, 1, deathtype);
352 attacker.taunt_soundtime = time + 1;
353 attacker.killcount = attacker.killcount + 1;
355 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
358 Send_Notification(NOTIF_ONE, attacker, MSG_ANNCE, ANNCE_KILLSTREAK_##countb); \
359 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_##counta, 1); \
362 switch(attacker.killcount)
369 if(!checkrules_firstblood)
371 checkrules_firstblood = true;
372 notif_firstblood = true; // modify the current messages so that they too show firstblood information
373 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
374 PS_GR_P_ADDVAL(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
376 // tell spree_inf and spree_cen that this is a first-blood and first-victim event
377 kill_count_to_attacker = -1;
378 kill_count_to_target = -2;
382 kill_count_to_attacker = attacker.killcount;
383 kill_count_to_target = 0;
394 kill_count_to_attacker,
395 (IS_BOT_CLIENT(targ) ? NO_MSG : targ.ping)
403 kill_count_to_target,
406 (IS_BOT_CLIENT(attacker) ? NO_MSG : attacker.ping)
417 kill_count_to_attacker,
418 (IS_BOT_CLIENT(targ) ? NO_MSG : targ.ping)
426 kill_count_to_target,
429 (IS_BOT_CLIENT(attacker) ? NO_MSG : attacker.ping)
434 if(deathtype == DEATH_BUFF.m_id)
437 if (!Obituary_WeaponDeath(targ, true, deathtype, targ.netname, attacker.netname, deathlocation, targ.killcount, kill_count_to_attacker))
438 Obituary_SpecialDeath(targ, true, deathtype, targ.netname, attacker.netname, deathlocation, targ.killcount, kill_count_to_attacker, f3);
447 switch(DEATH_ENT(deathtype))
449 // For now, we're just forcing HURTTRIGGER to behave as "DEATH_VOID" and giving it no special options...
450 // Later on you will only be able to make custom messages using DEATH_CUSTOM,
451 // and there will be a REAL DEATH_VOID implementation which mappers will use.
452 case DEATH_HURTTRIGGER:
454 Obituary_SpecialDeath(targ, false, deathtype,
466 Obituary_SpecialDeath(targ, false, deathtype,
468 ((strstrofs(deathmessage, "%", 0) < 0) ? strcat("%s ", deathmessage) : deathmessage),
478 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
483 LogDeath("accident", deathtype, targ, targ);
484 GiveFrags(targ, targ, -1, deathtype);
486 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5)
488 Send_Notification(NOTIF_ONE, targ, MSG_ANNCE, ANNCE_ACHIEVEMENT_BOTLIKE);
489 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
493 // reset target kill count
494 if(targ.killcount) { targ.killcount = 0; }
499 if(!STAT(FROZEN, self.owner) || self.owner.iceblock != self)
504 setorigin(self, self.owner.origin - '0 0 16');
505 self.nextthink = time;
508 void Freeze (entity targ, float freeze_time, float frozen_type, float show_waypoint)
510 if(!IS_PLAYER(targ) && !IS_MONSTER(targ)) // only specified entities can be freezed
513 if(STAT(FROZEN, targ))
516 float targ_maxhealth = ((IS_MONSTER(targ)) ? targ.max_health : start_health);
518 STAT(FROZEN, targ) = frozen_type;
519 targ.revive_progress = ((frozen_type == 3) ? 1 : 0);
520 targ.health = ((frozen_type == 3) ? targ_maxhealth : 1);
521 targ.revive_speed = freeze_time;
522 self.bot_attack = false;
524 entity ice = new(ice);
526 ice.scale = targ.scale;
527 ice.think = Ice_Think;
528 ice.nextthink = time;
529 ice.frame = floor(random() * 21); // ice model has 20 different looking frames
530 setmodel(ice, MDL_ICE);
532 ice.colormod = Team_ColorRGB(targ.team);
533 ice.glowmod = ice.colormod;
535 targ.revival_time = 0;
537 WITH(entity, self, ice, Ice_Think());
539 RemoveGrapplingHook(targ);
541 FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == targ, LAMBDA(RemoveGrapplingHook(it)));
545 WaypointSprite_Spawn(WP_Frozen, 0, 0, targ, '0 0 64', world, targ.team, targ, waypointsprite_attached, true, RADARICON_WAYPOINT);
548 void Unfreeze (entity targ)
550 if(!STAT(FROZEN, targ))
553 if(STAT(FROZEN, targ) && STAT(FROZEN, targ) != 3) // only reset health if target was frozen
554 targ.health = ((IS_PLAYER(targ)) ? start_health : targ.max_health);
556 STAT(FROZEN, targ) = 0;
557 targ.revive_progress = 0;
558 targ.revival_time = time;
559 self.bot_attack = true;
561 WaypointSprite_Kill(targ.waypointsprite_attached);
563 FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == targ, LAMBDA(RemoveGrapplingHook(it)));
565 // remove the ice block
567 remove(targ.iceblock);
568 targ.iceblock = world;
571 void Damage (entity targ, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
575 float complainteamdamage = 0;
576 entity attacker_save;
580 if (gameover || targ.killcount == FRAGS_SPECTATOR)
585 damage_inflictor = inflictor;
586 damage_attacker = attacker;
587 attacker_save = attacker;
592 if(targ.hook.aiment == attacker)
593 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
595 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
596 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
599 if(SAME_TEAM(targ, attacker))
606 if(deathtype == DEATH_KILL.m_id || deathtype == DEATH_TEAMCHANGE.m_id || deathtype == DEATH_AUTOTEAMCHANGE.m_id)
608 // exit the vehicle before killing (fixes a crash)
609 if(IS_PLAYER(targ) && targ.vehicle)
610 vehicles_exit(VHEF_RELEASE);
612 // These are ALWAYS lethal
613 // No damage modification here
614 // Instead, prepare the victim for his death...
616 targ.spawnshieldtime = 0;
617 targ.health = 0.9; // this is < 1
618 targ.flags -= targ.flags & FL_GODMODE;
621 else if(deathtype == DEATH_MIRRORDAMAGE.m_id || deathtype == DEATH_NOAMMO.m_id)
627 // nullify damage if teamplay is on
628 if(deathtype != DEATH_TELEFRAG.m_id)
629 if(IS_PLAYER(attacker))
631 if(IS_PLAYER(targ) && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
636 else if(SAME_TEAM(attacker, targ))
638 if(autocvar_teamplay_mode == 1)
640 else if(attacker != targ)
642 if(autocvar_teamplay_mode == 3)
644 else if(autocvar_teamplay_mode == 4)
646 if(IS_PLAYER(targ) && !IS_DEAD(targ))
648 attacker.dmg_team = attacker.dmg_team + damage;
649 complainteamdamage = attacker.dmg_team - autocvar_g_teamdamage_threshold;
650 if(complainteamdamage > 0)
651 mirrordamage = autocvar_g_mirrordamage * complainteamdamage;
652 mirrorforce = autocvar_g_mirrordamage * vlen(force);
653 damage = autocvar_g_friendlyfire * damage;
654 // mirrordamage will be used LATER
656 if(autocvar_g_mirrordamage_virtual)
658 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, mirrordamage);
659 attacker.dmg_take += v.x;
660 attacker.dmg_save += v.y;
661 attacker.dmg_inflictor = inflictor;
666 if(autocvar_g_friendlyfire_virtual)
668 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
669 targ.dmg_take += v.x;
670 targ.dmg_save += v.y;
671 targ.dmg_inflictor = inflictor;
673 if(!autocvar_g_friendlyfire_virtual_force)
684 if (!DEATH_ISSPECIAL(deathtype))
686 damage *= g_weapondamagefactor;
687 mirrordamage *= g_weapondamagefactor;
688 complainteamdamage *= g_weapondamagefactor;
689 force = force * g_weaponforcefactor;
690 mirrorforce *= g_weaponforcefactor;
693 // should this be changed at all? If so, in what way?
694 MUTATOR_CALLHOOK(PlayerDamage_Calculate, inflictor, attacker, targ, deathtype, damage, mirrordamage, force);
695 damage = frag_damage;
696 mirrordamage = frag_mirrordamage;
699 if(STAT(FROZEN, targ))
700 if(deathtype != DEATH_HURTTRIGGER.m_id && deathtype != DEATH_TEAMCHANGE.m_id && deathtype != DEATH_AUTOTEAMCHANGE.m_id)
702 if(autocvar_g_frozen_revive_falldamage > 0)
703 if(deathtype == DEATH_FALL.m_id)
704 if(damage >= autocvar_g_frozen_revive_falldamage)
707 targ.health = autocvar_g_frozen_revive_falldamage_health;
708 Send_Effect(EFFECT_ICEORGLASS, targ.origin, '0 0 0', 3);
709 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_FALL, targ.netname);
710 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
714 force *= autocvar_g_frozen_force;
717 if(STAT(FROZEN, targ) && deathtype == DEATH_HURTTRIGGER.m_id && !autocvar_g_frozen_damage_trigger)
719 Send_Effect(EFFECT_TELEPORT, targ.origin, '0 0 0', 1);
722 entity spot = SelectSpawnPoint (false);
727 self.deadflag = DEAD_NO;
729 self.angles = spot.angles;
732 self.effects |= EF_TELEPORT_BIT;
734 self.angles_z = 0; // never spawn tilted even if the spot says to
735 self.fixangle = true; // turn this way immediately
736 self.velocity = '0 0 0';
737 self.avelocity = '0 0 0';
738 self.punchangle = '0 0 0';
739 self.punchvector = '0 0 0';
740 self.oldvelocity = self.velocity;
742 self.spawnorigin = spot.origin;
743 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins.z - 24));
744 // don't reset back to last position, even if new position is stuck in solid
745 self.oldorigin = self.origin;
746 self.prevorigin = self.origin;
748 Send_Effect(EFFECT_TELEPORT, self.origin, '0 0 0', 1);
756 // apply strength multiplier
757 if (attacker.items & ITEM_Strength.m_itemid)
761 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
762 force = force * autocvar_g_balance_powerup_strength_selfforce;
766 damage = damage * autocvar_g_balance_powerup_strength_damage;
767 force = force * autocvar_g_balance_powerup_strength_force;
771 // apply invincibility multiplier
772 if (targ.items & ITEM_Shield.m_itemid)
773 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
776 if (targ == attacker)
777 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
782 if(deathtype != DEATH_BUFF.m_id)
783 if(targ.takedamage == DAMAGE_AIM)
787 if(IS_VEHICLE(targ) && targ.owner)
792 if(IS_PLAYER(victim) || (IS_TURRET(victim) && victim.active == ACTIVE_ACTIVE) || IS_MONSTER(victim) || MUTATOR_CALLHOOK(PlayHitsound, victim))
794 if(DIFF_TEAM(victim, attacker) && !STAT(FROZEN, victim))
798 if(deathtype != DEATH_FIRE.m_id)
800 if(victim.BUTTON_CHAT)
801 attacker.typehitsound += 1;
803 attacker.damage_dealt += damage;
806 damage_goodhits += 1;
807 damage_gooddamage += damage;
809 if (!DEATH_ISSPECIAL(deathtype))
811 if(IS_PLAYER(targ)) // don't do this for vehicles
819 if(deathtype != DEATH_FIRE.m_id)
821 attacker.typehitsound += 1;
823 if(complainteamdamage > 0)
824 if(time > attacker.teamkill_complain)
826 attacker.teamkill_complain = time + 5;
827 attacker.teamkill_soundtime = time + 0.4;
828 attacker.teamkill_soundsource = targ;
836 if (self.damageforcescale)
838 if (!IS_PLAYER(self) || time >= self.spawnshieldtime || self == attacker)
840 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
841 if(self.movetype == MOVETYPE_PHYSICS)
843 entity farcent = new(farce);
844 farcent.enemy = self;
845 farcent.movedir = farce * 10;
847 farcent.movedir = farcent.movedir * self.mass;
848 farcent.origin = hitloc;
849 farcent.forcetype = FORCETYPE_FORCEATPOS;
850 farcent.nextthink = time + 0.1;
851 farcent.think = SUB_Remove_self;
855 self.velocity = self.velocity + farce;
856 self.move_velocity = self.velocity;
858 UNSET_ONGROUND(self);
859 self.move_flags &= ~FL_ONGROUND;
860 UpdateCSQCProjectile(self);
863 if (damage != 0 || (self.damageforcescale && vlen(force)))
864 if (self.event_damage)
865 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
868 // apply mirror damage if any
869 if(mirrordamage > 0 || mirrorforce > 0)
871 attacker = attacker_save;
873 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
874 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE.m_id, attacker.origin, force);
878 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)
879 // Returns total damage applies to creatures
883 float total_damage_to_creatures;
888 float stat_damagedone;
890 if(RadiusDamage_running)
892 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
896 RadiusDamage_running = 1;
898 tfloordmg = autocvar_g_throughfloor_damage;
899 tfloorforce = autocvar_g_throughfloor_force;
901 total_damage_to_creatures = 0;
903 if(deathtype != (WEP_HOOK.m_id | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
904 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
906 force = inflictorvelocity;
910 force = normalize(force);
911 if(forceintensity >= 0)
912 Damage_DamageInfo(inflictororigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
914 Damage_DamageInfo(inflictororigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
919 targ = WarpZone_FindRadius (inflictororigin, rad + MAX_DAMAGEEXTRARADIUS, false);
923 if ((targ != inflictor) || inflictorselfdamage)
924 if (((cantbe != targ) && !mustbe) || (mustbe == targ))
931 // LordHavoc: measure distance to nearest point on target (not origin)
932 // (this guarentees 100% damage on a touch impact)
933 nearest = targ.WarpZone_findradius_nearest;
934 diff = targ.WarpZone_findradius_dist;
935 // round up a little on the damage to ensure full damage on impacts
936 // and turn the distance into a fraction of the radius
937 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
939 //bprint(ftos(power));
940 //if (targ == attacker)
941 // print(ftos(power), "\n");
947 finaldmg = coredamage * power + edgedamage * (1 - power);
953 vector myblastorigin;
956 myblastorigin = WarpZone_TransformOrigin(targ, inflictororigin);
958 // if it's a player, use the view origin as reference
959 center = CENTER_OR_VIEWOFS(targ);
961 force = normalize(center - myblastorigin);
962 force = force * (finaldmg / coredamage) * forceintensity;
965 if(deathtype & WEP_BLASTER.m_id)
966 force *= WEP_CVAR_BOTH(blaster, !(deathtype & HITTYPE_SECONDARY), force_zscale);
968 if(targ != directhitentity)
973 float mininv_f, mininv_d;
975 // test line of sight to multiple positions on box,
976 // and do damage if any of them hit
979 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
980 // so for a given max stddev:
981 // n = (1 / (2 * max stddev of hitratio))^2
983 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
984 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
986 if(autocvar_g_throughfloor_debug)
987 LOG_INFOF("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f);
990 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
992 if(autocvar_g_throughfloor_debug)
993 LOG_INFOF(" steps=%f", total);
997 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
999 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1001 if(autocvar_g_throughfloor_debug)
1002 LOG_INFOF(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total)));
1004 for(c = 0; c < total; ++c)
1006 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1007 WarpZone_TraceLine(inflictororigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1008 if (trace_fraction == 1 || trace_ent == targ)
1012 hitloc = hitloc + nearest;
1016 nearest.x = targ.origin.x + targ.mins.x + random() * targ.size.x;
1017 nearest.y = targ.origin.y + targ.mins.y + random() * targ.size.y;
1018 nearest.z = targ.origin.z + targ.mins.z + random() * targ.size.z;
1021 nearest = hitloc * (1 / max(1, hits));
1022 hitratio = (hits / total);
1023 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1024 finaldmg = finaldmg * a;
1025 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1028 if(autocvar_g_throughfloor_debug)
1029 LOG_INFOF(" D=%f F=%f\n", finaldmg, vlen(force));
1032 //if (targ == attacker)
1034 // print("hits ", ftos(hits), " / ", ftos(total));
1035 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1036 // print(" (", ftos(a), ")\n");
1038 if(finaldmg || vlen(force))
1042 total_damage_to_creatures += finaldmg;
1044 if(accuracy_isgooddamage(attacker, targ))
1045 stat_damagedone += finaldmg;
1048 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1049 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1051 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1059 RadiusDamage_running = 0;
1061 if(!DEATH_ISSPECIAL(deathtype))
1062 accuracy_add(attacker, DEATH_WEAPONOF(deathtype).m_id, 0, min(coredamage, stat_damagedone));
1064 return total_damage_to_creatures;
1067 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, int deathtype, entity directhitentity)
1069 return RadiusDamageForSource (inflictor, (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5), inflictor.velocity, attacker, coredamage, edgedamage, rad, cantbe, mustbe, false, forceintensity, deathtype, directhitentity);
1072 float Fire_IsBurning(entity e)
1074 return (time < e.fire_endtime);
1077 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1080 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1091 // print("adding a fire burner to ", e.classname, "\n");
1092 e.fire_burner = new(fireburner);
1093 e.fire_burner.think = fireburner_think;
1094 e.fire_burner.nextthink = time;
1095 e.fire_burner.owner = e;
1101 if(Fire_IsBurning(e))
1103 mintime = e.fire_endtime - time;
1104 maxtime = max(mintime, t);
1106 mindps = e.fire_damagepersec;
1107 maxdps = max(mindps, dps);
1109 if(maxtime > mintime || maxdps > mindps)
1113 // damage we have right now
1114 mindamage = mindps * mintime;
1116 // damage we want to get
1117 maxdamage = mindamage + d;
1119 // but we can't exceed maxtime * maxdps!
1120 totaldamage = min(maxdamage, maxtime * maxdps);
1124 // totaldamage = min(mindamage + d, maxtime * maxdps)
1126 // totaldamage <= maxtime * maxdps
1127 // ==> totaldamage / maxdps <= maxtime.
1129 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1130 // >= min(mintime, maxtime)
1131 // ==> totaldamage / maxdps >= mintime.
1134 // how long do we damage then?
1135 // at least as long as before
1136 // but, never exceed maxdps
1137 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1141 // at most as long as maximum allowed
1142 // but, never below mindps
1143 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1145 // assuming t > mintime, dps > mindps:
1146 // we get d = t * dps = maxtime * maxdps
1147 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1148 // totaldamage / maxdps = maxtime
1149 // totaldamage / mindps > totaldamage / maxdps = maxtime
1151 // a) totaltime = max(mintime, maxtime) = maxtime
1152 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1154 // assuming t <= mintime:
1155 // we get maxtime = mintime
1156 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1157 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1159 // assuming dps <= mindps:
1160 // we get mindps = maxdps.
1161 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1162 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1163 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1165 e.fire_damagepersec = totaldamage / totaltime;
1166 e.fire_endtime = time + totaltime;
1167 if(totaldamage > 1.2 * mindamage)
1169 e.fire_deathtype = dt;
1170 if(e.fire_owner != o)
1173 e.fire_hitsound = false;
1176 if(accuracy_isgooddamage(o, e))
1177 accuracy_add(o, DEATH_WEAPONOF(dt).m_id, 0, max(0, totaldamage - mindamage));
1178 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1185 e.fire_damagepersec = dps;
1186 e.fire_endtime = time + t;
1187 e.fire_deathtype = dt;
1189 e.fire_hitsound = false;
1190 if(accuracy_isgooddamage(o, e))
1191 accuracy_add(o, DEATH_WEAPONOF(dt).m_id, 0, d);
1196 void Fire_ApplyDamage(entity e)
1201 if (!Fire_IsBurning(e))
1204 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1205 if(IS_NOT_A_CLIENT(o))
1208 // water and slime stop fire
1210 if(e.watertype != CONTENT_LAVA)
1217 t = min(frametime, e.fire_endtime - time);
1218 d = e.fire_damagepersec * t;
1220 hi = e.fire_owner.damage_dealt;
1221 ty = e.fire_owner.typehitsound;
1222 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1223 if(e.fire_hitsound && e.fire_owner)
1225 e.fire_owner.damage_dealt = hi;
1226 e.fire_owner.typehitsound = ty;
1228 e.fire_hitsound = true;
1230 if(!IS_INDEPENDENT_PLAYER(e))
1231 if(!STAT(FROZEN, e))
1232 FOREACH_CLIENT(IS_PLAYER(it) && it != e, LAMBDA(
1234 if(!IS_INDEPENDENT_PLAYER(it))
1235 if(boxesoverlap(e.absmin, e.absmax, it.absmin, it.absmax))
1237 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1238 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1239 Fire_AddDamage(it, o, d, t, DEATH_FIRE.m_id);
1244 void Fire_ApplyEffect(entity e)
1246 if(Fire_IsBurning(e))
1247 e.effects |= EF_FLAME;
1249 e.effects &= ~EF_FLAME;
1252 void fireburner_think()
1254 // for players, this is done in the regular loop
1255 if(wasfreed(self.owner))
1260 Fire_ApplyEffect(self.owner);
1261 if(!Fire_IsBurning(self.owner))
1263 self.owner.fire_burner = world;
1267 Fire_ApplyDamage(self.owner);
1268 self.nextthink = time;