]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/projectile.qc
[11:57:02] <@LordHavoc> div0: or just remove the seeker for me and say "LordHavoc...
[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                 self.trail_oldorigin = self.origin;
242         }
243
244         if(f & 2)
245         {
246                 self.cnt = ReadByte();
247
248                 self.silent = (self.cnt & 0x80);
249                 self.cnt = (self.cnt & 0x7F);
250
251                 self.scale = 1;
252                 switch(self.cnt)
253                 {
254                         case PROJECTILE_ELECTRO: setmodel(self, "models/ebomb.mdl"); break;
255                         case PROJECTILE_ROCKET: setmodel(self, "models/rocket.md3"); self.scale = 2; break;
256                         case PROJECTILE_BULLET: setmodel(self, "models/tracer.mdl"); break;
257                         case PROJECTILE_BULLET_GLOWING: setmodel(self, "models/tracer.mdl"); break;
258                         case PROJECTILE_CRYLINK: setmodel(self, "models/plasmatrail.mdl"); break;
259                         case PROJECTILE_CRYLINK_BOUNCING: setmodel(self, "models/plasmatrail.mdl"); break;
260                         case PROJECTILE_ELECTRO_BEAM: setmodel(self, "models/elaser.mdl"); break;
261                         case PROJECTILE_GRENADE: setmodel(self, "models/grenademodel.md3"); break;
262                         case PROJECTILE_GRENADE_BOUNCING: setmodel(self, "models/grenademodel.md3"); break;
263                         case PROJECTILE_LASER: setmodel(self, "models/laser.mdl"); break;
264                         case PROJECTILE_HLAC: setmodel(self, "models/hlac_bullet.md3"); break;
265                         case PROJECTILE_PORTO_RED: setmodel(self, "models/grenademodel.md3"); self.scale = 4; break;
266                         case PROJECTILE_PORTO_BLUE: setmodel(self, "models/grenademodel.md3"); self.scale = 4; break;
267                         case PROJECTILE_HOOKBOMB: setmodel(self, "models/grenademodel.md3"); break;
268                         case PROJECTILE_HAGAR: setmodel(self, "models/hagarmissile.mdl"); self.scale = 0.4; break;
269                         case PROJECTILE_HAGAR_BOUNCING: setmodel(self, "models/hagarmissile.mdl"); self.scale = 0.4; break;
270                         default:
271                                 error("Received invalid CSQC projectile, can't work with this!");
272                                 break;
273                 }
274
275                 self.mins = '0 0 0';
276                 self.maxs = '0 0 0';
277                 self.colormod = '0 0 0';
278                 self.move_touch = SUB_Stop;
279                 self.move_movetype = MOVETYPE_TOSS;
280
281                 switch(self.cnt)
282                 {
283                         case PROJECTILE_ELECTRO:
284                                 // only new engines support sound moving with object
285                                 loopsound(self, CHAN_PROJECTILE, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
286                                 self.mins = '0 0 -3';
287                                 self.maxs = '0 0 -3';
288                                 self.move_movetype = MOVETYPE_BOUNCE;
289                                 self.move_touch = SUB_Null;
290                                 break;
291                         case PROJECTILE_ROCKET:
292                                 loopsound(self, CHAN_PROJECTILE, "weapons/rocket_fly.wav", VOL_BASE, ATTN_NORM);
293                                 self.mins = '-3 -3 -3';
294                                 self.maxs = '3 3 3';
295                                 break;
296                         case PROJECTILE_GRENADE:
297                                 self.mins = '0 0 -3';
298                                 self.maxs = '0 0 -3';
299                                 break;
300                         case PROJECTILE_GRENADE_BOUNCING:
301                                 self.mins = '0 0 -3';
302                                 self.maxs = '0 0 -3';
303                                 self.move_movetype = MOVETYPE_BOUNCE;
304                                 self.move_touch = SUB_Null;
305                                 break;
306                         case PROJECTILE_PORTO_RED:
307                                 self.colormod = '2 1 1';
308                                 self.alpha = 0.5;
309                                 self.move_movetype = MOVETYPE_BOUNCE;
310                                 self.move_touch = SUB_Null;
311                                 break;
312                         case PROJECTILE_PORTO_BLUE:
313                                 self.colormod = '1 1 2';
314                                 self.alpha = 0.5;
315                                 self.move_movetype = MOVETYPE_BOUNCE;
316                                 self.move_touch = SUB_Null;
317                                 break;
318                         case PROJECTILE_HAGAR_BOUNCING:
319                                 self.move_movetype = MOVETYPE_BOUNCE;
320                                 self.move_touch = SUB_Null;
321                                 break;
322                         case PROJECTILE_CRYLINK_BOUNCING:
323                                 self.move_movetype = MOVETYPE_BOUNCE;
324                                 self.move_touch = SUB_Null;
325                                 break;
326                         default:
327                                 break;
328                 }
329         }
330
331         if(self.gravity)
332         {
333                 if(self.move_movetype == MOVETYPE_FLY)
334                         self.move_movetype = MOVETYPE_TOSS;
335                 if(self.move_movetype == MOVETYPE_BOUNCEMISSILE)
336                         self.move_movetype = MOVETYPE_BOUNCE;
337         }
338         else
339         {
340                 if(self.move_movetype == MOVETYPE_TOSS)
341                         self.move_movetype = MOVETYPE_FLY;
342                 if(self.move_movetype == MOVETYPE_BOUNCE)
343                         self.move_movetype = MOVETYPE_BOUNCEMISSILE;
344         }
345
346         if(!(self.count & 0x80))
347                 InterpolateOrigin_Note();
348         
349         self.draw = Projectile_Draw;
350         self.entremove = Ent_RemoveProjectile;
351 }
352
353 void Projectile_Precache()
354 {
355         precache_model("models/ebomb.mdl");
356         precache_model("models/elaser.mdl");
357         precache_model("models/grenademodel.md3");
358         precache_model("models/hagarmissile.mdl");
359         precache_model("models/hlac_bullet.md3");
360         precache_model("models/laser.mdl");
361         precache_model("models/plasmatrail.mdl");
362         precache_model("models/rocket.md3");
363         precache_model("models/tracer.mdl");
364         precache_sound("weapons/electro_fly.wav");
365         precache_sound("weapons/rocket_fly.wav");
366 }