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