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