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