Hide the MOTD when going spec
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle / raptor.qc
1 #ifndef VEHICLE_RAPTOR
2 #define VEHICLE_RAPTOR
3 #include "raptor.qh"
4
5 #include "raptor_weapons.qc"
6
7 CLASS(Raptor, Vehicle)
8 /* spawnflags */ ATTRIB(Raptor, spawnflags, int, VHF_DMGSHAKE | VHF_DMGROLL);
9 /* mins       */ ATTRIB(Raptor, mins, vector, '-80 -80 0');
10 /* maxs       */ ATTRIB(Raptor, maxs, vector, '80 80 70');
11 /* model          */ ATTRIB(Raptor, mdl, string, "models/vehicles/raptor.dpm");
12 /* model          */ ATTRIB(Raptor, model, string, "models/vehicles/raptor.dpm");
13 /* head_model */ ATTRIB(Raptor, head_model, string, "");
14 /* hud_model  */ ATTRIB(Raptor, hud_model, string, "models/vehicles/raptor_cockpit.dpm");
15 /* tags       */ ATTRIB(Raptor, tag_head, string, "");
16 /* tags       */ ATTRIB(Raptor, tag_hud, string, "tag_hud");
17 /* tags       */ ATTRIB(Raptor, tag_view, string, "tag_camera");
18 /* netname    */ ATTRIB(Raptor, netname, string, "raptor");
19 /* fullname   */ ATTRIB(Raptor, vehicle_name, string, _("Raptor"));
20 /* icon       */ ATTRIB(Raptor, m_icon, string, "vehicle_raptor");
21 ENDCLASS(Raptor)
22 REGISTER_VEHICLE(RAPTOR, NEW(Raptor));
23
24 #endif
25
26 #ifdef IMPLEMENTATION
27
28 #include "raptor_weapons.qc"
29
30 #ifdef SVQC
31
32 bool autocvar_g_vehicle_raptor;
33
34 float autocvar_g_vehicle_raptor_respawntime;
35 float autocvar_g_vehicle_raptor_takeofftime;
36
37 float autocvar_g_vehicle_raptor_movestyle;
38 float autocvar_g_vehicle_raptor_turnspeed;
39 float autocvar_g_vehicle_raptor_pitchspeed;
40 float autocvar_g_vehicle_raptor_pitchlimit;
41
42 float autocvar_g_vehicle_raptor_speed_forward;
43 float autocvar_g_vehicle_raptor_speed_strafe;
44 float autocvar_g_vehicle_raptor_speed_up;
45 float autocvar_g_vehicle_raptor_speed_down;
46 float autocvar_g_vehicle_raptor_friction;
47
48 float autocvar_g_vehicle_raptor_cannon_turnspeed;
49 float autocvar_g_vehicle_raptor_cannon_turnlimit;
50 float autocvar_g_vehicle_raptor_cannon_pitchlimit_up;
51 float autocvar_g_vehicle_raptor_cannon_pitchlimit_down;
52
53 float autocvar_g_vehicle_raptor_cannon_locktarget;
54 float autocvar_g_vehicle_raptor_cannon_locking_time;
55 float autocvar_g_vehicle_raptor_cannon_locking_releasetime;
56 float autocvar_g_vehicle_raptor_cannon_locked_time;
57 float autocvar_g_vehicle_raptor_cannon_predicttarget;
58
59 float autocvar_g_vehicle_raptor_energy;
60 float autocvar_g_vehicle_raptor_energy_regen;
61 float autocvar_g_vehicle_raptor_energy_regen_pause;
62
63 float autocvar_g_vehicle_raptor_health;
64 float autocvar_g_vehicle_raptor_health_regen;
65 float autocvar_g_vehicle_raptor_health_regen_pause;
66
67 float autocvar_g_vehicle_raptor_shield;
68 float autocvar_g_vehicle_raptor_shield_regen;
69 float autocvar_g_vehicle_raptor_shield_regen_pause;
70
71 float autocvar_g_vehicle_raptor_bouncefactor;
72 float autocvar_g_vehicle_raptor_bouncestop;
73 vector autocvar_g_vehicle_raptor_bouncepain;
74
75 .entity bomb1;
76 .entity bomb2;
77
78 float raptor_altitude(float amax)
79 {SELFPARAM();
80         tracebox(self.origin, self.mins, self.maxs, self.origin - ('0 0 1' * amax), MOVE_WORLDONLY, self);
81         return vlen(self.origin - trace_endpos);
82 }
83
84 void raptor_land()
85 {SELFPARAM();
86         float hgt;
87
88         hgt = raptor_altitude(512);
89         self.velocity = (self.velocity * 0.9) + ('0 0 -1800' * (hgt / 256) * sys_frametime);
90         self.angles_x *= 0.95;
91         self.angles_z *= 0.95;
92
93         if(hgt < 128)
94         if(hgt > 0)
95                 self.frame = (hgt / 128) * 25;
96
97         self.bomb1.gun1.avelocity_y = 90 + ((self.frame / 25) * 2000);
98         self.bomb1.gun2.avelocity_y = -self.bomb1.gun1.avelocity_y;
99
100         if(hgt < 16)
101         {
102                 self.movetype = MOVETYPE_TOSS;
103                 self.think      = vehicles_think;
104                 self.frame      = 0;
105         }
106
107         self.nextthink  = time;
108
109         CSQCMODEL_AUTOUPDATE(self);
110 }
111
112 void raptor_exit(float eject)
113 {SELFPARAM();
114         vector spot;
115         self.tur_head.exteriormodeltoclient = world;
116
117         if(self.deadflag == DEAD_NO)
118         {
119                 self.think        = raptor_land;
120                 self.nextthink  = time;
121         }
122
123         if(!self.owner)
124                 return;
125
126         makevectors(self.angles);
127         if(eject)
128         {
129                 spot = self.origin + v_forward * 100 + '0 0 64';
130                 spot = vehicles_findgoodexit(spot);
131                 setorigin(self.owner , spot);
132                 self.owner.velocity = (v_up + v_forward * 0.25) * 750;
133                 self.owner.oldvelocity = self.owner.velocity;
134         }
135         else
136         {
137                 if(vlen(self.velocity) > 2 * autocvar_sv_maxairspeed)
138                 {
139                         self.owner.velocity = normalize(self.velocity) * autocvar_sv_maxairspeed * 2;
140                         self.owner.velocity_z += 200;
141                         spot = self.origin + v_forward * 32 + '0 0 64';
142                         spot = vehicles_findgoodexit(spot);
143                 }
144                 else
145                 {
146                         self.owner.velocity = self.velocity * 0.5;
147                         self.owner.velocity_z += 10;
148                         spot = self.origin - v_forward * 200 + '0 0 64';
149                         spot = vehicles_findgoodexit(spot);
150                 }
151                 self.owner.oldvelocity = self.owner.velocity;
152                 setorigin(self.owner , spot);
153         }
154
155         antilag_clear(self.owner);
156         self.owner = world;
157 }
158
159 float raptor_frame()
160 {SELFPARAM();
161         entity player, raptor;
162         float ftmp = 0;
163         vector df;
164
165         if(intermission_running)
166         {
167                 self.vehicle.velocity = '0 0 0';
168                 self.vehicle.avelocity = '0 0 0';
169                 return 1;
170         }
171
172         player = self;
173         raptor = self.vehicle;
174         setself(raptor);
175
176         vehicles_painframe();
177         /*
178         ftmp = vlen(self.velocity);
179         if(ftmp > autocvar_g_vehicle_raptor_speed_forward)
180                 ftmp = 1;
181         else
182                 ftmp = ftmp / autocvar_g_vehicle_raptor_speed_forward;
183         */
184
185         if(self.sound_nexttime < time)
186         {
187                 self.sound_nexttime = time + 7.955812;
188                 //sound (self.tur_head, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_FLY, 1 - ftmp,   ATTEN_NORM );
189                 sound (self, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_SPEED, 1, ATTEN_NORM);
190                 self.wait = ftmp;
191         }
192         /*
193         else if(fabs(ftmp - self.wait) > 0.2)
194         {
195                 sound (self.tur_head, CH_TRIGGER_SINGLE, SND_Null, 1 - ftmp,   ATTEN_NORM );
196                 sound (self, CH_TRIGGER_SINGLE, SND_Null, ftmp, ATTEN_NORM);
197                 self.wait = ftmp;
198         }
199         */
200
201         if(raptor.deadflag != DEAD_NO)
202         {
203                 setself(player);
204                 player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
205                 return 1;
206         }
207         crosshair_trace(player);
208
209         //if(time - self.lastteleporttime < 1)
210         //{
211                 if(raptor.angles_z > 50 || raptor.angles_z < -50)
212                 {
213                         if(player.BUTTON_JUMP)
214                         {
215                                 player.BUTTON_CROUCH = true;
216                                 player.BUTTON_JUMP = false;
217                         }
218                 }
219         //}
220
221         vector vang;
222         vang = raptor.angles;
223         df = vectoangles(normalize(trace_endpos - self.origin + '0 0 32'));
224         vang_x *= -1;
225         df_x *= -1;
226         if(df_x > 180)  df_x -= 360;
227         if(df_x < -180) df_x += 360;
228         if(df_y > 180)  df_y -= 360;
229         if(df_y < -180) df_y += 360;
230
231         ftmp = shortangle_f(player.v_angle_y - vang_y, vang_y);
232         if(ftmp > 180)  ftmp -= 360; if(ftmp < -180) ftmp += 360;
233         raptor.avelocity_y = bound(-autocvar_g_vehicle_raptor_turnspeed, ftmp + raptor.avelocity_y * 0.9, autocvar_g_vehicle_raptor_turnspeed);
234
235         // Pitch
236         ftmp = 0;
237         if(player.movement_x > 0 && vang_x < autocvar_g_vehicle_raptor_pitchlimit) ftmp = 5;
238         else if(player.movement_x < 0 && vang_x > -autocvar_g_vehicle_raptor_pitchlimit) ftmp = -20;
239
240         df_x = bound(-autocvar_g_vehicle_raptor_pitchlimit, df_x , autocvar_g_vehicle_raptor_pitchlimit);
241         ftmp = vang_x - bound(-autocvar_g_vehicle_raptor_pitchlimit, df_x + ftmp, autocvar_g_vehicle_raptor_pitchlimit);
242         raptor.avelocity_x = bound(-autocvar_g_vehicle_raptor_pitchspeed, ftmp + raptor.avelocity_x * 0.9, autocvar_g_vehicle_raptor_pitchspeed);
243
244         raptor.angles_x = anglemods(raptor.angles_x);
245         raptor.angles_y = anglemods(raptor.angles_y);
246         raptor.angles_z = anglemods(raptor.angles_z);
247
248         if(autocvar_g_vehicle_raptor_movestyle == 1)
249                 makevectors('0 1 0' * raptor.angles_y);
250         else
251                 makevectors(player.v_angle);
252
253         df = raptor.velocity * -autocvar_g_vehicle_raptor_friction;
254
255         if(player.movement_x != 0)
256         {
257                 if(player.movement_x > 0)
258                         df += v_forward  * autocvar_g_vehicle_raptor_speed_forward;
259                 else if(player.movement_x < 0)
260                         df -= v_forward  * autocvar_g_vehicle_raptor_speed_forward;
261         }
262
263         if(player.movement_y != 0)
264         {
265                 if(player.movement_y < 0)
266                         df -= v_right * autocvar_g_vehicle_raptor_speed_strafe;
267                 else if(player.movement_y > 0)
268                         df += v_right * autocvar_g_vehicle_raptor_speed_strafe;
269
270                 raptor.angles_z = bound(-30,raptor.angles_z + (player.movement_y / autocvar_g_vehicle_raptor_speed_strafe),30);
271         }
272         else
273         {
274                 raptor.angles_z *= 0.95;
275                 if(raptor.angles_z >= -1 && raptor.angles_z <= -1)
276                         raptor.angles_z = 0;
277         }
278
279         if(player.BUTTON_CROUCH)
280                 df -=   v_up * autocvar_g_vehicle_raptor_speed_down;
281         else if (player.BUTTON_JUMP)
282                 df +=  v_up * autocvar_g_vehicle_raptor_speed_up;
283
284         raptor.velocity  += df * frametime;
285         player.velocity = player.movement  = raptor.velocity;
286         setorigin(player, raptor.origin + '0 0 32');
287
288         player.vehicle_weapon2mode = raptor.vehicle_weapon2mode;
289
290         vector vf, ad;
291         // Target lock & predict
292         if(autocvar_g_vehicle_raptor_cannon_locktarget == 2)
293         {
294                 if(raptor.gun1.lock_time < time || raptor.gun1.enemy.deadflag)
295                         raptor.gun1.enemy = world;
296
297                 if(trace_ent)
298                 if(trace_ent.movetype)
299                 if(trace_ent.takedamage)
300                 if(!trace_ent.deadflag)
301                 {
302                         if(teamplay)
303                         {
304                                 if(trace_ent.team != player.team)
305                                 {
306                                         raptor.gun1.enemy = trace_ent;
307                                         raptor.gun1.lock_time = time + 5;
308                                 }
309                         }
310                         else
311                         {
312                                 raptor.gun1.enemy = trace_ent;
313                                 raptor.gun1.lock_time = time + 0.5;
314                         }
315                 }
316
317                 if(raptor.gun1.enemy)
318                 {
319                         float distance, impact_time;
320
321                         vf = real_origin(raptor.gun1.enemy);
322                         UpdateAuxiliaryXhair(player, vf, '1 0 0', 1);
323                         vector _vel = raptor.gun1.enemy.velocity;
324                         if(raptor.gun1.enemy.movetype == MOVETYPE_WALK)
325                                 _vel_z *= 0.1;
326
327                         if(autocvar_g_vehicle_raptor_cannon_predicttarget)
328                         {
329                                 ad = vf;
330                                 distance = vlen(ad - player.origin);
331                                 impact_time = distance / autocvar_g_vehicle_raptor_cannon_speed;
332                                 ad = vf + _vel * impact_time;
333                                 trace_endpos = ad;
334                         }
335                         else
336                                 trace_endpos = vf;
337                 }
338         }
339         else if(autocvar_g_vehicle_raptor_cannon_locktarget == 1)
340         {
341
342                 vehicles_locktarget((1 / autocvar_g_vehicle_raptor_cannon_locking_time) * frametime,
343                                                          (1 / autocvar_g_vehicle_raptor_cannon_locking_releasetime) * frametime,
344                                                          autocvar_g_vehicle_raptor_cannon_locked_time);
345
346                 if(self.lock_target != world)
347                 if(autocvar_g_vehicle_raptor_cannon_predicttarget)
348                 if(self.lock_strength == 1)
349                 {
350                         float i, distance, impact_time;
351
352                         vf = real_origin(raptor.lock_target);
353                         ad = vf;
354                         for(i = 0; i < 4; ++i)
355                         {
356                                 distance = vlen(ad - raptor.origin);
357                                 impact_time = distance / autocvar_g_vehicle_raptor_cannon_speed;
358                                 ad = vf + raptor.lock_target.velocity * impact_time;
359                         }
360                         trace_endpos = ad;
361                 }
362
363                 if(self.lock_target)
364                 {
365                         if(raptor.lock_strength == 1)
366                                 UpdateAuxiliaryXhair(player, real_origin(raptor.lock_target), '1 0 0', 1);
367                         else if(self.lock_strength > 0.5)
368                                 UpdateAuxiliaryXhair(player, real_origin(raptor.lock_target), '0 1 0', 1);
369                         else if(self.lock_strength < 0.5)
370                                 UpdateAuxiliaryXhair(player, real_origin(raptor.lock_target), '0 0 1', 1);
371                 }
372         }
373
374
375         vehicle_aimturret(raptor, trace_endpos, raptor.gun1, "fire1",
376                                                   autocvar_g_vehicle_raptor_cannon_pitchlimit_down * -1,  autocvar_g_vehicle_raptor_cannon_pitchlimit_up,
377                                                   autocvar_g_vehicle_raptor_cannon_turnlimit * -1,  autocvar_g_vehicle_raptor_cannon_turnlimit,  autocvar_g_vehicle_raptor_cannon_turnspeed);
378
379         vehicle_aimturret(raptor, trace_endpos, raptor.gun2, "fire1",
380                                                   autocvar_g_vehicle_raptor_cannon_pitchlimit_down * -1,  autocvar_g_vehicle_raptor_cannon_pitchlimit_up,
381                                                   autocvar_g_vehicle_raptor_cannon_turnlimit * -1,  autocvar_g_vehicle_raptor_cannon_turnlimit,  autocvar_g_vehicle_raptor_cannon_turnspeed);
382
383         /*
384         ad = ad * 0.5;
385         v_forward = vf * 0.5;
386         traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, raptor);
387         UpdateAuxiliaryXhair(player, trace_endpos, '0 1 0', 0);
388         */
389
390         Weapon wep1 = WEP_RAPTOR;
391         if(!forbidWeaponUse(player))
392         if(player.BUTTON_ATCK)
393         if (wep1.wr_checkammo1(wep1))
394         {
395                 wep1.wr_think(wep1, self, true, false);
396         }
397
398         if(self.vehicle_flags  & VHF_SHIELDREGEN)
399                 vehicles_regen(raptor.dmg_time, vehicle_shield, autocvar_g_vehicle_raptor_shield, autocvar_g_vehicle_raptor_shield_regen_pause, autocvar_g_vehicle_raptor_shield_regen, frametime, true);
400
401         if(self.vehicle_flags  & VHF_HEALTHREGEN)
402                 vehicles_regen(raptor.dmg_time, vehicle_health, autocvar_g_vehicle_raptor_health, autocvar_g_vehicle_raptor_health_regen_pause, autocvar_g_vehicle_raptor_health_regen, frametime, false);
403
404         if(self.vehicle_flags  & VHF_ENERGYREGEN)
405                 vehicles_regen(raptor.cnt, vehicle_energy, autocvar_g_vehicle_raptor_energy, autocvar_g_vehicle_raptor_energy_regen_pause, autocvar_g_vehicle_raptor_energy_regen, frametime, false);
406
407         Weapon wep2a = WEP_RAPTOR_BOMB;
408         if(!forbidWeaponUse(player))
409         if(raptor.vehicle_weapon2mode == RSM_BOMB)
410         {
411                 if(time > raptor.lip + autocvar_g_vehicle_raptor_bombs_refire)
412                 if(player.BUTTON_ATCK2)
413                 {
414                         wep2a.wr_think(wep2a, self, false, true);
415                         raptor.delay = time + autocvar_g_vehicle_raptor_bombs_refire;
416                         raptor.lip   = time;
417                 }
418         }
419         else
420         {
421                 Weapon wep2b = WEP_RAPTOR_FLARE;
422                 if(time > raptor.lip + autocvar_g_vehicle_raptor_flare_refire)
423                 if(player.BUTTON_ATCK2)
424                 {
425                         wep2b.wr_think(wep2b, self, false, true);
426                         raptor.delay = time + autocvar_g_vehicle_raptor_flare_refire;
427                         raptor.lip   = time;
428                 }
429         }
430
431         raptor.bomb1.alpha = raptor.bomb2.alpha = (time - raptor.lip) / (raptor.delay - raptor.lip);
432         player.vehicle_reload2 = bound(0, raptor.bomb1.alpha * 100, 100);
433         player.vehicle_ammo2 = (player.vehicle_reload2 == 100) ? 100 : 0;
434
435         if(self.bomb1.cnt < time)
436         {
437                 entity _missile = findchainentity(enemy, raptor);
438                 float _incomming = 0;
439                 while(_missile)
440                 {
441                         if(_missile.flags & FL_PROJECTILE)
442                         if(MISSILE_IS_TRACKING(_missile))
443                         if(vlen(self.origin - _missile.origin) < 2 * autocvar_g_vehicle_raptor_flare_range)
444                                 ++_incomming;
445
446                         _missile = _missile.chain;
447                 }
448
449                 if(_incomming)
450                         sound(self, CH_PAIN_SINGLE, SND_VEH_MISSILE_ALARM, VOL_BASE, ATTEN_NONE);
451
452                 self.bomb1.cnt = time + 1;
453         }
454
455
456         VEHICLE_UPDATE_PLAYER(player, health, raptor);
457         VEHICLE_UPDATE_PLAYER(player, energy, raptor);
458         if(self.vehicle_flags & VHF_HASSHIELD)
459                 VEHICLE_UPDATE_PLAYER(player, shield, raptor);
460
461         player.BUTTON_ATCK = player.BUTTON_ATCK2 = player.BUTTON_CROUCH = 0;
462
463         setself(player);
464         return 1;
465 }
466
467 float raptor_takeoff()
468 {SELFPARAM();
469         entity player, raptor;
470
471         player = self;
472         raptor = self.vehicle;
473         setself(raptor);
474
475         self.nextthink = time;
476         CSQCMODEL_AUTOUPDATE(self);
477         self.nextthink = 0; // will this work?
478
479         if(self.sound_nexttime < time)
480         {
481                 self.sound_nexttime = time + 7.955812; //soundlength("vehicles/raptor_fly.wav");
482                 sound (self, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_SPEED, VOL_VEHICLEENGINE, ATTEN_NORM);
483         }
484
485         // Takeoff sequense
486         if(raptor.frame < 25)
487         {
488                 raptor.frame += 25 / (autocvar_g_vehicle_raptor_takeofftime / sys_frametime);
489                 raptor.velocity_z = min(raptor.velocity_z * 1.5, 256);
490                 self.bomb1.gun1.avelocity_y = 90 + ((raptor.frame / 25) * 25000);
491                 self.bomb1.gun2.avelocity_y = -self.bomb1.gun1.avelocity_y;
492                 player.BUTTON_ATCK = player.BUTTON_ATCK2 = player.BUTTON_CROUCH = 0;
493
494                 setorigin(player, raptor.origin + '0 0 32');
495         }
496         else
497                 player.PlayerPhysplug = raptor_frame;
498
499         if(self.vehicle_flags  & VHF_SHIELDREGEN)
500                 vehicles_regen(raptor.dmg_time, vehicle_shield, autocvar_g_vehicle_raptor_shield, autocvar_g_vehicle_raptor_shield_regen_pause, autocvar_g_vehicle_raptor_shield_regen, frametime, true);
501
502         if(self.vehicle_flags  & VHF_HEALTHREGEN)
503                 vehicles_regen(raptor.dmg_time, vehicle_health, autocvar_g_vehicle_raptor_health, autocvar_g_vehicle_raptor_health_regen_pause, autocvar_g_vehicle_raptor_health_regen, frametime, false);
504
505         if(self.vehicle_flags  & VHF_ENERGYREGEN)
506                 vehicles_regen(raptor.cnt, vehicle_energy, autocvar_g_vehicle_raptor_energy, autocvar_g_vehicle_raptor_energy_regen_pause, autocvar_g_vehicle_raptor_energy_regen, frametime, false);
507
508
509         raptor.bomb1.alpha = raptor.bomb2.alpha = (time - raptor.lip) / (raptor.delay - raptor.lip);
510         player.vehicle_reload2 = bound(0, raptor.bomb1.alpha * 100, 100);
511         player.vehicle_ammo2 = (player.vehicle_reload2 == 100) ? 100 : 0;
512
513         VEHICLE_UPDATE_PLAYER(player, health, raptor);
514         VEHICLE_UPDATE_PLAYER(player, energy, raptor);
515         if(self.vehicle_flags & VHF_HASSHIELD)
516                 VEHICLE_UPDATE_PLAYER(player, shield, raptor);
517
518         player.BUTTON_ATCK = player.BUTTON_ATCK2 = player.BUTTON_CROUCH = 0;
519         setself(player);
520         return 1;
521 }
522
523 void raptor_blowup()
524 {SELFPARAM();
525         self.deadflag   = DEAD_DEAD;
526         self.vehicle_exit(VHEF_NORMAL);
527         RadiusDamage (self, self.enemy, 250, 15, 250, world, world, 250, DEATH_VH_RAPT_DEATH.m_id, world);
528
529         self.alpha                = -1;
530         self.movetype      = MOVETYPE_NONE;
531         self.effects            = EF_NODRAW;
532         self.colormod      = '0 0 0';
533         self.avelocity    = '0 0 0';
534         self.velocity      = '0 0 0';
535
536         setorigin(self, self.pos1);
537         self.touch = func_null;
538         self.nextthink = 0;
539 }
540
541 void raptor_diethink()
542 {SELFPARAM();
543         if(time >= self.wait)
544                 self.think = raptor_blowup;
545
546         if(random() < 0.05)
547         {
548                 sound (self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
549                 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
550         }
551         self.nextthink = time;
552
553         CSQCMODEL_AUTOUPDATE(self);
554 }
555
556 // If we dont do this ever now and then, the raptors rotors
557 // stop working, presumably due to angle overflow. cute.
558 void raptor_rotor_anglefix()
559 {SELFPARAM();
560         self.gun1.angles_y = anglemods(self.gun1.angles_y);
561         self.gun2.angles_y = anglemods(self.gun2.angles_y);
562         self.nextthink = time + 15;
563 }
564
565 float raptor_impulse(float _imp)
566 {SELFPARAM();
567         switch(_imp)
568         {
569                 case 1:
570                         self.vehicle.vehicle_weapon2mode = RSM_BOMB;
571                         CSQCVehicleSetup(self, 0);
572                         return true;
573                 case 2:
574                         self.vehicle.vehicle_weapon2mode = RSM_FLARE;
575                         CSQCVehicleSetup(self, 0);
576                         return true;
577
578                 case 10:
579                 case 15:
580                 case 18:
581                         self.vehicle.vehicle_weapon2mode += 1;
582                         if(self.vehicle.vehicle_weapon2mode > RSM_LAST)
583                                 self.vehicle.vehicle_weapon2mode = RSM_FIRST;
584
585                         CSQCVehicleSetup(self, 0);
586                         return true;
587                 case 11:
588                 case 12:
589                 case 16:
590                 case 19:
591                         self.vehicle.vehicle_weapon2mode -= 1;
592                         if(self.vehicle.vehicle_weapon2mode < RSM_FIRST)
593                                 self.vehicle.vehicle_weapon2mode = RSM_LAST;
594
595                         CSQCVehicleSetup(self, 0);
596                         return true;
597
598                 /*
599                 case 17: // toss gun, could be used to exit?
600                         break;
601                 case 20: // Manual minigun reload?
602                         break;
603                 */
604         }
605         return false;
606 }
607
608 spawnfunc(vehicle_raptor)
609 {
610         if(!autocvar_g_vehicle_raptor) { remove(self); return; }
611         if(!vehicle_initialize(VEH_RAPTOR, false)) { remove(self); return; }
612 }
613
614                 METHOD(Raptor, vr_impact, void(Raptor thisveh))
615                 {
616                         if(autocvar_g_vehicle_raptor_bouncepain)
617                                 vehicles_impact(autocvar_g_vehicle_raptor_bouncepain_x, autocvar_g_vehicle_raptor_bouncepain_y, autocvar_g_vehicle_raptor_bouncepain_z);
618                 }
619                 METHOD(Raptor, vr_enter, void(Raptor thisveh))
620                 {
621                         self.vehicle_weapon2mode = RSM_BOMB;
622                         self.owner.PlayerPhysplug = raptor_takeoff;
623                         self.movetype      = MOVETYPE_BOUNCEMISSILE;
624                         self.solid                = SOLID_SLIDEBOX;
625                         self.owner.vehicle_health = (self.vehicle_health / autocvar_g_vehicle_raptor_health) * 100;
626                         self.owner.vehicle_shield = (self.vehicle_shield / autocvar_g_vehicle_raptor_shield) * 100;
627                         self.velocity_z = 1; // Nudge upwards to takeoff sequense can work.
628                         self.tur_head.exteriormodeltoclient = self.owner;
629
630                         self.delay = time + autocvar_g_vehicle_raptor_bombs_refire;
631                         self.lip   = time;
632
633                         if(self.owner.flagcarried)
634                            setorigin(self.owner.flagcarried, '-20 0 96');
635
636                         CSQCVehicleSetup(self.owner, 0);
637                 }
638                 METHOD(Raptor, vr_death, void(Raptor thisveh))
639                 {
640                         self.health                             = 0;
641                         self.event_damage               = func_null;
642                         self.solid                              = SOLID_CORPSE;
643                         self.takedamage                 = DAMAGE_NO;
644                         self.deadflag                   = DEAD_DYING;
645                         self.movetype                   = MOVETYPE_BOUNCE;
646                         self.think                              = raptor_diethink;
647                         self.nextthink                  = time;
648                         self.wait                               = time + 5 + (random() * 5);
649
650                         Send_Effect(EFFECT_EXPLOSION_MEDIUM, findbetterlocation (self.origin, 16), '0 0 0', 1);
651
652                         self.velocity_z += 600;
653
654                         self.avelocity = '0 0.5 1' * (random() * 400);
655                         self.avelocity -= '0 0.5 1' * (random() * 400);
656
657                         self.colormod = '-0.5 -0.5 -0.5';
658                         self.touch = raptor_blowup;
659                 }
660                 METHOD(Raptor, vr_spawn, void(Raptor thisveh))
661                 {
662                         if(!self.gun1)
663                         {
664                                 entity spinner;
665                                 vector ofs;
666
667                                 //FIXME: Camera is in a bad place in HUD model.
668                                 //setorigin(self.vehicle_viewport, '25 0 5');
669
670                                 self.vehicles_impulse   = raptor_impulse;
671
672                                 self.frame = 0;
673
674                                 self.bomb1 = spawn();
675                                 self.bomb2 = spawn();
676                                 self.gun1  = spawn();
677                                 self.gun2  = spawn();
678
679                                 setmodel(self.bomb1, MDL_VEH_RAPTOR_CB_FOLDED);
680                                 setmodel(self.bomb2, MDL_VEH_RAPTOR_CB_FOLDED);
681                                 setmodel(self.gun1, MDL_VEH_RAPTOR_GUN);
682                                 setmodel(self.gun2, MDL_VEH_RAPTOR_GUN);
683                                 setmodel(self.tur_head, MDL_VEH_RAPTOR_TAIL);
684
685                                 setattachment(self.bomb1, self, "bombmount_left");
686                                 setattachment(self.bomb2, self, "bombmount_right");
687                                 setattachment(self.tur_head, self,"root");
688
689                                 // FIXMODEL Guns mounts to angled bones
690                                 self.bomb1.angles = self.angles;
691                                 self.angles = '0 0 0';
692                                 // This messes up gun-aim, so work arround it.
693                                 //setattachment(self.gun1, self, "gunmount_left");
694                                 ofs = gettaginfo(self, gettagindex(self, "gunmount_left"));
695                                 ofs -= self.origin;
696                                 setattachment(self.gun1, self, "");
697                                 setorigin(self.gun1, ofs);
698
699                                 //setattachment(self.gun2, self, "gunmount_right");
700                                 ofs = gettaginfo(self, gettagindex(self, "gunmount_right"));
701                                 ofs -= self.origin;
702                                 setattachment(self.gun2, self, "");
703                                 setorigin(self.gun2, ofs);
704
705                                 self.angles = self.bomb1.angles;
706                                 self.bomb1.angles = '0 0 0';
707
708                                 spinner = spawn();
709                                 spinner.owner = self;
710                                 setmodel(spinner, MDL_VEH_RAPTOR_PROP);
711                                 setattachment(spinner, self, "engine_left");
712                                 spinner.movetype = MOVETYPE_NOCLIP;
713                                 spinner.avelocity = '0 90 0';
714                                 self.bomb1.gun1 = spinner;
715
716                                 spinner = spawn();
717                                 spinner.owner = self;
718                                 setmodel(spinner, MDL_VEH_RAPTOR_PROP);
719                                 setattachment(spinner, self, "engine_right");
720                                 spinner.movetype = MOVETYPE_NOCLIP;
721                                 spinner.avelocity = '0 -90 0';
722                                 self.bomb1.gun2 = spinner;
723
724                                 // Sigh.
725                                 self.bomb1.think = raptor_rotor_anglefix;
726                                 self.bomb1.nextthink = time;
727
728                                 self.mass                          = 1 ;
729                         }
730
731                         self.frame                = 0;
732                         self.vehicle_health = autocvar_g_vehicle_raptor_health;
733                         self.vehicle_shield = autocvar_g_vehicle_raptor_shield;
734                         self.movetype      = MOVETYPE_TOSS;
735                         self.solid                = SOLID_SLIDEBOX;
736                         self.vehicle_energy = 1;
737
738                         self.PlayerPhysplug = raptor_frame;
739
740                         self.bomb1.gun1.avelocity_y = 90;
741                         self.bomb1.gun2.avelocity_y = -90;
742
743                         self.delay = time;
744
745                         self.bouncefactor = autocvar_g_vehicle_raptor_bouncefactor;
746                         self.bouncestop = autocvar_g_vehicle_raptor_bouncestop;
747                         self.damageforcescale = 0.25;
748                         self.vehicle_health = autocvar_g_vehicle_raptor_health;
749                         self.vehicle_shield = autocvar_g_vehicle_raptor_shield;
750                 }
751                 METHOD(Raptor, vr_setup, void(Raptor thisveh))
752                 {
753                         if(autocvar_g_vehicle_raptor_shield)
754                                 self.vehicle_flags |= VHF_HASSHIELD;
755
756                         if(autocvar_g_vehicle_raptor_shield_regen)
757                                 self.vehicle_flags |= VHF_SHIELDREGEN;
758
759                         if(autocvar_g_vehicle_raptor_health_regen)
760                                 self.vehicle_flags |= VHF_HEALTHREGEN;
761
762                         if(autocvar_g_vehicle_raptor_energy_regen)
763                                 self.vehicle_flags |= VHF_ENERGYREGEN;
764
765                         self.vehicle_exit = raptor_exit;
766                         self.respawntime = autocvar_g_vehicle_raptor_respawntime;
767                         self.vehicle_health = autocvar_g_vehicle_raptor_health;
768                         self.vehicle_shield = autocvar_g_vehicle_raptor_shield;
769                         self.max_health = self.vehicle_health;
770                 }
771
772 #endif
773 #ifdef CSQC
774
775                 METHOD(Raptor, vr_hud, void(Raptor thisveh))
776                 {
777                         Vehicles_drawHUD(VEH_RAPTOR.m_icon, "vehicle_raptor_weapon1", "vehicle_raptor_weapon2",
778                                                          "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
779                                                          "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
780                 }
781                 METHOD(Raptor, vr_crosshair, void(Raptor thisveh))
782                 {
783                         string crosshair;
784
785                         switch(weapon2mode)
786                         {
787                                 case RSM_FLARE: crosshair = vCROSS_RAIN;  break;
788                                 case RSM_BOMB:  crosshair = vCROSS_BURST; break;
789                                 default:        crosshair = vCROSS_BURST;
790                         }
791
792                         vector tmpSize = '0 0 0';
793                         if(weapon2mode != RSM_FLARE)
794                         {
795                                 vector where;
796
797                                 if(!dropmark)
798                                 {
799                                         dropmark = spawn();
800                                         dropmark.owner = self;
801                                         dropmark.gravity = 1;
802                                 }
803
804                                 float reload2 = getstati(STAT_VEHICLESTAT_RELOAD2) * 0.01;
805                                 if(reload2 == 1)
806                                 {
807                                         setorigin(dropmark, pmove_org);
808                                         dropmark.velocity = pmove_vel;
809                                         tracetoss(dropmark, self);
810
811                                         where = project_3d_to_2d(trace_endpos);
812
813                                         setorigin(dropmark, trace_endpos);
814                                         tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size;
815
816                                         if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight))
817                                         {
818                                                 where.x -= tmpSize.x * 0.5;
819                                                 where.y -= tmpSize.y * 0.5;
820                                                 where.z = 0;
821                                                 drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE);
822                                                 drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg
823                                         }
824                                         dropmark.cnt = time + 5;
825                                 }
826                                 else
827                                 {
828                                         if(dropmark.cnt > time)
829                                         {
830                                                 where = project_3d_to_2d(dropmark.origin);
831                                                 tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size * 1.25;
832
833                                                 if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight))
834                                                 {
835                                                         where.x -= tmpSize.x * 0.5;
836                                                         where.y -= tmpSize.y * 0.5;
837                                                         where.z = 0;
838                                                         drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE);
839                                                         drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg
840                                                 }
841                                         }
842                                 }
843                         }
844
845                         Vehicles_drawCrosshair(crosshair);
846                 }
847                 METHOD(Raptor, vr_setup, void(Raptor thisveh))
848                 {
849                         AuxiliaryXhair[1].axh_image = vCROSS_LOCK;
850                 }
851
852 #endif
853 #endif