Merge branch 'master' into Mario/vehicles
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / unit / raptor.qc
1 #ifdef REGISTER_VEHICLE
2 REGISTER_VEHICLE(
3 /* VEH_##id   */ RAPTOR,
4 /* function   */ v_raptor,
5 /* spawnflags */ VHF_DMGSHAKE | VHF_DMGROLL,
6 /* mins,maxs  */ '-80 -80 0', '80 80 70',
7 /* model          */ "models/vehicles/raptor.dpm",
8 /* head_model */ "",
9 /* hud_model  */ "models/vehicles/raptor_cockpit.dpm",
10 /* tags           */ "", "tag_hud", "tag_camera",
11 /* netname        */ "raptor",
12 /* fullname   */ _("Raptor")
13 );
14 #else
15
16 #ifdef SVQC
17 bool autocvar_g_vehicle_raptor;
18
19 float autocvar_g_vehicle_raptor_respawntime;
20 float autocvar_g_vehicle_raptor_takeofftime;
21
22 float autocvar_g_vehicle_raptor_movestyle;
23 float autocvar_g_vehicle_raptor_turnspeed;
24 float autocvar_g_vehicle_raptor_pitchspeed;
25 float autocvar_g_vehicle_raptor_pitchlimit;
26
27 float autocvar_g_vehicle_raptor_speed_forward;
28 float autocvar_g_vehicle_raptor_speed_strafe;
29 float autocvar_g_vehicle_raptor_speed_up;
30 float autocvar_g_vehicle_raptor_speed_down;
31 float autocvar_g_vehicle_raptor_friction;
32
33 float autocvar_g_vehicle_raptor_bomblets;
34 float autocvar_g_vehicle_raptor_bomblet_alt;
35 float autocvar_g_vehicle_raptor_bomblet_time;
36 float autocvar_g_vehicle_raptor_bomblet_damage;
37 float autocvar_g_vehicle_raptor_bomblet_spread;
38 float autocvar_g_vehicle_raptor_bomblet_edgedamage;
39 float autocvar_g_vehicle_raptor_bomblet_radius;
40 float autocvar_g_vehicle_raptor_bomblet_force;
41 float autocvar_g_vehicle_raptor_bomblet_explode_delay;
42 float autocvar_g_vehicle_raptor_bombs_refire;
43
44 float autocvar_g_vehicle_raptor_flare_refire;
45 float autocvar_g_vehicle_raptor_flare_lifetime;
46 float autocvar_g_vehicle_raptor_flare_chase;
47 float autocvar_g_vehicle_raptor_flare_range;
48
49 float autocvar_g_vehicle_raptor_cannon_turnspeed;
50 float autocvar_g_vehicle_raptor_cannon_turnlimit;
51 float autocvar_g_vehicle_raptor_cannon_pitchlimit_up;
52 float autocvar_g_vehicle_raptor_cannon_pitchlimit_down;
53
54 float autocvar_g_vehicle_raptor_cannon_locktarget;
55 float autocvar_g_vehicle_raptor_cannon_locking_time;
56 float autocvar_g_vehicle_raptor_cannon_locking_releasetime;
57 float autocvar_g_vehicle_raptor_cannon_locked_time;
58 float autocvar_g_vehicle_raptor_cannon_predicttarget;
59
60 float autocvar_g_vehicle_raptor_cannon_cost;
61 float autocvar_g_vehicle_raptor_cannon_damage;
62 float autocvar_g_vehicle_raptor_cannon_radius;
63 float autocvar_g_vehicle_raptor_cannon_refire;
64 float autocvar_g_vehicle_raptor_cannon_speed;
65 float autocvar_g_vehicle_raptor_cannon_spread;
66 float autocvar_g_vehicle_raptor_cannon_force;
67
68 float autocvar_g_vehicle_raptor_energy;
69 float autocvar_g_vehicle_raptor_energy_regen;
70 float autocvar_g_vehicle_raptor_energy_regen_pause;
71
72 float autocvar_g_vehicle_raptor_health;
73 float autocvar_g_vehicle_raptor_health_regen;
74 float autocvar_g_vehicle_raptor_health_regen_pause;
75
76 float autocvar_g_vehicle_raptor_shield;
77 float autocvar_g_vehicle_raptor_shield_regen;
78 float autocvar_g_vehicle_raptor_shield_regen_pause;
79
80 float autocvar_g_vehicle_raptor_bouncefactor;
81 float autocvar_g_vehicle_raptor_bouncestop;
82 vector autocvar_g_vehicle_raptor_bouncepain;
83
84 .entity bomb1;
85 .entity bomb2;
86
87 float raptor_altitude(float amax)
88 {
89         tracebox(self.origin, self.mins, self.maxs, self.origin - ('0 0 1' * amax), MOVE_WORLDONLY, self);
90         return vlen(self.origin - trace_endpos);
91 }
92
93 void raptor_bomblet_boom()
94 {
95         RadiusDamage (self, self.realowner, autocvar_g_vehicle_raptor_bomblet_damage,
96                                                                         autocvar_g_vehicle_raptor_bomblet_edgedamage,
97                                                                         autocvar_g_vehicle_raptor_bomblet_radius, world, world,
98                                                                         autocvar_g_vehicle_raptor_bomblet_force, DEATH_VH_RAPT_BOMB, world);
99         remove(self);
100 }
101
102 void raptor_bomblet_touch()
103 {
104         if(other == self.owner)
105                 return;
106
107         PROJECTILE_TOUCH;
108         self.think = raptor_bomblet_boom;
109         self.nextthink = time + random() * autocvar_g_vehicle_raptor_bomblet_explode_delay;
110 }
111
112 void raptor_bomb_burst()
113 {
114         if(self.cnt > time)
115         if(autocvar_g_vehicle_raptor_bomblet_alt)
116         {
117                 self.nextthink = time;
118                 traceline(self.origin, self.origin + (normalize(self.velocity) * autocvar_g_vehicle_raptor_bomblet_alt), MOVE_NORMAL, self);
119                 if((trace_fraction == 1.0) || (vlen(self.origin - self.owner.origin) < autocvar_g_vehicle_raptor_bomblet_radius))
120                 {
121                         UpdateCSQCProjectile(self);
122                         return;
123                 }
124         }
125
126         entity bomblet;
127         float i;
128
129         Damage_DamageInfo(self.origin, 0, 0, 0, '0 0 0', DEATH_VH_RAPT_FRAGMENT, 0, self);
130
131         for(i = 0; i < autocvar_g_vehicle_raptor_bomblets; ++i)
132         {
133                 bomblet = spawn();
134                 setorigin(bomblet, self.origin);
135
136                 bomblet.movetype        = MOVETYPE_TOSS;
137                 bomblet.touch      = raptor_bomblet_touch;
138                 bomblet.think      = raptor_bomblet_boom;
139                 bomblet.nextthink   = time + 5;
140                 bomblet.owner      = self.owner;
141                 bomblet.realowner   = self.realowner;
142                 bomblet.velocity        = normalize(normalize(self.velocity) + (randomvec() * autocvar_g_vehicle_raptor_bomblet_spread)) * vlen(self.velocity);
143
144                 PROJECTILE_MAKETRIGGER(bomblet);
145                 CSQCProjectile(bomblet, true, PROJECTILE_RAPTORBOMBLET, true);
146         }
147
148         remove(self);
149 }
150
151 void raptor_bombdrop()
152 {
153         entity bomb_1, bomb_2;
154
155         bomb_1 = spawn();
156         bomb_2 = spawn();
157
158         setorigin(bomb_1, gettaginfo(self, gettagindex(self, "bombmount_left")));
159         setorigin(bomb_2, gettaginfo(self, gettagindex(self, "bombmount_right")));
160
161         bomb_1.movetype  = bomb_2.movetype   = MOVETYPE_BOUNCE;
162         bomb_1.velocity  = bomb_2.velocity   = self.velocity;
163         bomb_1.touch            = bomb_2.touch    = raptor_bomb_burst;
164         bomb_1.think            = bomb_2.think    = raptor_bomb_burst;
165         bomb_1.cnt                = bomb_2.cnt          = time + 10;
166
167         if(autocvar_g_vehicle_raptor_bomblet_alt)
168                 bomb_1.nextthink = bomb_2.nextthink  = time;
169         else
170                 bomb_1.nextthink = bomb_2.nextthink  = time + autocvar_g_vehicle_raptor_bomblet_time;
171
172         bomb_1.owner     = bomb_2.owner   = self;
173         bomb_1.realowner = bomb_2.realowner  = self.owner;
174         bomb_1.solid     = bomb_2.solid   = SOLID_BBOX;
175         bomb_1.gravity   = bomb_2.gravity       = 1;
176
177         PROJECTILE_MAKETRIGGER(bomb_1);
178         PROJECTILE_MAKETRIGGER(bomb_2);
179
180         CSQCProjectile(bomb_1, true, PROJECTILE_RAPTORBOMB, true);
181         CSQCProjectile(bomb_2, true, PROJECTILE_RAPTORBOMB, true);
182 }
183
184
185 void raptor_fire_cannon(entity gun, string tagname)
186 {
187         vehicles_projectile("raptor_cannon_muzzleflash", "weapons/lasergun_fire.wav",
188                                                    gettaginfo(gun, gettagindex(gun, tagname)), normalize(v_forward + randomvec() * autocvar_g_vehicle_raptor_cannon_spread) * autocvar_g_vehicle_raptor_cannon_speed,
189                                                    autocvar_g_vehicle_raptor_cannon_damage, autocvar_g_vehicle_raptor_cannon_radius, autocvar_g_vehicle_raptor_cannon_force,  0,
190                                                    DEATH_VH_RAPT_CANNON, PROJECTILE_RAPTORCANNON, 0, true, true, self.owner);
191 }
192
193 void raptor_land()
194 {
195         float hgt;
196
197         hgt = raptor_altitude(512);
198         self.velocity = (self.velocity * 0.9) + ('0 0 -1800' * (hgt / 256) * sys_frametime);
199         self.angles_x *= 0.95;
200         self.angles_z *= 0.95;
201
202         if(hgt < 128)
203         if(hgt > 0)
204                 self.frame = (hgt / 128) * 25;
205
206         self.bomb1.gun1.avelocity_y = 90 + ((self.frame / 25) * 2000);
207         self.bomb1.gun2.avelocity_y = -self.bomb1.gun1.avelocity_y;
208
209         if(hgt < 16)
210         {
211                 self.movetype = MOVETYPE_TOSS;
212                 self.think      = vehicles_think;
213                 self.frame      = 0;
214         }
215
216         self.nextthink  = time;
217         
218         CSQCMODEL_AUTOUPDATE();
219 }
220
221 void raptor_exit(float eject)
222 {
223         vector spot;
224         self.tur_head.exteriormodeltoclient = world;
225
226         if(self.deadflag == DEAD_NO)
227         {
228                 self.think        = raptor_land;
229                 self.nextthink  = time;
230         }
231
232         if(!self.owner)
233                 return;
234
235         makevectors(self.angles);
236         if(eject)
237         {
238                 spot = self.origin + v_forward * 100 + '0 0 64';
239                 spot = vehicles_findgoodexit(spot);
240                 setorigin(self.owner , spot);
241                 self.owner.velocity = (v_up + v_forward * 0.25) * 750;
242                 self.owner.oldvelocity = self.owner.velocity;
243         }
244         else
245         {
246                 if(vlen(self.velocity) > 2 * autocvar_sv_maxairspeed)
247                 {
248                         self.owner.velocity = normalize(self.velocity) * autocvar_sv_maxairspeed * 2;
249                         self.owner.velocity_z += 200;
250                         spot = self.origin + v_forward * 32 + '0 0 64';
251                         spot = vehicles_findgoodexit(spot);
252                 }
253                 else
254                 {
255                         self.owner.velocity = self.velocity * 0.5;
256                         self.owner.velocity_z += 10;
257                         spot = self.origin - v_forward * 200 + '0 0 64';
258                         spot = vehicles_findgoodexit(spot);
259                 }
260                 self.owner.oldvelocity = self.owner.velocity;
261                 setorigin(self.owner , spot);
262         }
263
264         antilag_clear(self.owner);
265         self.owner = world;
266 }
267
268 void raptor_flare_touch()
269 {
270         remove(self);
271 }
272
273 void raptor_flare_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
274 {
275         self.health -= damage;
276         if(self.health <= 0)
277                 remove(self);
278 }
279
280 void raptor_flare_think()
281 {
282         self.nextthink = time + 0.1;
283         entity _missile = findchainentity(enemy, self.owner);
284         while(_missile)
285         {
286                 if(_missile.flags & FL_PROJECTILE)
287                 if(vlen(self.origin - _missile.origin) < autocvar_g_vehicle_raptor_flare_range)
288                 if(random() > autocvar_g_vehicle_raptor_flare_chase)
289                         _missile.enemy = self;
290                 _missile = _missile.chain;
291         }
292
293         if(self.tur_impacttime < time)
294                 remove(self);
295 }
296
297 float raptor_frame()
298 {
299         entity player, raptor;
300         float ftmp = 0;
301         vector df;
302
303         if(intermission_running)
304         {
305                 self.vehicle.velocity = '0 0 0';
306                 self.vehicle.avelocity = '0 0 0';
307                 return 1;
308         }
309
310         player = self;
311         raptor = self.vehicle;
312         self   = raptor;
313         
314         vehicles_painframe();
315         /*
316         ftmp = vlen(self.velocity);
317         if(ftmp > autocvar_g_vehicle_raptor_speed_forward)
318                 ftmp = 1;
319         else
320                 ftmp = ftmp / autocvar_g_vehicle_raptor_speed_forward;
321         */
322
323         if(self.sound_nexttime < time)
324         {
325                 self.sound_nexttime = time + 7.955812;
326                 //sound (self.tur_head, CH_TRIGGER_SINGLE, "vehicles/raptor_fly.wav", 1 - ftmp,   ATTEN_NORM );
327                 sound (self, CH_TRIGGER_SINGLE, "vehicles/raptor_speed.wav", 1, ATTEN_NORM);
328                 self.wait = ftmp;
329         }
330         /*
331         else if(fabs(ftmp - self.wait) > 0.2)
332         {
333                 sound (self.tur_head, CH_TRIGGER_SINGLE, "", 1 - ftmp,   ATTEN_NORM );
334                 sound (self, CH_TRIGGER_SINGLE, "", ftmp, ATTEN_NORM);
335                 self.wait = ftmp;
336         }
337         */
338
339         if(raptor.deadflag != DEAD_NO)
340         {
341                 self = player;
342                 player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
343                 return 1;
344         }
345         crosshair_trace(player);
346
347         //if(time - self.lastteleporttime < 1)
348         //{
349                 if(raptor.angles_z > 50 || raptor.angles_z < -50)
350                 {
351                         if(player.BUTTON_JUMP)
352                         {
353                                 player.BUTTON_CROUCH = true;
354                                 player.BUTTON_JUMP = false;
355                         }
356                 }
357         //}
358
359         vector vang;
360         vang = raptor.angles;
361         df = vectoangles(normalize(trace_endpos - self.origin + '0 0 32'));
362         vang_x *= -1;
363         df_x *= -1;
364         if(df_x > 180)  df_x -= 360;
365         if(df_x < -180) df_x += 360;
366         if(df_y > 180)  df_y -= 360;
367         if(df_y < -180) df_y += 360;
368
369         ftmp = shortangle_f(player.v_angle_y - vang_y, vang_y);
370         if(ftmp > 180)  ftmp -= 360; if(ftmp < -180) ftmp += 360;
371         raptor.avelocity_y = bound(-autocvar_g_vehicle_raptor_turnspeed, ftmp + raptor.avelocity_y * 0.9, autocvar_g_vehicle_raptor_turnspeed);
372
373         // Pitch
374         ftmp = 0;
375         if(player.movement_x > 0 && vang_x < autocvar_g_vehicle_raptor_pitchlimit) ftmp = 5;
376         else if(player.movement_x < 0 && vang_x > -autocvar_g_vehicle_raptor_pitchlimit) ftmp = -20;
377
378         df_x = bound(-autocvar_g_vehicle_raptor_pitchlimit, df_x , autocvar_g_vehicle_raptor_pitchlimit);
379         ftmp = vang_x - bound(-autocvar_g_vehicle_raptor_pitchlimit, df_x + ftmp, autocvar_g_vehicle_raptor_pitchlimit);
380         raptor.avelocity_x = bound(-autocvar_g_vehicle_raptor_pitchspeed, ftmp + raptor.avelocity_x * 0.9, autocvar_g_vehicle_raptor_pitchspeed);
381
382         raptor.angles_x = anglemods(raptor.angles_x);
383         raptor.angles_y = anglemods(raptor.angles_y);
384         raptor.angles_z = anglemods(raptor.angles_z);
385
386         if(autocvar_g_vehicle_raptor_movestyle == 1)
387                 makevectors('0 1 0' * raptor.angles_y);
388         else
389                 makevectors(player.v_angle);
390
391         df = raptor.velocity * -autocvar_g_vehicle_raptor_friction;
392
393         if(player.movement_x != 0)
394         {
395                 if(player.movement_x > 0)
396                         df += v_forward  * autocvar_g_vehicle_raptor_speed_forward;
397                 else if(player.movement_x < 0)
398                         df -= v_forward  * autocvar_g_vehicle_raptor_speed_forward;
399         }
400
401         if(player.movement_y != 0)
402         {
403                 if(player.movement_y < 0)
404                         df -= v_right * autocvar_g_vehicle_raptor_speed_strafe;
405                 else if(player.movement_y > 0)
406                         df += v_right * autocvar_g_vehicle_raptor_speed_strafe;
407
408                 raptor.angles_z = bound(-30,raptor.angles_z + (player.movement_y / autocvar_g_vehicle_raptor_speed_strafe),30);
409         }
410         else
411         {
412                 raptor.angles_z *= 0.95;
413                 if(raptor.angles_z >= -1 && raptor.angles_z <= -1)
414                         raptor.angles_z = 0;
415         }
416
417         if(player.BUTTON_CROUCH)
418                 df -=   v_up * autocvar_g_vehicle_raptor_speed_down;
419         else if (player.BUTTON_JUMP)
420                 df +=  v_up * autocvar_g_vehicle_raptor_speed_up;
421
422         raptor.velocity  += df * frametime;
423         player.velocity = player.movement  = raptor.velocity;
424         setorigin(player, raptor.origin + '0 0 32');
425
426         player.vehicle_weapon2mode = raptor.vehicle_weapon2mode;
427
428         vector vf, ad;
429         // Target lock & predict
430         if(autocvar_g_vehicle_raptor_cannon_locktarget == 2)
431         {
432                 if(raptor.gun1.lock_time < time || raptor.gun1.enemy.deadflag)
433                         raptor.gun1.enemy = world;
434
435                 if(trace_ent)
436                 if(trace_ent.movetype)
437                 if(trace_ent.takedamage)
438                 if(!trace_ent.deadflag)
439                 {
440                         if(teamplay)
441                         {
442                                 if(trace_ent.team != player.team)
443                                 {
444                                         raptor.gun1.enemy = trace_ent;
445                                         raptor.gun1.lock_time = time + 5;
446                                 }
447                         }
448                         else
449                         {
450                                 raptor.gun1.enemy = trace_ent;
451                                 raptor.gun1.lock_time = time + 0.5;
452                         }
453                 }
454
455                 if(raptor.gun1.enemy)
456                 {
457                         float distance, impact_time;
458
459                         vf = real_origin(raptor.gun1.enemy);
460                         UpdateAuxiliaryXhair(player, vf, '1 0 0', 1);
461                         vector _vel = raptor.gun1.enemy.velocity;
462                         if(raptor.gun1.enemy.movetype == MOVETYPE_WALK)
463                                 _vel_z *= 0.1;
464
465                         if(autocvar_g_vehicle_raptor_cannon_predicttarget)
466                         {
467                                 ad = vf;
468                                 distance = vlen(ad - player.origin);
469                                 impact_time = distance / autocvar_g_vehicle_raptor_cannon_speed;
470                                 ad = vf + _vel * impact_time;
471                                 trace_endpos = ad;
472                         }
473                         else
474                                 trace_endpos = vf;
475                 }
476         }
477         else if(autocvar_g_vehicle_raptor_cannon_locktarget == 1)
478         {
479
480                 vehicles_locktarget((1 / autocvar_g_vehicle_raptor_cannon_locking_time) * frametime,
481                                                          (1 / autocvar_g_vehicle_raptor_cannon_locking_releasetime) * frametime,
482                                                          autocvar_g_vehicle_raptor_cannon_locked_time);
483
484                 if(self.lock_target != world)
485                 if(autocvar_g_vehicle_raptor_cannon_predicttarget)
486                 if(self.lock_strength == 1)
487                 {
488                         float i, distance, impact_time;
489
490                         vf = real_origin(raptor.lock_target);
491                         ad = vf;
492                         for(i = 0; i < 4; ++i)
493                         {
494                                 distance = vlen(ad - raptor.origin);
495                                 impact_time = distance / autocvar_g_vehicle_raptor_cannon_speed;
496                                 ad = vf + raptor.lock_target.velocity * impact_time;
497                         }
498                         trace_endpos = ad;
499                 }
500
501                 if(self.lock_target)
502                 {
503                         if(raptor.lock_strength == 1)
504                                 UpdateAuxiliaryXhair(player, real_origin(raptor.lock_target), '1 0 0', 1);
505                         else if(self.lock_strength > 0.5)
506                                 UpdateAuxiliaryXhair(player, real_origin(raptor.lock_target), '0 1 0', 1);
507                         else if(self.lock_strength < 0.5)
508                                 UpdateAuxiliaryXhair(player, real_origin(raptor.lock_target), '0 0 1', 1);
509                 }
510         }
511
512
513         vehicle_aimturret(raptor, trace_endpos, raptor.gun1, "fire1",
514                                                   autocvar_g_vehicle_raptor_cannon_pitchlimit_down * -1,  autocvar_g_vehicle_raptor_cannon_pitchlimit_up,
515                                                   autocvar_g_vehicle_raptor_cannon_turnlimit * -1,  autocvar_g_vehicle_raptor_cannon_turnlimit,  autocvar_g_vehicle_raptor_cannon_turnspeed);
516
517         vehicle_aimturret(raptor, trace_endpos, raptor.gun2, "fire1",
518                                                   autocvar_g_vehicle_raptor_cannon_pitchlimit_down * -1,  autocvar_g_vehicle_raptor_cannon_pitchlimit_up,
519                                                   autocvar_g_vehicle_raptor_cannon_turnlimit * -1,  autocvar_g_vehicle_raptor_cannon_turnlimit,  autocvar_g_vehicle_raptor_cannon_turnspeed);
520
521         /*
522         ad = ad * 0.5;
523         v_forward = vf * 0.5;
524         traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, raptor);
525         UpdateAuxiliaryXhair(player, trace_endpos, '0 1 0', 0);
526         */
527
528         if(!forbidWeaponUse(player))
529         if(player.BUTTON_ATCK)
530         if(raptor.attack_finished_single <= time)
531         if(raptor.vehicle_energy > autocvar_g_vehicle_raptor_cannon_cost)
532         {
533                 raptor.misc_bulletcounter += 1;
534                 raptor.attack_finished_single = time + autocvar_g_vehicle_raptor_cannon_refire;
535                 if(raptor.misc_bulletcounter <= 2)
536                         raptor_fire_cannon(self.gun1, "fire1");
537                 else if(raptor.misc_bulletcounter == 3)
538                         raptor_fire_cannon(self.gun2, "fire1");
539                 else
540                 {
541                         raptor.attack_finished_single = time + autocvar_g_vehicle_raptor_cannon_refire * 2;
542                         raptor_fire_cannon(self.gun2, "fire1");
543                         raptor.misc_bulletcounter = 0;
544                 }
545                 raptor.vehicle_energy -= autocvar_g_vehicle_raptor_cannon_cost;
546                 self.cnt = time;
547         }
548
549         if(self.vehicle_flags  & VHF_SHIELDREGEN)
550                 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);
551
552         if(self.vehicle_flags  & VHF_HEALTHREGEN)
553                 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);
554
555         if(self.vehicle_flags  & VHF_ENERGYREGEN)
556                 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);
557
558         if(!forbidWeaponUse(player))
559         if(raptor.vehicle_weapon2mode == RSM_BOMB)
560         {
561                 if(time > raptor.lip + autocvar_g_vehicle_raptor_bombs_refire)
562                 if(player.BUTTON_ATCK2)
563                 {
564                         raptor_bombdrop();
565                         raptor.delay = time + autocvar_g_vehicle_raptor_bombs_refire;
566                         raptor.lip   = time;
567                 }
568         }
569         else
570         {
571                 if(time > raptor.lip + autocvar_g_vehicle_raptor_flare_refire)
572                 if(player.BUTTON_ATCK2)
573                 {
574                         float i;
575                         entity _flare;
576
577                         for(i = 0; i < 3; ++i)
578                         {
579                         _flare = spawn();
580                         setmodel(_flare, "models/runematch/rune.mdl");
581                         _flare.effects = EF_LOWPRECISION | EF_FLAME;
582                         _flare.scale = 0.5;
583                         setorigin(_flare, self.origin - '0 0 16');
584                         _flare.movetype = MOVETYPE_TOSS;
585                         _flare.gravity = 0.15;
586                         _flare.velocity = 0.25 * raptor.velocity + (v_forward + randomvec() * 0.25)* -500;
587                         _flare.think = raptor_flare_think;
588                         _flare.nextthink = time;
589                         _flare.owner = raptor;
590                         _flare.solid = SOLID_CORPSE;
591                         _flare.takedamage = DAMAGE_YES;
592                         _flare.event_damage = raptor_flare_damage;
593                         _flare.health = 20;
594                         _flare.tur_impacttime = time + autocvar_g_vehicle_raptor_flare_lifetime;
595                         _flare.touch = raptor_flare_touch;
596                         }
597                         raptor.delay = time + autocvar_g_vehicle_raptor_flare_refire;
598                         raptor.lip   = time;
599                 }
600         }
601
602         raptor.bomb1.alpha = raptor.bomb2.alpha = (time - raptor.lip) / (raptor.delay - raptor.lip);
603         player.vehicle_reload2 = bound(0, raptor.bomb1.alpha * 100, 100);
604         player.vehicle_ammo2 = (player.vehicle_reload2 == 100) ? 100 : 0;
605
606         if(self.bomb1.cnt < time)
607         {
608                 entity _missile = findchainentity(enemy, raptor);
609                 float _incomming = 0;
610                 while(_missile)
611                 {
612                         if(_missile.flags & FL_PROJECTILE)
613                         if(MISSILE_IS_TRACKING(_missile))
614                         if(vlen(self.origin - _missile.origin) < 2 * autocvar_g_vehicle_raptor_flare_range)
615                                 ++_incomming;
616
617                         _missile = _missile.chain;
618                 }
619
620                 if(_incomming)
621                         sound(self, CH_PAIN_SINGLE, "vehicles/missile_alarm.wav", VOL_BASE, ATTEN_NONE);
622
623                 self.bomb1.cnt = time + 1;
624         }
625
626
627         VEHICLE_UPDATE_PLAYER(player, health, raptor);
628         VEHICLE_UPDATE_PLAYER(player, energy, raptor);
629         if(self.vehicle_flags & VHF_HASSHIELD)
630                 VEHICLE_UPDATE_PLAYER(player, shield, raptor);
631
632         player.BUTTON_ATCK = player.BUTTON_ATCK2 = player.BUTTON_CROUCH = 0;
633
634         self = player;
635         return 1;
636 }
637
638 float raptor_takeoff()
639 {
640         entity player, raptor;
641
642         player = self;
643         raptor = self.vehicle;
644         self   = raptor;
645         
646         self.nextthink = time;
647         CSQCMODEL_AUTOUPDATE();
648         self.nextthink = 0; // will this work?
649         
650         if(self.sound_nexttime < time)
651         {
652                 self.sound_nexttime = time + 7.955812; //soundlength("vehicles/raptor_fly.wav");
653                 sound (self, CH_TRIGGER_SINGLE, "vehicles/raptor_speed.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
654         }
655
656         // Takeoff sequense
657         if(raptor.frame < 25)
658         {
659                 raptor.frame += 25 / (autocvar_g_vehicle_raptor_takeofftime / sys_frametime);
660                 raptor.velocity_z = min(raptor.velocity_z * 1.5, 256);
661                 self.bomb1.gun1.avelocity_y = 90 + ((raptor.frame / 25) * 25000);
662                 self.bomb1.gun2.avelocity_y = -self.bomb1.gun1.avelocity_y;
663                 player.BUTTON_ATCK = player.BUTTON_ATCK2 = player.BUTTON_CROUCH = 0;
664
665                 setorigin(player, raptor.origin + '0 0 32');
666         }
667         else
668                 player.PlayerPhysplug = raptor_frame;
669
670         if(self.vehicle_flags  & VHF_SHIELDREGEN)
671                 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);
672
673         if(self.vehicle_flags  & VHF_HEALTHREGEN)
674                 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);
675
676         if(self.vehicle_flags  & VHF_ENERGYREGEN)
677                 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);
678
679
680         raptor.bomb1.alpha = raptor.bomb2.alpha = (time - raptor.lip) / (raptor.delay - raptor.lip);
681         player.vehicle_reload2 = bound(0, raptor.bomb1.alpha * 100, 100);
682         player.vehicle_ammo2 = (player.vehicle_reload2 == 100) ? 100 : 0;
683
684         VEHICLE_UPDATE_PLAYER(player, health, raptor);
685         VEHICLE_UPDATE_PLAYER(player, energy, raptor);
686         if(self.vehicle_flags & VHF_HASSHIELD)
687                 VEHICLE_UPDATE_PLAYER(player, shield, raptor);
688
689         player.BUTTON_ATCK = player.BUTTON_ATCK2 = player.BUTTON_CROUCH = 0;
690         self = player;
691         return 1;
692 }
693
694 void raptor_blowup()
695 {
696         self.deadflag   = DEAD_DEAD;
697         self.vehicle_exit(VHEF_NORMAL);
698         RadiusDamage (self, self.enemy, 250, 15, 250, world, world, 250, DEATH_VH_RAPT_DEATH, world);
699
700         self.alpha                = -1;
701         self.movetype      = MOVETYPE_NONE;
702         self.effects            = EF_NODRAW;
703         self.colormod      = '0 0 0';
704         self.avelocity    = '0 0 0';
705         self.velocity      = '0 0 0';
706
707         setorigin(self, self.pos1);
708         self.touch = func_null;
709         self.nextthink = 0;
710 }
711
712 void raptor_diethink()
713 {
714         if(time >= self.wait)
715                 self.think = raptor_blowup;
716
717         if(random() < 0.05)
718         {
719                 sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
720                 Send_Effect("explosion_small", randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
721         }
722         self.nextthink = time;
723         
724         CSQCMODEL_AUTOUPDATE();
725 }
726
727 // If we dont do this ever now and then, the raptors rotors
728 // stop working, presumably due to angle overflow. cute.
729 void raptor_rotor_anglefix()
730 {
731         self.gun1.angles_y = anglemods(self.gun1.angles_y);
732         self.gun2.angles_y = anglemods(self.gun2.angles_y);
733         self.nextthink = time + 15;
734 }
735
736 float raptor_impulse(float _imp)
737 {
738         switch(_imp)
739         {
740                 case 1:
741                 case 230:
742                         self.vehicle.vehicle_weapon2mode = RSM_BOMB;
743                         CSQCVehicleSetup(self, 0);
744                         return true;
745                 case 2:
746                 case 231:
747                         self.vehicle.vehicle_weapon2mode = RSM_FLARE;
748                         CSQCVehicleSetup(self, 0);
749                         return true;
750
751                 case 10:
752                 case 15:
753                 case 18:
754                         self.vehicle.vehicle_weapon2mode += 1;
755                         if(self.vehicle.vehicle_weapon2mode > RSM_LAST)
756                                 self.vehicle.vehicle_weapon2mode = RSM_FIRST;
757
758                         CSQCVehicleSetup(self, 0);
759                         return true;
760                 case 11:
761                 case 12:
762                 case 16:
763                 case 19:
764                         self.vehicle.vehicle_weapon2mode -= 1;
765                         if(self.vehicle.vehicle_weapon2mode < RSM_FIRST)
766                                 self.vehicle.vehicle_weapon2mode = RSM_LAST;
767
768                         CSQCVehicleSetup(self, 0);
769                         return true;
770
771                 /*
772                 case 17: // toss gun, could be used to exit?
773                         break;
774                 case 20: // Manual minigun reload?
775                         break;
776                 */
777         }
778         return false;
779 }
780
781 void spawnfunc_vehicle_raptor()
782 {
783         if(!autocvar_g_vehicle_raptor) { remove(self); return; }
784         if(!vehicle_initialize(VEH_RAPTOR, false)) { remove(self); return; }
785 }
786
787 float v_raptor(float req)
788 {
789         switch(req)
790         {
791                 case VR_IMPACT:
792                 {
793                         if(autocvar_g_vehicle_raptor_bouncepain)
794                                 vehicles_impact(autocvar_g_vehicle_raptor_bouncepain_x, autocvar_g_vehicle_raptor_bouncepain_y, autocvar_g_vehicle_raptor_bouncepain_z);
795                                 
796                         return true;
797                 }
798                 case VR_ENTER:
799                 {
800                         self.vehicle_weapon2mode = RSM_BOMB;
801                         self.owner.PlayerPhysplug = raptor_takeoff;
802                         self.movetype      = MOVETYPE_BOUNCEMISSILE;
803                         self.solid                = SOLID_SLIDEBOX;
804                         self.owner.vehicle_health = (self.vehicle_health / autocvar_g_vehicle_raptor_health) * 100;
805                         self.owner.vehicle_shield = (self.vehicle_shield / autocvar_g_vehicle_raptor_shield) * 100;
806                         self.velocity_z = 1; // Nudge upwards to takeoff sequense can work.
807                         self.tur_head.exteriormodeltoclient = self.owner;
808
809                         self.delay = time + autocvar_g_vehicle_raptor_bombs_refire;
810                         self.lip   = time;
811
812                         if(self.owner.flagcarried)
813                            setorigin(self.owner.flagcarried, '-20 0 96');
814
815                         CSQCVehicleSetup(self.owner, 0);
816                         return true;
817                 }
818                 case VR_THINK:
819                 {
820                         return true;
821                 }
822                 case VR_DEATH:
823                 {
824                         self.health                             = 0;
825                         self.event_damage               = func_null;
826                         self.solid                              = SOLID_CORPSE;
827                         self.takedamage                 = DAMAGE_NO;
828                         self.deadflag                   = DEAD_DYING;
829                         self.movetype                   = MOVETYPE_BOUNCE;
830                         self.think                              = raptor_diethink;
831                         self.nextthink                  = time;
832                         self.wait                               = time + 5 + (random() * 5);
833
834                         Send_Effect("explosion_medium", findbetterlocation (self.origin, 16), '0 0 0', 1);
835
836                         self.velocity_z += 600;
837
838                         self.avelocity = '0 0.5 1' * (random() * 400);
839                         self.avelocity -= '0 0.5 1' * (random() * 400);
840
841                         self.colormod = '-0.5 -0.5 -0.5';
842                         self.touch = raptor_blowup;
843                         return true;
844                 }
845                 case VR_SPAWN:
846                 {
847                         if(!self.gun1)
848                         {
849                                 entity spinner;
850                                 vector ofs;
851
852                                 //FIXME: Camera is in a bad place in HUD model.
853                                 //setorigin(self.vehicle_viewport, '25 0 5');
854
855                                 self.vehicles_impulse   = raptor_impulse;
856
857                                 self.frame = 0;
858
859                                 self.bomb1 = spawn();
860                                 self.bomb2 = spawn();
861                                 self.gun1  = spawn();
862                                 self.gun2  = spawn();
863
864                                 setmodel(self.bomb1,"models/vehicles/clusterbomb_folded.md3");
865                                 setmodel(self.bomb2,"models/vehicles/clusterbomb_folded.md3");
866                                 setmodel(self.gun1, "models/vehicles/raptor_gun.dpm");
867                                 setmodel(self.gun2, "models/vehicles/raptor_gun.dpm");
868                                 setmodel(self.tur_head, "models/vehicles/raptor_body.dpm");
869
870                                 setattachment(self.bomb1, self, "bombmount_left");
871                                 setattachment(self.bomb2, self, "bombmount_right");
872                                 setattachment(self.tur_head, self,"root");
873
874                                 // FIXMODEL Guns mounts to angled bones
875                                 self.bomb1.angles = self.angles;
876                                 self.angles = '0 0 0';
877                                 // This messes up gun-aim, so work arround it.
878                                 //setattachment(self.gun1, self, "gunmount_left");
879                                 ofs = gettaginfo(self, gettagindex(self, "gunmount_left"));
880                                 ofs -= self.origin;
881                                 setattachment(self.gun1, self, "");
882                                 setorigin(self.gun1, ofs);
883
884                                 //setattachment(self.gun2, self, "gunmount_right");
885                                 ofs = gettaginfo(self, gettagindex(self, "gunmount_right"));
886                                 ofs -= self.origin;
887                                 setattachment(self.gun2, self, "");
888                                 setorigin(self.gun2, ofs);
889
890                                 self.angles = self.bomb1.angles;
891                                 self.bomb1.angles = '0 0 0';
892
893                                 spinner = spawn();
894                                 spinner.owner = self;
895                                 setmodel(spinner,"models/vehicles/spinner.dpm");
896                                 setattachment(spinner, self, "engine_left");
897                                 spinner.movetype = MOVETYPE_NOCLIP;
898                                 spinner.avelocity = '0 90 0';
899                                 self.bomb1.gun1 = spinner;
900
901                                 spinner = spawn();
902                                 spinner.owner = self;
903                                 setmodel(spinner,"models/vehicles/spinner.dpm");
904                                 setattachment(spinner, self, "engine_right");
905                                 spinner.movetype = MOVETYPE_NOCLIP;
906                                 spinner.avelocity = '0 -90 0';
907                                 self.bomb1.gun2 = spinner;
908
909                                 // Sigh.
910                                 self.bomb1.think = raptor_rotor_anglefix;
911                                 self.bomb1.nextthink = time;
912
913                                 self.mass                          = 1 ;
914                         }
915
916                         self.frame                = 0;
917                         self.vehicle_health = autocvar_g_vehicle_raptor_health;
918                         self.vehicle_shield = autocvar_g_vehicle_raptor_shield;
919                         self.movetype      = MOVETYPE_TOSS;
920                         self.solid                = SOLID_SLIDEBOX;
921                         self.vehicle_energy = 1;
922                         
923                         self.PlayerPhysplug = raptor_frame;
924
925                         self.bomb1.gun1.avelocity_y = 90;
926                         self.bomb1.gun2.avelocity_y = -90;
927                         
928                         self.delay = time;
929
930                         self.bouncefactor = autocvar_g_vehicle_raptor_bouncefactor;
931                         self.bouncestop = autocvar_g_vehicle_raptor_bouncestop;
932                         self.damageforcescale = 0.25;
933                         self.vehicle_health = autocvar_g_vehicle_raptor_health;
934                         self.vehicle_shield = autocvar_g_vehicle_raptor_shield;
935                         return true;
936                 }
937                 case VR_SETUP:
938                 {
939                         if(autocvar_g_vehicle_raptor_shield)
940                                 self.vehicle_flags |= VHF_HASSHIELD;
941
942                         if(autocvar_g_vehicle_raptor_shield_regen)
943                                 self.vehicle_flags |= VHF_SHIELDREGEN;
944
945                         if(autocvar_g_vehicle_raptor_health_regen)
946                                 self.vehicle_flags |= VHF_HEALTHREGEN;
947
948                         if(autocvar_g_vehicle_raptor_energy_regen)
949                                 self.vehicle_flags |= VHF_ENERGYREGEN;
950                                 
951                         self.vehicle_exit = raptor_exit;
952                         self.respawntime = autocvar_g_vehicle_raptor_respawntime;
953                         self.vehicle_health = autocvar_g_vehicle_raptor_health;
954                         self.vehicle_shield = autocvar_g_vehicle_raptor_shield;
955                         self.max_health = self.vehicle_health;
956                                 
957                         return true;
958                 }
959                 case VR_PRECACHE:
960                 {
961                         precache_model ("models/vehicles/raptor.dpm");
962                         precache_model ("models/vehicles/raptor_gun.dpm");
963                         precache_model ("models/vehicles/spinner.dpm");
964                         precache_model ("models/vehicles/raptor_cockpit.dpm");
965                         precache_model ("models/vehicles/clusterbomb_folded.md3");
966                         precache_model ("models/vehicles/raptor_body.dpm");
967
968                         precache_sound ("vehicles/raptor_fly.wav");
969                         precache_sound ("vehicles/raptor_speed.wav");
970                         precache_sound ("vehicles/missile_alarm.wav");
971                 
972                         return true;
973                 }
974         }
975
976         return true;
977 }
978
979 #endif // SVQC
980 #ifdef CSQC
981
982 void RaptorCBShellfragDraw()
983 {
984         if(wasfreed(self))
985                 return;
986
987         Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
988         self.move_avelocity += randomvec() * 15;
989         self.renderflags = 0;
990
991         if(self.cnt < time)
992                 self.alpha = bound(0, self.nextthink - time, 1);
993
994         if(self.alpha < ALPHA_MIN_VISIBLE)
995                 remove(self);
996 }
997
998 void RaptorCBShellfragToss(vector _org, vector _vel, vector _ang)
999 {
1000         entity sfrag;
1001
1002         sfrag = spawn();
1003         setmodel(sfrag, "models/vehicles/clusterbomb_fragment.md3");
1004         setorigin(sfrag, _org);
1005
1006         sfrag.move_movetype = MOVETYPE_BOUNCE;
1007         sfrag.gravity = 0.15;
1008         sfrag.solid = SOLID_CORPSE;
1009
1010         sfrag.draw = RaptorCBShellfragDraw;
1011
1012         sfrag.move_origin = sfrag.origin = _org;
1013         sfrag.move_velocity = _vel;
1014         sfrag.move_avelocity = prandomvec() * vlen(sfrag.move_velocity);
1015         sfrag.angles = self.move_angles = _ang;
1016
1017         sfrag.move_time = time;
1018         sfrag.damageforcescale = 4;
1019
1020         sfrag.nextthink = time + 3;
1021         sfrag.cnt = time + 2;
1022         sfrag.alpha = 1;
1023         sfrag.drawmask = MASK_NORMAL;
1024 }
1025
1026 float v_raptor(float req)
1027 {
1028         switch(req)
1029         {
1030                 case VR_HUD:
1031                 {
1032                         string crosshair;
1033
1034                         switch(weapon2mode)
1035                         {
1036                                 case RSM_FLARE: crosshair = vCROSS_RAIN;  break;
1037                                 case RSM_BOMB:  crosshair = vCROSS_BURST; break;
1038                                 default:        crosshair = vCROSS_BURST;
1039                         }
1040                         
1041                         Vehicles_drawHUD("vehicle_raptor", "vehicle_raptor_weapon1", "vehicle_raptor_weapon2",
1042                                                          "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
1043                                                          "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color,
1044                                                          crosshair);
1045                         return true;
1046                 }
1047                 case VR_SETUP:
1048                 {
1049                         AuxiliaryXhair[1].axh_image = vCROSS_LOCK;
1050                         return true;
1051                 }
1052                 case VR_PRECACHE:
1053                 {
1054                         return true;
1055                 }
1056         }
1057
1058         return true;
1059 }
1060
1061 #endif // CSQC
1062 #endif // REGISTER_VEHICLE