1 .float HookType; // ENT_CLIENT_*
7 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float alpha, float drawflag, vector vieworg)
9 // I want to draw a quad...
10 // from and to are MIDPOINTS.
12 vector axis, thickdir, A, B, C, D;
15 axis = normalize(to - from);
16 length_tex = aspect * vlen(to - from) / thickness;
18 // direction is perpendicular to the view normal, and perpendicular to the axis
19 thickdir = normalize(cross(axis, vieworg - from));
21 A = from - thickdir * (thickness / 2);
22 B = from + thickdir * (thickness / 2);
23 C = to + thickdir * (thickness / 2);
24 D = to - thickdir * (thickness / 2);
26 R_BeginPolygon(texture, drawflag);
27 R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, alpha);
28 R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, alpha);
29 R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, alpha);
30 R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, alpha);
34 string Draw_GrapplingHook_trace_callback_tex;
35 float Draw_GrapplingHook_trace_callback_rnd;
36 vector Draw_GrapplingHook_trace_callback_rgb;
37 float Draw_GrapplingHook_trace_callback_a;
38 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
42 vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
43 for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
44 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, vorg);
45 Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
49 void Draw_GrapplingHook()
57 float intensity, offset;
59 if(self.teleport_time)
60 if(time > self.teleport_time)
62 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTN_NORM); // safeguard
63 self.teleport_time = 0;
66 InterpolateOrigin_Do();
68 s = autocvar_cl_gunalign;
69 if(s != 1 && s != 2 && s != 4)
70 s = 3; // default value
76 vs = hook_shotorigin[s];
78 case ENT_CLIENT_LGBEAM:
79 vs = electro_shotorigin[s];
81 case ENT_CLIENT_GAUNTLET:
82 vs = gauntlet_shotorigin[s];
86 if((self.owner.sv_entnum == player_localentnum - 1))
92 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
95 case ENT_CLIENT_LGBEAM:
96 case ENT_CLIENT_GAUNTLET:
98 b = view_origin + view_forward * self.HookRange;
100 b = view_origin + view_forward * vlen(self.velocity - self.origin); // honor original length of beam!
101 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
102 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
103 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
109 switch(self.HookType)
112 case ENT_CLIENT_HOOK:
116 case ENT_CLIENT_LGBEAM:
117 case ENT_CLIENT_GAUNTLET:
124 t = GetPlayerColorForce(self.owner.sv_entnum);
126 switch(self.HookType)
129 case ENT_CLIENT_HOOK:
134 tex = "particles/hook_red";
137 else if(t == COLOR_TEAM2)
139 tex = "particles/hook_blue";
142 else if(t == COLOR_TEAM3)
144 tex = "particles/hook_yellow";
147 else if(t == COLOR_TEAM4)
149 tex = "particles/hook_pink";
154 tex = "particles/hook_green";
158 case ENT_CLIENT_LGBEAM:
159 intensity = bound(0.2, 1 + Noise_Pink(self, frametime) * 1 + Noise_Burst(self, frametime, 0.03) * 0.3, 2);
160 offset = Noise_Brown(self, frametime) * 10;
161 tex = "particles/lgbeam";
164 case ENT_CLIENT_GAUNTLET:
166 offset = Noise_White(self, frametime);
167 tex = "particles/gauntletbeam";
172 Draw_GrapplingHook_trace_callback_tex = tex;
173 Draw_GrapplingHook_trace_callback_rnd = offset;
174 Draw_GrapplingHook_trace_callback_rgb = rgb;
175 Draw_GrapplingHook_trace_callback_a = intensity;
176 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);
177 Draw_GrapplingHook_trace_callback_tex = string_null;
179 atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
181 switch(self.HookType)
184 case ENT_CLIENT_HOOK:
185 if(vlen(trace_endpos - atrans) > 0.5)
187 setorigin(self, trace_endpos); // hook endpoint!
188 self.angles = vectoangles(trace_endpos - atrans);
189 self.drawmask = MASK_NORMAL;
196 case ENT_CLIENT_LGBEAM:
197 case ENT_CLIENT_GAUNTLET:
198 setorigin(self, a); // beam origin!
202 switch(self.HookType)
205 case ENT_CLIENT_HOOK:
207 case ENT_CLIENT_LGBEAM:
208 pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity);
210 case ENT_CLIENT_GAUNTLET:
211 pointparticles(particleeffectnum("gauntlet_lightning"), b, normalize(a - b), frametime * intensity);
216 void Remove_GrapplingHook()
218 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTN_NORM);
221 void Ent_ReadHook(float bIsNew, float type)
223 self.HookType = type;
228 self.HookSilent = (sf & 0x80);
229 self.iflags = IFLAG_VELOCITY;
231 InterpolateOrigin_Undo();
235 self.owner = playerslots[ReadByte() - 1];
236 switch(self.HookType)
239 case ENT_CLIENT_HOOK:
240 case ENT_CLIENT_GAUNTLET:
243 case ENT_CLIENT_LGBEAM:
244 self.HookRange = ReadCoord();
250 self.origin_x = ReadCoord();
251 self.origin_y = ReadCoord();
252 self.origin_z = ReadCoord();
253 setorigin(self, self.origin);
257 self.velocity_x = ReadCoord();
258 self.velocity_y = ReadCoord();
259 self.velocity_z = ReadCoord();
262 InterpolateOrigin_Note();
264 if(bIsNew || !self.teleport_time)
266 self.draw = Draw_GrapplingHook;
267 self.entremove = Remove_GrapplingHook;
269 switch(self.HookType)
272 case ENT_CLIENT_HOOK:
274 setmodel(self, "models/hook.md3");
275 self.drawmask = MASK_NORMAL;
277 case ENT_CLIENT_LGBEAM:
278 sound (self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTN_NORM);
280 case ENT_CLIENT_GAUNTLET:
281 sound (self, CH_SHOTS_SINGLE, "weapons/gauntletbeam_fly.wav", VOL_BASE, ATTN_NORM);
286 self.teleport_time = time + 10;
291 precache_sound("weapons/lgbeam_fly.wav");
292 precache_sound("weapons/gauntletbeam_fly.wav");
293 precache_model("models/hook.md3");
296 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!