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