]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/vehicle/bumblebee.qc
Notifications: relocate
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle / bumblebee.qc
1 #ifndef VEHICLE_BUMBLEBEE
2 #define VEHICLE_BUMBLEBEE
3 #include "bumblebee.qh"
4
5 #include "bumblebee_weapons.qc"
6
7 CLASS(Bumblebee, Vehicle)
8 /* spawnflags */ ATTRIB(Bumblebee, spawnflags, int, VHF_DMGSHAKE);
9 /* mins       */ ATTRIB(Bumblebee, mins, vector, '-245 -130 -130');
10 /* maxs       */ ATTRIB(Bumblebee, maxs, vector, '230 130 130');
11 /* view offset*/ ATTRIB(Bumblebee, view_ofs, vector, '0 0 300');
12 /* view dist  */ ATTRIB(Bumblebee, height, float, 450);
13 /* model          */ ATTRIB(Bumblebee, mdl, string, "models/vehicles/bumblebee_body.dpm");
14 /* model          */ ATTRIB(Bumblebee, model, string, "models/vehicles/bumblebee_body.dpm");
15 /* head_model */ ATTRIB(Bumblebee, head_model, string, "");
16 /* hud_model  */ ATTRIB(Bumblebee, hud_model, string, "models/vehicles/spiderbot_cockpit.dpm");
17 /* tags       */ ATTRIB(Bumblebee, tag_head, string, "");
18 /* tags       */ ATTRIB(Bumblebee, tag_hud, string, "");
19 /* tags       */ ATTRIB(Bumblebee, tag_view, string, "tag_viewport");
20 /* netname    */ ATTRIB(Bumblebee, netname, string, "bumblebee");
21 /* fullname   */ ATTRIB(Bumblebee, vehicle_name, string, _("Bumblebee"));
22 /* icon       */ ATTRIB(Bumblebee, m_icon, string, "vehicle_bumble");
23 ENDCLASS(Bumblebee)
24 REGISTER_VEHICLE(BUMBLEBEE, NEW(Bumblebee));
25
26 #endif
27
28 #ifdef IMPLEMENTATION
29
30 const float BRG_SETUP = 2;
31 const float BRG_START = 4;
32 const float BRG_END = 8;
33
34 #include "bumblebee_weapons.qc"
35
36 #ifdef SVQC
37 float autocvar_g_vehicle_bumblebee_speed_forward;
38 float autocvar_g_vehicle_bumblebee_speed_strafe;
39 float autocvar_g_vehicle_bumblebee_speed_up;
40 float autocvar_g_vehicle_bumblebee_speed_down;
41 float autocvar_g_vehicle_bumblebee_turnspeed;
42 float autocvar_g_vehicle_bumblebee_pitchspeed;
43 float autocvar_g_vehicle_bumblebee_pitchlimit;
44 float autocvar_g_vehicle_bumblebee_friction;
45
46 float autocvar_g_vehicle_bumblebee_energy;
47 float autocvar_g_vehicle_bumblebee_energy_regen;
48 float autocvar_g_vehicle_bumblebee_energy_regen_pause;
49
50 float autocvar_g_vehicle_bumblebee_health;
51 float autocvar_g_vehicle_bumblebee_health_regen;
52 float autocvar_g_vehicle_bumblebee_health_regen_pause;
53
54 float autocvar_g_vehicle_bumblebee_shield;
55 float autocvar_g_vehicle_bumblebee_shield_regen;
56 float autocvar_g_vehicle_bumblebee_shield_regen_pause;
57
58 float autocvar_g_vehicle_bumblebee_cannon_ammo;
59 float autocvar_g_vehicle_bumblebee_cannon_ammo_regen;
60 float autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause;
61
62 float autocvar_g_vehicle_bumblebee_cannon_lock = 0;
63
64 float autocvar_g_vehicle_bumblebee_cannon_turnspeed;
65 float autocvar_g_vehicle_bumblebee_cannon_pitchlimit_down;
66 float autocvar_g_vehicle_bumblebee_cannon_pitchlimit_up;
67 float autocvar_g_vehicle_bumblebee_cannon_turnlimit_in;
68 float autocvar_g_vehicle_bumblebee_cannon_turnlimit_out;
69
70
71 float autocvar_g_vehicle_bumblebee_raygun_turnspeed;
72 float autocvar_g_vehicle_bumblebee_raygun_pitchlimit_down;
73 float autocvar_g_vehicle_bumblebee_raygun_pitchlimit_up;
74 float autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides;
75
76 float autocvar_g_vehicle_bumblebee_raygun_range;
77 float autocvar_g_vehicle_bumblebee_raygun_dps;
78 float autocvar_g_vehicle_bumblebee_raygun_aps;
79 float autocvar_g_vehicle_bumblebee_raygun_fps;
80
81 float autocvar_g_vehicle_bumblebee_raygun;
82 float autocvar_g_vehicle_bumblebee_healgun_hps;
83 float autocvar_g_vehicle_bumblebee_healgun_hmax;
84 float autocvar_g_vehicle_bumblebee_healgun_aps;
85 float autocvar_g_vehicle_bumblebee_healgun_amax;
86 float autocvar_g_vehicle_bumblebee_healgun_sps;
87 float autocvar_g_vehicle_bumblebee_healgun_locktime;
88
89 float autocvar_g_vehicle_bumblebee_respawntime;
90
91 float autocvar_g_vehicle_bumblebee_blowup_radius;
92 float autocvar_g_vehicle_bumblebee_blowup_coredamage;
93 float autocvar_g_vehicle_bumblebee_blowup_edgedamage;
94 float autocvar_g_vehicle_bumblebee_blowup_forceintensity;
95 vector autocvar_g_vehicle_bumblebee_bouncepain;
96
97 bool autocvar_g_vehicle_bumblebee = 0;
98
99 float bumblebee_gunner_frame()
100 {SELFPARAM();
101         entity vehic    = self.vehicle.owner;
102         entity gun      = self.vehicle;
103         entity gunner   = self;
104         setself(vehic);
105
106         // this isn't technically a vehicle (yet), let's not do frame functions on it (yet)
107         //vehicles_frame(gun, player);
108
109         vehic.solid = SOLID_NOT;
110         //setorigin(gunner, vehic.origin);
111         gunner.velocity = vehic.velocity;
112
113         float _in, _out;
114         vehic.angles_x *= -1;
115         makevectors(vehic.angles);
116         vehic.angles_x *= -1;
117         if(gun == vehic.gun1)
118         {
119                 _in = autocvar_g_vehicle_bumblebee_cannon_turnlimit_in;
120                 _out = autocvar_g_vehicle_bumblebee_cannon_turnlimit_out;
121                 setorigin(gunner, vehic.origin + v_up * -16 + v_forward * -16 + v_right * 128);
122         }
123         else
124         {
125                 _in = autocvar_g_vehicle_bumblebee_cannon_turnlimit_out;
126                 _out = autocvar_g_vehicle_bumblebee_cannon_turnlimit_in;
127                 setorigin(gunner, vehic.origin + v_up * -16 + v_forward * -16 + v_right * -128);
128         }
129
130         crosshair_trace(gunner);
131         vector _ct = trace_endpos;
132         vector ad;
133
134         if(autocvar_g_vehicle_bumblebee_cannon_lock)
135         {
136                 if(gun.lock_time < time)
137                         gun.enemy = world;
138
139                 if(trace_ent)
140                         if(trace_ent.movetype)
141                                 if(trace_ent.takedamage)
142                                         if(!IS_DEAD(trace_ent) && !STAT(FROZEN, trace_ent))
143                                         {
144                                                 if(DIFF_TEAM(trace_ent, gunner))
145                                                 {
146                                                         gun.enemy = trace_ent;
147                                                         gun.lock_time = time + 5;
148                                                 }
149                                         }
150         }
151
152         if(gun.enemy)
153         {
154                 float distance, impact_time;
155
156                 vector vf = real_origin(gun.enemy);
157                 vector _vel = gun.enemy.velocity;
158                 if(gun.enemy.movetype == MOVETYPE_WALK)
159                         _vel.z *= 0.1;
160
161
162                 ad = vf;
163                 distance = vlen(ad - gunner.origin);
164                 impact_time = distance / autocvar_g_vehicle_bumblebee_cannon_speed;
165                 ad = vf + _vel * impact_time;
166                 trace_endpos = ad;
167
168
169                 UpdateAuxiliaryXhair(gunner, ad, '1 0 1', 1);
170                 vehicle_aimturret(vehic, trace_endpos, gun, "fire",
171                                                   autocvar_g_vehicle_bumblebee_cannon_pitchlimit_down * -1, autocvar_g_vehicle_bumblebee_cannon_pitchlimit_up,
172                                                   _out * -1,  _in,  autocvar_g_vehicle_bumblebee_cannon_turnspeed);
173
174         }
175         else
176                 vehicle_aimturret(vehic, _ct, gun, "fire",
177                                                   autocvar_g_vehicle_bumblebee_cannon_pitchlimit_down * -1, autocvar_g_vehicle_bumblebee_cannon_pitchlimit_up,
178                                                   _out * -1,  _in,  autocvar_g_vehicle_bumblebee_cannon_turnspeed);
179
180         if(!forbidWeaponUse(gunner))
181         if(gunner.BUTTON_ATCK)
182                 if(time > gun.attack_finished_single[0])
183                         if(gun.vehicle_energy >= autocvar_g_vehicle_bumblebee_cannon_cost)
184                         {
185                                 gun.vehicle_energy -= autocvar_g_vehicle_bumblebee_cannon_cost;
186                                 bumblebee_fire_cannon(gun, "fire", gunner);
187                                 gun.delay = time;
188                                 gun.attack_finished_single[0] = time + autocvar_g_vehicle_bumblebee_cannon_refire;
189                         }
190
191         VEHICLE_UPDATE_PLAYER(gunner, health, bumblebee);
192
193         if(vehic.vehicle_flags & VHF_HASSHIELD)
194                 VEHICLE_UPDATE_PLAYER(gunner, shield, bumblebee);
195
196         ad = gettaginfo(gun, gettagindex(gun, "fire"));
197         traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, gun);
198
199         UpdateAuxiliaryXhair(gunner, trace_endpos, ('1 0 0' * gunner.vehicle_reload1) + ('0 1 0' *(1 - gunner.vehicle_reload1)), 0);
200
201         if(vehic.owner)
202                 UpdateAuxiliaryXhair(vehic.owner, trace_endpos, ('1 0 0' * gunner.vehicle_reload1) + ('0 1 0' *(1 - gunner.vehicle_reload1)), ((gunner == vehic.gunner1) ? 1 : 2));
203
204         vehic.solid = SOLID_BBOX;
205         gunner.BUTTON_ATCK = gunner.BUTTON_ATCK2 = gunner.BUTTON_CROUCH = 0;
206         gunner.vehicle_energy = (gun.vehicle_energy / autocvar_g_vehicle_bumblebee_cannon_ammo) * 100;
207
208         setself(gunner);
209         return 1;
210 }
211
212 vector bumblebee_gunner_findgoodexit(vector prefer_spot, entity gunner, entity player)
213 {
214         //vector exitspot;
215         float mysize;
216
217         tracebox(gunner.origin + '0 0 32', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), prefer_spot, MOVE_NORMAL, player);
218         if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
219                 return prefer_spot;
220
221         mysize = 1.5 * vlen(STAT(PL_MAX, NULL) - STAT(PL_MIN, NULL)); // can't use gunner's size, as they don't have a size
222         float i;
223         vector v, v2;
224         v2 = 0.5 * (gunner.absmin + gunner.absmax);
225         for(i = 0; i < 100; ++i)
226         {
227                 v = randomvec();
228                 v_z = 0;
229                 v = v2 + normalize(v) * mysize;
230                 tracebox(v2, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, MOVE_NORMAL, player);
231                 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
232                         return v;
233         }
234
235         return prefer_spot; // this should be considered a fallback?!
236 }
237
238 void bumblebee_gunner_exit(int _exitflag)
239 {SELFPARAM();
240         entity player = self;
241         entity gunner = player.vehicle;
242         entity vehic = gunner.owner;
243
244         if(IS_REAL_CLIENT(player))
245         {
246                 msg_entity = player;
247                 WriteByte(MSG_ONE, SVC_SETVIEWPORT);
248                 WriteEntity(MSG_ONE, player);
249
250                 WriteByte(MSG_ONE, SVC_SETVIEWANGLES);
251                 WriteAngle(MSG_ONE, 0);
252                 WriteAngle(MSG_ONE, vehic.angles.y);
253                 WriteAngle(MSG_ONE, 0);
254         }
255
256         CSQCVehicleSetup(player, HUD_NORMAL);
257         setsize(player, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
258
259         player.takedamage     = DAMAGE_AIM;
260         player.solid          = SOLID_SLIDEBOX;
261         player.movetype       = MOVETYPE_WALK;
262         player.effects       &= ~EF_NODRAW;
263         player.alpha          = 1;
264         player.PlayerPhysplug = func_null;
265         player.view_ofs       = STAT(PL_VIEW_OFS, NULL);
266         player.event_damage   = PlayerDamage;
267         player.hud            = HUD_NORMAL;
268         player.teleportable       = TELEPORT_NORMAL;
269         PS(player).m_switchweapon = gunner.m_switchweapon;
270         player.vehicle_enter_delay = time + 2;
271
272         fixedmakevectors(vehic.angles);
273
274         if(player == vehic.gunner1) { vehic.gunner1 = world; }
275         if(player == vehic.gunner2) { vehic.gunner2 = world; v_right *= -1; }
276
277         vector spot = real_origin(gunner);
278         spot = spot + v_up * 128 + v_forward * 300 + v_right * 150;
279         spot = bumblebee_gunner_findgoodexit(spot, gunner, player);
280
281         // TODO: figure a way to move player out of the gunner
282
283         player.velocity = 0.75 * vehic.velocity + normalize(spot - vehic.origin) * 200;
284         player.velocity_z += 10;
285
286         gunner.phase = time + 5;
287         gunner.vehicle_hudmodel.viewmodelforclient = gunner;
288
289         MUTATOR_CALLHOOK(VehicleExit, player, gunner);
290
291         player.vehicle = world;
292 }
293
294 bool bumblebee_gunner_enter()
295 {SELFPARAM();
296         entity vehic = self;
297         entity player = other;
298         entity gunner = world;
299
300         if(!vehic.gunner1 && !vehic.gunner2 && ((time >= vehic.gun1.phase) + (time >= vehic.gun2.phase)) == 2)
301         {
302                 // we can have some fun
303                 if(vlen2(real_origin(vehic.gun2) - player.origin) < vlen2(real_origin(vehic.gun1) - player.origin))
304                 {
305                         gunner = vehic.gun2;
306                         vehic.gunner2 = player;
307                 }
308                 else
309                 {
310                         gunner = vehic.gun1;
311                         vehic.gunner1 = player;
312                 }
313         }
314         else if(!vehic.gunner1 && time >= vehic.gun1.phase)     { gunner = vehic.gun1; vehic.gunner1 = player; }
315         else if(!vehic.gunner2 && time >= vehic.gun2.phase)             { gunner = vehic.gun2; vehic.gunner2 = player; }
316         else { LOG_TRACE("Vehicle is full, fail\n"); return false; }
317
318         player.vehicle                  = gunner;
319         player.angles                   = vehic.angles;
320         player.takedamage               = DAMAGE_NO;
321         player.solid                    = SOLID_NOT;
322         player.alpha                    = -1;
323         player.movetype                 = MOVETYPE_NOCLIP;
324         player.event_damage     = func_null;
325         player.view_ofs                 = '0 0 0';
326         player.hud                              = gunner.hud;
327         player.teleportable     = false;
328         player.PlayerPhysplug   = gunner.PlayerPhysplug;
329         player.vehicle_ammo1    = vehic.vehicle_ammo1;
330         player.vehicle_ammo2    = vehic.vehicle_ammo2;
331         player.vehicle_reload1  = vehic.vehicle_reload1;
332         player.vehicle_reload2  = vehic.vehicle_reload2;
333         player.vehicle_energy   = vehic.vehicle_energy;
334         player.flags               &= ~FL_ONGROUND;
335
336         RemoveGrapplingHook(player);
337
338         gunner.m_switchweapon = PS(player).m_switchweapon;
339         gunner.vehicle_exit = bumblebee_gunner_exit;
340         gunner.vehicle_hudmodel.viewmodelforclient = player;
341
342         if(IS_REAL_CLIENT(player))
343         {
344                 msg_entity = player;
345                 WriteByte(MSG_ONE,              SVC_SETVIEWPORT);
346                 WriteEntity(MSG_ONE,    gunner.vehicle_viewport);
347
348                 WriteByte(MSG_ONE,              SVC_SETVIEWANGLES);
349                 WriteAngle(MSG_ONE,     gunner.angles_x + vehic.angles_x); // tilt
350                 WriteAngle(MSG_ONE,     gunner.angles_y + vehic.angles_y); // yaw
351                 WriteAngle(MSG_ONE,     0); // roll
352         }
353
354         CSQCVehicleSetup(player, player.hud);
355
356         MUTATOR_CALLHOOK(VehicleEnter, player, gunner);
357
358         return true;
359 }
360
361 bool vehicles_valid_pilot()
362 {SELFPARAM();
363         if(IS_BOT_CLIENT(other) && !autocvar_g_vehicles_allow_bots)
364                 return false;
365
366         if((!IS_PLAYER(other))
367         || (IS_DEAD(other))
368         || (other.vehicle)
369         || (DIFF_TEAM(other, self))
370         ) { return false; }
371
372         return true;
373 }
374
375 void bumblebee_touch()
376 {SELFPARAM();
377         if(autocvar_g_vehicles_enter) { return; }
378
379         if(self.gunner1 != world && self.gunner2 != world)
380         {
381                 vehicles_touch();
382                 return;
383         }
384
385         if(vehicles_valid_pilot())
386         {
387                 float phase_time = (time >= self.gun1.phase) + (time >= self.gun2.phase);
388
389                 if(time >= other.vehicle_enter_delay && phase_time)
390                 if(bumblebee_gunner_enter())
391                         return;
392         }
393
394         vehicles_touch();
395 }
396
397 void bumblebee_regen()
398 {SELFPARAM();
399         if(self.gun1.delay + autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause < time)
400                 self.gun1.vehicle_energy = min(autocvar_g_vehicle_bumblebee_cannon_ammo,
401                                                                            self.gun1.vehicle_energy + autocvar_g_vehicle_bumblebee_cannon_ammo_regen * frametime);
402
403         if(self.gun2.delay + autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause < time)
404                 self.gun2.vehicle_energy = min(autocvar_g_vehicle_bumblebee_cannon_ammo,
405                                                                            self.gun2.vehicle_energy + autocvar_g_vehicle_bumblebee_cannon_ammo_regen * frametime);
406
407         if(self.vehicle_flags  & VHF_SHIELDREGEN)
408                 vehicles_regen(self.dmg_time, vehicle_shield, autocvar_g_vehicle_bumblebee_shield, autocvar_g_vehicle_bumblebee_shield_regen_pause, autocvar_g_vehicle_bumblebee_shield_regen, frametime, true);
409
410         if(self.vehicle_flags  & VHF_HEALTHREGEN)
411                 vehicles_regen(self.dmg_time, vehicle_health, autocvar_g_vehicle_bumblebee_health, autocvar_g_vehicle_bumblebee_health_regen_pause, autocvar_g_vehicle_bumblebee_health_regen, frametime, false);
412
413         if(self.vehicle_flags  & VHF_ENERGYREGEN)
414                 vehicles_regen(self.wait, vehicle_energy, autocvar_g_vehicle_bumblebee_energy, autocvar_g_vehicle_bumblebee_energy_regen_pause, autocvar_g_vehicle_bumblebee_energy_regen, frametime, false);
415
416 }
417
418 float bumblebee_pilot_frame()
419 {SELFPARAM();
420         entity pilot, vehic;
421         vector newvel;
422
423         if(intermission_running)
424         {
425                 self.vehicle.velocity = '0 0 0';
426                 self.vehicle.avelocity = '0 0 0';
427                 return 1;
428         }
429
430         pilot = self;
431         vehic = self.vehicle;
432         setself(vehic);
433
434         vehicles_frame(vehic, pilot);
435
436         if(IS_DEAD(vehic))
437         {
438                 setself(pilot);
439                 pilot.BUTTON_ATCK = pilot.BUTTON_ATCK2 = 0;
440                 return 1;
441         }
442
443         bumblebee_regen();
444
445         crosshair_trace(pilot);
446
447         vector vang;
448         float ftmp;
449
450         vang = vehic.angles;
451         newvel = vectoangles(normalize(trace_endpos - self.origin + '0 0 32'));
452         vang.x *= -1;
453         newvel.x *= -1;
454         if(newvel.x > 180)  newvel.x -= 360;
455         if(newvel.x < -180) newvel.x += 360;
456         if(newvel.y > 180)  newvel.y -= 360;
457         if(newvel.y < -180) newvel.y += 360;
458
459         ftmp = shortangle_f(pilot.v_angle.y - vang.y, vang.y);
460         if(ftmp > 180)  ftmp -= 360;
461         if(ftmp < -180) ftmp += 360;
462         vehic.avelocity_y = bound(-autocvar_g_vehicle_bumblebee_turnspeed, ftmp + vehic.avelocity.y * 0.9, autocvar_g_vehicle_bumblebee_turnspeed);
463
464         // Pitch
465         ftmp = 0;
466         if(pilot.movement.x > 0 && vang.x < autocvar_g_vehicle_bumblebee_pitchlimit)
467                 ftmp = 4;
468         else if(pilot.movement.x < 0 && vang.x > -autocvar_g_vehicle_bumblebee_pitchlimit)
469                 ftmp = -8;
470
471         newvel.x = bound(-autocvar_g_vehicle_bumblebee_pitchlimit, newvel.x , autocvar_g_vehicle_bumblebee_pitchlimit);
472         ftmp = vang.x - bound(-autocvar_g_vehicle_bumblebee_pitchlimit, newvel.x + ftmp, autocvar_g_vehicle_bumblebee_pitchlimit);
473         vehic.avelocity_x = bound(-autocvar_g_vehicle_bumblebee_pitchspeed, ftmp + vehic.avelocity.x * 0.9, autocvar_g_vehicle_bumblebee_pitchspeed);
474
475         vehic.angles_x = anglemods(vehic.angles.x);
476         vehic.angles_y = anglemods(vehic.angles.y);
477         vehic.angles_z = anglemods(vehic.angles.z);
478
479         makevectors('0 1 0' * vehic.angles.y);
480         newvel = vehic.velocity * -autocvar_g_vehicle_bumblebee_friction;
481
482         if(pilot.movement.x != 0)
483         {
484                 if(pilot.movement.x > 0)
485                         newvel += v_forward  * autocvar_g_vehicle_bumblebee_speed_forward;
486                 else if(pilot.movement.x < 0)
487                         newvel -= v_forward  * autocvar_g_vehicle_bumblebee_speed_forward;
488         }
489
490         if(pilot.movement.y != 0)
491         {
492                 if(pilot.movement.y < 0)
493                         newvel -= v_right * autocvar_g_vehicle_bumblebee_speed_strafe;
494                 else if(pilot.movement.y > 0)
495                         newvel += v_right * autocvar_g_vehicle_bumblebee_speed_strafe;
496                 ftmp = newvel * v_right;
497                 ftmp *= frametime * 0.1;
498                 vehic.angles_z = bound(-15, vehic.angles.z + ftmp, 15);
499         }
500         else
501         {
502                 vehic.angles_z *= 0.95;
503                 if(vehic.angles.z >= -1 && vehic.angles.z <= -1)
504                         vehic.angles_z = 0;
505         }
506
507         if(pilot.BUTTON_CROUCH)
508                 newvel -=   v_up * autocvar_g_vehicle_bumblebee_speed_down;
509         else if(pilot.BUTTON_JUMP)
510                 newvel +=  v_up * autocvar_g_vehicle_bumblebee_speed_up;
511
512         vehic.velocity  += newvel * frametime;
513         pilot.velocity = pilot.movement  = vehic.velocity;
514
515
516         if(autocvar_g_vehicle_bumblebee_healgun_locktime)
517         {
518                 if(vehic.tur_head.lock_time < time || IS_DEAD(vehic.tur_head.enemy) || STAT(FROZEN, vehic.tur_head.enemy))
519                         vehic.tur_head.enemy = world;
520
521                 if(trace_ent)
522                 if(trace_ent.movetype)
523                 if(trace_ent.takedamage)
524                 if(!IS_DEAD(trace_ent) && !STAT(FROZEN, trace_ent))
525                 {
526                         if(teamplay)
527                         {
528                                 if(trace_ent.team == pilot.team)
529                                 {
530                                         vehic.tur_head.enemy = trace_ent;
531                                         vehic.tur_head.lock_time = time + autocvar_g_vehicle_bumblebee_healgun_locktime;
532                                 }
533                         }
534                         else
535                         {
536                                 vehic.tur_head.enemy = trace_ent;
537                                 vehic.tur_head.lock_time = time + autocvar_g_vehicle_bumblebee_healgun_locktime;
538                         }
539                 }
540
541                 if(vehic.tur_head.enemy)
542                 {
543                         trace_endpos = real_origin(vehic.tur_head.enemy);
544                         UpdateAuxiliaryXhair(pilot, trace_endpos, '0 0.75 0', 0);
545                 }
546         }
547
548         vang = vehicle_aimturret(vehic, trace_endpos, self.gun3, "fire",
549                                           autocvar_g_vehicle_bumblebee_raygun_pitchlimit_down * -1,  autocvar_g_vehicle_bumblebee_raygun_pitchlimit_up,
550                                           autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides * -1,  autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides,  autocvar_g_vehicle_bumblebee_raygun_turnspeed);
551
552         if(!forbidWeaponUse(pilot))
553         if((pilot.BUTTON_ATCK || pilot.BUTTON_ATCK2) && (vehic.vehicle_energy > autocvar_g_vehicle_bumblebee_raygun_dps * sys_frametime || autocvar_g_vehicle_bumblebee_raygun == 0))
554         {
555                 vehic.gun3.enemy.realowner = pilot;
556                 vehic.gun3.enemy.effects &= ~EF_NODRAW;
557
558                 vehic.gun3.enemy.hook_start = gettaginfo(vehic.gun3, gettagindex(vehic.gun3, "fire"));
559                 vehic.gun3.enemy.SendFlags |= BRG_START;
560
561                 traceline(vehic.gun3.enemy.hook_start, vehic.gun3.enemy.hook_start + v_forward * autocvar_g_vehicle_bumblebee_raygun_range, MOVE_NORMAL, vehic);
562
563                 if(trace_ent)
564                 {
565                         if(autocvar_g_vehicle_bumblebee_raygun)
566                         {
567                                 Damage(trace_ent, vehic, pilot, autocvar_g_vehicle_bumblebee_raygun_dps * sys_frametime, DEATH_GENERIC.m_id, trace_endpos, v_forward * autocvar_g_vehicle_bumblebee_raygun_fps * sys_frametime);
568                                 vehic.vehicle_energy -= autocvar_g_vehicle_bumblebee_raygun_aps * sys_frametime;
569                         }
570                         else
571                         {
572                                 if(!IS_DEAD(trace_ent))
573                                         if((teamplay && trace_ent.team == pilot.team) || !teamplay)
574                                         {
575
576                                                 if(trace_ent.vehicle_flags & VHF_ISVEHICLE)
577                                                 {
578                                                         if(autocvar_g_vehicle_bumblebee_healgun_sps && trace_ent.vehicle_health <= trace_ent.max_health)
579                                                                 trace_ent.vehicle_shield = min(trace_ent.vehicle_shield + autocvar_g_vehicle_bumblebee_healgun_sps * frametime, trace_ent.tur_head.max_health);
580
581                                                         if(autocvar_g_vehicle_bumblebee_healgun_hps)
582                                                                 trace_ent.vehicle_health = min(trace_ent.vehicle_health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, trace_ent.max_health);
583                                                 }
584                                                 else if(IS_CLIENT(trace_ent))
585                                                 {
586                                                         if(trace_ent.health <= autocvar_g_vehicle_bumblebee_healgun_hmax && autocvar_g_vehicle_bumblebee_healgun_hps)
587                                                                 trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, autocvar_g_vehicle_bumblebee_healgun_hmax);
588
589                                                         if(trace_ent.armorvalue <= autocvar_g_vehicle_bumblebee_healgun_amax && autocvar_g_vehicle_bumblebee_healgun_aps)
590                                                                 trace_ent.armorvalue = min(trace_ent.armorvalue + autocvar_g_vehicle_bumblebee_healgun_aps * frametime, autocvar_g_vehicle_bumblebee_healgun_amax);
591
592                                                         trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, autocvar_g_vehicle_bumblebee_healgun_hmax);
593                                                 }
594                                                 else if(IS_TURRET(trace_ent))
595                                                 {
596                                                         if(trace_ent.health  <= trace_ent.max_health && autocvar_g_vehicle_bumblebee_healgun_hps)
597                                                                 trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, trace_ent.max_health);
598                                                         //else ..hmmm what? ammo?
599
600                                                         trace_ent.SendFlags |= TNSF_STATUS;
601                                                 }
602                                         }
603                         }
604                 }
605
606                 vehic.gun3.enemy.hook_end = trace_endpos;
607                 setorigin(vehic.gun3.enemy, trace_endpos);
608                 vehic.gun3.enemy.SendFlags |= BRG_END;
609
610                 vehic.wait = time + 1;
611         }
612         else
613                 vehic.gun3.enemy.effects |= EF_NODRAW;
614         /*{
615                 if(vehic.gun3.enemy)
616                         remove(vehic.gun3.enemy);
617
618                 vehic.gun3.enemy = world;
619         }
620         */
621
622         VEHICLE_UPDATE_PLAYER(pilot, health, bumblebee);
623         VEHICLE_UPDATE_PLAYER(pilot, energy, bumblebee);
624
625         pilot.vehicle_ammo1 = (vehic.gun1.vehicle_energy / autocvar_g_vehicle_bumblebee_cannon_ammo) * 100;
626         pilot.vehicle_ammo2 = (vehic.gun2.vehicle_energy / autocvar_g_vehicle_bumblebee_cannon_ammo) * 100;
627
628         if(vehic.vehicle_flags & VHF_HASSHIELD)
629                 VEHICLE_UPDATE_PLAYER(pilot, shield, bumblebee);
630
631         vehic.angles_x *= -1;
632         makevectors(vehic.angles);
633         vehic.angles_x *= -1;
634         setorigin(pilot, vehic.origin + v_up * 48 + v_forward * 160);
635
636         pilot.BUTTON_ATCK = pilot.BUTTON_ATCK2 = pilot.BUTTON_CROUCH = 0;
637         setself(pilot);
638
639         return 1;
640 }
641
642 void bumblebee_land()
643 {SELFPARAM();
644         float hgt;
645
646         hgt = raptor_altitude(512);
647         self.velocity = (self.velocity * 0.9) + ('0 0 -1800' * (hgt / 256) * sys_frametime);
648         self.angles_x *= 0.95;
649         self.angles_z *= 0.95;
650
651         if(hgt < 16)
652                 self.think      = vehicles_think;
653
654         self.nextthink = time;
655
656         CSQCMODEL_AUTOUPDATE(self);
657 }
658
659 void bumblebee_exit(float eject)
660 {SELFPARAM();
661         if(self.owner.vehicleid == VEH_BUMBLEBEE.vehicleid)
662         {
663                 bumblebee_gunner_exit(eject);
664                 return;
665         }
666
667         self.touch = vehicles_touch;
668
669         if(!IS_DEAD(self))
670         {
671                 self.think = bumblebee_land;
672                 self.nextthink  = time;
673         }
674
675         self.movetype = MOVETYPE_TOSS;
676
677         if(!self.owner)
678                 return;
679
680         fixedmakevectors(self.angles);
681         vector spot;
682         if(vdist(self.velocity, >, autocvar_g_vehicle_bumblebee_speed_forward * 0.5))
683                 spot = self.origin + v_up * 128 + v_forward * 300;
684         else
685                 spot = self.origin + v_up * 128 - v_forward * 300;
686
687         spot = vehicles_findgoodexit(spot);
688
689         // Hide beam
690         if(self.gun3.enemy || !wasfreed(self.gun3.enemy)) {
691                 self.gun3.enemy.effects |= EF_NODRAW;
692         }
693
694         self.owner.velocity = 0.75 * self.vehicle.velocity + normalize(spot - self.vehicle.origin) * 200;
695         self.owner.velocity_z += 10;
696         setorigin(self.owner, spot);
697
698         antilag_clear(self.owner);
699         self.owner = world;
700 }
701
702 void bumblebee_blowup()
703 {SELFPARAM();
704         RadiusDamage(self, self.enemy, autocvar_g_vehicle_bumblebee_blowup_coredamage,
705                                  autocvar_g_vehicle_bumblebee_blowup_edgedamage,
706                                  autocvar_g_vehicle_bumblebee_blowup_radius, self, world,
707                                  autocvar_g_vehicle_bumblebee_blowup_forceintensity,
708                                  DEATH_VH_BUMB_DEATH.m_id, world);
709
710         sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
711         Send_Effect(EFFECT_EXPLOSION_BIG, (self.origin + '0 0 100') + (randomvec() * 80), '0 0 0', 1);
712
713         if(self.owner.deadflag == DEAD_DYING)
714                 self.owner.deadflag = DEAD_DEAD;
715
716         remove(self);
717 }
718
719 void bumblebee_diethink()
720 {SELFPARAM();
721         if(time >= self.wait)
722                 self.think = bumblebee_blowup;
723
724         if(random() < 0.1)
725         {
726                 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
727                 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
728         }
729
730         self.nextthink = time + 0.1;
731 }
732
733 spawnfunc(vehicle_bumblebee)
734 {
735         if(!autocvar_g_vehicle_bumblebee) { remove(self); return; }
736         if(!vehicle_initialize(VEH_BUMBLEBEE, false)) { remove(self); return; }
737 }
738
739                 METHOD(Bumblebee, vr_impact, void(Bumblebee thisveh, entity instance))
740                 {
741                         if(autocvar_g_vehicle_bumblebee_bouncepain)
742                                 vehicles_impact(autocvar_g_vehicle_bumblebee_bouncepain_x, autocvar_g_vehicle_bumblebee_bouncepain_y, autocvar_g_vehicle_bumblebee_bouncepain_z);
743                 }
744                 METHOD(Bumblebee, vr_enter, void(Bumblebee thisveh, entity instance))
745                 {
746                         SELFPARAM();
747                         self.touch = bumblebee_touch;
748                         self.nextthink = 0;
749                         self.movetype = MOVETYPE_BOUNCEMISSILE;
750                 }
751                 METHOD(Bumblebee, vr_think, void(Bumblebee thisveh, entity instance))
752                 {
753                         SELFPARAM();
754                         self.angles_z *= 0.8;
755                         self.angles_x *= 0.8;
756
757                         self.nextthink = time;
758
759                         if(!self.owner)
760                         {
761                                 entity oldself = self;
762                                 if(self.gunner1)
763                                 {
764                                         setself(self.gunner1);
765                                         oldself.gun1.vehicle_exit(VHEF_EJECT);
766                                         entity oldother = other;
767                                         other = self;
768                                         setself(oldself);
769                                         self.phase = 0;
770                                         self.touch();
771                                         other = oldother;
772                                         return;
773                                 }
774
775                                 if(self.gunner2)
776                                 {
777                                         setself(self.gunner2);
778                                         oldself.gun2.vehicle_exit(VHEF_EJECT);
779                                         entity oldother = other;
780                                         other = self;
781                                         setself(oldself);
782                                         self.phase = 0;
783                                         self.touch();
784                                         other = oldother;
785                                         return;
786                                 }
787                         }
788                 }
789                 METHOD(Bumblebee, vr_death, void(Bumblebee thisveh, entity instance))
790                 {
791                         entity oldself = self;
792                         setself(instance);
793
794                         CSQCModel_UnlinkEntity(self);
795
796                         // Hide beam
797                         if(self.gun3.enemy || !wasfreed(self.gun3.enemy))
798                                 self.gun3.enemy.effects |= EF_NODRAW;
799
800                         if(self.gunner1)
801                         {
802                                 setself(self.gunner1);
803                                 oldself.gun1.vehicle_exit(VHEF_EJECT);
804                                 setself(oldself);
805                         }
806
807                         if(self.gunner2)
808                         {
809                                 setself(self.gunner2);
810                                 oldself.gun2.vehicle_exit(VHEF_EJECT);
811                                 setself(oldself);
812                         }
813
814                         self.vehicle_exit(VHEF_EJECT);
815
816                         fixedmakevectors(self.angles);
817                         vehicle_tossgib(self.gun1, self.velocity + v_right * 300 + v_up * 100 + randomvec() * 200, "cannon_right", rint(random()), rint(random()), 6, randomvec() * 200);
818                         vehicle_tossgib(self.gun2, self.velocity + v_right * -300 + v_up * 100 + randomvec() * 200, "cannon_left", rint(random()), rint(random()), 6, randomvec() * 200);
819                         vehicle_tossgib(self.gun3, self.velocity + v_forward * 300 + v_up * -100 + randomvec() * 200, "raygun", rint(random()), rint(random()), 6, randomvec() * 300);
820
821                         entity _body = vehicle_tossgib(self, self.velocity + randomvec() * 200, "", rint(random()), rint(random()), 6, randomvec() * 100);
822
823                         if(random() > 0.5)
824                                 _body.touch = bumblebee_blowup;
825                         else
826                                 _body.touch = func_null;
827
828                         _body.think = bumblebee_diethink;
829                         _body.nextthink = time;
830                         _body.wait = time + 2 + (random() * 8);
831                         _body.owner = self;
832                         _body.enemy = self.enemy;
833                         _body.scale = 1.5;
834                         _body.angles = self.angles;
835
836                         Send_Effect(EFFECT_EXPLOSION_MEDIUM, findbetterlocation(self.origin, 16), '0 0 0', 1);
837
838                         self.health                     = 0;
839                         self.event_damage       = func_null;
840                         self.solid                      = SOLID_NOT;
841                         self.takedamage         = DAMAGE_NO;
842                         self.deadflag           = DEAD_DYING;
843                         self.movetype           = MOVETYPE_NONE;
844                         self.effects            = EF_NODRAW;
845                         self.colormod           = '0 0 0';
846                         self.avelocity          = '0 0 0';
847                         self.velocity           = '0 0 0';
848                         self.touch                      = func_null;
849                         self.nextthink          = 0;
850
851                         setorigin(self, self.pos1);
852
853                         setself(oldself);
854                 }
855                 METHOD(Bumblebee, vr_spawn, void(Bumblebee thisveh, entity instance))
856                 {
857                         SELFPARAM();
858                         if(!self.gun1)
859                         {
860                                 // for some reason, autosizing of the shield entity refuses to work for this one so set it up in advance.
861                                 self.vehicle_shieldent = spawn();
862                                 self.vehicle_shieldent.effects = EF_LOWPRECISION;
863                                 setmodel(self.vehicle_shieldent, MDL_VEH_BUMBLEBEE_SHIELD);
864                                 setattachment(self.vehicle_shieldent, self, "");
865                                 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
866                                 self.vehicle_shieldent.scale       = 512 / vlen(self.maxs - self.mins);
867                                 self.vehicle_shieldent.think       = shieldhit_think;
868                                 self.vehicle_shieldent.alpha = -1;
869                                 self.vehicle_shieldent.effects = EF_LOWPRECISION | EF_NODRAW;
870
871                                 self.gun1 = new(vehicle_playerslot);
872                                 self.gun2 = new(vehicle_playerslot);
873                                 self.gun3 = new(bumblebee_raygun);
874
875                                 self.vehicle_flags |= VHF_MULTISLOT;
876
877                                 self.gun1.owner = self;
878                                 self.gun2.owner = self;
879                                 self.gun3.owner = self;
880
881                                 setmodel(self.gun1, MDL_VEH_BUMBLEBEE_CANNON_RIGHT);
882                                 setmodel(self.gun2, MDL_VEH_BUMBLEBEE_CANNON_LEFT);
883                                 setmodel(self.gun3, MDL_VEH_BUMBLEBEE_CANNON_CENTER);
884
885                                 setattachment(self.gun1, self, "cannon_right");
886                                 setattachment(self.gun2, self, "cannon_left");
887
888                                 // Angled bones are no fun, messes up gun-aim; so work arround it.
889                                 self.gun3.pos1 = self.angles;
890                                 self.angles = '0 0 0';
891                                 vector ofs = gettaginfo(self, gettagindex(self, "raygun"));
892                                 ofs -= self.origin;
893                                 setattachment(self.gun3, self, "");
894                                 setorigin(self.gun3, ofs);
895                                 self.angles = self.gun3.pos1;
896
897                                 vehicle_addplayerslot(self, self.gun1, HUD_BUMBLEBEE_GUN, "models/vehicles/wakizashi_cockpit.dpm", bumblebee_gunner_frame, bumblebee_gunner_exit, bumblebee_gunner_enter);
898                                 vehicle_addplayerslot(self, self.gun2, HUD_BUMBLEBEE_GUN, "models/vehicles/wakizashi_cockpit.dpm", bumblebee_gunner_frame, bumblebee_gunner_exit, bumblebee_gunner_enter);
899
900                                 setorigin(self.vehicle_hudmodel, '50 0 -5');    // Move cockpit forward - down.
901                                 setorigin(self.vehicle_viewport, '5 0 2');    // Move camera forward up
902
903                                 //fixme-model-bones
904                                 setorigin(self.gun1.vehicle_hudmodel, '90 -27 -23');
905                                 setorigin(self.gun1.vehicle_viewport, '-85 0 50');
906                                 //fixme-model-bones
907                                 setorigin(self.gun2.vehicle_hudmodel, '90 27 -23');
908                                 setorigin(self.gun2.vehicle_viewport, '-85 0 50');
909
910                                 self.scale = 1.5;
911
912                                 // Raygun beam
913                                 if(self.gun3.enemy == world)
914                                 {
915                                         self.gun3.enemy = spawn();
916                                         Net_LinkEntity(self.gun3.enemy, true, 0, bumble_raygun_send);
917                                         self.gun3.enemy.SendFlags = BRG_SETUP;
918                                         self.gun3.enemy.cnt = autocvar_g_vehicle_bumblebee_raygun;
919                                         self.gun3.enemy.effects = EF_NODRAW | EF_LOWPRECISION;
920                                 }
921                         }
922
923                         self.vehicle_health = autocvar_g_vehicle_bumblebee_health;
924                         self.vehicle_shield = autocvar_g_vehicle_bumblebee_shield;
925                         self.solid = SOLID_BBOX;
926                         self.movetype = MOVETYPE_TOSS;
927                         self.damageforcescale = 0.025;
928
929                         self.PlayerPhysplug = bumblebee_pilot_frame;
930
931                         setorigin(self, self.origin + '0 0 25');
932                 }
933                 METHOD(Bumblebee, vr_setup, void(Bumblebee thisveh, entity instance))
934                 {
935                         SELFPARAM();
936                         if(autocvar_g_vehicle_bumblebee_energy)
937                         if(autocvar_g_vehicle_bumblebee_energy_regen)
938                                 self.vehicle_flags |= VHF_ENERGYREGEN;
939
940                         if(autocvar_g_vehicle_bumblebee_shield)
941                                 self.vehicle_flags |= VHF_HASSHIELD;
942
943                         if(autocvar_g_vehicle_bumblebee_shield_regen)
944                                 self.vehicle_flags |= VHF_SHIELDREGEN;
945
946                         if(autocvar_g_vehicle_bumblebee_health_regen)
947                                 self.vehicle_flags |= VHF_HEALTHREGEN;
948
949                         self.vehicle_exit = bumblebee_exit;
950                         self.respawntime = autocvar_g_vehicle_bumblebee_respawntime;
951                         self.vehicle_health = autocvar_g_vehicle_bumblebee_health;
952                         self.max_health = self.vehicle_health;
953                         self.vehicle_shield = autocvar_g_vehicle_bumblebee_shield;
954                 }
955
956 #endif // SVQC
957 #ifdef CSQC
958
959 void CSQC_BUMBLE_GUN_HUD()
960 {
961         Vehicles_drawHUD("vehicle_gunner", "vehicle_gunner_weapon1", string_null,
962                                          "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
963                                          string_null, '0 0 0');
964 }
965
966                 METHOD(Bumblebee, vr_hud, void(Bumblebee thisveh))
967                 {
968                         Vehicles_drawHUD(VEH_BUMBLEBEE.m_icon, "vehicle_bumble_weapon1", "vehicle_bumble_weapon2",
969                                                          "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
970                                                          "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color);
971
972                         float hudAlpha = autocvar_hud_panel_fg_alpha;
973                         float blinkValue = 0.55 + sin(time * 7) * 0.45;
974                         vector tmpPos  = '0 0 0';
975                         vector tmpSize = '1 1 1' * hud_fontsize;
976                         tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (520/768);
977
978                         if(!AuxiliaryXhair[1].draw2d)
979                         {
980                                 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (96/256) - tmpSize.y;
981                                 drawstring(tmpPos, _("No right gunner!"), tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
982                         }
983
984                         if(!AuxiliaryXhair[2].draw2d)
985                         {
986                                 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (160/256);
987                                 drawstring(tmpPos, _("No left gunner!"), tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
988                         }
989                 }
990                 METHOD(Bumblebee, vr_crosshair, void(Bumblebee thisveh))
991                 {
992                         Vehicles_drawCrosshair(vCROSS_HEAL);
993                 }
994                 METHOD(Bumblebee, vr_setup, void(Bumblebee thisveh, entity instance))
995                 {
996                         AuxiliaryXhair[0].axh_image = vCROSS_LOCK;  // Raygun-locked
997                         AuxiliaryXhair[1].axh_image = vCROSS_BURST; // Gunner1
998                         AuxiliaryXhair[2].axh_image = vCROSS_BURST; // Gunner2
999                 }
1000
1001 #endif
1002 #endif