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