1 .float HookType; // ENT_CLIENT_*
8 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float alpha, float drawflag)
10 // I want to draw a quad...
11 // from and to are MIDPOINTS.
13 vector axis, thickdir, A, B, C, D;
16 axis = normalize(to - from);
17 length_tex = aspect * vlen(to - from) / thickness;
19 // direction is perpendicular to the view normal, and perpendicular to the axis
20 thickdir = normalize(cross(axis, view_origin - from));
23 print("from ", vtos(from), "\n");
24 print("to ", vtos(to), "\n");
25 print("org ", vtos(view_origin), "\n");
26 print("dir ", vtos(thickdir), "\n");
29 A = from - thickdir * (thickness / 2);
30 B = from + thickdir * (thickness / 2);
31 C = to + thickdir * (thickness / 2);
32 D = to - thickdir * (thickness / 2);
34 R_BeginPolygon(texture, drawflag);
35 R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, alpha);
36 R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, alpha);
37 R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, alpha);
38 R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, alpha);
42 string Draw_GrapplingHook_trace_callback_tex;
43 float Draw_GrapplingHook_trace_callback_rnd;
44 vector Draw_GrapplingHook_trace_callback_rgb;
45 float Draw_GrapplingHook_trace_callback_a;
46 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
49 for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
50 Draw_CylindricLine(hit, start, 8, Draw_GrapplingHook_trace_callback_tex, 0.25, Draw_GrapplingHook_trace_callback_rnd, Draw_GrapplingHook_trace_callback_rgb, min(1, Draw_GrapplingHook_trace_callback_a - i), DRAWFLAG_NORMAL);
51 Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
54 void Draw_GrapplingHook()
62 float intensity, offset;
64 InterpolateOrigin_Do();
66 s = cvar("cl_gunalign");
67 if(s != 1 && s != 2 && s != 4)
68 s = 3; // default value
74 vs = hook_shotorigin[s];
76 case ENT_CLIENT_LGBEAM:
77 vs = electro_shotorigin[s];
79 case ENT_CLIENT_GAUNTLET:
80 vs = gauntlet_shotorigin[s];
84 if((self.owner.sv_entnum == player_localentnum - 1))
90 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
93 case ENT_CLIENT_LGBEAM:
94 case ENT_CLIENT_GAUNTLET:
96 b = view_origin + view_forward * self.HookRange;
98 b = view_origin + view_forward * vlen(self.velocity - self.origin); // honor original length of beam!
99 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
100 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
101 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
107 switch(self.HookType)
110 case ENT_CLIENT_HOOK:
114 case ENT_CLIENT_LGBEAM:
115 case ENT_CLIENT_GAUNTLET:
122 t = GetPlayerColorForce(self.owner.sv_entnum);
124 switch(self.HookType)
127 case ENT_CLIENT_HOOK:
132 tex = "particles/hook_red";
135 else if(t == COLOR_TEAM2)
137 tex = "particles/hook_blue";
140 else if(t == COLOR_TEAM3)
142 tex = "particles/hook_yellow";
145 else if(t == COLOR_TEAM4)
147 tex = "particles/hook_pink";
152 tex = "particles/hook_green";
156 case ENT_CLIENT_LGBEAM:
157 intensity = bound(0.2, 1 + Noise_Pink(self, frametime) * 1 + Noise_Burst(self, frametime, 0.03) * 0.3, 2);
158 offset = Noise_Brown(self, frametime) * 10;
159 tex = "particles/lgbeam";
162 case ENT_CLIENT_GAUNTLET:
164 offset = Noise_White(self, frametime);
165 tex = "particles/gauntletbeam";
170 Draw_GrapplingHook_trace_callback_tex = tex;
171 Draw_GrapplingHook_trace_callback_rnd = offset;
172 Draw_GrapplingHook_trace_callback_rgb = rgb;
173 Draw_GrapplingHook_trace_callback_a = intensity;
174 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);
175 Draw_GrapplingHook_trace_callback_tex = string_null;
177 atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
179 switch(self.HookType)
182 case ENT_CLIENT_HOOK:
183 setorigin(self, trace_endpos); // hook endpoint!
184 self.angles = vectoangles(trace_endpos - atrans);
186 case ENT_CLIENT_LGBEAM:
187 case ENT_CLIENT_GAUNTLET:
188 setorigin(self, a); // beam origin!
192 switch(self.HookType)
195 case ENT_CLIENT_HOOK:
197 case ENT_CLIENT_LGBEAM:
198 pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity);
200 case ENT_CLIENT_GAUNTLET:
201 pointparticles(particleeffectnum("gauntlet_lightning"), b, normalize(a - b), frametime * intensity);
206 void Remove_GrapplingHook()
208 sound (self, CHAN_PROJECTILE, "misc/null.wav", VOL_BASE, ATTN_NORM);
211 void Ent_ReadHook(float bIsNew, float type)
213 self.HookType = type;
218 self.HookSilent = (sf & 0x80);
219 self.iflags = IFLAG_VELOCITY;
221 InterpolateOrigin_Undo();
225 self.owner = playerslots[ReadByte() - 1];
226 switch(self.HookType)
229 case ENT_CLIENT_HOOK:
230 case ENT_CLIENT_GAUNTLET:
233 case ENT_CLIENT_LGBEAM:
234 self.HookRange = ReadCoord();
240 self.origin_x = ReadCoord();
241 self.origin_y = ReadCoord();
242 self.origin_z = ReadCoord();
243 setorigin(self, self.origin);
247 self.velocity_x = ReadCoord();
248 self.velocity_y = ReadCoord();
249 self.velocity_z = ReadCoord();
252 InterpolateOrigin_Note();
256 self.draw = Draw_GrapplingHook;
257 self.entremove = Remove_GrapplingHook;
259 switch(self.HookType)
262 case ENT_CLIENT_HOOK:
264 setmodel(self, "models/hook.md3");
265 self.drawmask = MASK_NORMAL;
267 case ENT_CLIENT_LGBEAM:
268 sound (self, CHAN_PROJECTILE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTN_NORM);
270 case ENT_CLIENT_GAUNTLET:
271 sound (self, CHAN_PROJECTILE, "weapons/gauntletbeam_fly.wav", VOL_BASE, ATTN_NORM);
279 precache_sound("weapons/lgbeam_fly.wav");
280 precache_sound("weapons/gauntletbeam_fly.wav");
281 precache_model("models/hook.md3");
284 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!