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