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