]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hook.qc
use a better factor
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hook.qc
index 101ab9f019ad561e836b832a69f6941d2edac2b1..efa16533d584fe4a2ec253e1a01059322df9d00b 100644 (file)
@@ -1,6 +1,8 @@
-.vector HookStart;
-.vector HookEnd;
-.float HookKillTime;
+.float HookType; // ENT_CLIENT_*
+.vector origin;
+.vector velocity;
+.float HookSound;
+.float HookSilent;
 
 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float alpha, float drawflag)
 {
@@ -16,6 +18,13 @@ void Draw_CylindricLine(vector from, vector to, float thickness, string texture,
        // direction is perpendicular to the view normal, and perpendicular to the axis
        thickdir = normalize(cross(axis, view_origin - from));
 
+/*
+       print("from ", vtos(from), "\n");
+       print("to ", vtos(to), "\n");
+       print("org ", vtos(view_origin), "\n");
+       print("dir ", vtos(thickdir), "\n");
+*/
+
        A = from - thickdir * (thickness / 2);
        B = from + thickdir * (thickness / 2);
        C = to + thickdir * (thickness / 2);
@@ -40,76 +49,205 @@ void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
 void Draw_GrapplingHook()
 {
        vector a, b;
-       string tex;
+       string tex, snd;
        vector rgb;
        float t;
+       float s;
+       vector vs;
+
+       InterpolateOrigin_Do();
+
+       s = cvar("cl_gunalign");
+       if(s != 1 && s != 2 && s != 4)
+               s = 3; // default value
+       --s;
+       switch(self.HookType)
+       {
+               default:
+               case ENT_CLIENT_HOOK:
+                       vs = hook_shotorigin[s];
+                       break;
+               case ENT_CLIENT_LGBEAM:
+                       vs = electro_shotorigin[s];
+                       break;
+               case ENT_CLIENT_GAUNTLET:
+                       vs = gauntlet_shotorigin[s];
+                       break;
+       }
 
-       if(time >= self.HookKillTime)
-               return;
-       if(self.sv_entnum == player_localentnum - 1)
-               a = view_origin + view_forward * hook_shotorigin_x + view_right * hook_shotorigin_y + view_up * hook_shotorigin_z;
+       if((self.owner.sv_entnum == player_localentnum - 1))
+       {
+               switch(self.HookType)
+               {
+                       default:
+                       case ENT_CLIENT_HOOK:
+                               a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
+                               b = self.origin;
+                               break;
+                       case ENT_CLIENT_LGBEAM:
+                       case ENT_CLIENT_GAUNTLET:
+                               b = view_origin + view_forward * vlen(self.velocity - self.origin); // honor original length of beam!
+                               WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
+                               b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
+                               a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
+                               break;
+               }
+       }
        else
-               a = self.HookStart;
-       b = self.HookEnd;
+       {
+               switch(self.HookType)
+               {
+                       default:
+                       case ENT_CLIENT_HOOK:
+                               a = self.velocity;
+                               b = self.origin;
+                               break;
+                       case ENT_CLIENT_LGBEAM:
+                       case ENT_CLIENT_GAUNTLET:
+                               a = self.origin;
+                               b = self.velocity;
+                               break;
+               }
+       }
 
-       t = GetPlayerColorForce(self.sv_entnum);
+       t = GetPlayerColorForce(self.owner.sv_entnum);
 
-       if(t == COLOR_TEAM1)
+       switch(self.HookType)
        {
-               tex = "particles/hook_red";
-               rgb = '1 .3 .3';
+               default:
+               case ENT_CLIENT_HOOK:
+                       if(t == COLOR_TEAM1)
+                       {
+                               tex = "particles/hook_red";
+                               rgb = '1 .3 .3';
+                       }
+                       else if(t == COLOR_TEAM2)
+                       {
+                               tex = "particles/hook_blue";
+                               rgb = '.3 .3 1';
+                       }
+                       else if(t == COLOR_TEAM3)
+                       {
+                               tex = "particles/hook_yellow";
+                               rgb = '1 1 .3';
+                       }
+                       else if(t == COLOR_TEAM4)
+                       {
+                               tex = "particles/hook_pink";
+                               rgb = '1 .3 1';
+                       }
+                       else
+                       {
+                               tex = "particles/hook_green";
+                               rgb = '.3 1 .3';
+                       }
+                       break;
+               case ENT_CLIENT_LGBEAM:
+                       tex = "particles/lgbeam";
+                       rgb = '1 1 1';
+                       break;
+               case ENT_CLIENT_GAUNTLET:
+                       tex = "particles/gauntletbeam";
+                       rgb = '1 1 1';
+                       break;
        }
-       else if(t == COLOR_TEAM2)
+
+       Draw_GrapplingHook_trace_callback_tex = tex;
+       Draw_GrapplingHook_trace_callback_rnd = random();
+       WarpZone_TraceBox_ThroughZone(a, '0 0 0', '0 0 0', b, ((self.HookType == ENT_CLIENT_HOOK) ? MOVE_NOTHING : MOVE_NORMAL), world, world, Draw_GrapplingHook_trace_callback);
+       Draw_GrapplingHook_trace_callback_tex = string_null;
+
+       switch(self.HookType)
        {
-               tex = "particles/hook_blue";
-               rgb = '.3 .3 1';
+               default:
+               case ENT_CLIENT_HOOK:
+                       setorigin(self, trace_endpos); // hook endpoint!
+                       self.angles = vectoangles(trace_endpos - WarpZone_TransformOrigin(WarpZone_trace_transform, a));
+                       break;
+               case ENT_CLIENT_LGBEAM:
+               case ENT_CLIENT_GAUNTLET:
+                       setorigin(self, a); // beam origin!
+                       break;
        }
-       else if(t == COLOR_TEAM3)
+
+       switch(self.HookType)
        {
-               tex = "particles/hook_yellow";
-               rgb = '1 1 .3';
+               default:
+               case ENT_CLIENT_HOOK:
+                       break;
+               case ENT_CLIENT_LGBEAM:
+                       pointparticles(particleeffectnum("electro_lightning"), b, normalize(a - b), frametime);
+                       break;
+               case ENT_CLIENT_GAUNTLET:
+                       break;
        }
-       else if(t == COLOR_TEAM4)
+}
+
+void Remove_GrapplingHook()
+{
+       sound (self, CHAN_PROJECTILE, "misc/null.wav", VOL_BASE, ATTN_NORM);
+}
+
+void Ent_ReadHook(float bIsNew, float type)
+{
+       self.HookType = type;
+
+       float sf;
+       sf = ReadByte();
+
+       self.HookSilent = (sf & 0x80);
+       self.iflags = IFLAG_VELOCITY;
+
+       InterpolateOrigin_Undo();
+
+       if(sf & 1)
        {
-               tex = "particles/hook_pink";
-               rgb = '1 .3 1';
+               self.owner = playerslots[ReadByte() - 1];
        }
-       else
+       if(sf & 2)
        {
-               tex = "particles/hook_green";
-               rgb = '.3 1 .3';
+               self.origin_x = ReadCoord();
+               self.origin_y = ReadCoord();
+               self.origin_z = ReadCoord();
+               setorigin(self, self.origin);
+       }
+       if(sf & 4)
+       {
+               self.velocity_x = ReadCoord();
+               self.velocity_y = ReadCoord();
+               self.velocity_z = ReadCoord();
        }
 
-       Draw_GrapplingHook_trace_callback_tex = tex;
-       Draw_GrapplingHook_trace_callback_rnd = random();
-       WarpZone_TraceBox_ThroughZone(a, '0 0 0', '0 0 0', b, MOVE_NOMONSTERS, world, world, Draw_GrapplingHook_trace_callback);
-       Draw_GrapplingHook_trace_callback_tex = string_null;
+       InterpolateOrigin_Note();
+
+       if(bIsNew)
+       {
+               self.draw = Draw_GrapplingHook;
+               self.entremove = Remove_GrapplingHook;
+
+               switch(self.HookType)
+               {
+                       default:
+                       case ENT_CLIENT_HOOK:
+                               // for the model
+                               setmodel(self, "models/hook.md3");
+                               self.drawmask = MASK_NORMAL;
+                               break;
+                       case ENT_CLIENT_LGBEAM:
+                               sound (self, CHAN_PROJECTILE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTN_NORM);
+                               break;
+                       case ENT_CLIENT_GAUNTLET:
+                               sound (self, CHAN_PROJECTILE, "weapons/gauntletbeam_fly.wav", VOL_BASE, ATTN_NORM);
+                               break;
+               }
+       }
 }
 
-void Net_GrapplingHook()
+void Hook_Precache()
 {
-       float i;
-       vector start, end;
-       entity p;
-
-       i = ReadShort();
-       end_x = ReadCoord();
-       end_y = ReadCoord();
-       end_z = ReadCoord();
-       start_x = ReadCoord();
-       start_y = ReadCoord();
-       start_z = ReadCoord();
-
-       if(i <= 0 || i >= 256) // not owned by a client
-               return;
-       --i;
-
-       p = playerslots[i];
-       if(!p)
-               return;
-
-       p.HookKillTime = time + 0.1;
-       p.HookStart = start;
-       p.HookEnd = end;
-       p.draw = Draw_GrapplingHook;
+       precache_sound("weapons/lgbeam_fly.wav");
+       precache_sound("weapons/gauntletbeam_fly.wav");
+       precache_model("models/hook.md3");
 }
+
+// TODO: hook: temporarily transform self.origin for drawing the model along warpzones!