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