]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hook.qc
lgbeam prediction: use correct endpoint
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hook.qc
index 101ab9f019ad561e836b832a69f6941d2edac2b1..8644847b3f92efc78a38f75e5a7801359e153423 100644 (file)
@@ -1,6 +1,11 @@
 .vector HookStart;
 .vector HookEnd;
 .float HookKillTime;
+.vector LGBeamStart;
+.vector LGBeamEnd;
+.float LGBeamKillTime;
+.float LGBeamSound;
+.float LGBeamSilent;
 
 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float alpha, float drawflag)
 {
@@ -16,6 +21,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);
@@ -43,56 +55,115 @@ void Draw_GrapplingHook()
        string tex;
        vector rgb;
        float t;
+       float s;
+       vector vs;
 
-       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;
-       else
-               a = self.HookStart;
-       b = self.HookEnd;
-
-       t = GetPlayerColorForce(self.sv_entnum);
-
-       if(t == COLOR_TEAM1)
-       {
-               tex = "particles/hook_red";
-               rgb = '1 .3 .3';
-       }
-       else if(t == COLOR_TEAM2)
+       if(time < self.HookKillTime)
        {
-               tex = "particles/hook_blue";
-               rgb = '.3 .3 1';
+               s = cvar("cl_gunalign");
+               if(s != 1 && s != 2 && s != 4)
+                       s = 3; // default value
+               --s;
+               vs = hook_shotorigin[s];
+
+               if(self.sv_entnum == player_localentnum - 1)
+                       a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
+               else
+                       a = self.HookStart;
+               b = self.HookEnd;
+
+               t = GetPlayerColorForce(self.sv_entnum);
+
+               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';
+               }
+
+               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;
        }
-       else if(t == COLOR_TEAM3)
+
+       if(time < self.LGBeamKillTime)
        {
-               tex = "particles/hook_yellow";
-               rgb = '1 1 .3';
+               s = cvar("cl_gunalign");
+               if(s != 1 && s != 2 && s != 4)
+                       s = 3; // default value
+               --s;
+               vs = electro_shotorigin[s];
+
+               if(self.sv_entnum == player_localentnum - 1)
+               {
+                       b = view_origin + view_forward * MAX_SHOT_DISTANCE;
+                       WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
+                       a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
+               }
+               else
+               {
+                       a = self.LGBeamStart;
+                       b = self.LGBeamEnd;
+               }
+
+               tex = "particles/lgbeam";
+               rgb = '1 1 1';
+
+               Draw_GrapplingHook_trace_callback_tex = tex;
+               Draw_GrapplingHook_trace_callback_rnd = random();
+               WarpZone_TraceBox_ThroughZone(a, '0 0 0', '0 0 0', b, MOVE_NORMAL, world, world, Draw_GrapplingHook_trace_callback);
+               Draw_GrapplingHook_trace_callback_tex = string_null;
+
+               // helps the sound
+               setorigin(self, a);
        }
-       else if(t == COLOR_TEAM4)
+
+       if(time < self.LGBeamKillTime && !self.LGBeamSilent)
        {
-               tex = "particles/hook_pink";
-               rgb = '1 .3 1';
+               if(!self.LGBeamSound)
+               {
+                       sound (self, CHAN_PROJECTILE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTN_NORM);
+                       self.LGBeamSound = 1;
+               }
        }
        else
        {
-               tex = "particles/hook_green";
-               rgb = '.3 1 .3';
+               if(self.LGBeamSound)
+               {
+                       sound (self, CHAN_PROJECTILE, "misc/null.wav", VOL_BASE, ATTN_NORM);
+                       self.LGBeamSound = 0;
+               }
        }
-
-       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;
 }
 
 void Net_GrapplingHook()
 {
-       float i;
+       float i, t;
        vector start, end;
        entity p;
 
-       i = ReadShort();
+       i = ReadByte();
+       t = ReadByte();
        end_x = ReadCoord();
        end_y = ReadCoord();
        end_z = ReadCoord();
@@ -108,8 +179,32 @@ void Net_GrapplingHook()
        if(!p)
                return;
 
-       p.HookKillTime = time + 0.1;
-       p.HookStart = start;
-       p.HookEnd = end;
-       p.draw = Draw_GrapplingHook;
+       switch(t)
+       {
+               case 0: // hook beam
+                       p.HookKillTime = time + 0.1;
+                       p.HookStart = start;
+                       p.HookEnd = end;
+                       p.draw = Draw_GrapplingHook;
+                       break;
+               case 1: // electro lgbeam
+                       p.LGBeamKillTime = time + 0.1;
+                       p.LGBeamStart = start;
+                       p.LGBeamEnd = end;
+                       p.LGBeamSilent = 0;
+                       p.draw = Draw_GrapplingHook;
+                       break;
+               case 2: // silent electro lgbeam
+                       p.LGBeamKillTime = time + 0.1;
+                       p.LGBeamStart = start;
+                       p.LGBeamEnd = end;
+                       p.LGBeamSilent = 1;
+                       p.draw = Draw_GrapplingHook;
+                       break;
+       }
+}
+
+void Hook_Precache()
+{
+       precache_sound("weapons/lgbeam_fly.wav");
 }