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