1 .float HookType; // ENT_CLIENT_*
7 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, 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, theAlpha);
28 R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, theAlpha);
29 R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
30 R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
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];
83 if((self.owner.sv_entnum == player_localentnum - 1))
89 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
92 case ENT_CLIENT_LGBEAM:
94 b = view_origin + view_forward * self.HookRange;
96 b = view_origin + view_forward * vlen(self.velocity - self.origin); // honor original length of beam!
97 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
98 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
99 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
105 switch(self.HookType)
108 case ENT_CLIENT_HOOK:
112 case ENT_CLIENT_LGBEAM:
119 t = GetPlayerColorForce(self.owner.sv_entnum);
121 switch(self.HookType)
124 case ENT_CLIENT_HOOK:
129 tex = "particles/hook_red";
132 else if(t == COLOR_TEAM2)
134 tex = "particles/hook_blue";
137 else if(t == COLOR_TEAM3)
139 tex = "particles/hook_yellow";
142 else if(t == COLOR_TEAM4)
144 tex = "particles/hook_pink";
149 tex = "particles/hook_green";
153 case ENT_CLIENT_LGBEAM:
154 intensity = bound(0.2, 1 + Noise_Pink(self, frametime) * 1 + Noise_Burst(self, frametime, 0.03) * 0.3, 2);
155 offset = Noise_Brown(self, frametime) * 10;
156 tex = "particles/lgbeam";
161 Draw_GrapplingHook_trace_callback_tex = tex;
162 Draw_GrapplingHook_trace_callback_rnd = offset;
163 Draw_GrapplingHook_trace_callback_rgb = rgb;
164 Draw_GrapplingHook_trace_callback_a = intensity;
165 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);
166 Draw_GrapplingHook_trace_callback_tex = string_null;
168 atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
170 switch(self.HookType)
173 case ENT_CLIENT_HOOK:
174 if(vlen(trace_endpos - atrans) > 0.5)
176 setorigin(self, trace_endpos); // hook endpoint!
177 self.angles = vectoangles(trace_endpos - atrans);
178 self.drawmask = MASK_NORMAL;
185 case ENT_CLIENT_LGBEAM:
186 setorigin(self, a); // beam origin!
190 switch(self.HookType)
193 case ENT_CLIENT_HOOK:
195 case ENT_CLIENT_LGBEAM:
196 pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity);
201 void Remove_GrapplingHook()
203 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTN_NORM);
206 void Ent_ReadHook(float bIsNew, float type)
208 self.HookType = type;
213 self.HookSilent = (sf & 0x80);
214 self.iflags = IFLAG_VELOCITY;
216 InterpolateOrigin_Undo();
220 self.owner = playerslots[ReadByte() - 1];
221 switch(self.HookType)
224 case ENT_CLIENT_HOOK:
227 case ENT_CLIENT_LGBEAM:
228 self.HookRange = ReadCoord();
234 self.origin_x = ReadCoord();
235 self.origin_y = ReadCoord();
236 self.origin_z = ReadCoord();
237 setorigin(self, self.origin);
241 self.velocity_x = ReadCoord();
242 self.velocity_y = ReadCoord();
243 self.velocity_z = ReadCoord();
246 InterpolateOrigin_Note();
248 if(bIsNew || !self.teleport_time)
250 self.draw = Draw_GrapplingHook;
251 self.entremove = Remove_GrapplingHook;
253 switch(self.HookType)
256 case ENT_CLIENT_HOOK:
258 setmodel(self, "models/hook.md3");
259 self.drawmask = MASK_NORMAL;
261 case ENT_CLIENT_LGBEAM:
262 sound (self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTN_NORM);
267 self.teleport_time = time + 10;
272 precache_sound("weapons/lgbeam_fly.wav");
273 precache_model("models/hook.md3");
276 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!