]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/g_hook.qc
Merge branch 't0uYK8Ne/target_init' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_hook.qc
index 636e8c6aae99670ab355a0c24354c4a4c79291f3..7c21c45dd463aa42add4fe110329523a97c68a27 100644 (file)
@@ -1,5 +1,8 @@
 #include "g_hook.qh"
 
+#include <server/defs.qh>
+#include <server/miscfunctions.qh>
+#include <common/effects/all.qh>
 #include "weapons/common.qh"
 #include "weapons/csqcprojectile.qh"
 #include "weapons/weaponsystem.qh"
@@ -13,6 +16,7 @@
 #include "../common/vehicles/all.qh"
 #include "../common/constants.qh"
 #include "../common/util.qh"
+#include <common/net_linked.qh>
 #include <common/weapons/_all.qh>
 #include "../lib/warpzone/common.qh"
 #include "../lib/warpzone/server.qh"
@@ -78,11 +82,11 @@ void RemoveGrapplingHooks(entity pl)
        for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
     {
        .entity weaponentity = weaponentities[slot];
+       if(!pl.(weaponentity))
+               continue; // continue incase other slots exist?
        if(pl.(weaponentity).hook)
-       {
                delete(pl.(weaponentity).hook);
-               pl.(weaponentity).hook = NULL;
-       }
+       pl.(weaponentity).hook = NULL;
     }
 
        //pl.disableclientprediction = false;
@@ -90,15 +94,14 @@ void RemoveGrapplingHooks(entity pl)
 
 void RemoveHook(entity this)
 {
-       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
-    {
-       .entity weaponentity = weaponentities[slot];
-       if(this.realowner.(weaponentity).hook == this)
-               this.realowner.(weaponentity).hook = NULL;
-    }
+       entity player = this.realowner;
+    .entity weaponentity = this.weaponentity_fld;
 
-    if(this.realowner.move_movetype == MOVETYPE_FLY)
-       set_movetype(this.realowner, MOVETYPE_WALK);
+    if(player.(weaponentity).hook == this)
+       player.(weaponentity).hook = NULL;
+
+    if(player.move_movetype == MOVETYPE_FLY)
+       set_movetype(player, MOVETYPE_WALK);
     delete(this);
 }
 
@@ -162,7 +165,7 @@ void GrapplingHookThink(entity this)
                error("Owner lost the hook!\n");
                return;
        }
-       if(LostMovetypeFollow(this) || intermission_running || (round_handler_IsActive() && !round_handler_IsRoundStarted()) || ((this.aiment.flags & FL_PROJECTILE) && this.aiment.classname != "nade"))
+       if(LostMovetypeFollow(this) || game_stopped || (round_handler_IsActive() && !round_handler_IsRoundStarted()) || ((this.aiment.flags & FL_PROJECTILE) && this.aiment.classname != "nade"))
        {
                RemoveHook(this);
                return;
@@ -172,7 +175,7 @@ void GrapplingHookThink(entity this)
 
        this.nextthink = time;
 
-       int s = W_GunAlign(this.realowner.(weaponentity), STAT(GUNALIGN, this.realowner));
+       int s = W_GunAlign(this.realowner.(weaponentity), STAT(GUNALIGN, this.realowner)) - 1;
        vs = hook_shotorigin[s];
 
        makevectors(this.realowner.v_angle);
@@ -338,7 +341,7 @@ void GrapplingHookTouch(entity this, entity toucher)
        //this.realowner.disableclientprediction = true;
 }
 
-void GrapplingHook_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
+void GrapplingHook_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
 {
        if(this.health <= 0)
                return;
@@ -362,28 +365,24 @@ void GrapplingHook_Damage(entity this, entity inflictor, entity attacker, float
 
 void FireGrapplingHook(entity actor, .entity weaponentity)
 {
-       entity missile;
-       vector org;
-       vector vs;
-
        if(forbidWeaponUse(actor)) return;
        if(actor.vehicle) return;
 
        makevectors(actor.v_angle);
 
-       int s = W_GunAlign(actor.(weaponentity), STAT(GUNALIGN, actor));
-       vs = hook_shotorigin[s];
+       int s = W_GunAlign(actor.(weaponentity), STAT(GUNALIGN, actor)) - 1;
+       vector vs = hook_shotorigin[s];
 
        // UGLY WORKAROUND: play this on CH_WEAPON_B so it can't cut off fire sounds
        sound (actor, CH_WEAPON_B, SND_HOOK_FIRE, VOL_BASE, ATTEN_NORM);
-       org = actor.origin + actor.view_ofs + v_forward * vs.x + v_right * -vs.y + v_up * vs.z;
+       vector org = actor.origin + actor.view_ofs + v_forward * vs.x + v_right * -vs.y + v_up * vs.z;
 
        tracebox(actor.origin + actor.view_ofs, '-3 -3 -3', '3 3 3', org, MOVE_NORMAL, actor);
        org = trace_endpos;
 
        Send_Effect(EFFECT_HOOK_MUZZLEFLASH, org, '0 0 0', 1);
 
-       missile = WarpZone_RefSys_SpawnSameRefSys(actor);
+       entity missile = WarpZone_RefSys_SpawnSameRefSys(actor);
        missile.owner = missile.realowner = actor;
        actor.(weaponentity).hook = missile;
        missile.weaponentity_fld = weaponentity;
@@ -418,6 +417,8 @@ void FireGrapplingHook(entity actor, .entity weaponentity)
        missile.takedamage = DAMAGE_AIM;
        missile.damageforcescale = 0;
        missile.damagedbycontents = (autocvar_g_balance_grapplehook_damagedbycontents);
+       if(missile.damagedbycontents)
+               IL_PUSH(g_damagedbycontents, missile);
 
        missile.hook_start = missile.hook_end = missile.origin;