]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/vehicles/raptor.qc
996fbc7c9b8f7c40700edadb5ebd7789ea0c560e
[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);
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);
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);
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_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
324 {
325     self.health -= damage;
326     if(self.health <= 0)
327         remove(self);
328 }
329
330 void raptor_flare_think()
331 {
332     self.nextthink = time + 0.1;
333     entity _missile = findchainentity(enemy, self.owner);
334     while(_missile)
335     {
336         if(_missile.flags & FL_PROJECTILE)
337         if(vlen(self.origin - _missile.origin) < autocvar_g_vehicle_raptor_flare_range)
338         if(random() > autocvar_g_vehicle_raptor_flare_chase)
339             _missile.enemy = self;
340         _missile = _missile.chain;
341     }
342     
343     if(self.tur_impacttime < time)
344         remove(self);
345 }
346
347 float raptor_frame()
348 {
349     entity player, raptor;
350     float ftmp = 0;
351     vector df;
352     
353         if(intermission_running)
354                 return 1;
355
356     player = self;
357     raptor = self.vehicle;
358     self   = raptor;
359     vehicles_painframe();
360     /*
361     ftmp = vlen(self.velocity);
362     if(ftmp > autocvar_g_vehicle_raptor_speed_forward) 
363         ftmp = 1;
364     else  
365         ftmp = ftmp / autocvar_g_vehicle_raptor_speed_forward;
366     */
367         
368     if(self.sound_nexttime < time)
369     {        
370         self.sound_nexttime = time + 7.955812; 
371         //sound (self.tur_head, CH_TRIGGER_SINGLE, "vehicles/raptor_fly.wav", 1 - ftmp,   ATTN_NORM );
372         sound (self, CH_TRIGGER_SINGLE, "vehicles/raptor_speed.wav", 1, ATTN_NORM);        
373         self.wait = ftmp;
374     }        
375     /*
376     else if(fabs(ftmp - self.wait) > 0.2)
377     {
378         sound (self.tur_head, CH_TRIGGER_SINGLE, "", 1 - ftmp,   ATTN_NORM );
379         sound (self, CH_TRIGGER_SINGLE, "", ftmp, ATTN_NORM);        
380         self.wait = ftmp;
381     }
382     */
383     
384     if(raptor.deadflag != DEAD_NO)
385     {
386         self = player;
387         player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
388         return 1;
389     }
390     crosshair_trace(player);
391
392     vector vang;
393     vang = raptor.angles;
394     df = vectoangles(normalize(trace_endpos - self.origin + '0 0 32'));
395     vang_x *= -1;
396     df_x *= -1;
397     if(df_x > 180)  df_x -= 360;
398     if(df_x < -180) df_x += 360;
399     if(df_y > 180)  df_y -= 360;
400     if(df_y < -180) df_y += 360;
401
402     ftmp = shortangle_f(player.v_angle_y - vang_y, vang_y);
403     if(ftmp > 180)  ftmp -= 360; if(ftmp < -180) ftmp += 360;
404     raptor.avelocity_y = bound(-autocvar_g_vehicle_raptor_turnspeed, ftmp + raptor.avelocity_y * 0.9, autocvar_g_vehicle_raptor_turnspeed);
405
406     // Pitch
407     ftmp = 0;
408     if(player.movement_x > 0 && vang_x < autocvar_g_vehicle_raptor_pitchlimit) ftmp = 5;
409     else if(player.movement_x < 0 && vang_x > -autocvar_g_vehicle_raptor_pitchlimit) ftmp = -20;
410
411     df_x = bound(-autocvar_g_vehicle_raptor_pitchlimit, df_x , autocvar_g_vehicle_raptor_pitchlimit);
412     ftmp = vang_x - bound(-autocvar_g_vehicle_raptor_pitchlimit, df_x + ftmp, autocvar_g_vehicle_raptor_pitchlimit);
413     raptor.avelocity_x = bound(-autocvar_g_vehicle_raptor_pitchspeed, ftmp + raptor.avelocity_x * 0.9, autocvar_g_vehicle_raptor_pitchspeed);
414
415     raptor.angles_x = anglemods(raptor.angles_x);
416     raptor.angles_y = anglemods(raptor.angles_y);
417     raptor.angles_z = anglemods(raptor.angles_z);
418
419     if(autocvar_g_vehicle_raptor_movestyle == 1)
420         makevectors('0 1 0' * raptor.angles_y);
421     else
422         makevectors(player.v_angle);
423
424     df = raptor.velocity * -autocvar_g_vehicle_raptor_friction;
425
426     if(player.movement_x != 0)
427     {
428         if(player.movement_x > 0)
429             df += v_forward  * autocvar_g_vehicle_raptor_speed_forward;
430         else if(player.movement_x < 0)
431             df -= v_forward  * autocvar_g_vehicle_raptor_speed_forward;
432     }
433
434     if(player.movement_y != 0)
435     {
436         if(player.movement_y < 0)
437             df -= v_right * autocvar_g_vehicle_raptor_speed_strafe;
438         else if(player.movement_y > 0)
439             df += v_right * autocvar_g_vehicle_raptor_speed_strafe;
440
441         raptor.angles_z = bound(-30,raptor.angles_z + (player.movement_y / autocvar_g_vehicle_raptor_speed_strafe),30);
442     }
443     else
444     {
445         raptor.angles_z *= 0.95;
446         if(raptor.angles_z >= -1 && raptor.angles_z <= -1)
447             raptor.angles_z = 0;
448     }
449
450     if(player.BUTTON_CROUCH)
451         df -=   v_up * autocvar_g_vehicle_raptor_speed_down;
452     else if (player.BUTTON_JUMP)
453         df +=  v_up * autocvar_g_vehicle_raptor_speed_up;
454
455     raptor.velocity  += df * frametime;
456     player.velocity = player.movement  = raptor.velocity;
457     setorigin(player, raptor.origin + '0 0 32');
458
459     vector vf, ad;
460     // Target lock & predict
461     if(autocvar_g_vehicle_raptor_cannon_locktarget)
462     {
463
464         vehicles_locktarget((1 / autocvar_g_vehicle_raptor_cannon_locking_time) * frametime,
465                              (1 / autocvar_g_vehicle_raptor_cannon_locking_releasetime) * frametime,
466                              autocvar_g_vehicle_raptor_cannon_locked_time);
467
468         if(self.lock_target != world)
469         if(autocvar_g_vehicle_raptor_cannon_predicttarget)
470         if(self.lock_strength == 1)
471         {
472             float i, distance, impact_time;
473
474             vf = real_origin(raptor.lock_target);
475             ad = vf;
476             for(i = 0; i < 4; ++i)
477             {
478                 distance = vlen(ad - raptor.origin);
479                 impact_time = distance / autocvar_g_vehicle_raptor_cannon_speed;
480                 ad = vf + raptor.lock_target.velocity * impact_time;
481             }
482             trace_endpos = ad;
483         }
484
485         if(self.lock_target)
486         {
487             if(raptor.lock_strength == 1)
488                 UpdateAuxiliaryXhair(player, real_origin(raptor.lock_target), '1 0 0', 1);
489             else if(self.lock_strength > 0.5)
490                 UpdateAuxiliaryXhair(player, real_origin(raptor.lock_target), '0 1 0', 1);
491             else if(self.lock_strength < 0.5)
492                 UpdateAuxiliaryXhair(player, real_origin(raptor.lock_target), '0 0 1', 1);
493         }
494     }
495
496
497     vehicle_aimturret(raptor, trace_endpos, raptor.gun1, "fire1", 
498                           autocvar_g_vehicle_raptor_cannon_pitchlimit_down * -1,  autocvar_g_vehicle_raptor_cannon_pitchlimit_up, 
499                           autocvar_g_vehicle_raptor_cannon_turnlimit * -1,  autocvar_g_vehicle_raptor_cannon_turnlimit,  autocvar_g_vehicle_raptor_cannon_turnspeed);
500
501     vehicle_aimturret(raptor, trace_endpos, raptor.gun2, "fire1", 
502                           autocvar_g_vehicle_raptor_cannon_pitchlimit_down * -1,  autocvar_g_vehicle_raptor_cannon_pitchlimit_up, 
503                           autocvar_g_vehicle_raptor_cannon_turnlimit * -1,  autocvar_g_vehicle_raptor_cannon_turnlimit,  autocvar_g_vehicle_raptor_cannon_turnspeed);
504
505     /*
506     ad = ad * 0.5;
507     v_forward = vf * 0.5;
508     traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, raptor);
509     UpdateAuxiliaryXhair(player, trace_endpos, '0 1 0', 0);
510     */
511     
512     if(player.BUTTON_ATCK)
513     if(raptor.attack_finished_single <= time)
514     if(raptor.vehicle_energy > autocvar_g_vehicle_raptor_cannon_cost)
515     {
516         raptor.misc_bulletcounter += 1;
517         raptor.attack_finished_single = time + autocvar_g_vehicle_raptor_cannon_refire;
518         if(raptor.misc_bulletcounter <= 2)
519             raptor_fire_cannon(self.gun1, "fire1");
520         else if(raptor.misc_bulletcounter == 3)
521             raptor_fire_cannon(self.gun2, "fire1");
522         else
523         {
524             raptor.attack_finished_single = time + autocvar_g_vehicle_raptor_cannon_refire * 2;
525             raptor_fire_cannon(self.gun2, "fire1");
526             raptor.misc_bulletcounter = 0;
527         }
528         raptor.vehicle_energy -= autocvar_g_vehicle_raptor_cannon_cost;
529         self.cnt = time;
530     }
531
532     if(self.vehicle_flags  & VHF_SHIELDREGEN)
533         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);
534
535     if(self.vehicle_flags  & VHF_HEALTHREGEN)
536         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);
537
538     if(self.vehicle_flags  & VHF_ENERGYREGEN)
539         vehicles_regen(cnt, vehicle_energy, autocvar_g_vehicle_raptor_energy, autocvar_g_vehicle_raptor_energy_regen_pause, autocvar_g_vehicle_raptor_energy_regen, frametime);
540
541     if(raptor.vehicle_weapon2mode == RSM_BOMB)
542     {
543         if(time > raptor.lip + autocvar_g_vehicle_raptor_bombs_refire)
544         if(player.BUTTON_ATCK2)
545         {
546             raptor_bombdrop();
547             raptor.delay = time + autocvar_g_vehicle_raptor_bombs_refire;
548             raptor.lip   = time;
549         }        
550     }
551     else
552     {
553         if(time > raptor.lip + autocvar_g_vehicle_raptor_flare_refire)
554         if(player.BUTTON_ATCK2)
555         {
556             float i;
557             entity _flare;
558             
559             for(i = 0; i < 3; ++i)
560             {
561             _flare = spawn();
562             setmodel(_flare, "models/runematch/rune.mdl"); 
563             _flare.effects = EF_LOWPRECISION | EF_FLAME;
564             _flare.scale = 0.5;
565             setorigin(_flare, self.origin - '0 0 16');
566             _flare.movetype = MOVETYPE_TOSS;
567             _flare.gravity = 0.15;
568             _flare.velocity = 0.25 * raptor.velocity + (v_forward + randomvec() * 0.25)* -500;
569             _flare.think = raptor_flare_think;
570             _flare.nextthink = time;
571             _flare.owner = raptor;
572             _flare.solid = SOLID_CORPSE;
573             _flare.takedamage = DAMAGE_YES;
574             _flare.event_damage = raptor_flare_damage;
575             _flare.health = 20;
576             _flare.tur_impacttime = time + autocvar_g_vehicle_raptor_flare_lifetime;
577             }
578             raptor.delay = time + autocvar_g_vehicle_raptor_flare_refire;
579             raptor.lip   = time;
580         }
581     }
582     
583     raptor.bomb1.alpha = raptor.bomb2.alpha = (time - raptor.lip) / (raptor.delay - raptor.lip);
584     player.vehicle_reload2 = bound(0, raptor.bomb1.alpha * 100, 100);
585
586     VEHICLE_UPDATE_PLAYER(health, raptor);
587     VEHICLE_UPDATE_PLAYER(energy, raptor);
588     if(self.vehicle_flags & VHF_HASSHIELD)
589         VEHICLE_UPDATE_PLAYER(shield, raptor);
590
591     player.BUTTON_ATCK = player.BUTTON_ATCK2 = player.BUTTON_CROUCH = 0;
592     
593     self = player;
594     return 1;
595 }
596
597 void raptor_blowup()
598 {
599     self.deadflag    = DEAD_DEAD;
600     self.vehicle_exit(VHEF_NORMAL);
601     RadiusDamage (self, self.enemy, 250, 15, 250, world, 250, DEATH_WAKIBLOWUP, world);
602
603     self.alpha          = -1;
604     self.movetype       = MOVETYPE_NONE;
605     self.effects        = EF_NODRAW;
606     self.colormod       = '0 0 0';
607     self.avelocity      = '0 0 0';
608     self.velocity       = '0 0 0';
609
610     setorigin(self, self.pos1);
611     self.touch = SUB_Null;
612     self.nextthink = 0;
613 }
614
615 void raptor_diethink()
616 {
617     if(random() < 0.1)
618     {
619         sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
620         pointparticles(particleeffectnum("explosion_small"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
621     }
622     self.nextthink = time + 0.1;
623 }
624
625 void raptor_die()
626 {
627     self.health       = 0;
628     self.event_damage = SUB_Null;
629     self.solid        = SOLID_CORPSE;
630     self.takedamage   = DAMAGE_NO;
631     self.deadflag     = DEAD_DYING;
632     self.movetype     = MOVETYPE_BOUNCE;
633     self.think        = raptor_diethink;
634     self.nextthink    = time;
635     
636     pointparticles(particleeffectnum("explosion_medium"), findbetterlocation (self.origin, 16), '0 0 0', 1);
637
638     self.velocity_z += 600;
639
640     self.avelocity = '0 0.5 1' * (random() * 400);
641     self.avelocity -= '0 0.5 1' * (random() * 400);
642
643     self.colormod = '-0.5 -0.5 -0.5';
644         self.touch     = raptor_blowup;
645 }
646
647 void raptor_impact()
648 {
649     if(autocvar_g_vehicle_raptor_bouncepain_x)
650         vehilces_impact(autocvar_g_vehicle_raptor_bouncepain_x, autocvar_g_vehicle_raptor_bouncepain_y, autocvar_g_vehicle_raptor_bouncepain_z);
651 }
652
653 void raptor_spawn()
654 {
655     self.frame          = 0;
656     self.vehicle_health = autocvar_g_vehicle_raptor_health;
657     self.vehicle_shield = autocvar_g_vehicle_raptor_shield;
658     self.movetype       = MOVETYPE_TOSS;
659     self.solid          = SOLID_SLIDEBOX;
660     self.vehicle_energy = 1;
661
662     self.bomb1.gun1.avelocity_y = 90;
663     self.bomb1.gun2.avelocity_y = -90;
664
665     setsize(self, RAPTOR_MIN, RAPTOR_MAX );
666     self.delay = time;
667         
668     self.bouncefactor = autocvar_g_vehicle_raptor_bouncefactor;
669     self.bouncestop = autocvar_g_vehicle_raptor_bouncestop;    
670     self.vehicle_impact = raptor_impact;    
671 }
672
673 // If we dont do this ever now and then, the raptors rotors
674 // stop working, presumably due to angle overflow. cute.
675 void raptor_rotor_anglefix()
676 {
677     self.gun1.angles_y = anglemods(self.gun1.angles_y);
678     self.gun2.angles_y = anglemods(self.gun2.angles_y);
679     self.nextthink = time + 15;
680 }
681 float raptor_impulse(float _imp)
682 {
683     switch(_imp)
684     {
685         case 10:
686         case 15:        
687         case 18:
688             self.vehicle.vehicle_weapon2mode += 1;
689             if(self.vehicle.vehicle_weapon2mode > RSM_LAST)
690                 self.vehicle.vehicle_weapon2mode = RSM_FIRST;
691             
692             CSQCVehicleSetup(self, 0);
693             return TRUE;
694         case 12:
695         case 16:
696         case 19:
697             self.vehicle.vehicle_weapon2mode -= 1;
698             if(self.vehicle.vehicle_weapon2mode < RSM_FIRST)
699                 self.vehicle.vehicle_weapon2mode = RSM_LAST;
700             
701             CSQCVehicleSetup(self, 0);
702             return TRUE;
703
704         /*                      
705         case 17: // toss gun, could be used to exit?
706             break;
707         case 20: // Manual minigun reload?
708             break;
709         */
710     }    
711     return FALSE;
712 }
713
714 void raptor_dinit()
715 {
716     entity spinner;
717     vector ofs;
718
719     if not (vehicle_initialize(
720              "Raptor",
721              "models/vehicles/raptor.dpm",
722              "",
723              "models/vehicles/raptor_cockpit.dpm",
724              "", "tag_hud", "tag_camera",
725              HUD_RAPTOR,
726              RAPTOR_MIN, RAPTOR_MAX,
727              FALSE,
728              raptor_spawn, autocvar_g_vehicle_raptor_respawntime,
729              raptor_frame,
730              raptor_enter, raptor_exit,
731              raptor_die,   raptor_think,
732              FALSE))
733     {
734         remove(self);
735         return;
736     }
737
738     //FIXME: Camera is in a bad place in HUD model.
739     //setorigin(self.vehicle_viewport, '25 0 5');
740     
741     self.vehicles_impusle   = raptor_impulse;
742     
743     self.frame = 0;
744
745     self.bomb1 = spawn();
746     self.bomb2 = spawn();
747     self.gun1  = spawn();
748     self.gun2  = spawn();
749
750     setmodel(self.bomb1,"models/vehicles/clusterbomb_folded.md3");
751     setmodel(self.bomb2,"models/vehicles/clusterbomb_folded.md3");
752     setmodel(self.gun1, "models/vehicles/raptor_gun.dpm");
753     setmodel(self.gun2, "models/vehicles/raptor_gun.dpm");
754     setmodel(self.tur_head, "models/vehicles/raptor_body.dpm");
755
756     setattachment(self.bomb1, self,"bombmount_left");
757     setattachment(self.bomb2, self,"bombmount_right");
758     setattachment(self.tur_head, self,"root");
759
760
761     // FIXMODEL Guns mounts to angled bones
762     self.bomb1.angles = self.angles;
763     self.angles = '0 0 0';
764     // This messes up gun-aim, so work arround it.
765     //setattachment(self.gun1, self, "gunmount_left");
766     ofs = gettaginfo(self, gettagindex(self, "gunmount_left"));
767     ofs -= self.origin;
768     setattachment(self.gun1, self, "");
769     setorigin(self.gun1, ofs);
770
771     //setattachment(self.gun2, self, "gunmount_right");
772     ofs = gettaginfo(self, gettagindex(self, "gunmount_right"));
773     ofs -= self.origin;
774     setattachment(self.gun2, self, "");
775     setorigin(self.gun2, ofs);
776
777     self.angles = self.bomb1.angles;
778     self.bomb1.angles = '0 0 0';
779
780     spinner = spawn();
781     spinner.owner = self;
782     setmodel(spinner,"models/vehicles/spinner.dpm");
783     setattachment(spinner, self, "engine_left");
784     spinner.movetype = MOVETYPE_NOCLIP;
785     spinner.avelocity = '0 90 0';
786     self.bomb1.gun1 = spinner;
787
788     spinner = spawn();
789     spinner.owner = self;
790     setmodel(spinner,"models/vehicles/spinner.dpm");
791     setattachment(spinner, self, "engine_right");
792     spinner.movetype = MOVETYPE_NOCLIP;
793     spinner.avelocity = '0 -90 0';
794     self.bomb1.gun2 = spinner;
795
796     // Sigh.
797     self.bomb1.think = raptor_rotor_anglefix;
798     self.bomb1.nextthink = time;
799
800     self.mass               = 1 ;
801 }
802
803 void spawnfunc_vehicle_raptor()
804 {
805     vehicles_configcheck("vehicle_raptor.cfg", autocvar_g_vehicle_raptor_health);
806
807     self.vehicle_flags |= VHF_DMGSHAKE;
808     self.vehicle_flags |= VHF_DMGROLL;
809    
810     if(autocvar_g_vehicle_raptor_shield)
811         self.vehicle_flags |= VHF_HASSHIELD;
812
813     if(autocvar_g_vehicle_raptor_shield_regen)
814         self.vehicle_flags |= VHF_SHIELDREGEN;
815
816     if(autocvar_g_vehicle_raptor_health_regen)
817         self.vehicle_flags |= VHF_HEALTHREGEN;
818
819     if(autocvar_g_vehicle_raptor_energy_regen)
820         self.vehicle_flags |= VHF_ENERGYREGEN;
821
822     precache_model ("models/vehicles/raptor.dpm");
823     precache_model ("models/vehicles/raptor_gun.dpm");
824     precache_model ("models/vehicles/spinner.dpm");
825     precache_model ("models/vehicles/raptor_cockpit.dpm");
826     //precache_model ("models/vehicles/clusterbomb.md3");
827     precache_model ("models/vehicles/clusterbomb_folded.md3");
828     precache_model ("models/vehicles/raptor_body.dpm");
829     
830     precache_sound ("vehicles/raptor_fly.wav");
831     precache_sound ("vehicles/raptor_speed.wav");
832     
833     self.think = raptor_dinit;
834     
835     if(g_assault)
836         self.nextthink = time + 0.5;
837     else
838         self.nextthink = time + (autocvar_g_vehicles_delayspawn ? autocvar_g_vehicle_raptor_respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter) : 0.5);
839 }
840 #endif // SVQC