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 setorigin(self, trace_endpos); // hook endpoint!
193 self.angles = vectoangles(trace_endpos - atrans);
195 case ENT_CLIENT_LGBEAM:
196 case ENT_CLIENT_GAUNTLET:
197 setorigin(self, a); // beam origin!
201 switch(self.HookType)
204 case ENT_CLIENT_HOOK:
206 case ENT_CLIENT_LGBEAM:
207 pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity);
209 case ENT_CLIENT_GAUNTLET:
210 pointparticles(particleeffectnum("gauntlet_lightning"), b, normalize(a - b), frametime * intensity);
215 void Remove_GrapplingHook()
217 sound (self, CHAN_PROJECTILE, "misc/null.wav", VOL_BASE, ATTN_NORM);
220 void Ent_ReadHook(float bIsNew, float type)
222 self.HookType = type;
227 self.HookSilent = (sf & 0x80);
228 self.iflags = IFLAG_VELOCITY;
230 InterpolateOrigin_Undo();
234 self.owner = playerslots[ReadByte() - 1];
235 switch(self.HookType)
238 case ENT_CLIENT_HOOK:
239 case ENT_CLIENT_GAUNTLET:
242 case ENT_CLIENT_LGBEAM:
243 self.HookRange = ReadCoord();
249 self.origin_x = ReadCoord();
250 self.origin_y = ReadCoord();
251 self.origin_z = ReadCoord();
252 setorigin(self, self.origin);
256 self.velocity_x = ReadCoord();
257 self.velocity_y = ReadCoord();
258 self.velocity_z = ReadCoord();
261 InterpolateOrigin_Note();
263 if(bIsNew || !self.teleport_time)
265 self.draw = Draw_GrapplingHook;
266 self.entremove = Remove_GrapplingHook;
268 switch(self.HookType)
271 case ENT_CLIENT_HOOK:
273 setmodel(self, "models/hook.md3");
274 self.drawmask = MASK_NORMAL;
276 case ENT_CLIENT_LGBEAM:
277 sound (self, CHAN_PROJECTILE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTN_NORM);
279 case ENT_CLIENT_GAUNTLET:
280 sound (self, CHAN_PROJECTILE, "weapons/gauntletbeam_fly.wav", VOL_BASE, ATTN_NORM);
285 self.teleport_time = time + 10;
290 precache_sound("weapons/lgbeam_fly.wav");
291 precache_sound("weapons/gauntletbeam_fly.wav");
292 precache_model("models/hook.md3");
295 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!