]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hook.qc
Merge remote-tracking branch 'origin/Mario/bot_fire_fix', fixes #1955
[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, ATTEN_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_LGBEAM:
79                         vs = electro_shotorigin[s];
80                         break;
81                 case ENT_CLIENT_GAUNTLET:
82                         vs = gauntlet_shotorigin[s];
83                         break;
84         }
85
86         if((self.owner.sv_entnum == player_localentnum - 1) && autocvar_chase_active <= 0)
87         {
88                 switch(self.HookType)
89                 {
90                         default:
91                         case ENT_CLIENT_HOOK:
92                                 a = view_origin + view_forward * vs_x + view_right * -vs_y + view_up * vs_z;
93                                 b = self.origin;
94                                 break;
95                         case ENT_CLIENT_LGBEAM:
96                         case ENT_CLIENT_GAUNTLET:
97                                 if(self.HookRange)
98                                         b = view_origin + view_forward * self.HookRange;
99                                 else
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;
104                                 break;
105                 }
106         }
107         else
108         {
109                 switch(self.HookType)
110                 {
111                         default:
112                         case ENT_CLIENT_HOOK:
113                                 a = self.velocity;
114                                 b = self.origin;
115                                 break;
116                         case ENT_CLIENT_LGBEAM:
117                         case ENT_CLIENT_GAUNTLET:
118                                 a = self.origin;
119                                 b = self.velocity;
120                                 break;
121                 }
122         }
123
124         t = GetPlayerColorForce(self.owner.sv_entnum);
125
126         switch(self.HookType)
127         {
128                 default:
129                 case ENT_CLIENT_HOOK:
130                         intensity = 1;
131                         offset = 0;
132                         switch(t)
133                         {
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;
139                         }
140                         break;
141                 case ENT_CLIENT_LGBEAM:
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";
145                         rgb = '1 1 1';
146                         break;
147                 case ENT_CLIENT_GAUNTLET:
148                         intensity = 1;
149                         offset = Noise_White(self, frametime);
150                         tex = "particles/gauntletbeam";
151                         rgb = '1 1 1';
152                         break;
153         }
154
155         Draw_GrapplingHook_trace_callback_tex = tex;
156         Draw_GrapplingHook_trace_callback_rnd = offset;
157         Draw_GrapplingHook_trace_callback_rgb = rgb;
158         Draw_GrapplingHook_trace_callback_a = intensity;
159         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);
160         Draw_GrapplingHook_trace_callback_tex = string_null;
161
162         atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
163
164         switch(self.HookType)
165         {
166                 default:
167                 case ENT_CLIENT_HOOK:
168                         if(vlen(trace_endpos - atrans) > 0.5)
169                         {
170                                 setorigin(self, trace_endpos); // hook endpoint!
171                                 self.angles = vectoangles(trace_endpos - atrans);
172                                 self.drawmask = MASK_NORMAL;
173                         }
174                         else
175                         {
176                                 self.drawmask = 0;
177                         }
178                         break;
179                 case ENT_CLIENT_LGBEAM:
180                 case ENT_CLIENT_GAUNTLET:
181                         setorigin(self, a); // beam origin!
182                         break;
183         }
184
185         switch(self.HookType)
186         {
187                 default:
188                 case ENT_CLIENT_HOOK:
189                         break;
190                 case ENT_CLIENT_LGBEAM:
191                         pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity);
192                         break;
193                 case ENT_CLIENT_GAUNTLET:
194                         pointparticles(particleeffectnum("gauntlet_lightning"), b, normalize(a - b), frametime * intensity);
195                         break;
196         }
197 }
198
199 void Remove_GrapplingHook()
200 {
201         sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
202 }
203
204 void Ent_ReadHook(float bIsNew, float type)
205 {
206         self.HookType = type;
207
208         float sf;
209         sf = ReadByte();
210
211         self.HookSilent = (sf & 0x80);
212         self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
213
214         InterpolateOrigin_Undo();
215
216         if(sf & 1)
217         {
218                 float myowner = ReadByte();
219                 self.owner = playerslots[myowner - 1];
220                 self.sv_entnum = myowner;
221                 switch(self.HookType)
222                 {
223                         default:
224                         case ENT_CLIENT_HOOK:
225                         case ENT_CLIENT_GAUNTLET:
226                                 self.HookRange = 0;
227                                 break;
228                         case ENT_CLIENT_LGBEAM:
229                                 self.HookRange = ReadCoord();
230                                 break;
231                 }
232         }
233         if(sf & 2)
234         {
235                 self.origin_x = ReadCoord();
236                 self.origin_y = ReadCoord();
237                 self.origin_z = ReadCoord();
238                 setorigin(self, self.origin);
239         }
240         if(sf & 4)
241         {
242                 self.velocity_x = ReadCoord();
243                 self.velocity_y = ReadCoord();
244                 self.velocity_z = ReadCoord();
245         }
246
247         InterpolateOrigin_Note();
248
249         if(bIsNew || !self.teleport_time)
250         {
251                 self.draw = Draw_GrapplingHook;
252                 self.entremove = Remove_GrapplingHook;
253
254                 switch(self.HookType)
255                 {
256                         default:
257                         case ENT_CLIENT_HOOK:
258                                 // for the model
259                                 setmodel(self, "models/hook.md3");
260                                 self.drawmask = MASK_NORMAL;
261                                 break;
262                         case ENT_CLIENT_LGBEAM:
263                                 sound (self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
264                                 break;
265                         case ENT_CLIENT_GAUNTLET:
266                                 sound (self, CH_SHOTS_SINGLE, "weapons/gauntletbeam_fly.wav", VOL_BASE, ATTEN_NORM);
267                                 break;
268                 }
269         }
270
271         self.teleport_time = time + 10;
272 }
273
274 void Hook_Precache()
275 {
276         precache_sound("weapons/lgbeam_fly.wav");
277         precache_sound("weapons/gauntletbeam_fly.wav");
278         precache_model("models/hook.md3");
279 }
280
281 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!