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!)
148 if(MUTATOR_CALLHOOK(GiveFragsForKill, attacker, targ, f))
158 attacker.totalfrags += f;
161 UpdateFrags(attacker, f);
164 string AppendItemcodes(string s, entity player)
169 // w = player.switchweapon;
171 w = player.cnt; // previous weapon!
172 s = strcat(s, ftos(w));
173 if(time < player.strength_finished)
175 if(time < player.invincible_finished)
177 if(player.flagcarried != world)
179 if(player.BUTTON_CHAT)
186 void LogDeath(string mode, int deathtype, entity killer, entity killed)
189 if(!autocvar_sv_eventlog)
191 s = strcat(":kill:", mode);
192 s = strcat(s, ":", ftos(killer.playerid));
193 s = strcat(s, ":", ftos(killed.playerid));
194 s = strcat(s, ":type=", Deathtype_Name(deathtype));
195 s = strcat(s, ":items=");
196 s = AppendItemcodes(s, killer);
199 s = strcat(s, ":victimitems=");
200 s = AppendItemcodes(s, killed);
205 void Obituary_SpecialDeath(
209 string s1, string s2, string s3,
210 float f1, float f2, float f3)
212 if(DEATH_ISSPECIAL(deathtype))
214 entity deathent = deathtypes[(deathtype - DT_FIRST)];
215 if (!deathent) { backtrace("Obituary_SpecialDeath: Could not find deathtype entity!\n"); return; }
219 if(deathent.death_msgmurder)
221 Send_Notification_WOCOVA(
225 deathent.death_msgmurder.nent_id,
229 Send_Notification_WOCOVA(
233 deathent.death_msgmurder.nent_msginfo.nent_id,
241 if(deathent.death_msgself)
243 Send_Notification_WOCOVA(
247 deathent.death_msgself.nent_id,
251 Send_Notification_WOCOVA(
255 deathent.death_msgself.nent_msginfo.nent_id,
262 else { backtrace("Obituary_SpecialDeath called without a special deathtype?\n"); return; }
265 float Obituary_WeaponDeath(
269 string s1, string s2, string s3,
272 float death_weapon = DEATH_WEAPONOF(deathtype);
275 w_deathtype = deathtype;
276 int death_message = WEP_ACTION(death_weapon, ((murder) ? WR_KILLMESSAGE : WR_SUICIDEMESSAGE));
281 Send_Notification_WOCOVA(
289 Send_Notification_WOCOVA(
293 msg_multi_notifs[death_message - 1].nent_msginfo.nent_id,
301 "Obituary_WeaponDeath(): ^1Deathtype ^7(%d)^1 has no notification for weapon %d!\n",
312 void Obituary(entity attacker, entity inflictor, entity targ, int deathtype)
315 if (!IS_PLAYER(targ)) { backtrace("Obituary called on non-player?!\n"); return; }
318 float notif_firstblood = false;
319 float kill_count_to_attacker, kill_count_to_target;
321 // Set final information for the death
322 targ.death_origin = targ.origin;
323 if(targ != attacker) { targ.killer_origin = attacker.origin; }
324 string deathlocation = (autocvar_notification_server_allows_location ? NearestLocation(targ.death_origin) : "");
326 #ifdef NOTIFICATIONS_DEBUG
329 "Obituary(%s, %s, %s, %s = %d);\n",
333 Deathtype_Name(deathtype),
344 if(DEATH_ISSPECIAL(deathtype))
346 if(deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
348 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.team, 0, 0);
354 case DEATH_MIRRORDAMAGE:
356 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
362 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
368 else if (!Obituary_WeaponDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0))
370 backtrace("SUICIDE: what the hell happened here?\n");
373 LogDeath("suicide", deathtype, targ, targ);
374 GiveFrags(attacker, targ, -1, deathtype);
380 else if(IS_PLAYER(attacker))
382 if(SAME_TEAM(attacker, targ))
384 LogDeath("tk", deathtype, attacker, targ);
385 GiveFrags(attacker, targ, -1, deathtype);
387 attacker.killcount = 0;
389 Send_Notification(NOTIF_ONE, attacker, MSG_CENTER, CENTER_DEATH_TEAMKILL_FRAG, targ.netname);
390 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_DEATH_TEAMKILL_FRAGGED, attacker.netname);
391 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(targ.team, INFO_DEATH_TEAMKILL_), targ.netname, attacker.netname, deathlocation, targ.killcount);
393 // In this case, the death message will ALWAYS be "foo was betrayed by bar"
394 // No need for specific death/weapon messages...
398 LogDeath("frag", deathtype, attacker, targ);
399 GiveFrags(attacker, targ, 1, deathtype);
401 attacker.taunt_soundtime = time + 1;
402 attacker.killcount = attacker.killcount + 1;
404 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
407 Send_Notification(NOTIF_ONE, attacker, MSG_ANNCE, ANNCE_KILLSTREAK_##countb); \
408 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_##counta, 1); \
411 switch(attacker.killcount)
418 if(!checkrules_firstblood)
420 checkrules_firstblood = true;
421 notif_firstblood = true; // modify the current messages so that they too show firstblood information
422 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
423 PS_GR_P_ADDVAL(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
425 // tell spree_inf and spree_cen that this is a first-blood and first-victim event
426 kill_count_to_attacker = -1;
427 kill_count_to_target = -2;
431 kill_count_to_attacker = attacker.killcount;
432 kill_count_to_target = 0;
443 kill_count_to_attacker,
444 (IS_BOT_CLIENT(targ) ? NO_MSG : targ.ping)
452 kill_count_to_target,
455 (IS_BOT_CLIENT(attacker) ? NO_MSG : attacker.ping)
466 kill_count_to_attacker,
467 (IS_BOT_CLIENT(targ) ? NO_MSG : targ.ping)
475 kill_count_to_target,
478 (IS_BOT_CLIENT(attacker) ? NO_MSG : attacker.ping)
483 if(deathtype == DEATH_BUFF)
486 if (!Obituary_WeaponDeath(targ, true, deathtype, targ.netname, attacker.netname, deathlocation, targ.killcount, kill_count_to_attacker))
487 Obituary_SpecialDeath(targ, true, deathtype, targ.netname, attacker.netname, deathlocation, targ.killcount, kill_count_to_attacker, f3);
498 // For now, we're just forcing HURTTRIGGER to behave as "DEATH_VOID" and giving it no special options...
499 // Later on you will only be able to make custom messages using DEATH_CUSTOM,
500 // and there will be a REAL DEATH_VOID implementation which mappers will use.
501 case DEATH_HURTTRIGGER:
503 Obituary_SpecialDeath(targ, false, deathtype,
515 Obituary_SpecialDeath(targ, false, deathtype,
517 ((strstrofs(deathmessage, "%", 0) < 0) ? strcat("%s ", deathmessage) : deathmessage),
527 Obituary_SpecialDeath(targ, false, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
532 LogDeath("accident", deathtype, targ, targ);
533 GiveFrags(targ, targ, -1, deathtype);
535 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5)
537 Send_Notification(NOTIF_ONE, targ, MSG_ANNCE, ANNCE_ACHIEVEMENT_BOTLIKE);
538 PS_GR_P_ADDVAL(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
542 // reset target kill count
543 if(targ.killcount) { targ.killcount = 0; }
548 if(!self.owner.frozen || self.owner.iceblock != self)
553 setorigin(self, self.owner.origin - '0 0 16');
554 self.nextthink = time;
557 void Freeze (entity targ, float freeze_time, float frozen_type, float show_waypoint)
559 if(!IS_PLAYER(targ) && !IS_MONSTER(targ)) // only specified entities can be freezed
565 float targ_maxhealth = ((IS_MONSTER(targ)) ? targ.max_health : start_health);
567 targ.frozen = frozen_type;
568 targ.revive_progress = ((frozen_type == 3) ? 1 : 0);
569 targ.health = ((frozen_type == 3) ? targ_maxhealth : 1);
570 targ.revive_speed = freeze_time;
575 ice.classname = "ice";
576 ice.scale = targ.scale;
577 ice.think = Ice_Think;
578 ice.nextthink = time;
579 ice.frame = floor(random() * 21); // ice model has 20 different looking frames
580 setmodel(ice, "models/ice/ice.md3");
582 ice.colormod = Team_ColorRGB(targ.team);
583 ice.glowmod = ice.colormod;
585 targ.revival_time = 0;
593 RemoveGrapplingHook(targ);
595 FOR_EACH_PLAYER(head)
596 if(head.hook.aiment == targ)
597 RemoveGrapplingHook(head);
601 WaypointSprite_Spawn(WP_Frozen, 0, 0, targ, '0 0 64', world, targ.team, targ, waypointsprite_attached, true, RADARICON_WAYPOINT);
604 void Unfreeze (entity targ)
606 if(targ.frozen && targ.frozen != 3) // only reset health if target was frozen
607 targ.health = ((IS_PLAYER(targ)) ? start_health : targ.max_health);
611 targ.revive_progress = 0;
612 targ.revival_time = time;
614 WaypointSprite_Kill(targ.waypointsprite_attached);
616 FOR_EACH_PLAYER(head)
617 if(head.hook.aiment == targ)
618 RemoveGrapplingHook(head);
620 // remove the ice block
622 remove(targ.iceblock);
623 targ.iceblock = world;
626 void Damage (entity targ, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
630 float complainteamdamage = 0;
631 entity attacker_save;
635 if (gameover || targ.killcount == -666)
642 damage_inflictor = inflictor;
643 damage_attacker = attacker;
644 attacker_save = attacker;
649 if(targ.hook.aiment == attacker)
650 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
652 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
653 if(DEATH_ISWEAPON(deathtype, WEP_HOOK.m_id) || DEATH_ISWEAPON(deathtype, WEP_TUBA.m_id))
656 if(SAME_TEAM(targ, attacker))
663 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
665 // exit the vehicle before killing (fixes a crash)
666 if(IS_PLAYER(targ) && targ.vehicle)
667 vehicles_exit(VHEF_RELEASE);
669 // These are ALWAYS lethal
670 // No damage modification here
671 // Instead, prepare the victim for his death...
673 targ.spawnshieldtime = 0;
674 targ.health = 0.9; // this is < 1
675 targ.flags -= targ.flags & FL_GODMODE;
678 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
684 // nullify damage if teamplay is on
685 if(deathtype != DEATH_TELEFRAG)
686 if(IS_PLAYER(attacker))
688 if(IS_PLAYER(targ) && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
693 else if(SAME_TEAM(attacker, targ))
695 if(autocvar_teamplay_mode == 1)
697 else if(attacker != targ)
699 if(autocvar_teamplay_mode == 3)
701 else if(autocvar_teamplay_mode == 4)
703 if(IS_PLAYER(targ) && targ.deadflag == DEAD_NO)
705 attacker.dmg_team = attacker.dmg_team + damage;
706 complainteamdamage = attacker.dmg_team - autocvar_g_teamdamage_threshold;
707 if(complainteamdamage > 0)
708 mirrordamage = autocvar_g_mirrordamage * complainteamdamage;
709 mirrorforce = autocvar_g_mirrordamage * vlen(force);
710 damage = autocvar_g_friendlyfire * damage;
711 // mirrordamage will be used LATER
713 if(autocvar_g_mirrordamage_virtual)
715 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, mirrordamage);
716 attacker.dmg_take += v.x;
717 attacker.dmg_save += v.y;
718 attacker.dmg_inflictor = inflictor;
723 if(autocvar_g_friendlyfire_virtual)
725 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
726 targ.dmg_take += v.x;
727 targ.dmg_save += v.y;
728 targ.dmg_inflictor = inflictor;
730 if(!autocvar_g_friendlyfire_virtual_force)
741 if (!DEATH_ISSPECIAL(deathtype))
743 damage *= g_weapondamagefactor;
744 mirrordamage *= g_weapondamagefactor;
745 complainteamdamage *= g_weapondamagefactor;
746 force = force * g_weaponforcefactor;
747 mirrorforce *= g_weaponforcefactor;
750 // should this be changed at all? If so, in what way?
751 MUTATOR_CALLHOOK(PlayerDamage_Calculate, inflictor, attacker, targ, deathtype, damage, mirrordamage, force);
752 damage = frag_damage;
753 mirrordamage = frag_mirrordamage;
757 if(deathtype != DEATH_HURTTRIGGER && deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_AUTOTEAMCHANGE)
759 if(autocvar_g_freezetag_revive_falldamage > 0)
760 if(deathtype == DEATH_FALL)
761 if(damage >= autocvar_g_freezetag_revive_falldamage)
764 targ.health = autocvar_g_freezetag_revive_falldamage_health;
765 Send_Effect(EFFECT_ICEORGLASS, targ.origin, '0 0 0', 3);
766 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_FALL, targ.netname);
767 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
771 force *= autocvar_g_freezetag_frozen_force;
774 if(targ.frozen && deathtype == DEATH_HURTTRIGGER && !autocvar_g_freezetag_frozen_damage_trigger)
776 Send_Effect(EFFECT_TELEPORT, targ.origin, '0 0 0', 1);
778 entity oldself = self;
780 entity spot = SelectSpawnPoint (false);
785 self.deadflag = DEAD_NO;
787 self.angles = spot.angles;
790 self.effects |= EF_TELEPORT_BIT;
792 self.angles_z = 0; // never spawn tilted even if the spot says to
793 self.fixangle = true; // turn this way immediately
794 self.velocity = '0 0 0';
795 self.avelocity = '0 0 0';
796 self.punchangle = '0 0 0';
797 self.punchvector = '0 0 0';
798 self.oldvelocity = self.velocity;
800 self.spawnorigin = spot.origin;
801 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins.z - 24));
802 // don't reset back to last position, even if new position is stuck in solid
803 self.oldorigin = self.origin;
804 self.prevorigin = self.origin;
806 Send_Effect(EFFECT_TELEPORT, self.origin, '0 0 0', 1);
814 // apply strength multiplier
815 if (attacker.items & ITEM_Strength.m_itemid)
819 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
820 force = force * autocvar_g_balance_powerup_strength_selfforce;
824 damage = damage * autocvar_g_balance_powerup_strength_damage;
825 force = force * autocvar_g_balance_powerup_strength_force;
829 // apply invincibility multiplier
830 if (targ.items & ITEM_Shield.m_itemid)
831 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
834 if (targ == attacker)
835 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
840 if(deathtype != DEATH_BUFF)
841 if(targ.takedamage == DAMAGE_AIM)
845 if(IS_VEHICLE(targ) && targ.owner)
850 if(IS_PLAYER(victim) || (IS_TURRET(victim) && victim.active == ACTIVE_ACTIVE) || IS_MONSTER(victim) || MUTATOR_CALLHOOK(PlayHitsound, victim))
852 if(DIFF_TEAM(victim, attacker) && !victim.frozen)
856 if(deathtype != DEATH_FIRE)
858 if(victim.BUTTON_CHAT)
859 attacker.typehitsound += 1;
861 attacker.damage_dealt += damage;
864 damage_goodhits += 1;
865 damage_gooddamage += damage;
867 if (!DEATH_ISSPECIAL(deathtype))
869 if(IS_PLAYER(targ)) // don't do this for vehicles
877 if(deathtype != DEATH_FIRE)
879 attacker.typehitsound += 1;
881 if(complainteamdamage > 0)
882 if(time > attacker.teamkill_complain)
884 attacker.teamkill_complain = time + 5;
885 attacker.teamkill_soundtime = time + 0.4;
886 attacker.teamkill_soundsource = targ;
894 if (self.damageforcescale)
896 if (!IS_PLAYER(self) || time >= self.spawnshieldtime || self == attacker)
898 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
899 if(self.movetype == MOVETYPE_PHYSICS)
903 farcent.classname = "farce";
904 farcent.enemy = self;
905 farcent.movedir = farce * 10;
907 farcent.movedir = farcent.movedir * self.mass;
908 farcent.origin = hitloc;
909 farcent.forcetype = FORCETYPE_FORCEATPOS;
910 farcent.nextthink = time + 0.1;
911 farcent.think = SUB_Remove;
915 self.velocity = self.velocity + farce;
916 self.move_velocity = self.velocity;
918 self.flags &= ~FL_ONGROUND;
919 self.move_flags &= ~FL_ONGROUND;
920 UpdateCSQCProjectile(self);
923 if (damage != 0 || (self.damageforcescale && vlen(force)))
924 if (self.event_damage)
925 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
928 // apply mirror damage if any
929 if(mirrordamage > 0 || mirrorforce > 0)
931 attacker = attacker_save;
933 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
934 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
938 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)
939 // Returns total damage applies to creatures
943 float total_damage_to_creatures;
948 float stat_damagedone;
950 if(RadiusDamage_running)
952 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
956 RadiusDamage_running = 1;
958 tfloordmg = autocvar_g_throughfloor_damage;
959 tfloorforce = autocvar_g_throughfloor_force;
961 total_damage_to_creatures = 0;
963 if(deathtype != (WEP_HOOK.m_id | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
964 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA.m_id) // do not send tuba damage (bandwidth hog)
966 force = inflictorvelocity;
970 force = normalize(force);
971 if(forceintensity >= 0)
972 Damage_DamageInfo(inflictororigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
974 Damage_DamageInfo(inflictororigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
979 targ = WarpZone_FindRadius (inflictororigin, rad + MAX_DAMAGEEXTRARADIUS, false);
983 if ((targ != inflictor) || inflictorselfdamage)
984 if (((cantbe != targ) && !mustbe) || (mustbe == targ))
991 // LordHavoc: measure distance to nearest point on target (not origin)
992 // (this guarentees 100% damage on a touch impact)
993 nearest = targ.WarpZone_findradius_nearest;
994 diff = targ.WarpZone_findradius_dist;
995 // round up a little on the damage to ensure full damage on impacts
996 // and turn the distance into a fraction of the radius
997 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
999 //bprint(ftos(power));
1000 //if (targ == attacker)
1001 // print(ftos(power), "\n");
1007 finaldmg = coredamage * power + edgedamage * (1 - power);
1013 vector myblastorigin;
1016 myblastorigin = WarpZone_TransformOrigin(targ, inflictororigin);
1018 // if it's a player, use the view origin as reference
1019 center = CENTER_OR_VIEWOFS(targ);
1021 force = normalize(center - myblastorigin);
1022 force = force * (finaldmg / coredamage) * forceintensity;
1025 if(deathtype & WEP_BLASTER.m_id)
1026 force *= WEP_CVAR_BOTH(blaster, !(deathtype & HITTYPE_SECONDARY), force_zscale);
1028 if(targ != directhitentity)
1033 float mininv_f, mininv_d;
1035 // test line of sight to multiple positions on box,
1036 // and do damage if any of them hit
1039 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
1040 // so for a given max stddev:
1041 // n = (1 / (2 * max stddev of hitratio))^2
1043 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
1044 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
1046 if(autocvar_g_throughfloor_debug)
1047 LOG_INFOF("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f);
1050 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
1052 if(autocvar_g_throughfloor_debug)
1053 LOG_INFOF(" steps=%f", total);
1056 if (IS_PLAYER(targ))
1057 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
1059 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1061 if(autocvar_g_throughfloor_debug)
1062 LOG_INFOF(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total)));
1064 for(c = 0; c < total; ++c)
1066 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1067 WarpZone_TraceLine(inflictororigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1068 if (trace_fraction == 1 || trace_ent == targ)
1072 hitloc = hitloc + nearest;
1076 nearest.x = targ.origin.x + targ.mins.x + random() * targ.size.x;
1077 nearest.y = targ.origin.y + targ.mins.y + random() * targ.size.y;
1078 nearest.z = targ.origin.z + targ.mins.z + random() * targ.size.z;
1081 nearest = hitloc * (1 / max(1, hits));
1082 hitratio = (hits / total);
1083 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1084 finaldmg = finaldmg * a;
1085 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1088 if(autocvar_g_throughfloor_debug)
1089 LOG_INFOF(" D=%f F=%f\n", finaldmg, vlen(force));
1092 //if (targ == attacker)
1094 // print("hits ", ftos(hits), " / ", ftos(total));
1095 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1096 // print(" (", ftos(a), ")\n");
1098 if(finaldmg || vlen(force))
1102 total_damage_to_creatures += finaldmg;
1104 if(accuracy_isgooddamage(attacker, targ))
1105 stat_damagedone += finaldmg;
1108 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1109 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1111 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1119 RadiusDamage_running = 0;
1121 if(!DEATH_ISSPECIAL(deathtype))
1122 accuracy_add(attacker, DEATH_WEAPONOF(deathtype), 0, min(coredamage, stat_damagedone));
1124 return total_damage_to_creatures;
1127 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, int deathtype, entity directhitentity)
1129 return RadiusDamageForSource (inflictor, (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5), inflictor.velocity, attacker, coredamage, edgedamage, rad, cantbe, mustbe, false, forceintensity, deathtype, directhitentity);
1132 float Fire_IsBurning(entity e)
1134 return (time < e.fire_endtime);
1137 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1140 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1151 // print("adding a fire burner to ", e.classname, "\n");
1152 e.fire_burner = spawn();
1153 e.fire_burner.classname = "fireburner";
1154 e.fire_burner.think = fireburner_think;
1155 e.fire_burner.nextthink = time;
1156 e.fire_burner.owner = e;
1162 if(Fire_IsBurning(e))
1164 mintime = e.fire_endtime - time;
1165 maxtime = max(mintime, t);
1167 mindps = e.fire_damagepersec;
1168 maxdps = max(mindps, dps);
1170 if(maxtime > mintime || maxdps > mindps)
1174 // damage we have right now
1175 mindamage = mindps * mintime;
1177 // damage we want to get
1178 maxdamage = mindamage + d;
1180 // but we can't exceed maxtime * maxdps!
1181 totaldamage = min(maxdamage, maxtime * maxdps);
1185 // totaldamage = min(mindamage + d, maxtime * maxdps)
1187 // totaldamage <= maxtime * maxdps
1188 // ==> totaldamage / maxdps <= maxtime.
1190 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1191 // >= min(mintime, maxtime)
1192 // ==> totaldamage / maxdps >= mintime.
1195 // how long do we damage then?
1196 // at least as long as before
1197 // but, never exceed maxdps
1198 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1202 // at most as long as maximum allowed
1203 // but, never below mindps
1204 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1206 // assuming t > mintime, dps > mindps:
1207 // we get d = t * dps = maxtime * maxdps
1208 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1209 // totaldamage / maxdps = maxtime
1210 // totaldamage / mindps > totaldamage / maxdps = maxtime
1212 // a) totaltime = max(mintime, maxtime) = maxtime
1213 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1215 // assuming t <= mintime:
1216 // we get maxtime = mintime
1217 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1218 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1220 // assuming dps <= mindps:
1221 // we get mindps = maxdps.
1222 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1223 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1224 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1226 e.fire_damagepersec = totaldamage / totaltime;
1227 e.fire_endtime = time + totaltime;
1228 if(totaldamage > 1.2 * mindamage)
1230 e.fire_deathtype = dt;
1231 if(e.fire_owner != o)
1234 e.fire_hitsound = false;
1237 if(accuracy_isgooddamage(o, e))
1238 accuracy_add(o, DEATH_WEAPONOF(dt), 0, max(0, totaldamage - mindamage));
1239 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1246 e.fire_damagepersec = dps;
1247 e.fire_endtime = time + t;
1248 e.fire_deathtype = dt;
1250 e.fire_hitsound = false;
1251 if(accuracy_isgooddamage(o, e))
1252 accuracy_add(o, DEATH_WEAPONOF(dt), 0, d);
1257 void Fire_ApplyDamage(entity e)
1262 if (!Fire_IsBurning(e))
1265 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1266 if(IS_NOT_A_CLIENT(o))
1269 // water and slime stop fire
1271 if(e.watertype != CONTENT_LAVA)
1278 t = min(frametime, e.fire_endtime - time);
1279 d = e.fire_damagepersec * t;
1281 hi = e.fire_owner.damage_dealt;
1282 ty = e.fire_owner.typehitsound;
1283 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1284 if(e.fire_hitsound && e.fire_owner)
1286 e.fire_owner.damage_dealt = hi;
1287 e.fire_owner.typehitsound = ty;
1289 e.fire_hitsound = true;
1291 if (!IS_INDEPENDENT_PLAYER(e))
1293 FOR_EACH_PLAYER(other) if(e != other)
1295 if(IS_PLAYER(other))
1296 if(other.deadflag == DEAD_NO)
1297 if (!IS_INDEPENDENT_PLAYER(other))
1298 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1300 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1301 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1302 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1307 void Fire_ApplyEffect(entity e)
1309 if(Fire_IsBurning(e))
1310 e.effects |= EF_FLAME;
1312 e.effects &= ~EF_FLAME;
1315 void fireburner_think()
1317 // for players, this is done in the regular loop
1318 if(wasfreed(self.owner))
1323 Fire_ApplyEffect(self.owner);
1324 if(!Fire_IsBurning(self.owner))
1326 self.owner.fire_burner = world;
1330 Fire_ApplyDamage(self.owner);
1331 self.nextthink = time;