Merge remote-tracking branch 'origin/master' into samual/spawn_weapons
[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, 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
629     RadiusDamage (self, self.enemy, 250, 15, 250, world, world, 250, DEATH_WAKIBLOWUP, world);
630
631     self.alpha          = -1;
632     self.movetype       = MOVETYPE_NONE;
633     self.effects        = EF_NODRAW;
634     self.colormod       = '0 0 0';
635     self.avelocity      = '0 0 0';
636     self.velocity       = '0 0 0';
637
638     setorigin(self, self.pos1);
639     self.touch = SUB_Null;
640     self.nextthink = 0;
641 }
642
643 void raptor_diethink()
644 {
645     if(random() < 0.1)
646     {
647         sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
648         pointparticles(particleeffectnum("explosion_small"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
649     }
650     self.nextthink = time + 0.1;
651 }
652
653 void raptor_die()
654 {
655     self.health       = 0;
656     self.event_damage = SUB_Null;
657     self.solid        = SOLID_CORPSE;
658     self.takedamage   = DAMAGE_NO;
659     self.deadflag     = DEAD_DYING;
660     self.movetype     = MOVETYPE_BOUNCE;
661     self.think        = raptor_diethink;
662     self.nextthink    = time;
663     
664     pointparticles(particleeffectnum("explosion_medium"), findbetterlocation (self.origin, 16), '0 0 0', 1);
665
666     self.velocity_z += 600;
667
668     self.avelocity = '0 0.5 1' * (random() * 400);
669     self.avelocity -= '0 0.5 1' * (random() * 400);
670
671     self.colormod = '-0.5 -0.5 -0.5';
672         self.touch     = raptor_blowup;
673 }
674
675 void raptor_impact()
676 {
677     if(autocvar_g_vehicle_raptor_bouncepain_x)
678         vehilces_impact(autocvar_g_vehicle_raptor_bouncepain_x, autocvar_g_vehicle_raptor_bouncepain_y, autocvar_g_vehicle_raptor_bouncepain_z);
679 }
680
681 void raptor_spawn()
682 {
683     self.frame          = 0;
684     self.vehicle_health = autocvar_g_vehicle_raptor_health;
685     self.vehicle_shield = autocvar_g_vehicle_raptor_shield;
686     self.movetype       = MOVETYPE_TOSS;
687     self.solid          = SOLID_SLIDEBOX;
688     self.vehicle_energy = 1;
689
690     self.bomb1.gun1.avelocity_y = 90;
691     self.bomb1.gun2.avelocity_y = -90;
692
693     setsize(self, RAPTOR_MIN, RAPTOR_MAX );
694     self.delay = time;
695         
696     self.bouncefactor = autocvar_g_vehicle_raptor_bouncefactor;
697     self.bouncestop = autocvar_g_vehicle_raptor_bouncestop;    
698     self.vehicle_impact = raptor_impact;    
699 }
700
701 // If we dont do this ever now and then, the raptors rotors
702 // stop working, presumably due to angle overflow. cute.
703 void raptor_rotor_anglefix()
704 {
705     self.gun1.angles_y = anglemods(self.gun1.angles_y);
706     self.gun2.angles_y = anglemods(self.gun2.angles_y);
707     self.nextthink = time + 15;
708 }
709 float raptor_impulse(float _imp)
710 {
711     switch(_imp)
712     {
713         case 10:
714         case 15:        
715         case 18:
716             self.vehicle.vehicle_weapon2mode += 1;
717             if(self.vehicle.vehicle_weapon2mode > RSM_LAST)
718                 self.vehicle.vehicle_weapon2mode = RSM_FIRST;
719             
720             CSQCVehicleSetup(self, 0);
721             return TRUE;
722         case 12:
723         case 16:
724         case 19:
725             self.vehicle.vehicle_weapon2mode -= 1;
726             if(self.vehicle.vehicle_weapon2mode < RSM_FIRST)
727                 self.vehicle.vehicle_weapon2mode = RSM_LAST;
728             
729             CSQCVehicleSetup(self, 0);
730             return TRUE;
731
732         /*                      
733         case 17: // toss gun, could be used to exit?
734             break;
735         case 20: // Manual minigun reload?
736             break;
737         */
738     }    
739     return FALSE;
740 }
741
742 void raptor_dinit()
743 {
744     entity spinner;
745     vector ofs;
746
747     if not (vehicle_initialize(
748              "Raptor",
749              "models/vehicles/raptor.dpm",
750              "",
751              "models/vehicles/raptor_cockpit.dpm",
752              "", "tag_hud", "tag_camera",
753              HUD_RAPTOR,
754              RAPTOR_MIN, RAPTOR_MAX,
755              FALSE,
756              raptor_spawn, autocvar_g_vehicle_raptor_respawntime,
757              raptor_frame,
758              raptor_enter, raptor_exit,
759              raptor_die,   raptor_think,
760              FALSE, 
761              autocvar_g_vehicle_raptor_health))
762     {
763         remove(self);
764         return;
765     }
766
767     //FIXME: Camera is in a bad place in HUD model.
768     //setorigin(self.vehicle_viewport, '25 0 5');
769     
770     self.vehicles_impusle   = raptor_impulse;
771     
772     self.frame = 0;
773
774     self.bomb1 = spawn();
775     self.bomb2 = spawn();
776     self.gun1  = spawn();
777     self.gun2  = spawn();
778
779     setmodel(self.bomb1,"models/vehicles/clusterbomb_folded.md3");
780     setmodel(self.bomb2,"models/vehicles/clusterbomb_folded.md3");
781     setmodel(self.gun1, "models/vehicles/raptor_gun.dpm");
782     setmodel(self.gun2, "models/vehicles/raptor_gun.dpm");
783     setmodel(self.tur_head, "models/vehicles/raptor_body.dpm");
784
785     setattachment(self.bomb1, self,"bombmount_left");
786     setattachment(self.bomb2, self,"bombmount_right");
787     setattachment(self.tur_head, self,"root");
788
789
790     // FIXMODEL Guns mounts to angled bones
791     self.bomb1.angles = self.angles;
792     self.angles = '0 0 0';
793     // This messes up gun-aim, so work arround it.
794     //setattachment(self.gun1, self, "gunmount_left");
795     ofs = gettaginfo(self, gettagindex(self, "gunmount_left"));
796     ofs -= self.origin;
797     setattachment(self.gun1, self, "");
798     setorigin(self.gun1, ofs);
799
800     //setattachment(self.gun2, self, "gunmount_right");
801     ofs = gettaginfo(self, gettagindex(self, "gunmount_right"));
802     ofs -= self.origin;
803     setattachment(self.gun2, self, "");
804     setorigin(self.gun2, ofs);
805
806     self.angles = self.bomb1.angles;
807     self.bomb1.angles = '0 0 0';
808
809     spinner = spawn();
810     spinner.owner = self;
811     setmodel(spinner,"models/vehicles/spinner.dpm");
812     setattachment(spinner, self, "engine_left");
813     spinner.movetype = MOVETYPE_NOCLIP;
814     spinner.avelocity = '0 90 0';
815     self.bomb1.gun1 = spinner;
816
817     spinner = spawn();
818     spinner.owner = self;
819     setmodel(spinner,"models/vehicles/spinner.dpm");
820     setattachment(spinner, self, "engine_right");
821     spinner.movetype = MOVETYPE_NOCLIP;
822     spinner.avelocity = '0 -90 0';
823     self.bomb1.gun2 = spinner;
824
825     // Sigh.
826     self.bomb1.think = raptor_rotor_anglefix;
827     self.bomb1.nextthink = time;
828
829     self.mass               = 1 ;
830 }
831
832 void spawnfunc_vehicle_raptor()
833 {
834     vehicles_configcheck("vehicle_raptor.cfg", autocvar_g_vehicle_raptor_health);
835
836     self.vehicle_flags |= VHF_DMGSHAKE;
837     self.vehicle_flags |= VHF_DMGROLL;
838    
839     if(autocvar_g_vehicle_raptor_shield)
840         self.vehicle_flags |= VHF_HASSHIELD;
841
842     if(autocvar_g_vehicle_raptor_shield_regen)
843         self.vehicle_flags |= VHF_SHIELDREGEN;
844
845     if(autocvar_g_vehicle_raptor_health_regen)
846         self.vehicle_flags |= VHF_HEALTHREGEN;
847
848     if(autocvar_g_vehicle_raptor_energy_regen)
849         self.vehicle_flags |= VHF_ENERGYREGEN;
850
851     precache_model ("models/vehicles/raptor.dpm");
852     precache_model ("models/vehicles/raptor_gun.dpm");
853     precache_model ("models/vehicles/spinner.dpm");
854     precache_model ("models/vehicles/raptor_cockpit.dpm");
855     //precache_model ("models/vehicles/clusterbomb.md3");
856     precache_model ("models/vehicles/clusterbomb_folded.md3");
857     precache_model ("models/vehicles/raptor_body.dpm");
858     
859     precache_sound ("vehicles/raptor_fly.wav");
860     precache_sound ("vehicles/raptor_speed.wav");
861     precache_sound ("vehicles/missile_alarm.wav");
862     
863     self.think = raptor_dinit;
864     
865     if(g_assault)
866         self.nextthink = time + 0.5;
867     else
868         self.nextthink = time + (autocvar_g_vehicles_delayspawn ? autocvar_g_vehicle_raptor_respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter) : 0.5);
869 }
870 #endif // SVQC