Kill g_antilag_bullets (always assume 1); kill bullet gravity.
[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;
6
7 float autocvar_g_vehicle_spiderbot_respawntime;
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_turnspeed_strafe;
14 float autocvar_g_vehicle_spiderbot_movement_inertia;
15
16 float autocvar_g_vehicle_spiderbot_springlength;
17 float autocvar_g_vehicle_spiderbot_springup;
18 float autocvar_g_vehicle_spiderbot_springblend;
19 float autocvar_g_vehicle_spiderbot_tiltlimit;
20
21 float autocvar_g_vehicle_spiderbot_head_pitchlimit_down;
22 float autocvar_g_vehicle_spiderbot_head_pitchlimit_up;
23 float autocvar_g_vehicle_spiderbot_head_turnlimit;
24 float autocvar_g_vehicle_spiderbot_head_turnspeed;
25
26 //float autocvar_g_vehicle_spiderbot_energy;
27 //float autocvar_g_vehicle_spiderbot_energy_regen;
28 //float autocvar_g_vehicle_spiderbot_energy_regen_pause;
29
30 float autocvar_g_vehicle_spiderbot_health;
31 float autocvar_g_vehicle_spiderbot_health_regen;
32 float autocvar_g_vehicle_spiderbot_health_regen_pause;
33
34 float autocvar_g_vehicle_spiderbot_shield;
35 float autocvar_g_vehicle_spiderbot_shield_regen;
36 float autocvar_g_vehicle_spiderbot_shield_regen_pause;
37
38 float autocvar_g_vehicle_spiderbot_minigun_damage;
39 float autocvar_g_vehicle_spiderbot_minigun_refire;
40 float autocvar_g_vehicle_spiderbot_minigun_spread;
41 float autocvar_g_vehicle_spiderbot_minigun_ammo_cost;
42 float autocvar_g_vehicle_spiderbot_minigun_ammo_max;
43 float autocvar_g_vehicle_spiderbot_minigun_ammo_regen;
44 float autocvar_g_vehicle_spiderbot_minigun_ammo_regen_pause;
45 float autocvar_g_vehicle_spiderbot_minigun_force;
46 float autocvar_g_vehicle_spiderbot_minigun_speed;
47 float autocvar_g_vehicle_spiderbot_minigun_bulletconstant;
48
49 float autocvar_g_vehicle_spiderbot_rocket_damage;
50 float autocvar_g_vehicle_spiderbot_rocket_force;
51 float autocvar_g_vehicle_spiderbot_rocket_radius;
52 float autocvar_g_vehicle_spiderbot_rocket_speed;
53 float autocvar_g_vehicle_spiderbot_rocket_spread;
54 float autocvar_g_vehicle_spiderbot_rocket_refire;
55 float autocvar_g_vehicle_spiderbot_rocket_refire2;
56 float autocvar_g_vehicle_spiderbot_rocket_reload;
57 float autocvar_g_vehicle_spiderbot_rocket_health;
58 float autocvar_g_vehicle_spiderbot_rocket_noise;
59 float autocvar_g_vehicle_spiderbot_rocket_turnrate;
60 float autocvar_g_vehicle_spiderbot_rocket_lifetime;
61
62 vector autocvar_g_vehicle_spiderbot_bouncepain;
63
64
65 void spiderbot_exit(float eject);
66 void spiderbot_enter();
67 void spiderbot_spawn(float);
68 #define SBRM_FIRST 0
69 #define SBRM_VOLLY 0
70 #define SBRM_GUIDE 1
71 #define SBRM_ARTILLERY 2
72 #define SBRM_LAST 2
73
74 void spiderbot_rocket_artillery()
75 {
76     self.nextthink  = time;
77     UpdateCSQCProjectile(self);
78 }
79
80 void spiderbot_rocket_unguided()
81 {
82     vector newdir, olddir;
83
84     self.nextthink  = time;
85
86     olddir = normalize(self.velocity);
87     newdir = normalize(self.pos1 - 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 || vlen(self.pos1 - self.origin) < 16)
93         self.use();
94 }
95
96 void spiderbot_rocket_guided()
97 {
98     vector newdir, olddir;
99
100     self.nextthink  = time;
101
102     if (!self.realowner.vehicle)
103         self.think = spiderbot_rocket_unguided;
104
105     crosshair_trace(self.realowner);
106     olddir = normalize(self.velocity);
107     newdir = normalize(trace_endpos - self.origin) + randomvec() * autocvar_g_vehicle_spiderbot_rocket_noise;
108     self.velocity = normalize(olddir + newdir * autocvar_g_vehicle_spiderbot_rocket_turnrate) * autocvar_g_vehicle_spiderbot_rocket_speed;
109
110     UpdateCSQCProjectile(self);
111
112     if (self.owner.deadflag != DEAD_NO || self.cnt < time)
113         self.use();
114 }
115
116 void spiderbot_guide_release()
117 {
118     entity rkt;
119     rkt = findchainentity(realowner, self.owner);
120     if (!rkt)
121         return;
122
123     crosshair_trace(self.owner);
124     while(rkt)
125     {
126         if(rkt.think == spiderbot_rocket_guided)
127         {
128             rkt.pos1 = trace_endpos;
129             rkt.think = spiderbot_rocket_unguided;
130         }
131         rkt = rkt.chain;
132     }
133 }
134
135 float spiberbot_calcartillery_flighttime;
136 vector spiberbot_calcartillery(vector org, vector tgt, float ht)
137 {
138         float grav, sdist, zdist, vs, vz, jumpheight;
139         vector sdir;
140
141         grav  = autocvar_sv_gravity;
142         zdist = tgt_z - org_z;
143         sdist = vlen(tgt - org - zdist * '0 0 1');
144         sdir  = normalize(tgt - org - zdist * '0 0 1');
145
146         // how high do we need to go?
147         jumpheight = fabs(ht);
148         if(zdist > 0)
149                 jumpheight = jumpheight + zdist;
150
151         // push so high...
152         vz = sqrt(2 * grav * jumpheight); // NOTE: sqrt(positive)!
153
154         // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
155         if(ht < 0)
156                 if(zdist < 0)
157                         vz = -vz;
158
159         vector solution;
160         solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
161         // ALWAYS solvable because jumpheight >= zdist
162         if(!solution_z)
163                 solution_y = solution_x; // just in case it is not solvable due to roundoff errors, assume two equal solutions at their center (this is mainly for the usual case with ht == 0)
164         if(zdist == 0)
165                 solution_x = solution_y; // solution_x is 0 in this case, so don't use it, but rather use solution_y (which will be sqrt(0.5 * jumpheight / grav), actually)
166
167         if(zdist < 0)
168         {
169                 // down-jump
170                 if(ht < 0)
171                 {
172                         // almost straight line type
173                         // jump apex is before the jump
174                         // we must take the larger one
175                         spiberbot_calcartillery_flighttime = solution_y;
176                 }
177                 else
178                 {
179                         // regular jump
180                         // jump apex is during the jump
181                         // we must take the larger one too
182                         spiberbot_calcartillery_flighttime = solution_y;
183                 }
184         }
185         else
186         {
187                 // up-jump
188                 if(ht < 0)
189                 {
190                         // almost straight line type
191                         // jump apex is after the jump
192                         // we must take the smaller one
193                         spiberbot_calcartillery_flighttime = solution_x;
194                 }
195                 else
196                 {
197                         // regular jump
198                         // jump apex is during the jump
199                         // we must take the larger one
200                         spiberbot_calcartillery_flighttime = solution_y;
201                 }
202         }
203         vs = sdist / spiberbot_calcartillery_flighttime;
204
205         // finally calculate the velocity
206         return sdir * vs + '0 0 1' * vz;
207 }
208
209 void spiderbot_rocket_do()
210 {
211
212     vector v;
213     entity rocket = world;
214
215     if (self.wait != -10)
216     {
217         if (self.owner.BUTTON_ATCK2 && self.vehicle_weapon2mode == SBRM_GUIDE)
218         {
219             if (self.wait == 1)
220             if (self.tur_head.frame == 9 || self.tur_head.frame == 1)
221             {
222                 if(self.gun2.cnt < time && self.tur_head.frame == 9)
223                     self.tur_head.frame = 1;
224
225                 return;
226             }
227             self.wait = 1;
228         }
229         else
230         {
231             if(self.wait)
232                 spiderbot_guide_release();
233
234             self.wait = 0;
235         }
236     }
237
238     if(self.gun2.cnt > time)
239         return;
240
241     if (self.tur_head.frame >= 9)
242     {
243         self.tur_head.frame = 1;
244         self.wait = 0;
245     }
246
247     if (self.wait != -10)
248         if (!self.owner.BUTTON_ATCK2)
249             return;
250
251
252     v = gettaginfo(self.tur_head,gettagindex(self.tur_head,"tag_fire"));
253
254     switch(self.vehicle_weapon2mode)
255     {
256         case SBRM_VOLLY:
257             rocket = vehicles_projectile("spiderbot_rocket_launch", "weapons/rocket_fire.wav",
258                                    v, normalize(randomvec() * autocvar_g_vehicle_spiderbot_rocket_spread + v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed,
259                                    autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1,
260                                    DEATH_VH_SPID_ROCKET, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, FALSE, TRUE, self.owner);
261             crosshair_trace(self.owner);
262             float _dist = (random() * autocvar_g_vehicle_spiderbot_rocket_radius) + vlen(v - trace_endpos);
263             _dist -= (random() * autocvar_g_vehicle_spiderbot_rocket_radius) ;
264             rocket.nextthink  = time + (_dist / autocvar_g_vehicle_spiderbot_rocket_speed);
265             rocket.think     = vehicles_projectile_explode;
266
267             if(self.owner.BUTTON_ATCK2 && self.tur_head.frame == 1)
268                 self.wait = -10;
269             break;
270         case SBRM_GUIDE:
271             rocket = vehicles_projectile("spiderbot_rocket_launch", "weapons/rocket_fire.wav",
272                                    v, normalize(v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed,
273                                    autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1,
274                                    DEATH_VH_SPID_ROCKET, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, FALSE, FALSE, self.owner);
275             crosshair_trace(self.owner);
276             rocket.pos1       = trace_endpos;
277             rocket.nextthink  = time;
278             rocket.think      = spiderbot_rocket_guided;
279
280
281         break;
282         case SBRM_ARTILLERY:
283             rocket = vehicles_projectile("spiderbot_rocket_launch", "weapons/rocket_fire.wav",
284                                    v, normalize(v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed,
285                                    autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1,
286                                    DEATH_VH_SPID_ROCKET, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, FALSE, TRUE, self.owner);
287
288             crosshair_trace(self.owner);
289
290             rocket.pos1       = trace_endpos + randomvec() * (0.75 * autocvar_g_vehicle_spiderbot_rocket_radius);
291             rocket.pos1_z       = trace_endpos_z;
292
293             traceline(v, v + '0 0 1' * MAX_SHOT_DISTANCE, MOVE_WORLDONLY, self);
294             float h1 = 0.75 * vlen(v - trace_endpos);
295
296             //v = trace_endpos;
297             traceline(v , rocket.pos1 + '0 0 1' * MAX_SHOT_DISTANCE, MOVE_WORLDONLY, self);
298             float h2 = 0.75 * vlen(rocket.pos1 - v);
299
300             rocket.velocity  = spiberbot_calcartillery(v, rocket.pos1, ((h1 < h2) ? h1 : h2));
301             rocket.movetype  = MOVETYPE_TOSS;
302             rocket.gravity   = 1;
303             //rocket.think     = spiderbot_rocket_artillery;
304         break;
305     }
306     rocket.classname  = "spiderbot_rocket";
307
308     rocket.cnt = time + autocvar_g_vehicle_spiderbot_rocket_lifetime;
309
310     self.tur_head.frame += 1;
311     if (self.tur_head.frame == 9)
312         self.attack_finished_single = autocvar_g_vehicle_spiderbot_rocket_reload;
313     else
314         self.attack_finished_single = ((self.vehicle_weapon2mode ==  SBRM_VOLLY) ? autocvar_g_vehicle_spiderbot_rocket_refire2 : autocvar_g_vehicle_spiderbot_rocket_refire);
315
316     self.gun2.cnt = time + self.attack_finished_single;
317 }
318
319 float spiderbot_aiframe()
320 {
321     return FALSE;
322 }
323
324 float spiderbot_frame()
325 {
326     vector ad, vf;
327     entity player, spider;
328     float ftmp;
329
330         if(intermission_running)
331                 return 1;
332
333     player = self;
334     spider = self.vehicle;
335     self   = spider;
336
337     vehicles_painframe();
338
339     player.BUTTON_ZOOM      = 0;
340     player.BUTTON_CROUCH    = 0;
341     player.switchweapon     = 0;
342
343
344 #if 1 // 0 to enable per-gun impact aux crosshairs
345     // Avarage gun impact point's -> aux cross
346     ad = gettaginfo(spider.tur_head, gettagindex(spider.tur_head, "tag_hardpoint01"));
347     vf = v_forward;
348     ad += gettaginfo(spider.tur_head, gettagindex(spider.tur_head, "tag_hardpoint02"));
349     vf += v_forward;
350     ad = ad * 0.5;
351     v_forward = vf * 0.5;
352     traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, spider);
353     UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload1) + ('0 1 0' * (1 - player.vehicle_reload1)), 0);
354 #else
355     ad = gettaginfo(spider.gun1, gettagindex(spider.gun1, "barrels"));
356     traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, spider);
357     UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload1) + ('0 1 0' * (1 - player.vehicle_reload1)), 0);
358     vf = ad;
359     ad = gettaginfo(spider.gun2, gettagindex(spider.gun2, "barrels"));
360     traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, spider);
361     UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload1) + ('0 1 0' * (1 - player.vehicle_reload1)), 1);
362     ad = 0.5 * (ad + vf);
363 #endif
364
365     crosshair_trace(player);
366     ad = vectoangles(normalize(trace_endpos - ad));
367     ad = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(spider.angles), AnglesTransform_FromAngles(ad))) - spider.tur_head.angles;
368     ad = AnglesTransform_Normalize(ad, TRUE);
369     //UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload2) + ('0 1 0' * (1 - player.vehicle_reload2)), 2);
370
371     // Rotate head
372     ftmp = autocvar_g_vehicle_spiderbot_head_turnspeed * sys_frametime;
373     ad_y = bound(-ftmp, ad_y, ftmp);
374     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);
375
376     // Pitch head
377     ad_x = bound(ftmp * -1, ad_x, ftmp);
378     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);
379
380
381     //fixedmakevectors(spider.angles);
382     makevectors(spider.angles + '-2 0 0' * spider.angles_x);
383
384     movelib_groundalign4point(autocvar_g_vehicle_spiderbot_springlength, autocvar_g_vehicle_spiderbot_springup, autocvar_g_vehicle_spiderbot_springblend, autocvar_g_vehicle_spiderbot_tiltlimit);
385
386     if(spider.flags & FL_ONGROUND)
387     {
388         if(spider.frame == 4 && self.tur_head.wait != 0)
389         {
390             sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_land.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
391             spider.frame = 5;
392         }
393
394         if(player.BUTTON_JUMP && self.tur_head.wait < time)
395         {
396             sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_jump.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
397             //dprint("spiderbot_jump:", ftos(soundlength("vehicles/spiderbot_jump.wav")), "\n");
398             self.delay = 0;
399
400             self.tur_head.wait = time + 2;
401             player.BUTTON_JUMP = 0;
402             spider.velocity   = v_forward * 700 + v_up * 600;
403             spider.frame = 4;
404         }
405         else
406         {
407             if(vlen(player.movement) == 0)
408             {
409                 if(self.sound_nexttime < time || self.delay != 3)
410                 {
411                     self.delay = 3;
412                     self.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_idle.wav");
413                     //dprint("spiderbot_idle:", ftos(soundlength("vehicles/spiderbot_idle.wav")), "\n");
414                     sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_idle.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
415                 }
416                 movelib_beak_simple(autocvar_g_vehicle_spiderbot_speed_stop);
417                 spider.frame = 5;
418             }
419             else
420             {
421                 // Turn Body
422                 if(player.movement_x == 0 && player.movement_y != 0)
423                     ftmp = autocvar_g_vehicle_spiderbot_turnspeed_strafe * sys_frametime;
424                 else
425                     ftmp = autocvar_g_vehicle_spiderbot_turnspeed * sys_frametime;
426
427                 ftmp = bound(-ftmp, spider.tur_head.angles_y, ftmp);
428                 spider.angles_y = anglemods(spider.angles_y + ftmp);
429                 spider.tur_head.angles_y -= ftmp;
430
431                 if(player.movement_x != 0)
432                 {
433                     if(player.movement_x > 0)
434                     {
435                         player.movement_x = 1;
436                         spider.frame = 0;
437                     }
438                     else if(player.movement_x < 0)
439                     {
440                         player.movement_x = -1;
441                         spider.frame = 1;
442                     }
443                     player.movement_y = 0;
444                     movelib_move_simple(normalize(v_forward * player.movement_x),autocvar_g_vehicle_spiderbot_speed_walk,autocvar_g_vehicle_spiderbot_movement_inertia);
445
446                     if(self.sound_nexttime < time || self.delay != 1)
447                     {
448                         self.delay = 1;
449                         self.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_walk.wav");
450                         sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_walk.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
451                         //dprint("spiderbot_walk:", ftos(soundlength("vehicles/spiderbot_walk.wav")), "\n");
452                     }
453                 }
454                 else if(player.movement_y != 0)
455                 {
456                     if(player.movement_y < 0)
457                     {
458                         player.movement_y = -1;
459                         spider.frame = 2;
460                     }
461                     else if(player.movement_y > 0)
462                     {
463                         player.movement_y = 1;
464                         spider.frame = 3;
465                     }
466                     movelib_move_simple(normalize(v_right * player.movement_y),autocvar_g_vehicle_spiderbot_speed_strafe,autocvar_g_vehicle_spiderbot_movement_inertia);
467                     if(self.sound_nexttime < time || self.delay != 2)
468                     {
469                         self.delay = 2;
470                         self.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_strafe.wav");
471                         sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_strafe.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
472                         //dprint("spiderbot_strafe:", ftos(soundlength("vehicles/spiderbot_strafe.wav")), "\n");
473                     }
474                 }
475             }
476         }
477     }
478
479     self.angles_x = bound(-autocvar_g_vehicle_spiderbot_tiltlimit, self.angles_x, autocvar_g_vehicle_spiderbot_tiltlimit);
480     self.angles_z = bound(-autocvar_g_vehicle_spiderbot_tiltlimit, self.angles_z, autocvar_g_vehicle_spiderbot_tiltlimit);
481
482     if(player.BUTTON_ATCK)
483     {
484         spider.cnt = time;
485         if(spider.vehicle_ammo1 >= autocvar_g_vehicle_spiderbot_minigun_ammo_cost && spider.tur_head.attack_finished_single <= time)
486         {
487             entity gun;
488             vector v;
489             spider.misc_bulletcounter += 1;
490
491             self = player;
492
493             mod(spider.misc_bulletcounter, 2) ? gun = spider.gun1 : gun = spider.gun2;
494             v = gettaginfo(gun, gettagindex(gun, "barrels"));
495             v_forward = normalize(v_forward);
496             v += v_forward * 50;
497
498 //void fireBallisticBullet(vector start, vector dir, float spread, float pSpeed, float lifetime, float damage, float force, float dtype, float tracereffects, float bulletconstant)
499
500             fireBallisticBullet(v, v_forward, autocvar_g_vehicle_spiderbot_minigun_spread, autocvar_g_vehicle_spiderbot_minigun_speed,
501                                 5, autocvar_g_vehicle_spiderbot_minigun_damage, autocvar_g_vehicle_spiderbot_minigun_force, DEATH_VH_SPID_MINIGUN, 0, autocvar_g_vehicle_spiderbot_minigun_bulletconstant);
502
503             endFireBallisticBullet();
504
505 //            fireBullet (v, v_forward, autocvar_g_vehicle_spiderbot_minigun_spread, autocvar_g_vehicle_spiderbot_minigun_damage,
506 //                autocvar_g_vehicle_spiderbot_minigun_spread, DEATH_VH_SPID_MINIGUN, 0);
507
508             sound (gun, CH_WEAPON_A, "weapons/uzi_fire.wav", VOL_BASE, ATTEN_NORM);
509             //trailparticles(self, particleeffectnum("spiderbot_minigun_trail"), v, trace_endpos);
510             pointparticles(particleeffectnum("spiderbot_minigun_muzzleflash"), v, v_forward * 2500, 1);
511
512             self = spider;
513
514             spider.vehicle_ammo1 -= autocvar_g_vehicle_spiderbot_minigun_ammo_cost;
515             spider.tur_head.attack_finished_single = time + autocvar_g_vehicle_spiderbot_minigun_refire;
516             player.vehicle_ammo1 = (spider.vehicle_ammo1 / autocvar_g_vehicle_spiderbot_minigun_ammo_max) * 100;
517             spider.gun1.angles_z += 45;
518             spider.gun2.angles_z -= 45;
519             if(spider.gun1.angles_z >= 360)
520             {
521                 spider.gun1.angles_z = 0;
522                 spider.gun2.angles_z = 0;
523             }
524         }
525     }
526     else
527         vehicles_regen(spider.cnt, vehicle_ammo1, autocvar_g_vehicle_spiderbot_minigun_ammo_max,
528                                            autocvar_g_vehicle_spiderbot_minigun_ammo_regen_pause,
529                                            autocvar_g_vehicle_spiderbot_minigun_ammo_regen, frametime, FALSE);
530
531
532     spiderbot_rocket_do();
533
534     if(self.vehicle_flags  & VHF_SHIELDREGEN)
535         vehicles_regen(spider.dmg_time, vehicle_shield, autocvar_g_vehicle_spiderbot_shield, autocvar_g_vehicle_spiderbot_shield_regen_pause, autocvar_g_vehicle_spiderbot_shield_regen, frametime, TRUE);
536
537     if(self.vehicle_flags  & VHF_HEALTHREGEN)
538         vehicles_regen(spider.dmg_time, vehicle_health, autocvar_g_vehicle_spiderbot_health, autocvar_g_vehicle_spiderbot_health_regen_pause, autocvar_g_vehicle_spiderbot_health_regen, frametime, FALSE);
539
540     player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
541     player.vehicle_ammo2 = spider.tur_head.frame;
542
543     if(spider.gun2.cnt <= time)
544         player.vehicle_reload2 = 100;
545     else
546         player.vehicle_reload2 = 100 - ((spider.gun2.cnt - time) / spider.attack_finished_single) * 100;
547
548     setorigin(player, spider.origin + '0 0 1' * SPIDERBOT_MAX_z);
549     player.velocity = spider.velocity;
550
551     VEHICLE_UPDATE_PLAYER(player, health, spiderbot);
552
553     if(self.vehicle_flags & VHF_HASSHIELD)
554         VEHICLE_UPDATE_PLAYER(player, shield, spiderbot);
555
556     self = player;
557     return 1;
558 }
559 void spiderbot_think()
560 {
561     if(self.flags & FL_ONGROUND)
562         movelib_beak_simple(autocvar_g_vehicle_spiderbot_speed_stop);
563
564     self.nextthink = time;
565 }
566
567 void spiderbot_enter()
568 {
569     self.vehicle_weapon2mode = SBRM_GUIDE;
570     self.movetype   = MOVETYPE_WALK;
571     CSQCVehicleSetup(self.owner, 0);
572     self.owner.vehicle_health = (self.vehicle_health / autocvar_g_vehicle_spiderbot_health) * 100;
573     self.owner.vehicle_shield = (self.vehicle_shield / autocvar_g_vehicle_spiderbot_shield) * 100;
574
575     if(self.owner.flagcarried)
576     {
577         setattachment(self.owner.flagcarried, self.tur_head, "");
578         setorigin(self.owner.flagcarried, '-20 0 120');
579     }
580 }
581
582 void spiderbot_exit(float eject)
583 {
584     entity e;
585     vector spot;
586
587     e = findchain(classname,"spiderbot_rocket");
588     while(e)
589     {
590         if(e.owner == self.owner)
591         {
592             e.realowner = self.owner;
593             e.owner = world;
594         }
595         e = e.chain;
596     }
597
598     //self.velocity   = '0 0 0';
599     self.think      = spiderbot_think;
600     self.nextthink  = time;
601     self.frame      = 5;
602     self.movetype   = MOVETYPE_WALK;
603
604     if (!self.owner)
605         return;
606
607         makevectors(self.angles);
608         if(eject)
609         {
610             spot = self.origin + v_forward * 100 + '0 0 64';
611             spot = vehicles_findgoodexit(spot);
612             setorigin(self.owner , spot);
613             self.owner.velocity = (v_up + v_forward * 0.25) * 750;
614             self.owner.oldvelocity = self.owner.velocity;
615         }
616         else
617         {
618                 if(vlen(self.velocity) > autocvar_g_vehicle_spiderbot_speed_strafe)
619                 {
620                         self.owner.velocity = normalize(self.velocity) * vlen(self.velocity);
621                         self.owner.velocity_z += 200;
622                         spot = self.origin + v_forward * 128 + '0 0 64';
623                         spot = vehicles_findgoodexit(spot);
624                 }
625                 else
626                 {
627                         self.owner.velocity = self.velocity * 0.5;
628                         self.owner.velocity_z += 10;
629                         spot = self.origin + v_forward * 256 + '0 0 64';
630                         spot = vehicles_findgoodexit(spot);
631                 }
632             self.owner.oldvelocity = self.owner.velocity;
633             setorigin(self.owner , spot);
634         }
635
636         antilag_clear(self.owner);
637     self.owner = world;
638 }
639
640 void spider_impact()
641 {
642     if(autocvar_g_vehicle_spiderbot_bouncepain_x)
643         vehilces_impact(autocvar_g_vehicle_spiderbot_bouncepain_x, autocvar_g_vehicle_spiderbot_bouncepain_y, autocvar_g_vehicle_spiderbot_bouncepain_z);
644 }
645
646 void spiderbot_headfade()
647 {
648         self.think = spiderbot_headfade;
649         self.nextthink = self.fade_time;
650         self.alpha = 1 - (time - self.fade_time) * self.fade_rate;
651
652     if(self.cnt < time || self.alpha < 0.1)
653     {
654         if(self.alpha > 0.1)
655         {
656             sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
657             pointparticles(particleeffectnum("explosion_big"), self.origin + '0 0 100', '0 0 0', 1);
658         }
659         remove(self);
660     }
661 }
662
663 void spiderbot_blowup()
664 {
665     if(self.cnt > time)
666     {
667         if(random() < 0.1)
668         {
669             sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
670             pointparticles(particleeffectnum("explosion_small"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
671         }
672         self.nextthink = time + 0.1;
673         return;
674     }
675
676     entity h, g1, g2, b;
677     b = spawn();
678     h = spawn();
679     g1 = spawn();
680     g2 = spawn();
681
682     setmodel(b,  "models/vehicles/spiderbot.dpm");
683     setmodel(h,  "models/vehicles/spiderbot_top.dpm");
684     setmodel(g1, "models/vehicles/spiderbot_barrels.dpm");
685     setmodel(g2, "models/vehicles/spiderbot_barrels.dpm");
686
687     setorigin(b, self.origin);
688     b.frame         = 11;
689     b.angles        = self.angles;
690     setsize(b, self.mins, self.maxs);
691
692     setorigin(h, gettaginfo(self, gettagindex(self, "tag_head")));
693     h.movetype      = MOVETYPE_BOUNCE;
694     h.solid         = SOLID_BBOX;
695     h.velocity      = v_up * (500 + random() * 500) + randomvec() * 128;
696     h.modelflags    = MF_ROCKET;
697     h.effects       = EF_FLAME | EF_LOWPRECISION;
698     h.avelocity     = randomvec() * 360;
699
700     h.alpha         = 1;
701     h.cnt           = time + (3.5 * random());
702     h.fade_rate     = 1 / min(autocvar_g_vehicle_spiderbot_respawntime, 10);
703     h.fade_time     = time;
704     h.think         = spiderbot_headfade;
705     h.nextthink     = time;
706
707     setorigin(g1, gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_hardpoint01")));
708     g1.movetype     = MOVETYPE_TOSS;
709     g1.solid        = SOLID_CORPSE;
710     g1.velocity     = v_forward * 700 + (randomvec() * 32);
711     g1.avelocity    = randomvec() * 180;
712
713     setorigin(g2, gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_hardpoint02")));
714     g2.movetype     = MOVETYPE_TOSS;
715     g2.solid        = SOLID_CORPSE;
716     g2.velocity     = v_forward * 700 + (randomvec() * 32);
717     g2.avelocity    = randomvec() * 180;
718
719     h.colormod = b.colormod = g1.colormod = g2.colormod = '-2 -2 -2';
720
721     SUB_SetFade(b,  time + 5, min(autocvar_g_vehicle_spiderbot_respawntime, 1));
722     //SUB_SetFade(h,  time, min(autocvar_g_vehicle_spiderbot_respawntime, 10));
723     SUB_SetFade(g1, time, min(autocvar_g_vehicle_spiderbot_respawntime, 10));
724     SUB_SetFade(g2, time, min(autocvar_g_vehicle_spiderbot_respawntime, 10));
725
726     RadiusDamage (self, self.enemy, 250, 15, 250, world, 250, DEATH_VH_SPID_DEATH, world);
727
728     self.alpha = self.tur_head.alpha = self.gun1.alpha = self.gun2.alpha = -1;
729     self.movetype   = MOVETYPE_NONE;
730     self.deadflag   = DEAD_DEAD;
731     self.solid      = SOLID_NOT;
732     self.tur_head.effects  &=  ~EF_FLAME;
733     self.vehicle_hudmodel.viewmodelforclient = self;
734 }
735
736 void spiderbot_die()
737 {
738     self.health             = 0;
739     self.event_damage       = func_null;
740     self.takedamage         = DAMAGE_NO;
741     self.touch              = func_null;
742     self.cnt                = 3.4 + time + random() * 2;
743     self.think              = spiderbot_blowup;
744     self.nextthink          = time;
745     self.deadflag           = DEAD_DYING;
746         self.frame              = 5;
747         self.tur_head.effects  |= EF_FLAME;
748         self.colormod           = self.tur_head.colormod = '-1 -1 -1';
749         self.frame              = 10;
750         self.movetype           = MOVETYPE_TOSS;
751 }
752
753 float spiderbot_impulse(float _imp)
754 {
755     switch(_imp)
756     {
757         case 10:
758         case 15:
759         case 18:
760             self.vehicle.vehicle_weapon2mode += 1;
761             if(self.vehicle.vehicle_weapon2mode > SBRM_LAST)
762                 self.vehicle.vehicle_weapon2mode = SBRM_FIRST;
763
764             //centerprint(self, strcat("Rocket mode is ", ftos(self.vehicle.vehicle_weapon2mode)));
765             CSQCVehicleSetup(self, 0);
766             return TRUE;
767         case 12:
768         case 16:
769         case 19:
770             self.vehicle.vehicle_weapon2mode -= 1;
771             if(self.vehicle.vehicle_weapon2mode < SBRM_FIRST)
772                 self.vehicle.vehicle_weapon2mode = SBRM_LAST;
773
774             //centerprint(self, strcat("Rocket mode is ", ftos(self.vehicle.vehicle_weapon2mode)));
775             CSQCVehicleSetup(self, 0);
776             return TRUE;
777
778         /*
779         case 17: // toss gun, could be used to exit?
780             break;
781         case 20: // Manual minigun reload?
782             break;
783         */
784     }
785     return FALSE;
786 }
787
788 void spiderbot_spawn(float _f)
789 {
790     if(!self.gun1)
791     {
792         self.vehicles_impusle   = spiderbot_impulse;
793         self.gun1               = spawn();
794         self.gun2               = spawn();
795         setmodel(self.gun1, "models/vehicles/spiderbot_barrels.dpm");
796         setmodel(self.gun2, "models/vehicles/spiderbot_barrels.dpm");
797         setattachment(self.gun1, self.tur_head, "tag_hardpoint01");
798         setattachment(self.gun2, self.tur_head, "tag_hardpoint02");
799         self.gravity            = 2;
800         self.mass               = 5000;
801     }
802
803     self.frame              = 5;
804     self.tur_head.frame     = 1;
805     self.think              = spiderbot_think;
806     self.nextthink          = time;
807     self.vehicle_health     = autocvar_g_vehicle_spiderbot_health;
808     self.vehicle_shield     = autocvar_g_vehicle_spiderbot_shield;
809     self.movetype           = MOVETYPE_WALK;
810     self.solid              = SOLID_SLIDEBOX;
811     self.alpha              = self.tur_head.alpha = self.gun1.alpha = self.gun2.alpha = 1;
812     self.tur_head.angles    = '0 0 0';
813
814     setorigin(self, self.pos1 + '0 0 128');
815     self.angles = self.pos2;
816     self.vehicle_impact = spider_impact;
817     self.damageforcescale = 0.03;
818 }
819
820 void spawnfunc_vehicle_spiderbot()
821 {
822     if(!autocvar_g_vehicle_spiderbot)
823     {
824         remove(self);
825         return;
826     }
827
828     self.vehicle_flags |= VHF_DMGSHAKE;
829     //self.vehicle_flags |= VHF_DMGROLL;
830     //self.vehicle_flags |= VHF_DMGHEADROLL;
831
832     precache_model ( "models/vhshield.md3");
833     precache_model ( "models/vehicles/spiderbot.dpm");
834     precache_model ( "models/vehicles/spiderbot_top.dpm");
835     precache_model ( "models/vehicles/spiderbot_barrels.dpm");
836     precache_model ( "models/vehicles/spiderbot_cockpit.dpm");
837     precache_model ( "models/uziflash.md3");
838
839     precache_sound ( "weapons/uzi_fire.wav" );
840     precache_sound ( "weapons/rocket_impact.wav");
841
842     precache_sound ( "vehicles/spiderbot_die.wav");
843     precache_sound ( "vehicles/spiderbot_idle.wav");
844     precache_sound ( "vehicles/spiderbot_jump.wav");
845     precache_sound ( "vehicles/spiderbot_strafe.wav");
846     precache_sound ( "vehicles/spiderbot_walk.wav");
847     precache_sound ( "vehicles/spiderbot_land.wav");
848
849     if(autocvar_g_vehicle_spiderbot_shield)
850         self.vehicle_flags |= VHF_HASSHIELD;
851
852     if(autocvar_g_vehicle_spiderbot_shield_regen)
853         self.vehicle_flags |= VHF_SHIELDREGEN;
854
855     if(autocvar_g_vehicle_spiderbot_health_regen)
856         self.vehicle_flags |= VHF_HEALTHREGEN;
857
858     if(!vehicle_initialize(
859              "Spiderbot",
860              "models/vehicles/spiderbot.dpm",
861              "models/vehicles/spiderbot_top.dpm",
862              "models/vehicles/spiderbot_cockpit.dpm",
863              "tag_head", "tag_hud", "",
864              HUD_SPIDERBOT,
865              SPIDERBOT_MIN, SPIDERBOT_MAX,
866              FALSE,
867              spiderbot_spawn, autocvar_g_vehicle_spiderbot_respawntime,
868              spiderbot_frame,
869              spiderbot_enter, spiderbot_exit,
870              spiderbot_die,   spiderbot_think,
871              FALSE,
872              autocvar_g_vehicle_spiderbot_health,
873              autocvar_g_vehicle_spiderbot_shield))
874     {
875         remove(self);
876         return;
877     }
878 }
879 #endif // SVQC