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