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