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