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