]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/vehicle/spiderbot.qc
Set self in vehicle frames as before (until we can purify weapon functions), fixes...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle / spiderbot.qc
1 #ifndef VEHICLE_SPIDERBOT
2 #define VEHICLE_SPIDERBOT
3
4 #include "spiderbot_weapons.qh"
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 #ifdef SVQC
37 bool autocvar_g_vehicle_spiderbot = true;
38
39 float autocvar_g_vehicle_spiderbot_respawntime = 45;
40
41 float autocvar_g_vehicle_spiderbot_speed_stop = 50;
42 float autocvar_g_vehicle_spiderbot_speed_strafe = 400;
43 float autocvar_g_vehicle_spiderbot_speed_walk = 500;
44 float autocvar_g_vehicle_spiderbot_speed_run = 700;
45 float autocvar_g_vehicle_spiderbot_turnspeed = 90;
46 float autocvar_g_vehicle_spiderbot_turnspeed_strafe = 300;
47 float autocvar_g_vehicle_spiderbot_movement_inertia = 0.15;
48
49 float autocvar_g_vehicle_spiderbot_springlength = 150;
50 float autocvar_g_vehicle_spiderbot_springup = 20;
51 float autocvar_g_vehicle_spiderbot_springblend = 0.1;
52 float autocvar_g_vehicle_spiderbot_tiltlimit = 90;
53
54 float autocvar_g_vehicle_spiderbot_head_pitchlimit_down = -20;
55 float autocvar_g_vehicle_spiderbot_head_pitchlimit_up = 30;
56 float autocvar_g_vehicle_spiderbot_head_turnlimit = 90;
57 float autocvar_g_vehicle_spiderbot_head_turnspeed = 110;
58
59 int autocvar_g_vehicle_spiderbot_health = 800;
60 float autocvar_g_vehicle_spiderbot_health_regen = 10;
61 float autocvar_g_vehicle_spiderbot_health_regen_pause = 5;
62
63 int autocvar_g_vehicle_spiderbot_shield = 200;
64 float autocvar_g_vehicle_spiderbot_shield_regen = 25;
65 float autocvar_g_vehicle_spiderbot_shield_regen_pause = 0.35;
66
67 // 'minspeed_for_pain speedchange_to_pain_factor max_damage'
68 vector autocvar_g_vehicle_spiderbot_bouncepain = '0 0 0';
69
70 .float jump_delay;
71 bool spiderbot_frame(entity this)
72 {
73         entity vehic = this.vehicle;
74         return = true;
75
76         if(intermission_running)
77         {
78                 vehic.velocity = '0 0 0';
79                 vehic.avelocity = '0 0 0';
80                 return;
81         }
82
83         setself(vehic);
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         movelib_groundalign4point(vehic, 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         setself(this);
340 }
341
342 void spiderbot_exit(float eject)
343 {SELFPARAM();
344         entity e;
345         vector spot;
346
347         e = findchain(classname,"spiderbot_rocket");
348         while(e)
349         {
350                 if(e.owner == self.owner)
351                 {
352                         e.realowner = self.owner;
353                         e.owner = world;
354                 }
355                 e = e.chain;
356         }
357
358         self.think = vehicles_think;
359         self.nextthink = time;
360         self.frame = 5;
361         self.movetype = MOVETYPE_WALK;
362
363         if(!self.owner)
364                 return;
365
366         makevectors(self.angles);
367         if(eject)
368         {
369                 spot = self.origin + v_forward * 100 + '0 0 64';
370                 spot = vehicles_findgoodexit(spot);
371                 setorigin(self.owner , spot);
372                 self.owner.velocity = (v_up + v_forward * 0.25) * 750;
373                 self.owner.oldvelocity = self.owner.velocity;
374         }
375         else
376         {
377                 if(vdist(self.velocity, >, autocvar_g_vehicle_spiderbot_speed_strafe))
378                 {
379                         self.owner.velocity = normalize(self.velocity) * vlen(self.velocity);
380                         self.owner.velocity_z += 200;
381                         spot = self.origin + v_forward * 128 + '0 0 64';
382                         spot = vehicles_findgoodexit(spot);
383                 }
384                 else
385                 {
386                         self.owner.velocity = self.velocity * 0.5;
387                         self.owner.velocity_z += 10;
388                         spot = self.origin + v_forward * 256 + '0 0 64';
389                         spot = vehicles_findgoodexit(spot);
390                 }
391                 self.owner.oldvelocity = self.owner.velocity;
392                 setorigin(self.owner , spot);
393         }
394
395         antilag_clear(self.owner, CS(self.owner));
396         self.owner = world;
397 }
398
399 void spiderbot_headfade()
400 {SELFPARAM();
401         self.think = spiderbot_headfade;
402         self.nextthink = self.fade_time;
403         self.alpha = 1 - (time - self.fade_time) * self.fade_rate;
404
405         if(self.cnt < time || self.alpha < 0.1)
406         {
407                 if(self.alpha > 0.1)
408                 {
409                         sound (self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
410                         Send_Effect(EFFECT_EXPLOSION_BIG, self.origin + '0 0 100', '0 0 0', 1);
411                 }
412                 remove(self);
413         }
414 }
415
416 void spiderbot_blowup()
417 {SELFPARAM();
418         if(self.cnt > time)
419         {
420                 if(random() < 0.1)
421                 {
422                         sound (self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
423                         Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
424                 }
425                 self.nextthink = time + 0.1;
426                 return;
427         }
428
429         entity h, g1, g2, b;
430         b = spawn();
431         h = spawn();
432         g1 = spawn();
433         g2 = spawn();
434
435         setmodel(b, MDL_VEH_SPIDERBOT_BODY);
436         setmodel(h, MDL_VEH_SPIDERBOT_TOP);
437         setmodel(g1, MDL_VEH_SPIDERBOT_GUN);
438         setmodel(g2, MDL_VEH_SPIDERBOT_GUN);
439
440         setorigin(b, self.origin);
441         b.frame = 11;
442         b.angles = self.angles;
443         setsize(b, self.mins, self.maxs);
444
445         vector org = gettaginfo(self, gettagindex(self, "tag_head"));
446         setorigin(h, org);
447         h.movetype = MOVETYPE_BOUNCE;
448         h.solid = SOLID_BBOX;
449         h.velocity = v_up * (500 + random() * 500) + randomvec() * 128;
450         h.modelflags = MF_ROCKET;
451         h.effects = EF_FLAME | EF_LOWPRECISION;
452         h.avelocity = randomvec() * 360;
453
454         h.alpha = 1;
455         h.cnt = time + (3.5 * random());
456         h.fade_rate = 1 / min(self.respawntime, 10);
457         h.fade_time = time;
458         h.think = spiderbot_headfade;
459         h.nextthink = time;
460
461         org = gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_hardpoint01"));
462         setorigin(g1, org);
463         g1.movetype = MOVETYPE_TOSS;
464         g1.solid = SOLID_CORPSE;
465         g1.velocity = v_forward * 700 + (randomvec() * 32);
466         g1.avelocity = randomvec() * 180;
467
468         org = gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_hardpoint02"));
469         setorigin(g2, org);
470         g2.movetype = MOVETYPE_TOSS;
471         g2.solid = SOLID_CORPSE;
472         g2.velocity = v_forward * 700 + (randomvec() * 32);
473         g2.avelocity = randomvec() * 180;
474
475         h.colormod = b.colormod = g1.colormod = g2.colormod = '-2 -2 -2';
476
477         SUB_SetFade(b,  time + 5, min(self.respawntime, 1));
478         //SUB_SetFade(h,  time, min(self.respawntime, 10));
479         SUB_SetFade(g1, time, min(self.respawntime, 10));
480         SUB_SetFade(g2, time, min(self.respawntime, 10));
481
482         RadiusDamage (self, self.enemy, 250, 15, 250, world, world, 250, DEATH_VH_SPID_DEATH.m_id, world);
483
484         self.alpha = self.tur_head.alpha = self.gun1.alpha = self.gun2.alpha = -1;
485         self.movetype = MOVETYPE_NONE;
486         self.deadflag = DEAD_DEAD;
487         self.solid = SOLID_NOT;
488         self.tur_head.effects &= ~EF_FLAME;
489         self.vehicle_hudmodel.viewmodelforclient = self;
490 }
491
492 bool spiderbot_impulse(int _imp)
493 {SELFPARAM();
494         switch(_imp)
495         {
496                 case IMP_weapon_group_1.impulse:
497                         self.vehicle.vehicle_weapon2mode = SBRM_VOLLY;
498                         CSQCVehicleSetup(self, 0);
499                         return true;
500                 case IMP_weapon_group_2.impulse:
501                         self.vehicle.vehicle_weapon2mode = SBRM_GUIDE;
502                         CSQCVehicleSetup(self, 0);
503                         return true;
504                 case IMP_weapon_group_3.impulse:
505                         self.vehicle.vehicle_weapon2mode = SBRM_ARTILLERY;
506                         CSQCVehicleSetup(self, 0);
507                         return true;
508
509                 case IMP_weapon_next_byid.impulse:
510                 case IMP_weapon_next_bypriority.impulse:
511                 case IMP_weapon_next_bygroup.impulse:
512                         self.vehicle.vehicle_weapon2mode += 1;
513                         if(self.vehicle.vehicle_weapon2mode > SBRM_LAST)
514                                 self.vehicle.vehicle_weapon2mode = SBRM_FIRST;
515
516                         //centerprint(self, strcat("Rocket mode is ", ftos(self.vehicle.vehicle_weapon2mode)));
517                         CSQCVehicleSetup(self, 0);
518                         return true;
519                 case IMP_weapon_last.impulse:
520                 case IMP_weapon_prev_byid.impulse:
521                 case IMP_weapon_prev_bypriority.impulse:
522                 case IMP_weapon_prev_bygroup.impulse:
523                         self.vehicle.vehicle_weapon2mode -= 1;
524                         if(self.vehicle.vehicle_weapon2mode < SBRM_FIRST)
525                                 self.vehicle.vehicle_weapon2mode = SBRM_LAST;
526
527                         //centerprint(self, strcat("Rocket mode is ", ftos(self.vehicle.vehicle_weapon2mode)));
528                         CSQCVehicleSetup(self, 0);
529                         return true;
530
531                 /*
532                 case IMP_weapon_drop.impulse: // toss gun, could be used to exit?
533                         break;
534                 case IMP_weapon_reload.impulse: // Manual minigun reload?
535                         break;
536                 */
537         }
538         return false;
539 }
540
541 spawnfunc(vehicle_spiderbot)
542 {
543         if(!autocvar_g_vehicle_spiderbot) { remove(self); return; }
544         if(!vehicle_initialize(VEH_SPIDERBOT, false)) { remove(self); return; }
545 }
546
547 METHOD(Spiderbot, vr_impact, void(Spiderbot thisveh, entity instance))
548 {
549     if(autocvar_g_vehicle_spiderbot_bouncepain)
550         vehicles_impact(autocvar_g_vehicle_spiderbot_bouncepain_x, autocvar_g_vehicle_spiderbot_bouncepain_y, autocvar_g_vehicle_spiderbot_bouncepain_z);
551 }
552 METHOD(Spiderbot, vr_enter, void(Spiderbot thisveh, entity instance))
553 {
554     SELFPARAM();
555     self.vehicle_weapon2mode = SBRM_GUIDE;
556     self.movetype = MOVETYPE_WALK;
557     CSQCVehicleSetup(self.owner, 0);
558     self.owner.vehicle_health = (self.vehicle_health / autocvar_g_vehicle_spiderbot_health) * 100;
559     self.owner.vehicle_shield = (self.vehicle_shield / autocvar_g_vehicle_spiderbot_shield) * 100;
560
561     if(self.owner.flagcarried)
562     {
563         setattachment(self.owner.flagcarried, self.tur_head, "");
564         setorigin(self.owner.flagcarried, '-20 0 120');
565     }
566 }
567 METHOD(Spiderbot, vr_think, void(Spiderbot thisveh, entity instance))
568 {
569     SELFPARAM();
570     if(IS_ONGROUND(self))
571         movelib_brake_simple(self, autocvar_g_vehicle_spiderbot_speed_stop);
572 }
573 METHOD(Spiderbot, vr_death, void(Spiderbot thisveh, entity instance))
574 {
575     instance.health                             = 0;
576     instance.event_damage               = func_null;
577     instance.takedamage                 = DAMAGE_NO;
578     instance.touch                              = func_null;
579     instance.cnt                                = 3.4 + time + random() * 2;
580     instance.think                              = spiderbot_blowup;
581     instance.nextthink                  = time;
582     instance.deadflag                   = DEAD_DYING;
583     instance.frame                              = 5;
584     instance.tur_head.effects  |= EF_FLAME;
585     instance.colormod                   = instance.tur_head.colormod = '-1 -1 -1';
586     instance.frame                              = 10;
587     instance.movetype                   = MOVETYPE_TOSS;
588
589     CSQCModel_UnlinkEntity(instance); // networking the death scene would be a nightmare
590 }
591 METHOD(Spiderbot, vr_spawn, void(Spiderbot thisveh, entity instance))
592 {
593     SELFPARAM();
594     if(!self.gun1)
595     {
596         self.vehicles_impulse = spiderbot_impulse;
597         self.gun1 = spawn();
598         self.gun2 = spawn();
599         setmodel(self.gun1, MDL_VEH_SPIDERBOT_GUN);
600         setmodel(self.gun2, MDL_VEH_SPIDERBOT_GUN);
601         setattachment(self.gun1, self.tur_head, "tag_hardpoint01");
602         setattachment(self.gun2, self.tur_head, "tag_hardpoint02");
603         self.gravity = 2;
604         self.mass = 5000;
605     }
606
607     self.frame = 5;
608     self.tur_head.frame = 1;
609     self.movetype = MOVETYPE_WALK;
610     self.solid = SOLID_SLIDEBOX;
611     self.alpha = self.tur_head.alpha = self.gun1.alpha = self.gun2.alpha = 1;
612     self.tur_head.angles = '0 0 0';
613     self.vehicle_exit = spiderbot_exit;
614
615     setorigin(self, self.pos1 + '0 0 128');
616     self.angles = self.pos2;
617     self.damageforcescale = 0.03;
618     self.vehicle_health = autocvar_g_vehicle_spiderbot_health;
619     self.vehicle_shield = autocvar_g_vehicle_spiderbot_shield;
620
621     self.PlayerPhysplug = spiderbot_frame;
622 }
623 METHOD(Spiderbot, vr_setup, void(Spiderbot thisveh, entity instance))
624 {
625     SELFPARAM();
626     if(autocvar_g_vehicle_spiderbot_shield)
627         self.vehicle_flags |= VHF_HASSHIELD;
628
629     if(autocvar_g_vehicle_spiderbot_shield_regen)
630         self.vehicle_flags |= VHF_SHIELDREGEN;
631
632     if(autocvar_g_vehicle_spiderbot_health_regen)
633         self.vehicle_flags |= VHF_HEALTHREGEN;
634
635     self.respawntime = autocvar_g_vehicle_spiderbot_respawntime;
636     self.vehicle_health = autocvar_g_vehicle_spiderbot_health;
637     self.vehicle_shield = autocvar_g_vehicle_spiderbot_shield;
638     self.max_health = self.vehicle_health;
639     self.pushable = true; // spiderbot can use jumppads
640 }
641
642 #endif // SVQC
643 #ifdef CSQC
644 float autocvar_cl_vehicle_spiderbot_cross_alpha = 0.6;
645 float autocvar_cl_vehicle_spiderbot_cross_size = 1;
646
647 METHOD(Spiderbot, vr_hud, void(Spiderbot thisveh))
648 {
649     Vehicles_drawHUD(VEH_SPIDERBOT.m_icon, "vehicle_spider_weapon1", "vehicle_spider_weapon2",
650                      "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
651                      "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
652 }
653 METHOD(Spiderbot, vr_crosshair, void(Spiderbot thisveh))
654 {
655     string crosshair;
656
657     switch(weapon2mode)
658     {
659         case SBRM_VOLLY:     crosshair = vCROSS_BURST; break;
660         case SBRM_GUIDE:     crosshair = vCROSS_GUIDE; break;
661         case SBRM_ARTILLERY: crosshair = vCROSS_RAIN;  break;
662         default:             crosshair = vCROSS_BURST;
663     }
664
665     Vehicles_drawCrosshair(crosshair);
666 }
667 METHOD(Spiderbot, vr_setup, void(Spiderbot thisveh, entity instance))
668 {
669     AuxiliaryXhair[0].axh_image = vCROSS_HINT; // Minigun1
670     AuxiliaryXhair[1].axh_image = vCROSS_HINT; // Minigun2
671 }
672
673 #endif
674 #endif