]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/weapon/hook.qc
Give W_SetupShot a deathtype parameter, fixes some ugly hacks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / hook.qc
index ba7efe6a31a33384e1c1b0cbcb0a535e6ca72b99..e04376b2f4fee279a289c1bb7bb8fcb4de320e36 100644 (file)
@@ -1,96 +1,18 @@
 #include "hook.qh"
-#ifndef IMPLEMENTATION
-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");
-#ifdef GAMEQC
-/* 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, m_name, string, _("Grappling Hook"));
-       ATTRIB(Hook, ammo_factor, float, 1);
-
-#define X(BEGIN, P, END, class, prefix) \
-       BEGIN(class) \
-               P(class, prefix, ammo, float, PRI) \
-               P(class, prefix, animtime, float, BOTH) \
-               P(class, prefix, damageforcescale, float, SEC) \
-               P(class, prefix, damage, float, SEC) \
-               P(class, prefix, duration, float, SEC) \
-               P(class, prefix, edgedamage, float, SEC) \
-               P(class, prefix, force, float, SEC) \
-               P(class, prefix, gravity, float, SEC) \
-               P(class, prefix, health, float, SEC) \
-               P(class, prefix, hooked_ammo, float, PRI) \
-               P(class, prefix, hooked_time_free, float, PRI) \
-               P(class, prefix, hooked_time_max, float, PRI) \
-               P(class, prefix, lifetime, float, SEC) \
-               P(class, prefix, power, float, SEC) \
-               P(class, prefix, radius, float, SEC) \
-               P(class, prefix, refire, float, BOTH) \
-               P(class, prefix, speed, float, SEC) \
-        P(class, prefix, switchdelay_drop, float, NONE) \
-               P(class, prefix, switchdelay_raise, float, NONE) \
-        P(class, prefix, weaponreplace, string, NONE) \
-        P(class, prefix, weaponstartoverride, float, NONE) \
-        P(class, prefix, weaponstart, float, NONE) \
-        P(class, prefix, weaponthrowable, float, NONE) \
-       END()
-    W_PROPS(X, Hook, hook)
-#undef X
-
-ENDCLASS(Hook)
-REGISTER_WEAPON(HOOK, 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); }
 
 #ifdef SVQC
 
-.float dmg;
-.float dmg_edge;
-.float dmg_radius;
-.float dmg_force;
-.float dmg_power;
-.float dmg_duration;
-.float dmg_last;
-.float hook_refire;
-.float hook_time_hooked;
-.float hook_time_fueldecrease;
-#endif
-#endif
-#ifdef IMPLEMENTATION
-#ifdef SVQC
-
-spawnfunc(weapon_hook) { weapon_defaultspawnfunc(this, WEP_HOOK); }
-
 void W_Hook_ExplodeThink(entity this)
 {
        float dt, dmg_remaining_next, f;
 
        dt = time - this.teleport_time;
-       dmg_remaining_next = pow(bound(0, 1 - dt / this.dmg_duration, 1), this.dmg_power);
+       dmg_remaining_next = (bound(0, 1 - dt / this.dmg_duration, 1) ** this.dmg_power);
 
        f = this.dmg_last - dmg_remaining_next;
        this.dmg_last = dmg_remaining_next;
 
-       RadiusDamage(this, this.realowner, this.dmg * f, this.dmg_edge * f, this.dmg_radius, this.realowner, NULL, this.dmg_force * f, this.projectiledeathtype, NULL);
+       RadiusDamage(this, this.realowner, this.dmg * f, this.dmg_edge * f, this.dmg_radius, this.realowner, NULL, this.dmg_force * f, this.projectiledeathtype, this.weaponentity_fld, NULL);
        this.projectiledeathtype |= HITTYPE_BOUNCE;
        //RadiusDamage(this, NULL, this.dmg * f, this.dmg_edge * f, this.dmg_radius, NULL, NULL, this.dmg_force * f, this.projectiledeathtype, NULL);
 
@@ -124,7 +46,7 @@ void W_Hook_Explode2_use(entity this, entity actor, entity trigger)
        W_Hook_Explode2(this);
 }
 
-void W_Hook_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
+void W_Hook_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
 {
        if(this.health <= 0)
                return;
@@ -147,7 +69,7 @@ void W_Hook_Touch2(entity this, entity toucher)
 void W_Hook_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
 {
        //W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb)
-       W_SetupShot(actor, weaponentity, false, 4, SND_HOOKBOMB_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(hook, damage));
+       W_SetupShot(actor, weaponentity, false, 4, SND_HOOKBOMB_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(hook, damage), WEP_HOOK.m_id | HITTYPE_SECONDARY);
 
        entity gren = new(hookbomb);
        gren.owner = gren.realowner = actor;
@@ -156,6 +78,7 @@ void W_Hook_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
        set_movetype(gren, MOVETYPE_TOSS);
        PROJECTILE_MAKETRIGGER(gren);
        gren.projectiledeathtype = WEP_HOOK.m_id | HITTYPE_SECONDARY;
+       gren.weaponentity_fld = weaponentity;
        setorigin(gren, w_shotorg);
        setsize(gren, '0 0 0', '0 0 0');
 
@@ -169,6 +92,7 @@ void W_Hook_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
        gren.damageforcescale = WEP_CVAR_SEC(hook, damageforcescale);
        gren.event_damage = W_Hook_Damage;
        gren.damagedbycontents = true;
+       IL_PUSH(g_damagedbycontents, gren);
        gren.missile_flags = MIF_SPLASH | MIF_ARC;
 
        gren.velocity = '0 0 1' * WEP_CVAR_SEC(hook, speed);
@@ -191,19 +115,19 @@ void W_Hook_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
 METHOD(Hook, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
 {
     if (fire & 1) {
-        if(!actor.hook)
-        if(!(actor.hook_state & HOOK_WAITING_FOR_RELEASE))
-        if(time > actor.hook_refire)
+        if(!actor.(weaponentity).hook)
+        if(!(actor.(weaponentity).hook_state & HOOK_WAITING_FOR_RELEASE))
+        if(time > actor.(weaponentity).hook_refire)
         if(weapon_prepareattack(thiswep, actor, weaponentity, false, -1))
         {
-            W_DecreaseAmmo(thiswep, actor, thiswep.ammo_factor * WEP_CVAR_PRI(hook, ammo));
-            actor.hook_state |= HOOK_FIRING;
-            actor.hook_state |= HOOK_WAITING_FOR_RELEASE;
+            W_DecreaseAmmo(thiswep, actor, thiswep.ammo_factor * WEP_CVAR_PRI(hook, ammo), weaponentity);
+            actor.(weaponentity).hook_state |= HOOK_FIRING;
+            actor.(weaponentity).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;
+        actor.(weaponentity).hook_state |= HOOK_REMOVING;
+        actor.(weaponentity).hook_state &= ~HOOK_WAITING_FOR_RELEASE;
     }
 
     if(fire & 2)
@@ -215,43 +139,44 @@ METHOD(Hook, wr_think, void(entity thiswep, entity actor, .entity weaponentity,
         }
     }
 
-    if(actor.hook)
+    if(actor.(weaponentity).hook)
     {
         // if hooked, no bombs, and increase the timer
-        actor.hook_refire = max(actor.hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor(actor));
+        actor.(weaponentity).hook_refire = max(actor.(weaponentity).hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor(actor));
 
         // hook also inhibits health regeneration, but only for 1 second
         if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
             actor.pauseregen_finished = max(actor.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
     }
 
-    if(actor.hook && actor.hook.state == 1)
+    if(actor.(weaponentity).hook && actor.(weaponentity).hook.state == 1)
     {
         float hooked_time_max = WEP_CVAR_PRI(hook, hooked_time_max);
         if(hooked_time_max > 0)
         {
-            if( time > actor.hook_time_hooked + hooked_time_max )
-                actor.hook_state |= HOOK_REMOVING;
+            if( time > actor.(weaponentity).hook_time_hooked + hooked_time_max )
+                actor.(weaponentity).hook_state |= HOOK_REMOVING;
         }
 
         float hooked_fuel = thiswep.ammo_factor * WEP_CVAR_PRI(hook, hooked_ammo);
         if(hooked_fuel > 0)
         {
-            if( time > actor.hook_time_fueldecrease )
+            if( time > actor.(weaponentity).hook_time_fueldecrease )
             {
                 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
                 {
-                    if( actor.ammo_fuel >= (time - actor.hook_time_fueldecrease) * hooked_fuel )
+                    if( actor.ammo_fuel >= (time - actor.(weaponentity).hook_time_fueldecrease) * hooked_fuel )
                     {
-                        W_DecreaseAmmo(thiswep, actor, (time - actor.hook_time_fueldecrease) * hooked_fuel);
-                        actor.hook_time_fueldecrease = time;
+                        W_DecreaseAmmo(thiswep, actor, (time - actor.(weaponentity).hook_time_fueldecrease) * hooked_fuel, weaponentity);
+                        actor.(weaponentity).hook_time_fueldecrease = time;
                         // decrease next frame again
                     }
                     else
                     {
                         actor.ammo_fuel = 0;
-                        actor.hook_state |= HOOK_REMOVING;
-                        W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+                        actor.(weaponentity).hook_state |= HOOK_REMOVING;
+                        if(actor.(weaponentity).m_weapon != WEP_Null) // offhand
+                               W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
                     }
                 }
             }
@@ -259,49 +184,54 @@ METHOD(Hook, wr_think, void(entity thiswep, entity actor, .entity weaponentity,
     }
     else
     {
-        actor.hook_time_hooked = time;
-        actor.hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free);
+        actor.(weaponentity).hook_time_hooked = time;
+        actor.(weaponentity).hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free);
     }
 
-    actor.hook_state = BITSET(actor.hook_state, HOOK_PULLING, (!PHYS_INPUT_BUTTON_CROUCH(actor) || !autocvar_g_balance_grapplehook_crouchslide));
+    actor.(weaponentity).hook_state = BITSET(actor.(weaponentity).hook_state, HOOK_PULLING, (!PHYS_INPUT_BUTTON_CROUCH(actor) || !autocvar_g_balance_grapplehook_crouchslide));
 
-    if (actor.hook_state & HOOK_FIRING)
+    if (actor.(weaponentity).hook_state & HOOK_FIRING)
     {
-        if (actor.hook)
-            RemoveGrapplingHook(actor);
-        FireGrapplingHook(actor);
-        actor.hook_state &= ~HOOK_FIRING;
-        actor.hook_refire = max(actor.hook_refire, time + autocvar_g_balance_grapplehook_refire * W_WeaponRateFactor(actor));
+        if (actor.(weaponentity).hook)
+            RemoveHook(actor.(weaponentity).hook);
+        FireGrapplingHook(actor, weaponentity);
+        actor.(weaponentity).hook_state &= ~HOOK_FIRING;
+        actor.(weaponentity).hook_refire = max(actor.(weaponentity).hook_refire, time + autocvar_g_balance_grapplehook_refire * W_WeaponRateFactor(actor));
     }
-    else if (actor.hook_state & HOOK_REMOVING)
+    else if (actor.(weaponentity).hook_state & HOOK_REMOVING)
     {
-        if (actor.hook)
-            RemoveGrapplingHook(actor);
-        actor.hook_state &= ~HOOK_REMOVING;
+        if (actor.(weaponentity).hook)
+            RemoveHook(actor.(weaponentity).hook);
+        actor.(weaponentity).hook_state &= ~HOOK_REMOVING;
     }
 }
-METHOD(Hook, wr_setup, void(entity thiswep, entity actor))
+METHOD(Hook, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
 {
-    actor.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
+       actor.(weaponentity).hook_state &= ~HOOK_WAITING_FOR_RELEASE;
 }
-METHOD(Hook, wr_checkammo1, bool(Hook thiswep, entity actor))
+METHOD(Hook, wr_checkammo1, bool(Hook thiswep, entity actor, .entity weaponentity))
 {
     if (!thiswep.ammo_factor) return true;
-    if(actor.hook)
-        return actor.ammo_fuel > 0;
-    else
-        return actor.ammo_fuel >= WEP_CVAR_PRI(hook, ammo);
+
+    if(actor.(weaponentity).hook)
+       return actor.ammo_fuel > 0;
+
+    return actor.ammo_fuel >= WEP_CVAR_PRI(hook, ammo);
 }
-METHOD(Hook, wr_checkammo2, bool(Hook thiswep, entity actor))
+METHOD(Hook, wr_checkammo2, bool(Hook thiswep, entity actor, .entity weaponentity))
 {
     // infinite ammo for now
     return true; // actor.ammo_cells >= WEP_CVAR_SEC(hook, ammo); // WEAPONTODO: see above
 }
 METHOD(Hook, wr_resetplayer, void(entity thiswep, entity actor))
 {
-    RemoveGrapplingHook(actor);
-    actor.hook_time = 0;
-    actor.hook_refire = time;
+    RemoveGrapplingHooks(actor);
+    for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+    {
+       .entity weaponentity = weaponentities[slot];
+       actor.(weaponentity).hook_time = 0;
+       actor.(weaponentity).hook_refire = time;
+    }
 }
 METHOD(Hook, wr_killmessage, Notification(entity thiswep))
 {
@@ -370,7 +300,7 @@ void Draw_GrapplingHook(entity this)
 
        InterpolateOrigin_Do(this);
 
-       int s = W_GetGunAlignment(NULL);
+       int s = W_GunAlign(viewmodels[this.cnt], STAT(GUNALIGN)) - 1;
 
        switch(this.HookType)
        {
@@ -389,8 +319,8 @@ void Draw_GrapplingHook(entity this)
                {
                        default:
                        case NET_ENT_CLIENT_HOOK:
-                               if(autocvar_chase_active > 0)
-                                       a = csqcplayer.origin;
+                               if(autocvar_chase_active)
+                                       a = csqcplayer.origin + csqcplayer.view_ofs;
                                else
                                        a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
                                b = this.origin;
@@ -495,8 +425,12 @@ void Remove_GrapplingHook(entity this)
 {
        sound (this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
 
-       if(csqcplayer && csqcplayer.hook == this)
-               csqcplayer.hook = NULL;
+       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+       {
+               entity wep = viewmodels[slot];
+               if(wep.hook == this)
+                       wep.hook = NULL;
+       }
 }
 
 NET_HANDLE(ENT_CLIENT_HOOK, bool bIsNew)
@@ -513,10 +447,12 @@ NET_HANDLE(ENT_CLIENT_HOOK, bool bIsNew)
        if(sf & 1)
        {
                int myowner = ReadByte();
+               int slot = ReadByte();
                this.owner = playerslots[myowner - 1];
                this.sv_entnum = myowner;
-               if(csqcplayer && myowner == player_localentnum)
-                       csqcplayer.hook = this;
+               if(myowner == player_localentnum)
+                       viewmodels[slot].hook = this;
+               this.cnt = slot;
                switch(this.HookType)
                {
                        default:
@@ -570,5 +506,3 @@ NET_HANDLE(ENT_CLIENT_HOOK, bool bIsNew)
 
 // TODO: hook: temporarily transform this.origin for drawing the model along warpzones!
 #endif
-
-#endif