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