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