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