Merge remote-tracking branch 'origin/master' into samual/spawn_weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / vehicles / spiderbot.qc
1 const vector SPIDERBOT_MIN = '-75 -75 10';
2 const vector SPIDERBOT_MAX  = '75 75 125';
3
4 #ifdef SVQC
5 float autocvar_g_vehicle_spiderbot_respawntime;
6
7 float autocvar_g_vehicle_spiderbot_speed_stop;
8 float autocvar_g_vehicle_spiderbot_speed_strafe;
9 float autocvar_g_vehicle_spiderbot_speed_walk;
10 float autocvar_g_vehicle_spiderbot_turnspeed;
11 float autocvar_g_vehicle_spiderbot_movement_inertia;
12
13 float autocvar_g_vehicle_spiderbot_springlength;
14 float autocvar_g_vehicle_spiderbot_springup;
15 float autocvar_g_vehicle_spiderbot_springblend;
16
17 float autocvar_g_vehicle_spiderbot_head_pitchlimit_down;
18 float autocvar_g_vehicle_spiderbot_head_pitchlimit_up;
19 float autocvar_g_vehicle_spiderbot_head_pitchspeed;
20 float autocvar_g_vehicle_spiderbot_head_turnlimit;
21 float autocvar_g_vehicle_spiderbot_head_turnspeed;
22
23 //float autocvar_g_vehicle_spiderbot_energy;
24 //float autocvar_g_vehicle_spiderbot_energy_regen;
25 //float autocvar_g_vehicle_spiderbot_energy_regen_pause;
26
27 float autocvar_g_vehicle_spiderbot_health;
28 float autocvar_g_vehicle_spiderbot_health_regen;
29 float autocvar_g_vehicle_spiderbot_health_regen_pause;
30
31 float autocvar_g_vehicle_spiderbot_shield;
32 float autocvar_g_vehicle_spiderbot_shield_regen;
33 float autocvar_g_vehicle_spiderbot_shield_regen_pause;
34
35 float autocvar_g_vehicle_spiderbot_minigun_damage;
36 float autocvar_g_vehicle_spiderbot_minigun_refire;
37 float autocvar_g_vehicle_spiderbot_minigun_spread;
38 float autocvar_g_vehicle_spiderbot_minigun_ammo_cost;
39 float autocvar_g_vehicle_spiderbot_minigun_ammo_max;
40 float autocvar_g_vehicle_spiderbot_minigun_ammo_regen;
41 float autocvar_g_vehicle_spiderbot_minigun_ammo_regen_pause;
42
43 float autocvar_g_vehicle_spiderbot_rocket_damage;
44 float autocvar_g_vehicle_spiderbot_rocket_force;
45 float autocvar_g_vehicle_spiderbot_rocket_radius;
46 float autocvar_g_vehicle_spiderbot_rocket_speed;
47 float autocvar_g_vehicle_spiderbot_rocket_refire;
48 float autocvar_g_vehicle_spiderbot_rocket_reload;
49 float autocvar_g_vehicle_spiderbot_rocket_health;
50 float autocvar_g_vehicle_spiderbot_rocket_noise;
51 float autocvar_g_vehicle_spiderbot_rocket_turnrate;
52 float autocvar_g_vehicle_spiderbot_rocket_lifetime;
53
54 vector autocvar_g_vehicle_spiderbot_bouncepain;
55
56
57 void spiderbot_exit(float eject);
58 void spiderbot_enter();
59 void spiderbot_spawn();
60
61 void spiderbot_rocket_unguided()
62 {
63     vector newdir, olddir;
64
65     self.nextthink  = time;
66
67     olddir = normalize(self.velocity);
68     newdir = normalize(self.pos1 - self.origin) + randomvec() * autocvar_g_vehicle_spiderbot_rocket_noise;
69     self.velocity = normalize(olddir + newdir * autocvar_g_vehicle_spiderbot_rocket_turnrate) * autocvar_g_vehicle_spiderbot_rocket_speed;
70
71     UpdateCSQCProjectile(self);
72
73     if (self.owner.deadflag != DEAD_NO || self.cnt < time || vlen(self.pos1 - self.origin) < 16)
74         self.use();
75 }
76
77 void spiderbot_rocket_guided()
78 {
79     vector newdir, olddir;
80
81     self.nextthink  = time;
82
83     if not (self.realowner.vehicle)
84         self.think = spiderbot_rocket_unguided;
85
86     crosshair_trace(self.realowner);
87     olddir = normalize(self.velocity);
88     newdir = normalize(trace_endpos - self.origin) + randomvec() * autocvar_g_vehicle_spiderbot_rocket_noise;
89     self.velocity = normalize(olddir + newdir * autocvar_g_vehicle_spiderbot_rocket_turnrate) * autocvar_g_vehicle_spiderbot_rocket_speed;
90
91     UpdateCSQCProjectile(self);
92
93     if (self.owner.deadflag != DEAD_NO || self.cnt < time)
94         self.use();
95 }
96
97 void spiderbot_guide_release()
98 {
99     entity rkt;
100     rkt = findchainentity(realowner, self.owner);
101     if not (rkt)
102         return;
103
104     crosshair_trace(self.owner);
105     while(rkt)
106     {
107         if(rkt.think == spiderbot_rocket_guided)
108         {
109             rkt.pos1 = trace_endpos;
110             rkt.think = spiderbot_rocket_unguided;
111         }
112         rkt = rkt.chain;
113     }
114 }
115
116 void spiderbot_rocket_do()
117 {
118
119     vector v;
120     entity rocket;
121
122     if (self.owner.BUTTON_ATCK2)
123     {
124         if (self.wait == 1)
125         if (self.tur_head.frame == 9 || self.tur_head.frame == 1)
126         {
127             if(self.gun2.cnt < time && self.tur_head.frame == 9)
128                 self.tur_head.frame = 1;
129
130             return;
131         }
132         self.wait = 1;
133     }
134     else
135     {
136         if(self.wait)
137             spiderbot_guide_release();
138
139         self.wait = 0;
140     }
141
142     if(self.gun2.cnt > time)
143         return;
144
145     if (self.tur_head.frame >= 9)
146         self.tur_head.frame = 1;
147
148     if not (self.owner.BUTTON_ATCK2)
149         return;
150
151     crosshair_trace(self.owner);
152
153     v = gettaginfo(self.tur_head,gettagindex(self.tur_head,"tag_fire"));
154     rocket = vehicles_projectile("spiderbot_rocket_launch", "weapons/rocket_fire.wav",
155                            v, normalize(v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed,
156                            autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1,
157                            DEATH_SBROCKET, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, FALSE, FALSE);
158
159     rocket.cnt        = time + 15;
160     rocket.classname  = "spiderbot_rocket";
161     rocket.pos1       = trace_endpos;
162     rocket.think      = spiderbot_rocket_guided;
163     rocket.nextthink  = time;
164     rocket.cnt        = time + autocvar_g_vehicle_spiderbot_rocket_lifetime;
165
166     self.tur_head.frame += 1;
167     if (self.tur_head.frame == 9)
168         self.attack_finished_single = autocvar_g_vehicle_spiderbot_rocket_reload;
169     else
170         self.attack_finished_single = autocvar_g_vehicle_spiderbot_rocket_refire;
171
172     self.gun2.cnt = time + self.attack_finished_single;
173 }
174
175 float spiderbot_frame()
176 {
177     vector ad, vf;
178     entity player, spider;
179     float ftmp;
180
181         if(intermission_running)
182                 return 1;
183                 
184     player = self;
185     spider = self.vehicle;
186     self   = spider;
187
188     vehicles_painframe();
189     
190     player.BUTTON_ZOOM      = 0;
191     player.BUTTON_CROUCH    = 0;
192     player.switchweapon     = 0;
193
194 #if 1 // 0 to enable per-gun impact aux crosshairs
195     // Avarage gun impact point's -> aux cross
196     ad = gettaginfo(spider.tur_head, gettagindex(spider.tur_head, "tag_hardpoint01"));
197     vf = v_forward;
198     ad += gettaginfo(spider.tur_head, gettagindex(spider.tur_head, "tag_hardpoint02"));
199     vf += v_forward;
200     ad = ad * 0.5;
201     v_forward = vf * 0.5;
202     traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, spider);
203     UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload1) + ('0 1 0' * (1 - player.vehicle_reload1)), 0);
204 #else
205     ad = gettaginfo(spider.gun1, gettagindex(spider.gun1, "barrels"));
206     traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, spider);
207     UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload1) + ('0 1 0' * (1 - player.vehicle_reload1)), 0);
208     vf = ad;
209     ad = gettaginfo(spider.gun2, gettagindex(spider.gun2, "barrels"));
210     traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, spider);
211     UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload1) + ('0 1 0' * (1 - player.vehicle_reload1)), 1);
212     ad = 0.5 * (ad + vf);
213 #endif
214
215     crosshair_trace(player);
216     ad = vectoangles(normalize(trace_endpos - ad));
217     ad = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(spider.angles), AnglesTransform_FromAngles(ad))) - spider.tur_head.angles;
218     ad = AnglesTransform_Normalize(ad, TRUE);
219     //UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload2) + ('0 1 0' * (1 - player.vehicle_reload2)), 2);
220     
221     // Rotate head
222     ftmp = autocvar_g_vehicle_spiderbot_head_turnspeed * sys_frametime;
223     ad_y = bound(-ftmp, ad_y, ftmp);
224     spider.tur_head.angles_y = bound(autocvar_g_vehicle_spiderbot_head_turnlimit * -1, spider.tur_head.angles_y + ad_y, autocvar_g_vehicle_spiderbot_head_turnlimit);
225
226     // Pitch head
227     ftmp = autocvar_g_vehicle_spiderbot_head_pitchspeed * sys_frametime;
228     ad_x = bound(ftmp * -1, ad_x, ftmp);
229     spider.tur_head.angles_x = bound(autocvar_g_vehicle_spiderbot_head_pitchlimit_down, spider.tur_head.angles_x + ad_x, autocvar_g_vehicle_spiderbot_head_pitchlimit_up);
230
231     // Turn Body
232     ftmp = autocvar_g_vehicle_spiderbot_turnspeed * sys_frametime;
233     ftmp = bound(-ftmp, spider.tur_head.angles_y, ftmp);
234
235     //fixedmakevectors(spider.angles);
236     makevectors(spider.angles + '-2 0 0' * spider.angles_x);
237     
238     movelib_groundalign4point(autocvar_g_vehicle_spiderbot_springlength, autocvar_g_vehicle_spiderbot_springup, autocvar_g_vehicle_spiderbot_springblend);
239
240     if(spider.flags & FL_ONGROUND)
241     {
242         if(spider.frame == 4 && self.tur_head.wait != 0)
243         {
244             sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_land.wav", VOL_VEHICLEENGINE, ATTN_NORM);
245             spider.frame = 5;            
246         }
247         
248         if(player.BUTTON_JUMP && self.tur_head.wait < time)
249         {        
250             sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_jump.wav", VOL_VEHICLEENGINE, ATTN_NORM);
251             //dprint("spiderbot_jump:", ftos(soundlength("vehicles/spiderbot_jump.wav")), "\n");
252             self.delay = 0;
253
254             self.tur_head.wait = time + 2;
255             player.BUTTON_JUMP = 0;
256             spider.velocity   = v_forward * 700 + v_up * 600;
257             spider.frame = 4;
258         }
259         else
260         {
261             if(vlen(player.movement) == 0)
262             {
263                 if(self.sound_nexttime < time || self.delay != 3)
264                 {                        
265                     self.delay = 3;
266                     self.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_idle.wav");
267                     //dprint("spiderbot_idle:", ftos(soundlength("vehicles/spiderbot_idle.wav")), "\n");
268                     sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_idle.wav", VOL_VEHICLEENGINE, ATTN_NORM);
269                 }                
270                 movelib_beak_simple(autocvar_g_vehicle_spiderbot_speed_stop);
271                 spider.frame = 5;
272             }
273             else
274             {
275                 spider.angles_y = anglemods(spider.angles_y + ftmp);
276                 spider.tur_head.angles_y -= ftmp;
277
278                 if(player.movement_x != 0)
279                 {
280                     if(player.movement_x > 0)
281                     {
282                         player.movement_x = 1;
283                         spider.frame = 0;
284                     }
285                     else if(player.movement_x < 0)
286                     {
287                         player.movement_x = -1;
288                         spider.frame = 1;
289                     }
290                     player.movement_y = 0;
291                     movelib_move_simple(normalize(v_forward * player.movement_x),autocvar_g_vehicle_spiderbot_speed_walk,autocvar_g_vehicle_spiderbot_movement_inertia);
292
293                     if(self.sound_nexttime < time || self.delay != 1)
294                     {                        
295                         self.delay = 1;
296                         self.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_walk.wav");
297                         sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_walk.wav", VOL_VEHICLEENGINE, ATTN_NORM);
298                         //dprint("spiderbot_walk:", ftos(soundlength("vehicles/spiderbot_walk.wav")), "\n");
299                     }
300                 }
301                 else if(player.movement_y != 0)
302                 {
303                     if(player.movement_y < 0)
304                     {
305                         player.movement_y = -1;
306                         spider.frame = 2;
307                     }
308                     else if(player.movement_y > 0)
309                     {
310                         player.movement_y = 1;
311                         spider.frame = 3;
312                     }
313                     movelib_move_simple(normalize(v_right * player.movement_y),autocvar_g_vehicle_spiderbot_speed_strafe,autocvar_g_vehicle_spiderbot_movement_inertia);
314                     if(self.sound_nexttime < time || self.delay != 2)
315                     {                        
316                         self.delay = 2;
317                         self.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_strafe.wav");
318                         sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_strafe.wav", VOL_VEHICLEENGINE, ATTN_NORM);
319                         //dprint("spiderbot_strafe:", ftos(soundlength("vehicles/spiderbot_strafe.wav")), "\n");
320                     }
321                 }
322             }
323         }
324     }
325
326     self.angles_x = bound(-45, self.angles_x, 45);
327     self.angles_z = bound(-45, self.angles_z, 45);
328
329     if(player.BUTTON_ATCK)
330     {
331         spider.cnt = time;
332         if(spider.vehicle_ammo1 >= autocvar_g_vehicle_spiderbot_minigun_ammo_cost && spider.tur_head.attack_finished_single <= time)
333         {
334             entity gun;
335             vector v;
336             spider.misc_bulletcounter += 1;
337
338             self = player;
339
340             mod(spider.misc_bulletcounter, 2) ? gun = spider.gun1 : gun = spider.gun2;
341             v = gettaginfo(gun, gettagindex(gun, "barrels"));
342             v_forward = normalize(v_forward);
343             v += v_forward * 50;
344
345             fireBullet (v, v_forward, autocvar_g_vehicle_spiderbot_minigun_spread, autocvar_g_vehicle_spiderbot_minigun_damage,
346                 autocvar_g_vehicle_spiderbot_minigun_spread, DEATH_SBMINIGUN, 0);
347
348             sound (gun, CH_WEAPON_A, "weapons/uzi_fire.wav", VOL_BASE, ATTN_NORM);
349             trailparticles(self, particleeffectnum("spiderbot_minigun_trail"), v, trace_endpos);
350             pointparticles(particleeffectnum("spiderbot_minigun_muzzleflash"), v, v_forward * 2500, 1);
351
352             self = spider;
353
354             spider.vehicle_ammo1 -= autocvar_g_vehicle_spiderbot_minigun_ammo_cost;
355             spider.tur_head.attack_finished_single = time + autocvar_g_vehicle_spiderbot_minigun_refire;
356             player.vehicle_ammo1 = (spider.vehicle_ammo1 / autocvar_g_vehicle_spiderbot_minigun_ammo_max) * 100;
357             spider.gun1.angles_z += 45;
358             spider.gun2.angles_z -= 45;
359             if(spider.gun1.angles_z >= 360)
360             {
361                 spider.gun1.angles_z = 0;
362                 spider.gun2.angles_z = 0;
363             }
364         }
365     }
366     else
367         vehicles_regen(cnt, vehicle_ammo1, autocvar_g_vehicle_spiderbot_minigun_ammo_max,
368                                            autocvar_g_vehicle_spiderbot_minigun_ammo_regen_pause,
369                                            autocvar_g_vehicle_spiderbot_minigun_ammo_regen, frametime);
370         
371
372     spiderbot_rocket_do();
373
374     if(self.vehicle_flags  & VHF_SHIELDREGEN)
375         vehicles_regen(dmg_time, vehicle_shield, autocvar_g_vehicle_spiderbot_shield, autocvar_g_vehicle_spiderbot_shield_regen_pause, autocvar_g_vehicle_spiderbot_shield_regen, frametime);
376
377     if(self.vehicle_flags  & VHF_HEALTHREGEN)
378         vehicles_regen(dmg_time, vehicle_health, autocvar_g_vehicle_spiderbot_health, autocvar_g_vehicle_spiderbot_health_regen_pause, autocvar_g_vehicle_spiderbot_health_regen, frametime);
379
380     player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
381     player.vehicle_ammo2 = spider.tur_head.frame;
382
383     if(spider.gun2.cnt <= time)
384         player.vehicle_reload2 = 100;
385     else
386         player.vehicle_reload2 = 100 - ((spider.gun2.cnt - time) / spider.attack_finished_single) * 100;
387
388     setorigin(player, spider.origin + '0 0 1' * SPIDERBOT_MAX_z);
389     player.velocity = spider.velocity;
390
391     VEHICLE_UPDATE_PLAYER(health, spiderbot);
392
393     if(self.vehicle_flags & VHF_HASSHIELD)
394         VEHICLE_UPDATE_PLAYER(shield, spiderbot);
395
396     self = player;
397     return 1;    
398 }
399 void spiderbot_think()
400 {
401     if(self.flags & FL_ONGROUND)
402         movelib_beak_simple(autocvar_g_vehicle_spiderbot_speed_stop);
403
404     self.nextthink = time;
405 }
406
407 void spiderbot_enter()
408 {
409     self.movetype   = MOVETYPE_WALK;
410
411     self.owner.vehicle_health = (self.vehicle_health / autocvar_g_vehicle_spiderbot_health) * 100;
412     self.owner.vehicle_shield = (self.vehicle_shield / autocvar_g_vehicle_spiderbot_shield) * 100;
413
414     if(self.owner.flagcarried)
415     {
416         setattachment(self.owner.flagcarried, self.tur_head, ""); 
417         setorigin(self.owner.flagcarried, '-20 0 120'); 
418     }
419 }
420
421 void spiderbot_exit(float eject)
422 {
423     entity e;
424     vector spot;
425     
426     e = findchain(classname,"spiderbot_rocket");
427     while(e)
428     {
429         if(e.owner == self.owner)
430         {
431             e.realowner = self.owner;
432             e.owner = world;
433         }
434         e = e.chain;
435     }
436
437     self.velocity   = '0 0 0';
438     self.think      = spiderbot_think;
439     self.nextthink  = time;
440     self.frame      = 5;
441     self.movetype   = MOVETYPE_WALK;
442     
443     if not (self.owner)
444         return;
445
446         makevectors(self.angles);
447         if(eject)
448         {
449             spot = self.origin + v_forward * 100 + '0 0 64';
450             spot = vehicles_findgoodexit(spot);
451             setorigin(self.owner , spot);
452             self.owner.velocity = (v_up + v_forward * 0.25) * 750;
453             self.owner.oldvelocity = self.owner.velocity;
454         }
455         else
456         {
457             self.owner.velocity = normalize(self.velocity) * autocvar_sv_maxairspeed;
458             self.owner.oldvelocity = self.owner.velocity;           
459             spot = self.origin - v_forward * 200 + '0 0 64';
460             spot = vehicles_findgoodexit(spot);
461             setorigin(self.owner , spot);
462         }
463     antilag_clear(self.owner);
464     self.owner = world;
465 }
466 void spider_impact()
467 {
468     if(autocvar_g_vehicle_spiderbot_bouncepain_x)
469         vehilces_impact(autocvar_g_vehicle_spiderbot_bouncepain_x, autocvar_g_vehicle_spiderbot_bouncepain_y, autocvar_g_vehicle_spiderbot_bouncepain_z);    
470 }
471 void spiderbot_spawn()
472 {
473     self.frame              = 5;
474     self.tur_head.frame     = 1;
475     self.think              = spiderbot_think;
476     self.nextthink          = time;
477     self.vehicle_health     = autocvar_g_vehicle_spiderbot_health;
478     self.vehicle_shield     = autocvar_g_vehicle_spiderbot_shield;
479     self.movetype           = MOVETYPE_WALK;
480     self.solid              = SOLID_SLIDEBOX;
481     self.alpha              = self.tur_head.alpha = self.gun1.alpha = self.gun2.alpha = 1;
482     self.tur_head.angles    = '0 0 0';
483
484     setorigin(self, self.pos1 + '0 0 128');
485     self.angles = self.pos2;
486     self.vehicle_impact = spider_impact;
487 }
488
489 void spiderbot_headfade()
490 {
491         self.think = spiderbot_headfade;
492         self.nextthink = self.fade_time;
493         self.alpha = 1 - (time - self.fade_time) * self.fade_rate;
494
495     if(self.cnt < time || self.alpha < 0.1)
496     {
497         if(self.alpha > 0.1)
498         {
499             sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
500             pointparticles(particleeffectnum("explosion_big"), self.origin + '0 0 100', '0 0 0', 1);
501         }
502         remove(self);
503     }
504 }
505
506 void spiderbot_blowup()
507 {
508     if(self.cnt > time)
509     {
510         if(random() < 0.1)
511         {
512             sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
513             pointparticles(particleeffectnum("explosion_small"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
514         }
515         self.nextthink = time + 0.1;
516         return;
517     }
518     
519     entity h, g1, g2, b;
520     b = spawn();
521     h = spawn();
522     g1 = spawn();
523     g2 = spawn();
524
525     setmodel(b,  "models/vehicles/spiderbot.dpm");
526     setmodel(h,  "models/vehicles/spiderbot_top.dpm");
527     setmodel(g1, "models/vehicles/spiderbot_barrels.dpm");
528     setmodel(g2, "models/vehicles/spiderbot_barrels.dpm");
529
530     setorigin(b, self.origin);
531     b.frame         = 11;
532     b.angles        = self.angles;
533     setsize(b, self.mins, self.maxs);
534
535     setorigin(h, gettaginfo(self, gettagindex(self, "tag_head")));
536     h.movetype      = MOVETYPE_BOUNCE;
537     h.solid         = SOLID_BBOX;
538     h.velocity      = v_up * (500 + random() * 500) + randomvec() * 128;
539     h.modelflags    = MF_ROCKET;
540     h.effects       = EF_FLAME | EF_LOWPRECISION;
541     h.avelocity     = randomvec() * 360;
542
543     h.alpha         = 1;
544     h.cnt           = time + (3.5 * random());
545     h.fade_rate     = 1 / min(autocvar_g_vehicle_spiderbot_respawntime, 10);
546     h.fade_time     = time;
547     h.think         = spiderbot_headfade;
548     h.nextthink     = time;
549
550     setorigin(g1, gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_hardpoint01")));
551     g1.movetype     = MOVETYPE_TOSS;
552     g1.solid        = SOLID_CORPSE;
553     g1.velocity     = v_forward * 700 + (randomvec() * 32);
554     g1.avelocity    = randomvec() * 180;
555
556     setorigin(g2, gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_hardpoint02")));
557     g2.movetype     = MOVETYPE_TOSS;
558     g2.solid        = SOLID_CORPSE;
559     g2.velocity     = v_forward * 700 + (randomvec() * 32);
560     g2.avelocity    = randomvec() * 180;
561
562     h.colormod = b.colormod = g1.colormod = g2.colormod = '-2 -2 -2';
563
564     SUB_SetFade(b,  time + 5, min(autocvar_g_vehicle_spiderbot_respawntime, 1));
565     //SUB_SetFade(h,  time, min(autocvar_g_vehicle_spiderbot_respawntime, 10));
566     SUB_SetFade(g1, time, min(autocvar_g_vehicle_spiderbot_respawntime, 10));
567     SUB_SetFade(g2, time, min(autocvar_g_vehicle_spiderbot_respawntime, 10));
568
569     RadiusDamage (self, self, 250, 15, 250, world, world, 250, DEATH_SBBLOWUP, world);
570
571     self.alpha = self.tur_head.alpha = self.gun1.alpha = self.gun2.alpha = -1;
572     self.movetype   = MOVETYPE_NONE;
573     self.deadflag   = DEAD_DEAD;
574     self.solid      = SOLID_NOT;
575     self.tur_head.effects  &~=  EF_FLAME;
576         self.vehicle_hudmodel.viewmodelforclient = self;
577 }
578
579 void spiderbot_die()
580 {
581     self.health             = 0;
582     self.event_damage       = SUB_Null;
583     self.takedamage         = DAMAGE_NO;
584     self.touch              = SUB_Null;
585     self.cnt                = 3.4 + time + random() * 2;
586     self.think              = spiderbot_blowup;
587     self.nextthink          = time;
588     self.deadflag           = DEAD_DYING;
589         self.frame              = 5;
590         self.tur_head.effects  |= EF_FLAME;
591         self.colormod           = self.tur_head.colormod = '-1 -1 -1';
592         self.frame              = 10;
593         self.movetype           = MOVETYPE_TOSS;
594 }
595
596 void vewhicle_spiderbot_dinit()
597 {
598     if not (vehicle_initialize(
599              "Spiderbot",
600              "models/vehicles/spiderbot.dpm",
601              "models/vehicles/spiderbot_top.dpm",
602              "models/vehicles/spiderbot_cockpit.dpm",
603              "tag_head", "tag_hud", "",
604              HUD_SPIDERBOT,
605              SPIDERBOT_MIN, SPIDERBOT_MAX,
606              FALSE,
607              spiderbot_spawn, autocvar_g_vehicle_spiderbot_respawntime,
608              spiderbot_frame,
609              spiderbot_enter, spiderbot_exit,
610              spiderbot_die,   spiderbot_think,
611              FALSE))
612     {
613         remove(self);
614         return;
615     }
616
617
618     self.gun1               = spawn();
619     self.gun2               = spawn();
620
621     setmodel(self.gun1, "models/vehicles/spiderbot_barrels.dpm");
622     setmodel(self.gun2, "models/vehicles/spiderbot_barrels.dpm");
623
624     setattachment(self.gun1, self.tur_head, "tag_hardpoint01");
625     setattachment(self.gun2, self.tur_head, "tag_hardpoint02");
626
627     self.gravity            = 2;
628     self.mass               = 5000;
629 }
630
631 void spawnfunc_vehicle_spiderbot()
632 {
633     self.vehicle_flags |= VHF_DMGSHAKE;
634     //self.vehicle_flags |= VHF_DMGROLL;
635     //self.vehicle_flags |= VHF_DMGHEADROLL;
636     
637     precache_model ( "models/vhshield.md3");
638     precache_model ( "models/vehicles/spiderbot.dpm");
639     precache_model ( "models/vehicles/spiderbot_top.dpm");
640     precache_model ( "models/vehicles/spiderbot_barrels.dpm");
641     precache_model ( "models/vehicles/spiderbot_cockpit.dpm");
642     precache_model ( "models/uziflash.md3");
643
644     precache_sound ( "weapons/uzi_fire.wav" );
645     precache_sound ( "weapons/rocket_impact.wav");
646     
647     precache_sound ( "vehicles/spiderbot_die.wav");
648     precache_sound ( "vehicles/spiderbot_idle.wav");
649     precache_sound ( "vehicles/spiderbot_jump.wav");
650     precache_sound ( "vehicles/spiderbot_strafe.wav");
651     precache_sound ( "vehicles/spiderbot_walk.wav");
652     precache_sound ( "vehicles/spiderbot_land.wav");
653
654     vehicles_configcheck("vehicle_spiderbot.cfg", autocvar_g_vehicle_spiderbot_health);
655     if(autocvar_g_vehicle_spiderbot_shield)
656         self.vehicle_flags |= VHF_HASSHIELD;
657
658     if(autocvar_g_vehicle_spiderbot_shield_regen)
659         self.vehicle_flags |= VHF_SHIELDREGEN;
660
661     if(autocvar_g_vehicle_spiderbot_health_regen)
662         self.vehicle_flags |= VHF_HEALTHREGEN;
663     
664     self.think = vewhicle_spiderbot_dinit;
665     
666     if(g_assault)
667         self.nextthink = time + 0.5;
668     else
669         self.nextthink = time + (autocvar_g_vehicles_delayspawn ? autocvar_g_vehicle_spiderbot_respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter) : 0.5);
670 }
671 #endif // SVQC