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