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