Better Grabber impact effects
[voretournament/voretournament.git] / data / qcsrc / server / w_grabber.qc
index 5a7e0e9..dbf470f 100644 (file)
@@ -1,5 +1,5 @@
 #ifdef REGISTER_WEAPON\r
-REGISTER_WEAPON(GRABBER, w_grabber, IT_FUEL, 0, WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, 0, "grabber", "grabber", "Grabber");\r
+REGISTER_WEAPON(GRABBER, w_grabber, IT_FUEL, 0, WEP_FLAG_CANCLIMB | WEP_TYPE_HITSCAN | WEP_FLAG_RELOADABLE, 0, "grabber", "grabber", "Grabber");\r
 #else\r
 .float dmg;\r
 .float dmg_edge;\r
@@ -9,6 +9,22 @@ REGISTER_WEAPON(GRABBER, w_grabber, IT_FUEL, 0, WEP_FLAG_CANCLIMB | WEP_TYPE_SPL
 .float grabber_time_grabbered;\r
 .float grabber_time_fueldecrease;\r
 \r
+void W_Grabber_UpdateStats(entity e, float shot, float hit)\r
+{\r
+       // this may not be entierly right, but for the time being we're handling grabber accuracy here\r
+       // this is likely needed for detecting if the hook has hit (linked to) another player, which is counted as a hit\r
+       if(shot)\r
+       {\r
+               e.stats_fired[e.weapon - 1] += 1;\r
+               e.stat_fired = e.weapon + 64 * floor(e.stats_fired[e.weapon - 1]);\r
+       }\r
+       if(hit)\r
+       {\r
+               e.stats_hit[e.weapon - 1] += 1;\r
+               e.stat_hit = e.weapon + 64 * floor(e.stats_hit[e.weapon - 1]);\r
+       }\r
+}\r
+\r
 void W_Grabber_Touch2 (void)\r
 {\r
        PROJECTILE_TOUCH;\r
@@ -17,17 +33,27 @@ void W_Grabber_Touch2 (void)
 \r
 void W_Grabber_Attack2()\r
 {\r
+       if(time < self.weapon_delay)\r
+               return;\r
+\r
        W_SetupShot (self, TRUE, 0, "weapons/grabber_altfire.wav", cvar("g_balance_grabber_secondary_damage"));\r
+       W_Grabber_UpdateStats(self, TRUE, FALSE); // the hit is recorded below\r
 \r
        WarpZone_traceline_antilag(self, w_shotorg, w_shotorg + w_shotdir * cvar("g_balance_grabber_secondary_radius"), FALSE, self, ANTILAG_LATENCY(self));\r
 \r
        pointparticles(particleeffectnum("grabber_melee"), w_shotorg + w_shotdir * cvar("g_balance_grabber_secondary_radius"), '0 0 0', 1);\r
 \r
        if (trace_fraction < 1)\r
+       {\r
                Damage(trace_ent, self, self, cvar("g_balance_grabber_secondary_damage"), WEP_GRABBER | HITTYPE_SECONDARY, trace_endpos, cvar("g_balance_grabber_secondary_force") * w_shotdir);\r
+               pointparticles(particleeffectnum("grabber_impact2"), trace_endpos, '0 0 0', 1);\r
+               W_Grabber_UpdateStats(self, FALSE, TRUE); // the shot is recorded above\r
+       }\r
 \r
-       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
-               self.ammo_fuel = self.ammo_fuel - cvar("g_balance_grabber_secondary_ammo");\r
+       if (!g_norecoil)\r
+               self.punchangle_x -= cvar("g_balance_grabber_secondary_recoil");\r
+\r
+       W_DecreaseAmmo(ammo_fuel, cvar("g_balance_grabber_secondary_ammo"), cvar("g_balance_grabber_reload_ammo"));\r
 }\r
 \r
 void spawnfunc_weapon_grabber (void)\r
@@ -37,12 +63,13 @@ void spawnfunc_weapon_grabber (void)
 \r
 float w_grabber(float req)\r
 {\r
-       if(self.eater.classname == "player") // we can't use weapons while in the stomach\r
+       if(self.stat_eaten) // we can't use weapons while in the stomach\r
        {\r
                self.grabber_state |= GRABBER_REMOVING;\r
                return FALSE;\r
        }\r
 \r
+       float ammo_amount;\r
        float grabbered_time_max, grabbered_fuel;\r
                \r
        if (req == WR_AIM)\r
@@ -51,30 +78,42 @@ float w_grabber(float req)
        }\r
        else if (req == WR_THINK)\r
        {\r
-               if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_JETPACK))\r
+               grabbered_fuel = cvar("g_balance_grabber_primary_grabbered_fuel");\r
+               // forced reload\r
+               if(cvar("g_balance_grabber_reload_ammo") && self.clip_load < min(cvar("g_balance_grabber_primary_ammo"), cvar("g_balance_grabber_secondary_ammo"))\r
+               && !(self.clip_load >= (time - self.grabber_time_fueldecrease) * grabbered_fuel && self.BUTTON_ATCK)) // not while hooked and still have ammo to stay hooked\r
                {\r
-                       if(time < self.weapon_delay)\r
-                               return FALSE;\r
-\r
-                       if(!self.grabber)\r
-                       if not(self.grabber_state & GRABBER_WAITING_FOR_RELEASE)\r
-                       if not(self.grabber_state & GRABBER_FIRING)\r
-                       if (time > self.grabber_refire)\r
-                       if (weapon_prepareattack(0, -1))\r
-                       {\r
-                               if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
-                                       self.ammo_fuel = self.ammo_fuel - cvar("g_balance_grabber_primary_ammo");\r
-                               self.grabber_state |= GRABBER_FIRING;\r
-                               weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_grabber_primary_animtime"), w_ready);                               \r
-                       }\r
+                       if(self.ammo_fuel >= 1) // we only have one weapon in VT, so nothing else to switch to if we're out of ammo\r
+                               weapon_action(self.weapon, WR_RELOAD);\r
                }\r
-\r
-               if (self.BUTTON_ATCK2)\r
+               else if not(self.clip_load < 0) // we're not currently reloading\r
                {\r
-                       if (weapon_prepareattack(1, cvar("g_balance_grabber_secondary_refire")))\r
+                       if (self.BUTTON_ATCK && weapon_action(self.weapon, WR_CHECKAMMO1))\r
+                       {\r
+                               if(time < self.weapon_delay)\r
+                                       return FALSE;\r
+\r
+                               if(!self.grabber)\r
+                               if not(self.grabber_state & GRABBER_WAITING_FOR_RELEASE)\r
+                               if not(self.grabber_state & GRABBER_FIRING)\r
+                               if (time > self.grabber_refire)\r
+                               if (weapon_prepareattack(0, -1))\r
+                               {\r
+                                       if (!g_norecoil)\r
+                                               self.punchangle_x -= cvar("g_balance_grabber_primary_recoil");\r
+                                       W_DecreaseAmmo(ammo_fuel, cvar("g_balance_grabber_primary_ammo"), cvar("g_balance_grabber_reload_ammo"));\r
+                                       self.grabber_state |= GRABBER_FIRING;\r
+                                       weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_grabber_primary_animtime"), w_ready);                               \r
+                               }\r
+                       }\r
+                       if (self.BUTTON_ATCK2 && weapon_action(self.weapon, WR_CHECKAMMO2))\r
                        {\r
-                               W_Grabber_Attack2();\r
-                               weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_grabber_secondary_animtime"), w_ready);\r
+                               if (weapon_prepareattack(1, cvar("g_balance_grabber_secondary_refire")))\r
+                               {\r
+                                       W_Grabber_Attack2();\r
+                                       weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_grabber_secondary_animtime"), w_ready);\r
+                                       sound (self, CHAN_WEAPON2, "weapons/grabber_swing.wav", VOL_BASE, ATTN_NORM);\r
+                               }\r
                        }\r
                }\r
 \r
@@ -85,7 +124,7 @@ float w_grabber(float req)
 \r
                        // grabber also inhibits health regeneration, but only for 1 second\r
                        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
-                               self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));\r
+                               self.pauseregenhealth_finished = max(self.pauseregenhealth_finished, time + cvar("g_balance_pause_fuel_regen"));\r
                }\r
 \r
                if(self.grabber && self.grabber.state == 1)\r
@@ -96,23 +135,27 @@ float w_grabber(float req)
                                if ( time > self.grabber_time_grabbered + grabbered_time_max )\r
                                        self.grabber_state |= GRABBER_REMOVING;\r
                        }\r
-                       \r
-                       grabbered_fuel = cvar("g_balance_grabber_primary_grabbered_fuel");\r
+\r
                        if (grabbered_fuel > 0)\r
                        {\r
                                if ( time > self.grabber_time_fueldecrease )\r
                                {\r
                                        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
                                        {\r
-                                               if ( self.ammo_fuel >= (time - self.grabber_time_fueldecrease) * grabbered_fuel )\r
+                                               float active_ammo;\r
+                                               if(cvar("g_balance_grabber_reload_ammo"))\r
+                                                       active_ammo = self.clip_load;\r
+                                               else\r
+                                                       active_ammo = self.ammo_fuel;\r
+\r
+                                               if (active_ammo >= (time - self.grabber_time_fueldecrease) * grabbered_fuel )\r
                                                {\r
-                                                       self.ammo_fuel -= (time - self.grabber_time_fueldecrease) * grabbered_fuel;\r
+                                                       W_DecreaseAmmo(ammo_fuel, (time - self.grabber_time_fueldecrease) * grabbered_fuel, cvar("g_balance_grabber_reload_ammo"));\r
                                                        self.grabber_time_fueldecrease = time;\r
                                                        // decrease next frame again\r
                                                }\r
                                                else\r
                                                {\r
-                                                       self.ammo_fuel = 0;\r
                                                        self.grabber_state |= GRABBER_REMOVING;\r
                                                        W_SwitchWeapon_Force(self, w_getbestweapon(self));\r
                                                }\r
@@ -129,7 +172,7 @@ float w_grabber(float req)
                if (self.BUTTON_CROUCH)\r
                {\r
                        self.grabber_state &~= GRABBER_PULLING;\r
-                       if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_JETPACK))\r
+                       if (self.BUTTON_ATCK)\r
                                self.grabber_state &~= GRABBER_RELEASING;\r
                        else\r
                                self.grabber_state |= GRABBER_RELEASING;\r
@@ -139,7 +182,7 @@ float w_grabber(float req)
                        self.grabber_state |= GRABBER_PULLING;\r
                        self.grabber_state &~= GRABBER_RELEASING;\r
 \r
-                       if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_JETPACK))\r
+                       if (self.BUTTON_ATCK)\r
                        {\r
                                // already fired\r
                                if(self.grabber)\r
@@ -156,26 +199,43 @@ float w_grabber(float req)
        {\r
                precache_model ("models/weapons/g_grabber.md3");\r
                precache_model ("models/weapons/v_grabber.md3");\r
-               precache_model ("models/weapons/h_grabber.dpm");\r
+               precache_model ("models/weapons/h_grabber.iqm");\r
                precache_sound ("weapons/grabber_impact.wav"); // done by g_grabber.qc\r
                precache_sound ("weapons/grabber_fire.wav");\r
                precache_sound ("weapons/grabber_altfire.wav");\r
+               precache_sound ("weapons/grabber_swing.wav");\r
+               precache_sound ("weapons/reload.wav");\r
        }\r
        else if (req == WR_SETUP)\r
        {\r
                weapon_setup(WEP_GRABBER);\r
                self.grabber_state &~= GRABBER_WAITING_FOR_RELEASE;\r
+               self.current_ammo = ammo_fuel;\r
        }\r
        else if (req == WR_CHECKAMMO1)\r
        {\r
                if(self.grabber)\r
-                       return self.ammo_fuel > 0;\r
+               {\r
+                       ammo_amount = self.ammo_fuel > 0;\r
+                       ammo_amount += self.weapon_load[WEP_GRABBER] > 0;\r
+               }\r
                else\r
-                       return self.ammo_fuel >= cvar("g_balance_grabber_primary_ammo");\r
+               {\r
+                       ammo_amount = self.ammo_fuel >= cvar("g_balance_grabber_primary_ammo");\r
+                       ammo_amount += self.weapon_load[WEP_GRABBER] >= cvar("g_balance_grabber_primary_ammo");\r
+               }\r
+               return ammo_amount;\r
        }\r
        else if (req == WR_CHECKAMMO2)\r
        {\r
-               return self.ammo_fuel >= cvar("g_balance_grabber_secondary_ammo");\r
+               ammo_amount = self.ammo_fuel >= cvar("g_balance_grabber_secondary_ammo");\r
+               ammo_amount += self.weapon_load[WEP_GRABBER] >= cvar("g_balance_grabber_secondary_ammo");\r
+               return ammo_amount;\r
+       }\r
+       else if (req == WR_RELOAD)\r
+       {\r
+               self.grabber_state |= GRABBER_REMOVING;\r
+               W_Reload(min(cvar("g_balance_grabber_primary_ammo"), cvar("g_balance_grabber_secondary_ammo")), cvar("g_balance_grabber_reload_ammo"), cvar("g_balance_grabber_reload_time"), "weapons/reload.wav");\r
        }\r
        else if (req == WR_SUICIDEMESSAGE)\r
                w_deathtypestring = "did the impossible";\r