7 #include "../common/teams.qh"
9 #include "../csqcmodellib/interpolate.qh"
11 #include "../warpzonelib/common.qh"
12 #include "../warpzonelib/mathlib.qh"
15 class(Hook) .float HookType; // ENT_CLIENT_*
16 class(Hook) .vector origin;
17 class(Hook) .vector velocity;
18 class(Hook) .float HookSilent;
19 class(Hook) .float HookRange;
21 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg)
23 // I want to draw a quad...
24 // from and to are MIDPOINTS.
26 vector axis, thickdir, A, B, C, D;
29 axis = normalize(to - from);
30 length_tex = aspect * vlen(to - from) / thickness;
32 // direction is perpendicular to the view normal, and perpendicular to the axis
33 thickdir = normalize(cross(axis, vieworg - from));
35 A = from - thickdir * (thickness / 2);
36 B = from + thickdir * (thickness / 2);
37 C = to + thickdir * (thickness / 2);
38 D = to - thickdir * (thickness / 2);
40 R_BeginPolygon(texture, drawflag);
41 R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, theAlpha);
42 R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, theAlpha);
43 R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
44 R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
48 string Draw_GrapplingHook_trace_callback_tex;
49 float Draw_GrapplingHook_trace_callback_rnd;
50 vector Draw_GrapplingHook_trace_callback_rgb;
51 float Draw_GrapplingHook_trace_callback_a;
52 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
56 vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
57 for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
58 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);
59 Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
62 class(Hook) .float teleport_time;
63 void Draw_GrapplingHook()
71 float intensity, offset;
73 if(self.teleport_time)
74 if(time > self.teleport_time)
76 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM); // safeguard
77 self.teleport_time = 0;
80 InterpolateOrigin_Do();
82 s = autocvar_cl_gunalign;
83 if(s != 1 && s != 2 && s != 4)
84 s = 3; // default value
90 vs = hook_shotorigin[s];
92 case ENT_CLIENT_ARC_BEAM:
93 vs = lightning_shotorigin[s];
97 if((self.owner.sv_entnum == player_localentnum - 1) && autocvar_chase_active <= 0)
102 case ENT_CLIENT_HOOK:
103 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
106 case ENT_CLIENT_ARC_BEAM:
108 b = view_origin + view_forward * self.HookRange;
110 b = view_origin + view_forward * vlen(self.velocity - self.origin); // honor original length of beam!
111 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
112 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
113 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
119 switch(self.HookType)
122 case ENT_CLIENT_HOOK:
126 case ENT_CLIENT_ARC_BEAM:
133 t = GetPlayerColorForce(self.owner.sv_entnum);
135 switch(self.HookType)
138 case ENT_CLIENT_HOOK:
143 case NUM_TEAM_1: tex = "particles/hook_red"; rgb = '1 0.3 0.3'; break;
144 case NUM_TEAM_2: tex = "particles/hook_blue"; rgb = '0.3 0.3 1'; break;
145 case NUM_TEAM_3: tex = "particles/hook_yellow"; rgb = '1 1 0.3'; break;
146 case NUM_TEAM_4: tex = "particles/hook_pink"; rgb = '1 0.3 1'; break;
147 default: tex = "particles/hook_white"; rgb = getcsqcplayercolor(self.sv_entnum); break;
150 case ENT_CLIENT_ARC_BEAM: // todo
151 intensity = bound(0.2, 1 + Noise_Pink(self, frametime) * 1 + Noise_Burst(self, frametime, 0.03) * 0.3, 2);
152 offset = Noise_Brown(self, frametime) * 10;
153 tex = "particles/lgbeam";
158 Draw_GrapplingHook_trace_callback_tex = tex;
159 Draw_GrapplingHook_trace_callback_rnd = offset;
160 Draw_GrapplingHook_trace_callback_rgb = rgb;
161 Draw_GrapplingHook_trace_callback_a = intensity;
162 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);
163 Draw_GrapplingHook_trace_callback_tex = string_null;
165 atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
167 switch(self.HookType)
170 case ENT_CLIENT_HOOK:
171 if(vlen(trace_endpos - atrans) > 0.5)
173 setorigin(self, trace_endpos); // hook endpoint!
174 self.angles = vectoangles(trace_endpos - atrans);
175 self.drawmask = MASK_NORMAL;
182 case ENT_CLIENT_ARC_BEAM:
183 setorigin(self, a); // beam origin!
187 switch(self.HookType)
190 case ENT_CLIENT_HOOK:
192 case ENT_CLIENT_ARC_BEAM:
193 pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity); // todo: new effect
198 void Remove_GrapplingHook()
200 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
203 void Ent_ReadHook(float bIsNew, float type)
205 self.HookType = type;
209 self.HookSilent = (sf & 0x80);
210 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
212 InterpolateOrigin_Undo();
216 int myowner = ReadByte();
217 self.owner = playerslots[myowner - 1];
218 self.sv_entnum = myowner;
219 switch(self.HookType)
222 case ENT_CLIENT_HOOK:
225 case ENT_CLIENT_ARC_BEAM:
226 self.HookRange = ReadCoord();
232 self.origin_x = ReadCoord();
233 self.origin_y = ReadCoord();
234 self.origin_z = ReadCoord();
235 setorigin(self, self.origin);
239 self.velocity_x = ReadCoord();
240 self.velocity_y = ReadCoord();
241 self.velocity_z = ReadCoord();
244 InterpolateOrigin_Note();
246 if(bIsNew || !self.teleport_time)
248 self.draw = Draw_GrapplingHook;
249 self.entremove = Remove_GrapplingHook;
251 switch(self.HookType)
254 case ENT_CLIENT_HOOK:
256 setmodel(self, "models/hook.md3");
257 self.drawmask = MASK_NORMAL;
259 case ENT_CLIENT_ARC_BEAM:
260 sound (self, CH_SHOTS_SINGLE, W_Sound("lgbeam_fly"), VOL_BASE, ATTEN_NORM);
265 self.teleport_time = time + 10;
270 precache_sound(W_Sound("lgbeam_fly"));
271 precache_model("models/hook.md3");
274 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!