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