6 #include "../common/teams.qh"
8 #include "../csqcmodellib/interpolate.qh"
10 #include "../warpzonelib/common.qh"
13 class(Hook) .float HookType; // ENT_CLIENT_*
14 class(Hook) .vector origin;
15 class(Hook) .vector velocity;
16 class(Hook) .float HookSilent;
17 class(Hook) .float HookRange;
19 string Draw_GrapplingHook_trace_callback_tex;
20 float Draw_GrapplingHook_trace_callback_rnd;
21 vector Draw_GrapplingHook_trace_callback_rgb;
22 float Draw_GrapplingHook_trace_callback_a;
23 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
27 vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
28 for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
29 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);
30 Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
33 class(Hook) .float teleport_time;
34 void Draw_GrapplingHook()
42 float intensity, offset;
44 if(self.teleport_time)
45 if(time > self.teleport_time)
47 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM); // safeguard
48 self.teleport_time = 0;
51 InterpolateOrigin_Do();
53 s = autocvar_cl_gunalign;
54 if(s != 1 && s != 2 && s != 4)
55 s = 3; // default value
61 vs = hook_shotorigin[s];
63 case ENT_CLIENT_ARC_BEAM:
64 vs = lightning_shotorigin[s];
68 if((self.owner.sv_entnum == player_localentnum - 1) && autocvar_chase_active <= 0)
74 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
77 case ENT_CLIENT_ARC_BEAM:
79 b = view_origin + view_forward * self.HookRange;
81 b = view_origin + view_forward * vlen(self.velocity - self.origin); // honor original length of beam!
82 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
83 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
84 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
97 case ENT_CLIENT_ARC_BEAM:
104 t = GetPlayerColorForce(self.owner.sv_entnum);
106 switch(self.HookType)
109 case ENT_CLIENT_HOOK:
114 case NUM_TEAM_1: tex = "particles/hook_red"; rgb = '1 0.3 0.3'; break;
115 case NUM_TEAM_2: tex = "particles/hook_blue"; rgb = '0.3 0.3 1'; break;
116 case NUM_TEAM_3: tex = "particles/hook_yellow"; rgb = '1 1 0.3'; break;
117 case NUM_TEAM_4: tex = "particles/hook_pink"; rgb = '1 0.3 1'; break;
118 default: tex = "particles/hook_white"; rgb = getcsqcplayercolor(self.sv_entnum); break;
121 case ENT_CLIENT_ARC_BEAM: // todo
122 intensity = bound(0.2, 1 + Noise_Pink(self, frametime) * 1 + Noise_Burst(self, frametime, 0.03) * 0.3, 2);
123 offset = Noise_Brown(self, frametime) * 10;
124 tex = "particles/lgbeam";
129 Draw_GrapplingHook_trace_callback_tex = tex;
130 Draw_GrapplingHook_trace_callback_rnd = offset;
131 Draw_GrapplingHook_trace_callback_rgb = rgb;
132 Draw_GrapplingHook_trace_callback_a = intensity;
133 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);
134 Draw_GrapplingHook_trace_callback_tex = string_null;
136 atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
138 switch(self.HookType)
141 case ENT_CLIENT_HOOK:
142 if(vlen(trace_endpos - atrans) > 0.5)
144 setorigin(self, trace_endpos); // hook endpoint!
145 self.angles = vectoangles(trace_endpos - atrans);
146 self.drawmask = MASK_NORMAL;
153 case ENT_CLIENT_ARC_BEAM:
154 setorigin(self, a); // beam origin!
158 switch(self.HookType)
161 case ENT_CLIENT_HOOK:
163 case ENT_CLIENT_ARC_BEAM:
164 pointparticles(particleeffectnum(EFFECT_ARC_LIGHTNING2), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity); // todo: new effect
169 void Remove_GrapplingHook()
171 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
174 void Ent_ReadHook(float bIsNew, float type)
176 self.HookType = type;
180 self.HookSilent = (sf & 0x80);
181 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
183 InterpolateOrigin_Undo();
187 int myowner = ReadByte();
188 self.owner = playerslots[myowner - 1];
189 self.sv_entnum = myowner;
190 switch(self.HookType)
193 case ENT_CLIENT_HOOK:
196 case ENT_CLIENT_ARC_BEAM:
197 self.HookRange = ReadCoord();
203 self.origin_x = ReadCoord();
204 self.origin_y = ReadCoord();
205 self.origin_z = ReadCoord();
206 setorigin(self, self.origin);
210 self.velocity_x = ReadCoord();
211 self.velocity_y = ReadCoord();
212 self.velocity_z = ReadCoord();
215 InterpolateOrigin_Note();
217 if(bIsNew || !self.teleport_time)
219 self.draw = Draw_GrapplingHook;
220 self.entremove = Remove_GrapplingHook;
222 switch(self.HookType)
225 case ENT_CLIENT_HOOK:
227 setmodel(self, "models/hook.md3");
228 self.drawmask = MASK_NORMAL;
230 case ENT_CLIENT_ARC_BEAM:
231 sound (self, CH_SHOTS_SINGLE, W_Sound("lgbeam_fly"), VOL_BASE, ATTEN_NORM);
236 self.teleport_time = time + 10;
241 precache_sound(W_Sound("lgbeam_fly"));
242 precache_model("models/hook.md3");
245 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!