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