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