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