]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hook.qc
Merge branch 'master' into terencehill/weapon_panel_fix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hook.qc
1 #include "hud.qh"
2 #include "noise.qh"
3 #include "../warpzonelib/common.qh"
4
5 .float HookType; // ENT_CLIENT_*
6 .vector origin;
7 .vector velocity;
8 .float HookSilent;
9 .float HookRange;
10
11 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg)
12 {
13         // I want to draw a quad...
14         // from and to are MIDPOINTS.
15
16         vector axis, thickdir, A, B, C, D;
17         float length_tex;
18
19         axis = normalize(to - from);
20         length_tex = aspect * vlen(to - from) / thickness;
21
22         // direction is perpendicular to the view normal, and perpendicular to the axis
23         thickdir = normalize(cross(axis, vieworg - from));
24
25         A = from - thickdir * (thickness / 2);
26         B = from + thickdir * (thickness / 2);
27         C = to + thickdir * (thickness / 2);
28         D = to - thickdir * (thickness / 2);
29
30         R_BeginPolygon(texture, drawflag);
31         R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, theAlpha);
32         R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, theAlpha);
33         R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
34         R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
35         R_EndPolygon();
36 }
37
38 string Draw_GrapplingHook_trace_callback_tex;
39 float Draw_GrapplingHook_trace_callback_rnd;
40 vector Draw_GrapplingHook_trace_callback_rgb;
41 float Draw_GrapplingHook_trace_callback_a;
42 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
43 {
44         float i;
45         vector vorg;
46         vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
47         for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
48                 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);
49         Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
50 }
51
52 .float teleport_time;
53 void Draw_GrapplingHook()
54 {
55         vector a, b, atrans;
56         string tex;
57         vector rgb;
58         float t;
59         int s;
60         vector vs;
61         float intensity, offset;
62
63         if(self.teleport_time)
64         if(time > self.teleport_time)
65         {
66                 sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM); // safeguard
67                 self.teleport_time = 0;
68         }
69
70         InterpolateOrigin_Do();
71
72         s = autocvar_cl_gunalign;
73         if(s != 1 && s != 2 && s != 4)
74                 s = 3; // default value
75         --s;
76         switch(self.HookType)
77         {
78                 default:
79                 case ENT_CLIENT_HOOK:
80                         vs = hook_shotorigin[s];
81                         break;
82                 case ENT_CLIENT_ARC_BEAM:
83                         vs = lightning_shotorigin[s];
84                         break;
85         }
86
87         if((self.owner.sv_entnum == player_localentnum - 1) && autocvar_chase_active <= 0)
88         {
89                 switch(self.HookType)
90                 {
91                         default:
92                         case ENT_CLIENT_HOOK:
93                                 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
94                                 b = self.origin;
95                                 break;
96                         case ENT_CLIENT_ARC_BEAM:
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_ARC_BEAM:
117                                 a = self.origin;
118                                 b = self.velocity;
119                                 break;
120                 }
121         }
122
123         t = GetPlayerColorForce(self.owner.sv_entnum);
124
125         switch(self.HookType)
126         {
127                 default:
128                 case ENT_CLIENT_HOOK:
129                         intensity = 1;
130                         offset = 0;
131                         switch(t)
132                         {
133                                 case NUM_TEAM_1: tex = "particles/hook_red"; rgb = '1 0.3 0.3'; break;
134                                 case NUM_TEAM_2: tex = "particles/hook_blue"; rgb = '0.3 0.3 1'; break;
135                                 case NUM_TEAM_3: tex = "particles/hook_yellow"; rgb = '1 1 0.3'; break;
136                                 case NUM_TEAM_4: tex = "particles/hook_pink"; rgb = '1 0.3 1'; break;
137                                 default: tex = "particles/hook_white"; rgb = getcsqcplayercolor(self.sv_entnum); break;
138                         }
139                         break;
140                 case ENT_CLIENT_ARC_BEAM: // todo
141                         intensity = bound(0.2, 1 + Noise_Pink(self, frametime) * 1 + Noise_Burst(self, frametime, 0.03) * 0.3, 2);
142                         offset = Noise_Brown(self, frametime) * 10;
143                         tex = "particles/lgbeam";
144                         rgb = '1 1 1';
145                         break;
146         }
147
148         Draw_GrapplingHook_trace_callback_tex = tex;
149         Draw_GrapplingHook_trace_callback_rnd = offset;
150         Draw_GrapplingHook_trace_callback_rgb = rgb;
151         Draw_GrapplingHook_trace_callback_a = intensity;
152         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);
153         Draw_GrapplingHook_trace_callback_tex = string_null;
154
155         atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
156
157         switch(self.HookType)
158         {
159                 default:
160                 case ENT_CLIENT_HOOK:
161                         if(vlen(trace_endpos - atrans) > 0.5)
162                         {
163                                 setorigin(self, trace_endpos); // hook endpoint!
164                                 self.angles = vectoangles(trace_endpos - atrans);
165                                 self.drawmask = MASK_NORMAL;
166                         }
167                         else
168                         {
169                                 self.drawmask = 0;
170                         }
171                         break;
172                 case ENT_CLIENT_ARC_BEAM:
173                         setorigin(self, a); // beam origin!
174                         break;
175         }
176
177         switch(self.HookType)
178         {
179                 default:
180                 case ENT_CLIENT_HOOK:
181                         break;
182                 case ENT_CLIENT_ARC_BEAM:
183                         pointparticles(particleeffectnum("electro_lightning"), trace_endpos, normalize(atrans - trace_endpos), frametime * intensity); // todo: new effect
184                         break;
185         }
186 }
187
188 void Remove_GrapplingHook()
189 {
190         sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
191 }
192
193 void Ent_ReadHook(float bIsNew, float type)
194 {
195         self.HookType = type;
196
197         int sf = ReadByte();
198
199         self.HookSilent = (sf & 0x80);
200         self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
201
202         InterpolateOrigin_Undo();
203
204         if(sf & 1)
205         {
206                 int myowner = ReadByte();
207                 self.owner = playerslots[myowner - 1];
208                 self.sv_entnum = myowner;
209                 switch(self.HookType)
210                 {
211                         default:
212                         case ENT_CLIENT_HOOK:
213                                 self.HookRange = 0;
214                                 break;
215                         case ENT_CLIENT_ARC_BEAM:
216                                 self.HookRange = ReadCoord();
217                                 break;
218                 }
219         }
220         if(sf & 2)
221         {
222                 self.origin_x = ReadCoord();
223                 self.origin_y = ReadCoord();
224                 self.origin_z = ReadCoord();
225                 setorigin(self, self.origin);
226         }
227         if(sf & 4)
228         {
229                 self.velocity_x = ReadCoord();
230                 self.velocity_y = ReadCoord();
231                 self.velocity_z = ReadCoord();
232         }
233
234         InterpolateOrigin_Note();
235
236         if(bIsNew || !self.teleport_time)
237         {
238                 self.draw = Draw_GrapplingHook;
239                 self.entremove = Remove_GrapplingHook;
240
241                 switch(self.HookType)
242                 {
243                         default:
244                         case ENT_CLIENT_HOOK:
245                                 // for the model
246                                 setmodel(self, "models/hook.md3");
247                                 self.drawmask = MASK_NORMAL;
248                                 break;
249                         case ENT_CLIENT_ARC_BEAM:
250                                 sound (self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
251                                 break;
252                 }
253         }
254
255         self.teleport_time = time + 10;
256 }
257
258 void Hook_Precache()
259 {
260         precache_sound("weapons/lgbeam_fly.wav");
261         precache_model("models/hook.md3");
262 }
263
264 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!