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));
22 print("from ", vtos(from), "\n");
23 print("to ", vtos(to), "\n");
24 print("org ", vtos(view_origin), "\n");
25 print("dir ", vtos(thickdir), "\n");
28 A = from - thickdir * (thickness / 2);
29 B = from + thickdir * (thickness / 2);
30 C = to + thickdir * (thickness / 2);
31 D = to - thickdir * (thickness / 2);
33 R_BeginPolygon(texture, drawflag);
34 R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, alpha);
35 R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, alpha);
36 R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, alpha);
37 R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, alpha);
41 string Draw_GrapplingHook_trace_callback_tex;
42 float Draw_GrapplingHook_trace_callback_rnd;
43 vector Draw_GrapplingHook_trace_callback_rgb;
44 float Draw_GrapplingHook_trace_callback_a;
45 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
49 vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
50 for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
51 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);
52 Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
56 void Draw_GrapplingHook()
64 float intensity, offset;
66 if(self.teleport_time)
67 if(time > self.teleport_time)
69 sound (self, CHAN_PROJECTILE, "misc/null.wav", VOL_BASE, ATTN_NORM); // safeguard
70 self.teleport_time = 0;
73 InterpolateOrigin_Do();
75 s = cvar("cl_gunalign");
76 if(s != 1 && s != 2 && s != 4)
77 s = 3; // default value
83 vs = hook_shotorigin[s];
85 case ENT_CLIENT_LGBEAM:
86 vs = electro_shotorigin[s];
88 case ENT_CLIENT_GAUNTLET:
89 vs = gauntlet_shotorigin[s];
93 if((self.owner.sv_entnum == player_localentnum - 1))
99 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
102 case ENT_CLIENT_LGBEAM:
103 case ENT_CLIENT_GAUNTLET:
105 b = view_origin + view_forward * self.HookRange;
107 b = view_origin + view_forward * vlen(self.velocity - self.origin); // honor original length of beam!
108 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
109 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
110 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
116 switch(self.HookType)
119 case ENT_CLIENT_HOOK:
123 case ENT_CLIENT_LGBEAM:
124 case ENT_CLIENT_GAUNTLET:
131 t = GetPlayerColorForce(self.owner.sv_entnum);
133 switch(self.HookType)
136 case ENT_CLIENT_HOOK:
141 tex = "particles/hook_red";
144 else if(t == COLOR_TEAM2)
146 tex = "particles/hook_blue";
149 else if(t == COLOR_TEAM3)
151 tex = "particles/hook_yellow";
154 else if(t == COLOR_TEAM4)
156 tex = "particles/hook_pink";
161 tex = "particles/hook_green";
165 case ENT_CLIENT_LGBEAM:
166 intensity = bound(0.2, 1 + Noise_Pink(self, frametime) * 1 + Noise_Burst(self, frametime, 0.03) * 0.3, 2);
167 offset = Noise_Brown(self, frametime) * 10;
168 tex = "particles/lgbeam";
171 case ENT_CLIENT_GAUNTLET:
173 offset = Noise_White(self, frametime);
174 tex = "particles/gauntletbeam";
179 Draw_GrapplingHook_trace_callback_tex = tex;
180 Draw_GrapplingHook_trace_callback_rnd = offset;
181 Draw_GrapplingHook_trace_callback_rgb = rgb;
182 Draw_GrapplingHook_trace_callback_a = intensity;
183 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);
184 Draw_GrapplingHook_trace_callback_tex = string_null;
186 atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
188 switch(self.HookType)
191 case ENT_CLIENT_HOOK:
192 if(vlen(trace_endpos - atrans) > 0.5)
194 setorigin(self, trace_endpos); // hook endpoint!
195 self.angles = vectoangles(trace_endpos - atrans);
196 self.drawmask = MASK_NORMAL;
203 case ENT_CLIENT_LGBEAM:
204 case ENT_CLIENT_GAUNTLET:
205 setorigin(self, a); // beam origin!
209 switch(self.HookType)
212 case ENT_CLIENT_HOOK:
214 case ENT_CLIENT_LGBEAM:
215 pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity);
217 case ENT_CLIENT_GAUNTLET:
218 pointparticles(particleeffectnum("gauntlet_lightning"), b, normalize(a - b), frametime * intensity);
223 void Remove_GrapplingHook()
225 sound (self, CHAN_PROJECTILE, "misc/null.wav", VOL_BASE, ATTN_NORM);
228 void Ent_ReadHook(float bIsNew, float type)
230 self.HookType = type;
235 self.HookSilent = (sf & 0x80);
236 self.iflags = IFLAG_VELOCITY;
238 InterpolateOrigin_Undo();
242 self.owner = playerslots[ReadByte() - 1];
243 switch(self.HookType)
246 case ENT_CLIENT_HOOK:
247 case ENT_CLIENT_GAUNTLET:
250 case ENT_CLIENT_LGBEAM:
251 self.HookRange = ReadCoord();
257 self.origin_x = ReadCoord();
258 self.origin_y = ReadCoord();
259 self.origin_z = ReadCoord();
260 setorigin(self, self.origin);
264 self.velocity_x = ReadCoord();
265 self.velocity_y = ReadCoord();
266 self.velocity_z = ReadCoord();
269 InterpolateOrigin_Note();
271 if(bIsNew || !self.teleport_time)
273 self.draw = Draw_GrapplingHook;
274 self.entremove = Remove_GrapplingHook;
276 switch(self.HookType)
279 case ENT_CLIENT_HOOK:
281 setmodel(self, "models/hook.md3");
282 self.drawmask = MASK_NORMAL;
284 case ENT_CLIENT_LGBEAM:
285 sound (self, CHAN_PROJECTILE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTN_NORM);
287 case ENT_CLIENT_GAUNTLET:
288 sound (self, CHAN_PROJECTILE, "weapons/gauntletbeam_fly.wav", VOL_BASE, ATTN_NORM);
293 self.teleport_time = time + 10;
298 precache_sound("weapons/lgbeam_fly.wav");
299 precache_sound("weapons/gauntletbeam_fly.wav");
300 precache_model("models/hook.md3");
303 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!