3 #include "../warpzonelib/common.qh"
5 .float HookType; // ENT_CLIENT_*
11 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg)
13 // I want to draw a quad...
14 // from and to are MIDPOINTS.
16 vector axis, thickdir, A, B, C, D;
19 axis = normalize(to - from);
20 length_tex = aspect * vlen(to - from) / thickness;
22 // direction is perpendicular to the view normal, and perpendicular to the axis
23 thickdir = normalize(cross(axis, vieworg - from));
25 A = from - thickdir * (thickness / 2);
26 B = from + thickdir * (thickness / 2);
27 C = to + thickdir * (thickness / 2);
28 D = to - thickdir * (thickness / 2);
30 R_BeginPolygon(texture, drawflag);
31 R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, theAlpha);
32 R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, theAlpha);
33 R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
34 R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
38 string Draw_GrapplingHook_trace_callback_tex;
39 float Draw_GrapplingHook_trace_callback_rnd;
40 vector Draw_GrapplingHook_trace_callback_rgb;
41 float Draw_GrapplingHook_trace_callback_a;
42 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
46 vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
47 for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
48 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);
49 Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
53 void Draw_GrapplingHook()
61 float intensity, offset;
63 if(self.teleport_time)
64 if(time > self.teleport_time)
66 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM); // safeguard
67 self.teleport_time = 0;
70 InterpolateOrigin_Do();
72 s = autocvar_cl_gunalign;
73 if(s != 1 && s != 2 && s != 4)
74 s = 3; // default value
80 vs = hook_shotorigin[s];
82 case ENT_CLIENT_ARC_BEAM:
83 vs = lightning_shotorigin[s];
87 if((self.owner.sv_entnum == player_localentnum - 1) && autocvar_chase_active <= 0)
93 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
96 case ENT_CLIENT_ARC_BEAM:
98 b = view_origin + view_forward * self.HookRange;
100 b = view_origin + view_forward * vlen(self.velocity - self.origin); // honor original length of beam!
101 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
102 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
103 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
109 switch(self.HookType)
112 case ENT_CLIENT_HOOK:
116 case ENT_CLIENT_ARC_BEAM:
123 t = GetPlayerColorForce(self.owner.sv_entnum);
125 switch(self.HookType)
128 case ENT_CLIENT_HOOK:
133 case NUM_TEAM_1: tex = "particles/hook_red"; rgb = '1 0.3 0.3'; break;
134 case NUM_TEAM_2: tex = "particles/hook_blue"; rgb = '0.3 0.3 1'; break;
135 case NUM_TEAM_3: tex = "particles/hook_yellow"; rgb = '1 1 0.3'; break;
136 case NUM_TEAM_4: tex = "particles/hook_pink"; rgb = '1 0.3 1'; break;
137 default: tex = "particles/hook_white"; rgb = getcsqcplayercolor(self.sv_entnum); break;
140 case ENT_CLIENT_ARC_BEAM: // todo
141 intensity = bound(0.2, 1 + Noise_Pink(self, frametime) * 1 + Noise_Burst(self, frametime, 0.03) * 0.3, 2);
142 offset = Noise_Brown(self, frametime) * 10;
143 tex = "particles/lgbeam";
148 Draw_GrapplingHook_trace_callback_tex = tex;
149 Draw_GrapplingHook_trace_callback_rnd = offset;
150 Draw_GrapplingHook_trace_callback_rgb = rgb;
151 Draw_GrapplingHook_trace_callback_a = intensity;
152 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);
153 Draw_GrapplingHook_trace_callback_tex = string_null;
155 atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
157 switch(self.HookType)
160 case ENT_CLIENT_HOOK:
161 if(vlen(trace_endpos - atrans) > 0.5)
163 setorigin(self, trace_endpos); // hook endpoint!
164 self.angles = vectoangles(trace_endpos - atrans);
165 self.drawmask = MASK_NORMAL;
172 case ENT_CLIENT_ARC_BEAM:
173 setorigin(self, a); // beam origin!
177 switch(self.HookType)
180 case ENT_CLIENT_HOOK:
182 case ENT_CLIENT_ARC_BEAM:
183 pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity); // todo: new effect
188 void Remove_GrapplingHook()
190 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
193 void Ent_ReadHook(float bIsNew, float type)
195 self.HookType = type;
199 self.HookSilent = (sf & 0x80);
200 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
202 InterpolateOrigin_Undo();
206 int myowner = ReadByte();
207 self.owner = playerslots[myowner - 1];
208 self.sv_entnum = myowner;
209 switch(self.HookType)
212 case ENT_CLIENT_HOOK:
215 case ENT_CLIENT_ARC_BEAM:
216 self.HookRange = ReadCoord();
222 self.origin_x = ReadCoord();
223 self.origin_y = ReadCoord();
224 self.origin_z = ReadCoord();
225 setorigin(self, self.origin);
229 self.velocity_x = ReadCoord();
230 self.velocity_y = ReadCoord();
231 self.velocity_z = ReadCoord();
234 InterpolateOrigin_Note();
236 if(bIsNew || !self.teleport_time)
238 self.draw = Draw_GrapplingHook;
239 self.entremove = Remove_GrapplingHook;
241 switch(self.HookType)
244 case ENT_CLIENT_HOOK:
246 setmodel(self, "models/hook.md3");
247 self.drawmask = MASK_NORMAL;
249 case ENT_CLIENT_ARC_BEAM:
250 sound (self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
255 self.teleport_time = time + 10;
260 precache_sound("weapons/lgbeam_fly.wav");
261 precache_model("models/hook.md3");
264 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!