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