]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/projectile.qc
Merge remote branch 'origin/fruitiex/gakarmor'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / projectile.qc
1 .vector iorigin1, iorigin2;
2 .float spawntime;
3 .vector trail_oldorigin;
4 .float trail_oldtime;
5 .float fade_time, fade_rate;
6
7 void SUB_Null()
8 {
9 }
10
11 void SUB_Stop()
12 {
13         self.move_velocity = self.move_avelocity = '0 0 0';
14         self.move_movetype = MOVETYPE_NONE;
15 }
16
17 .float alphamod;
18 .float count; // set if clientside projectile
19 .float cnt; // sound index
20 .float gravity;
21 .float snd_looping;
22 .float silent;
23 .float traileffect;
24
25 void Projectile_ResetTrail(vector to)
26 {
27         self.trail_oldorigin = to;
28         self.trail_oldtime = time;
29 }
30 void Projectile_DrawTrail(vector to)
31 {
32         vector from;
33         float t0;
34         from = self.trail_oldorigin;
35         t0 = self.trail_oldtime;
36         self.trail_oldorigin = to;
37         self.trail_oldtime = time;
38
39         // force the effect even for stationary firemine
40         if(self.cnt == PROJECTILE_FIREMINE)
41                 if(from == to)
42                         from_z += 1;
43
44         if (self.traileffect)
45         {
46                 particles_alphamin = particles_alphamax = sqrt(self.alpha);
47                 boxparticles(self.traileffect, self, from, to, self.velocity, self.velocity, sqrt(self.alpha), PARTICLES_USEALPHA);
48         }
49 }
50
51 void Projectile_Draw()
52 {
53         vector rot;
54         vector trailorigin;
55         float f;
56         float drawn;
57         float t;
58         float a;
59
60         f = self.move_flags;
61
62         if(self.count & 0x80)
63         {
64                 //self.move_flags &~= FL_ONGROUND;
65                 if(self.move_movetype == MOVETYPE_NONE || self.move_movetype == MOVETYPE_FLY)
66                         Movetype_Physics_NoMatchServer();
67                         // the trivial movetypes do not have to match the
68                         // server's ticrate as they are ticrate independent
69                         // NOTE: this assumption is only true if MOVETYPE_FLY
70                         // projectiles detonate on impact. If they continue
71                         // moving, we might still be ticrate dependent.
72                 else
73                         Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
74                 if(!(self.move_flags & FL_ONGROUND))
75                         if(self.velocity != '0 0 0')
76                                 self.angles = vectoangles(self.velocity);
77         }
78         else
79         {
80                 InterpolateOrigin_Do();
81         }
82
83         if(self.count & 0x80)
84         {
85                 drawn = (time >= self.spawntime - 0.02);
86                 t = max(time, self.spawntime);
87         }
88         else
89         {
90                 drawn = (self.iflags & IFLAG_VALID);
91                 t = time;
92         }
93
94         if(!(f & FL_ONGROUND))
95         {
96                 rot = '0 0 0';
97                 switch(self.cnt)
98                 {
99                         /*
100                         case PROJECTILE_GRENADE:
101                                 rot = '-2000 0 0'; // forward
102                                 break;
103                         */
104                         case PROJECTILE_GRENADE_BOUNCING:
105                                 rot = '0 -1000 0'; // sideways
106                                 break;
107                         case PROJECTILE_HOOKBOMB:
108                                 rot = '1000 0 0'; // forward
109                                 break;
110                         default:
111                                 break;
112                 }
113                 self.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(self.angles), rot * (t - self.spawntime)));
114         }
115
116         vector ang;
117         ang = self.angles;
118         ang_x = -ang_x;
119         makevectors(ang);
120
121         a = 1 - (time - self.fade_time) * self.fade_rate;
122         self.alpha = bound(0, self.alphamod * a, 1);
123         if(self.alpha <= 0)
124                 drawn = 0;
125         self.renderflags = 0;
126
127         trailorigin = self.origin;
128         switch(self.cnt)
129         {
130                 case PROJECTILE_GRENADE:
131                 case PROJECTILE_GRENADE_BOUNCING:
132                         trailorigin += v_right * 1 + v_forward * -10;
133                         break;
134                 default:
135                         break;
136         }
137         if(drawn)
138                 Projectile_DrawTrail(trailorigin);
139         else
140                 Projectile_ResetTrail(trailorigin);
141
142         if(!drawn)
143                 return;
144
145         switch(self.cnt)
146         {
147                 case PROJECTILE_BULLET_GLOWING:
148                 case PROJECTILE_BULLET_GLOWING_TRACER:
149                         R_AddDynamicLight(self.origin, 50 * a, '1 1 0');
150                         break;
151                 default:
152                         break;
153         }
154
155         R_AddEntity(self);
156 }
157
158 void loopsound(entity e, float ch, string samp, float vol, float attn)
159 {
160         if(self.silent)
161                 return;
162
163         sound(e, ch, samp, vol, attn);
164         e.snd_looping = 1;
165 }
166
167 void Ent_RemoveProjectile()
168 {
169         if(self.snd_looping)
170                 sound(self, CHAN_PROJECTILE, "misc/null.wav", VOL_BASE, ATTN_NORM);
171
172         if(self.count & 0x80)
173         {
174                 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.05, MOVE_NORMAL, self);
175                 Projectile_DrawTrail(trace_endpos);
176         }
177 }
178
179 void Ent_Projectile()
180 {
181         float f;
182
183         // projectile properties:
184         //   kind (interpolated, or clientside)
185         //
186         //   modelindex
187         //   origin
188         //   scale
189         //   if clientside:
190         //     velocity
191         //     gravity
192         //   soundindex (hardcoded list)
193         //   effects
194         //
195         // projectiles don't send angles, because they always follow the velocity
196         
197         f = ReadByte();
198         self.count = (f & 0x80);
199         self.iflags = (self.iflags & IFLAG_INTERNALMASK) | IFLAG_AUTOANGLES | IFLAG_ANGLES;
200         self.solid = SOLID_TRIGGER;
201         //self.effects = EF_NOMODELFLAGS;
202
203         // this should make collisions with bmodels more exact, but it leads to
204         // projectiles no longer being able to lie on a bmodel
205         self.move_nomonsters = MOVE_WORLDONLY;
206         if(f & 0x40)
207                 self.move_flags |= FL_ONGROUND;
208         else
209                 self.move_flags &~= FL_ONGROUND;
210
211         if(!self.move_time)
212         {
213                 // for some unknown reason, we don't need to care for
214                 // sv_gameplayfix_delayprojectiles here.
215                 self.move_time = time;
216                 self.spawntime = time;
217         }
218         else
219                 self.move_time = max(self.move_time, time);
220
221         if(!(self.count & 0x80))
222                 InterpolateOrigin_Undo();
223
224         if(f & 1)
225         {
226                 self.origin_x = ReadCoord();
227                 self.origin_y = ReadCoord();
228                 self.origin_z = ReadCoord();
229                 if(self.count & 0x80)
230                 {
231                         self.velocity_x = ReadCoord();
232                         self.velocity_y = ReadCoord();
233                         self.velocity_z = ReadCoord();
234                         if(f & 0x10)
235                                 self.gravity = ReadCoord();
236                         else
237                                 self.gravity = 0; // none
238                         self.move_origin = self.origin;
239                         self.move_velocity = self.velocity;
240                 }
241
242                 if(time == self.spawntime || (self.count & 0x80) || (f & 0x08))
243                 {
244                         self.trail_oldorigin = self.origin;
245                         if(!(self.count & 0x80))
246                                 InterpolateOrigin_Reset();
247                 }
248
249                 if(f & 0x20)
250                 {
251                         self.fade_time = time + ReadByte() * ticrate;
252                         self.fade_rate = 1 / (ReadByte() * ticrate);
253                 }
254                 else
255                 {
256                         self.fade_time = 0;
257                         self.fade_rate = 0;
258                 }
259         }
260
261         if(f & 2)
262         {
263                 self.cnt = ReadByte();
264
265                 self.silent = (self.cnt & 0x80);
266                 self.cnt = (self.cnt & 0x7F);
267
268                 self.scale = 1;
269                 self.traileffect = 0;
270                 switch(self.cnt)
271                 {
272                         case PROJECTILE_ELECTRO: setmodel(self, "models/ebomb.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
273                         case PROJECTILE_ROCKET: setmodel(self, "models/rocket.md3");self.traileffect = particleeffectnum("TR_ROCKET"); self.scale = 2; break;
274                         case PROJECTILE_BULLET: setmodel(self, "models/tracer.mdl");self.traileffect = particleeffectnum("tr_bullet"); break;
275                         case PROJECTILE_BULLET_GLOWING: setmodel(self, "models/tracer.mdl");self.traileffect = particleeffectnum("tr_bullet"); break;
276                         case PROJECTILE_BULLET_GLOWING_TRACER: setmodel(self, "models/tracer.mdl");self.traileffect = particleeffectnum("tr_rifle"); break;
277                         case PROJECTILE_CRYLINK: setmodel(self, "models/plasmatrail.mdl");self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
278                         case PROJECTILE_CRYLINK_BOUNCING: setmodel(self, "models/plasmatrail.mdl");self.traileffect = particleeffectnum("TR_CRYLINKPLASMA"); break;
279                         case PROJECTILE_ELECTRO_BEAM: setmodel(self, "models/elaser.mdl");self.traileffect = particleeffectnum("TR_NEXUIZPLASMA"); break;
280                         case PROJECTILE_GRENADE: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
281                         case PROJECTILE_GRENADE_BOUNCING: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_GRENADE"); break;
282                         case PROJECTILE_MINE: setmodel(self, "models/mine.md3");self.traileffect = particleeffectnum(""); break;
283                         case PROJECTILE_LASER: setmodel(self, "models/laser.mdl");self.traileffect = particleeffectnum(""); break;
284                         case PROJECTILE_HLAC: setmodel(self, "models/hlac_bullet.md3");self.traileffect = particleeffectnum(""); break;
285                         case PROJECTILE_PORTO_RED: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_WIZSPIKE"); self.scale = 4; break;
286                         case PROJECTILE_PORTO_BLUE: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_WIZSPIKE"); self.scale = 4; break;
287                         case PROJECTILE_HOOKBOMB: setmodel(self, "models/grenademodel.md3");self.traileffect = particleeffectnum("TR_KNIGHTSPIKE"); break;
288                         case PROJECTILE_HAGAR: setmodel(self, "models/hagarmissile.mdl");self.traileffect = particleeffectnum("TR_GRENADE"); self.scale = 0.4; break;
289                         case PROJECTILE_HAGAR_BOUNCING: setmodel(self, "models/hagarmissile.mdl");self.traileffect = particleeffectnum("TR_GRENADE"); self.scale = 0.4; break;
290                         case PROJECTILE_FIREBALL: self.model = ""; self.modelindex = 0; self.traileffect = particleeffectnum("fireball"); break; // particle effect is good enough
291                         case PROJECTILE_FIREMINE: self.model = ""; self.modelindex = 0; self.traileffect = particleeffectnum("firemine"); break; // particle effect is good enough
292                         case PROJECTILE_TAG: setmodel(self, "models/laser.mdl"); self.traileffect = particleeffectnum("TR_ROCKET"); break;
293                         case PROJECTILE_FLAC: setmodel(self, "models/hagarmissile.mdl"); self.scale = 0.4; self.traileffect = particleeffectnum("TR_ROCKET"); break;
294                         case PROJECTILE_SEEKER: setmodel(self, "models/tagrocket.md3"); self.scale = 2; self.traileffect = particleeffectnum("TR_ROCKET"); break;
295                         default:
296                                 error("Received invalid CSQC projectile, can't work with this!");
297                                 break;
298                 }
299
300                 self.mins = '0 0 0';
301                 self.maxs = '0 0 0';
302                 self.colormod = '0 0 0';
303                 self.move_touch = SUB_Stop;
304                 self.move_movetype = MOVETYPE_TOSS;
305                 self.alphamod = 1;
306
307                 switch(self.cnt)
308                 {
309                         case PROJECTILE_ELECTRO:
310                                 // only new engines support sound moving with object
311                                 loopsound(self, CHAN_PROJECTILE, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
312                                 self.mins = '0 0 -4';
313                                 self.maxs = '0 0 -4';
314                                 self.move_movetype = MOVETYPE_BOUNCE;
315                                 self.move_touch = SUB_Null;
316                                 break;
317                         case PROJECTILE_ROCKET:
318                                 loopsound(self, CHAN_PROJECTILE, "weapons/rocket_fly.wav", VOL_BASE, ATTN_NORM);
319                                 self.mins = '-3 -3 -3';
320                                 self.maxs = '3 3 3';
321                                 break;
322                         case PROJECTILE_GRENADE:
323                                 self.mins = '-3 -3 -3';
324                                 self.maxs = '3 3 3';
325                                 break;
326                         case PROJECTILE_GRENADE_BOUNCING:
327                                 self.mins = '-3 -3 -3';
328                                 self.maxs = '3 3 3';
329                                 self.move_movetype = MOVETYPE_BOUNCE;
330                                 self.move_touch = SUB_Null;
331                                 self.move_bounce_factor = g_balance_grenadelauncher_secondary_bouncefactor;
332                                 self.move_bounce_stopspeed = g_balance_grenadelauncher_secondary_bouncestop;
333                                 break;
334                         case PROJECTILE_MINE:
335                                 self.mins = '-4 -4 -4';
336                                 self.maxs = '4 4 4';
337                                 break;
338                         case PROJECTILE_PORTO_RED:
339                                 self.colormod = '2 1 1';
340                                 self.alphamod = 0.5;
341                                 self.move_movetype = MOVETYPE_BOUNCE;
342                                 self.move_touch = SUB_Null;
343                                 break;
344                         case PROJECTILE_PORTO_BLUE:
345                                 self.colormod = '1 1 2';
346                                 self.alphamod = 0.5;
347                                 self.move_movetype = MOVETYPE_BOUNCE;
348                                 self.move_touch = SUB_Null;
349                                 break;
350                         case PROJECTILE_HAGAR_BOUNCING:
351                                 self.move_movetype = MOVETYPE_BOUNCE;
352                                 self.move_touch = SUB_Null;
353                                 break;
354                         case PROJECTILE_CRYLINK_BOUNCING:
355                                 self.move_movetype = MOVETYPE_BOUNCE;
356                                 self.move_touch = SUB_Null;
357                                 break;
358                         case PROJECTILE_FIREBALL:
359                                 loopsound(self, CHAN_PROJECTILE, "weapons/fireball_fly2.wav", VOL_BASE, ATTN_NORM);
360                                 self.mins = '-16 -16 -16';
361                                 self.maxs = '16 16 16';
362                                 break;
363                         case PROJECTILE_FIREMINE:
364                                 loopsound(self, CHAN_PROJECTILE, "weapons/fireball_fly.wav", VOL_BASE, ATTN_NORM);
365                                 self.move_movetype = MOVETYPE_BOUNCE;
366                                 self.move_touch = SUB_Null;
367                                 self.mins = '-4 -4 -4';
368                                 self.maxs = '4 4 4';
369                                 break;
370                         case PROJECTILE_TAG:
371                                 loopsound(self, CHAN_PROJECTILE, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTN_NORM);
372                                 self.mins = '-2 -2 -2';
373                                 self.maxs = '2 2 2';
374                                 break;
375                         case PROJECTILE_FLAC:
376                                 self.mins = '-2 -2 -2';
377                                 self.maxs = '2 2 2';
378                                 break;
379                         case PROJECTILE_SEEKER:
380                                 self.mins = '-4 -4 -4';
381                                 self.maxs = '4 4 4';
382                                 break;
383                         default:
384                                 break;
385                 }
386         }
387
388         if(self.gravity)
389         {
390                 if(self.move_movetype == MOVETYPE_FLY)
391                         self.move_movetype = MOVETYPE_TOSS;
392                 if(self.move_movetype == MOVETYPE_BOUNCEMISSILE)
393                         self.move_movetype = MOVETYPE_BOUNCE;
394         }
395         else
396         {
397                 if(self.move_movetype == MOVETYPE_TOSS)
398                         self.move_movetype = MOVETYPE_FLY;
399                 if(self.move_movetype == MOVETYPE_BOUNCE)
400                         self.move_movetype = MOVETYPE_BOUNCEMISSILE;
401         }
402
403         if(!(self.count & 0x80))
404                 InterpolateOrigin_Note();
405         
406         self.draw = Projectile_Draw;
407         self.entremove = Ent_RemoveProjectile;
408 }
409
410 void Projectile_Precache()
411 {
412         precache_model("models/ebomb.mdl");
413         precache_model("models/elaser.mdl");
414         precache_model("models/grenademodel.md3");
415         precache_model("models/mine.md3");
416         precache_model("models/hagarmissile.mdl");
417         precache_model("models/hlac_bullet.md3");
418         precache_model("models/laser.mdl");
419         precache_model("models/plasmatrail.mdl");
420         precache_model("models/rocket.md3");
421         precache_model("models/tagrocket.md3");
422         precache_model("models/tracer.mdl");
423         precache_sound("weapons/electro_fly.wav");
424         precache_sound("weapons/rocket_fly.wav");
425         precache_sound("weapons/fireball_fly.wav");
426         precache_sound("weapons/fireball_fly2.wav");
427         precache_sound("weapons/tag_rocket_fly.wav");
428 }