5 #include "mutators/mutators_include.qh"
7 #include "spawnpoints.qh"
9 #include "../common/vehicles/all.qh"
10 #include "weapons/accuracy.qh"
11 #include "weapons/csqcprojectile.qh"
12 #include "weapons/selection.qh"
13 #include "../common/buffs.qh"
14 #include "../common/constants.qh"
15 #include "../common/deathtypes.qh"
16 #include "../common/notifications.qh"
17 #include "../common/movetypes/movetypes.qh"
18 #include "../common/playerstats.qh"
19 #include "../common/teams.qh"
20 #include "../common/util.qh"
21 #include "../common/weapons/all.qh"
22 #include "../csqcmodellib/sv_model.qh"
23 #include "../warpzonelib/common.qh"
25 float Damage_DamageInfo_SendEntity(entity to, int sf)
27 WriteByte(MSG_ENTITY, ENT_CLIENT_DAMAGEINFO);
28 WriteShort(MSG_ENTITY, self.projectiledeathtype);
29 WriteCoord(MSG_ENTITY, floor(self.origin.x));
30 WriteCoord(MSG_ENTITY, floor(self.origin.y));
31 WriteCoord(MSG_ENTITY, floor(self.origin.z));
32 WriteByte(MSG_ENTITY, bound(1, self.dmg, 255));
33 WriteByte(MSG_ENTITY, bound(0, self.dmg_radius, 255));
34 WriteByte(MSG_ENTITY, bound(1, self.dmg_edge, 255));
35 WriteShort(MSG_ENTITY, self.oldorigin.x);
36 WriteByte(MSG_ENTITY, self.species);
40 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, int deathtype, float bloodtype, entity dmgowner)
42 // TODO maybe call this from non-edgedamage too?
43 // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
47 if(!sound_allowed(MSG_BROADCAST, dmgowner))
52 e.projectiledeathtype = deathtype;
54 e.dmg_edge = edgedamage;
56 e.dmg_force = vlen(force);
58 e.oldorigin_x = compressShortVector(e.velocity);
59 e.species = bloodtype;
61 Net_LinkEntity(e, false, 0.2, Damage_DamageInfo_SendEntity);
64 void UpdateFrags(entity player, float f)
66 PlayerTeamScore_AddScore(player, f);
69 void GiveFrags (entity attacker, entity targ, float f, int deathtype)
71 // TODO route through PlayerScores instead
79 PlayerScore_Add(attacker, SP_SUICIDES, 1);
84 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
90 PlayerScore_Add(attacker, SP_KILLS, 1);
92 PS_GR_P_ADDVAL(attacker, sprintf("kills-%d", targ.playerid), 1);
95 PlayerScore_Add(targ, SP_DEATHS, 1);
97 if(targ != attacker) // not for suicides
98 if(g_weaponarena_random)
100 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
102 culprit = DEATH_WEAPONOF(deathtype);
104 culprit = attacker.weapon;
105 else if(!(attacker.weapons & WepSet_FromWeapon(culprit)))
106 culprit = attacker.weapon;
108 if(g_weaponarena_random_with_blaster && culprit == WEP_BLASTER.m_id) // WEAPONTODO: Shouldn't this be in a mutator?
114 if(!GiveFrags_randomweapons)
116 GiveFrags_randomweapons = spawn();
117 GiveFrags_randomweapons.classname = "GiveFrags_randomweapons";
121 GiveFrags_randomweapons.weapons = WARMUP_START_WEAPONS;
123 GiveFrags_randomweapons.weapons = start_weapons;
125 // all others (including the culprit): remove
126 GiveFrags_randomweapons.weapons &= ~attacker.weapons;
127 GiveFrags_randomweapons.weapons &= ~WepSet_FromWeapon(culprit);
129 // among the remaining ones, choose one by random
130 W_RandomWeapons(GiveFrags_randomweapons, 1);
132 if(GiveFrags_randomweapons.weapons)
134 attacker.weapons |= GiveFrags_randomweapons.weapons;
135 attacker.weapons &= ~WepSet_FromWeapon(culprit);
139 // after a frag, choose another random weapon set
140 if (!(attacker.weapons & WepSet_FromWeapon(attacker.weapon)))
141 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
144 // FIXME fix the mess this is (we have REAL points now!)
145 if(MUTATOR_CALLHOOK(GiveFragsForKill, self, attacker, targ, f))
150 attacker.totalfrags += f;
153 UpdateFrags(attacker, f);
156 string AppendItemcodes(string s, entity player)
161 // w = player.switchweapon;
163 w = player.cnt; // previous weapon!
164 s = strcat(s, ftos(w));
165 if(time < player.strength_finished)
167 if(time < player.invincible_finished)
169 if(player.flagcarried != world)
171 if(player.BUTTON_CHAT)
178 void LogDeath(string mode, int deathtype, entity killer, entity killed)
181 if(!autocvar_sv_eventlog)
183 s = strcat(":kill:", mode);
184 s = strcat(s, ":", ftos(killer.playerid));
185 s = strcat(s, ":", ftos(killed.playerid));
186 s = strcat(s, ":type=", Deathtype_Name(deathtype));
187 s = strcat(s, ":items=");
188 s = AppendItemcodes(s, killer);
191 s = strcat(s, ":victimitems=");
192 s = AppendItemcodes(s, killed);
197 void Obituary_SpecialDeath(
201 string s1, string s2, string s3,
202 float f1, float f2, float f3)
204 if(DEATH_ISSPECIAL(deathtype))
206 entity deathent = deathtypes[(deathtype - DT_FIRST)];
207 if (!deathent) { backtrace("Obituary_SpecialDeath: Could not find deathtype entity!\n"); return; }
211 if(deathent.death_msgmurder)
213 Send_Notification_WOCOVA(
217 deathent.death_msgmurder.nent_id,
221 Send_Notification_WOCOVA(
225 deathent.death_msgmurder.nent_msginfo.nent_id,
233 if(deathent.death_msgself)
235 Send_Notification_WOCOVA(
239 deathent.death_msgself.nent_id,
243 Send_Notification_WOCOVA(
247 deathent.death_msgself.nent_msginfo.nent_id,
254 else { backtrace("Obituary_SpecialDeath called without a special deathtype?\n"); return; }
257 float Obituary_WeaponDeath(
261 string s1, string s2, string s3,
264 float death_weapon = DEATH_WEAPONOF(deathtype);
267 w_deathtype = deathtype;
268 int death_message = WEP_ACTION(death_weapon, ((murder) ? WR_KILLMESSAGE : WR_SUICIDEMESSAGE));
273 Send_Notification_WOCOVA(
281 Send_Notification_WOCOVA(
285 msg_multi_notifs[death_message - 1].nent_msginfo.nent_id,
293 "Obituary_WeaponDeath(): ^1Deathtype ^7(%d)^1 has no notification for weapon %d!\n",
304 void Obituary(entity attacker, entity inflictor, entity targ, int deathtype)
307 if (!IS_PLAYER(targ)) { backtrace("Obituary called on non-player?!\n"); return; }
310 float notif_firstblood = false;
311 float kill_count_to_attacker, kill_count_to_target;
313 // Set final information for the death
314 targ.death_origin = targ.origin;
315 if(targ != attacker) { targ.killer_origin = attacker.origin; }
316 string deathlocation = (autocvar_notification_server_allows_location ? NearestLocation(targ.death_origin) : "");
318 #ifdef NOTIFICATIONS_DEBUG
321 "Obituary(%s, %s, %s, %s = %d);\n",
325 Deathtype_Name(deathtype),
336 if(DEATH_ISSPECIAL(deathtype))
338 if(deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
340 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.team, 0, 0);
346 case DEATH_MIRRORDAMAGE:
348 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
354 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
360 else if (!Obituary_WeaponDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0))
362 backtrace("SUICIDE: what the hell happened here?\n");
365 LogDeath("suicide", deathtype, targ, targ);
366 GiveFrags(attacker, targ, -1, deathtype);
372 else if(IS_PLAYER(attacker))
374 if(SAME_TEAM(attacker, targ))
376 LogDeath("tk", deathtype, attacker, targ);
377 GiveFrags(attacker, targ, -1, deathtype);
379 attacker.killcount = 0;
381 Send_Notification(NOTIF_ONE, attacker, MSG_CENTER, CENTER_DEATH_TEAMKILL_FRAG, targ.netname);
382 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_DEATH_TEAMKILL_FRAGGED, attacker.netname);
383 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(targ.team, INFO_DEATH_TEAMKILL_), targ.netname, attacker.netname, deathlocation, targ.killcount);
385 // In this case, the death message will ALWAYS be "foo was betrayed by bar"
386 // No need for specific death/weapon messages...
390 LogDeath("frag", deathtype, attacker, targ);
391 GiveFrags(attacker, targ, 1, deathtype);
393 attacker.taunt_soundtime = time + 1;
394 attacker.killcount = attacker.killcount + 1;
396 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
399 Send_Notification(NOTIF_ONE, attacker, MSG_ANNCE, ANNCE_KILLSTREAK_##countb); \
400 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_##counta, 1); \
403 switch(attacker.killcount)
410 if(!checkrules_firstblood)
412 checkrules_firstblood = true;
413 notif_firstblood = true; // modify the current messages so that they too show firstblood information
414 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
415 PS_GR_P_ADDVAL(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
417 // tell spree_inf and spree_cen that this is a first-blood and first-victim event
418 kill_count_to_attacker = -1;
419 kill_count_to_target = -2;
423 kill_count_to_attacker = attacker.killcount;
424 kill_count_to_target = 0;
435 kill_count_to_attacker,
436 (IS_BOT_CLIENT(targ) ? NO_MSG : targ.ping)
444 kill_count_to_target,
447 (IS_BOT_CLIENT(attacker) ? NO_MSG : attacker.ping)
458 kill_count_to_attacker,
459 (IS_BOT_CLIENT(targ) ? NO_MSG : targ.ping)
467 kill_count_to_target,
470 (IS_BOT_CLIENT(attacker) ? NO_MSG : attacker.ping)
475 if(deathtype == DEATH_BUFF)
478 if (!Obituary_WeaponDeath(targ, true, deathtype, targ.netname, attacker.netname, deathlocation, targ.killcount, kill_count_to_attacker))
479 Obituary_SpecialDeath(targ, true, deathtype, targ.netname, attacker.netname, deathlocation, targ.killcount, kill_count_to_attacker, f3);
490 // For now, we're just forcing HURTTRIGGER to behave as "DEATH_VOID" and giving it no special options...
491 // Later on you will only be able to make custom messages using DEATH_CUSTOM,
492 // and there will be a REAL DEATH_VOID implementation which mappers will use.
493 case DEATH_HURTTRIGGER:
495 Obituary_SpecialDeath(targ, false, deathtype,
507 Obituary_SpecialDeath(targ, false, deathtype,
509 ((strstrofs(deathmessage, "%", 0) < 0) ? strcat("%s ", deathmessage) : deathmessage),
519 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
524 LogDeath("accident", deathtype, targ, targ);
525 GiveFrags(targ, targ, -1, deathtype);
527 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5)
529 Send_Notification(NOTIF_ONE, targ, MSG_ANNCE, ANNCE_ACHIEVEMENT_BOTLIKE);
530 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
534 // reset target kill count
535 if(targ.killcount) { targ.killcount = 0; }
540 if(!self.owner.frozen || self.owner.iceblock != self)
545 setorigin(self, self.owner.origin - '0 0 16');
546 self.nextthink = time;
549 void Freeze (entity targ, float freeze_time, float frozen_type, float show_waypoint)
551 if(!IS_PLAYER(targ) && !IS_MONSTER(targ)) // only specified entities can be freezed
557 float targ_maxhealth = ((IS_MONSTER(targ)) ? targ.max_health : start_health);
559 targ.frozen = frozen_type;
560 targ.revive_progress = ((frozen_type == 3) ? 1 : 0);
561 targ.health = ((frozen_type == 3) ? targ_maxhealth : 1);
562 targ.revive_speed = freeze_time;
567 ice.classname = "ice";
568 ice.scale = targ.scale;
569 ice.think = Ice_Think;
570 ice.nextthink = time;
571 ice.frame = floor(random() * 21); // ice model has 20 different looking frames
572 setmodel(ice, MDL_ICE);
574 ice.colormod = Team_ColorRGB(targ.team);
575 ice.glowmod = ice.colormod;
577 targ.revival_time = 0;
579 WITH(entity, self, ice, Ice_Think());
581 RemoveGrapplingHook(targ);
583 FOR_EACH_PLAYER(head)
584 if(head.hook.aiment == targ)
585 RemoveGrapplingHook(head);
589 WaypointSprite_Spawn(WP_Frozen, 0, 0, targ, '0 0 64', world, targ.team, targ, waypointsprite_attached, true, RADARICON_WAYPOINT);
592 void Unfreeze (entity targ)
594 if(targ.frozen && targ.frozen != 3) // only reset health if target was frozen
595 targ.health = ((IS_PLAYER(targ)) ? start_health : targ.max_health);
599 targ.revive_progress = 0;
600 targ.revival_time = time;
602 WaypointSprite_Kill(targ.waypointsprite_attached);
604 FOR_EACH_PLAYER(head)
605 if(head.hook.aiment == targ)
606 RemoveGrapplingHook(head);
608 // remove the ice block
610 remove(targ.iceblock);
611 targ.iceblock = world;
614 void Damage (entity targ, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
618 float complainteamdamage = 0;
619 entity attacker_save;
623 if (gameover || targ.killcount == -666)
628 damage_inflictor = inflictor;
629 damage_attacker = attacker;
630 attacker_save = attacker;
635 if(targ.hook.aiment == attacker)
636 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
638 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
639 if(DEATH_ISWEAPON(deathtype, WEP_HOOK.m_id) || DEATH_ISWEAPON(deathtype, WEP_TUBA.m_id))
642 if(SAME_TEAM(targ, attacker))
649 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
651 // exit the vehicle before killing (fixes a crash)
652 if(IS_PLAYER(targ) && targ.vehicle)
653 vehicles_exit(VHEF_RELEASE);
655 // These are ALWAYS lethal
656 // No damage modification here
657 // Instead, prepare the victim for his death...
659 targ.spawnshieldtime = 0;
660 targ.health = 0.9; // this is < 1
661 targ.flags -= targ.flags & FL_GODMODE;
664 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
670 // nullify damage if teamplay is on
671 if(deathtype != DEATH_TELEFRAG)
672 if(IS_PLAYER(attacker))
674 if(IS_PLAYER(targ) && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
679 else if(SAME_TEAM(attacker, targ))
681 if(autocvar_teamplay_mode == 1)
683 else if(attacker != targ)
685 if(autocvar_teamplay_mode == 3)
687 else if(autocvar_teamplay_mode == 4)
689 if(IS_PLAYER(targ) && targ.deadflag == DEAD_NO)
691 attacker.dmg_team = attacker.dmg_team + damage;
692 complainteamdamage = attacker.dmg_team - autocvar_g_teamdamage_threshold;
693 if(complainteamdamage > 0)
694 mirrordamage = autocvar_g_mirrordamage * complainteamdamage;
695 mirrorforce = autocvar_g_mirrordamage * vlen(force);
696 damage = autocvar_g_friendlyfire * damage;
697 // mirrordamage will be used LATER
699 if(autocvar_g_mirrordamage_virtual)
701 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, mirrordamage);
702 attacker.dmg_take += v.x;
703 attacker.dmg_save += v.y;
704 attacker.dmg_inflictor = inflictor;
709 if(autocvar_g_friendlyfire_virtual)
711 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
712 targ.dmg_take += v.x;
713 targ.dmg_save += v.y;
714 targ.dmg_inflictor = inflictor;
716 if(!autocvar_g_friendlyfire_virtual_force)
727 if (!DEATH_ISSPECIAL(deathtype))
729 damage *= g_weapondamagefactor;
730 mirrordamage *= g_weapondamagefactor;
731 complainteamdamage *= g_weapondamagefactor;
732 force = force * g_weaponforcefactor;
733 mirrorforce *= g_weaponforcefactor;
736 // should this be changed at all? If so, in what way?
737 MUTATOR_CALLHOOK(PlayerDamage_Calculate, inflictor, attacker, targ, deathtype, damage, mirrordamage, force);
738 damage = frag_damage;
739 mirrordamage = frag_mirrordamage;
743 if(deathtype != DEATH_HURTTRIGGER && deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_AUTOTEAMCHANGE)
745 if(autocvar_g_freezetag_revive_falldamage > 0)
746 if(deathtype == DEATH_FALL)
747 if(damage >= autocvar_g_freezetag_revive_falldamage)
750 targ.health = autocvar_g_freezetag_revive_falldamage_health;
751 Send_Effect(EFFECT_ICEORGLASS, targ.origin, '0 0 0', 3);
752 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_FALL, targ.netname);
753 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
757 force *= autocvar_g_freezetag_frozen_force;
760 if(targ.frozen && deathtype == DEATH_HURTTRIGGER && !autocvar_g_freezetag_frozen_damage_trigger)
762 Send_Effect(EFFECT_TELEPORT, targ.origin, '0 0 0', 1);
765 entity spot = SelectSpawnPoint (false);
770 self.deadflag = DEAD_NO;
772 self.angles = spot.angles;
775 self.effects |= EF_TELEPORT_BIT;
777 self.angles_z = 0; // never spawn tilted even if the spot says to
778 self.fixangle = true; // turn this way immediately
779 self.velocity = '0 0 0';
780 self.avelocity = '0 0 0';
781 self.punchangle = '0 0 0';
782 self.punchvector = '0 0 0';
783 self.oldvelocity = self.velocity;
785 self.spawnorigin = spot.origin;
786 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins.z - 24));
787 // don't reset back to last position, even if new position is stuck in solid
788 self.oldorigin = self.origin;
789 self.prevorigin = self.origin;
791 Send_Effect(EFFECT_TELEPORT, self.origin, '0 0 0', 1);
799 // apply strength multiplier
800 if (attacker.items & ITEM_Strength.m_itemid)
804 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
805 force = force * autocvar_g_balance_powerup_strength_selfforce;
809 damage = damage * autocvar_g_balance_powerup_strength_damage;
810 force = force * autocvar_g_balance_powerup_strength_force;
814 // apply invincibility multiplier
815 if (targ.items & ITEM_Shield.m_itemid)
816 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
819 if (targ == attacker)
820 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
825 if(deathtype != DEATH_BUFF)
826 if(targ.takedamage == DAMAGE_AIM)
830 if(IS_VEHICLE(targ) && targ.owner)
835 if(IS_PLAYER(victim) || (IS_TURRET(victim) && victim.active == ACTIVE_ACTIVE) || IS_MONSTER(victim) || MUTATOR_CALLHOOK(PlayHitsound, victim))
837 if(DIFF_TEAM(victim, attacker) && !victim.frozen)
841 if(deathtype != DEATH_FIRE)
843 if(victim.BUTTON_CHAT)
844 attacker.typehitsound += 1;
846 attacker.damage_dealt += damage;
849 damage_goodhits += 1;
850 damage_gooddamage += damage;
852 if (!DEATH_ISSPECIAL(deathtype))
854 if(IS_PLAYER(targ)) // don't do this for vehicles
862 if(deathtype != DEATH_FIRE)
864 attacker.typehitsound += 1;
866 if(complainteamdamage > 0)
867 if(time > attacker.teamkill_complain)
869 attacker.teamkill_complain = time + 5;
870 attacker.teamkill_soundtime = time + 0.4;
871 attacker.teamkill_soundsource = targ;
879 if (self.damageforcescale)
881 if (!IS_PLAYER(self) || time >= self.spawnshieldtime || self == attacker)
883 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
884 if(self.movetype == MOVETYPE_PHYSICS)
888 farcent.classname = "farce";
889 farcent.enemy = self;
890 farcent.movedir = farce * 10;
892 farcent.movedir = farcent.movedir * self.mass;
893 farcent.origin = hitloc;
894 farcent.forcetype = FORCETYPE_FORCEATPOS;
895 farcent.nextthink = time + 0.1;
896 farcent.think = SUB_Remove;
900 self.velocity = self.velocity + farce;
901 self.move_velocity = self.velocity;
903 self.flags &= ~FL_ONGROUND;
904 self.move_flags &= ~FL_ONGROUND;
905 UpdateCSQCProjectile(self);
908 if (damage != 0 || (self.damageforcescale && vlen(force)))
909 if (self.event_damage)
910 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
913 // apply mirror damage if any
914 if(mirrordamage > 0 || mirrorforce > 0)
916 attacker = attacker_save;
918 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
919 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
923 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)
924 // Returns total damage applies to creatures
928 float total_damage_to_creatures;
933 float stat_damagedone;
935 if(RadiusDamage_running)
937 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
941 RadiusDamage_running = 1;
943 tfloordmg = autocvar_g_throughfloor_damage;
944 tfloorforce = autocvar_g_throughfloor_force;
946 total_damage_to_creatures = 0;
948 if(deathtype != (WEP_HOOK.m_id | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
949 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA.m_id) // do not send tuba damage (bandwidth hog)
951 force = inflictorvelocity;
955 force = normalize(force);
956 if(forceintensity >= 0)
957 Damage_DamageInfo(inflictororigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
959 Damage_DamageInfo(inflictororigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
964 targ = WarpZone_FindRadius (inflictororigin, rad + MAX_DAMAGEEXTRARADIUS, false);
968 if ((targ != inflictor) || inflictorselfdamage)
969 if (((cantbe != targ) && !mustbe) || (mustbe == targ))
976 // LordHavoc: measure distance to nearest point on target (not origin)
977 // (this guarentees 100% damage on a touch impact)
978 nearest = targ.WarpZone_findradius_nearest;
979 diff = targ.WarpZone_findradius_dist;
980 // round up a little on the damage to ensure full damage on impacts
981 // and turn the distance into a fraction of the radius
982 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
984 //bprint(ftos(power));
985 //if (targ == attacker)
986 // print(ftos(power), "\n");
992 finaldmg = coredamage * power + edgedamage * (1 - power);
998 vector myblastorigin;
1001 myblastorigin = WarpZone_TransformOrigin(targ, inflictororigin);
1003 // if it's a player, use the view origin as reference
1004 center = CENTER_OR_VIEWOFS(targ);
1006 force = normalize(center - myblastorigin);
1007 force = force * (finaldmg / coredamage) * forceintensity;
1010 if(deathtype & WEP_BLASTER.m_id)
1011 force *= WEP_CVAR_BOTH(blaster, !(deathtype & HITTYPE_SECONDARY), force_zscale);
1013 if(targ != directhitentity)
1018 float mininv_f, mininv_d;
1020 // test line of sight to multiple positions on box,
1021 // and do damage if any of them hit
1024 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
1025 // so for a given max stddev:
1026 // n = (1 / (2 * max stddev of hitratio))^2
1028 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
1029 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
1031 if(autocvar_g_throughfloor_debug)
1032 LOG_INFOF("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f);
1035 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
1037 if(autocvar_g_throughfloor_debug)
1038 LOG_INFOF(" steps=%f", total);
1041 if (IS_PLAYER(targ))
1042 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
1044 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1046 if(autocvar_g_throughfloor_debug)
1047 LOG_INFOF(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total)));
1049 for(c = 0; c < total; ++c)
1051 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1052 WarpZone_TraceLine(inflictororigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1053 if (trace_fraction == 1 || trace_ent == targ)
1057 hitloc = hitloc + nearest;
1061 nearest.x = targ.origin.x + targ.mins.x + random() * targ.size.x;
1062 nearest.y = targ.origin.y + targ.mins.y + random() * targ.size.y;
1063 nearest.z = targ.origin.z + targ.mins.z + random() * targ.size.z;
1066 nearest = hitloc * (1 / max(1, hits));
1067 hitratio = (hits / total);
1068 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1069 finaldmg = finaldmg * a;
1070 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1073 if(autocvar_g_throughfloor_debug)
1074 LOG_INFOF(" D=%f F=%f\n", finaldmg, vlen(force));
1077 //if (targ == attacker)
1079 // print("hits ", ftos(hits), " / ", ftos(total));
1080 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1081 // print(" (", ftos(a), ")\n");
1083 if(finaldmg || vlen(force))
1087 total_damage_to_creatures += finaldmg;
1089 if(accuracy_isgooddamage(attacker, targ))
1090 stat_damagedone += finaldmg;
1093 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1094 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1096 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1104 RadiusDamage_running = 0;
1106 if(!DEATH_ISSPECIAL(deathtype))
1107 accuracy_add(attacker, DEATH_WEAPONOF(deathtype), 0, min(coredamage, stat_damagedone));
1109 return total_damage_to_creatures;
1112 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, int deathtype, entity directhitentity)
1114 return RadiusDamageForSource (inflictor, (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5), inflictor.velocity, attacker, coredamage, edgedamage, rad, cantbe, mustbe, false, forceintensity, deathtype, directhitentity);
1117 float Fire_IsBurning(entity e)
1119 return (time < e.fire_endtime);
1122 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1125 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1136 // print("adding a fire burner to ", e.classname, "\n");
1137 e.fire_burner = spawn();
1138 e.fire_burner.classname = "fireburner";
1139 e.fire_burner.think = fireburner_think;
1140 e.fire_burner.nextthink = time;
1141 e.fire_burner.owner = e;
1147 if(Fire_IsBurning(e))
1149 mintime = e.fire_endtime - time;
1150 maxtime = max(mintime, t);
1152 mindps = e.fire_damagepersec;
1153 maxdps = max(mindps, dps);
1155 if(maxtime > mintime || maxdps > mindps)
1159 // damage we have right now
1160 mindamage = mindps * mintime;
1162 // damage we want to get
1163 maxdamage = mindamage + d;
1165 // but we can't exceed maxtime * maxdps!
1166 totaldamage = min(maxdamage, maxtime * maxdps);
1170 // totaldamage = min(mindamage + d, maxtime * maxdps)
1172 // totaldamage <= maxtime * maxdps
1173 // ==> totaldamage / maxdps <= maxtime.
1175 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1176 // >= min(mintime, maxtime)
1177 // ==> totaldamage / maxdps >= mintime.
1180 // how long do we damage then?
1181 // at least as long as before
1182 // but, never exceed maxdps
1183 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1187 // at most as long as maximum allowed
1188 // but, never below mindps
1189 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1191 // assuming t > mintime, dps > mindps:
1192 // we get d = t * dps = maxtime * maxdps
1193 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1194 // totaldamage / maxdps = maxtime
1195 // totaldamage / mindps > totaldamage / maxdps = maxtime
1197 // a) totaltime = max(mintime, maxtime) = maxtime
1198 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1200 // assuming t <= mintime:
1201 // we get maxtime = mintime
1202 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1203 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1205 // assuming dps <= mindps:
1206 // we get mindps = maxdps.
1207 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1208 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1209 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1211 e.fire_damagepersec = totaldamage / totaltime;
1212 e.fire_endtime = time + totaltime;
1213 if(totaldamage > 1.2 * mindamage)
1215 e.fire_deathtype = dt;
1216 if(e.fire_owner != o)
1219 e.fire_hitsound = false;
1222 if(accuracy_isgooddamage(o, e))
1223 accuracy_add(o, DEATH_WEAPONOF(dt), 0, max(0, totaldamage - mindamage));
1224 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1231 e.fire_damagepersec = dps;
1232 e.fire_endtime = time + t;
1233 e.fire_deathtype = dt;
1235 e.fire_hitsound = false;
1236 if(accuracy_isgooddamage(o, e))
1237 accuracy_add(o, DEATH_WEAPONOF(dt), 0, d);
1242 void Fire_ApplyDamage(entity e)
1247 if (!Fire_IsBurning(e))
1250 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1251 if(IS_NOT_A_CLIENT(o))
1254 // water and slime stop fire
1256 if(e.watertype != CONTENT_LAVA)
1263 t = min(frametime, e.fire_endtime - time);
1264 d = e.fire_damagepersec * t;
1266 hi = e.fire_owner.damage_dealt;
1267 ty = e.fire_owner.typehitsound;
1268 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1269 if(e.fire_hitsound && e.fire_owner)
1271 e.fire_owner.damage_dealt = hi;
1272 e.fire_owner.typehitsound = ty;
1274 e.fire_hitsound = true;
1276 if (!IS_INDEPENDENT_PLAYER(e))
1278 FOR_EACH_PLAYER(other) if(e != other)
1280 if(IS_PLAYER(other))
1281 if(other.deadflag == DEAD_NO)
1282 if (!IS_INDEPENDENT_PLAYER(other))
1283 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1285 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1286 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1287 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1292 void Fire_ApplyEffect(entity e)
1294 if(Fire_IsBurning(e))
1295 e.effects |= EF_FLAME;
1297 e.effects &= ~EF_FLAME;
1300 void fireburner_think()
1302 // for players, this is done in the regular loop
1303 if(wasfreed(self.owner))
1308 Fire_ApplyEffect(self.owner);
1309 if(!Fire_IsBurning(self.owner))
1311 self.owner.fire_burner = world;
1315 Fire_ApplyDamage(self.owner);
1316 self.nextthink = time;