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