]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/vehicle/raptor.qc
Set self in vehicle frames as before (until we can purify weapon functions), fixes...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle / raptor.qc
1 #ifndef VEHICLE_RAPTOR
2 #define VEHICLE_RAPTOR
3 #include "raptor.qh"
4
5 #include "raptor_weapons.qh"
6
7 CLASS(Raptor, Vehicle)
8 /* spawnflags */ ATTRIB(Raptor, spawnflags, int, VHF_DMGSHAKE | VHF_DMGROLL);
9 /* mins       */ ATTRIB(Raptor, mins, vector, '-80 -80 0');
10 /* maxs       */ ATTRIB(Raptor, maxs, vector, '80 80 70');
11 /* view offset*/ ATTRIB(Raptor, view_ofs, vector, '0 0 160');
12 /* view dist  */ ATTRIB(Raptor, height, float, 200);
13 /* model          */ ATTRIB(Raptor, mdl, string, "models/vehicles/raptor.dpm");
14 /* model          */ ATTRIB(Raptor, model, string, "models/vehicles/raptor.dpm");
15 /* head_model */ ATTRIB(Raptor, head_model, string, "");
16 /* hud_model  */ ATTRIB(Raptor, hud_model, string, "models/vehicles/raptor_cockpit.dpm");
17 /* tags       */ ATTRIB(Raptor, tag_head, string, "");
18 /* tags       */ ATTRIB(Raptor, tag_hud, string, "tag_hud");
19 /* tags       */ ATTRIB(Raptor, tag_view, string, "tag_camera");
20 /* netname    */ ATTRIB(Raptor, netname, string, "raptor");
21 /* fullname   */ ATTRIB(Raptor, vehicle_name, string, _("Raptor"));
22 /* icon       */ ATTRIB(Raptor, m_icon, string, "vehicle_raptor");
23 ENDCLASS(Raptor)
24 REGISTER_VEHICLE(RAPTOR, NEW(Raptor));
25
26 #endif
27
28 #ifdef IMPLEMENTATION
29
30 #ifdef SVQC
31
32 bool autocvar_g_vehicle_raptor = true;
33
34 float autocvar_g_vehicle_raptor_respawntime = 40;
35 float autocvar_g_vehicle_raptor_takeofftime = 1.5;
36
37 // 0: go where player aims, +forward etc relative to aim angles
38 // 1: ignore aim for up/down movement. +forward always moved forward, +jump always moves up
39 int autocvar_g_vehicle_raptor_movestyle = 1;
40 float autocvar_g_vehicle_raptor_turnspeed = 200;
41 float autocvar_g_vehicle_raptor_pitchspeed = 50;
42 float autocvar_g_vehicle_raptor_pitchlimit = 45;
43
44 float autocvar_g_vehicle_raptor_speed_forward = 1700;
45 float autocvar_g_vehicle_raptor_speed_strafe = 900;
46 float autocvar_g_vehicle_raptor_speed_up = 1700;
47 float autocvar_g_vehicle_raptor_speed_down = 1700;
48 float autocvar_g_vehicle_raptor_friction = 2;
49
50 float autocvar_g_vehicle_raptor_cannon_turnspeed = 120;
51 float autocvar_g_vehicle_raptor_cannon_turnlimit = 20;
52 float autocvar_g_vehicle_raptor_cannon_pitchlimit_up = 12;
53 float autocvar_g_vehicle_raptor_cannon_pitchlimit_down = 32;
54
55 float autocvar_g_vehicle_raptor_cannon_locktarget = 0;
56 float autocvar_g_vehicle_raptor_cannon_locking_time = 0.2;
57 float autocvar_g_vehicle_raptor_cannon_locking_releasetime = 0.45;
58 float autocvar_g_vehicle_raptor_cannon_locked_time = 1;
59 float autocvar_g_vehicle_raptor_cannon_predicttarget = 1;
60
61 float autocvar_g_vehicle_raptor_energy = 100;
62 float autocvar_g_vehicle_raptor_energy_regen = 25;
63 float autocvar_g_vehicle_raptor_energy_regen_pause = 0.25;
64
65 float autocvar_g_vehicle_raptor_health = 150;
66 float autocvar_g_vehicle_raptor_health_regen = 0;
67 float autocvar_g_vehicle_raptor_health_regen_pause = 0;
68
69 float autocvar_g_vehicle_raptor_shield = 75;
70 float autocvar_g_vehicle_raptor_shield_regen = 25;
71 float autocvar_g_vehicle_raptor_shield_regen_pause = 1.5;
72
73 float autocvar_g_vehicle_raptor_bouncefactor = 0.2;
74 float autocvar_g_vehicle_raptor_bouncestop = 0;
75 vector autocvar_g_vehicle_raptor_bouncepain = '1 4 1000';
76
77 .entity bomb1;
78 .entity bomb2;
79
80 float raptor_altitude(float amax)
81 {SELFPARAM();
82         tracebox(self.origin, self.mins, self.maxs, self.origin - ('0 0 1' * amax), MOVE_WORLDONLY, self);
83         return vlen(self.origin - trace_endpos);
84 }
85
86 void raptor_land()
87 {SELFPARAM();
88         float hgt;
89
90         hgt = raptor_altitude(512);
91         self.velocity = (self.velocity * 0.9) + ('0 0 -1800' * (hgt / 256) * sys_frametime);
92         self.angles_x *= 0.95;
93         self.angles_z *= 0.95;
94
95         if(hgt < 128)
96         if(hgt > 0)
97                 self.frame = (hgt / 128) * 25;
98
99         self.bomb1.gun1.avelocity_y = 90 + ((self.frame / 25) * 2000);
100         self.bomb1.gun2.avelocity_y = -self.bomb1.gun1.avelocity_y;
101
102         if(hgt < 16)
103         {
104                 self.movetype = MOVETYPE_TOSS;
105                 self.think      = vehicles_think;
106                 self.frame      = 0;
107         }
108
109         self.nextthink  = time;
110
111         CSQCMODEL_AUTOUPDATE(self);
112 }
113
114 void raptor_exit(float eject)
115 {SELFPARAM();
116         vector spot;
117         self.tur_head.exteriormodeltoclient = world;
118
119         if(!IS_DEAD(self))
120         {
121                 self.think        = raptor_land;
122                 self.nextthink  = time;
123         }
124
125         if(!self.owner)
126                 return;
127
128         makevectors(self.angles);
129         if(eject)
130         {
131                 spot = self.origin + v_forward * 100 + '0 0 64';
132                 spot = vehicles_findgoodexit(spot);
133                 setorigin(self.owner , spot);
134                 self.owner.velocity = (v_up + v_forward * 0.25) * 750;
135                 self.owner.oldvelocity = self.owner.velocity;
136         }
137         else
138         {
139                 if(vdist(self.velocity, >, 2 * autocvar_sv_maxairspeed))
140                 {
141                         self.owner.velocity = normalize(self.velocity) * autocvar_sv_maxairspeed * 2;
142                         self.owner.velocity_z += 200;
143                         spot = self.origin + v_forward * 32 + '0 0 64';
144                         spot = vehicles_findgoodexit(spot);
145                 }
146                 else
147                 {
148                         self.owner.velocity = self.velocity * 0.5;
149                         self.owner.velocity_z += 10;
150                         spot = self.origin - v_forward * 200 + '0 0 64';
151                         spot = vehicles_findgoodexit(spot);
152                 }
153                 self.owner.oldvelocity = self.owner.velocity;
154                 setorigin(self.owner , spot);
155         }
156
157         antilag_clear(self.owner, CS(self.owner));
158         self.owner = world;
159 }
160
161 bool raptor_frame(entity this)
162 {
163         entity vehic = this.vehicle;
164         return = true;
165
166         if(intermission_running)
167         {
168                 vehic.velocity = '0 0 0';
169                 vehic.avelocity = '0 0 0';
170                 return;
171         }
172
173         setself(vehic);
174
175         vehicles_frame(vehic, this);
176
177         float ftmp = 0;
178         /*
179         ftmp = vlen(vehic.velocity);
180         if(ftmp > autocvar_g_vehicle_raptor_speed_forward)
181                 ftmp = 1;
182         else
183                 ftmp = ftmp / autocvar_g_vehicle_raptor_speed_forward;
184         */
185
186         if(vehic.sound_nexttime < time)
187         {
188                 vehic.sound_nexttime = time + 7.955812;
189                 //sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_FLY, 1 - ftmp,   ATTEN_NORM );
190                 sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_SPEED, 1, ATTEN_NORM);
191                 vehic.wait = ftmp;
192         }
193         /*
194         else if(fabs(ftmp - vehic.wait) > 0.2)
195         {
196                 sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_Null, 1 - ftmp,   ATTEN_NORM );
197                 sound (vehic, CH_TRIGGER_SINGLE, SND_Null, ftmp, ATTEN_NORM);
198                 vehic.wait = ftmp;
199         }
200         */
201
202         if(IS_DEAD(vehic))
203         {
204                 PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false;
205                 return;
206         }
207         crosshair_trace(this);
208
209         //if(time - vehic.lastteleporttime < 1)
210         //{
211                 if(vehic.angles_z > 50 || vehic.angles_z < -50)
212                 {
213                         if(PHYS_INPUT_BUTTON_JUMP(this))
214                         {
215                                 PHYS_INPUT_BUTTON_CROUCH(this) = true;
216                                 PHYS_INPUT_BUTTON_JUMP(this) = false;
217                         }
218                 }
219         //}
220
221         vector vang;
222         vang = vehic.angles;
223         vector df = vectoangles(normalize(trace_endpos - vehic.origin + '0 0 32'));
224         vang_x *= -1;
225         df_x *= -1;
226         if(df_x > 180)  df_x -= 360;
227         if(df_x < -180) df_x += 360;
228         if(df_y > 180)  df_y -= 360;
229         if(df_y < -180) df_y += 360;
230
231         ftmp = shortangle_f(this.v_angle_y - vang_y, vang_y);
232         if(ftmp > 180)  ftmp -= 360; if(ftmp < -180) ftmp += 360;
233         vehic.avelocity_y = bound(-autocvar_g_vehicle_raptor_turnspeed, ftmp + vehic.avelocity_y * 0.9, autocvar_g_vehicle_raptor_turnspeed);
234
235         // Pitch
236         ftmp = 0;
237         if(this.movement_x > 0 && vang_x < autocvar_g_vehicle_raptor_pitchlimit) ftmp = 5;
238         else if(this.movement_x < 0 && vang_x > -autocvar_g_vehicle_raptor_pitchlimit) ftmp = -20;
239
240         df_x = bound(-autocvar_g_vehicle_raptor_pitchlimit, df_x , autocvar_g_vehicle_raptor_pitchlimit);
241         ftmp = vang_x - bound(-autocvar_g_vehicle_raptor_pitchlimit, df_x + ftmp, autocvar_g_vehicle_raptor_pitchlimit);
242         vehic.avelocity_x = bound(-autocvar_g_vehicle_raptor_pitchspeed, ftmp + vehic.avelocity_x * 0.9, autocvar_g_vehicle_raptor_pitchspeed);
243
244         vehic.angles_x = anglemods(vehic.angles_x);
245         vehic.angles_y = anglemods(vehic.angles_y);
246         vehic.angles_z = anglemods(vehic.angles_z);
247
248         if(autocvar_g_vehicle_raptor_movestyle == 1)
249                 makevectors('0 1 0' * vehic.angles_y);
250         else
251                 makevectors(this.v_angle);
252
253         df = vehic.velocity * -autocvar_g_vehicle_raptor_friction;
254
255         if(this.movement_x != 0)
256         {
257                 if(this.movement_x > 0)
258                         df += v_forward  * autocvar_g_vehicle_raptor_speed_forward;
259                 else if(this.movement_x < 0)
260                         df -= v_forward  * autocvar_g_vehicle_raptor_speed_forward;
261         }
262
263         if(this.movement_y != 0)
264         {
265                 if(this.movement_y < 0)
266                         df -= v_right * autocvar_g_vehicle_raptor_speed_strafe;
267                 else if(this.movement_y > 0)
268                         df += v_right * autocvar_g_vehicle_raptor_speed_strafe;
269
270                 vehic.angles_z = bound(-30,vehic.angles_z + (this.movement_y / autocvar_g_vehicle_raptor_speed_strafe),30);
271         }
272         else
273         {
274                 vehic.angles_z *= 0.95;
275                 if(vehic.angles_z >= -1 && vehic.angles_z <= -1)
276                         vehic.angles_z = 0;
277         }
278
279         if(PHYS_INPUT_BUTTON_CROUCH(this))
280                 df -=   v_up * autocvar_g_vehicle_raptor_speed_down;
281         else if (PHYS_INPUT_BUTTON_JUMP(this))
282                 df +=  v_up * autocvar_g_vehicle_raptor_speed_up;
283
284         vehic.velocity  += df * frametime;
285         this.velocity = this.movement  = vehic.velocity;
286         setorigin(this, vehic.origin + '0 0 32');
287
288         this.vehicle_weapon2mode = vehic.vehicle_weapon2mode;
289
290         vector vf, ad;
291         // Target lock & predict
292         if(autocvar_g_vehicle_raptor_cannon_locktarget == 2)
293         {
294                 if(vehic.gun1.lock_time < time || IS_DEAD(vehic.gun1.enemy) || STAT(FROZEN, vehic.gun1.enemy))
295                         vehic.gun1.enemy = world;
296
297                 if(trace_ent)
298                 if(trace_ent.movetype)
299                 if(trace_ent.takedamage)
300                 if(!IS_DEAD(trace_ent) && !STAT(FROZEN, trace_ent))
301                 {
302                         if(teamplay)
303                         {
304                                 if(trace_ent.team != this.team)
305                                 {
306                                         vehic.gun1.enemy = trace_ent;
307                                         vehic.gun1.lock_time = time + 5;
308                                 }
309                         }
310                         else
311                         {
312                                 vehic.gun1.enemy = trace_ent;
313                                 vehic.gun1.lock_time = time + 0.5;
314                         }
315                 }
316
317                 if(vehic.gun1.enemy)
318                 {
319                         float distance, impact_time;
320
321                         vf = real_origin(vehic.gun1.enemy);
322                         UpdateAuxiliaryXhair(this, vf, '1 0 0', 1);
323                         vector _vel = vehic.gun1.enemy.velocity;
324                         if(vehic.gun1.enemy.movetype == MOVETYPE_WALK)
325                                 _vel_z *= 0.1;
326
327                         if(autocvar_g_vehicle_raptor_cannon_predicttarget)
328                         {
329                                 ad = vf;
330                                 distance = vlen(ad - this.origin);
331                                 impact_time = distance / autocvar_g_vehicle_raptor_cannon_speed;
332                                 ad = vf + _vel * impact_time;
333                                 trace_endpos = ad;
334                         }
335                         else
336                                 trace_endpos = vf;
337                 }
338         }
339         else if(autocvar_g_vehicle_raptor_cannon_locktarget == 1)
340         {
341
342                 vehicles_locktarget(vehic, (1 / autocvar_g_vehicle_raptor_cannon_locking_time) * frametime,
343                                                          (1 / autocvar_g_vehicle_raptor_cannon_locking_releasetime) * frametime,
344                                                          autocvar_g_vehicle_raptor_cannon_locked_time);
345
346                 if(vehic.lock_target != world)
347                 if(autocvar_g_vehicle_raptor_cannon_predicttarget)
348                 if(vehic.lock_strength == 1)
349                 {
350                         float i, distance, impact_time;
351
352                         vf = real_origin(vehic.lock_target);
353                         ad = vf;
354                         for(i = 0; i < 4; ++i)
355                         {
356                                 distance = vlen(ad - vehic.origin);
357                                 impact_time = distance / autocvar_g_vehicle_raptor_cannon_speed;
358                                 ad = vf + vehic.lock_target.velocity * impact_time;
359                         }
360                         trace_endpos = ad;
361                 }
362
363                 if(vehic.lock_target)
364                 {
365                         if(vehic.lock_strength == 1)
366                                 UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '1 0 0', 1);
367                         else if(vehic.lock_strength > 0.5)
368                                 UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '0 1 0', 1);
369                         else if(vehic.lock_strength < 0.5)
370                                 UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '0 0 1', 1);
371                 }
372         }
373
374
375         vehicle_aimturret(vehic, trace_endpos, vehic.gun1, "fire1",
376                                                   autocvar_g_vehicle_raptor_cannon_pitchlimit_down * -1,  autocvar_g_vehicle_raptor_cannon_pitchlimit_up,
377                                                   autocvar_g_vehicle_raptor_cannon_turnlimit * -1,  autocvar_g_vehicle_raptor_cannon_turnlimit,  autocvar_g_vehicle_raptor_cannon_turnspeed);
378
379         vehicle_aimturret(vehic, trace_endpos, vehic.gun2, "fire1",
380                                                   autocvar_g_vehicle_raptor_cannon_pitchlimit_down * -1,  autocvar_g_vehicle_raptor_cannon_pitchlimit_up,
381                                                   autocvar_g_vehicle_raptor_cannon_turnlimit * -1,  autocvar_g_vehicle_raptor_cannon_turnlimit,  autocvar_g_vehicle_raptor_cannon_turnspeed);
382
383         /*
384         ad = ad * 0.5;
385         v_forward = vf * 0.5;
386         traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, vehic);
387         UpdateAuxiliaryXhair(this, trace_endpos, '0 1 0', 0);
388         */
389
390         Weapon wep1 = WEP_RAPTOR;
391         if(!forbidWeaponUse(this))
392         if(PHYS_INPUT_BUTTON_ATCK(this))
393         if (wep1.wr_checkammo1(wep1))
394         {
395             .entity weaponentity = weaponentities[0];
396                 wep1.wr_think(wep1, vehic, weaponentity, 1);
397         }
398
399         if(vehic.vehicle_flags  & VHF_SHIELDREGEN)
400                 vehicles_regen(vehic, vehic.dmg_time, vehicle_shield, autocvar_g_vehicle_raptor_shield, autocvar_g_vehicle_raptor_shield_regen_pause, autocvar_g_vehicle_raptor_shield_regen, frametime, true);
401
402         if(vehic.vehicle_flags  & VHF_HEALTHREGEN)
403                 vehicles_regen(vehic, vehic.dmg_time, vehicle_health, autocvar_g_vehicle_raptor_health, autocvar_g_vehicle_raptor_health_regen_pause, autocvar_g_vehicle_raptor_health_regen, frametime, false);
404
405         if(vehic.vehicle_flags  & VHF_ENERGYREGEN)
406                 vehicles_regen(vehic, vehic.cnt, vehicle_energy, autocvar_g_vehicle_raptor_energy, autocvar_g_vehicle_raptor_energy_regen_pause, autocvar_g_vehicle_raptor_energy_regen, frametime, false);
407
408         Weapon wep2a = WEP_RAPTOR_BOMB;
409         if(!forbidWeaponUse(this))
410         if(vehic.vehicle_weapon2mode == RSM_BOMB)
411         {
412                 if(time > vehic.lip + autocvar_g_vehicle_raptor_bombs_refire)
413                 if(PHYS_INPUT_BUTTON_ATCK2(this))
414                 {
415                     .entity weaponentity = weaponentities[1];
416                         wep2a.wr_think(wep2a, vehic, weaponentity, 2);
417                         vehic.delay = time + autocvar_g_vehicle_raptor_bombs_refire;
418                         vehic.lip   = time;
419                 }
420         }
421         else
422         {
423                 Weapon wep2b = WEP_RAPTOR_FLARE;
424                 if(time > vehic.lip + autocvar_g_vehicle_raptor_flare_refire)
425                 if(PHYS_INPUT_BUTTON_ATCK2(this))
426                 {
427                     .entity weaponentity = weaponentities[1];
428                         wep2b.wr_think(wep2b, vehic, weaponentity, 2);
429                         vehic.delay = time + autocvar_g_vehicle_raptor_flare_refire;
430                         vehic.lip   = time;
431                 }
432         }
433
434         vehic.bomb1.alpha = vehic.bomb2.alpha = (time - vehic.lip) / (vehic.delay - vehic.lip);
435         this.vehicle_reload2 = bound(0, vehic.bomb1.alpha * 100, 100);
436         this.vehicle_ammo2 = (this.vehicle_reload2 == 100) ? 100 : 0;
437
438         if(vehic.bomb1.cnt < time)
439         {
440                 entity _missile = findchainentity(enemy, vehic);
441                 float _incomming = 0;
442                 while(_missile)
443                 {
444                         if(_missile.flags & FL_PROJECTILE)
445                         if(MISSILE_IS_TRACKING(_missile))
446                         if(vdist(vehic.origin - _missile.origin, <, 2 * autocvar_g_vehicle_raptor_flare_range))
447                                 ++_incomming;
448
449                         _missile = _missile.chain;
450                 }
451
452                 if(_incomming)
453                         sound(vehic, CH_PAIN_SINGLE, SND_VEH_MISSILE_ALARM, VOL_BASE, ATTEN_NONE);
454
455                 vehic.bomb1.cnt = time + 1;
456         }
457
458
459         VEHICLE_UPDATE_PLAYER(this, vehic, health, raptor);
460         VEHICLE_UPDATE_PLAYER(this, vehic, energy, raptor);
461         if(vehic.vehicle_flags & VHF_HASSHIELD)
462                 VEHICLE_UPDATE_PLAYER(this, vehic, shield, raptor);
463
464         PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = PHYS_INPUT_BUTTON_CROUCH(this) = false;
465
466         setself(this);
467 }
468
469 bool raptor_takeoff(entity this)
470 {
471         entity vehic = this.vehicle;
472         return = true;
473
474         setself(this);
475
476         vehic.nextthink = time;
477         CSQCMODEL_AUTOUPDATE(vehic);
478         vehic.nextthink = 0; // will this work?
479
480         if(vehic.sound_nexttime < time)
481         {
482                 vehic.sound_nexttime = time + 7.955812; //soundlength("vehicles/raptor_fly.wav");
483                 sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_SPEED, VOL_VEHICLEENGINE, ATTEN_NORM);
484         }
485
486         // Takeoff sequense
487         if(vehic.frame < 25)
488         {
489                 vehic.frame += 25 / (autocvar_g_vehicle_raptor_takeofftime / sys_frametime);
490                 vehic.velocity_z = min(vehic.velocity_z * 1.5, 256);
491                 vehic.bomb1.gun1.avelocity_y = 90 + ((vehic.frame / 25) * 25000);
492                 vehic.bomb1.gun2.avelocity_y = -vehic.bomb1.gun1.avelocity_y;
493                 PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = PHYS_INPUT_BUTTON_CROUCH(this) = false;
494
495                 setorigin(this, vehic.origin + '0 0 32');
496         }
497         else
498                 this.PlayerPhysplug = raptor_frame;
499
500         if(vehic.vehicle_flags  & VHF_SHIELDREGEN)
501                 vehicles_regen(vehic, vehic.dmg_time, vehicle_shield, autocvar_g_vehicle_raptor_shield, autocvar_g_vehicle_raptor_shield_regen_pause, autocvar_g_vehicle_raptor_shield_regen, frametime, true);
502
503         if(vehic.vehicle_flags  & VHF_HEALTHREGEN)
504                 vehicles_regen(vehic, vehic.dmg_time, vehicle_health, autocvar_g_vehicle_raptor_health, autocvar_g_vehicle_raptor_health_regen_pause, autocvar_g_vehicle_raptor_health_regen, frametime, false);
505
506         if(vehic.vehicle_flags  & VHF_ENERGYREGEN)
507                 vehicles_regen(vehic, vehic.cnt, vehicle_energy, autocvar_g_vehicle_raptor_energy, autocvar_g_vehicle_raptor_energy_regen_pause, autocvar_g_vehicle_raptor_energy_regen, frametime, false);
508
509
510         vehic.bomb1.alpha = vehic.bomb2.alpha = (time - vehic.lip) / (vehic.delay - vehic.lip);
511         this.vehicle_reload2 = bound(0, vehic.bomb1.alpha * 100, 100);
512         this.vehicle_ammo2 = (this.vehicle_reload2 == 100) ? 100 : 0;
513
514         VEHICLE_UPDATE_PLAYER(this, vehic, health, raptor);
515         VEHICLE_UPDATE_PLAYER(this, vehic, energy, raptor);
516         if(vehic.vehicle_flags & VHF_HASSHIELD)
517                 VEHICLE_UPDATE_PLAYER(this, vehic, shield, raptor);
518
519         PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = PHYS_INPUT_BUTTON_CROUCH(this) = false;
520
521         setself(vehic);
522 }
523
524 void raptor_blowup()
525 {SELFPARAM();
526         self.deadflag   = DEAD_DEAD;
527         self.vehicle_exit(VHEF_NORMAL);
528         RadiusDamage (self, self.enemy, 250, 15, 250, world, world, 250, DEATH_VH_RAPT_DEATH.m_id, world);
529
530         self.alpha                = -1;
531         self.movetype      = MOVETYPE_NONE;
532         self.effects            = EF_NODRAW;
533         self.colormod      = '0 0 0';
534         self.avelocity    = '0 0 0';
535         self.velocity      = '0 0 0';
536
537         setorigin(self, self.pos1);
538         self.touch = func_null;
539         self.nextthink = 0;
540 }
541
542 void raptor_diethink()
543 {SELFPARAM();
544         if(time >= self.wait)
545                 self.think = raptor_blowup;
546
547         if(random() < 0.05)
548         {
549                 sound (self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
550                 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
551         }
552         self.nextthink = time;
553
554         CSQCMODEL_AUTOUPDATE(self);
555 }
556
557 // If we dont do this ever now and then, the raptors rotors
558 // stop working, presumably due to angle overflow. cute.
559 void raptor_rotor_anglefix()
560 {SELFPARAM();
561         self.gun1.angles_y = anglemods(self.gun1.angles_y);
562         self.gun2.angles_y = anglemods(self.gun2.angles_y);
563         self.nextthink = time + 15;
564 }
565
566 float raptor_impulse(float _imp)
567 {SELFPARAM();
568         switch(_imp)
569         {
570                 case IMP_weapon_group_1.impulse:
571                         self.vehicle.vehicle_weapon2mode = RSM_BOMB;
572                         CSQCVehicleSetup(self, 0);
573                         return true;
574                 case IMP_weapon_group_2.impulse:
575                         self.vehicle.vehicle_weapon2mode = RSM_FLARE;
576                         CSQCVehicleSetup(self, 0);
577                         return true;
578
579                 case IMP_weapon_next_byid.impulse:
580                 case IMP_weapon_next_bypriority.impulse:
581                 case IMP_weapon_next_bygroup.impulse:
582                         self.vehicle.vehicle_weapon2mode += 1;
583                         if(self.vehicle.vehicle_weapon2mode > RSM_LAST)
584                                 self.vehicle.vehicle_weapon2mode = RSM_FIRST;
585
586                         CSQCVehicleSetup(self, 0);
587                         return true;
588                 case IMP_weapon_last.impulse:
589                 case IMP_weapon_prev_byid.impulse:
590                 case IMP_weapon_prev_bypriority.impulse:
591                 case IMP_weapon_prev_bygroup.impulse:
592                         self.vehicle.vehicle_weapon2mode -= 1;
593                         if(self.vehicle.vehicle_weapon2mode < RSM_FIRST)
594                                 self.vehicle.vehicle_weapon2mode = RSM_LAST;
595
596                         CSQCVehicleSetup(self, 0);
597                         return true;
598
599                 /*
600                 case IMP_weapon_drop.impulse: // toss gun, could be used to exit?
601                         break;
602                 case IMP_weapon_reload.impulse: // Manual minigun reload?
603                         break;
604                 */
605         }
606         return false;
607 }
608
609 spawnfunc(vehicle_raptor)
610 {
611         if(!autocvar_g_vehicle_raptor) { remove(self); return; }
612         if(!vehicle_initialize(VEH_RAPTOR, false)) { remove(self); return; }
613 }
614
615 METHOD(Raptor, vr_impact, void(Raptor thisveh, entity instance))
616 {
617     if(autocvar_g_vehicle_raptor_bouncepain)
618         vehicles_impact(autocvar_g_vehicle_raptor_bouncepain_x, autocvar_g_vehicle_raptor_bouncepain_y, autocvar_g_vehicle_raptor_bouncepain_z);
619 }
620 METHOD(Raptor, vr_enter, void(Raptor thisveh, entity instance))
621 {
622     SELFPARAM();
623     self.vehicle_weapon2mode = RSM_BOMB;
624     self.owner.PlayerPhysplug = raptor_takeoff;
625     self.movetype          = MOVETYPE_BOUNCEMISSILE;
626     self.solid            = SOLID_SLIDEBOX;
627     self.owner.vehicle_health = (self.vehicle_health / autocvar_g_vehicle_raptor_health) * 100;
628     self.owner.vehicle_shield = (self.vehicle_shield / autocvar_g_vehicle_raptor_shield) * 100;
629     self.velocity_z = 1; // Nudge upwards to takeoff sequense can work.
630     self.tur_head.exteriormodeltoclient = self.owner;
631
632     self.delay = time + autocvar_g_vehicle_raptor_bombs_refire;
633     self.lip   = time;
634
635     if(self.owner.flagcarried)
636        setorigin(self.owner.flagcarried, '-20 0 96');
637
638     CSQCVehicleSetup(self.owner, 0);
639 }
640 METHOD(Raptor, vr_death, void(Raptor thisveh, entity instance))
641 {
642     instance.health                             = 0;
643     instance.event_damage               = func_null;
644     instance.solid                              = SOLID_CORPSE;
645     instance.takedamage                 = DAMAGE_NO;
646     instance.deadflag                   = DEAD_DYING;
647     instance.movetype                   = MOVETYPE_BOUNCE;
648     instance.think                              = raptor_diethink;
649     instance.nextthink                  = time;
650     instance.wait                               = time + 5 + (random() * 5);
651
652     Send_Effect(EFFECT_EXPLOSION_MEDIUM, findbetterlocation (instance.origin, 16), '0 0 0', 1);
653
654     instance.velocity_z += 600;
655
656     instance.avelocity = '0 0.5 1' * (random() * 400);
657     instance.avelocity -= '0 0.5 1' * (random() * 400);
658
659     instance.colormod = '-0.5 -0.5 -0.5';
660     instance.touch = raptor_blowup;
661 }
662 METHOD(Raptor, vr_spawn, void(Raptor thisveh, entity instance))
663 {
664     SELFPARAM();
665     if(!self.gun1)
666     {
667         entity spinner;
668         vector ofs;
669
670         //FIXME: Camera is in a bad place in HUD model.
671         //setorigin(self.vehicle_viewport, '25 0 5');
672
673         self.vehicles_impulse   = raptor_impulse;
674
675         self.frame = 0;
676
677         self.bomb1 = new(raptor_bomb);
678         self.bomb2 = new(raptor_bomb);
679         self.gun1  = new(raptor_gun);
680         self.gun2  = new(raptor_gun);
681
682         setmodel(self.bomb1, MDL_VEH_RAPTOR_CB_FOLDED);
683         setmodel(self.bomb2, MDL_VEH_RAPTOR_CB_FOLDED);
684         setmodel(self.gun1, MDL_VEH_RAPTOR_GUN);
685         setmodel(self.gun2, MDL_VEH_RAPTOR_GUN);
686         setmodel(self.tur_head, MDL_VEH_RAPTOR_TAIL);
687
688         setattachment(self.bomb1, self, "bombmount_left");
689         setattachment(self.bomb2, self, "bombmount_right");
690         setattachment(self.tur_head, self,"root");
691
692         // FIXMODEL Guns mounts to angled bones
693         self.bomb1.angles = self.angles;
694         self.angles = '0 0 0';
695         // This messes up gun-aim, so work arround it.
696         //setattachment(self.gun1, self, "gunmount_left");
697         ofs = gettaginfo(self, gettagindex(self, "gunmount_left"));
698         ofs -= self.origin;
699         setattachment(self.gun1, self, "");
700         setorigin(self.gun1, ofs);
701
702         //setattachment(self.gun2, self, "gunmount_right");
703         ofs = gettaginfo(self, gettagindex(self, "gunmount_right"));
704         ofs -= self.origin;
705         setattachment(self.gun2, self, "");
706         setorigin(self.gun2, ofs);
707
708         self.angles = self.bomb1.angles;
709         self.bomb1.angles = '0 0 0';
710
711         spinner = new(raptor_spinner);
712         spinner.owner = self;
713         setmodel(spinner, MDL_VEH_RAPTOR_PROP);
714         setattachment(spinner, self, "engine_left");
715         spinner.movetype = MOVETYPE_NOCLIP;
716         spinner.avelocity = '0 90 0';
717         self.bomb1.gun1 = spinner;
718
719         spinner = new(raptor_spinner);
720         spinner.owner = self;
721         setmodel(spinner, MDL_VEH_RAPTOR_PROP);
722         setattachment(spinner, self, "engine_right");
723         spinner.movetype = MOVETYPE_NOCLIP;
724         spinner.avelocity = '0 -90 0';
725         self.bomb1.gun2 = spinner;
726
727         // Sigh.
728         self.bomb1.think = raptor_rotor_anglefix;
729         self.bomb1.nextthink = time;
730
731         self.mass                          = 1 ;
732     }
733
734     self.frame            = 0;
735     self.vehicle_health = autocvar_g_vehicle_raptor_health;
736     self.vehicle_shield = autocvar_g_vehicle_raptor_shield;
737     self.movetype          = MOVETYPE_TOSS;
738     self.solid            = SOLID_SLIDEBOX;
739     self.vehicle_energy = 1;
740
741     self.PlayerPhysplug = raptor_frame;
742
743     self.bomb1.gun1.avelocity_y = 90;
744     self.bomb1.gun2.avelocity_y = -90;
745
746     self.delay = time;
747
748     self.bouncefactor = autocvar_g_vehicle_raptor_bouncefactor;
749     self.bouncestop = autocvar_g_vehicle_raptor_bouncestop;
750     self.damageforcescale = 0.25;
751     self.vehicle_health = autocvar_g_vehicle_raptor_health;
752     self.vehicle_shield = autocvar_g_vehicle_raptor_shield;
753 }
754 METHOD(Raptor, vr_setup, void(Raptor thisveh, entity instance))
755 {
756     SELFPARAM();
757     if(autocvar_g_vehicle_raptor_shield)
758         self.vehicle_flags |= VHF_HASSHIELD;
759
760     if(autocvar_g_vehicle_raptor_shield_regen)
761         self.vehicle_flags |= VHF_SHIELDREGEN;
762
763     if(autocvar_g_vehicle_raptor_health_regen)
764         self.vehicle_flags |= VHF_HEALTHREGEN;
765
766     if(autocvar_g_vehicle_raptor_energy_regen)
767         self.vehicle_flags |= VHF_ENERGYREGEN;
768
769     self.vehicle_exit = raptor_exit;
770     self.respawntime = autocvar_g_vehicle_raptor_respawntime;
771     self.vehicle_health = autocvar_g_vehicle_raptor_health;
772     self.vehicle_shield = autocvar_g_vehicle_raptor_shield;
773     self.max_health = self.vehicle_health;
774 }
775
776 #endif
777 #ifdef CSQC
778
779 METHOD(Raptor, vr_hud, void(Raptor thisveh))
780 {
781     Vehicles_drawHUD(VEH_RAPTOR.m_icon, "vehicle_raptor_weapon1", "vehicle_raptor_weapon2",
782                      "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
783                      "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
784 }
785 METHOD(Raptor, vr_crosshair, void(Raptor thisveh))
786 {
787     SELFPARAM();
788     string crosshair;
789
790     switch(weapon2mode)
791     {
792         case RSM_FLARE: crosshair = vCROSS_RAIN;  break;
793         case RSM_BOMB:  crosshair = vCROSS_BURST; break;
794         default:        crosshair = vCROSS_BURST;
795     }
796
797     vector tmpSize = '0 0 0';
798     if(weapon2mode != RSM_FLARE)
799     {
800         vector where;
801
802         if(!dropmark)
803         {
804             dropmark = spawn();
805             dropmark.owner = self;
806             dropmark.gravity = 1;
807         }
808
809         float reload2 = STAT(VEHICLESTAT_RELOAD2) * 0.01;
810         if(reload2 == 1)
811         {
812             setorigin(dropmark, pmove_org);
813             dropmark.velocity = pmove_vel;
814             tracetoss(dropmark, self);
815
816             where = project_3d_to_2d(trace_endpos);
817
818             setorigin(dropmark, trace_endpos);
819             tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size;
820
821             if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight))
822             {
823                 where.x -= tmpSize.x * 0.5;
824                 where.y -= tmpSize.y * 0.5;
825                 where.z = 0;
826                 drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE);
827                 drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg
828             }
829             dropmark.cnt = time + 5;
830         }
831         else
832         {
833             if(dropmark.cnt > time)
834             {
835                 where = project_3d_to_2d(dropmark.origin);
836                 tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size * 1.25;
837
838                 if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight))
839                 {
840                     where.x -= tmpSize.x * 0.5;
841                     where.y -= tmpSize.y * 0.5;
842                     where.z = 0;
843                     drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE);
844                     drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg
845                 }
846             }
847         }
848     }
849
850     Vehicles_drawCrosshair(crosshair);
851 }
852 METHOD(Raptor, vr_setup, void(Raptor thisveh, entity instance))
853 {
854     AuxiliaryXhair[1].axh_image = vCROSS_LOCK;
855 }
856
857 #endif
858 #endif