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