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