Remove some leftovers from merge
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / unit / bumblebee.qc
1 #ifdef REGISTER_VEHICLE
2 REGISTER_VEHICLE(
3 /* VEH_##id   */ BUMBLEBEE,
4 /* function   */ v_bumblebee,
5 /* spawnflags */ VHF_DMGSHAKE,
6 /* mins,maxs  */ '-245 -130 -130', '230 130 130',
7 /* model          */ "models/vehicles/bumblebee_body.dpm",
8 /* head_model */ "",
9 /* hud_model  */ "models/vehicles/spiderbot_cockpit.dpm",
10 /* tags           */ "", "", "tag_viewport",
11 /* netname        */ "bumblebee",
12 /* fullname   */ _("Bumblebee")
13 );
14 #else
15
16 const float BRG_SETUP = 2;
17 const float BRG_START = 4;
18 const float BRG_END = 8;
19
20 #ifdef SVQC
21 float autocvar_g_vehicle_bumblebee_speed_forward;
22 float autocvar_g_vehicle_bumblebee_speed_strafe;
23 float autocvar_g_vehicle_bumblebee_speed_up;
24 float autocvar_g_vehicle_bumblebee_speed_down;
25 float autocvar_g_vehicle_bumblebee_turnspeed;
26 float autocvar_g_vehicle_bumblebee_pitchspeed;
27 float autocvar_g_vehicle_bumblebee_pitchlimit;
28 float autocvar_g_vehicle_bumblebee_friction;
29
30 float autocvar_g_vehicle_bumblebee_energy;
31 float autocvar_g_vehicle_bumblebee_energy_regen;
32 float autocvar_g_vehicle_bumblebee_energy_regen_pause;
33
34 float autocvar_g_vehicle_bumblebee_health;
35 float autocvar_g_vehicle_bumblebee_health_regen;
36 float autocvar_g_vehicle_bumblebee_health_regen_pause;
37
38 float autocvar_g_vehicle_bumblebee_shield;
39 float autocvar_g_vehicle_bumblebee_shield_regen;
40 float autocvar_g_vehicle_bumblebee_shield_regen_pause;
41
42 float autocvar_g_vehicle_bumblebee_cannon_cost;
43 float autocvar_g_vehicle_bumblebee_cannon_damage;
44 float autocvar_g_vehicle_bumblebee_cannon_radius;
45 float autocvar_g_vehicle_bumblebee_cannon_refire;
46 float autocvar_g_vehicle_bumblebee_cannon_speed;
47 float autocvar_g_vehicle_bumblebee_cannon_spread;
48 float autocvar_g_vehicle_bumblebee_cannon_force;
49
50 float autocvar_g_vehicle_bumblebee_cannon_ammo;
51 float autocvar_g_vehicle_bumblebee_cannon_ammo_regen;
52 float autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause;
53
54 float autocvar_g_vehicle_bumblebee_cannon_lock = 0;
55
56 float autocvar_g_vehicle_bumblebee_cannon_turnspeed;
57 float autocvar_g_vehicle_bumblebee_cannon_pitchlimit_down;
58 float autocvar_g_vehicle_bumblebee_cannon_pitchlimit_up;
59 float autocvar_g_vehicle_bumblebee_cannon_turnlimit_in;
60 float autocvar_g_vehicle_bumblebee_cannon_turnlimit_out;
61
62
63 float autocvar_g_vehicle_bumblebee_raygun_turnspeed;
64 float autocvar_g_vehicle_bumblebee_raygun_pitchlimit_down;
65 float autocvar_g_vehicle_bumblebee_raygun_pitchlimit_up;
66 float autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides;
67
68 float autocvar_g_vehicle_bumblebee_raygun_range;
69 float autocvar_g_vehicle_bumblebee_raygun_dps;
70 float autocvar_g_vehicle_bumblebee_raygun_aps;
71 float autocvar_g_vehicle_bumblebee_raygun_fps;
72
73 float autocvar_g_vehicle_bumblebee_raygun;
74 float autocvar_g_vehicle_bumblebee_healgun_hps;
75 float autocvar_g_vehicle_bumblebee_healgun_hmax;
76 float autocvar_g_vehicle_bumblebee_healgun_aps;
77 float autocvar_g_vehicle_bumblebee_healgun_amax;
78 float autocvar_g_vehicle_bumblebee_healgun_sps;
79 float autocvar_g_vehicle_bumblebee_healgun_locktime;
80
81 float autocvar_g_vehicle_bumblebee_respawntime;
82
83 float autocvar_g_vehicle_bumblebee_blowup_radius;
84 float autocvar_g_vehicle_bumblebee_blowup_coredamage;
85 float autocvar_g_vehicle_bumblebee_blowup_edgedamage;
86 float autocvar_g_vehicle_bumblebee_blowup_forceintensity;
87 vector autocvar_g_vehicle_bumblebee_bouncepain;
88
89 bool autocvar_g_vehicle_bumblebee = 0;
90
91 float bumble_raygun_send(entity to, int sf);
92
93 void bumblebee_fire_cannon(entity _gun, string _tagname, entity _owner)
94 {
95         vector v = gettaginfo(_gun, gettagindex(_gun, _tagname));
96         vehicles_projectile("bigplasma_muzzleflash", "weapons/flacexp3.wav",
97                                                 v, normalize(v_forward + randomvec() * autocvar_g_vehicle_bumblebee_cannon_spread) * autocvar_g_vehicle_bumblebee_cannon_speed,
98                                                 autocvar_g_vehicle_bumblebee_cannon_damage, autocvar_g_vehicle_bumblebee_cannon_radius, autocvar_g_vehicle_bumblebee_cannon_force,  0,
99                                                 DEATH_VH_BUMB_GUN, PROJECTILE_BUMBLE_GUN, 0, true, true, _owner);
100 }
101
102 float bumblebee_gunner_frame()
103 {
104         entity vehic    = self.vehicle.owner;
105         entity gun      = self.vehicle;
106         entity gunner   = self;
107         self = vehic;
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(!trace_ent.deadflag)
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)
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 = 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         self = 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', PL_MIN, PL_MAX, 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(PL_MAX - PL_MIN); // 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, PL_MIN, PL_MAX, 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 {
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, PL_MIN, PL_MAX);
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       = PL_VIEW_OFS;
266         player.event_damage   = PlayerDamage;
267         player.hud            = HUD_NORMAL;
268         player.teleportable       = TELEPORT_NORMAL;
269         player.switchweapon   = gunner.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         vh_player = player;
290         vh_vehicle = gunner;
291         MUTATOR_CALLHOOK(VehicleExit);
292         player = vh_player;
293         gunner = vh_vehicle;
294
295         player.vehicle = world;
296 }
297
298 bool bumblebee_gunner_enter()
299 {
300         entity vehic = self;
301         entity player = other;
302         entity gunner = world;
303
304         if(!vehic.gunner1 && !vehic.gunner2 && ((time >= vehic.gun1.phase) + (time >= vehic.gun2.phase)) == 2)
305         {
306                 // we can have some fun
307                 if(vlen(real_origin(vehic.gun2) - player.origin) < vlen(real_origin(vehic.gun1) - player.origin))
308                 {
309                         gunner = vehic.gun2;
310                         vehic.gunner2 = player;
311                 }
312                 else
313                 {
314                         gunner = vehic.gun1;
315                         vehic.gunner1 = player;
316                 }
317         }
318         else if(!vehic.gunner1 && time >= vehic.gun1.phase)     { gunner = vehic.gun1; vehic.gunner1 = player; }
319         else if(!vehic.gunner2 && time >= vehic.gun2.phase)             { gunner = vehic.gun2; vehic.gunner2 = player; }
320         else { dprint("Vehicle is full, fail\n"); return false; }
321
322         player.vehicle                  = gunner;
323         player.angles                   = vehic.angles;
324         player.takedamage               = DAMAGE_NO;
325         player.solid                    = SOLID_NOT;
326         player.alpha                    = -1;
327         player.movetype                 = MOVETYPE_NOCLIP;
328         player.event_damage     = func_null;
329         player.view_ofs                 = '0 0 0';
330         player.hud                              = gunner.hud;
331         player.teleportable     = false;
332         player.PlayerPhysplug   = gunner.PlayerPhysplug;
333         player.vehicle_ammo1    = vehic.vehicle_ammo1;
334         player.vehicle_ammo2    = vehic.vehicle_ammo2;
335         player.vehicle_reload1  = vehic.vehicle_reload1;
336         player.vehicle_reload2  = vehic.vehicle_reload2;
337         player.vehicle_energy   = vehic.vehicle_energy;
338         player.flags               &= ~FL_ONGROUND;
339
340         RemoveGrapplingHook(player);
341
342         gunner.switchweapon = player.switchweapon;
343         gunner.vehicle_exit = bumblebee_gunner_exit;
344         gunner.vehicle_hudmodel.viewmodelforclient = player;
345
346         if(IS_REAL_CLIENT(player))
347         {
348                 msg_entity = player;
349                 WriteByte(MSG_ONE,              SVC_SETVIEWPORT);
350                 WriteEntity(MSG_ONE,    gunner.vehicle_viewport);
351
352                 WriteByte(MSG_ONE,              SVC_SETVIEWANGLES);
353                 WriteAngle(MSG_ONE,     gunner.angles_x + vehic.angles_x); // tilt
354                 WriteAngle(MSG_ONE,     gunner.angles_y + vehic.angles_y); // yaw
355                 WriteAngle(MSG_ONE,     0); // roll
356         }
357
358         CSQCVehicleSetup(player, player.hud);
359
360         vh_player = player;
361         vh_vehicle = gunner;
362         MUTATOR_CALLHOOK(VehicleEnter);
363         player = vh_player;
364         gunner = vh_vehicle;
365
366         return true;
367 }
368
369 bool vehicles_valid_pilot()
370 {
371         if(IS_BOT_CLIENT(other) && !autocvar_g_vehicles_allow_bots)
372                 return false;
373
374         if((!IS_PLAYER(other))
375         || (other.deadflag != DEAD_NO)
376         || (other.vehicle)
377         || (DIFF_TEAM(other, self))
378         ) { return false; }
379
380         return true;
381 }
382
383 void bumblebee_touch()
384 {
385         if(autocvar_g_vehicles_enter) { return; }
386
387         if(self.gunner1 != world && self.gunner2 != world)
388         {
389                 vehicles_touch();
390                 return;
391         }
392
393         if(vehicles_valid_pilot())
394         {
395                 float phase_time = (time >= self.gun1.phase) + (time >= self.gun2.phase);
396
397                 if(time >= other.vehicle_enter_delay && phase_time)
398                 if(bumblebee_gunner_enter())
399                         return;
400         }
401
402         vehicles_touch();
403 }
404
405 void bumblebee_regen()
406 {
407         if(self.gun1.delay + autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause < time)
408                 self.gun1.vehicle_energy = min(autocvar_g_vehicle_bumblebee_cannon_ammo,
409                                                                            self.gun1.vehicle_energy + autocvar_g_vehicle_bumblebee_cannon_ammo_regen * frametime);
410
411         if(self.gun2.delay + autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause < time)
412                 self.gun2.vehicle_energy = min(autocvar_g_vehicle_bumblebee_cannon_ammo,
413                                                                            self.gun2.vehicle_energy + autocvar_g_vehicle_bumblebee_cannon_ammo_regen * frametime);
414
415         if(self.vehicle_flags  & VHF_SHIELDREGEN)
416                 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);
417
418         if(self.vehicle_flags  & VHF_HEALTHREGEN)
419                 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);
420
421         if(self.vehicle_flags  & VHF_ENERGYREGEN)
422                 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);
423
424 }
425
426 float bumblebee_pilot_frame()
427 {
428         entity pilot, vehic;
429         vector newvel;
430         
431         if(intermission_running)
432         {
433                 self.vehicle.velocity = '0 0 0';
434                 self.vehicle.avelocity = '0 0 0';
435                 return 1;
436         }
437
438         pilot = self;
439         vehic = self.vehicle;
440         self   = vehic;
441
442         if(vehic.deadflag != DEAD_NO)
443         {
444                 self = pilot;
445                 pilot.BUTTON_ATCK = pilot.BUTTON_ATCK2 = 0;
446                 return 1;
447         }
448
449         bumblebee_regen();
450
451         crosshair_trace(pilot);
452
453         vector vang;
454         float ftmp;
455
456         vang = vehic.angles;
457         newvel = vectoangles(normalize(trace_endpos - self.origin + '0 0 32'));
458         vang.x *= -1;
459         newvel.x *= -1;
460         if(newvel.x > 180)  newvel.x -= 360;
461         if(newvel.x < -180) newvel.x += 360;
462         if(newvel.y > 180)  newvel.y -= 360;
463         if(newvel.y < -180) newvel.y += 360;
464
465         ftmp = shortangle_f(pilot.v_angle.y - vang.y, vang.y);
466         if(ftmp > 180)  ftmp -= 360;
467         if(ftmp < -180) ftmp += 360;
468         vehic.avelocity_y = bound(-autocvar_g_vehicle_bumblebee_turnspeed, ftmp + vehic.avelocity.y * 0.9, autocvar_g_vehicle_bumblebee_turnspeed);
469
470         // Pitch
471         ftmp = 0;
472         if(pilot.movement.x > 0 && vang.x < autocvar_g_vehicle_bumblebee_pitchlimit)
473                 ftmp = 4;
474         else if(pilot.movement.x < 0 && vang.x > -autocvar_g_vehicle_bumblebee_pitchlimit)
475                 ftmp = -8;
476
477         newvel.x = bound(-autocvar_g_vehicle_bumblebee_pitchlimit, newvel.x , autocvar_g_vehicle_bumblebee_pitchlimit);
478         ftmp = vang.x - bound(-autocvar_g_vehicle_bumblebee_pitchlimit, newvel.x + ftmp, autocvar_g_vehicle_bumblebee_pitchlimit);
479         vehic.avelocity_x = bound(-autocvar_g_vehicle_bumblebee_pitchspeed, ftmp + vehic.avelocity.x * 0.9, autocvar_g_vehicle_bumblebee_pitchspeed);
480
481         vehic.angles_x = anglemods(vehic.angles.x);
482         vehic.angles_y = anglemods(vehic.angles.y);
483         vehic.angles_z = anglemods(vehic.angles.z);
484
485         makevectors('0 1 0' * vehic.angles.y);
486         newvel = vehic.velocity * -autocvar_g_vehicle_bumblebee_friction;
487
488         if(pilot.movement.x != 0)
489         {
490                 if(pilot.movement.x > 0)
491                         newvel += v_forward  * autocvar_g_vehicle_bumblebee_speed_forward;
492                 else if(pilot.movement.x < 0)
493                         newvel -= v_forward  * autocvar_g_vehicle_bumblebee_speed_forward;
494         }
495
496         if(pilot.movement.y != 0)
497         {
498                 if(pilot.movement.y < 0)
499                         newvel -= v_right * autocvar_g_vehicle_bumblebee_speed_strafe;
500                 else if(pilot.movement.y > 0)
501                         newvel += v_right * autocvar_g_vehicle_bumblebee_speed_strafe;
502                 ftmp = newvel * v_right;
503                 ftmp *= frametime * 0.1;
504                 vehic.angles_z = bound(-15, vehic.angles.z + ftmp, 15);
505         }
506         else
507         {
508                 vehic.angles_z *= 0.95;
509                 if(vehic.angles.z >= -1 && vehic.angles.z <= -1)
510                         vehic.angles_z = 0;
511         }
512
513         if(pilot.BUTTON_CROUCH)
514                 newvel -=   v_up * autocvar_g_vehicle_bumblebee_speed_down;
515         else if(pilot.BUTTON_JUMP)
516                 newvel +=  v_up * autocvar_g_vehicle_bumblebee_speed_up;
517
518         vehic.velocity  += newvel * frametime;
519         pilot.velocity = pilot.movement  = vehic.velocity;
520
521
522         if(autocvar_g_vehicle_bumblebee_healgun_locktime)
523         {
524                 if(vehic.tur_head.lock_time < time || vehic.tur_head.enemy.deadflag)
525                         vehic.tur_head.enemy = world;
526
527                 if(trace_ent)
528                 if(trace_ent.movetype)
529                 if(trace_ent.takedamage)
530                 if(!trace_ent.deadflag)
531                 {
532                         if(teamplay)
533                         {
534                                 if(trace_ent.team == pilot.team)
535                                 {
536                                         vehic.tur_head.enemy = trace_ent;
537                                         vehic.tur_head.lock_time = time + autocvar_g_vehicle_bumblebee_healgun_locktime;
538                                 }
539                         }
540                         else
541                         {
542                                 vehic.tur_head.enemy = trace_ent;
543                                 vehic.tur_head.lock_time = time + autocvar_g_vehicle_bumblebee_healgun_locktime;
544                         }
545                 }
546
547                 if(vehic.tur_head.enemy)
548                 {
549                         trace_endpos = real_origin(vehic.tur_head.enemy);
550                         UpdateAuxiliaryXhair(pilot, trace_endpos, '0 0.75 0', 0);
551                 }
552         }
553
554         vang = vehicle_aimturret(vehic, trace_endpos, self.gun3, "fire",
555                                           autocvar_g_vehicle_bumblebee_raygun_pitchlimit_down * -1,  autocvar_g_vehicle_bumblebee_raygun_pitchlimit_up,
556                                           autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides * -1,  autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides,  autocvar_g_vehicle_bumblebee_raygun_turnspeed);
557
558         if(!forbidWeaponUse(pilot))
559         if((pilot.BUTTON_ATCK || pilot.BUTTON_ATCK2) && (vehic.vehicle_energy > autocvar_g_vehicle_bumblebee_raygun_dps * sys_frametime || autocvar_g_vehicle_bumblebee_raygun == 0))
560         {
561                 vehic.gun3.enemy.realowner = pilot;
562                 vehic.gun3.enemy.effects &= ~EF_NODRAW;
563
564                 vehic.gun3.enemy.hook_start = gettaginfo(vehic.gun3, gettagindex(vehic.gun3, "fire"));
565                 vehic.gun3.enemy.SendFlags |= BRG_START;
566
567                 traceline(vehic.gun3.enemy.hook_start, vehic.gun3.enemy.hook_start + v_forward * autocvar_g_vehicle_bumblebee_raygun_range, MOVE_NORMAL, vehic);
568
569                 if(trace_ent)
570                 {
571                         if(autocvar_g_vehicle_bumblebee_raygun)
572                         {
573                                 Damage(trace_ent, vehic, pilot, autocvar_g_vehicle_bumblebee_raygun_dps * sys_frametime, DEATH_GENERIC, trace_endpos, v_forward * autocvar_g_vehicle_bumblebee_raygun_fps * sys_frametime);
574                                 vehic.vehicle_energy -= autocvar_g_vehicle_bumblebee_raygun_aps * sys_frametime;
575                         }
576                         else
577                         {
578                                 if(trace_ent.deadflag == DEAD_NO)
579                                         if((teamplay && trace_ent.team == pilot.team) || !teamplay)
580                                         {
581
582                                                 if(trace_ent.vehicle_flags & VHF_ISVEHICLE)
583                                                 {
584                                                         if(autocvar_g_vehicle_bumblebee_healgun_sps && trace_ent.vehicle_health <= trace_ent.max_health)
585                                                                 trace_ent.vehicle_shield = min(trace_ent.vehicle_shield + autocvar_g_vehicle_bumblebee_healgun_sps * frametime, trace_ent.tur_head.max_health);
586
587                                                         if(autocvar_g_vehicle_bumblebee_healgun_hps)
588                                                                 trace_ent.vehicle_health = min(trace_ent.vehicle_health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, trace_ent.max_health);
589                                                 }
590                                                 else if(IS_CLIENT(trace_ent))
591                                                 {
592                                                         if(trace_ent.health <= autocvar_g_vehicle_bumblebee_healgun_hmax && autocvar_g_vehicle_bumblebee_healgun_hps)
593                                                                 trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, autocvar_g_vehicle_bumblebee_healgun_hmax);
594
595                                                         if(trace_ent.armorvalue <= autocvar_g_vehicle_bumblebee_healgun_amax && autocvar_g_vehicle_bumblebee_healgun_aps)
596                                                                 trace_ent.armorvalue = min(trace_ent.armorvalue + autocvar_g_vehicle_bumblebee_healgun_aps * frametime, autocvar_g_vehicle_bumblebee_healgun_amax);
597
598                                                         trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, autocvar_g_vehicle_bumblebee_healgun_hmax);
599                                                 }
600                                                 else if(trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
601                                                 {
602                                                         if(trace_ent.health  <= trace_ent.max_health && autocvar_g_vehicle_bumblebee_healgun_hps)
603                                                                 trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, trace_ent.max_health);
604                                                         //else ..hmmm what? ammo?
605
606                                                         trace_ent.SendFlags |= TNSF_STATUS;
607                                                 }
608                                         }
609                         }
610                 }
611
612                 vehic.gun3.enemy.hook_end = trace_endpos;
613                 setorigin(vehic.gun3.enemy, trace_endpos);
614                 vehic.gun3.enemy.SendFlags |= BRG_END;
615
616                 vehic.wait = time + 1;
617         }
618         else
619                 vehic.gun3.enemy.effects |= EF_NODRAW;
620         /*{
621                 if(vehic.gun3.enemy)
622                         remove(vehic.gun3.enemy);
623
624                 vehic.gun3.enemy = world;
625         }
626         */
627
628         VEHICLE_UPDATE_PLAYER(pilot, health, bumblebee);
629         VEHICLE_UPDATE_PLAYER(pilot, energy, bumblebee);
630
631         pilot.vehicle_ammo1 = (vehic.gun1.vehicle_energy / autocvar_g_vehicle_bumblebee_cannon_ammo) * 100;
632         pilot.vehicle_ammo2 = (vehic.gun2.vehicle_energy / autocvar_g_vehicle_bumblebee_cannon_ammo) * 100;
633
634         if(vehic.vehicle_flags & VHF_HASSHIELD)
635                 VEHICLE_UPDATE_PLAYER(pilot, shield, bumblebee);
636
637         vehic.angles_x *= -1;
638         makevectors(vehic.angles);
639         vehic.angles_x *= -1;
640         setorigin(pilot, vehic.origin + v_up * 48 + v_forward * 160);
641
642         pilot.BUTTON_ATCK = pilot.BUTTON_ATCK2 = pilot.BUTTON_CROUCH = 0;
643         self = pilot;
644
645         return 1;
646 }
647
648 void bumblebee_land()
649 {
650         float hgt;
651
652         hgt = raptor_altitude(512);
653         self.velocity = (self.velocity * 0.9) + ('0 0 -1800' * (hgt / 256) * sys_frametime);
654         self.angles_x *= 0.95;
655         self.angles_z *= 0.95;
656
657         if(hgt < 16)
658                 self.think      = vehicles_think;
659
660         self.nextthink = time;
661         
662         CSQCMODEL_AUTOUPDATE();
663 }
664
665 void bumblebee_exit(float eject)
666 {
667         if(self.owner.vehicleid == VEH_BUMBLEBEE)
668         {
669                 bumblebee_gunner_exit(eject);
670                 return;
671         }
672
673         self.touch = vehicles_touch;
674
675         if(self.deadflag == DEAD_NO)
676         {
677                 self.think = bumblebee_land;
678                 self.nextthink  = time;
679         }
680         
681         self.movetype = MOVETYPE_TOSS;
682
683         if(!self.owner)
684                 return;
685
686         fixedmakevectors(self.angles);
687         vector spot;
688         if(vlen(self.velocity) > autocvar_g_vehicle_bumblebee_speed_forward * 0.5)
689                 spot = self.origin + v_up * 128 + v_forward * 300;
690         else
691                 spot = self.origin + v_up * 128 - v_forward * 300;
692
693         spot = vehicles_findgoodexit(spot);
694
695         // Hide beam
696         if(self.gun3.enemy || !wasfreed(self.gun3.enemy)) {
697                 self.gun3.enemy.effects |= EF_NODRAW;
698         }
699
700         self.owner.velocity = 0.75 * self.vehicle.velocity + normalize(spot - self.vehicle.origin) * 200;
701         self.owner.velocity_z += 10;
702         setorigin(self.owner, spot);
703
704         antilag_clear(self.owner);
705         self.owner = world;
706 }
707
708 void bumblebee_blowup()
709 {
710         RadiusDamage(self, self.enemy, autocvar_g_vehicle_bumblebee_blowup_coredamage,
711                                  autocvar_g_vehicle_bumblebee_blowup_edgedamage,
712                                  autocvar_g_vehicle_bumblebee_blowup_radius, self, world,
713                                  autocvar_g_vehicle_bumblebee_blowup_forceintensity,
714                                  DEATH_VH_BUMB_DEATH, world);
715
716         sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
717         pointparticles(particleeffectnum("explosion_big"), (self.origin + '0 0 100') + (randomvec() * 80), '0 0 0', 1);
718
719         if(self.owner.deadflag == DEAD_DYING)
720                 self.owner.deadflag = DEAD_DEAD;
721
722         remove(self);
723 }
724
725 void bumblebee_diethink()
726 {
727         if(time >= self.wait)
728                 self.think = bumblebee_blowup;
729
730         if(random() < 0.1)
731         {
732                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
733                 pointparticles(particleeffectnum("explosion_small"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
734         }
735
736         self.nextthink = time + 0.1;
737 }
738
739 float bumble_raygun_send(entity to, float sf)
740 {
741         WriteByte(MSG_ENTITY, ENT_CLIENT_BUMBLE_RAYGUN);
742
743         WriteByte(MSG_ENTITY, sf);
744         if(sf & BRG_SETUP)
745         {
746                 WriteByte(MSG_ENTITY, num_for_edict(self.realowner));
747                 WriteByte(MSG_ENTITY, self.realowner.team);
748                 WriteByte(MSG_ENTITY, self.cnt);
749         }
750
751         if(sf & BRG_START)
752         {
753                 WriteCoord(MSG_ENTITY, self.hook_start_x);
754                 WriteCoord(MSG_ENTITY, self.hook_start_y);
755                 WriteCoord(MSG_ENTITY, self.hook_start_z);
756         }
757
758         if(sf & BRG_END)
759         {
760                 WriteCoord(MSG_ENTITY, self.hook_end_x);
761                 WriteCoord(MSG_ENTITY, self.hook_end_y);
762                 WriteCoord(MSG_ENTITY, self.hook_end_z);
763         }
764
765         return true;
766 }
767
768 void spawnfunc_vehicle_bumblebee()
769 {
770         if(!autocvar_g_vehicle_bumblebee) { remove(self); return; }
771         if(!vehicle_initialize(VEH_BUMBLEBEE, false)) { remove(self); return; }
772 }
773
774 float v_bumblebee(float req)
775 {
776         switch(req)
777         {
778                 case VR_IMPACT:
779                 {
780                         if(autocvar_g_vehicle_bumblebee_bouncepain)
781                                 vehicles_impact(autocvar_g_vehicle_bumblebee_bouncepain_x, autocvar_g_vehicle_bumblebee_bouncepain_y, autocvar_g_vehicle_bumblebee_bouncepain_z);
782                                 
783                         return true;
784                 }
785                 case VR_ENTER:
786                 {
787                         self.touch = bumblebee_touch;
788                         self.nextthink = 0;
789                         self.movetype = MOVETYPE_BOUNCEMISSILE;
790                         return true;
791                 }
792                 case VR_THINK:
793                 {
794                         self.angles_z *= 0.8;
795                         self.angles_x *= 0.8;
796                         
797                         self.nextthink = time;
798                         
799                         if(!self.owner)
800                         {
801                                 entity oldself = self;          
802                                 if(self.gunner1)
803                                 {
804                                         self = self.gunner1;
805                                         oldself.gun1.vehicle_exit(VHEF_EJECT);
806                                         entity oldother = other;
807                                         other = self;
808                                         self = oldself;
809                                         self.phase = 0;
810                                         self.touch();
811                                         other = oldother;
812                                         return true;
813                                 }
814                                 
815                                 if(self.gunner2)
816                                 {
817                                         self = self.gunner2;
818                                         oldself.gun2.vehicle_exit(VHEF_EJECT);
819                                         entity oldother = other;
820                                         other = self;
821                                         self = oldself;
822                                         self.phase = 0;
823                                         self.touch();
824                                         other = oldother;
825                                         return true;
826                                 }               
827                         }
828                         
829                         return true;
830                 }
831                 case VR_DEATH:
832                 {
833                         entity oldself = self;
834
835                         CSQCModel_UnlinkEntity();
836
837                         // Hide beam
838                         if(self.gun3.enemy || !wasfreed(self.gun3.enemy))
839                                 self.gun3.enemy.effects |= EF_NODRAW;
840                         
841                         if(self.gunner1)
842                         {
843                                 self = self.gunner1;
844                                 oldself.gun1.vehicle_exit(VHEF_EJECT);
845                                 self = oldself;
846                         }
847
848                         if(self.gunner2)
849                         {
850                                 self = self.gunner2;
851                                 oldself.gun2.vehicle_exit(VHEF_EJECT);
852                                 self = oldself;
853                         }
854
855                         self.vehicle_exit(VHEF_EJECT);
856
857                         fixedmakevectors(self.angles);
858                         vehicle_tossgib(self.gun1, self.velocity + v_right * 300 + v_up * 100 + randomvec() * 200, "cannon_right", rint(random()), rint(random()), 6, randomvec() * 200);
859                         vehicle_tossgib(self.gun2, self.velocity + v_right * -300 + v_up * 100 + randomvec() * 200, "cannon_left", rint(random()), rint(random()), 6, randomvec() * 200);
860                         vehicle_tossgib(self.gun3, self.velocity + v_forward * 300 + v_up * -100 + randomvec() * 200, "raygun", rint(random()), rint(random()), 6, randomvec() * 300);
861
862                         entity _body = vehicle_tossgib(self, self.velocity + randomvec() * 200, "", rint(random()), rint(random()), 6, randomvec() * 100);
863
864                         if(random() > 0.5)
865                                 _body.touch = bumblebee_blowup;
866                         else
867                                 _body.touch = func_null;
868                                 
869                         _body.think = bumblebee_diethink;
870                         _body.nextthink = time;
871                         _body.wait = time + 2 + (random() * 8);
872                         _body.owner = self;
873                         _body.enemy = self.enemy;
874                         _body.scale = 1.5;
875                         _body.angles = self.angles;
876
877                         pointparticles(particleeffectnum("explosion_medium"), findbetterlocation(self.origin, 16), '0 0 0', 1);
878                         
879                         self.health                     = 0;
880                         self.event_damage       = func_null;
881                         self.solid                      = SOLID_NOT;
882                         self.takedamage         = DAMAGE_NO;
883                         self.deadflag           = DEAD_DYING;
884                         self.movetype           = MOVETYPE_NONE;
885                         self.effects            = EF_NODRAW;
886                         self.colormod           = '0 0 0';
887                         self.avelocity          = '0 0 0';
888                         self.velocity           = '0 0 0';
889                         self.touch                      = func_null;
890                         self.nextthink          = 0;
891
892                         setorigin(self, self.pos1);
893                         return true;
894                 }
895                 case VR_SPAWN:
896                 {
897                         if(!self.gun1)
898                         {
899                                 // for some reason, autosizing of the shield entity refuses to work for this one so set it up in advance.
900                                 self.vehicle_shieldent = spawn();
901                                 self.vehicle_shieldent.effects = EF_LOWPRECISION;
902                                 setmodel(self.vehicle_shieldent, "models/vhshield.md3");
903                                 setattachment(self.vehicle_shieldent, self, "");
904                                 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
905                                 self.vehicle_shieldent.scale       = 512 / vlen(self.maxs - self.mins);
906                                 self.vehicle_shieldent.think       = shieldhit_think;
907                                 self.vehicle_shieldent.alpha = -1;
908                                 self.vehicle_shieldent.effects = EF_LOWPRECISION | EF_NODRAW;
909
910                                 self.gun1 = spawn();
911                                 self.gun2 = spawn();
912                                 self.gun3 = spawn();
913
914                                 self.vehicle_flags |= VHF_MULTISLOT;
915
916                                 self.gun1.owner = self;
917                                 self.gun2.owner = self;
918                                 self.gun3.owner = self;
919
920                                 self.gun1.classname = self.gun2.classname = "vehicle_playerslot";
921
922                                 setmodel(self.gun1, "models/vehicles/bumblebee_plasma_right.dpm");
923                                 setmodel(self.gun2, "models/vehicles/bumblebee_plasma_left.dpm");
924                                 setmodel(self.gun3, "models/vehicles/bumblebee_ray.dpm");
925
926                                 setattachment(self.gun1, self, "cannon_right");
927                                 setattachment(self.gun2, self, "cannon_left");
928
929                                 // Angled bones are no fun, messes up gun-aim; so work arround it.
930                                 self.gun3.pos1 = self.angles;
931                                 self.angles = '0 0 0';
932                                 vector ofs = gettaginfo(self, gettagindex(self, "raygun"));
933                                 ofs -= self.origin;
934                                 setattachment(self.gun3, self, "");
935                                 setorigin(self.gun3, ofs);
936                                 self.angles = self.gun3.pos1;
937
938                                 vehicle_addplayerslot(self, self.gun1, HUD_BUMBLEBEE_GUN, "models/vehicles/wakizashi_cockpit.dpm", bumblebee_gunner_frame, bumblebee_gunner_exit, bumblebee_gunner_enter);
939                                 vehicle_addplayerslot(self, self.gun2, HUD_BUMBLEBEE_GUN, "models/vehicles/wakizashi_cockpit.dpm", bumblebee_gunner_frame, bumblebee_gunner_exit, bumblebee_gunner_enter);
940
941                                 setorigin(self.vehicle_hudmodel, '50 0 -5');    // Move cockpit forward - down.
942                                 setorigin(self.vehicle_viewport, '5 0 2');    // Move camera forward up
943
944                                 //fixme-model-bones
945                                 setorigin(self.gun1.vehicle_hudmodel, '90 -27 -23');
946                                 setorigin(self.gun1.vehicle_viewport, '-85 0 50');
947                                 //fixme-model-bones
948                                 setorigin(self.gun2.vehicle_hudmodel, '90 27 -23');
949                                 setorigin(self.gun2.vehicle_viewport, '-85 0 50');
950
951                                 self.scale = 1.5;
952                                 
953                                 // Raygun beam
954                                 if(self.gun3.enemy == world)
955                                 {                       
956                                         self.gun3.enemy = spawn();
957                                         Net_LinkEntity(self.gun3.enemy, true, 0, bumble_raygun_send);
958                                         self.gun3.enemy.SendFlags = BRG_SETUP;                  
959                                         self.gun3.enemy.cnt = autocvar_g_vehicle_bumblebee_raygun;                      
960                                         self.gun3.enemy.effects = EF_NODRAW | EF_LOWPRECISION;
961                                 }
962                         }
963
964                         self.vehicle_health = autocvar_g_vehicle_bumblebee_health;
965                         self.vehicle_shield = autocvar_g_vehicle_bumblebee_shield;
966                         self.solid = SOLID_BBOX;
967                         self.movetype = MOVETYPE_TOSS;
968                         self.damageforcescale = 0.025;
969                         
970                         self.PlayerPhysplug = bumblebee_pilot_frame;
971                         
972                         setorigin(self, self.origin + '0 0 25');
973                         return true;
974                 }
975                 case VR_SETUP:
976                 {
977                         if(autocvar_g_vehicle_bumblebee_energy)
978                         if(autocvar_g_vehicle_bumblebee_energy_regen)
979                                 self.vehicle_flags |= VHF_ENERGYREGEN;
980
981                         if(autocvar_g_vehicle_bumblebee_shield)
982                                 self.vehicle_flags |= VHF_HASSHIELD;
983
984                         if(autocvar_g_vehicle_bumblebee_shield_regen)
985                                 self.vehicle_flags |= VHF_SHIELDREGEN;
986
987                         if(autocvar_g_vehicle_bumblebee_health_regen)
988                                 self.vehicle_flags |= VHF_HEALTHREGEN;
989                                 
990                         self.vehicle_exit = bumblebee_exit;
991                         self.respawntime = autocvar_g_vehicle_bumblebee_respawntime;
992                         self.vehicle_health = autocvar_g_vehicle_bumblebee_health;
993                         self.max_health = self.vehicle_health;
994                         self.vehicle_shield = autocvar_g_vehicle_bumblebee_shield;
995                                 
996                         return true;
997                 }
998                 case VR_PRECACHE:
999                 {
1000                         precache_model("models/vehicles/bumblebee_body.dpm");
1001                         precache_model("models/vehicles/bumblebee_plasma_left.dpm");
1002                         precache_model("models/vehicles/bumblebee_plasma_right.dpm");
1003                         precache_model("models/vehicles/bumblebee_ray.dpm");
1004                         precache_model("models/vehicles/wakizashi_cockpit.dpm");
1005                         precache_model("models/vehicles/spiderbot_cockpit.dpm");
1006                         precache_model("models/vehicles/raptor_cockpit.dpm");
1007                         return true;
1008                 }
1009         }
1010
1011         return true;
1012 }
1013
1014 #endif // SVQC
1015 #ifdef CSQC
1016
1017 #define bumb_ico  "gfx/vehicles/bumb.tga"
1018 #define bumb_lgun  "gfx/vehicles/bumb_lgun.tga"
1019 #define bumb_rgun  "gfx/vehicles/bumb_rgun.tga"
1020
1021 #define bumb_gun_ico  "gfx/vehicles/bumb_side.tga"
1022 #define bumb_gun_gun  "gfx/vehicles/bumb_side_gun.tga"
1023
1024 void CSQC_BUMBLE_GUN_HUD()
1025 {
1026         if(autocvar_r_letterbox)
1027                 return;
1028
1029         vector picsize, hudloc = '0 0 0', pic2size, picloc;
1030
1031         // Fetch health & ammo stats
1032         HUD_GETVEHICLESTATS
1033
1034         picsize = draw_getimagesize(hud_bg) * autocvar_cl_vehicles_hudscale;
1035         hudloc_y = vid_conheight - picsize_y;
1036         hudloc_x = vid_conwidth * 0.5 - picsize_x * 0.5;
1037
1038         drawpic(hudloc, hud_bg, picsize, '1 1 1', autocvar_cl_vehicles_hudalpha, DRAWFLAG_NORMAL);
1039
1040         shield  *= 0.01;
1041         vh_health  *= 0.01;
1042         energy  *= 0.01;
1043         reload1 *= 0.01;
1044
1045         pic2size = draw_getimagesize(bumb_gun_ico) * (autocvar_cl_vehicles_hudscale * 0.8);
1046         picloc = picsize * 0.5 - pic2size * 0.5;
1047
1048         if(vh_health < 0.25)
1049                 drawpic(hudloc + picloc, bumb_gun_ico, pic2size,  '1 0 0' + '0 1 1' * sin(time * 8),  1, DRAWFLAG_NORMAL);
1050         else
1051                 drawpic(hudloc + picloc, bumb_gun_ico, pic2size,  '1 1 1' * vh_health  + '1 0 0' * (1 - vh_health),  1, DRAWFLAG_NORMAL);
1052
1053         drawpic(hudloc + picloc, bumb_gun_gun, pic2size, '1 1 1' * energy   + '1 0 0' * (1 - energy),   1, DRAWFLAG_NORMAL);
1054         drawpic(hudloc + picloc, hud_sh, pic2size,  '1 1 1', shield, DRAWFLAG_NORMAL);
1055
1056 // Health bar
1057         picsize = draw_getimagesize(hud_hp_bar) * autocvar_cl_vehicles_hudscale;
1058         picloc = '69 69 0' * autocvar_cl_vehicles_hudscale;
1059         drawsetcliparea(hudloc_x + picloc_x + (picsize_x * (1 - vh_health)), 0, vid_conwidth, vid_conheight);
1060         drawpic(hudloc + picloc, hud_hp_bar, picsize, '1 1 1', 1 , DRAWFLAG_NORMAL);
1061         drawresetcliparea();
1062 // ..  and icon
1063         picsize = draw_getimagesize(hud_hp_ico) * autocvar_cl_vehicles_hudscale;
1064         picloc = '37 65 0' * autocvar_cl_vehicles_hudscale;
1065         if(vh_health < 0.25)
1066         {
1067                 if(alarm1time < time)
1068                 {
1069                         alarm1time = time + 2;
1070                         vehicle_alarm(self, CH_PAIN_SINGLE, "vehicles/alarm.wav");
1071                 }
1072
1073                 drawpic(hudloc + picloc, hud_hp_ico, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
1074         }
1075         else
1076         {
1077                 drawpic(hudloc + picloc, hud_hp_ico, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1078                 if(alarm1time)
1079                 {
1080                         vehicle_alarm(self, CH_PAIN_SINGLE, "misc/null.wav");
1081                         alarm1time = 0;
1082                 }
1083         }
1084
1085 // Shield bar
1086         picsize = draw_getimagesize(hud_sh_bar) * autocvar_cl_vehicles_hudscale;
1087         picloc = '69 140 0' * autocvar_cl_vehicles_hudscale;
1088         drawsetcliparea(hudloc_x + picloc_x + (picsize_x * (1 - shield)), 0, vid_conwidth, vid_conheight);
1089         drawpic(hudloc + picloc, hud_sh_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1090         drawresetcliparea();
1091 // ..  and icon
1092         picloc = '40 136 0' * autocvar_cl_vehicles_hudscale;
1093         picsize = draw_getimagesize(hud_sh_ico) * autocvar_cl_vehicles_hudscale;
1094         if(shield < 0.25)
1095         {
1096                 if(alarm2time < time)
1097                 {
1098                         alarm2time = time + 1;
1099                         vehicle_alarm(self, CH_TRIGGER_SINGLE, "vehicles/alarm_shield.wav");
1100                 }
1101                 drawpic(hudloc + picloc, hud_sh_ico, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
1102         }
1103         else
1104         {
1105                 drawpic(hudloc + picloc, hud_sh_ico, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1106                 if(alarm2time)
1107                 {
1108                         vehicle_alarm(self, CH_TRIGGER_SINGLE, "misc/null.wav");
1109                         alarm2time = 0;
1110                 }
1111         }
1112
1113 // Gun bar
1114         picsize = draw_getimagesize(hud_ammo1_bar) * autocvar_cl_vehicles_hudscale;
1115         picloc = '450 69 0' * autocvar_cl_vehicles_hudscale;
1116         drawsetcliparea(hudloc_x + picloc_x, picloc_y, picsize_x * energy, vid_conheight);
1117         drawpic(hudloc + picloc, hud_ammo1_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1118         drawresetcliparea();
1119
1120 // ..  and icon
1121         picsize = 1.5 * draw_getimagesize(hud_energy) * autocvar_cl_vehicles_hudscale;
1122         picloc = '664 60 0' * autocvar_cl_vehicles_hudscale;
1123         if(energy < 0.2)
1124                 drawpic(hudloc + picloc, hud_energy, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
1125         else
1126                 drawpic(hudloc + picloc, hud_energy, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1127
1128         if (scoreboard_showscores)
1129                 HUD_DrawScoreboard();
1130         /*
1131         else
1132         {
1133                 picsize = draw_getimagesize(waki_xhair);
1134                 picsize_x *= 0.5;
1135                 picsize_y *= 0.5;
1136
1137
1138                 drawpic('0.5 0 0' * (vid_conwidth - picsize_x) + '0 0.5 0' * (vid_conheight - picsize_y), waki_xhair, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1139         }
1140         */
1141 }
1142
1143 void bumble_raygun_draw()
1144 {
1145         float _len;
1146         vector _dir;
1147         vector _vtmp1, _vtmp2;
1148
1149         _len = vlen(self.origin - self.move_origin);
1150         _dir = normalize(self.move_origin - self.origin);
1151
1152         if(self.total_damages < time)
1153         {
1154                 boxparticles(self.traileffect, self, self.origin, self.origin + _dir * -64, _dir * -_len , _dir * -_len, 1, PARTICLES_USEALPHA);
1155                 boxparticles(self.lip, self, self.move_origin, self.move_origin + _dir * -64, _dir * -200 , _dir * -200, 1, PARTICLES_USEALPHA);
1156                 self.total_damages = time + 0.1;
1157         }
1158
1159         float i, df, sz, al;
1160         for(i = -0.1; i < 0.2; i += 0.1)
1161         {
1162                 df = DRAWFLAG_NORMAL; //((random() < 0.5) ? DRAWFLAG_ADDITIVE : DRAWFLAG_SCREEN);
1163                 sz = 5 + random() * 5;
1164                 al = 0.25 + random() * 0.5;
1165                 _vtmp1 = self.origin + _dir * _len * (0.25 + i);
1166                 _vtmp1 += (randomvec() * (_len * 0.2) * (frametime * 2));       //self.raygun_l1;
1167                 Draw_CylindricLine(self.origin, _vtmp1, sz, "gfx/colors/white.tga", 1, 1, self.colormod, al, df, view_origin);
1168
1169                 _vtmp2 = self.origin + _dir * _len * (0.5 + i);
1170                 _vtmp2 += (randomvec() * (_len * 0.2) * (frametime * 5));       //self.raygun_l2;
1171                 Draw_CylindricLine(_vtmp1, _vtmp2, sz, "gfx/colors/white.tga", 1, 1, self.colormod, al, df, view_origin);
1172
1173                 _vtmp1 = self.origin + _dir * _len * (0.75 + i);
1174                 _vtmp1 += randomvec() * (_len * 0.2) * (frametime * 10);     //self.raygun_l3;
1175                 Draw_CylindricLine(_vtmp2, _vtmp1, sz, "gfx/colors/white.tga", 1, 1, self.colormod, al, df, view_origin);
1176
1177                 Draw_CylindricLine(_vtmp1, self.move_origin +  randomvec() * 32, sz, "gfx/colors/white.tga", 1, 1, self.colormod, al, df, view_origin);
1178         }
1179 }
1180
1181 void bumble_raygun_read(bool bIsNew)
1182 {
1183         int sf = ReadByte();
1184
1185         if(sf & BRG_SETUP)
1186         {
1187                 self.cnt  = ReadByte();
1188                 self.team = ReadByte();
1189                 self.cnt  = ReadByte();
1190
1191                 if(self.cnt)
1192                         self.colormod = '1 0 0';
1193                 else
1194                         self.colormod = '0 1 0';
1195
1196                 self.traileffect = particleeffectnum("healray_muzzleflash");
1197                 self.lip = particleeffectnum("healray_impact");
1198
1199                 self.draw = bumble_raygun_draw;
1200         }
1201
1202
1203         if(sf & BRG_START)
1204         {
1205                 self.origin_x = ReadCoord();
1206                 self.origin_y = ReadCoord();
1207                 self.origin_z = ReadCoord();
1208                 setorigin(self, self.origin);
1209         }
1210
1211         if(sf & BRG_END)
1212         {
1213                 self.move_origin_x = ReadCoord();
1214                 self.move_origin_y = ReadCoord();
1215                 self.move_origin_z = ReadCoord();
1216         }
1217 }
1218
1219 float v_bumblebee(float req)
1220 {
1221         switch(req)
1222         {
1223                 case VR_HUD:
1224                 {
1225                         if(autocvar_r_letterbox)
1226                                 return true;
1227
1228                         vector picsize, hudloc = '0 0 0', pic2size, picloc;
1229
1230                         // Fetch health & ammo stats
1231                         HUD_GETVEHICLESTATS
1232
1233                         picsize = draw_getimagesize(hud_bg) * autocvar_cl_vehicles_hudscale;
1234                         hudloc_y = vid_conheight - picsize_y;
1235                         hudloc_x = vid_conwidth * 0.5 - picsize_x * 0.5;
1236
1237                         drawpic(hudloc, hud_bg, picsize, '1 1 1', autocvar_cl_vehicles_hudalpha, DRAWFLAG_NORMAL);
1238
1239                         shield  *= 0.01;
1240                         vh_health  *= 0.01;
1241                         energy  *= 0.01;
1242                         reload1 *= 0.01;
1243
1244                         pic2size = draw_getimagesize(bumb_ico) * (autocvar_cl_vehicles_hudscale * 0.8);
1245                         picloc = picsize * 0.5 - pic2size * 0.5;
1246
1247                         if(vh_health < 0.25)
1248                                 drawpic(hudloc + picloc, bumb_ico, pic2size,  '1 0 0' + '0 1 1' * sin(time * 8),  1, DRAWFLAG_NORMAL);
1249                         else
1250                                 drawpic(hudloc + picloc, bumb_ico, pic2size,  '1 1 1' * vh_health  + '1 0 0' * (1 - vh_health),  1, DRAWFLAG_NORMAL);
1251
1252                         drawpic(hudloc + picloc, bumb_lgun, pic2size, '1 1 1' * energy   + '1 0 0' * (1 - energy),   1, DRAWFLAG_NORMAL);
1253                         drawpic(hudloc + picloc, bumb_lgun, pic2size, '1 1 1' * energy   + '1 0 0' * (1 - energy),   1, DRAWFLAG_NORMAL);
1254                         drawpic(hudloc + picloc, hud_sh, pic2size,  '1 1 1', shield, DRAWFLAG_NORMAL);
1255
1256                 // Health bar
1257                         picsize = draw_getimagesize(hud_hp_bar) * autocvar_cl_vehicles_hudscale;
1258                         picloc = '69 69 0' * autocvar_cl_vehicles_hudscale;
1259                         drawsetcliparea(hudloc_x + picloc_x + (picsize_x * (1 - vh_health)), 0, vid_conwidth, vid_conheight);
1260                         drawpic(hudloc + picloc, hud_hp_bar, picsize, '1 1 1', 1 , DRAWFLAG_NORMAL);
1261                         drawresetcliparea();
1262                 // ..  and icon
1263                         picsize = draw_getimagesize(hud_hp_ico) * autocvar_cl_vehicles_hudscale;
1264                         picloc = '37 65 0' * autocvar_cl_vehicles_hudscale;
1265                         if(vh_health < 0.25)
1266                         {
1267                                 if(alarm1time < time)
1268                                 {
1269                                         alarm1time = time + 2;
1270                                         vehicle_alarm(self, CH_PAIN_SINGLE, "vehicles/alarm.wav");
1271                                 }
1272
1273                                 drawpic(hudloc + picloc, hud_hp_ico, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
1274                         }
1275                         else
1276                         {
1277                                 drawpic(hudloc + picloc, hud_hp_ico, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1278                                 if(alarm1time)
1279                                 {
1280                                         vehicle_alarm(self, CH_PAIN_SINGLE, "misc/null.wav");
1281                                         alarm1time = 0;
1282                                 }
1283                         }
1284
1285                 // Shield bar
1286                         picsize = draw_getimagesize(hud_sh_bar) * autocvar_cl_vehicles_hudscale;
1287                         picloc = '69 140 0' * autocvar_cl_vehicles_hudscale;
1288                         drawsetcliparea(hudloc_x + picloc_x + (picsize_x * (1 - shield)), 0, vid_conwidth, vid_conheight);
1289                         drawpic(hudloc + picloc, hud_sh_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1290                         drawresetcliparea();
1291                 // ..  and icon
1292                         picloc = '40 136 0' * autocvar_cl_vehicles_hudscale;
1293                         picsize = draw_getimagesize(hud_sh_ico) * autocvar_cl_vehicles_hudscale;
1294                         if(shield < 0.25)
1295                         {
1296                                 if(alarm2time < time)
1297                                 {
1298                                         alarm2time = time + 1;
1299                                         vehicle_alarm(self, CH_TRIGGER_SINGLE, "vehicles/alarm_shield.wav");
1300                                 }
1301                                 drawpic(hudloc + picloc, hud_sh_ico, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
1302                         }
1303                         else
1304                         {
1305                                 drawpic(hudloc + picloc, hud_sh_ico, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1306                                 if(alarm2time)
1307                                 {
1308                                         vehicle_alarm(self, CH_TRIGGER_SINGLE, "misc/null.wav");
1309                                         alarm2time = 0;
1310                                 }
1311                         }
1312
1313                         ammo1 *= 0.01;
1314                         ammo2 *= 0.01;
1315
1316                 // Gunner1 bar
1317                         picsize = draw_getimagesize(hud_ammo1_bar) * autocvar_cl_vehicles_hudscale;
1318                         picloc = '450 69 0' * autocvar_cl_vehicles_hudscale;
1319                         drawsetcliparea(hudloc_x + picloc_x, picloc_y, picsize_x * ammo1, vid_conheight);
1320                         drawpic(hudloc + picloc, hud_ammo1_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1321                         drawresetcliparea();
1322
1323                 // Right gunner slot occupied?
1324                         if(!AuxiliaryXhair[1].draw2d)
1325                         {
1326                                 shield = (picsize_x * 0.5) - (0.5 * stringwidth(_("No right gunner!"), false, '1 0 0' * picsize_y + '0 1 0' * picsize_y));
1327                                 drawfill(hudloc + picloc - '0.2 0.2 0', picsize + '0.4 0.4 0', '0.25 0.25 0.25', 0.75, DRAWFLAG_NORMAL);
1328                                 drawstring(hudloc + picloc + '1 0 0' * shield, _("No right gunner!"), '1 0 0' * picsize_y + '0 1 0' * picsize_y, '1 0 0' + '0 1 1' * sin(time * 10), 1, DRAWFLAG_NORMAL);
1329                         }
1330
1331                 // ..  and icon
1332                         picsize = 1.5 * draw_getimagesize(hud_energy) * autocvar_cl_vehicles_hudscale;
1333                         picloc = '664 60 0' * autocvar_cl_vehicles_hudscale;
1334                         if(ammo1 < 0.2)
1335                                 drawpic(hudloc + picloc, hud_energy, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
1336                         else
1337                                 drawpic(hudloc + picloc, hud_energy, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1338
1339                 // Gunner2 bar
1340                         picsize = draw_getimagesize(hud_ammo2_bar) * autocvar_cl_vehicles_hudscale;
1341                         picloc = '450 140 0' * autocvar_cl_vehicles_hudscale;
1342                         drawsetcliparea(hudloc_x + picloc_x, picloc_y, picsize_x * ammo2, vid_conheight);
1343                         drawpic(hudloc + picloc, hud_ammo2_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1344                         drawresetcliparea();
1345                 // Left gunner slot occupied?
1346                         if(!AuxiliaryXhair[2].draw2d)
1347                         {
1348                                 shield = (picsize_x * 0.5) - (0.5 * stringwidth(_("No left gunner!"), false, '1 0 0' * picsize_y + '0 1 0' * picsize_y));
1349                                 drawfill(hudloc + picloc - '0.2 0.2 0', picsize + '0.4 0.4 0', '0.25 0.25 0.25', 0.75, DRAWFLAG_NORMAL);
1350                                 drawstring(hudloc + picloc + '1 0 0' * shield, _("No left gunner!"), '1 0 0' * picsize_y + '0 1 0' * picsize_y, '1 0 0' + '0 1 1' * sin(time * 10), 1, DRAWFLAG_NORMAL);
1351                         }
1352
1353                 // ..  and icon
1354                         picsize = 1.5 * draw_getimagesize(hud_energy) * autocvar_cl_vehicles_hudscale;
1355                         picloc = '664 130 0' * autocvar_cl_vehicles_hudscale;
1356                         if(ammo2 < 0.2)
1357                                 drawpic(hudloc + picloc, hud_energy, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
1358                         else
1359                                 drawpic(hudloc + picloc, hud_energy, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1360
1361                         if (scoreboard_showscores)
1362                                 HUD_DrawScoreboard();
1363                         else
1364                         {
1365                                 picsize = draw_getimagesize(waki_xhair);
1366                                 picsize_x *= 0.5;
1367                                 picsize_y *= 0.5;
1368                                 drawpic('0.5 0 0' * (vid_conwidth - picsize_x) + '0 0.5 0' * (vid_conheight - picsize_y), waki_xhair, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1369                         }
1370                         return true;
1371                 }
1372                 case VR_SETUP:
1373                 {
1374                         // raygun-locked
1375                         AuxiliaryXhair[0].axh_image   = "gfx/vehicles/axh-bracket.tga";
1376                         AuxiliaryXhair[0].axh_scale   = 0.5;
1377
1378                         // Gunner1
1379                         AuxiliaryXhair[1].axh_image   = "gfx/vehicles/axh-target.tga";
1380                         AuxiliaryXhair[1].axh_scale   = 0.75;
1381
1382                         // Gunner2
1383                         AuxiliaryXhair[2].axh_image   = "gfx/vehicles/axh-target.tga";
1384                         AuxiliaryXhair[2].axh_scale   = 0.75;
1385                         return true;
1386                 }
1387                 case VR_PRECACHE:
1388                 {
1389                         return true;
1390                 }
1391         }
1392
1393         return true;
1394 }
1395
1396 #endif // CSQC
1397 #endif // REGISTER_VEHICLE