]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/weapon/hook.qc
s/(void)/()
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / hook.qc
index b0b8b8b3f11dcd9ffaabad70b52c4c3e73ab8033..4e3722f138032c5aefbe1512923864901c48bbf7 100644 (file)
@@ -13,10 +13,23 @@ CLASS(Hook, Weapon)
 /* 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"));
+/* wepname   */ ATTRIB(Hook, m_name, string, _("Grappling Hook"));
+       ATTRIB(Hook, ammo_factor, float, 1)
 ENDCLASS(Hook)
 REGISTER_WEAPON(HOOK, NEW(Hook));
 
+CLASS(OffhandHook, OffhandWeapon)
+#ifdef SVQC
+    METHOD(OffhandHook, offhand_think, void(OffhandHook this, entity actor, bool key_pressed))
+    {
+       Weapon wep = WEP_HOOK;
+       .entity weaponentity = weaponentities[1];
+       wep.wr_think(wep, actor, weaponentity, key_pressed ? 1 : 0);
+    }
+#endif
+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) \
        w_cvar(id, sn, BOTH, animtime) \
@@ -61,18 +74,9 @@ HOOK_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
 #ifdef IMPLEMENTATION
 #ifdef SVQC
 
-void spawnfunc_weapon_hook(void)
-{SELFPARAM();
-       if(g_grappling_hook) // offhand hook
-       {
-               startitem_failed = true;
-               remove(self);
-               return;
-       }
-       weapon_defaultspawnfunc(WEP_HOOK.m_id);
-}
+spawnfunc(weapon_hook) { weapon_defaultspawnfunc(this, WEP_HOOK); }
 
-void W_Hook_ExplodeThink(void)
+void W_Hook_ExplodeThink()
 {SELFPARAM();
        float dt, dmg_remaining_next, f;
 
@@ -92,7 +96,7 @@ void W_Hook_ExplodeThink(void)
                remove(self);
 }
 
-void W_Hook_Explode2(void)
+void W_Hook_Explode2()
 {SELFPARAM();
        self.event_damage = func_null;
        self.touch = func_null;
@@ -125,22 +129,19 @@ void W_Hook_Damage(entity inflictor, entity attacker, float damage, int deathtyp
                W_PrepareExplosionByDamage(self.realowner, W_Hook_Explode2);
 }
 
-void W_Hook_Touch2(void)
+void W_Hook_Touch2()
 {SELFPARAM();
        PROJECTILE_TOUCH;
        self.use();
 }
 
-void W_Hook_Attack2(void)
-{SELFPARAM();
-       entity gren;
-
-       //W_DecreaseAmmo(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));
+void W_Hook_Attack2(Weapon thiswep, entity actor)
+{
+       //W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb)
+       W_SetupShot(actor, false, 4, SND(HOOKBOMB_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(hook, damage));
 
-       gren = spawn();
-       gren.owner = gren.realowner = self;
-       gren.classname = "hookbomb";
+       entity gren = new(hookbomb);
+       gren.owner = gren.realowner = actor;
        gren.bot_dodge = true;
        gren.bot_dodgerating = WEP_CVAR_SEC(hook, damage);
        gren.movetype = MOVETYPE_TOSS;
@@ -162,8 +163,8 @@ void W_Hook_Attack2(void)
        gren.missile_flags = MIF_SPLASH | MIF_ARC;
 
        gren.velocity = '0 0 1' * WEP_CVAR_SEC(hook, speed);
-       if(autocvar_g_projectiles_newton_style)
-               gren.velocity = gren.velocity + self.velocity;
+       if (autocvar_g_projectiles_newton_style)
+               gren.velocity = gren.velocity + actor.velocity;
 
        gren.gravity = WEP_CVAR_SEC(hook, gravity);
        //W_SetupProjVelocity_Basic(gren); // just falling down!
@@ -173,76 +174,73 @@ void W_Hook_Attack2(void)
 
        CSQCProjectile(gren, true, PROJECTILE_HOOKBOMB, true);
 
-       MUTATOR_CALLHOOK(EditProjectile, self, gren);
+       MUTATOR_CALLHOOK(EditProjectile, actor, gren);
 }
 
-               METHOD(Hook, wr_aim, bool(entity thiswep))
-               {
-                       // no bot AI for hook (yet?)
-                       return true;
-               }
-               METHOD(Hook, wr_think, bool(entity thiswep))
+               METHOD(Hook, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
                {
-                       if(self.BUTTON_ATCK || self.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 (fire & 1) {
+                               if(!actor.hook)
+                               if(!(actor.hook_state & HOOK_WAITING_FOR_RELEASE))
+                               if(time > actor.hook_refire)
+                               if(weapon_prepareattack(thiswep, actor, weaponentity, 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, thiswep.ammo_factor * WEP_CVAR_PRI(hook, ammo));
+                                       actor.hook_state |= HOOK_FIRING;
+                                       actor.hook_state |= HOOK_WAITING_FOR_RELEASE;
+                                       weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready);
                                }
+                       } else {
+                               actor.hook_state |= HOOK_REMOVING;
+                               actor.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
                        }
 
-                       if(self.BUTTON_ATCK2)
+                       if(fire & 2)
                        {
-                               if(weapon_prepareattack(1, WEP_CVAR_SEC(hook, refire)))
+                               if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hook, refire)))
                                {
-                                       W_Hook_Attack2();
-                                       weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(hook, animtime), w_ready);
+                                       W_Hook_Attack2(thiswep, actor);
+                                       weapon_thinkf(actor, weaponentity, 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)
                        {
                                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;
                                }
 
-                               float hooked_fuel = WEP_CVAR_PRI(hook, hooked_ammo);
+                               float hooked_fuel = thiswep.ammo_factor * 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));
                                                        }
                                                }
                                        }
@@ -250,75 +248,63 @@ void W_Hook_Attack2(void)
                        }
                        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)
+                       actor.hook_state = BITSET(actor.hook_state, HOOK_PULLING, (!actor.BUTTON_CROUCH || !autocvar_g_balance_grapplehook_crouchslide));
+
+                       if (actor.hook_state & HOOK_FIRING)
                        {
-                               self.hook_state &= ~HOOK_PULLING;
-                               if(self.BUTTON_ATCK || self.BUTTON_HOOK)
-                                       self.hook_state &= ~HOOK_RELEASING;
-                               else
-                                       self.hook_state |= HOOK_RELEASING;
+                               if (actor.hook)
+                                       RemoveGrapplingHook(actor);
+                               WITH(entity, self, actor, FireGrapplingHook());
+                               actor.hook_state &= ~HOOK_FIRING;
+                               actor.hook_refire = max(actor.hook_refire, time + autocvar_g_balance_grapplehook_refire * W_WeaponRateFactor());
                        }
-                       else
+                       else if (actor.hook_state & HOOK_REMOVING)
                        {
-                               self.hook_state |= HOOK_PULLING;
-                               self.hook_state &= ~HOOK_RELEASING;
-
-                               if(self.BUTTON_ATCK || self.BUTTON_HOOK)
-                               {
-                                       // already fired
-                                       if(self.hook)
-                                               self.hook_state |= HOOK_WAITING_FOR_RELEASE;
-                               }
-                               else
-                               {
-                                       self.hook_state |= HOOK_REMOVING;
-                                       self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
-                               }
+                               if (actor.hook)
+                                       RemoveGrapplingHook(actor);
+                               actor.hook_state &= ~HOOK_REMOVING;
                        }
-
-                       return true;
                }
-               METHOD(Hook, wr_init, bool(entity thiswep))
+               METHOD(Hook, wr_init, void(entity thiswep))
                {
                        HOOK_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
-                       return true;
                }
-               METHOD(Hook, wr_setup, bool(entity thiswep))
+               METHOD(Hook, wr_setup, void(entity thiswep))
                {
                        self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
-                       return true;
                }
-               METHOD(Hook, wr_checkammo1, bool(entity thiswep))
+               METHOD(Hook, wr_checkammo1, bool(Hook thiswep))
                {
+                       if (!thiswep.ammo_factor) return true;
                        if(self.hook)
                                return self.ammo_fuel > 0;
                        else
                                return self.ammo_fuel >= WEP_CVAR_PRI(hook, ammo);
                }
-               METHOD(Hook, wr_checkammo2, bool(entity thiswep))
+               METHOD(Hook, wr_checkammo2, bool(Hook thiswep))
                {
                        // infinite ammo for now
                        return true; // self.ammo_cells >= WEP_CVAR_SEC(hook, ammo); // WEAPONTODO: see above
                }
-               METHOD(Hook, wr_config, bool(entity thiswep))
+               METHOD(Hook, wr_config, void(entity thiswep))
                {
                        HOOK_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
-                       return true;
                }
-               METHOD(Hook, wr_resetplayer, bool(entity thiswep))
+               METHOD(Hook, wr_resetplayer, void(entity thiswep))
                {
+                       RemoveGrapplingHook(self);
+                       self.hook_time = 0;
                        self.hook_refire = time;
-                       return true;
                }
-               METHOD(Hook, wr_suicidemessage, bool(entity thiswep))
+               METHOD(Hook, wr_suicidemessage, int(entity thiswep))
                {
                        return false;
                }
-               METHOD(Hook, wr_killmessage, bool(entity thiswep))
+               METHOD(Hook, wr_killmessage, int(entity thiswep))
                {
                        return WEAPON_HOOK_MURDER;
                }
@@ -326,24 +312,13 @@ void W_Hook_Attack2(void)
 #endif
 #ifdef CSQC
 
-               METHOD(Hook, wr_impacteffect, bool(entity thiswep))
+               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);
+                       pointparticles(EFFECT_HOOK_EXPLODE, org2, '0 0 0', 1);
                        if(!w_issilent)
                                sound(self, CH_SHOTS, SND_HOOKBOMB_IMPACT, VOL_BASE, ATTN_NORM);
-
-                       return true;
-               }
-               METHOD(Hook, wr_init, bool(entity thiswep))
-               {
-                       return true;
-               }
-               METHOD(Hook, wr_zoomreticle, bool(entity thiswep))
-               {
-                       // no weapon specific image for this weapon
-                       return false;
                }
 
 #endif