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