Fix extra life powerup giving infinite lives in lms & minstagib
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / vehicles / bumblebee.qc
1 #define BRG_SETUP 2
2 #define BRG_START 4
3 #define BRG_END 8
4
5 #ifdef SVQC
6 // Auto cvars
7 float autocvar_g_vehicle_bumblebee_speed_forward;
8 float autocvar_g_vehicle_bumblebee_speed_strafe;
9 float autocvar_g_vehicle_bumblebee_speed_up;
10 float autocvar_g_vehicle_bumblebee_speed_down;
11 float autocvar_g_vehicle_bumblebee_turnspeed;
12 float autocvar_g_vehicle_bumblebee_pitchspeed;
13 float autocvar_g_vehicle_bumblebee_pitchlimit;
14 float autocvar_g_vehicle_bumblebee_friction;
15
16 float autocvar_g_vehicle_bumblebee_energy;
17 float autocvar_g_vehicle_bumblebee_energy_regen;
18 float autocvar_g_vehicle_bumblebee_energy_regen_pause;
19
20 float autocvar_g_vehicle_bumblebee_health;
21 float autocvar_g_vehicle_bumblebee_health_regen;
22 float autocvar_g_vehicle_bumblebee_health_regen_pause;
23
24 float autocvar_g_vehicle_bumblebee_shield;
25 float autocvar_g_vehicle_bumblebee_shield_regen;
26 float autocvar_g_vehicle_bumblebee_shield_regen_pause;
27
28 float autocvar_g_vehicle_bumblebee_cannon_cost;
29 float autocvar_g_vehicle_bumblebee_cannon_damage;
30 float autocvar_g_vehicle_bumblebee_cannon_radius;
31 float autocvar_g_vehicle_bumblebee_cannon_refire;
32 float autocvar_g_vehicle_bumblebee_cannon_speed;
33 float autocvar_g_vehicle_bumblebee_cannon_spread;
34 float autocvar_g_vehicle_bumblebee_cannon_force;
35
36 float autocvar_g_vehicle_bumblebee_cannon_ammo;
37 float autocvar_g_vehicle_bumblebee_cannon_ammo_regen;
38 float autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause;
39
40 var float autocvar_g_vehicle_bumblebee_cannon_lock = 0;
41
42 float autocvar_g_vehicle_bumblebee_cannon_turnspeed;
43 float autocvar_g_vehicle_bumblebee_cannon_pitchlimit_down;
44 float autocvar_g_vehicle_bumblebee_cannon_pitchlimit_up;
45 float autocvar_g_vehicle_bumblebee_cannon_turnlimit_in;
46 float autocvar_g_vehicle_bumblebee_cannon_turnlimit_out;
47
48
49 float autocvar_g_vehicle_bumblebee_raygun_turnspeed;
50 float autocvar_g_vehicle_bumblebee_raygun_pitchlimit_down;
51 float autocvar_g_vehicle_bumblebee_raygun_pitchlimit_up;
52 float autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides;
53
54 float autocvar_g_vehicle_bumblebee_raygun_range;
55 float autocvar_g_vehicle_bumblebee_raygun_dps;
56 float autocvar_g_vehicle_bumblebee_raygun_aps;
57 float autocvar_g_vehicle_bumblebee_raygun_fps;
58
59 float autocvar_g_vehicle_bumblebee_raygun;
60 float autocvar_g_vehicle_bumblebee_healgun_hps;
61 float autocvar_g_vehicle_bumblebee_healgun_hmax;
62 float autocvar_g_vehicle_bumblebee_healgun_aps;
63 float autocvar_g_vehicle_bumblebee_healgun_amax;
64 float autocvar_g_vehicle_bumblebee_healgun_sps;
65 float autocvar_g_vehicle_bumblebee_healgun_locktime;
66
67 float autocvar_g_vehicle_bumblebee_respawntime;
68
69 float autocvar_g_vehicle_bumblebee_blowup_radius;
70 float autocvar_g_vehicle_bumblebee_blowup_coredamage;
71 float autocvar_g_vehicle_bumblebee_blowup_edgedamage;
72 float autocvar_g_vehicle_bumblebee_blowup_forceintensity;
73 var vector autocvar_g_vehicle_bumblebee_bouncepain;
74
75 var float autocvar_g_vehicle_bumblebee = 0;
76
77
78 float bumble_raygun_send(entity to, float sf);
79
80 #define BUMB_MIN '-130 -130 -130'
81 #define BUMB_MAX '130 130 130'
82
83 void bumb_fire_cannon(entity _gun, string _tagname, entity _owner)
84 {
85         vector v = gettaginfo(_gun, gettagindex(_gun, _tagname));
86         vehicles_projectile("bigplasma_muzzleflash", "weapons/flacexp3.wav",
87                                                 v, normalize(v_forward + randomvec() * autocvar_g_vehicle_bumblebee_cannon_spread) * autocvar_g_vehicle_bumblebee_cannon_speed,
88                                                 autocvar_g_vehicle_bumblebee_cannon_damage, autocvar_g_vehicle_bumblebee_cannon_radius, autocvar_g_vehicle_bumblebee_cannon_force,  0,
89                                                 DEATH_VH_BUMB_GUN, PROJECTILE_BUMBLE_GUN, 0, TRUE, TRUE, _owner);
90 }
91
92 float bumb_gunner_frame()
93 {
94         entity vehic    = self.vehicle.owner;
95         entity gun      = self.vehicle;
96         entity gunner   = self;
97         self = vehic;
98
99
100         
101         
102         vehic.solid = SOLID_NOT;
103         //setorigin(gunner, vehic.origin);
104         gunner.velocity = vehic.velocity;
105         
106         float _in, _out;
107         vehic.angles_x *= -1;
108         makevectors(vehic.angles);
109         vehic.angles_x *= -1;
110         if((gun == vehic.gun1))
111         {
112                 _in = autocvar_g_vehicle_bumblebee_cannon_turnlimit_in;
113                 _out = autocvar_g_vehicle_bumblebee_cannon_turnlimit_out;
114                 setorigin(gunner, vehic.origin + v_up * -16 + v_forward * -16 + v_right * 128);
115         }
116         else
117         {
118                 _in = autocvar_g_vehicle_bumblebee_cannon_turnlimit_out;
119                 _out = autocvar_g_vehicle_bumblebee_cannon_turnlimit_in;
120                 setorigin(gunner, vehic.origin + v_up * -16 + v_forward * -16 + v_right * -128);                
121         }
122         
123         crosshair_trace(gunner);
124         vector _ct = trace_endpos;
125         vector ad;
126
127         if(autocvar_g_vehicle_bumblebee_cannon_lock)
128         {
129                 if(gun.lock_time < time)
130                         gun.enemy = world;
131
132                 if(trace_ent)
133                         if(trace_ent.movetype)
134                                 if(trace_ent.takedamage)
135                                         if(!trace_ent.deadflag)
136                                         {
137                                                 if(teamplay)
138                                                 {
139                                                         if(trace_ent.team != gunner.team)
140                                                         {
141                                                                 gun.enemy = trace_ent;
142                                                                 gun.lock_time = time + 5;
143                                                         }
144                                                 }
145                                                 else
146                                                 {
147                                                         gun.enemy = trace_ent;
148                                                         gun.lock_time = time + 5;
149                                                 }
150                                         }
151         }
152
153         if(gun.enemy)
154         {
155                 float i, distance, impact_time;
156
157                 vector vf = real_origin(gun.enemy);
158                 vector _vel = gun.enemy.velocity;
159                 if(gun.enemy.movetype == MOVETYPE_WALK)
160                         _vel_z *= 0.1;
161
162
163                 ad = vf;
164                 for(i = 0; i < 4; ++i)
165                 {
166                         distance = vlen(ad - gunner.origin);
167                         impact_time = distance / autocvar_g_vehicle_bumblebee_cannon_speed;
168                         ad = vf + _vel * impact_time;
169                 }
170                 trace_endpos = ad;
171
172
173                 UpdateAuxiliaryXhair(gunner, ad, '1 0 1', 1);
174                 vehicle_aimturret(vehic, trace_endpos, gun, "fire",
175                                                   autocvar_g_vehicle_bumblebee_cannon_pitchlimit_down * -1, autocvar_g_vehicle_bumblebee_cannon_pitchlimit_up,
176                                                   _out * -1,  _in,  autocvar_g_vehicle_bumblebee_cannon_turnspeed);
177
178         }
179         else
180                 vehicle_aimturret(vehic, _ct, gun, "fire",
181                                                   autocvar_g_vehicle_bumblebee_cannon_pitchlimit_down * -1, autocvar_g_vehicle_bumblebee_cannon_pitchlimit_up,
182                                                   _out * -1,  _in,  autocvar_g_vehicle_bumblebee_cannon_turnspeed);
183
184         if(gunner.BUTTON_ATCK)
185                 if(time > gun.attack_finished_single)
186                         if(gun.vehicle_energy >= autocvar_g_vehicle_bumblebee_cannon_cost)
187                         {
188                                 gun.vehicle_energy -= autocvar_g_vehicle_bumblebee_cannon_cost;
189                                 bumb_fire_cannon(gun, "fire", gunner);
190                                 gun.delay = time;
191                                 gun.attack_finished_single = time + autocvar_g_vehicle_bumblebee_cannon_refire;
192                         }
193
194         VEHICLE_UPDATE_PLAYER(gunner, health, bumblebee);
195
196         if(vehic.vehicle_flags & VHF_HASSHIELD)
197                 VEHICLE_UPDATE_PLAYER(gunner, shield, bumblebee);
198
199         ad = gettaginfo(gun, gettagindex(gun, "fire"));
200         traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, gun);
201
202         UpdateAuxiliaryXhair(gunner, trace_endpos, ('1 0 0' * gunner.vehicle_reload1) + ('0 1 0' *(1 - gunner.vehicle_reload1)), 0);
203
204         if(vehic.owner)
205                 UpdateAuxiliaryXhair(vehic.owner, trace_endpos, ('1 0 0' * gunner.vehicle_reload1) + ('0 1 0' *(1 - gunner.vehicle_reload1)), ((gunner == vehic.gunner1) ? 1 : 2));
206
207         vehic.solid = SOLID_BBOX;
208         gunner.BUTTON_ATCK = gunner.BUTTON_ATCK2 = gunner.BUTTON_CROUCH = 0;
209         gunner.vehicle_energy = (gun.vehicle_energy / autocvar_g_vehicle_bumblebee_cannon_ammo) * 100;
210
211         self = gunner;
212         return 1;
213 }
214
215 void bumb_gunner_exit(float _exitflag)
216 {
217
218
219         if(clienttype(self) == CLIENTTYPE_REAL)
220         {
221                 msg_entity = self;
222                 WriteByte(MSG_ONE, SVC_SETVIEWPORT);
223                 WriteEntity(MSG_ONE, self);
224
225                 WriteByte(MSG_ONE, SVC_SETVIEWANGLES);
226                 WriteAngle(MSG_ONE, 0);
227                 WriteAngle(MSG_ONE, self.vehicle.angles_y);
228                 WriteAngle(MSG_ONE, 0);
229         }
230         
231         CSQCVehicleSetup(self, HUD_NORMAL);
232         setsize(self, PL_MIN, PL_MAX);
233
234         self.takedamage     = DAMAGE_AIM;
235         self.solid          = SOLID_SLIDEBOX;
236         self.movetype       = MOVETYPE_WALK;
237         self.effects        &~= EF_NODRAW;
238         self.alpha          = 1;
239         self.PlayerPhysplug = func_null;
240         self.view_ofs       = PL_VIEW_OFS;
241         self.event_damage   = PlayerDamage;
242         self.hud            = HUD_NORMAL;
243         self.switchweapon   = self.vehicle.switchweapon;
244
245     vh_player = self;
246     vh_vehicle = self.vehicle;
247     MUTATOR_CALLHOOK(VehicleExit);
248     self = vh_player;
249     self.vehicle = vh_vehicle;
250
251         self.vehicle.vehicle_hudmodel.viewmodelforclient = self.vehicle;
252
253         fixedmakevectors(self.vehicle.owner.angles);
254
255         if(self == self.vehicle.owner.gunner1)
256         {
257                 self.vehicle.owner.gunner1 = world;             
258         }
259         else if(self == self.vehicle.owner.gunner2)
260         {
261                 self.vehicle.owner.gunner2 = world;     
262                 v_right *= -1;
263         }       
264         else
265                 dprint("^1self != gunner1 or gunner2, this is a BIG PROBLEM, tell tZork this happend.\n");
266                 
267         vector spot = self.vehicle.owner.origin + + v_up * 128 + v_right * 300;
268         spot = vehicles_findgoodexit(spot);
269         //setorigin(self , spot);
270
271         self.velocity = 0.75 * self.vehicle.owner.velocity + normalize(spot - self.vehicle.owner.origin) * 200;
272         self.velocity_z += 10;
273
274         self.vehicle.phase = time + 5;
275         self.vehicle        = world;
276 }
277
278 float bumb_gunner_enter()
279 {
280         RemoveGrapplingHook(other);
281         entity _gun, _gunner;
282         if(!self.gunner1)
283         {
284                 _gun = self.gun1;
285                 _gunner = self.gunner1;
286                 self.gunner1 = other;
287         }
288         else if(!self.gunner2)
289         {
290                 _gun = self.gun2;
291                 _gunner = self.gunner2;
292                 self.gunner2 = other;
293         }
294         else
295         {
296                 dprint("^1ERROR:^7Tried to enter a fully occupied vehicle!\n");
297                 return FALSE;
298         }
299
300         _gunner            = other;
301         _gunner.vehicle    = _gun;
302         _gun.switchweapon  = other.switchweapon;
303         _gun.vehicle_exit  = bumb_gunner_exit;
304
305         other.angles            = self.angles;
306         other.takedamage        = DAMAGE_NO;
307         other.solid             = SOLID_NOT;
308         other.movetype          = MOVETYPE_NOCLIP;
309         other.alpha             = -1;
310         other.event_damage      = func_null;
311         other.view_ofs          = '0 0 0';
312         other.hud               = _gun.hud;
313         other.PlayerPhysplug    = _gun.PlayerPhysplug;
314         other.vehicle_ammo1     = self.vehicle_ammo1;
315         other.vehicle_ammo2     = self.vehicle_ammo2;
316         other.vehicle_reload1   = self.vehicle_reload1;
317         other.vehicle_reload2   = self.vehicle_reload2;
318         other.vehicle_energy    = self.vehicle_energy;
319         other.PlayerPhysplug    = bumb_gunner_frame;
320         other.flags             &~= FL_ONGROUND;
321
322         msg_entity = other;
323         WriteByte(MSG_ONE, SVC_SETVIEWPORT);
324         WriteEntity(MSG_ONE, _gun.vehicle_viewport);
325         WriteByte(MSG_ONE, SVC_SETVIEWANGLES);
326         WriteAngle(MSG_ONE, _gun.angles_x + self.angles_x);    // tilt
327         WriteAngle(MSG_ONE, _gun.angles_y + self.angles_y);    // yaw
328         WriteAngle(MSG_ONE, 0);                             // roll
329         _gun.vehicle_hudmodel.viewmodelforclient = other;
330
331         CSQCVehicleSetup(other, other.hud);
332         
333     vh_player = other;
334     vh_vehicle = _gun;
335     MUTATOR_CALLHOOK(VehicleEnter);
336     other = vh_player;
337     _gun = vh_vehicle;
338
339         return TRUE;
340 }
341
342 float vehicles_valid_pilot()
343 {
344         if(other.classname != "player")
345                 return FALSE;
346
347         if(other.deadflag != DEAD_NO)
348                 return FALSE;
349
350         if(other.vehicle != world)
351                 return FALSE;
352
353         if(clienttype(other) != CLIENTTYPE_REAL)
354                 if(!autocvar_g_vehicles_allow_bots)
355                         return FALSE;
356
357         if(teamplay && other.team != self.team)
358                 return FALSE;
359
360         return TRUE;
361 }
362
363 void bumb_touch()
364 {
365
366         if(self.gunner1 != world && self.gunner2 != world)
367         {
368                 vehicles_touch();
369                 return;
370         }
371
372         if(vehicles_valid_pilot())
373         {
374                 if(self.gun1.phase <= time)
375                         if(bumb_gunner_enter())
376                                 return;
377
378                 if(self.gun2.phase <= time)
379                         if(bumb_gunner_enter())
380                                 return;
381         }
382
383         vehicles_touch();
384 }
385
386 void bumb_regen()
387 {
388         if(self.gun1.delay + autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause < time)
389                 self.gun1.vehicle_energy = min(autocvar_g_vehicle_bumblebee_cannon_ammo,
390                                                                            self.gun1.vehicle_energy + autocvar_g_vehicle_bumblebee_cannon_ammo_regen * frametime);
391
392         if(self.gun2.delay + autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause < time)
393                 self.gun2.vehicle_energy = min(autocvar_g_vehicle_bumblebee_cannon_ammo,
394                                                                            self.gun2.vehicle_energy + autocvar_g_vehicle_bumblebee_cannon_ammo_regen * frametime);
395
396         if(self.vehicle_flags  & VHF_SHIELDREGEN)
397                 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);
398
399         if(self.vehicle_flags  & VHF_HEALTHREGEN)
400                 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);
401
402         if(self.vehicle_flags  & VHF_ENERGYREGEN)
403                 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);
404
405 }
406
407 float bumb_pilot_frame()
408 {
409         entity pilot, vehic;
410         vector newvel;
411
412         pilot = self;
413         vehic = self.vehicle;
414         self   = vehic;
415
416
417         if(vehic.deadflag != DEAD_NO)
418         {
419                 self = pilot;
420                 pilot.BUTTON_ATCK = pilot.BUTTON_ATCK2 = 0;
421                 return 1;
422         }
423
424         bumb_regen();
425
426         crosshair_trace(pilot);
427
428         vector vang;
429         float ftmp;
430
431         vang = vehic.angles;
432         newvel = vectoangles(normalize(trace_endpos - self.origin + '0 0 32'));
433         vang_x *= -1;
434         newvel_x *= -1;
435         if(newvel_x > 180)  newvel_x -= 360;
436         if(newvel_x < -180) newvel_x += 360;
437         if(newvel_y > 180)  newvel_y -= 360;
438         if(newvel_y < -180) newvel_y += 360;
439
440         ftmp = shortangle_f(pilot.v_angle_y - vang_y, vang_y);
441         if(ftmp > 180)  ftmp -= 360;
442         if(ftmp < -180) ftmp += 360;
443         vehic.avelocity_y = bound(-autocvar_g_vehicle_bumblebee_turnspeed, ftmp + vehic.avelocity_y * 0.9, autocvar_g_vehicle_bumblebee_turnspeed);
444
445         // Pitch
446         ftmp = 0;
447         if(pilot.movement_x > 0 && vang_x < autocvar_g_vehicle_bumblebee_pitchlimit) 
448                 ftmp = 4;
449         else if(pilot.movement_x < 0 && vang_x > -autocvar_g_vehicle_bumblebee_pitchlimit) 
450                 ftmp = -8;
451
452         newvel_x = bound(-autocvar_g_vehicle_bumblebee_pitchlimit, newvel_x , autocvar_g_vehicle_bumblebee_pitchlimit);
453         ftmp = vang_x - bound(-autocvar_g_vehicle_bumblebee_pitchlimit, newvel_x + ftmp, autocvar_g_vehicle_bumblebee_pitchlimit);
454         vehic.avelocity_x = bound(-autocvar_g_vehicle_bumblebee_pitchspeed, ftmp + vehic.avelocity_x * 0.9, autocvar_g_vehicle_bumblebee_pitchspeed);
455
456         vehic.angles_x = anglemods(vehic.angles_x);
457         vehic.angles_y = anglemods(vehic.angles_y);
458         vehic.angles_z = anglemods(vehic.angles_z);
459
460         makevectors('0 1 0' * vehic.angles_y);
461         newvel = vehic.velocity * -autocvar_g_vehicle_bumblebee_friction;
462
463         if(pilot.movement_x != 0)
464         {
465                 if(pilot.movement_x > 0)
466                         newvel += v_forward  * autocvar_g_vehicle_bumblebee_speed_forward;
467                 else if(pilot.movement_x < 0)
468                         newvel -= v_forward  * autocvar_g_vehicle_bumblebee_speed_forward;
469         }
470
471         if(pilot.movement_y != 0)
472         {
473                 if(pilot.movement_y < 0)
474                         newvel -= v_right * autocvar_g_vehicle_bumblebee_speed_strafe;
475                 else if(pilot.movement_y > 0)
476                         newvel += v_right * autocvar_g_vehicle_bumblebee_speed_strafe;
477                 ftmp = newvel * v_right;
478                 ftmp *= frametime * 0.1;
479                 vehic.angles_z = bound(-15, vehic.angles_z + ftmp, 15);
480         }
481         else
482         {
483                 vehic.angles_z *= 0.95;
484                 if(vehic.angles_z >= -1 && vehic.angles_z <= -1)
485                         vehic.angles_z = 0;
486         }
487
488         if(pilot.BUTTON_CROUCH)
489                 newvel -=   v_up * autocvar_g_vehicle_bumblebee_speed_down;
490         else if(pilot.BUTTON_JUMP)
491                 newvel +=  v_up * autocvar_g_vehicle_bumblebee_speed_up;
492
493         vehic.velocity  += newvel * frametime;
494         pilot.velocity = pilot.movement  = vehic.velocity;
495         
496
497         if(autocvar_g_vehicle_bumblebee_healgun_locktime)
498         {               
499                 if(vehic.tur_head.lock_time < time || vehic.tur_head.enemy.deadflag)
500                         vehic.tur_head.enemy = world;
501
502                 if(trace_ent)
503                 if(trace_ent.movetype)
504                 if(trace_ent.takedamage)
505                 if(!trace_ent.deadflag)
506                 {
507                         if(teamplay)
508                         {
509                                 if(trace_ent.team == pilot.team)
510                                 {
511                                         vehic.tur_head.enemy = trace_ent;
512                                         vehic.tur_head.lock_time = time + autocvar_g_vehicle_bumblebee_healgun_locktime;
513                                 }
514                         }
515                         else
516                         {            
517                                 vehic.tur_head.enemy = trace_ent;
518                                 vehic.tur_head.lock_time = time + autocvar_g_vehicle_bumblebee_healgun_locktime;
519                         }
520                 }
521                         
522                 if(vehic.tur_head.enemy)
523                 {
524                         trace_endpos = real_origin(vehic.tur_head.enemy);                       
525                         UpdateAuxiliaryXhair(pilot, trace_endpos, '0 0.75 0', 0);               
526                 }
527         }
528         
529         vang = vehicle_aimturret(vehic, trace_endpos, self.gun3, "fire",
530                                           autocvar_g_vehicle_bumblebee_raygun_pitchlimit_down * -1,  autocvar_g_vehicle_bumblebee_raygun_pitchlimit_up,
531                                           autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides * -1,  autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides,  autocvar_g_vehicle_bumblebee_raygun_turnspeed);
532
533         if((pilot.BUTTON_ATCK || pilot.BUTTON_ATCK2) && (vehic.vehicle_energy > autocvar_g_vehicle_bumblebee_raygun_dps * sys_frametime || autocvar_g_vehicle_bumblebee_raygun == 0))
534         {
535                 vehic.gun3.enemy.realowner = pilot;
536                 vehic.gun3.enemy.effects &~= EF_NODRAW;
537                 
538                 vehic.gun3.enemy.hook_start = gettaginfo(vehic.gun3, gettagindex(vehic.gun3, "fire"));
539                 vehic.gun3.enemy.SendFlags |= BRG_START;
540                 
541                 traceline(vehic.gun3.enemy.hook_start, vehic.gun3.enemy.hook_start + v_forward * autocvar_g_vehicle_bumblebee_raygun_range, MOVE_NORMAL, vehic);
542                 
543                 if(trace_ent)
544                 {
545                         if(autocvar_g_vehicle_bumblebee_raygun)
546                         {
547                                 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);
548                                 vehic.vehicle_energy -= autocvar_g_vehicle_bumblebee_raygun_aps * sys_frametime;
549                         }
550                         else
551                         {
552                                 if(trace_ent.deadflag == DEAD_NO)
553                                         if((teamplay && trace_ent.team == pilot.team) || !teamplay)
554                                         {
555
556                                                 if(trace_ent.vehicle_flags & VHF_ISVEHICLE)
557                                                 {
558                                                         if(autocvar_g_vehicle_bumblebee_healgun_sps && trace_ent.vehicle_health <= trace_ent.tur_health)
559                                                                 trace_ent.vehicle_shield = min(trace_ent.vehicle_shield + autocvar_g_vehicle_bumblebee_healgun_sps * frametime, trace_ent.tur_head.tur_health);
560
561                                                         if(autocvar_g_vehicle_bumblebee_healgun_hps)
562                                                                 trace_ent.vehicle_health = min(trace_ent.vehicle_health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, trace_ent.tur_health);
563                                                 }
564                                                 else if(trace_ent.flags & FL_CLIENT)
565                                                 {
566                                                         if(trace_ent.health <= autocvar_g_vehicle_bumblebee_healgun_hmax && autocvar_g_vehicle_bumblebee_healgun_hps)
567                                                                 trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, autocvar_g_vehicle_bumblebee_healgun_hmax);
568
569                                                         if(trace_ent.armorvalue <= autocvar_g_vehicle_bumblebee_healgun_amax && autocvar_g_vehicle_bumblebee_healgun_aps)
570                                                                 trace_ent.armorvalue = min(trace_ent.armorvalue + autocvar_g_vehicle_bumblebee_healgun_aps * frametime, autocvar_g_vehicle_bumblebee_healgun_amax);
571
572                                                         trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, autocvar_g_vehicle_bumblebee_healgun_hmax);
573                                                 }
574                                                 else if(trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
575                                                 {
576                                                         if(trace_ent.health  <= trace_ent.tur_health && autocvar_g_vehicle_bumblebee_healgun_hps)
577                                                                 trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, trace_ent.tur_health);
578                                                         //else ..hmmm what? ammo?
579
580                                                         trace_ent.SendFlags |= TNSF_STATUS;
581                                                 }
582                                         }
583                         }
584                 }
585                 
586                 vehic.gun3.enemy.hook_end = trace_endpos;
587                 setorigin(vehic.gun3.enemy, trace_endpos);
588                 vehic.gun3.enemy.SendFlags |= BRG_END;
589                 
590                 vehic.wait = time + 1;
591         }
592         else
593                 vehic.gun3.enemy.effects |= EF_NODRAW;
594         /*{
595                 if(vehic.gun3.enemy)
596                         remove(vehic.gun3.enemy);
597
598                 vehic.gun3.enemy = world;
599         }
600         */
601         
602         VEHICLE_UPDATE_PLAYER(pilot, health, bumblebee);
603         VEHICLE_UPDATE_PLAYER(pilot, energy, bumblebee);
604
605         pilot.vehicle_ammo1 = (vehic.gun1.vehicle_energy / autocvar_g_vehicle_bumblebee_cannon_ammo) * 100;
606         pilot.vehicle_ammo2 = (vehic.gun2.vehicle_energy / autocvar_g_vehicle_bumblebee_cannon_ammo) * 100;
607
608         if(vehic.vehicle_flags & VHF_HASSHIELD)
609                 VEHICLE_UPDATE_PLAYER(pilot, shield, bumblebee);
610                 
611         vehic.angles_x *= -1;
612         makevectors(vehic.angles);
613         vehic.angles_x *= -1;
614         setorigin(pilot, vehic.origin + v_up * 48 + v_forward * 160);
615
616         pilot.BUTTON_ATCK = pilot.BUTTON_ATCK2 = pilot.BUTTON_CROUCH = 0;
617         self = pilot;
618
619         return 1;
620 }
621
622 void bumb_think()
623 {
624         self.movetype = MOVETYPE_TOSS;
625                 
626                 //self.velocity = self.velocity * 0.5;
627         self.angles_z *= 0.8;
628         self.angles_x *= 0.8;
629         
630         self.nextthink = time + 0.05;
631         
632         if(!self.owner)
633         {
634                 entity oldself = self;          
635                 if(self.gunner1)
636                 {
637                         self = self.gunner1;
638                         oldself.gun1.vehicle_exit(VHEF_EJECT);
639                         entity oldother = other;
640                         other = self;
641                         self = oldself;
642                         self.phase = 0;
643                         self.touch();
644                         other = oldother;
645                         return;
646                 }
647                 
648                 if(self.gunner2)
649                 {
650                         self = self.gunner2;
651                         oldself.gun2.vehicle_exit(VHEF_EJECT);
652                         entity oldother = other;
653                         other = self;
654                         self = oldself;
655                         self.phase = 0;
656                         self.touch();
657                         other = oldother;
658                         return;
659                 }               
660         }
661         
662 }
663
664 void bumb_enter()
665 {
666         self.touch = bumb_touch;
667         self.nextthink = 0;
668         self.movetype = MOVETYPE_BOUNCEMISSILE;
669         //setattachment(self.owner, self.vehicle_viewport, "");
670 }
671
672 void bumb_exit(float eject)
673 {
674         self.touch = vehicles_touch;
675         self.think = bumb_think;
676         self.nextthink = time;
677         
678         if(!self.owner)
679                 return;
680         
681         fixedmakevectors(self.angles);
682         vector spot;
683         if(vlen(self.velocity) > autocvar_g_vehicle_bumblebee_speed_forward * 0.5)              
684                 spot = self.origin + v_up * 128 + v_forward * 200;
685         else
686                 spot = self.origin + v_up * 128 - v_forward * 200;
687         
688         spot = vehicles_findgoodexit(spot);
689         
690
691         self.owner.velocity = 0.75 * self.vehicle.velocity + normalize(spot - self.vehicle.origin) * 200;
692         self.owner.velocity_z += 10;
693         setorigin(self.owner, spot);
694
695         /*if(eject)
696         {
697             spot = self.origin + v_forward * 100 + '0 0 64';
698             spot = vehicles_findgoodexit(spot);
699             //setorigin(self.owner , spot);
700             self.owner.velocity = (v_up + v_forward * 0.25) * 250;
701             self.owner.oldvelocity = self.owner.velocity;
702         }
703         else
704         {
705                 if(vlen(self.velocity) > autocvar_g_vehicle_bumblebee_speed_forward * 0.5)              
706                 {
707                         if(vlen(self.velocity) > autocvar_sv_maxairspeed)
708                                 self.owner.velocity = normalize(self.velocity) * autocvar_sv_maxairspeed;
709                         else
710                                 self.owner.velocity = self.velocity + v_forward * 100;
711                         
712                         self.owner.velocity_z += 200;
713                         spot = self.origin + v_forward * 128 + '0 0 32';
714                         spot = vehicles_findgoodexit(spot);
715                 }
716                 else
717                 {
718                         self.owner.velocity = self.velocity * 0.5;
719                         self.owner.velocity_z += 10;
720                         spot = self.origin - v_forward * 300 + '0 0 32';
721                         spot = vehicles_findgoodexit(spot);
722                 }
723             self.owner.oldvelocity = self.owner.velocity;
724             //setorigin(self.owner , spot);
725         }
726         */
727         
728         antilag_clear(self.owner);
729     self.owner = world;
730 }
731
732 void bumb_blowup()
733 {
734         RadiusDamage(self, self.enemy, autocvar_g_vehicle_bumblebee_blowup_coredamage,
735                                  autocvar_g_vehicle_bumblebee_blowup_edgedamage,
736                                  autocvar_g_vehicle_bumblebee_blowup_radius, self,
737                                  autocvar_g_vehicle_bumblebee_blowup_forceintensity,
738                                  DEATH_VH_BUMB_DEATH, world);
739
740         sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
741         pointparticles(particleeffectnum("explosion_large"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
742         
743         if(self.owner.deadflag == DEAD_DYING)
744                 self.owner.deadflag = DEAD_DEAD;
745         
746         remove(self);
747 }
748
749 void bumb_diethink()
750 {
751         if(time >= self.wait)
752                 self.think = bumb_blowup;
753
754         if(random() < 0.1)
755         {
756                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
757                 pointparticles(particleeffectnum("explosion_small"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
758         }
759
760         self.nextthink = time + 0.1;
761 }
762
763 void bumb_die()
764 {
765         entity oldself = self;
766         
767         // Hide beam
768         if(self.gun3.enemy || !wasfreed(self.gun3.enemy))
769                 self.gun3.enemy.effects |= EF_NODRAW;
770         
771         if(self.gunner1)
772         {
773                 self = self.gunner1;
774                 oldself.gun1.vehicle_exit(VHEF_EJECT);
775                 self = oldself;
776         }
777
778         if(self.gunner2)
779         {
780                 self = self.gunner2;
781                 oldself.gun2.vehicle_exit(VHEF_EJECT);
782                 self = oldself;
783         }
784
785         self.vehicle_exit(VHEF_EJECT);
786
787         fixedmakevectors(self.angles);
788         vehicle_tossgib(self.gun1, self.velocity + v_right * 300 + v_up * 100 + randomvec() * 200, "cannon_right", rint(random()), rint(random()), 6, randomvec() * 200);
789         vehicle_tossgib(self.gun2, self.velocity + v_right * -300 + v_up * 100 + randomvec() * 200, "cannon_left", rint(random()), rint(random()), 6, randomvec() * 200);
790         vehicle_tossgib(self.gun3, self.velocity + v_forward * 300 + v_up * -100 + randomvec() * 200, "raygun", rint(random()), rint(random()), 6, randomvec() * 300);
791
792         entity _body = vehicle_tossgib(self, self.velocity + randomvec() * 200, "", rint(random()), rint(random()), 6, randomvec() * 100);
793
794         if(random() > 0.5)
795                 _body.touch = bumb_blowup;
796         else
797                 _body.touch = func_null;
798                 
799         _body.think = bumb_diethink;
800         _body.nextthink = time;
801         _body.wait = time + 2 + (random() * 8);
802         _body.owner = self;
803         _body.enemy = self.enemy;
804         
805         pointparticles(particleeffectnum("explosion_medium"), findbetterlocation(self.origin, 16), '0 0 0', 1);
806         
807         self.health                     = 0;
808         self.event_damage       = func_null;
809         self.solid                      = SOLID_CORPSE;
810         self.takedamage         = DAMAGE_NO;
811         self.deadflag           = DEAD_DYING;
812         self.movetype           = MOVETYPE_NONE;
813         self.effects            = EF_NODRAW;
814         self.colormod           = '0 0 0';
815         self.avelocity          = '0 0 0';
816         self.velocity           = '0 0 0';
817         self.touch                      = func_null;
818         self.nextthink          = 0;
819
820         setorigin(self, self.pos1);
821
822 }
823
824 void bumb_impact()
825 {
826     if(autocvar_g_vehicle_bumblebee_bouncepain_x)
827         vehilces_impact(autocvar_g_vehicle_bumblebee_bouncepain_x, 
828                                                 autocvar_g_vehicle_bumblebee_bouncepain_y, 
829                                                 autocvar_g_vehicle_bumblebee_bouncepain_z);
830 }
831
832 void bumb_spawn(float _f)
833 {
834         /*
835         float i;
836         for(i=1; gettaginfo(self.gun1, i), gettaginfo_name; ++i)
837         {
838
839             dprint(" ------- ^1gettaginfo_name^2(",ftos(i),") ^3=", gettaginfo_name, "\n");
840         }
841         */
842         if(!self.gun1)
843         {
844                 // for some reason, autosizing of the shiled entity refuses to work for this one so set it up in advance.
845                 self.vehicle_shieldent = spawn();
846                 self.vehicle_shieldent.effects = EF_LOWPRECISION;
847                 setmodel(self.vehicle_shieldent, "models/vhshield.md3");
848                 setattachment(self.vehicle_shieldent, self, "");
849                 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
850                 self.vehicle_shieldent.scale       = 512 / vlen(self.maxs - self.mins);
851                 self.vehicle_shieldent.think       = shieldhit_think;
852                 self.vehicle_shieldent.alpha = -1;
853                 self.vehicle_shieldent.effects = EF_LOWPRECISION | EF_NODRAW;
854
855                 self.gun1 = spawn();
856                 self.gun2 = spawn();
857                 self.gun3 = spawn();
858
859                 self.vehicle_flags |= VHF_MULTISLOT;
860
861                 self.gun1.owner = self;
862                 self.gun2.owner = self;
863                 self.gun3.owner = self;
864
865                 setmodel(self.gun1, "models/vehicles/bumblebee_plasma_right.dpm");
866                 setmodel(self.gun2, "models/vehicles/bumblebee_plasma_left.dpm");
867                 setmodel(self.gun3, "models/vehicles/bumblebee_ray.dpm");
868
869                 setattachment(self.gun1, self, "cannon_right");
870                 setattachment(self.gun2, self, "cannon_left");
871
872                 // Angled bones are no fun, messes up gun-aim; so work arround it.
873                 self.gun3.pos1 = self.angles;
874                 self.angles = '0 0 0';
875                 vector ofs = gettaginfo(self, gettagindex(self, "raygun"));
876                 ofs -= self.origin;
877                 setattachment(self.gun3, self, "");
878                 setorigin(self.gun3, ofs);
879                 self.angles = self.gun3.pos1;
880
881                 vehicle_addplayerslot(self, self.gun1, HUD_BUMBLEBEE_GUN, "models/vehicles/wakizashi_cockpit.dpm", bumb_gunner_frame, bumb_gunner_exit);
882                 vehicle_addplayerslot(self, self.gun2, HUD_BUMBLEBEE_GUN, "models/vehicles/wakizashi_cockpit.dpm", bumb_gunner_frame, bumb_gunner_exit);
883
884                 setorigin(self.vehicle_hudmodel, '50 0 -5');    // Move cockpit forward - down.
885                 setorigin(self.vehicle_viewport, '5 0 2');    // Move camera forward up
886
887                 //fixme-model-bones
888                 setorigin(self.gun1.vehicle_hudmodel, '90 -27 -23');
889                 setorigin(self.gun1.vehicle_viewport, '-85 0 50');
890                 //fixme-model-bones
891                 setorigin(self.gun2.vehicle_hudmodel, '90 27 -23');
892                 setorigin(self.gun2.vehicle_viewport, '-85 0 50');
893
894                 self.scale = 1.5;
895                 
896                 // Raygun beam
897                 if(self.gun3.enemy == world)
898                 {                       
899                         self.gun3.enemy = spawn();
900                         Net_LinkEntity(self.gun3.enemy, TRUE, 0, bumble_raygun_send);
901                         self.gun3.enemy.SendFlags = BRG_SETUP;                  
902                         self.gun3.enemy.cnt = autocvar_g_vehicle_bumblebee_raygun;                      
903                         self.gun3.enemy.effects = EF_NODRAW | EF_LOWPRECISION;
904                 }
905         }
906
907         self.vehicle_health = autocvar_g_vehicle_bumblebee_health;
908         self.vehicle_shield = autocvar_g_vehicle_bumblebee_shield;
909         self.solid          = SOLID_BBOX;
910         //self.movetype         = MOVETYPE_BOUNCEMISSILE;
911         self.movetype           = MOVETYPE_TOSS;
912         self.vehicle_impact = bumb_impact;
913         self.damageforcescale = 0.025;
914         
915         setorigin(self, self.origin + '0 0 25');
916 }
917
918 void spawnfunc_vehicle_bumblebee()
919 {
920         if(!autocvar_g_vehicle_bumblebee)
921         {
922                 remove(self);
923                 return;
924         }
925
926         precache_model("models/vehicles/bumblebee_body.dpm");
927         precache_model("models/vehicles/bumblebee_plasma_left.dpm");
928         precache_model("models/vehicles/bumblebee_plasma_right.dpm");
929         precache_model("models/vehicles/bumblebee_ray.dpm");
930         precache_model("models/vehicles/wakizashi_cockpit.dpm");
931         precache_model("models/vehicles/spiderbot_cockpit.dpm");
932         precache_model("models/vehicles/raptor_cockpit.dpm");
933
934         if(autocvar_g_vehicle_bumblebee_energy)
935                 if(autocvar_g_vehicle_bumblebee_energy_regen)
936                         self.vehicle_flags |= VHF_ENERGYREGEN;
937
938         if(autocvar_g_vehicle_bumblebee_shield)
939                 self.vehicle_flags |= VHF_HASSHIELD;
940
941         if(autocvar_g_vehicle_bumblebee_shield_regen)
942                 self.vehicle_flags |= VHF_SHIELDREGEN;
943
944         if(autocvar_g_vehicle_bumblebee_health_regen)
945                 self.vehicle_flags |= VHF_HEALTHREGEN;
946
947         if not(vehicle_initialize(
948                            "Bumblebee", "models/vehicles/bumblebee_body.dpm",
949                            "", "models/vehicles/spiderbot_cockpit.dpm", "", "", "tag_viewport",
950                            HUD_BUMBLEBEE, BUMB_MIN, BUMB_MAX, FALSE,
951                            bumb_spawn, autocvar_g_vehicle_bumblebee_respawntime,
952                            bumb_pilot_frame, bumb_enter, bumb_exit,
953                            bumb_die, bumb_think, FALSE, autocvar_g_vehicle_bumblebee_health, autocvar_g_vehicle_bumblebee_shield))
954         {
955                 remove(self);
956                 return;
957         }
958 }
959
960 float bumble_raygun_send(entity to, float sf)
961 {
962         WriteByte(MSG_ENTITY, ENT_CLIENT_BUMBLE_RAYGUN);
963
964         WriteByte(MSG_ENTITY, sf);
965         if(sf & BRG_SETUP)
966         {
967                 WriteByte(MSG_ENTITY, num_for_edict(self.realowner));
968                 WriteByte(MSG_ENTITY, self.realowner.team);
969                 WriteByte(MSG_ENTITY, self.cnt);
970         }
971
972         if(sf & BRG_START)
973         {
974                 WriteCoord(MSG_ENTITY, self.hook_start_x);
975                 WriteCoord(MSG_ENTITY, self.hook_start_y);
976                 WriteCoord(MSG_ENTITY, self.hook_start_z);
977         }
978
979         if(sf & BRG_END)
980         {
981                 WriteCoord(MSG_ENTITY, self.hook_end_x);
982                 WriteCoord(MSG_ENTITY, self.hook_end_y);
983                 WriteCoord(MSG_ENTITY, self.hook_end_z);
984         }
985
986         return TRUE;
987 }
988 #endif // SVQC
989
990 #ifdef CSQC
991 /*
992 .vector raygun_l1
993 .vector raygun_l2;
994 .vector raygun_l3;
995 */
996
997 void bumble_raygun_draw()
998 {
999         float _len;
1000         vector _dir;
1001         vector _vtmp1, _vtmp2;
1002
1003         _len = vlen(self.origin - self.move_origin);
1004         _dir = normalize(self.move_origin - self.origin);
1005         
1006         if(self.total_damages < time)
1007         {
1008                 boxparticles(self.traileffect, self, self.origin, self.origin + _dir * -64, _dir * -_len , _dir * -_len, 1, PARTICLES_USEALPHA);
1009                 boxparticles(self.lip, self, self.move_origin, self.move_origin + _dir * -64, _dir * -200 , _dir * -200, 1, PARTICLES_USEALPHA);
1010                 self.total_damages = time + 0.1;
1011         }
1012
1013         float i, df, sz, al;
1014         for(i = -0.1; i < 0.2; i += 0.1)
1015         {
1016                 df = DRAWFLAG_NORMAL; //((random() < 0.5) ? DRAWFLAG_ADDITIVE : DRAWFLAG_SCREEN);
1017                 sz = 5 + random() * 5;
1018                 al = 0.25 + random() * 0.5;
1019                 _vtmp1 = self.origin + _dir * _len * (0.25 + i);
1020                 _vtmp1 += (randomvec() * (_len * 0.2) * (frametime * 2));       //self.raygun_l1;
1021                 Draw_CylindricLine(self.origin, _vtmp1, sz, "gfx/colors/white.tga", 1, 1, self.colormod, al, df, view_origin);
1022
1023                 _vtmp2 = self.origin + _dir * _len * (0.5 + i);
1024                 _vtmp2 += (randomvec() * (_len * 0.2) * (frametime * 5));       //self.raygun_l2;
1025                 Draw_CylindricLine(_vtmp1, _vtmp2, sz, "gfx/colors/white.tga", 1, 1, self.colormod, al, df, view_origin);
1026
1027                 _vtmp1 = self.origin + _dir * _len * (0.75 + i);
1028                 _vtmp1 += randomvec() * (_len * 0.2) * (frametime * 10);     //self.raygun_l3;
1029                 Draw_CylindricLine(_vtmp2, _vtmp1, sz, "gfx/colors/white.tga", 1, 1, self.colormod, al, df, view_origin);
1030
1031                 Draw_CylindricLine(_vtmp1, self.move_origin +  randomvec() * 32, sz, "gfx/colors/white.tga", 1, 1, self.colormod, al, df, view_origin);
1032         }
1033 }
1034
1035 void bumble_raygun_read(float bIsNew)
1036 {
1037         float sf = ReadByte();
1038
1039         if(sf & BRG_SETUP)
1040         {
1041                 self.cnt  = ReadByte();
1042                 self.team = ReadByte();
1043                 self.cnt  = ReadByte();
1044                 
1045                 if(self.cnt)
1046                         self.colormod = '1 0 0';
1047                 else
1048                         self.colormod = '0 1 0';
1049
1050                 self.traileffect = particleeffectnum("healray_muzzleflash");
1051                 self.lip = particleeffectnum("healray_impact");         
1052
1053                 self.draw = bumble_raygun_draw;
1054         }
1055         
1056         
1057         if(sf & BRG_START)
1058         {
1059                 self.origin_x = ReadCoord();
1060                 self.origin_y = ReadCoord();
1061                 self.origin_z = ReadCoord();
1062                 setorigin(self, self.origin);
1063         }
1064
1065         if(sf & BRG_END)
1066         {
1067                 self.move_origin_x = ReadCoord();
1068                 self.move_origin_y = ReadCoord();
1069                 self.move_origin_z = ReadCoord();
1070         }
1071 }
1072
1073 void bumblebee_draw()
1074 {
1075
1076 }
1077
1078 void bumblebee_draw2d()
1079 {
1080
1081 }
1082
1083 void bumblebee_read_extra()
1084 {
1085
1086 }
1087
1088 void vehicle_bumblebee_assemble()
1089 {
1090
1091 }
1092 #endif //CSQC