]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hook.qc
Merge remote-tracking branch 'origin/master' into samual/lightning_gun
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hook.qc
1 .float HookType; // ENT_CLIENT_*
2 .vector origin;
3 .vector velocity;
4 .float HookSilent;
5 .float HookRange;
6
7 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg)
8 {
9         // I want to draw a quad...
10         // from and to are MIDPOINTS.
11         
12         vector axis, thickdir, A, B, C, D;
13         float length_tex;
14
15         axis = normalize(to - from);
16         length_tex = aspect * vlen(to - from) / thickness;
17
18         // direction is perpendicular to the view normal, and perpendicular to the axis
19         thickdir = normalize(cross(axis, vieworg - from));
20
21         A = from - thickdir * (thickness / 2);
22         B = from + thickdir * (thickness / 2);
23         C = to + thickdir * (thickness / 2);
24         D = to - thickdir * (thickness / 2);
25
26         R_BeginPolygon(texture, drawflag);
27         R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, theAlpha);
28         R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, theAlpha);
29         R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
30         R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
31         R_EndPolygon();
32 }
33
34 string Draw_GrapplingHook_trace_callback_tex;
35 float Draw_GrapplingHook_trace_callback_rnd;
36 vector Draw_GrapplingHook_trace_callback_rgb;
37 float Draw_GrapplingHook_trace_callback_a;
38 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
39 {
40         float i;
41         vector vorg;
42         vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
43         for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
44                 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);
45         Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
46 }
47
48 .float teleport_time;
49 void Draw_GrapplingHook()
50 {
51         vector a, b, atrans;
52         string tex;
53         vector rgb;
54         float t;
55         float s;
56         vector vs;
57         float intensity, offset;
58
59         if(self.teleport_time)
60         if(time > self.teleport_time)
61         {
62                 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTN_NORM); // safeguard
63                 self.teleport_time = 0;
64         }
65
66         InterpolateOrigin_Do();
67
68         s = autocvar_cl_gunalign;
69         if(s != 1 && s != 2 && s != 4)
70                 s = 3; // default value
71         --s;
72         switch(self.HookType)
73         {
74                 default:
75                 case ENT_CLIENT_HOOK:
76                         vs = hook_shotorigin[s];
77                         break;
78                 case ENT_CLIENT_ELECTRO_BEAM:
79                         vs = electro_shotorigin[s];
80                         break;
81                 case ENT_CLIENT_LIGHTNING_BEAM:
82                         vs = lightning_shotorigin[s];
83                         break;
84                 case ENT_CLIENT_GAUNTLET:
85                         vs = gauntlet_shotorigin[s];
86                         break;
87         }
88
89         if((self.owner.sv_entnum == player_localentnum - 1))
90         {
91                 switch(self.HookType)
92                 {
93                         default:
94                         case ENT_CLIENT_HOOK:
95                                 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
96                                 b = self.origin;
97                                 break;
98                         case ENT_CLIENT_ELECTRO_BEAM:
99                         case ENT_CLIENT_LIGHTNING_BEAM:
100                         case ENT_CLIENT_GAUNTLET:
101                                 if(self.HookRange)
102                                         b = view_origin + view_forward * self.HookRange;
103                                 else
104                                         b = view_origin + view_forward * vlen(self.velocity - self.origin); // honor original length of beam!
105                                 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
106                                 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
107                                 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
108                                 break;
109                 }
110         }
111         else
112         {
113                 switch(self.HookType)
114                 {
115                         default:
116                         case ENT_CLIENT_HOOK:
117                                 a = self.velocity;
118                                 b = self.origin;
119                                 break;
120                         case ENT_CLIENT_ELECTRO_BEAM:
121                         case ENT_CLIENT_LIGHTNING_BEAM:
122                         case ENT_CLIENT_GAUNTLET:
123                                 a = self.origin;
124                                 b = self.velocity;
125                                 break;
126                 }
127         }
128
129         t = GetPlayerColorForce(self.owner.sv_entnum);
130
131         switch(self.HookType)
132         {
133                 default:
134                 case ENT_CLIENT_HOOK:
135                         intensity = 1;
136                         offset = 0;
137                         if(t == NUM_TEAM_1)
138                         {
139                                 tex = "particles/hook_red";
140                                 rgb = '1 .3 .3';
141                         }
142                         else if(t == NUM_TEAM_2)
143                         {
144                                 tex = "particles/hook_blue";
145                                 rgb = '.3 .3 1';
146                         }
147                         else if(t == NUM_TEAM_3)
148                         {
149                                 tex = "particles/hook_yellow";
150                                 rgb = '1 1 .3';
151                         }
152                         else if(t == NUM_TEAM_4)
153                         {
154                                 tex = "particles/hook_pink";
155                                 rgb = '1 .3 1';
156                         }
157                         else
158                         {
159                                 tex = "particles/hook_green";
160                                 rgb = '.3 1 .3';
161                         }
162                         break;
163                 case ENT_CLIENT_ELECTRO_BEAM:
164                         intensity = bound(0.2, 1 + Noise_Pink(self, frametime) * 1 + Noise_Burst(self, frametime, 0.03) * 0.3, 2);
165                         offset = Noise_Brown(self, frametime) * 10;
166                         tex = "particles/lgbeam";
167                         rgb = '1 1 1';
168                         break;
169                 case ENT_CLIENT_LIGHTNING_BEAM: // todo
170                         intensity = bound(0.2, 1 + Noise_Pink(self, frametime) * 1 + Noise_Burst(self, frametime, 0.03) * 0.3, 2);
171                         offset = Noise_Brown(self, frametime) * 10;
172                         tex = "particles/lgbeam";
173                         rgb = '1 1 1';
174                         break;
175                 case ENT_CLIENT_GAUNTLET:
176                         intensity = 1;
177                         offset = Noise_White(self, frametime);
178                         tex = "particles/gauntletbeam";
179                         rgb = '1 1 1';
180                         break;
181         }
182
183         Draw_GrapplingHook_trace_callback_tex = tex;
184         Draw_GrapplingHook_trace_callback_rnd = offset;
185         Draw_GrapplingHook_trace_callback_rgb = rgb;
186         Draw_GrapplingHook_trace_callback_a = intensity;
187         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);
188         Draw_GrapplingHook_trace_callback_tex = string_null;
189
190         atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
191
192         switch(self.HookType)
193         {
194                 default:
195                 case ENT_CLIENT_HOOK:
196                         if(vlen(trace_endpos - atrans) > 0.5)
197                         {
198                                 setorigin(self, trace_endpos); // hook endpoint!
199                                 self.angles = vectoangles(trace_endpos - atrans);
200                                 self.drawmask = MASK_NORMAL;
201                         }
202                         else
203                         {
204                                 self.drawmask = 0;
205                         }
206                         break;
207                 case ENT_CLIENT_ELECTRO_BEAM:
208                 case ENT_CLIENT_LIGHTNING_BEAM:
209                 case ENT_CLIENT_GAUNTLET:
210                         setorigin(self, a); // beam origin!
211                         break;
212         }
213
214         switch(self.HookType)
215         {
216                 default:
217                 case ENT_CLIENT_HOOK:
218                         break;
219                 case ENT_CLIENT_ELECTRO_BEAM:
220                         pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity); // todo: new effect
221                         break;
222                 case ENT_CLIENT_LIGHTNING_BEAM:
223                         pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity); // todo: new effect
224                         break;
225                 case ENT_CLIENT_GAUNTLET:
226                         pointparticles(particleeffectnum("gauntlet_lightning"), b, normalize(a - b), frametime * intensity);
227                         break;
228         }
229 }
230
231 void Remove_GrapplingHook()
232 {
233         sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTN_NORM);
234 }
235
236 void Ent_ReadHook(float bIsNew, float type)
237 {
238         self.HookType = type;
239
240         float sf;
241         sf = ReadByte();
242
243         self.HookSilent = (sf & 0x80);
244         self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
245
246         InterpolateOrigin_Undo();
247
248         if(sf & 1)
249         {
250                 self.owner = playerslots[ReadByte() - 1];
251                 switch(self.HookType)
252                 {
253                         default:
254                         case ENT_CLIENT_HOOK:
255                         case ENT_CLIENT_GAUNTLET:
256                                 self.HookRange = 0;
257                                 break;
258                         case ENT_CLIENT_ELECTRO_BEAM:
259                         case ENT_CLIENT_LIGHTNING_BEAM:
260                                 self.HookRange = ReadCoord();
261                                 break;
262                 }
263         }
264         if(sf & 2)
265         {
266                 self.origin_x = ReadCoord();
267                 self.origin_y = ReadCoord();
268                 self.origin_z = ReadCoord();
269                 setorigin(self, self.origin);
270         }
271         if(sf & 4)
272         {
273                 self.velocity_x = ReadCoord();
274                 self.velocity_y = ReadCoord();
275                 self.velocity_z = ReadCoord();
276         }
277
278         InterpolateOrigin_Note();
279
280         if(bIsNew || !self.teleport_time)
281         {
282                 self.draw = Draw_GrapplingHook;
283                 self.entremove = Remove_GrapplingHook;
284
285                 switch(self.HookType)
286                 {
287                         default:
288                         case ENT_CLIENT_HOOK:
289                                 // for the model
290                                 setmodel(self, "models/hook.md3");
291                                 self.drawmask = MASK_NORMAL;
292                                 break;
293                         case ENT_CLIENT_ELECTRO_BEAM:
294                                 sound (self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTN_NORM);
295                                 break;
296                         case ENT_CLIENT_LIGHTNING_BEAM:
297                                 sound (self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTN_NORM);
298                                 break;
299                         case ENT_CLIENT_GAUNTLET:
300                                 sound (self, CH_SHOTS_SINGLE, "weapons/gauntletbeam_fly.wav", VOL_BASE, ATTN_NORM);
301                                 break;
302                 }
303         }
304
305         self.teleport_time = time + 10;
306 }
307
308 void Hook_Precache()
309 {
310         precache_sound("weapons/lgbeam_fly.wav");
311         precache_sound("weapons/gauntletbeam_fly.wav");
312         precache_model("models/hook.md3");
313 }
314
315 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!