]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/weapon/hook.qc
Merge branch 'master' into TimePath/unified_weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / hook.qc
index 6c1f82fdf8561a6ed83387731cbbbb89bbe64343..9d5eb29ec844ce85ff71fd2a8de16a6681da2c5d 100644 (file)
@@ -1,19 +1,30 @@
 #ifndef IMPLEMENTATION
-REGISTER_WEAPON(
-/* WEP_##id  */ HOOK,
-/* function  */ W_Hook,
-/* ammotype  */ ammo_fuel,
-/* impulse   */ 0,
-/* flags     */ WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH,
-/* rating    */ 0,
-/* color     */ '0 0.5 0',
-/* modelname */ "hookgun",
-/* simplemdl */ "foobar",
-/* crosshair */ "gfx/crosshairhook 0.5",
-/* wepimg    */ "weaponhook",
-/* refname   */ "hook",
-/* wepname   */ _("Grappling Hook")
-);
+CLASS(Hook, Weapon)
+/* ammotype  */ ATTRIB(Hook, ammo_field, .int, ammo_fuel)
+/* impulse   */ ATTRIB(Hook, impulse, int, 0)
+/* flags     */ ATTRIB(Hook, spawnflags, int, WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
+/* rating    */ ATTRIB(Hook, bot_pickupbasevalue, float, 0);
+/* color     */ ATTRIB(Hook, wpcolor, vector, '0 0.5 0');
+/* modelname */ ATTRIB(Hook, mdl, string, "hookgun");
+#ifndef MENUQC
+/* model     */ ATTRIB(Hook, m_model, Model, MDL_HOOK_ITEM);
+#endif
+/* crosshair */ ATTRIB(Hook, w_crosshair, string, "gfx/crosshairhook");
+/* crosshair */ ATTRIB(Hook, w_crosshair_size, float, 0.5);
+/* wepimg    */ ATTRIB(Hook, model2, string, "weaponhook");
+/* refname   */ ATTRIB(Hook, netname, string, "hook");
+/* wepname   */ ATTRIB(Hook, message, string, _("Grappling Hook"));
+ENDCLASS(Hook)
+REGISTER_WEAPON(HOOK, NEW(Hook));
+
+CLASS(OffhandHook, OffhandWeapon)
+    METHOD(OffhandHook, offhand_think, void(OffhandHook this, entity player, bool key_pressed))
+    {
+       Weapon wep = WEP_HOOK;
+       WITH(entity, self, player, wep.wr_think(wep, self, key_pressed, false));
+    }
+ENDCLASS(OffhandHook)
+OffhandHook OFFHAND_HOOK; STATIC_INIT(OFFHAND_HOOK) { OFFHAND_HOOK = NEW(OffhandHook); }
 
 #define HOOK_SETTINGS(w_cvar,w_prop) HOOK_SETTINGS_LIST(w_cvar, w_prop, HOOK, hook)
 #define HOOK_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
@@ -59,16 +70,7 @@ HOOK_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
 #ifdef IMPLEMENTATION
 #ifdef SVQC
 
-spawnfunc(weapon_hook)
-{
-       if(g_grappling_hook) // offhand hook
-       {
-               startitem_failed = true;
-               remove(self);
-               return;
-       }
-       weapon_defaultspawnfunc(WEP_HOOK.m_id);
-}
+spawnfunc(weapon_hook) { weapon_defaultspawnfunc(WEP_HOOK.m_id); }
 
 void W_Hook_ExplodeThink(void)
 {SELFPARAM();
@@ -129,11 +131,11 @@ void W_Hook_Touch2(void)
        self.use();
 }
 
-void W_Hook_Attack2(void)
+void W_Hook_Attack2(Weapon thiswep)
 {SELFPARAM();
        entity gren;
 
-       //W_DecreaseAmmo(WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb)
+       //W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb)
        W_SetupShot(self, false, 4, SND(HOOKBOMB_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(hook, damage));
 
        gren = spawn();
@@ -174,79 +176,68 @@ void W_Hook_Attack2(void)
        MUTATOR_CALLHOOK(EditProjectile, self, gren);
 }
 
-bool W_Hook(int req)
-{SELFPARAM();
-       float hooked_time_max, hooked_fuel;
-
-       switch(req)
-       {
-               case WR_AIM:
+               METHOD(Hook, wr_think, void(entity thiswep, entity actor, bool fire1, bool fire2))
                {
-                       // no bot AI for hook (yet?)
-                       return true;
-               }
-               case WR_THINK:
-               {
-                       if(self.BUTTON_ATCK || self.BUTTON_HOOK)
+                       if(fire1 || actor.BUTTON_HOOK)
                        {
-                               if(!self.hook)
-                               if(!(self.hook_state & HOOK_WAITING_FOR_RELEASE))
-                               if(!(self.hook_state & HOOK_FIRING))
-                               if(time > self.hook_refire)
-                               if(weapon_prepareattack(0, -1))
+                               if(!actor.hook)
+                               if(!(actor.hook_state & HOOK_WAITING_FOR_RELEASE))
+                               if(!(actor.hook_state & HOOK_FIRING))
+                               if(time > actor.hook_refire)
+                               if(weapon_prepareattack(actor, false, -1))
                                {
-                                       W_DecreaseAmmo(WEP_CVAR_PRI(hook, ammo));
-                                       self.hook_state |= HOOK_FIRING;
-                                       weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready);
+                                       W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(hook, ammo));
+                                       actor.hook_state |= HOOK_FIRING;
+                                       weapon_thinkf(actor, WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready);
                                }
                        }
 
-                       if(self.BUTTON_ATCK2)
+                       if(fire2)
                        {
-                               if(weapon_prepareattack(1, WEP_CVAR_SEC(hook, refire)))
+                               if(weapon_prepareattack(actor, true, WEP_CVAR_SEC(hook, refire)))
                                {
-                                       W_Hook_Attack2();
-                                       weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(hook, animtime), w_ready);
+                                       W_Hook_Attack2(thiswep);
+                                       weapon_thinkf(actor, WFRAME_FIRE2, WEP_CVAR_SEC(hook, animtime), w_ready);
                                }
                        }
 
-                       if(self.hook)
+                       if(actor.hook)
                        {
                                // if hooked, no bombs, and increase the timer
-                               self.hook_refire = max(self.hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor());
+                               actor.hook_refire = max(actor.hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor());
 
                                // hook also inhibits health regeneration, but only for 1 second
-                               if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
-                                       self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
+                               if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
+                                       actor.pauseregen_finished = max(actor.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
                        }
 
-                       if(self.hook && self.hook.state == 1)
+                       if(actor.hook && actor.hook.state == 1)
                        {
-                               hooked_time_max = WEP_CVAR_PRI(hook, hooked_time_max);
+                               float hooked_time_max = WEP_CVAR_PRI(hook, hooked_time_max);
                                if(hooked_time_max > 0)
                                {
-                                       if( time > self.hook_time_hooked + hooked_time_max )
-                                               self.hook_state |= HOOK_REMOVING;
+                                       if( time > actor.hook_time_hooked + hooked_time_max )
+                                               actor.hook_state |= HOOK_REMOVING;
                                }
 
-                               hooked_fuel = WEP_CVAR_PRI(hook, hooked_ammo);
+                               float hooked_fuel = WEP_CVAR_PRI(hook, hooked_ammo);
                                if(hooked_fuel > 0)
                                {
-                                       if( time > self.hook_time_fueldecrease )
+                                       if( time > actor.hook_time_fueldecrease )
                                        {
-                                               if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
+                                               if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
                                                {
-                                                       if( self.ammo_fuel >= (time - self.hook_time_fueldecrease) * hooked_fuel )
+                                                       if( actor.ammo_fuel >= (time - actor.hook_time_fueldecrease) * hooked_fuel )
                                                        {
-                                                               W_DecreaseAmmo((time - self.hook_time_fueldecrease) * hooked_fuel);
-                                                               self.hook_time_fueldecrease = time;
+                                                               W_DecreaseAmmo(thiswep, actor, (time - actor.hook_time_fueldecrease) * hooked_fuel);
+                                                               actor.hook_time_fueldecrease = time;
                                                                // decrease next frame again
                                                        }
                                                        else
                                                        {
-                                                               self.ammo_fuel = 0;
-                                                               self.hook_state |= HOOK_REMOVING;
-                                                               W_SwitchWeapon_Force(self, w_getbestweapon(self));
+                                                               actor.ammo_fuel = 0;
+                                                               actor.hook_state |= HOOK_REMOVING;
+                                                               W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
                                                        }
                                                }
                                        }
@@ -254,108 +245,86 @@ bool W_Hook(int req)
                        }
                        else
                        {
-                               self.hook_time_hooked = time;
-                               self.hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free);
+                               actor.hook_time_hooked = time;
+                               actor.hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free);
                        }
 
-                       if(self.BUTTON_CROUCH)
+                       if(actor.BUTTON_CROUCH)
                        {
-                               self.hook_state &= ~HOOK_PULLING;
-                               if(self.BUTTON_ATCK || self.BUTTON_HOOK)
-                                       self.hook_state &= ~HOOK_RELEASING;
+                               actor.hook_state &= ~HOOK_PULLING;
+                               if(fire1 || actor.BUTTON_HOOK)
+                                       actor.hook_state &= ~HOOK_RELEASING;
                                else
-                                       self.hook_state |= HOOK_RELEASING;
+                                       actor.hook_state |= HOOK_RELEASING;
                        }
                        else
                        {
-                               self.hook_state |= HOOK_PULLING;
-                               self.hook_state &= ~HOOK_RELEASING;
+                               actor.hook_state |= HOOK_PULLING;
+                               actor.hook_state &= ~HOOK_RELEASING;
 
-                               if(self.BUTTON_ATCK || self.BUTTON_HOOK)
+                               if(fire1 || actor.BUTTON_HOOK)
                                {
                                        // already fired
-                                       if(self.hook)
-                                               self.hook_state |= HOOK_WAITING_FOR_RELEASE;
+                                       if(actor.hook)
+                                               actor.hook_state |= HOOK_WAITING_FOR_RELEASE;
                                }
                                else
                                {
-                                       self.hook_state |= HOOK_REMOVING;
-                                       self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
+                                       actor.hook_state |= HOOK_REMOVING;
+                                       actor.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
                                }
                        }
 
-                       return true;
+                       _GrapplingHookFrame();
                }
-               case WR_INIT:
+               METHOD(Hook, wr_init, void(entity thiswep))
                {
                        HOOK_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
-                       return true;
                }
-               case WR_SETUP:
+               METHOD(Hook, wr_setup, void(entity thiswep))
                {
                        self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
-                       return true;
                }
-               case WR_CHECKAMMO1:
+               METHOD(Hook, wr_checkammo1, bool(entity thiswep))
                {
                        if(self.hook)
                                return self.ammo_fuel > 0;
                        else
                                return self.ammo_fuel >= WEP_CVAR_PRI(hook, ammo);
                }
-               case WR_CHECKAMMO2:
+               METHOD(Hook, wr_checkammo2, bool(entity thiswep))
                {
                        // infinite ammo for now
                        return true; // self.ammo_cells >= WEP_CVAR_SEC(hook, ammo); // WEAPONTODO: see above
                }
-               case WR_CONFIG:
+               METHOD(Hook, wr_config, void(entity thiswep))
                {
                        HOOK_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
-                       return true;
                }
-               case WR_RESETPLAYER:
+               METHOD(Hook, wr_resetplayer, void(entity thiswep))
                {
                        self.hook_refire = time;
-                       return true;
                }
-               case WR_SUICIDEMESSAGE:
+               METHOD(Hook, wr_suicidemessage, int(entity thiswep))
                {
                        return false;
                }
-               case WR_KILLMESSAGE:
+               METHOD(Hook, wr_killmessage, int(entity thiswep))
                {
                        return WEAPON_HOOK_MURDER;
                }
-       }
-       return false;
-}
+
 #endif
 #ifdef CSQC
-bool W_Hook(int req)
-{SELFPARAM();
-       switch(req)
-       {
-               case WR_IMPACTEFFECT:
+
+               METHOD(Hook, wr_impacteffect, void(entity thiswep))
                {
                        vector org2;
                        org2 = w_org + w_backoff * 2;
                        pointparticles(particleeffectnum(EFFECT_HOOK_EXPLODE), org2, '0 0 0', 1);
                        if(!w_issilent)
                                sound(self, CH_SHOTS, SND_HOOKBOMB_IMPACT, VOL_BASE, ATTN_NORM);
-
-                       return true;
-               }
-               case WR_INIT:
-               {
-                       return true;
                }
-               case WR_ZOOMRETICLE:
-               {
-                       // no weapon specific image for this weapon
-                       return false;
-               }
-       }
-       return false;
-}
+
 #endif
 #endif