]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/g_damage.qc
Merge branch 'master' into TimePath/vehicles_cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_damage.qc
index 18d58f4eb9b374d38c3176f41f331bb5cea858fe..0721e885210de95188de6b70b6899864fafbc8d9 100644 (file)
@@ -1,34 +1,30 @@
 #include "g_damage.qh"
-
-#if defined(CSQC)
-#elif defined(MENUQC)
-#elif defined(SVQC)
-    #include "../warpzonelib/common.qh"
-    #include "../common/constants.qh"
-    #include "../common/buffs.qh"
-    #include "../common/teams.qh"
-    #include "../common/util.qh"
-    #include "../common/weapons/weapons.qh"
-    #include "weapons/accuracy.qh"
-    #include "weapons/csqcprojectile.qh"
-    #include "weapons/selection.qh"
-    #include "t_items.qh"
-    #include "autocvars.qh"
-    #include "constants.qh"
-    #include "defs.qh"
-    #include "../common/notifications.qh"
-    #include "../common/deathtypes.qh"
-    #include "mutators/mutators_include.qh"
-    #include "tturrets/include/turrets_early.qh"
-    #include "vehicles/vehicles_def.qh"
-    #include "../csqcmodellib/sv_model.qh"
-    #include "../common/playerstats.qh"
-    #include "g_hook.qh"
-    #include "scores.qh"
-    #include "spawnpoints.qh"
-#endif
-
-float Damage_DamageInfo_SendEntity(entity to, float sf)
+#include "_all.qh"
+
+#include "g_hook.qh"
+#include "mutators/mutators_include.qh"
+#include "scores.qh"
+#include "waypointsprites.qh"
+#include "spawnpoints.qh"
+#include "tturrets/include/turrets_early.qh"
+#include "t_items.qh"
+#include "../common/vehicles/all.qh"
+#include "weapons/accuracy.qh"
+#include "weapons/csqcprojectile.qh"
+#include "weapons/selection.qh"
+#include "../common/buffs.qh"
+#include "../common/constants.qh"
+#include "../common/deathtypes.qh"
+#include "../common/notifications.qh"
+#include "../common/movetypes/movetypes.qh"
+#include "../common/playerstats.qh"
+#include "../common/teams.qh"
+#include "../common/util.qh"
+#include "../common/weapons/all.qh"
+#include "../csqcmodellib/sv_model.qh"
+#include "../warpzonelib/common.qh"
+
+float Damage_DamageInfo_SendEntity(entity to, int sf)
 {
        WriteByte(MSG_ENTITY, ENT_CLIENT_DAMAGEINFO);
        WriteShort(MSG_ENTITY, self.projectiledeathtype);
@@ -43,7 +39,7 @@ float Damage_DamageInfo_SendEntity(entity to, float sf)
        return true;
 }
 
-void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, float bloodtype, entity dmgowner)
+void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, int deathtype, float bloodtype, entity dmgowner)
 {
        // TODO maybe call this from non-edgedamage too?
        // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
@@ -67,24 +63,12 @@ void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad
        Net_LinkEntity(e, false, 0.2, Damage_DamageInfo_SendEntity);
 }
 
-float IsFlying(entity a)
-{
-       if(a.flags & FL_ONGROUND)
-               return 0;
-       if(a.waterlevel >= WATERLEVEL_SWIMMING)
-               return 0;
-       traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
-       if(trace_fraction < 1)
-               return 0;
-       return 1;
-}
-
 void UpdateFrags(entity player, float f)
 {
        PlayerTeamScore_AddScore(player, f);
 }
 
-void GiveFrags (entity attacker, entity targ, float f, float deathtype)
+void GiveFrags (entity attacker, entity targ, float f, int deathtype)
 {
        // TODO route through PlayerScores instead
        if(gameover) return;
@@ -123,7 +107,7 @@ void GiveFrags (entity attacker, entity targ, float f, float deathtype)
                else if(!(attacker.weapons & WepSet_FromWeapon(culprit)))
                        culprit = attacker.weapon;
 
-               if(g_weaponarena_random_with_blaster && culprit == WEP_BLASTER) // WEAPONTODO: Shouldn't this be in a mutator?
+               if(g_weaponarena_random_with_blaster && culprit == WEP_BLASTER.m_id) // WEAPONTODO: Shouldn't this be in a mutator?
                {
                        // no exchange
                }
@@ -163,10 +147,7 @@ void GiveFrags (entity attacker, entity targ, float f, float deathtype)
        entity oldself;
        oldself = self;
        self = attacker;
-       frag_attacker = attacker;
-       frag_target = targ;
-       frag_score = f;
-       if(MUTATOR_CALLHOOK(GiveFragsForKill))
+       if(MUTATOR_CALLHOOK(GiveFragsForKill, attacker, targ, f))
        {
                f = frag_score;
                self = oldself;
@@ -204,7 +185,7 @@ string AppendItemcodes(string s, entity player)
        return s;
 }
 
-void LogDeath(string mode, float deathtype, entity killer, entity killed)
+void LogDeath(string mode, int deathtype, entity killer, entity killed)
 {
        string s;
        if(!autocvar_sv_eventlog)
@@ -226,7 +207,7 @@ void LogDeath(string mode, float deathtype, entity killer, entity killed)
 void Obituary_SpecialDeath(
        entity notif_target,
        float murder,
-       float deathtype,
+       int deathtype,
        string s1, string s2, string s3,
        float f1, float f2, float f3)
 {
@@ -286,7 +267,7 @@ void Obituary_SpecialDeath(
 float Obituary_WeaponDeath(
        entity notif_target,
        float murder,
-       float deathtype,
+       int deathtype,
        string s1, string s2, string s3,
        float f1, float f2)
 {
@@ -294,10 +275,10 @@ float Obituary_WeaponDeath(
        if(death_weapon)
        {
                w_deathtype = deathtype;
-               float death_message = WEP_ACTION(death_weapon, ((murder) ? WR_KILLMESSAGE : WR_SUICIDEMESSAGE));
+               int death_message = WEP_ACTION(death_weapon, ((murder) ? WR_KILLMESSAGE : WR_SUICIDEMESSAGE));
                w_deathtype = false;
 
-               if(death_message)
+               if (death_message)
                {
                        Send_Notification_WOCOVA(
                                NOTIF_ONE,
@@ -330,7 +311,7 @@ float Obituary_WeaponDeath(
        return false;
 }
 
-void Obituary(entity attacker, entity inflictor, entity targ, float deathtype)
+void Obituary(entity attacker, entity inflictor, entity targ, int deathtype)
 {
        // Sanity check
        if (!IS_PLAYER(targ)) { backtrace("Obituary called on non-player?!\n"); return; }
@@ -573,13 +554,13 @@ void Ice_Think()
 
 void Freeze (entity targ, float freeze_time, float frozen_type, float show_waypoint)
 {
-       if(!IS_PLAYER(targ) && !(targ.flags & FL_MONSTER)) // only specified entities can be freezed
+       if(!IS_PLAYER(targ) && !IS_MONSTER(targ)) // only specified entities can be freezed
                return;
 
        if(targ.frozen)
                return;
 
-       float targ_maxhealth = ((targ.flags & FL_MONSTER) ? targ.max_health : start_health);
+       float targ_maxhealth = ((IS_MONSTER(targ)) ? targ.max_health : start_health);
 
        targ.frozen = frozen_type;
        targ.revive_progress = ((frozen_type == 3) ? 1 : 0);
@@ -640,7 +621,7 @@ void Unfreeze (entity targ)
        targ.iceblock = world;
 }
 
-void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
+void Damage (entity targ, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
 {
        float mirrordamage;
        float mirrorforce;
@@ -667,7 +648,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                                        RemoveGrapplingHook(targ); // STOP THAT, you parasite!
 
        // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
-       if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
+       if(DEATH_ISWEAPON(deathtype, WEP_HOOK.m_id) || DEATH_ISWEAPON(deathtype, WEP_TUBA.m_id))
        {
                if(IS_PLAYER(targ))
                        if(SAME_TEAM(targ, attacker))
@@ -681,7 +662,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
        {
                // exit the vehicle before killing (fixes a crash)
                if(IS_PLAYER(targ) && targ.vehicle)
-                       vehicles_exit(VHEF_RELESE);
+                       vehicles_exit(VHEF_RELEASE);
 
                // These are ALWAYS lethal
                // No damage modification here
@@ -765,13 +746,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                }
 
                // should this be changed at all? If so, in what way?
-               frag_attacker = attacker;
-               frag_target = targ;
-               frag_damage = damage;
-               frag_force = force;
-               frag_deathtype = deathtype;
-               frag_mirrordamage = mirrordamage;
-               MUTATOR_CALLHOOK(PlayerDamage_Calculate);
+               MUTATOR_CALLHOOK(PlayerDamage_Calculate, attacker, targ, deathtype, damage, mirrordamage, force);
                damage = frag_damage;
                mirrordamage = frag_mirrordamage;
                force = frag_force;
@@ -785,7 +760,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                        {
                                Unfreeze(targ);
                                targ.health = autocvar_g_freezetag_revive_falldamage_health;
-                               pointparticles(particleeffectnum("iceorglass"), targ.origin, '0 0 0', 3);
+                               Send_Effect("iceorglass", targ.origin, '0 0 0', 3);
                                Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_FALL, targ.netname);
                                Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
                        }
@@ -796,7 +771,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
 
                if(targ.frozen && deathtype == DEATH_HURTTRIGGER && !autocvar_g_freezetag_frozen_damage_trigger)
                {
-                       pointparticles(particleeffectnum("teleport"), targ.origin, '0 0 0', 1);
+                       Send_Effect("teleport", targ.origin, '0 0 0', 1);
 
                        entity oldself = self;
                        self = targ;
@@ -826,7 +801,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                                self.oldorigin = self.origin;
                                self.prevorigin = self.origin;
 
-                               pointparticles(particleeffectnum("teleport"), self.origin, '0 0 0', 1);
+                               Send_Effect("teleport", self.origin, '0 0 0', 1);
                        }
 
                        self = oldself;
@@ -835,7 +810,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                if(!g_instagib)
                {
                        // apply strength multiplier
-                       if (attacker.items & IT_STRENGTH)
+                       if (attacker.items & ITEM_Strength.m_itemid)
                        {
                                if(targ == attacker)
                                {
@@ -850,7 +825,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                        }
 
                        // apply invincibility multiplier
-                       if (targ.items & IT_INVINCIBLE)
+                       if (targ.items & ITEM_Shield.m_itemid)
                                damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
                }
 
@@ -865,12 +840,12 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                if(targ != attacker)
                {
                        entity victim;
-                       if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
+                       if(IS_VEHICLE(targ) && targ.owner)
                                victim = targ.owner;
                        else
                                victim = targ;
 
-                       if(IS_PLAYER(victim) || (victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET) || (victim.flags & FL_MONSTER))
+                       if(IS_PLAYER(victim) || IS_TURRET(victim) || IS_MONSTER(victim) || MUTATOR_CALLHOOK(PlayHitsound, victim))
                        {
                                if(DIFF_TEAM(victim, attacker) && !victim.frozen)
                                {
@@ -934,8 +909,12 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                        farcent.think = SUB_Remove;
                }
                else
+               {
                        self.velocity = self.velocity + farce;
+                       self.move_velocity = self.velocity;
+               }
                self.flags &= ~FL_ONGROUND;
+               self.move_flags &= ~FL_ONGROUND;
                UpdateCSQCProjectile(self);
        }
        // apply damage
@@ -954,7 +933,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
        }
 }
 
-float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector inflictorvelocity, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float inflictorselfdamage, float forceintensity, float deathtype, entity directhitentity)
+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)
        // Returns total damage applies to creatures
 {
        entity  targ;
@@ -979,8 +958,8 @@ float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector in
 
        total_damage_to_creatures = 0;
 
-       if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
-               if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
+       if(deathtype != (WEP_HOOK.m_id | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
+               if(DEATH_WEAPONOF(deathtype) != WEP_TUBA.m_id) // do not send tuba damage (bandwidth hog)
                {
                        force = inflictorvelocity;
                        if(vlen(force) == 0)
@@ -1041,7 +1020,7 @@ float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector in
                                        force = force * (finaldmg / coredamage) * forceintensity;
                                        hitloc = nearest;
 
-                                       if(deathtype & WEP_BLASTER)
+                                       if(deathtype & WEP_BLASTER.m_id)
                                                force *= WEP_CVAR_BOTH(blaster, !(deathtype & HITTYPE_SECONDARY), force_zscale);
 
                                        if(targ != directhitentity)
@@ -1143,7 +1122,7 @@ float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector in
        return total_damage_to_creatures;
 }
 
-float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, float deathtype, entity directhitentity)
+float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, int deathtype, entity directhitentity)
 {
        return RadiusDamageForSource (inflictor, (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5), inflictor.velocity, attacker, coredamage, edgedamage, rad, cantbe, mustbe, false, forceintensity, deathtype, directhitentity);
 }