Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle / spiderbot.qc
1 #include "spiderbot.qh"
2
3 #ifdef IMPLEMENTATION
4
5 const int SBRM_FIRST = 1;
6 const int SBRM_VOLLY = 1;
7 const int SBRM_GUIDE = 2;
8 const int SBRM_ARTILLERY = 3;
9 const int SBRM_LAST = 3;
10
11 #ifdef SVQC
12 bool autocvar_g_vehicle_spiderbot = true;
13
14 float autocvar_g_vehicle_spiderbot_respawntime = 45;
15
16 float autocvar_g_vehicle_spiderbot_speed_stop = 50;
17 float autocvar_g_vehicle_spiderbot_speed_strafe = 400;
18 float autocvar_g_vehicle_spiderbot_speed_walk = 500;
19 float autocvar_g_vehicle_spiderbot_speed_run = 700;
20 float autocvar_g_vehicle_spiderbot_turnspeed = 90;
21 float autocvar_g_vehicle_spiderbot_turnspeed_strafe = 300;
22 float autocvar_g_vehicle_spiderbot_movement_inertia = 0.15;
23
24 float autocvar_g_vehicle_spiderbot_springlength = 150;
25 float autocvar_g_vehicle_spiderbot_springup = 20;
26 float autocvar_g_vehicle_spiderbot_springblend = 0.1;
27 float autocvar_g_vehicle_spiderbot_tiltlimit = 90;
28
29 float autocvar_g_vehicle_spiderbot_head_pitchlimit_down = -20;
30 float autocvar_g_vehicle_spiderbot_head_pitchlimit_up = 30;
31 float autocvar_g_vehicle_spiderbot_head_turnlimit = 90;
32 float autocvar_g_vehicle_spiderbot_head_turnspeed = 110;
33
34 int autocvar_g_vehicle_spiderbot_health = 800;
35 float autocvar_g_vehicle_spiderbot_health_regen = 10;
36 float autocvar_g_vehicle_spiderbot_health_regen_pause = 5;
37
38 int autocvar_g_vehicle_spiderbot_shield = 200;
39 float autocvar_g_vehicle_spiderbot_shield_regen = 25;
40 float autocvar_g_vehicle_spiderbot_shield_regen_pause = 0.35;
41
42 // 'minspeed_for_pain speedchange_to_pain_factor max_damage'
43 vector autocvar_g_vehicle_spiderbot_bouncepain = '0 0 0';
44
45 .float jump_delay;
46 bool spiderbot_frame(entity this, float dt)
47 {
48         entity vehic = this.vehicle;
49         return = true;
50
51         if(intermission_running)
52         {
53                 vehic.solid = SOLID_NOT;
54                 vehic.takedamage = DAMAGE_NO;
55                 set_movetype(vehic, MOVETYPE_NONE);
56                 return;
57         }
58
59         vehicles_frame(vehic, this);
60
61         PHYS_INPUT_BUTTON_ZOOM(this) = false;
62         PHYS_INPUT_BUTTON_CROUCH(this) = false;
63         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
64         {
65                 .entity weaponentity = weaponentities[slot];
66                 this.(weaponentity).m_switchweapon = WEP_Null;
67         }
68         this.vehicle_weapon2mode = vehic.vehicle_weapon2mode;
69
70
71 #if 1 // 0 to enable per-gun impact aux crosshairs
72         // Avarage gun impact point's -> aux cross
73         vector ad = gettaginfo(vehic.tur_head, gettagindex(vehic.tur_head, "tag_hardpoint01"));
74         vector vf = v_forward;
75         ad += gettaginfo(vehic.tur_head, gettagindex(vehic.tur_head, "tag_hardpoint02"));
76         vf += v_forward;
77         ad = ad * 0.5;
78         v_forward = vf * 0.5;
79         traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, vehic);
80         UpdateAuxiliaryXhair(this, trace_endpos, ('1 0 0' * this.vehicle_reload1) + ('0 1 0' * (1 - this.vehicle_reload1)), 0);
81 #else
82         vector ad = gettaginfo(vehic.gun1, gettagindex(vehic.gun1, "barrels"));
83         traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, vehic);
84         UpdateAuxiliaryXhair(this, trace_endpos, ('1 0 0' * this.vehicle_reload1) + ('0 1 0' * (1 - this.vehicle_reload1)), 0);
85         vector vf = ad;
86         ad = gettaginfo(vehic.gun2, gettagindex(vehic.gun2, "barrels"));
87         traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, vehic);
88         UpdateAuxiliaryXhair(this, trace_endpos, ('1 0 0' * this.vehicle_reload1) + ('0 1 0' * (1 - this.vehicle_reload1)), 1);
89         ad = 0.5 * (ad + vf);
90 #endif
91
92         crosshair_trace(this);
93         ad = vectoangles(normalize(trace_endpos - ad));
94         ad = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(vehic.angles), AnglesTransform_FromAngles(ad))) - vehic.tur_head.angles;
95         ad = AnglesTransform_Normalize(ad, true);
96         //UpdateAuxiliaryXhair(this, trace_endpos, ('1 0 0' * this.vehicle_reload2) + ('0 1 0' * (1 - this.vehicle_reload2)), 2);
97
98         // Rotate head
99         float ftmp = autocvar_g_vehicle_spiderbot_head_turnspeed * PHYS_INPUT_FRAMETIME;
100         ad_y = bound(-ftmp, ad_y, ftmp);
101         vehic.tur_head.angles_y = bound(autocvar_g_vehicle_spiderbot_head_turnlimit * -1, vehic.tur_head.angles_y + ad_y, autocvar_g_vehicle_spiderbot_head_turnlimit);
102
103         // Pitch head
104         ad_x = bound(ftmp * -1, ad_x, ftmp);
105         vehic.tur_head.angles_x = bound(autocvar_g_vehicle_spiderbot_head_pitchlimit_down, vehic.tur_head.angles_x + ad_x, autocvar_g_vehicle_spiderbot_head_pitchlimit_up);
106
107
108         //fixedmakevectors(vehic.angles);
109         makevectors(vehic.angles + '-2 0 0' * vehic.angles_x);
110
111         movelib_groundalign4point(vehic, autocvar_g_vehicle_spiderbot_springlength, autocvar_g_vehicle_spiderbot_springup, autocvar_g_vehicle_spiderbot_springblend, autocvar_g_vehicle_spiderbot_tiltlimit);
112
113         if(IS_ONGROUND(vehic))
114                 vehic.jump_delay = time; // reset now so movement can begin
115
116         //if(IS_ONGROUND(vehic))
117         {
118                 if(IS_ONGROUND(vehic))
119                 if(vehic.frame == 4 && vehic.tur_head.wait != 0)
120                 {
121                         sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_LAND, VOL_VEHICLEENGINE, ATTEN_NORM);
122                         vehic.frame = 5;
123                 }
124
125                 if (!PHYS_INPUT_BUTTON_JUMP(this))
126                         PHYS_INPUT_BUTTON_JUMP(vehic) = false;
127
128                 if((IS_ONGROUND(vehic)) && PHYS_INPUT_BUTTON_JUMP(this) && !PHYS_INPUT_BUTTON_JUMP(vehic) && vehic.tur_head.wait < time)
129                 {
130                         sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_JUMP, VOL_VEHICLEENGINE, ATTEN_NORM);
131                         //dprint("spiderbot_jump:", ftos(soundlength("vehicles/spiderbot_jump.wav")), "\n");
132                         vehic.delay = 0;
133
134                         vehic.tur_head.wait = time + 2;
135                         vehic.jump_delay = time + 2;
136                         PHYS_INPUT_BUTTON_JUMP(vehic) = true; // set spider's jump
137                         //PHYS_INPUT_BUTTON_JUMP(this) = false;
138
139                         vector movefix = '0 0 0';
140                         if(this.movement_x > 0) movefix_x = 1;
141                         if(this.movement_x < 0) movefix_x = -1;
142                         if(this.movement_y > 0) movefix_y = 1;
143                         if(this.movement_y < 0) movefix_y = -1;
144
145                         vector rt = movefix_y * v_right;
146                         vector sd = movefix_x * v_forward;
147                         if(movefix_y == 0 && movefix_x == 0)
148                                 sd = v_forward; // always do forward
149
150                         UNSET_ONGROUND(vehic);
151
152                         vehic.velocity = sd * 700 + rt * 600 + v_up * 600;
153                         vehic.frame = 4;
154                 }
155                 else if(time >= vehic.jump_delay)
156                 {
157                         if(!this.movement)
158                         {
159                                 if(IS_ONGROUND(vehic))
160                                 {
161                                         if(vehic.sound_nexttime < time || vehic.delay != 3)
162                                         {
163                                                 vehic.delay = 3;
164                                                 vehic.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_idle.wav");
165                                                 //dprint("spiderbot_idle:", ftos(soundlength("vehicles/spiderbot_idle.wav")), "\n");
166                                                 sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_IDLE, VOL_VEHICLEENGINE, ATTEN_NORM);
167                                         }
168                                         movelib_brake_simple(vehic, autocvar_g_vehicle_spiderbot_speed_stop);
169                                         vehic.frame = 5;
170                                 }
171                         }
172                         else
173                         {
174                                 // Turn Body
175                                 if(this.movement_x == 0 && this.movement_y != 0)
176                                         ftmp = autocvar_g_vehicle_spiderbot_turnspeed_strafe * PHYS_INPUT_FRAMETIME;
177                                 else
178                                         ftmp = autocvar_g_vehicle_spiderbot_turnspeed * PHYS_INPUT_FRAMETIME;
179
180                                 ftmp = bound(-ftmp, vehic.tur_head.angles_y, ftmp);
181                                 vehic.angles_y = anglemods(vehic.angles_y + ftmp);
182                                 vehic.tur_head.angles_y -= ftmp;
183
184                                 if(this.movement_x != 0)
185                                 {
186                                         if(this.movement_x > 0)
187                                         {
188                                                 this.movement_x = 1;
189                                                 if(IS_ONGROUND(vehic))
190                                                         vehic.frame = 0;
191                                         }
192                                         else if(this.movement_x < 0)
193                                         {
194                                                 this.movement_x = -1;
195                                                 if(IS_ONGROUND(vehic))
196                                                         vehic.frame = 1;
197                                         }
198                                         this.movement_y = 0;
199                                         float oldvelz = vehic.velocity_z;
200                                         movelib_move_simple(vehic, normalize(v_forward * this.movement_x),((PHYS_INPUT_BUTTON_JUMP(this)) ? autocvar_g_vehicle_spiderbot_speed_run : autocvar_g_vehicle_spiderbot_speed_walk),autocvar_g_vehicle_spiderbot_movement_inertia);
201                                         vehic.velocity_z = oldvelz;
202                                         float g = ((autocvar_sv_gameplayfix_gravityunaffectedbyticrate) ? 0.5 : 1);
203                                         if(vehic.velocity_z <= 20) // not while jumping
204                                                 vehic.velocity_z -= g * PHYS_INPUT_FRAMETIME * autocvar_sv_gravity;
205                                         if(IS_ONGROUND(vehic))
206                                         if(vehic.sound_nexttime < time || vehic.delay != 1)
207                                         {
208                                                 vehic.delay = 1;
209                                                 vehic.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_walk.wav");
210                                                 sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_WALK, VOL_VEHICLEENGINE, ATTEN_NORM);
211                                                 //dprint("spiderbot_walk:", ftos(soundlength("vehicles/spiderbot_walk.wav")), "\n");
212                                         }
213                                 }
214                                 else if(this.movement_y != 0)
215                                 {
216                                         if(this.movement_y < 0)
217                                         {
218                                                 this.movement_y = -1;
219                                                 if(IS_ONGROUND(vehic))
220                                                         vehic.frame = 2;
221                                         }
222                                         else if(this.movement_y > 0)
223                                         {
224                                                 this.movement_y = 1;
225                                                 if(IS_ONGROUND(vehic))
226                                                         vehic.frame = 3;
227                                         }
228
229                                         float oldvelz = vehic.velocity_z;
230                                         movelib_move_simple(vehic, normalize(v_right * this.movement_y),autocvar_g_vehicle_spiderbot_speed_strafe,autocvar_g_vehicle_spiderbot_movement_inertia);
231                                         vehic.velocity_z = oldvelz;
232                                         float g = ((autocvar_sv_gameplayfix_gravityunaffectedbyticrate) ? 0.5 : 1);
233                                         if(vehic.velocity_z <= 20) // not while jumping
234                                                 vehic.velocity_z -= g * PHYS_INPUT_FRAMETIME * autocvar_sv_gravity;
235                                         if(IS_ONGROUND(vehic))
236                                         if(vehic.sound_nexttime < time || vehic.delay != 2)
237                                         {
238                                                 vehic.delay = 2;
239                                                 vehic.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_strafe.wav");
240                                                 sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_STRAFE, VOL_VEHICLEENGINE, ATTEN_NORM);
241                                                 //dprint("spiderbot_strafe:", ftos(soundlength("vehicles/spiderbot_strafe.wav")), "\n");
242                                         }
243                                 }
244                         }
245                 }
246         }
247
248         vehic.angles_x = bound(-autocvar_g_vehicle_spiderbot_tiltlimit, vehic.angles_x, autocvar_g_vehicle_spiderbot_tiltlimit);
249         vehic.angles_z = bound(-autocvar_g_vehicle_spiderbot_tiltlimit, vehic.angles_z, autocvar_g_vehicle_spiderbot_tiltlimit);
250
251         if(!forbidWeaponUse(this))
252         if(PHYS_INPUT_BUTTON_ATCK(this))
253         {
254                 vehic.cnt = time;
255                 if(vehic.vehicle_ammo1 >= autocvar_g_vehicle_spiderbot_minigun_ammo_cost && vehic.tur_head.attack_finished_single[0] <= time)
256                 {
257                         entity gun;
258                         vector v;
259                         vehic.misc_bulletcounter += 1;
260
261                         gun = (vehic.misc_bulletcounter % 2) ? vehic.gun1 : vehic.gun2;
262
263                         v = gettaginfo(gun, gettagindex(gun, "barrels"));
264                         v_forward = normalize(v_forward);
265                         v += v_forward * 50;
266
267                         .entity weaponentity = weaponentities[0]; // TODO: unhardcode
268                         fireBullet(this, weaponentity, v, v_forward, autocvar_g_vehicle_spiderbot_minigun_spread, autocvar_g_vehicle_spiderbot_minigun_solidpenetration,
269                                 autocvar_g_vehicle_spiderbot_minigun_damage, autocvar_g_vehicle_spiderbot_minigun_force, DEATH_VH_SPID_MINIGUN.m_id, 0);
270
271                         sound (gun, CH_WEAPON_A, SND_UZI_FIRE, VOL_BASE, ATTEN_NORM);
272                         //trailparticles(this, _particleeffectnum("spiderbot_minigun_trail"), v, trace_endpos);
273                         Send_Effect(EFFECT_SPIDERBOT_MINIGUN_MUZZLEFLASH, v, v_forward * 2500, 1);
274
275                         vehic.vehicle_ammo1 -= autocvar_g_vehicle_spiderbot_minigun_ammo_cost;
276                         vehic.tur_head.attack_finished_single[0] = time + autocvar_g_vehicle_spiderbot_minigun_refire;
277                         this.vehicle_ammo1 = (vehic.vehicle_ammo1 / autocvar_g_vehicle_spiderbot_minigun_ammo_max) * 100;
278                         vehic.gun1.angles_z += 45;
279                         vehic.gun2.angles_z -= 45;
280                         if(vehic.gun1.angles_z >= 360)
281                         {
282                                 vehic.gun1.angles_z = 0;
283                                 vehic.gun2.angles_z = 0;
284                         }
285                 }
286         }
287         else
288                 vehicles_regen(vehic, vehic.cnt, vehicle_ammo1, autocvar_g_vehicle_spiderbot_minigun_ammo_max,
289                                                                                    autocvar_g_vehicle_spiderbot_minigun_ammo_regen_pause,
290                                                                                    autocvar_g_vehicle_spiderbot_minigun_ammo_regen, dt, false);
291
292
293         spiderbot_rocket_do(vehic);
294
295         if(vehic.vehicle_flags  & VHF_SHIELDREGEN)
296                 vehicles_regen(vehic, vehic.dmg_time, vehicle_shield, autocvar_g_vehicle_spiderbot_shield, autocvar_g_vehicle_spiderbot_shield_regen_pause, autocvar_g_vehicle_spiderbot_shield_regen, dt, true);
297
298         if(vehic.vehicle_flags  & VHF_HEALTHREGEN)
299                 vehicles_regen(vehic, vehic.dmg_time, vehicle_health, autocvar_g_vehicle_spiderbot_health, autocvar_g_vehicle_spiderbot_health_regen_pause, autocvar_g_vehicle_spiderbot_health_regen, dt, false);
300
301         PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false;
302         //this.vehicle_ammo2 = vehic.tur_head.frame;
303         this.vehicle_ammo2 = (9 - vehic.tur_head.frame) / 8 * 100; // Percentage, like ammo1
304
305         if(vehic.gun2.cnt <= time)
306                 this.vehicle_reload2 = 100;
307         else
308                 this.vehicle_reload2 = 100 - ((vehic.gun2.cnt - time) / vehic.attack_finished_single[0]) * 100;
309
310         setorigin(this, vehic.origin + '0 0 1' * vehic.maxs_z);
311         this.velocity = vehic.velocity;
312
313         VEHICLE_UPDATE_PLAYER(this, vehic, health, spiderbot);
314
315         if(vehic.vehicle_flags & VHF_HASSHIELD)
316                 VEHICLE_UPDATE_PLAYER(this, vehic, shield, spiderbot);
317 }
318
319 void spiderbot_exit(entity this, int eject)
320 {
321         vector spot;
322
323         IL_EACH(g_projectiles, it.owner == this.owner && it.classname == "spiderbot_rocket",
324         {
325                 it.realowner = this.owner;
326                 it.owner = NULL;
327         });
328
329         setthink(this, vehicles_think);
330         this.nextthink = time;
331         this.frame = 5;
332         set_movetype(this, MOVETYPE_WALK);
333
334         if(!this.owner)
335                 return;
336
337         makevectors(this.angles);
338         if(eject)
339         {
340                 spot = this.origin + v_forward * 100 + '0 0 64';
341                 spot = vehicles_findgoodexit(this, spot);
342                 setorigin(this.owner , spot);
343                 this.owner.velocity = (v_up + v_forward * 0.25) * 750;
344                 this.owner.oldvelocity = this.owner.velocity;
345         }
346         else
347         {
348                 if(vdist(this.velocity, >, autocvar_g_vehicle_spiderbot_speed_strafe))
349                 {
350                         this.owner.velocity = normalize(this.velocity) * vlen(this.velocity);
351                         this.owner.velocity_z += 200;
352                         spot = this.origin + v_forward * 128 + '0 0 64';
353                         spot = vehicles_findgoodexit(this, spot);
354                 }
355                 else
356                 {
357                         this.owner.velocity = this.velocity * 0.5;
358                         this.owner.velocity_z += 10;
359                         spot = this.origin + v_forward * 256 + '0 0 64';
360                         spot = vehicles_findgoodexit(this, spot);
361                 }
362                 this.owner.oldvelocity = this.owner.velocity;
363                 setorigin(this.owner , spot);
364         }
365
366         antilag_clear(this.owner, CS(this.owner));
367         this.owner = NULL;
368 }
369
370 void spiderbot_headfade(entity this)
371 {
372         setthink(this, spiderbot_headfade);
373         this.nextthink = this.fade_time;
374         this.alpha = 1 - (time - this.fade_time) * this.fade_rate;
375
376         if(this.cnt < time || this.alpha < 0.1)
377         {
378                 if(this.alpha > 0.1)
379                 {
380                         sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
381                         Send_Effect(EFFECT_EXPLOSION_BIG, this.origin + '0 0 100', '0 0 0', 1);
382                 }
383                 delete(this);
384         }
385 }
386
387 void spiderbot_blowup(entity this)
388 {
389         if(this.cnt > time)
390         {
391                 if(random() < 0.1)
392                 {
393                         sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
394                         Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (this.origin + '0 0 100'), '0 0 0', 1);
395                 }
396                 this.nextthink = time + 0.1;
397                 return;
398         }
399
400         entity h, g1, g2, b;
401         b = spawn();
402         h = spawn();
403         g1 = spawn();
404         g2 = spawn();
405
406         setmodel(b, MDL_VEH_SPIDERBOT_BODY);
407         setmodel(h, MDL_VEH_SPIDERBOT_TOP);
408         setmodel(g1, MDL_VEH_SPIDERBOT_GUN);
409         setmodel(g2, MDL_VEH_SPIDERBOT_GUN);
410
411         setorigin(b, this.origin);
412         b.frame = 11;
413         b.angles = this.angles;
414         setsize(b, this.mins, this.maxs);
415
416         vector org = gettaginfo(this, gettagindex(this, "tag_head"));
417         setorigin(h, org);
418         set_movetype(h, MOVETYPE_BOUNCE);
419         h.solid = SOLID_BBOX;
420         h.velocity = v_up * (500 + random() * 500) + randomvec() * 128;
421         h.modelflags = MF_ROCKET;
422         h.effects = EF_FLAME | EF_LOWPRECISION;
423         h.avelocity = randomvec() * 360;
424
425         h.alpha = 1;
426         h.cnt = time + (3.5 * random());
427         h.fade_rate = 1 / min(this.respawntime, 10);
428         h.fade_time = time;
429         setthink(h, spiderbot_headfade);
430         h.nextthink = time;
431
432         org = gettaginfo(this.tur_head, gettagindex(this.tur_head, "tag_hardpoint01"));
433         setorigin(g1, org);
434         set_movetype(g1, MOVETYPE_TOSS);
435         g1.solid = SOLID_CORPSE;
436         g1.velocity = v_forward * 700 + (randomvec() * 32);
437         g1.avelocity = randomvec() * 180;
438
439         org = gettaginfo(this.tur_head, gettagindex(this.tur_head, "tag_hardpoint02"));
440         setorigin(g2, org);
441         set_movetype(g2, MOVETYPE_TOSS);
442         g2.solid = SOLID_CORPSE;
443         g2.velocity = v_forward * 700 + (randomvec() * 32);
444         g2.avelocity = randomvec() * 180;
445
446         h.colormod = b.colormod = g1.colormod = g2.colormod = '-2 -2 -2';
447
448         SUB_SetFade(b,  time + 5, min(this.respawntime, 1));
449         //SUB_SetFade(h,  time, min(this.respawntime, 10));
450         SUB_SetFade(g1, time, min(this.respawntime, 10));
451         SUB_SetFade(g2, time, min(this.respawntime, 10));
452
453         RadiusDamage (this, this.enemy, 250, 15, 250, NULL, NULL, 250, DEATH_VH_SPID_DEATH.m_id, NULL);
454
455         this.alpha = this.tur_head.alpha = this.gun1.alpha = this.gun2.alpha = -1;
456         set_movetype(this, MOVETYPE_NONE);
457         this.deadflag = DEAD_DEAD;
458         this.solid = SOLID_NOT;
459         this.tur_head.effects &= ~EF_FLAME;
460         this.vehicle_hudmodel.viewmodelforclient = this;
461 }
462
463 bool spiderbot_impulse(entity this, int _imp)
464 {
465         switch(_imp)
466         {
467                 case IMP_weapon_group_1.impulse:
468                         this.vehicle.vehicle_weapon2mode = SBRM_VOLLY;
469                         CSQCVehicleSetup(this, 0);
470                         return true;
471                 case IMP_weapon_group_2.impulse:
472                         this.vehicle.vehicle_weapon2mode = SBRM_GUIDE;
473                         CSQCVehicleSetup(this, 0);
474                         return true;
475                 case IMP_weapon_group_3.impulse:
476                         this.vehicle.vehicle_weapon2mode = SBRM_ARTILLERY;
477                         CSQCVehicleSetup(this, 0);
478                         return true;
479
480                 case IMP_weapon_next_byid.impulse:
481                 case IMP_weapon_next_bypriority.impulse:
482                 case IMP_weapon_next_bygroup.impulse:
483                         this.vehicle.vehicle_weapon2mode += 1;
484                         if(this.vehicle.vehicle_weapon2mode > SBRM_LAST)
485                                 this.vehicle.vehicle_weapon2mode = SBRM_FIRST;
486
487                         //centerprint(this, strcat("Rocket mode is ", ftos(this.vehicle.vehicle_weapon2mode)));
488                         CSQCVehicleSetup(this, 0);
489                         return true;
490                 case IMP_weapon_last.impulse:
491                 case IMP_weapon_prev_byid.impulse:
492                 case IMP_weapon_prev_bypriority.impulse:
493                 case IMP_weapon_prev_bygroup.impulse:
494                         this.vehicle.vehicle_weapon2mode -= 1;
495                         if(this.vehicle.vehicle_weapon2mode < SBRM_FIRST)
496                                 this.vehicle.vehicle_weapon2mode = SBRM_LAST;
497
498                         //centerprint(this, strcat("Rocket mode is ", ftos(this.vehicle.vehicle_weapon2mode)));
499                         CSQCVehicleSetup(this, 0);
500                         return true;
501
502                 /*
503                 case IMP_weapon_drop.impulse: // toss gun, could be used to exit?
504                         break;
505                 case IMP_weapon_reload.impulse: // Manual minigun reload?
506                         break;
507                 */
508         }
509         return false;
510 }
511
512 spawnfunc(vehicle_spiderbot)
513 {
514         if(!autocvar_g_vehicle_spiderbot) { delete(this); return; }
515         if(!vehicle_initialize(this, VEH_SPIDERBOT, false)) { delete(this); return; }
516 }
517
518 METHOD(Spiderbot, vr_impact, void(Spiderbot thisveh, entity instance))
519 {
520     if(autocvar_g_vehicle_spiderbot_bouncepain)
521         vehicles_impact(instance, autocvar_g_vehicle_spiderbot_bouncepain_x, autocvar_g_vehicle_spiderbot_bouncepain_y, autocvar_g_vehicle_spiderbot_bouncepain_z);
522 }
523 METHOD(Spiderbot, vr_enter, void(Spiderbot thisveh, entity instance))
524 {
525     instance.vehicle_weapon2mode = SBRM_GUIDE;
526     set_movetype(instance, MOVETYPE_WALK);
527     CSQCVehicleSetup(instance.owner, 0);
528     instance.owner.vehicle_health = (instance.vehicle_health / autocvar_g_vehicle_spiderbot_health) * 100;
529     instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_spiderbot_shield) * 100;
530
531     if(instance.owner.flagcarried)
532     {
533         setattachment(instance.owner.flagcarried, instance.tur_head, "");
534         setorigin(instance.owner.flagcarried, '-20 0 120');
535     }
536 }
537 METHOD(Spiderbot, vr_think, void(Spiderbot thisveh, entity instance))
538 {
539     if(IS_ONGROUND(instance))
540         movelib_brake_simple(instance, autocvar_g_vehicle_spiderbot_speed_stop);
541 }
542 METHOD(Spiderbot, vr_death, void(Spiderbot thisveh, entity instance))
543 {
544     instance.health                             = 0;
545     instance.event_damage               = func_null;
546     instance.takedamage                 = DAMAGE_NO;
547     settouch(instance, func_null);
548     instance.cnt                                = 3.4 + time + random() * 2;
549     setthink(instance, spiderbot_blowup);
550     instance.nextthink                  = time;
551     instance.deadflag                   = DEAD_DYING;
552     instance.frame                              = 5;
553     instance.tur_head.effects  |= EF_FLAME;
554     instance.colormod                   = instance.tur_head.colormod = '-1 -1 -1';
555     instance.frame                              = 10;
556     set_movetype(instance, MOVETYPE_TOSS);
557
558     CSQCModel_UnlinkEntity(instance); // networking the death scene would be a nightmare
559 }
560 METHOD(Spiderbot, vr_spawn, void(Spiderbot thisveh, entity instance))
561 {
562     if(!instance.gun1)
563     {
564         instance.vehicles_impulse = spiderbot_impulse;
565         instance.gun1 = spawn();
566         instance.gun2 = spawn();
567         setmodel(instance.gun1, MDL_VEH_SPIDERBOT_GUN);
568         setmodel(instance.gun2, MDL_VEH_SPIDERBOT_GUN);
569         setattachment(instance.gun1, instance.tur_head, "tag_hardpoint01");
570         setattachment(instance.gun2, instance.tur_head, "tag_hardpoint02");
571         instance.gravity = 2;
572         instance.mass = 5000;
573     }
574
575     instance.frame = 5;
576     instance.tur_head.frame = 1;
577     set_movetype(instance, MOVETYPE_WALK);
578     instance.solid = SOLID_SLIDEBOX;
579     instance.alpha = instance.tur_head.alpha = instance.gun1.alpha = instance.gun2.alpha = 1;
580     instance.tur_head.angles = '0 0 0';
581     instance.vehicle_exit = spiderbot_exit;
582
583     setorigin(instance, instance.pos1 + '0 0 128');
584     instance.angles = instance.pos2;
585     instance.damageforcescale = 0.03;
586     instance.vehicle_health = autocvar_g_vehicle_spiderbot_health;
587     instance.vehicle_shield = autocvar_g_vehicle_spiderbot_shield;
588
589     instance.PlayerPhysplug = spiderbot_frame;
590 }
591 METHOD(Spiderbot, vr_setup, void(Spiderbot thisveh, entity instance))
592 {
593     if(autocvar_g_vehicle_spiderbot_shield)
594         instance.vehicle_flags |= VHF_HASSHIELD;
595
596     if(autocvar_g_vehicle_spiderbot_shield_regen)
597         instance.vehicle_flags |= VHF_SHIELDREGEN;
598
599     if(autocvar_g_vehicle_spiderbot_health_regen)
600         instance.vehicle_flags |= VHF_HEALTHREGEN;
601
602     instance.respawntime = autocvar_g_vehicle_spiderbot_respawntime;
603     instance.vehicle_health = autocvar_g_vehicle_spiderbot_health;
604     instance.vehicle_shield = autocvar_g_vehicle_spiderbot_shield;
605     instance.max_health = instance.vehicle_health;
606     instance.pushable = true; // spiderbot can use jumppads
607 }
608
609 #endif // SVQC
610 #ifdef CSQC
611 //float autocvar_cl_vehicle_spiderbot_cross_alpha = 0.6;
612 //float autocvar_cl_vehicle_spiderbot_cross_size = 1;
613
614 METHOD(Spiderbot, vr_hud, void(Spiderbot thisveh))
615 {
616     Vehicles_drawHUD(VEH_SPIDERBOT.m_icon, "vehicle_spider_weapon1", "vehicle_spider_weapon2",
617                      "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
618                      "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
619 }
620 METHOD(Spiderbot, vr_crosshair, void(Spiderbot thisveh, entity player))
621 {
622     string crosshair;
623
624     switch(weapon2mode)
625     {
626         case SBRM_VOLLY:     crosshair = vCROSS_BURST; break;
627         case SBRM_GUIDE:     crosshair = vCROSS_GUIDE; break;
628         case SBRM_ARTILLERY: crosshair = vCROSS_RAIN;  break;
629         default:             crosshair = vCROSS_BURST;
630     }
631
632     Vehicles_drawCrosshair(crosshair);
633 }
634 METHOD(Spiderbot, vr_setup, void(Spiderbot thisveh, entity instance))
635 {
636     AuxiliaryXhair[0].axh_image = vCROSS_HINT; // Minigun1
637     AuxiliaryXhair[1].axh_image = vCROSS_HINT; // Minigun2
638 }
639
640 #endif
641 #endif