3 #include "../lib/csqcmodel/interpolate.qh"
4 #include "../lib/warpzone/common.qh"
7 class(Hook) .entity HookType; // ENT_CLIENT_*
8 class(Hook) .vector origin;
9 class(Hook) .vector velocity;
10 class(Hook) .float HookSilent;
11 class(Hook) .float HookRange;
13 string Draw_GrapplingHook_trace_callback_tex;
14 float Draw_GrapplingHook_trace_callback_rnd;
15 vector Draw_GrapplingHook_trace_callback_rgb;
16 float Draw_GrapplingHook_trace_callback_a;
17 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
21 vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
22 for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
23 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);
24 Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
27 class(Hook) .float teleport_time;
28 void Draw_GrapplingHook(entity this)
35 float intensity, offset;
37 if(self.teleport_time)
38 if(time > self.teleport_time)
40 sound (self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM); // safeguard
41 self.teleport_time = 0;
44 InterpolateOrigin_Do();
46 int s = W_GetGunAlignment(world);
51 case NET_ENT_CLIENT_HOOK:
52 vs = hook_shotorigin[s];
54 case NET_ENT_CLIENT_ARC_BEAM:
55 vs = lightning_shotorigin[s];
59 if((self.owner.sv_entnum == player_localentnum - 1) && autocvar_chase_active <= 0)
64 case NET_ENT_CLIENT_HOOK:
65 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
68 case NET_ENT_CLIENT_ARC_BEAM:
70 b = view_origin + view_forward * self.HookRange;
72 b = view_origin + view_forward * vlen(self.velocity - self.origin); // honor original length of beam!
73 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
74 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
75 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
84 case NET_ENT_CLIENT_HOOK:
88 case NET_ENT_CLIENT_ARC_BEAM:
95 t = GetPlayerColorForce(self.owner.sv_entnum);
100 case NET_ENT_CLIENT_HOOK:
105 case NUM_TEAM_1: tex = "particles/hook_red"; rgb = '1 0.3 0.3'; break;
106 case NUM_TEAM_2: tex = "particles/hook_blue"; rgb = '0.3 0.3 1'; break;
107 case NUM_TEAM_3: tex = "particles/hook_yellow"; rgb = '1 1 0.3'; break;
108 case NUM_TEAM_4: tex = "particles/hook_pink"; rgb = '1 0.3 1'; break;
109 default: tex = "particles/hook_white"; rgb = getcsqcplayercolor(self.sv_entnum); break;
112 case NET_ENT_CLIENT_ARC_BEAM: // todo
113 intensity = bound(0.2, 1 + Noise_Pink(self, frametime) * 1 + Noise_Burst(self, frametime, 0.03) * 0.3, 2);
114 offset = Noise_Brown(self, frametime) * 10;
115 tex = "particles/lgbeam";
120 Draw_GrapplingHook_trace_callback_tex = tex;
121 Draw_GrapplingHook_trace_callback_rnd = offset;
122 Draw_GrapplingHook_trace_callback_rgb = rgb;
123 Draw_GrapplingHook_trace_callback_a = intensity;
124 WarpZone_TraceBox_ThroughZone(a, '0 0 0', '0 0 0', b, ((self.HookType == NET_ENT_CLIENT_HOOK) ? MOVE_NOTHING : MOVE_NORMAL), world, world, Draw_GrapplingHook_trace_callback);
125 Draw_GrapplingHook_trace_callback_tex = string_null;
127 atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
129 switch(self.HookType)
132 case NET_ENT_CLIENT_HOOK:
133 if(vlen(trace_endpos - atrans) > 0.5)
135 setorigin(self, trace_endpos); // hook endpoint!
136 self.angles = vectoangles(trace_endpos - atrans);
137 self.drawmask = MASK_NORMAL;
144 case NET_ENT_CLIENT_ARC_BEAM:
145 setorigin(self, a); // beam origin!
149 switch(self.HookType)
152 case NET_ENT_CLIENT_HOOK:
154 case NET_ENT_CLIENT_ARC_BEAM:
155 pointparticles(EFFECT_ARC_LIGHTNING2, trace_endpos, normalize(atrans - trace_endpos), frametime * intensity); // todo: new effect
160 void Remove_GrapplingHook()
162 sound (self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
165 NET_HANDLE(ENT_CLIENT_HOOK, bool bIsNew)
167 self.HookType = NET_ENT_CLIENT_HOOK;
171 self.HookSilent = (sf & 0x80);
172 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
174 InterpolateOrigin_Undo();
178 int myowner = ReadByte();
179 self.owner = playerslots[myowner - 1];
180 self.sv_entnum = myowner;
181 switch(self.HookType)
184 case NET_ENT_CLIENT_HOOK:
187 case NET_ENT_CLIENT_ARC_BEAM:
188 self.HookRange = ReadCoord();
194 self.origin_x = ReadCoord();
195 self.origin_y = ReadCoord();
196 self.origin_z = ReadCoord();
197 setorigin(self, self.origin);
201 self.velocity_x = ReadCoord();
202 self.velocity_y = ReadCoord();
203 self.velocity_z = ReadCoord();
206 InterpolateOrigin_Note();
208 if(bIsNew || !self.teleport_time)
210 self.draw = Draw_GrapplingHook;
211 self.entremove = Remove_GrapplingHook;
213 switch(self.HookType)
216 case NET_ENT_CLIENT_HOOK:
218 setmodel(self, MDL_HOOK);
219 self.drawmask = MASK_NORMAL;
221 case NET_ENT_CLIENT_ARC_BEAM:
222 sound (self, CH_SHOTS_SINGLE, SND_LGBEAM_FLY, VOL_BASE, ATTEN_NORM);
227 self.teleport_time = time + 10;
231 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!