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