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 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
46 Draw_CylindricLine(hit, start, 8, Draw_GrapplingHook_trace_callback_tex, 0.25, Draw_GrapplingHook_trace_callback_rnd, '1 1 1', 1, DRAWFLAG_NORMAL);
47 Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
50 void Draw_GrapplingHook()
59 InterpolateOrigin_Do();
61 s = cvar("cl_gunalign");
62 if(s != 1 && s != 2 && s != 4)
63 s = 3; // default value
69 vs = hook_shotorigin[s];
71 case ENT_CLIENT_LGBEAM:
72 vs = electro_shotorigin[s];
74 case ENT_CLIENT_GAUNTLET:
75 vs = gauntlet_shotorigin[s];
79 if((self.owner.sv_entnum == player_localentnum - 1))
85 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
88 case ENT_CLIENT_LGBEAM:
89 case ENT_CLIENT_GAUNTLET:
91 b = view_origin + view_forward * self.HookRange;
93 b = view_origin + view_forward * vlen(self.velocity - self.origin); // honor original length of beam!
94 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
95 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
96 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
102 switch(self.HookType)
105 case ENT_CLIENT_HOOK:
109 case ENT_CLIENT_LGBEAM:
110 case ENT_CLIENT_GAUNTLET:
117 t = GetPlayerColorForce(self.owner.sv_entnum);
119 switch(self.HookType)
122 case ENT_CLIENT_HOOK:
125 tex = "particles/hook_red";
128 else if(t == COLOR_TEAM2)
130 tex = "particles/hook_blue";
133 else if(t == COLOR_TEAM3)
135 tex = "particles/hook_yellow";
138 else if(t == COLOR_TEAM4)
140 tex = "particles/hook_pink";
145 tex = "particles/hook_green";
149 case ENT_CLIENT_LGBEAM:
150 tex = "particles/lgbeam";
153 case ENT_CLIENT_GAUNTLET:
154 tex = "particles/gauntletbeam";
159 Draw_GrapplingHook_trace_callback_tex = tex;
160 Draw_GrapplingHook_trace_callback_rnd = random();
161 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);
162 Draw_GrapplingHook_trace_callback_tex = string_null;
164 atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
166 switch(self.HookType)
169 case ENT_CLIENT_HOOK:
170 setorigin(self, trace_endpos); // hook endpoint!
171 self.angles = vectoangles(trace_endpos - atrans);
173 case ENT_CLIENT_LGBEAM:
174 case ENT_CLIENT_GAUNTLET:
175 setorigin(self, a); // beam origin!
179 switch(self.HookType)
182 case ENT_CLIENT_HOOK:
184 case ENT_CLIENT_LGBEAM:
185 pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime);
187 case ENT_CLIENT_GAUNTLET:
192 void Remove_GrapplingHook()
194 sound (self, CHAN_PROJECTILE, "misc/null.wav", VOL_BASE, ATTN_NORM);
197 void Ent_ReadHook(float bIsNew, float type)
199 self.HookType = type;
204 self.HookSilent = (sf & 0x80);
205 self.iflags = IFLAG_VELOCITY;
207 InterpolateOrigin_Undo();
211 self.owner = playerslots[ReadByte() - 1];
212 switch(self.HookType)
215 case ENT_CLIENT_HOOK:
216 case ENT_CLIENT_GAUNTLET:
219 case ENT_CLIENT_LGBEAM:
220 self.HookRange = ReadCoord();
226 self.origin_x = ReadCoord();
227 self.origin_y = ReadCoord();
228 self.origin_z = ReadCoord();
229 setorigin(self, self.origin);
233 self.velocity_x = ReadCoord();
234 self.velocity_y = ReadCoord();
235 self.velocity_z = ReadCoord();
238 InterpolateOrigin_Note();
242 self.draw = Draw_GrapplingHook;
243 self.entremove = Remove_GrapplingHook;
245 switch(self.HookType)
248 case ENT_CLIENT_HOOK:
250 setmodel(self, "models/hook.md3");
251 self.drawmask = MASK_NORMAL;
253 case ENT_CLIENT_LGBEAM:
254 sound (self, CHAN_PROJECTILE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTN_NORM);
256 case ENT_CLIENT_GAUNTLET:
257 sound (self, CHAN_PROJECTILE, "weapons/gauntletbeam_fly.wav", VOL_BASE, ATTN_NORM);
265 precache_sound("weapons/lgbeam_fly.wav");
266 precache_sound("weapons/gauntletbeam_fly.wav");
267 precache_model("models/hook.md3");
270 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!