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