]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/vehicle/raptor.qc
Merge branch 'Mario/teams_bitflag' into 'master'
[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) * sys_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)
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 * frametime;
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) * frametime,
335                                                          (1 / autocvar_g_vehicle_raptor_cannon_locking_releasetime) * frametime,
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, frametime, 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, frametime, 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, frametime, 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                 FOREACH_ENTITY_ENT(enemy, vehic,
434                 {
435                         if(it.flags & FL_PROJECTILE)
436                         if(MISSILE_IS_TRACKING(it))
437                         if(vdist(vehic.origin - it.origin, <, 2 * autocvar_g_vehicle_raptor_flare_range))
438                         {
439                                 incoming = true;
440                                 break;
441                         }
442                 });
443
444                 if(incoming)
445                 {
446                         msg_entity = this;
447                         soundto(MSG_ONE, vehic, CH_PAIN_SINGLE, SND(VEH_MISSILE_ALARM), VOL_BASE, ATTEN_NONE);
448                 }
449
450                 vehic.bomb1.cnt = time + 1;
451         }
452
453
454         VEHICLE_UPDATE_PLAYER(this, vehic, health, raptor);
455         VEHICLE_UPDATE_PLAYER(this, vehic, energy, raptor);
456         if(vehic.vehicle_flags & VHF_HASSHIELD)
457                 VEHICLE_UPDATE_PLAYER(this, vehic, shield, raptor);
458
459         PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = PHYS_INPUT_BUTTON_CROUCH(this) = false;
460 }
461
462 bool raptor_takeoff(entity this)
463 {
464         entity vehic = this.vehicle;
465         return = true;
466
467         vehic.nextthink = time;
468         CSQCMODEL_AUTOUPDATE(vehic);
469         vehic.nextthink = 0; // will this work?
470
471         if(vehic.sound_nexttime < time)
472         {
473                 vehic.sound_nexttime = time + 7.955812; //soundlength("vehicles/raptor_fly.wav");
474                 sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_SPEED, VOL_VEHICLEENGINE, ATTEN_NORM);
475         }
476
477         // Takeoff sequense
478         if(vehic.frame < 25)
479         {
480                 vehic.frame += 25 / (autocvar_g_vehicle_raptor_takeofftime / sys_frametime);
481                 vehic.velocity_z = min(vehic.velocity_z * 1.5, 256);
482                 vehic.bomb1.gun1.avelocity_y = 90 + ((vehic.frame / 25) * 25000);
483                 vehic.bomb1.gun2.avelocity_y = -vehic.bomb1.gun1.avelocity_y;
484                 PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = PHYS_INPUT_BUTTON_CROUCH(this) = false;
485
486                 setorigin(this, vehic.origin + '0 0 32');
487         }
488         else
489                 this.PlayerPhysplug = raptor_frame;
490
491         if(vehic.vehicle_flags  & VHF_SHIELDREGEN)
492                 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);
493
494         if(vehic.vehicle_flags  & VHF_HEALTHREGEN)
495                 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);
496
497         if(vehic.vehicle_flags  & VHF_ENERGYREGEN)
498                 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);
499
500
501         vehic.bomb1.alpha = vehic.bomb2.alpha = (time - vehic.lip) / (vehic.delay - vehic.lip);
502         this.vehicle_reload2 = bound(0, vehic.bomb1.alpha * 100, 100);
503         this.vehicle_ammo2 = (this.vehicle_reload2 == 100) ? 100 : 0;
504
505         VEHICLE_UPDATE_PLAYER(this, vehic, health, raptor);
506         VEHICLE_UPDATE_PLAYER(this, vehic, energy, raptor);
507         if(vehic.vehicle_flags & VHF_HASSHIELD)
508                 VEHICLE_UPDATE_PLAYER(this, vehic, shield, raptor);
509
510         PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = PHYS_INPUT_BUTTON_CROUCH(this) = false;
511 }
512
513 void raptor_blowup(entity this, entity toucher)
514 {
515         this.deadflag   = DEAD_DEAD;
516         this.vehicle_exit(this, VHEF_NORMAL);
517         RadiusDamage (this, this.enemy, 250, 15, 250, NULL, NULL, 250, DEATH_VH_RAPT_DEATH.m_id, NULL);
518
519         this.alpha                = -1;
520         set_movetype(this, MOVETYPE_NONE);
521         this.effects            = EF_NODRAW;
522         this.colormod      = '0 0 0';
523         this.avelocity    = '0 0 0';
524         this.velocity      = '0 0 0';
525
526         setorigin(this, this.pos1);
527         settouch(this, func_null);
528         this.nextthink = 0;
529 }
530
531 void raptor_diethink(entity this)
532 {
533         if(time >= this.wait)
534         {
535                 raptor_blowup(this, NULL);
536                 return;
537         }
538
539         if(random() < 0.05)
540         {
541                 sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
542                 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (this.origin + '0 0 100'), '0 0 0', 1);
543         }
544         this.nextthink = time;
545
546         CSQCMODEL_AUTOUPDATE(this);
547 }
548
549 // If we dont do this ever now and then, the raptors rotors
550 // stop working, presumably due to angle overflow. cute.
551 void raptor_rotor_anglefix(entity this)
552 {
553         this.gun1.angles_y = anglemods(this.gun1.angles_y);
554         this.gun2.angles_y = anglemods(this.gun2.angles_y);
555         this.nextthink = time + 15;
556 }
557
558 bool raptor_impulse(entity this, int _imp)
559 {
560         switch(_imp)
561         {
562                 case IMP_weapon_group_1.impulse:
563                         this.vehicle.vehicle_weapon2mode = RSM_BOMB;
564                         CSQCVehicleSetup(this, 0);
565                         return true;
566                 case IMP_weapon_group_2.impulse:
567                         this.vehicle.vehicle_weapon2mode = RSM_FLARE;
568                         CSQCVehicleSetup(this, 0);
569                         return true;
570
571                 case IMP_weapon_next_byid.impulse:
572                 case IMP_weapon_next_bypriority.impulse:
573                 case IMP_weapon_next_bygroup.impulse:
574                         this.vehicle.vehicle_weapon2mode += 1;
575                         if(this.vehicle.vehicle_weapon2mode > RSM_LAST)
576                                 this.vehicle.vehicle_weapon2mode = RSM_FIRST;
577
578                         CSQCVehicleSetup(this, 0);
579                         return true;
580                 case IMP_weapon_last.impulse:
581                 case IMP_weapon_prev_byid.impulse:
582                 case IMP_weapon_prev_bypriority.impulse:
583                 case IMP_weapon_prev_bygroup.impulse:
584                         this.vehicle.vehicle_weapon2mode -= 1;
585                         if(this.vehicle.vehicle_weapon2mode < RSM_FIRST)
586                                 this.vehicle.vehicle_weapon2mode = RSM_LAST;
587
588                         CSQCVehicleSetup(this, 0);
589                         return true;
590
591                 /*
592                 case IMP_weapon_drop.impulse: // toss gun, could be used to exit?
593                         break;
594                 case IMP_weapon_reload.impulse: // Manual minigun reload?
595                         break;
596                 */
597         }
598         return false;
599 }
600
601 spawnfunc(vehicle_raptor)
602 {
603         if(!autocvar_g_vehicle_raptor) { remove(this); return; }
604         if(!vehicle_initialize(this, VEH_RAPTOR, false)) { remove(this); return; }
605 }
606
607 METHOD(Raptor, vr_impact, void(Raptor thisveh, entity instance))
608 {
609     if(autocvar_g_vehicle_raptor_bouncepain)
610         vehicles_impact(instance, autocvar_g_vehicle_raptor_bouncepain_x, autocvar_g_vehicle_raptor_bouncepain_y, autocvar_g_vehicle_raptor_bouncepain_z);
611 }
612 METHOD(Raptor, vr_enter, void(Raptor thisveh, entity instance))
613 {
614     instance.vehicle_weapon2mode = RSM_BOMB;
615     instance.owner.PlayerPhysplug = raptor_takeoff;
616     set_movetype(instance, MOVETYPE_BOUNCEMISSILE);
617     instance.solid                = SOLID_SLIDEBOX;
618     instance.owner.vehicle_health = (instance.vehicle_health / autocvar_g_vehicle_raptor_health) * 100;
619     instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_raptor_shield) * 100;
620     instance.velocity = '0 0 1'; // nudge upwards so takeoff sequence can work
621     instance.tur_head.exteriormodeltoclient = instance.owner;
622
623     instance.delay = time + autocvar_g_vehicle_raptor_bombs_refire;
624     instance.lip   = time;
625
626     if(instance.owner.flagcarried)
627        setorigin(instance.owner.flagcarried, '-20 0 96');
628
629     CSQCVehicleSetup(instance.owner, 0);
630 }
631 METHOD(Raptor, vr_death, void(Raptor thisveh, entity instance))
632 {
633     instance.health                             = 0;
634     instance.event_damage               = func_null;
635     instance.solid                              = SOLID_CORPSE;
636     instance.takedamage                 = DAMAGE_NO;
637     instance.deadflag                   = DEAD_DYING;
638     set_movetype(instance, MOVETYPE_BOUNCE);
639     setthink(instance, raptor_diethink);
640     instance.nextthink                  = time;
641     instance.wait                               = time + 5 + (random() * 5);
642
643     Send_Effect(EFFECT_EXPLOSION_MEDIUM, findbetterlocation (instance.origin, 16), '0 0 0', 1);
644
645     instance.velocity_z += 600;
646
647     instance.avelocity = '0 0.5 1' * (random() * 400);
648     instance.avelocity -= '0 0.5 1' * (random() * 400);
649
650     instance.colormod = '-0.5 -0.5 -0.5';
651     settouch(instance, raptor_blowup);
652 }
653 METHOD(Raptor, vr_spawn, void(Raptor thisveh, entity instance))
654 {
655     if(!instance.gun1)
656     {
657         entity spinner;
658         vector ofs;
659
660         //FIXME: Camera is in a bad place in HUD model.
661         //setorigin(instance.vehicle_viewport, '25 0 5');
662
663         instance.vehicles_impulse = raptor_impulse;
664
665         instance.frame = 0;
666
667         instance.bomb1 = new(raptor_bomb);
668         instance.bomb2 = new(raptor_bomb);
669         instance.gun1  = new(raptor_gun);
670         instance.gun2  = new(raptor_gun);
671
672         setmodel(instance.bomb1, MDL_VEH_RAPTOR_CB_FOLDED);
673         setmodel(instance.bomb2, MDL_VEH_RAPTOR_CB_FOLDED);
674         setmodel(instance.gun1, MDL_VEH_RAPTOR_GUN);
675         setmodel(instance.gun2, MDL_VEH_RAPTOR_GUN);
676         setmodel(instance.tur_head, MDL_VEH_RAPTOR_TAIL);
677
678         setattachment(instance.bomb1, instance, "bombmount_left");
679         setattachment(instance.bomb2, instance, "bombmount_right");
680         setattachment(instance.tur_head, instance,"root");
681
682         // FIXMODEL Guns mounts to angled bones
683         instance.bomb1.angles = instance.angles;
684         instance.angles = '0 0 0';
685         // This messes up gun-aim, so work arround it.
686         //setattachment(instance.gun1, instance, "gunmount_left");
687         ofs = gettaginfo(instance, gettagindex(instance, "gunmount_left"));
688         ofs -= instance.origin;
689         setattachment(instance.gun1, instance, "");
690         setorigin(instance.gun1, ofs);
691
692         //setattachment(instance.gun2, instance, "gunmount_right");
693         ofs = gettaginfo(instance, gettagindex(instance, "gunmount_right"));
694         ofs -= instance.origin;
695         setattachment(instance.gun2, instance, "");
696         setorigin(instance.gun2, ofs);
697
698         instance.angles = instance.bomb1.angles;
699         instance.bomb1.angles = '0 0 0';
700
701         spinner = new(raptor_spinner);
702         spinner.owner = instance;
703         setmodel(spinner, MDL_VEH_RAPTOR_PROP);
704         setattachment(spinner, instance, "engine_left");
705         set_movetype(spinner, MOVETYPE_NOCLIP);
706         spinner.avelocity = '0 90 0';
707         instance.bomb1.gun1 = spinner;
708
709         spinner = new(raptor_spinner);
710         spinner.owner = instance;
711         setmodel(spinner, MDL_VEH_RAPTOR_PROP);
712         setattachment(spinner, instance, "engine_right");
713         set_movetype(spinner, MOVETYPE_NOCLIP);
714         spinner.avelocity = '0 -90 0';
715         instance.bomb1.gun2 = spinner;
716
717         // Sigh.
718         setthink(instance.bomb1, raptor_rotor_anglefix);
719         instance.bomb1.nextthink = time;
720
721         instance.mass                      = 1 ;
722     }
723
724     instance.frame                = 0;
725     instance.vehicle_health = autocvar_g_vehicle_raptor_health;
726     instance.vehicle_shield = autocvar_g_vehicle_raptor_shield;
727     set_movetype(instance, MOVETYPE_TOSS);
728     instance.solid                = SOLID_SLIDEBOX;
729     instance.vehicle_energy = 1;
730
731     if(!autocvar_g_vehicle_raptor_swim)
732         instance.dphitcontentsmask |= DPCONTENTS_LIQUIDSMASK;
733
734     instance.PlayerPhysplug = raptor_frame;
735
736     instance.bomb1.gun1.avelocity_y = 90;
737     instance.bomb1.gun2.avelocity_y = -90;
738
739     instance.delay = time;
740
741     instance.bouncefactor = autocvar_g_vehicle_raptor_bouncefactor;
742     instance.bouncestop = autocvar_g_vehicle_raptor_bouncestop;
743     instance.damageforcescale = 0.25;
744     instance.vehicle_health = autocvar_g_vehicle_raptor_health;
745     instance.vehicle_shield = autocvar_g_vehicle_raptor_shield;
746 }
747 METHOD(Raptor, vr_setup, void(Raptor thisveh, entity instance))
748 {
749     if(autocvar_g_vehicle_raptor_shield)
750         instance.vehicle_flags |= VHF_HASSHIELD;
751
752     if(autocvar_g_vehicle_raptor_shield_regen)
753         instance.vehicle_flags |= VHF_SHIELDREGEN;
754
755     if(autocvar_g_vehicle_raptor_health_regen)
756         instance.vehicle_flags |= VHF_HEALTHREGEN;
757
758     if(autocvar_g_vehicle_raptor_energy_regen)
759         instance.vehicle_flags |= VHF_ENERGYREGEN;
760
761     instance.vehicle_exit = raptor_exit;
762     instance.respawntime = autocvar_g_vehicle_raptor_respawntime;
763     instance.vehicle_health = autocvar_g_vehicle_raptor_health;
764     instance.vehicle_shield = autocvar_g_vehicle_raptor_shield;
765     instance.max_health = instance.vehicle_health;
766
767     if(!autocvar_g_vehicle_raptor_swim)
768         instance.dphitcontentsmask |= DPCONTENTS_LIQUIDSMASK;
769 }
770
771 #endif
772 #ifdef CSQC
773
774 METHOD(Raptor, vr_hud, void(Raptor thisveh))
775 {
776     Vehicles_drawHUD(VEH_RAPTOR.m_icon, "vehicle_raptor_weapon1", "vehicle_raptor_weapon2",
777                      "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
778                      "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
779 }
780 METHOD(Raptor, vr_crosshair, void(Raptor thisveh, entity player))
781 {
782     string crosshair;
783
784     switch(weapon2mode)
785     {
786         case RSM_FLARE: crosshair = vCROSS_RAIN;  break;
787         case RSM_BOMB:  crosshair = vCROSS_BURST; break;
788         default:        crosshair = vCROSS_BURST;
789     }
790
791     vector tmpSize = '0 0 0';
792     if(weapon2mode != RSM_FLARE && !spectatee_status)
793     {
794         vector where;
795
796         if(!dropmark)
797         {
798             dropmark = spawn();
799             dropmark.owner = player;
800             dropmark.gravity = 1;
801         }
802
803         float reload2 = STAT(VEHICLESTAT_RELOAD2) * 0.01;
804         if(reload2 == 1)
805         {
806             setorigin(dropmark, pmove_org);
807             dropmark.velocity = pmove_vel;
808             tracetoss(dropmark, player);
809
810             where = project_3d_to_2d(trace_endpos);
811
812             setorigin(dropmark, trace_endpos);
813             tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size;
814
815             if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight))
816             {
817                 where.x -= tmpSize.x * 0.5;
818                 where.y -= tmpSize.y * 0.5;
819                 where.z = 0;
820                 drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE);
821                 drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg
822             }
823             dropmark.cnt = time + 5;
824         }
825         else
826         {
827             if(dropmark.cnt > time)
828             {
829                 where = project_3d_to_2d(dropmark.origin);
830                 tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size * 1.25;
831
832                 if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight))
833                 {
834                     where.x -= tmpSize.x * 0.5;
835                     where.y -= tmpSize.y * 0.5;
836                     where.z = 0;
837                     drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE);
838                     drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg
839                 }
840             }
841         }
842     }
843
844     Vehicles_drawCrosshair(crosshair);
845 }
846 METHOD(Raptor, vr_setup, void(Raptor thisveh, entity instance))
847 {
848     AuxiliaryXhair[1].axh_image = vCROSS_LOCK;
849 }
850
851 #endif
852 #endif