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