]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/vehicle/spiderbot.qc
7634e7680fc59022282c1471c9dbfe015074457f
[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(game_stopped)
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         entity player = this.owner;
322         this.owner = NULL;
323
324         IL_EACH(g_projectiles, it.owner == player && it.classname == "spiderbot_rocket",
325         {
326                 it.realowner = player;
327                 it.owner = NULL;
328         });
329
330         setthink(this, vehicles_think);
331         this.nextthink = time;
332         this.frame = 5;
333         set_movetype(this, MOVETYPE_WALK);
334
335         if(!player)
336                 return;
337
338         makevectors(this.angles);
339         vector spot;
340         if(eject)
341         {
342                 spot = this.origin + v_forward * 100 + '0 0 64';
343                 spot = vehicles_findgoodexit(this, player, spot);
344                 setorigin(player, spot);
345                 player.velocity = (v_up + v_forward * 0.25) * 750;
346                 player.oldvelocity = player.velocity;
347         }
348         else
349         {
350                 if(vdist(this.velocity, >, autocvar_g_vehicle_spiderbot_speed_strafe))
351                 {
352                         player.velocity = normalize(this.velocity) * vlen(this.velocity);
353                         player.velocity_z += 200;
354                         spot = this.origin + v_forward * 128 + '0 0 64';
355                         spot = vehicles_findgoodexit(this, player, spot);
356                 }
357                 else
358                 {
359                         player.velocity = this.velocity * 0.5;
360                         player.velocity_z += 10;
361                         spot = this.origin + v_forward * 256 + '0 0 64';
362                         spot = vehicles_findgoodexit(this, player, spot);
363                 }
364                 player.oldvelocity = player.velocity;
365                 setorigin(player, spot);
366         }
367
368         antilag_clear(player, CS(player));
369 }
370
371 void spiderbot_headfade(entity this)
372 {
373         setthink(this, spiderbot_headfade);
374         this.nextthink = this.fade_time;
375         this.alpha = 1 - (time - this.fade_time) * this.fade_rate;
376
377         if(this.cnt < time || this.alpha < 0.1)
378         {
379                 if(this.alpha > 0.1)
380                 {
381                         sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
382                         Send_Effect(EFFECT_EXPLOSION_BIG, this.origin + '0 0 100', '0 0 0', 1);
383                 }
384                 delete(this);
385         }
386 }
387
388 void spiderbot_blowup(entity this)
389 {
390         if(this.cnt > time)
391         {
392                 if(random() < 0.1)
393                 {
394                         sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
395                         Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (this.origin + '0 0 100'), '0 0 0', 1);
396                 }
397                 this.nextthink = time + 0.1;
398                 return;
399         }
400
401         entity h = spawn(), g1 = spawn(), g2 = spawn(), b = spawn();
402
403         setmodel(b, MDL_VEH_SPIDERBOT_BODY);
404         setmodel(h, MDL_VEH_SPIDERBOT_TOP);
405         setmodel(g1, MDL_VEH_SPIDERBOT_GUN);
406         setmodel(g2, MDL_VEH_SPIDERBOT_GUN);
407
408         setorigin(b, this.origin);
409         b.frame = 11;
410         b.angles = this.angles;
411         setsize(b, this.mins, this.maxs);
412
413         vector org = gettaginfo(this, gettagindex(this, "tag_head"));
414         setorigin(h, org);
415         set_movetype(h, MOVETYPE_BOUNCE);
416         h.solid = SOLID_BBOX;
417         h.velocity = v_up * (500 + random() * 500) + randomvec() * 128;
418         h.modelflags = MF_ROCKET;
419         h.effects = EF_FLAME | EF_LOWPRECISION;
420         h.avelocity = randomvec() * 360;
421
422         h.alpha = 1;
423         h.cnt = time + (3.5 * random());
424         h.fade_rate = 1 / min(this.respawntime, 10);
425         h.fade_time = time;
426         setthink(h, spiderbot_headfade);
427         h.nextthink = time;
428
429         org = gettaginfo(this.tur_head, gettagindex(this.tur_head, "tag_hardpoint01"));
430         setorigin(g1, org);
431         set_movetype(g1, MOVETYPE_TOSS);
432         g1.solid = SOLID_CORPSE;
433         g1.velocity = v_forward * 700 + (randomvec() * 32);
434         g1.avelocity = randomvec() * 180;
435
436         org = gettaginfo(this.tur_head, gettagindex(this.tur_head, "tag_hardpoint02"));
437         setorigin(g2, org);
438         set_movetype(g2, MOVETYPE_TOSS);
439         g2.solid = SOLID_CORPSE;
440         g2.velocity = v_forward * 700 + (randomvec() * 32);
441         g2.avelocity = randomvec() * 180;
442
443         h.colormod = b.colormod = g1.colormod = g2.colormod = '-2 -2 -2';
444
445         SUB_SetFade(b,  time + 5, min(this.respawntime, 1));
446         //SUB_SetFade(h,  time, min(this.respawntime, 10));
447         SUB_SetFade(g1, time, min(this.respawntime, 10));
448         SUB_SetFade(g2, time, min(this.respawntime, 10));
449
450         RadiusDamage (this, this.enemy, 250, 15, 250, NULL, NULL, 250, DEATH_VH_SPID_DEATH.m_id, NULL);
451
452         this.alpha = this.tur_head.alpha = this.gun1.alpha = this.gun2.alpha = -1;
453         set_movetype(this, MOVETYPE_NONE);
454         this.deadflag = DEAD_DEAD;
455         this.solid = SOLID_NOT;
456         this.tur_head.effects &= ~EF_FLAME;
457         this.vehicle_hudmodel.viewmodelforclient = this;
458 }
459
460 bool spiderbot_impulse(entity this, int _imp)
461 {
462         switch(_imp)
463         {
464                 case IMP_weapon_group_1.impulse:
465                         this.vehicle.vehicle_weapon2mode = SBRM_VOLLY;
466                         CSQCVehicleSetup(this, 0);
467                         return true;
468                 case IMP_weapon_group_2.impulse:
469                         this.vehicle.vehicle_weapon2mode = SBRM_GUIDE;
470                         CSQCVehicleSetup(this, 0);
471                         return true;
472                 case IMP_weapon_group_3.impulse:
473                         this.vehicle.vehicle_weapon2mode = SBRM_ARTILLERY;
474                         CSQCVehicleSetup(this, 0);
475                         return true;
476
477                 case IMP_weapon_next_byid.impulse:
478                 case IMP_weapon_next_bypriority.impulse:
479                 case IMP_weapon_next_bygroup.impulse:
480                         this.vehicle.vehicle_weapon2mode += 1;
481                         if(this.vehicle.vehicle_weapon2mode > SBRM_LAST)
482                                 this.vehicle.vehicle_weapon2mode = SBRM_FIRST;
483
484                         //centerprint(this, strcat("Rocket mode is ", ftos(this.vehicle.vehicle_weapon2mode)));
485                         CSQCVehicleSetup(this, 0);
486                         return true;
487                 case IMP_weapon_last.impulse:
488                 case IMP_weapon_prev_byid.impulse:
489                 case IMP_weapon_prev_bypriority.impulse:
490                 case IMP_weapon_prev_bygroup.impulse:
491                         this.vehicle.vehicle_weapon2mode -= 1;
492                         if(this.vehicle.vehicle_weapon2mode < SBRM_FIRST)
493                                 this.vehicle.vehicle_weapon2mode = SBRM_LAST;
494
495                         //centerprint(this, strcat("Rocket mode is ", ftos(this.vehicle.vehicle_weapon2mode)));
496                         CSQCVehicleSetup(this, 0);
497                         return true;
498
499                 /*
500                 case IMP_weapon_drop.impulse: // toss gun, could be used to exit?
501                         break;
502                 case IMP_weapon_reload.impulse: // Manual minigun reload?
503                         break;
504                 */
505         }
506         return false;
507 }
508
509 spawnfunc(vehicle_spiderbot)
510 {
511         if(!autocvar_g_vehicle_spiderbot) { delete(this); return; }
512         if(!vehicle_initialize(this, VEH_SPIDERBOT, false)) { delete(this); return; }
513 }
514
515 METHOD(Spiderbot, vr_impact, void(Spiderbot thisveh, entity instance))
516 {
517     if(autocvar_g_vehicle_spiderbot_bouncepain)
518         vehicles_impact(instance, autocvar_g_vehicle_spiderbot_bouncepain_x, autocvar_g_vehicle_spiderbot_bouncepain_y, autocvar_g_vehicle_spiderbot_bouncepain_z);
519 }
520 METHOD(Spiderbot, vr_enter, void(Spiderbot thisveh, entity instance))
521 {
522     instance.vehicle_weapon2mode = SBRM_GUIDE;
523     set_movetype(instance, MOVETYPE_WALK);
524     CSQCVehicleSetup(instance.owner, 0);
525     instance.owner.vehicle_health = (instance.vehicle_health / autocvar_g_vehicle_spiderbot_health) * 100;
526     instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_spiderbot_shield) * 100;
527
528     if(instance.owner.flagcarried)
529     {
530         setattachment(instance.owner.flagcarried, instance.tur_head, "");
531         setorigin(instance.owner.flagcarried, '-20 0 120');
532     }
533 }
534 METHOD(Spiderbot, vr_think, void(Spiderbot thisveh, entity instance))
535 {
536     if(IS_ONGROUND(instance))
537         movelib_brake_simple(instance, autocvar_g_vehicle_spiderbot_speed_stop);
538 }
539 METHOD(Spiderbot, vr_death, void(Spiderbot thisveh, entity instance))
540 {
541     instance.health                             = 0;
542     instance.event_damage               = func_null;
543     instance.takedamage                 = DAMAGE_NO;
544     settouch(instance, func_null);
545     instance.cnt                                = 3.4 + time + random() * 2;
546     setthink(instance, spiderbot_blowup);
547     instance.nextthink                  = time;
548     instance.deadflag                   = DEAD_DYING;
549     instance.frame                              = 5;
550     instance.tur_head.effects  |= EF_FLAME;
551     instance.colormod                   = instance.tur_head.colormod = '-1 -1 -1';
552     instance.frame                              = 10;
553     set_movetype(instance, MOVETYPE_TOSS);
554
555     CSQCModel_UnlinkEntity(instance); // networking the death scene would be a nightmare
556 }
557 METHOD(Spiderbot, vr_spawn, void(Spiderbot thisveh, entity instance))
558 {
559     if(!instance.gun1)
560     {
561         instance.vehicles_impulse = spiderbot_impulse;
562         instance.gun1 = spawn();
563         instance.gun2 = spawn();
564         setmodel(instance.gun1, MDL_VEH_SPIDERBOT_GUN);
565         setmodel(instance.gun2, MDL_VEH_SPIDERBOT_GUN);
566         setattachment(instance.gun1, instance.tur_head, "tag_hardpoint01");
567         setattachment(instance.gun2, instance.tur_head, "tag_hardpoint02");
568         instance.gravity = 2;
569         instance.mass = 5000;
570     }
571
572     instance.frame = 5;
573     instance.tur_head.frame = 1;
574     set_movetype(instance, MOVETYPE_WALK);
575     instance.solid = SOLID_SLIDEBOX;
576     instance.alpha = instance.tur_head.alpha = instance.gun1.alpha = instance.gun2.alpha = 1;
577     instance.tur_head.angles = '0 0 0';
578     instance.vehicle_exit = spiderbot_exit;
579
580     setorigin(instance, instance.pos1 + '0 0 128');
581     instance.angles = instance.pos2;
582     instance.damageforcescale = 0.03;
583     instance.vehicle_health = autocvar_g_vehicle_spiderbot_health;
584     instance.vehicle_shield = autocvar_g_vehicle_spiderbot_shield;
585
586     instance.PlayerPhysplug = spiderbot_frame;
587 }
588 METHOD(Spiderbot, vr_setup, void(Spiderbot thisveh, entity instance))
589 {
590     if(autocvar_g_vehicle_spiderbot_shield)
591         instance.vehicle_flags |= VHF_HASSHIELD;
592
593     if(autocvar_g_vehicle_spiderbot_shield_regen)
594         instance.vehicle_flags |= VHF_SHIELDREGEN;
595
596     if(autocvar_g_vehicle_spiderbot_health_regen)
597         instance.vehicle_flags |= VHF_HEALTHREGEN;
598
599     instance.respawntime = autocvar_g_vehicle_spiderbot_respawntime;
600     instance.vehicle_health = autocvar_g_vehicle_spiderbot_health;
601     instance.vehicle_shield = autocvar_g_vehicle_spiderbot_shield;
602     instance.max_health = instance.vehicle_health;
603     instance.pushable = true; // spiderbot can use jumppads
604 }
605
606 #endif // SVQC
607 #ifdef CSQC
608 //float autocvar_cl_vehicle_spiderbot_cross_alpha = 0.6;
609 //float autocvar_cl_vehicle_spiderbot_cross_size = 1;
610
611 METHOD(Spiderbot, vr_hud, void(Spiderbot thisveh))
612 {
613     Vehicles_drawHUD(VEH_SPIDERBOT.m_icon, "vehicle_spider_weapon1", "vehicle_spider_weapon2",
614                      "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
615                      "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
616 }
617 METHOD(Spiderbot, vr_crosshair, void(Spiderbot thisveh, entity player))
618 {
619     string crosshair;
620
621     switch(weapon2mode)
622     {
623         case SBRM_VOLLY:     crosshair = vCROSS_BURST; break;
624         case SBRM_GUIDE:     crosshair = vCROSS_GUIDE; break;
625         case SBRM_ARTILLERY: crosshair = vCROSS_RAIN;  break;
626         default:             crosshair = vCROSS_BURST;
627     }
628
629     Vehicles_drawCrosshair(crosshair);
630 }
631 METHOD(Spiderbot, vr_setup, void(Spiderbot thisveh, entity instance))
632 {
633     AuxiliaryXhair[0].axh_image = vCROSS_HINT; // Minigun1
634     AuxiliaryXhair[1].axh_image = vCROSS_HINT; // Minigun2
635 }
636
637 #endif
638 #endif