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