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