3 #include "../warpzonelib/common.qh"
6 class(Hook) .float HookType; // ENT_CLIENT_*
7 class(Hook) .vector origin;
8 class(Hook) .vector velocity;
9 class(Hook) .float HookSilent;
10 class(Hook) .float HookRange;
12 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg)
14 // I want to draw a quad...
15 // from and to are MIDPOINTS.
17 vector axis, thickdir, A, B, C, D;
20 axis = normalize(to - from);
21 length_tex = aspect * vlen(to - from) / thickness;
23 // direction is perpendicular to the view normal, and perpendicular to the axis
24 thickdir = normalize(cross(axis, vieworg - from));
26 A = from - thickdir * (thickness / 2);
27 B = from + thickdir * (thickness / 2);
28 C = to + thickdir * (thickness / 2);
29 D = to - thickdir * (thickness / 2);
31 R_BeginPolygon(texture, drawflag);
32 R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, theAlpha);
33 R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, theAlpha);
34 R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
35 R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
39 string Draw_GrapplingHook_trace_callback_tex;
40 float Draw_GrapplingHook_trace_callback_rnd;
41 vector Draw_GrapplingHook_trace_callback_rgb;
42 float Draw_GrapplingHook_trace_callback_a;
43 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
47 vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
48 for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
49 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);
50 Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
53 class(Hook) .float teleport_time;
54 void Draw_GrapplingHook()
62 float intensity, offset;
64 if(self.teleport_time)
65 if(time > self.teleport_time)
67 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM); // safeguard
68 self.teleport_time = 0;
71 InterpolateOrigin_Do();
73 s = autocvar_cl_gunalign;
74 if(s != 1 && s != 2 && s != 4)
75 s = 3; // default value
81 vs = hook_shotorigin[s];
83 case ENT_CLIENT_ARC_BEAM:
84 vs = lightning_shotorigin[s];
88 if((self.owner.sv_entnum == player_localentnum - 1) && autocvar_chase_active <= 0)
94 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
97 case ENT_CLIENT_ARC_BEAM:
99 b = view_origin + view_forward * self.HookRange;
101 b = view_origin + view_forward * vlen(self.velocity - self.origin); // honor original length of beam!
102 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
103 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
104 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
110 switch(self.HookType)
113 case ENT_CLIENT_HOOK:
117 case ENT_CLIENT_ARC_BEAM:
124 t = GetPlayerColorForce(self.owner.sv_entnum);
126 switch(self.HookType)
129 case ENT_CLIENT_HOOK:
134 case NUM_TEAM_1: tex = "particles/hook_red"; rgb = '1 0.3 0.3'; break;
135 case NUM_TEAM_2: tex = "particles/hook_blue"; rgb = '0.3 0.3 1'; break;
136 case NUM_TEAM_3: tex = "particles/hook_yellow"; rgb = '1 1 0.3'; break;
137 case NUM_TEAM_4: tex = "particles/hook_pink"; rgb = '1 0.3 1'; break;
138 default: tex = "particles/hook_white"; rgb = getcsqcplayercolor(self.sv_entnum); break;
141 case ENT_CLIENT_ARC_BEAM: // todo
142 intensity = bound(0.2, 1 + Noise_Pink(self, frametime) * 1 + Noise_Burst(self, frametime, 0.03) * 0.3, 2);
143 offset = Noise_Brown(self, frametime) * 10;
144 tex = "particles/lgbeam";
149 Draw_GrapplingHook_trace_callback_tex = tex;
150 Draw_GrapplingHook_trace_callback_rnd = offset;
151 Draw_GrapplingHook_trace_callback_rgb = rgb;
152 Draw_GrapplingHook_trace_callback_a = intensity;
153 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);
154 Draw_GrapplingHook_trace_callback_tex = string_null;
156 atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
158 switch(self.HookType)
161 case ENT_CLIENT_HOOK:
162 if(vlen(trace_endpos - atrans) > 0.5)
164 setorigin(self, trace_endpos); // hook endpoint!
165 self.angles = vectoangles(trace_endpos - atrans);
166 self.drawmask = MASK_NORMAL;
173 case ENT_CLIENT_ARC_BEAM:
174 setorigin(self, a); // beam origin!
178 switch(self.HookType)
181 case ENT_CLIENT_HOOK:
183 case ENT_CLIENT_ARC_BEAM:
184 pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity); // todo: new effect
189 void Remove_GrapplingHook()
191 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
194 void Ent_ReadHook(float bIsNew, float type)
196 self.HookType = type;
200 self.HookSilent = (sf & 0x80);
201 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
203 InterpolateOrigin_Undo();
207 int myowner = ReadByte();
208 self.owner = playerslots[myowner - 1];
209 self.sv_entnum = myowner;
210 switch(self.HookType)
213 case ENT_CLIENT_HOOK:
216 case ENT_CLIENT_ARC_BEAM:
217 self.HookRange = ReadCoord();
223 self.origin_x = ReadCoord();
224 self.origin_y = ReadCoord();
225 self.origin_z = ReadCoord();
226 setorigin(self, self.origin);
230 self.velocity_x = ReadCoord();
231 self.velocity_y = ReadCoord();
232 self.velocity_z = ReadCoord();
235 InterpolateOrigin_Note();
237 if(bIsNew || !self.teleport_time)
239 self.draw = Draw_GrapplingHook;
240 self.entremove = Remove_GrapplingHook;
242 switch(self.HookType)
245 case ENT_CLIENT_HOOK:
247 setmodel(self, "models/hook.md3");
248 self.drawmask = MASK_NORMAL;
250 case ENT_CLIENT_ARC_BEAM:
251 sound (self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
256 self.teleport_time = time + 10;
261 precache_sound("weapons/lgbeam_fly.wav");
262 precache_model("models/hook.md3");
265 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!