Remove some leftovers from merge
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / unit / spiderbot.qc
1 #ifdef REGISTER_VEHICLE
2 REGISTER_VEHICLE(
3 /* VEH_##id   */ SPIDERBOT,
4 /* function   */ v_spiderbot,
5 /* spawnflags */ VHF_DMGSHAKE,
6 /* mins,maxs  */ '-75 -75 10', '75 75 125',
7 /* model          */ "models/vehicles/spiderbot.dpm",
8 /* head_model */ "models/vehicles/spiderbot_top.dpm",
9 /* hud_model  */ "models/vehicles/spiderbot_cockpit.dpm",
10 /* tags           */ "tag_head", "tag_hud", "",
11 /* netname        */ "spiderbot",
12 /* fullname   */ _("Spiderbot")
13 );
14 #else
15
16 const int SBRM_FIRST = 1;
17 const int SBRM_VOLLY = 1;
18 const int SBRM_GUIDE = 2;
19 const int SBRM_ARTILLERY = 3;
20 const int SBRM_LAST = 3;
21
22 #ifdef SVQC
23 bool autocvar_g_vehicle_spiderbot;
24
25 float autocvar_g_vehicle_spiderbot_respawntime;
26
27 float autocvar_g_vehicle_spiderbot_speed_stop;
28 float autocvar_g_vehicle_spiderbot_speed_strafe;
29 float autocvar_g_vehicle_spiderbot_speed_walk;
30 float autocvar_g_vehicle_spiderbot_speed_run = 700;
31 float autocvar_g_vehicle_spiderbot_turnspeed;
32 float autocvar_g_vehicle_spiderbot_turnspeed_strafe;
33 float autocvar_g_vehicle_spiderbot_movement_inertia;
34
35 float autocvar_g_vehicle_spiderbot_springlength;
36 float autocvar_g_vehicle_spiderbot_springup;
37 float autocvar_g_vehicle_spiderbot_springblend;
38 float autocvar_g_vehicle_spiderbot_tiltlimit;
39
40 float autocvar_g_vehicle_spiderbot_head_pitchlimit_down;
41 float autocvar_g_vehicle_spiderbot_head_pitchlimit_up;
42 float autocvar_g_vehicle_spiderbot_head_turnlimit;
43 float autocvar_g_vehicle_spiderbot_head_turnspeed;
44
45 int autocvar_g_vehicle_spiderbot_health;
46 float autocvar_g_vehicle_spiderbot_health_regen;
47 float autocvar_g_vehicle_spiderbot_health_regen_pause;
48
49 int autocvar_g_vehicle_spiderbot_shield;
50 float autocvar_g_vehicle_spiderbot_shield_regen;
51 float autocvar_g_vehicle_spiderbot_shield_regen_pause;
52
53 float autocvar_g_vehicle_spiderbot_minigun_damage;
54 float autocvar_g_vehicle_spiderbot_minigun_refire;
55 float autocvar_g_vehicle_spiderbot_minigun_spread;
56 int autocvar_g_vehicle_spiderbot_minigun_ammo_cost;
57 int autocvar_g_vehicle_spiderbot_minigun_ammo_max;
58 int autocvar_g_vehicle_spiderbot_minigun_ammo_regen;
59 float autocvar_g_vehicle_spiderbot_minigun_ammo_regen_pause;
60 float autocvar_g_vehicle_spiderbot_minigun_force;
61 float autocvar_g_vehicle_spiderbot_minigun_solidpenetration;
62
63 float autocvar_g_vehicle_spiderbot_rocket_damage;
64 float autocvar_g_vehicle_spiderbot_rocket_force;
65 float autocvar_g_vehicle_spiderbot_rocket_radius;
66 float autocvar_g_vehicle_spiderbot_rocket_speed;
67 float autocvar_g_vehicle_spiderbot_rocket_spread;
68 float autocvar_g_vehicle_spiderbot_rocket_refire;
69 float autocvar_g_vehicle_spiderbot_rocket_refire2;
70 float autocvar_g_vehicle_spiderbot_rocket_reload;
71 float autocvar_g_vehicle_spiderbot_rocket_health;
72 float autocvar_g_vehicle_spiderbot_rocket_noise;
73 float autocvar_g_vehicle_spiderbot_rocket_turnrate;
74 float autocvar_g_vehicle_spiderbot_rocket_lifetime;
75
76 vector autocvar_g_vehicle_spiderbot_bouncepain;
77
78 void spiderbot_rocket_artillery()
79 {
80         self.nextthink = time;
81         UpdateCSQCProjectile(self);
82 }
83
84 void spiderbot_rocket_unguided()
85 {
86         vector newdir, olddir;
87
88         self.nextthink  = time;
89
90         olddir = normalize(self.velocity);
91         newdir = normalize(self.pos1 - self.origin) + randomvec() * autocvar_g_vehicle_spiderbot_rocket_noise;
92         self.velocity = normalize(olddir + newdir * autocvar_g_vehicle_spiderbot_rocket_turnrate) * autocvar_g_vehicle_spiderbot_rocket_speed;
93
94         UpdateCSQCProjectile(self);
95
96         if (self.owner.deadflag != DEAD_NO || self.cnt < time || vlen(self.pos1 - self.origin) < 16)
97                 self.use();
98 }
99
100 void spiderbot_rocket_guided()
101 {
102         vector newdir, olddir;
103
104         self.nextthink  = time;
105
106         if(!self.realowner.vehicle)
107                 self.think = spiderbot_rocket_unguided;
108
109         crosshair_trace(self.realowner);
110         olddir = normalize(self.velocity);
111         newdir = normalize(trace_endpos - self.origin) + randomvec() * autocvar_g_vehicle_spiderbot_rocket_noise;
112         self.velocity = normalize(olddir + newdir * autocvar_g_vehicle_spiderbot_rocket_turnrate) * autocvar_g_vehicle_spiderbot_rocket_speed;
113
114         UpdateCSQCProjectile(self);
115
116         if (self.owner.deadflag != DEAD_NO || self.cnt < time)
117                 self.use();
118 }
119
120 void spiderbot_guide_release()
121 {
122         entity rkt;
123         rkt = findchainentity(realowner, self.owner);
124         if(!rkt)
125                 return;
126
127         crosshair_trace(self.owner);
128         while(rkt)
129         {
130                 if(rkt.think == spiderbot_rocket_guided)
131                 {
132                         rkt.pos1 = trace_endpos;
133                         rkt.think = spiderbot_rocket_unguided;
134                 }
135                 rkt = rkt.chain;
136         }
137 }
138
139 float spiberbot_calcartillery_flighttime;
140 vector spiberbot_calcartillery(vector org, vector tgt, float ht)
141 {
142         float grav, sdist, zdist, vs, vz, jumpheight;
143         vector sdir;
144
145         grav  = autocvar_sv_gravity;
146         zdist = tgt_z - org_z;
147         sdist = vlen(tgt - org - zdist * '0 0 1');
148         sdir  = normalize(tgt - org - zdist * '0 0 1');
149
150         // how high do we need to go?
151         jumpheight = fabs(ht);
152         if(zdist > 0)
153                 jumpheight = jumpheight + zdist;
154
155         // push so high...
156         vz = sqrt(2 * grav * jumpheight); // NOTE: sqrt(positive)!
157
158         // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
159         if(ht < 0)
160                 if(zdist < 0)
161                         vz = -vz;
162
163         vector solution;
164         solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
165         // ALWAYS solvable because jumpheight >= zdist
166         if(!solution_z)
167                 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)
168         if(zdist == 0)
169                 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)
170
171         if(zdist < 0)
172         {
173                 // down-jump
174                 if(ht < 0)
175                 {
176                         // almost straight line type
177                         // jump apex is before the jump
178                         // we must take the larger one
179                         spiberbot_calcartillery_flighttime = solution_y;
180                 }
181                 else
182                 {
183                         // regular jump
184                         // jump apex is during the jump
185                         // we must take the larger one too
186                         spiberbot_calcartillery_flighttime = solution_y;
187                 }
188         }
189         else
190         {
191                 // up-jump
192                 if(ht < 0)
193                 {
194                         // almost straight line type
195                         // jump apex is after the jump
196                         // we must take the smaller one
197                         spiberbot_calcartillery_flighttime = solution_x;
198                 }
199                 else
200                 {
201                         // regular jump
202                         // jump apex is during the jump
203                         // we must take the larger one
204                         spiberbot_calcartillery_flighttime = solution_y;
205                 }
206         }
207         vs = sdist / spiberbot_calcartillery_flighttime;
208
209         // finally calculate the velocity
210         return sdir * vs + '0 0 1' * vz;
211 }
212
213 void spiderbot_rocket_do()
214 {
215         vector v;
216         entity rocket = world;
217
218         if (self.wait != -10)
219         {
220                 if (self.owner.BUTTON_ATCK2 && self.vehicle_weapon2mode == SBRM_GUIDE)
221                 {
222                         if (self.wait == 1)
223                         if (self.tur_head.frame == 9 || self.tur_head.frame == 1)
224                         {
225                                 if(self.gun2.cnt < time && self.tur_head.frame == 9)
226                                         self.tur_head.frame = 1;
227
228                                 return;
229                         }
230                         self.wait = 1;
231                 }
232                 else
233                 {
234                         if(self.wait)
235                                 spiderbot_guide_release();
236
237                         self.wait = 0;
238                 }
239         }
240
241         if(self.gun2.cnt > time)
242                 return;
243
244         if (self.tur_head.frame >= 9)
245         {
246                 self.tur_head.frame = 1;
247                 self.wait = 0;
248         }
249
250         if(self.wait != -10)
251         if(!self.owner.BUTTON_ATCK2)
252                 return;
253                 
254         if(forbidWeaponUse(self.owner))
255                 return;
256
257         v = gettaginfo(self.tur_head,gettagindex(self.tur_head,"tag_fire"));
258
259         switch(self.vehicle_weapon2mode)
260         {
261                 case SBRM_VOLLY:
262                         rocket = vehicles_projectile("spiderbot_rocket_launch", "weapons/rocket_fire.wav",
263                                                                    v, normalize(randomvec() * autocvar_g_vehicle_spiderbot_rocket_spread + v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed,
264                                                                    autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1,
265                                                                    DEATH_VH_SPID_ROCKET, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, true, self.owner);
266                         crosshair_trace(self.owner);
267                         float _dist = (random() * autocvar_g_vehicle_spiderbot_rocket_radius) + vlen(v - trace_endpos);
268                         _dist -= (random() * autocvar_g_vehicle_spiderbot_rocket_radius) ;
269                         rocket.nextthink  = time + (_dist / autocvar_g_vehicle_spiderbot_rocket_speed);
270                         rocket.think     = vehicles_projectile_explode;
271
272                         if(self.owner.BUTTON_ATCK2 && self.tur_head.frame == 1)
273                                 self.wait = -10;
274                         break;
275                 case SBRM_GUIDE:
276                         rocket = vehicles_projectile("spiderbot_rocket_launch", "weapons/rocket_fire.wav",
277                                                                    v, normalize(v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed,
278                                                                    autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1,
279                                                                    DEATH_VH_SPID_ROCKET, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, false, self.owner);
280                         crosshair_trace(self.owner);
281                         rocket.pos1        = trace_endpos;
282                         rocket.nextthink  = time;
283                         rocket.think      = spiderbot_rocket_guided;
284
285
286                 break;
287                 case SBRM_ARTILLERY:
288                         rocket = vehicles_projectile("spiderbot_rocket_launch", "weapons/rocket_fire.wav",
289                                                                    v, normalize(v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed,
290                                                                    autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1,
291                                                                    DEATH_VH_SPID_ROCKET, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, true, self.owner);
292
293                         crosshair_trace(self.owner);
294
295                         rocket.pos1        = trace_endpos + randomvec() * (0.75 * autocvar_g_vehicle_spiderbot_rocket_radius);
296                         rocket.pos1_z      = trace_endpos_z;
297
298                         traceline(v, v + '0 0 1' * MAX_SHOT_DISTANCE, MOVE_WORLDONLY, self);
299                         float h1 = 0.75 * vlen(v - trace_endpos);
300
301                         //v = trace_endpos;
302                         traceline(v , rocket.pos1 + '0 0 1' * MAX_SHOT_DISTANCE, MOVE_WORLDONLY, self);
303                         float h2 = 0.75 * vlen(rocket.pos1 - v);
304
305                         rocket.velocity  = spiberbot_calcartillery(v, rocket.pos1, ((h1 < h2) ? h1 : h2));
306                         rocket.movetype  = MOVETYPE_TOSS;
307                         rocket.gravity   = 1;
308                         //rocket.think   = spiderbot_rocket_artillery;
309                 break;
310         }
311         rocket.classname  = "spiderbot_rocket";
312
313         rocket.cnt = time + autocvar_g_vehicle_spiderbot_rocket_lifetime;
314
315         self.tur_head.frame += 1;
316         if (self.tur_head.frame == 9)
317                 self.attack_finished_single = autocvar_g_vehicle_spiderbot_rocket_reload;
318         else
319                 self.attack_finished_single = ((self.vehicle_weapon2mode ==  SBRM_VOLLY) ? autocvar_g_vehicle_spiderbot_rocket_refire2 : autocvar_g_vehicle_spiderbot_rocket_refire);
320
321         self.gun2.cnt = time + self.attack_finished_single;
322 }
323
324 .float jump_delay;
325 float spiderbot_frame()
326 {
327         vector ad, vf;
328         entity player, spider;
329         float ftmp;
330
331         if(intermission_running)
332         {
333                 self.vehicle.velocity = '0 0 0';
334                 self.vehicle.avelocity = '0 0 0';
335                 return 1;
336         }
337
338         player = self;
339         spider = self.vehicle;
340         self   = spider;
341
342         vehicles_painframe();
343
344         player.BUTTON_ZOOM        = 0;
345         player.BUTTON_CROUCH    = 0;
346         player.switchweapon      = 0;
347         player.vehicle_weapon2mode = spider.vehicle_weapon2mode;
348
349
350 #if 1 // 0 to enable per-gun impact aux crosshairs
351         // Avarage gun impact point's -> aux cross
352         ad = gettaginfo(spider.tur_head, gettagindex(spider.tur_head, "tag_hardpoint01"));
353         vf = v_forward;
354         ad += gettaginfo(spider.tur_head, gettagindex(spider.tur_head, "tag_hardpoint02"));
355         vf += v_forward;
356         ad = ad * 0.5;
357         v_forward = vf * 0.5;
358         traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, spider);
359         UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload1) + ('0 1 0' * (1 - player.vehicle_reload1)), 0);
360 #else
361         ad = gettaginfo(spider.gun1, gettagindex(spider.gun1, "barrels"));
362         traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, spider);
363         UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload1) + ('0 1 0' * (1 - player.vehicle_reload1)), 0);
364         vf = ad;
365         ad = gettaginfo(spider.gun2, gettagindex(spider.gun2, "barrels"));
366         traceline(ad, ad + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, spider);
367         UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload1) + ('0 1 0' * (1 - player.vehicle_reload1)), 1);
368         ad = 0.5 * (ad + vf);
369 #endif
370
371         crosshair_trace(player);
372         ad = vectoangles(normalize(trace_endpos - ad));
373         ad = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(spider.angles), AnglesTransform_FromAngles(ad))) - spider.tur_head.angles;
374         ad = AnglesTransform_Normalize(ad, true);
375         //UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload2) + ('0 1 0' * (1 - player.vehicle_reload2)), 2);
376
377         // Rotate head
378         ftmp = autocvar_g_vehicle_spiderbot_head_turnspeed * sys_frametime;
379         ad_y = bound(-ftmp, ad_y, ftmp);
380         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);
381
382         // Pitch head
383         ad_x = bound(ftmp * -1, ad_x, ftmp);
384         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);
385
386
387         //fixedmakevectors(spider.angles);
388         makevectors(spider.angles + '-2 0 0' * spider.angles_x);
389
390         movelib_groundalign4point(autocvar_g_vehicle_spiderbot_springlength, autocvar_g_vehicle_spiderbot_springup, autocvar_g_vehicle_spiderbot_springblend, autocvar_g_vehicle_spiderbot_tiltlimit);
391
392         if(spider.flags & FL_ONGROUND)
393                 spider.jump_delay = time; // reset now so movement can begin
394
395         //if(spider.flags & FL_ONGROUND)
396         {
397                 if(spider.flags & FL_ONGROUND)
398                 if(spider.frame == 4 && self.tur_head.wait != 0)
399                 {
400                         sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_land.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
401                         spider.frame = 5;
402                 }
403
404                 if(!player.BUTTON_JUMP)
405                         spider.BUTTON_JUMP = 0;
406
407                 if((spider.flags & FL_ONGROUND) && player.BUTTON_JUMP && !spider.BUTTON_JUMP && self.tur_head.wait < time)
408                 {
409                         sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_jump.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
410                         //dprint("spiderbot_jump:", ftos(soundlength("vehicles/spiderbot_jump.wav")), "\n");
411                         self.delay = 0;
412
413                         self.tur_head.wait = time + 2;
414                         spider.jump_delay = time + 2;
415                         spider.BUTTON_JUMP = 1; // set spider's jump
416                         //player.BUTTON_JUMP = 0;
417
418                         vector movefix = '0 0 0';
419                         if(player.movement_x > 0) movefix_x = 1;
420                         if(player.movement_x < 0) movefix_x = -1;
421                         if(player.movement_y > 0) movefix_y = 1;
422                         if(player.movement_y < 0) movefix_y = -1;
423
424                         vector rt = movefix_y * v_right;
425                         vector sd = movefix_x * v_forward;
426                         if(movefix_y == 0 && movefix_x == 0)
427                                 sd = v_forward; // always do forward
428
429                         spider.flags &= ~FL_ONGROUND;
430
431                         spider.velocity = sd * 700 + rt * 600 + v_up * 600;
432                         spider.frame = 4;
433                 }
434                 else if(time >= spider.jump_delay)
435                 {
436                         if(vlen(player.movement) == 0)
437                         {
438                                 if(spider.flags & FL_ONGROUND)
439                                 {
440                                         if(self.sound_nexttime < time || self.delay != 3)
441                                         {
442                                                 self.delay = 3;
443                                                 self.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_idle.wav");
444                                                 //dprint("spiderbot_idle:", ftos(soundlength("vehicles/spiderbot_idle.wav")), "\n");
445                                                 sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_idle.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
446                                         }
447                                         movelib_beak_simple(autocvar_g_vehicle_spiderbot_speed_stop);
448                                         spider.frame = 5;
449                                 }
450                         }
451                         else
452                         {
453                                 // Turn Body
454                                 if(player.movement_x == 0 && player.movement_y != 0)
455                                         ftmp = autocvar_g_vehicle_spiderbot_turnspeed_strafe * sys_frametime;
456                                 else
457                                         ftmp = autocvar_g_vehicle_spiderbot_turnspeed * sys_frametime;
458
459                                 ftmp = bound(-ftmp, spider.tur_head.angles_y, ftmp);
460                                 spider.angles_y = anglemods(spider.angles_y + ftmp);
461                                 spider.tur_head.angles_y -= ftmp;
462
463                                 if(player.movement_x != 0)
464                                 {
465                                         if(player.movement_x > 0)
466                                         {
467                                                 player.movement_x = 1;
468                                                 if(spider.flags & FL_ONGROUND)
469                                                         spider.frame = 0;
470                                         }
471                                         else if(player.movement_x < 0)
472                                         {
473                                                 player.movement_x = -1;
474                                                 if(spider.flags & FL_ONGROUND)
475                                                         spider.frame = 1;
476                                         }
477                                         player.movement_y = 0;
478                                         float oldvelz = spider.velocity_z;
479                                         movelib_move_simple(normalize(v_forward * player.movement_x),((player.BUTTON_JUMP) ? autocvar_g_vehicle_spiderbot_speed_run : autocvar_g_vehicle_spiderbot_speed_walk),autocvar_g_vehicle_spiderbot_movement_inertia);
480                                         spider.velocity_z = oldvelz;
481                                         float g = ((autocvar_sv_gameplayfix_gravityunaffectedbyticrate) ? 0.5 : 1);
482                                         if(spider.velocity_z <= 20) // not while jumping
483                                                 spider.velocity_z -= g * sys_frametime * autocvar_sv_gravity;
484                                         if(spider.flags & FL_ONGROUND)
485                                         if(self.sound_nexttime < time || self.delay != 1)
486                                         {
487                                                 self.delay = 1;
488                                                 self.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_walk.wav");
489                                                 sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_walk.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
490                                                 //dprint("spiderbot_walk:", ftos(soundlength("vehicles/spiderbot_walk.wav")), "\n");
491                                         }
492                                 }
493                                 else if(player.movement_y != 0)
494                                 {
495                                         if(player.movement_y < 0)
496                                         {
497                                                 player.movement_y = -1;
498                                                 if(spider.flags & FL_ONGROUND)
499                                                         spider.frame = 2;
500                                         }
501                                         else if(player.movement_y > 0)
502                                         {
503                                                 player.movement_y = 1;
504                                                 if(spider.flags & FL_ONGROUND)
505                                                         spider.frame = 3;
506                                         }
507
508                                         float oldvelz = spider.velocity_z;
509                                         movelib_move_simple(normalize(v_right * player.movement_y),autocvar_g_vehicle_spiderbot_speed_strafe,autocvar_g_vehicle_spiderbot_movement_inertia);
510                                         spider.velocity_z = oldvelz;
511                                         float g = ((autocvar_sv_gameplayfix_gravityunaffectedbyticrate) ? 0.5 : 1);
512                                         if(spider.velocity_z <= 20) // not while jumping
513                                                 spider.velocity_z -= g * sys_frametime * autocvar_sv_gravity;
514                                         if(spider.flags & FL_ONGROUND)
515                                         if(self.sound_nexttime < time || self.delay != 2)
516                                         {
517                                                 self.delay = 2;
518                                                 self.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_strafe.wav");
519                                                 sound (self, CH_TRIGGER_SINGLE, "vehicles/spiderbot_strafe.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
520                                                 //dprint("spiderbot_strafe:", ftos(soundlength("vehicles/spiderbot_strafe.wav")), "\n");
521                                         }
522                                 }
523                         }
524                 }
525         }
526
527         self.angles_x = bound(-autocvar_g_vehicle_spiderbot_tiltlimit, self.angles_x, autocvar_g_vehicle_spiderbot_tiltlimit);
528         self.angles_z = bound(-autocvar_g_vehicle_spiderbot_tiltlimit, self.angles_z, autocvar_g_vehicle_spiderbot_tiltlimit);
529
530         if(!forbidWeaponUse(player))
531         if(player.BUTTON_ATCK)
532         {
533                 spider.cnt = time;
534                 if(spider.vehicle_ammo1 >= autocvar_g_vehicle_spiderbot_minigun_ammo_cost && spider.tur_head.attack_finished_single <= time)
535                 {
536                         entity gun;
537                         vector v;
538                         spider.misc_bulletcounter += 1;
539
540                         self = player;
541
542                         gun = (spider.misc_bulletcounter % 2) ? spider.gun1 : spider.gun2;
543
544                         v = gettaginfo(gun, gettagindex(gun, "barrels"));
545                         v_forward = normalize(v_forward);
546                         v += v_forward * 50;
547
548                         fireBullet(v, v_forward, autocvar_g_vehicle_spiderbot_minigun_spread, autocvar_g_vehicle_spiderbot_minigun_solidpenetration,
549                                 autocvar_g_vehicle_spiderbot_minigun_damage, autocvar_g_vehicle_spiderbot_minigun_force, DEATH_VH_SPID_MINIGUN, 0);
550
551                         sound (gun, CH_WEAPON_A, "weapons/uzi_fire.wav", VOL_BASE, ATTEN_NORM);
552                         //trailparticles(self, particleeffectnum("spiderbot_minigun_trail"), v, trace_endpos);
553                         pointparticles(particleeffectnum("spiderbot_minigun_muzzleflash"), v, v_forward * 2500, 1);
554
555                         self = spider;
556
557                         spider.vehicle_ammo1 -= autocvar_g_vehicle_spiderbot_minigun_ammo_cost;
558                         spider.tur_head.attack_finished_single = time + autocvar_g_vehicle_spiderbot_minigun_refire;
559                         player.vehicle_ammo1 = (spider.vehicle_ammo1 / autocvar_g_vehicle_spiderbot_minigun_ammo_max) * 100;
560                         spider.gun1.angles_z += 45;
561                         spider.gun2.angles_z -= 45;
562                         if(spider.gun1.angles_z >= 360)
563                         {
564                                 spider.gun1.angles_z = 0;
565                                 spider.gun2.angles_z = 0;
566                         }
567                 }
568         }
569         else
570                 vehicles_regen(spider.cnt, vehicle_ammo1, autocvar_g_vehicle_spiderbot_minigun_ammo_max,
571                                                                                    autocvar_g_vehicle_spiderbot_minigun_ammo_regen_pause,
572                                                                                    autocvar_g_vehicle_spiderbot_minigun_ammo_regen, frametime, false);
573
574
575         spiderbot_rocket_do();
576
577         if(self.vehicle_flags  & VHF_SHIELDREGEN)
578                 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);
579
580         if(self.vehicle_flags  & VHF_HEALTHREGEN)
581                 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);
582
583         player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
584         player.vehicle_ammo2 = spider.tur_head.frame;
585
586         if(spider.gun2.cnt <= time)
587                 player.vehicle_reload2 = 100;
588         else
589                 player.vehicle_reload2 = 100 - ((spider.gun2.cnt - time) / spider.attack_finished_single) * 100;
590
591         setorigin(player, spider.origin + '0 0 1' * spider.maxs_z);
592         player.velocity = spider.velocity;
593
594         VEHICLE_UPDATE_PLAYER(player, health, spiderbot);
595
596         if(self.vehicle_flags & VHF_HASSHIELD)
597                 VEHICLE_UPDATE_PLAYER(player, shield, spiderbot);
598
599         self = player;
600         return 1;
601 }
602
603 void spiderbot_exit(float eject)
604 {
605         entity e;
606         vector spot;
607
608         e = findchain(classname,"spiderbot_rocket");
609         while(e)
610         {
611                 if(e.owner == self.owner)
612                 {
613                         e.realowner = self.owner;
614                         e.owner = world;
615                 }
616                 e = e.chain;
617         }
618
619         self.think = vehicles_think;
620         self.nextthink = time;
621         self.frame = 5;
622         self.movetype = MOVETYPE_WALK;
623
624         if(!self.owner)
625                 return;
626
627         makevectors(self.angles);
628         if(eject)
629         {
630                 spot = self.origin + v_forward * 100 + '0 0 64';
631                 spot = vehicles_findgoodexit(spot);
632                 setorigin(self.owner , spot);
633                 self.owner.velocity = (v_up + v_forward * 0.25) * 750;
634                 self.owner.oldvelocity = self.owner.velocity;
635         }
636         else
637         {
638                 if(vlen(self.velocity) > autocvar_g_vehicle_spiderbot_speed_strafe)
639                 {
640                         self.owner.velocity = normalize(self.velocity) * vlen(self.velocity);
641                         self.owner.velocity_z += 200;
642                         spot = self.origin + v_forward * 128 + '0 0 64';
643                         spot = vehicles_findgoodexit(spot);
644                 }
645                 else
646                 {
647                         self.owner.velocity = self.velocity * 0.5;
648                         self.owner.velocity_z += 10;
649                         spot = self.origin + v_forward * 256 + '0 0 64';
650                         spot = vehicles_findgoodexit(spot);
651                 }
652                 self.owner.oldvelocity = self.owner.velocity;
653                 setorigin(self.owner , spot);
654         }
655
656         antilag_clear(self.owner);
657         self.owner = world;
658 }
659
660 void spiderbot_headfade()
661 {
662         self.think = spiderbot_headfade;
663         self.nextthink = self.fade_time;
664         self.alpha = 1 - (time - self.fade_time) * self.fade_rate;
665
666         if(self.cnt < time || self.alpha < 0.1)
667         {
668                 if(self.alpha > 0.1)
669                 {
670                         sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
671                         pointparticles(particleeffectnum("explosion_big"), self.origin + '0 0 100', '0 0 0', 1);
672                 }
673                 remove(self);
674         }
675 }
676
677 void spiderbot_blowup()
678 {
679         if(self.cnt > time)
680         {
681                 if(random() < 0.1)
682                 {
683                         sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
684                         pointparticles(particleeffectnum("explosion_small"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
685                 }
686                 self.nextthink = time + 0.1;
687                 return;
688         }
689
690         entity h, g1, g2, b;
691         b = spawn();
692         h = spawn();
693         g1 = spawn();
694         g2 = spawn();
695
696         setmodel(b, "models/vehicles/spiderbot.dpm");
697         setmodel(h, "models/vehicles/spiderbot_top.dpm");
698         setmodel(g1, "models/vehicles/spiderbot_barrels.dpm");
699         setmodel(g2, "models/vehicles/spiderbot_barrels.dpm");
700
701         setorigin(b, self.origin);
702         b.frame = 11;
703         b.angles = self.angles;
704         setsize(b, self.mins, self.maxs);
705
706         setorigin(h, gettaginfo(self, gettagindex(self, "tag_head")));
707         h.movetype = MOVETYPE_BOUNCE;
708         h.solid = SOLID_BBOX;
709         h.velocity = v_up * (500 + random() * 500) + randomvec() * 128;
710         h.modelflags = MF_ROCKET;
711         h.effects = EF_FLAME | EF_LOWPRECISION;
712         h.avelocity = randomvec() * 360;
713
714         h.alpha = 1;
715         h.cnt = time + (3.5 * random());
716         h.fade_rate = 1 / min(self.respawntime, 10);
717         h.fade_time = time;
718         h.think = spiderbot_headfade;
719         h.nextthink = time;
720
721         setorigin(g1, gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_hardpoint01")));
722         g1.movetype = MOVETYPE_TOSS;
723         g1.solid = SOLID_CORPSE;
724         g1.velocity = v_forward * 700 + (randomvec() * 32);
725         g1.avelocity = randomvec() * 180;
726
727         setorigin(g2, gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_hardpoint02")));
728         g2.movetype = MOVETYPE_TOSS;
729         g2.solid = SOLID_CORPSE;
730         g2.velocity = v_forward * 700 + (randomvec() * 32);
731         g2.avelocity = randomvec() * 180;
732
733         h.colormod = b.colormod = g1.colormod = g2.colormod = '-2 -2 -2';
734
735         SUB_SetFade(b,  time + 5, min(self.respawntime, 1));
736         //SUB_SetFade(h,  time, min(self.respawntime, 10));
737         SUB_SetFade(g1, time, min(self.respawntime, 10));
738         SUB_SetFade(g2, time, min(self.respawntime, 10));
739
740         RadiusDamage (self, self.enemy, 250, 15, 250, world, world, 250, DEATH_VH_SPID_DEATH, world);
741
742         self.alpha = self.tur_head.alpha = self.gun1.alpha = self.gun2.alpha = -1;
743         self.movetype = MOVETYPE_NONE;
744         self.deadflag = DEAD_DEAD;
745         self.solid = SOLID_NOT;
746         self.tur_head.effects &= ~EF_FLAME;
747         self.vehicle_hudmodel.viewmodelforclient = self;
748 }
749
750 bool spiderbot_impulse(int _imp)
751 {
752         switch(_imp)
753         {
754                 case 1:
755                 case 230:
756                         self.vehicle.vehicle_weapon2mode = SBRM_VOLLY;
757                         CSQCVehicleSetup(self, 0);
758                         return true;
759                 case 2:
760                 case 231:
761                         self.vehicle.vehicle_weapon2mode = SBRM_GUIDE;
762                         CSQCVehicleSetup(self, 0);
763                         return true;
764                 case 3:
765                 case 232:
766                 case 251:
767                         self.vehicle.vehicle_weapon2mode = SBRM_ARTILLERY;
768                         CSQCVehicleSetup(self, 0);
769                         return true;
770
771                 case 10:
772                 case 15:
773                 case 18:
774                         self.vehicle.vehicle_weapon2mode += 1;
775                         if(self.vehicle.vehicle_weapon2mode > SBRM_LAST)
776                                 self.vehicle.vehicle_weapon2mode = SBRM_FIRST;
777
778                         //centerprint(self, strcat("Rocket mode is ", ftos(self.vehicle.vehicle_weapon2mode)));
779                         CSQCVehicleSetup(self, 0);
780                         return true;
781                 case 11:
782                 case 12:
783                 case 16:
784                 case 19:
785                         self.vehicle.vehicle_weapon2mode -= 1;
786                         if(self.vehicle.vehicle_weapon2mode < SBRM_FIRST)
787                                 self.vehicle.vehicle_weapon2mode = SBRM_LAST;
788
789                         //centerprint(self, strcat("Rocket mode is ", ftos(self.vehicle.vehicle_weapon2mode)));
790                         CSQCVehicleSetup(self, 0);
791                         return true;
792
793                 /*
794                 case 17: // toss gun, could be used to exit?
795                         break;
796                 case 20: // Manual minigun reload?
797                         break;
798                 */
799         }
800         return false;
801 }
802
803 void spawnfunc_vehicle_spiderbot()
804 {
805         if(!autocvar_g_vehicle_spiderbot) { remove(self); return; }
806         if(!vehicle_initialize(VEH_SPIDERBOT, false)) { remove(self); return; }
807 }
808
809 float v_spiderbot(float req)
810 {
811         switch(req)
812         {
813                 case VR_IMPACT:
814                 {
815                         if(autocvar_g_vehicle_spiderbot_bouncepain)
816                                 vehicles_impact(autocvar_g_vehicle_spiderbot_bouncepain_x, autocvar_g_vehicle_spiderbot_bouncepain_y, autocvar_g_vehicle_spiderbot_bouncepain_z);
817                 
818                         return true;
819                 }
820                 case VR_ENTER:
821                 {
822                         self.vehicle_weapon2mode = SBRM_GUIDE;
823                         self.movetype = MOVETYPE_WALK;
824                         CSQCVehicleSetup(self.owner, 0);
825                         self.owner.vehicle_health = (self.vehicle_health / autocvar_g_vehicle_spiderbot_health) * 100;
826                         self.owner.vehicle_shield = (self.vehicle_shield / autocvar_g_vehicle_spiderbot_shield) * 100;
827
828                         if(self.owner.flagcarried)
829                         {
830                                 setattachment(self.owner.flagcarried, self.tur_head, "");
831                                 setorigin(self.owner.flagcarried, '-20 0 120');
832                         }
833                 
834                         return true;
835                 }
836                 case VR_THINK:
837                 {
838                         if(self.flags & FL_ONGROUND)
839                                 movelib_beak_simple(autocvar_g_vehicle_spiderbot_speed_stop);
840                         
841                         return true;
842                 }
843                 case VR_DEATH:
844                 {
845                         self.health                             = 0;
846                         self.event_damage               = func_null;
847                         self.takedamage                 = DAMAGE_NO;
848                         self.touch                              = func_null;
849                         self.cnt                                = 3.4 + time + random() * 2;
850                         self.think                              = spiderbot_blowup;
851                         self.nextthink                  = time;
852                         self.deadflag                   = DEAD_DYING;
853                         self.frame                              = 5;
854                         self.tur_head.effects  |= EF_FLAME;
855                         self.colormod                   = self.tur_head.colormod = '-1 -1 -1';
856                         self.frame                              = 10;
857                         self.movetype                   = MOVETYPE_TOSS;
858                         
859                         CSQCModel_UnlinkEntity(); // networking the death scene would be a nightmare
860
861                         return true;
862                 }
863                 case VR_SPAWN:
864                 {
865                         if(!self.gun1)
866                         {
867                                 self.vehicles_impulse = spiderbot_impulse;
868                                 self.gun1 = spawn();
869                                 self.gun2 = spawn();
870                                 setmodel(self.gun1, "models/vehicles/spiderbot_barrels.dpm");
871                                 setmodel(self.gun2, "models/vehicles/spiderbot_barrels.dpm");
872                                 setattachment(self.gun1, self.tur_head, "tag_hardpoint01");
873                                 setattachment(self.gun2, self.tur_head, "tag_hardpoint02");
874                                 self.gravity = 2;
875                                 self.mass = 5000;
876                         }
877
878                         self.frame = 5;
879                         self.tur_head.frame = 1;
880                         self.movetype = MOVETYPE_WALK;
881                         self.solid = SOLID_SLIDEBOX;
882                         self.alpha = self.tur_head.alpha = self.gun1.alpha = self.gun2.alpha = 1;
883                         self.tur_head.angles = '0 0 0';
884                         self.vehicle_exit = spiderbot_exit;
885
886                         setorigin(self, self.pos1 + '0 0 128');
887                         self.angles = self.pos2;
888                         self.damageforcescale = 0.03;
889                         self.vehicle_health = autocvar_g_vehicle_spiderbot_health;
890                         self.vehicle_shield = autocvar_g_vehicle_spiderbot_shield;
891                         
892                         self.PlayerPhysplug = spiderbot_frame;
893
894                         return true;
895                 }
896                 case VR_SETUP:
897                 {
898                         if(autocvar_g_vehicle_spiderbot_shield)
899                                 self.vehicle_flags |= VHF_HASSHIELD;
900
901                         if(autocvar_g_vehicle_spiderbot_shield_regen)
902                                 self.vehicle_flags |= VHF_SHIELDREGEN;
903
904                         if(autocvar_g_vehicle_spiderbot_health_regen)
905                                 self.vehicle_flags |= VHF_HEALTHREGEN;
906
907                         self.respawntime = autocvar_g_vehicle_spiderbot_respawntime;
908                         self.vehicle_health = autocvar_g_vehicle_spiderbot_health;
909                         self.vehicle_shield = autocvar_g_vehicle_spiderbot_shield;
910                         self.max_health = self.vehicle_health;
911                         self.pushable = true; // spiderbot can use jumppads
912
913                         return true;
914                 }
915                 case VR_PRECACHE:
916                 {
917                         precache_model ("models/vhshield.md3");
918                         precache_model ("models/vehicles/spiderbot.dpm");
919                         precache_model ("models/vehicles/spiderbot_top.dpm");
920                         precache_model ("models/vehicles/spiderbot_barrels.dpm");
921                         precache_model ("models/vehicles/spiderbot_cockpit.dpm");
922                         precache_model ( "models/uziflash.md3");
923
924                         precache_sound ("weapons/uzi_fire.wav" );
925                         precache_sound ("weapons/rocket_impact.wav");
926
927                         precache_sound ("vehicles/spiderbot_die.wav");
928                         precache_sound ("vehicles/spiderbot_idle.wav");
929                         precache_sound ("vehicles/spiderbot_jump.wav");
930                         precache_sound ("vehicles/spiderbot_strafe.wav");
931                         precache_sound ("vehicles/spiderbot_walk.wav");
932                         precache_sound ("vehicles/spiderbot_land.wav");
933                         return true;
934                 }
935         }
936
937         return true;
938 }
939
940 #endif // SVQC
941 #ifdef CSQC
942 float autocvar_cl_vehicle_spiderbot_cross_alpha = 0.6;
943 float autocvar_cl_vehicle_spiderbot_cross_size = 1;
944
945 #define spider_ico  "gfx/vehicles/sbot.tga"
946 #define spider_rkt  "gfx/vehicles/sbot_rpods.tga"
947 #define spider_mgun "gfx/vehicles/sbot_mguns.tga"
948 string spider_xhair; // = "gfx/vehicles/axh-special1.tga";
949
950 float v_spiderbot(float req)
951 {
952         switch(req)
953         {
954                 case VR_HUD:
955                 {
956                         if(autocvar_r_letterbox)
957                                 return true;
958
959                         vector picsize, hudloc = '0 0 0', pic2size, picloc;
960                         float i;
961
962                         // Fetch health & ammo stats
963                         HUD_GETVEHICLESTATS
964
965                         picsize = draw_getimagesize(hud_bg) * autocvar_cl_vehicles_hudscale;
966                         hudloc_y = vid_conheight - picsize_y;
967                         hudloc_x = vid_conwidth * 0.5 - picsize_x * 0.5;
968
969                         drawpic(hudloc, hud_bg, picsize, '1 1 1', autocvar_cl_vehicles_hudalpha, DRAWFLAG_NORMAL);
970
971                         ammo1   *= 0.01;
972                         shield  *= 0.01;
973                         vh_health  *= 0.01;
974                         reload2 *= 0.01;
975
976                         pic2size = draw_getimagesize(spider_ico) * (autocvar_cl_vehicles_hudscale * 0.8);
977                         picloc = picsize * 0.5 - pic2size * 0.5;
978                         if(vh_health < 0.25)
979                                 drawpic(hudloc + picloc, spider_ico, pic2size,  '1 0 0' + '0 1 1' * sin(time * 8),  1, DRAWFLAG_NORMAL);
980                         else
981                                 drawpic(hudloc + picloc, spider_ico, pic2size,  '1 1 1' * vh_health  + '1 0 0' * (1 - vh_health),  1, DRAWFLAG_NORMAL);
982                         drawpic(hudloc + picloc, spider_rkt, pic2size,  '1 1 1' * reload2 + '1 0 0' * (1 - reload2), 1, DRAWFLAG_NORMAL);
983                         drawpic(hudloc + picloc, spider_mgun, pic2size, '1 1 1' * ammo1   + '1 0 0' * (1 - ammo1),   1, DRAWFLAG_NORMAL);
984                         drawpic(hudloc + picloc, hud_sh, pic2size,  '1 1 1', shield, DRAWFLAG_NORMAL);
985
986                 // Health bar
987                         picsize = draw_getimagesize(hud_hp_bar) * autocvar_cl_vehicles_hudscale;
988                         picloc = '69 69 0' * autocvar_cl_vehicles_hudscale;
989                         drawsetcliparea(hudloc_x + picloc_x + (picsize_x * (1 - vh_health)), 0, vid_conwidth, vid_conheight);
990                         drawpic(hudloc + picloc, hud_hp_bar, picsize, '1 1 1', 1 , DRAWFLAG_NORMAL);
991                         drawresetcliparea();
992                 // ..  and icon
993                         picsize = draw_getimagesize(hud_hp_ico) * autocvar_cl_vehicles_hudscale;
994                         picloc = '37 65 0' * autocvar_cl_vehicles_hudscale;
995                         if(vh_health < 0.25)
996                         {
997                                 if(alarm1time < time)
998                                 {
999                                         alarm1time = time + 2;
1000                                         vehicle_alarm(self, CH_PAIN_SINGLE, "vehicles/alarm.wav");
1001                                 }
1002                                 drawpic(hudloc + picloc, hud_hp_ico, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
1003                         }
1004                         else
1005                         {
1006                                 drawpic(hudloc + picloc, hud_hp_ico, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1007                                 if(alarm1time)
1008                                 {
1009                                         vehicle_alarm(self, CH_PAIN_SINGLE, "misc/null.wav");
1010                                         alarm1time = 0;
1011                                 }
1012                         }
1013                 // Shield bar
1014                         picsize = draw_getimagesize(hud_sh_bar) * autocvar_cl_vehicles_hudscale;
1015                         picloc = '69 140 0' * autocvar_cl_vehicles_hudscale;
1016                         drawsetcliparea(hudloc_x + picloc_x + (picsize_x * (1 - shield)), 0, vid_conwidth, vid_conheight);
1017                         drawpic(hudloc + picloc, hud_sh_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1018                         drawresetcliparea();
1019                 // ..  and icon
1020                         picloc = '40 136 0' * autocvar_cl_vehicles_hudscale;
1021                         picsize = draw_getimagesize(hud_sh_ico) * autocvar_cl_vehicles_hudscale;
1022                         if(shield < 0.25)
1023                         {
1024                                 if(alarm2time < time)
1025                                 {
1026                                         alarm2time = time + 1;
1027                                         vehicle_alarm(self, CH_PAIN_SINGLE, "vehicles/alarm_shield.wav");
1028                                 }
1029                                 drawpic(hudloc + picloc, hud_sh_ico, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
1030                         }
1031                         else
1032                         {
1033                                 drawpic(hudloc + picloc, hud_sh_ico, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1034                                 if(alarm2time)
1035                                 {
1036                                         vehicle_alarm(self, CH_PAIN_SINGLE, "misc/null.wav");
1037                                         alarm2time = 0;
1038                                 }
1039                         }
1040
1041                 // Minigun bar
1042                         picsize = draw_getimagesize(hud_ammo1_bar) * autocvar_cl_vehicles_hudscale;
1043                         picloc = '450 69 0' * autocvar_cl_vehicles_hudscale;
1044                         drawsetcliparea(hudloc_x + picloc_x, picloc_y, picsize_x * ammo1, vid_conheight);
1045                         drawpic(hudloc + picloc, hud_ammo1_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1046                         drawresetcliparea();
1047                 // ..  and icon
1048                         picsize = draw_getimagesize(hud_ammo1_ico) * autocvar_cl_vehicles_hudscale;
1049                         picloc = '664 60 0' * autocvar_cl_vehicles_hudscale;
1050                         if(ammo1 < 0.2)
1051                                 drawpic(hudloc + picloc, hud_ammo1_ico, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
1052                         else
1053                                 drawpic(hudloc + picloc, hud_ammo1_ico, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1054
1055                 // Rocket ammo bar
1056                         picsize = draw_getimagesize(hud_ammo2_bar) * autocvar_cl_vehicles_hudscale;
1057                         ammo1 = picsize_x / 8;
1058                         picloc = '450 140 0' * autocvar_cl_vehicles_hudscale;
1059                         drawsetcliparea(hudloc_x + picloc_x, hudloc_y + picloc_y, picsize_x * reload2, vid_conheight);
1060                         drawpic(hudloc + picloc, hud_ammo2_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1061                         drawresetcliparea();
1062
1063                 // ..  and icons
1064                         pic2size = 0.35 * draw_getimagesize(hud_ammo2_ico) * autocvar_cl_vehicles_hudscale;
1065                         picloc_x -= pic2size_x;
1066                         picloc_y += pic2size_y * 2.25;
1067                         if(ammo2 == 9)
1068                         {
1069                                 for(i = 1; i < 9; ++i)
1070                                 {
1071                                         picloc_x += ammo1;
1072                                         drawpic(hudloc + picloc, hud_ammo2_ico, pic2size, ((8 * reload2 <= i) ? '0 0 0' : '1 1 1'), 0.75, DRAWFLAG_NORMAL);
1073                                 }
1074                         }
1075                         else
1076                         {
1077                                 for(i = 1; i < 9; ++i)
1078                                 {
1079                                         picloc_x += ammo1;
1080                                         drawpic(hudloc + picloc, hud_ammo2_ico, pic2size, ((i >= ammo2) ? '1 1 1' : '0 0 0'), 0.75, DRAWFLAG_NORMAL);
1081                                 }
1082                         }
1083                         pic2size = draw_getimagesize(hud_ammo2_ico) * autocvar_cl_vehicles_hudscale;
1084                         picloc = '664 130 0' * autocvar_cl_vehicles_hudscale;
1085                         if(ammo2 == 9)
1086                                 drawpic(hudloc + picloc, hud_ammo2_ico, pic2size, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
1087                         else
1088                                 drawpic(hudloc + picloc, hud_ammo2_ico, pic2size, '1 1 1', 1, DRAWFLAG_NORMAL);
1089
1090                         if (scoreboard_showscores)
1091                                 HUD_DrawScoreboard();
1092                         else
1093                         {
1094                                 switch(getstati(STAT_VEHICLESTAT_W2MODE))
1095                                 {
1096                                         case SBRM_VOLLY:
1097                                                 spider_xhair = "gfx/vehicles/axh-bracket.tga";
1098                                                 break;
1099                                         case SBRM_GUIDE:
1100                                                 spider_xhair = "gfx/vehicles/axh-cross.tga";
1101                                                 break;
1102                                         case SBRM_ARTILLERY:
1103                                                 spider_xhair = "gfx/vehicles/axh-tag.tga";
1104                                                 break;
1105                                         default:
1106                                                 spider_xhair= "gfx/vehicles/axh-tag.tga";
1107                                 }
1108
1109                                 picsize = draw_getimagesize(spider_xhair);
1110                                 picsize_x *= autocvar_cl_vehicle_spiderbot_cross_size;
1111                                 picsize_y *= autocvar_cl_vehicle_spiderbot_cross_size;
1112
1113                                 drawpic('0.5 0 0' * (vid_conwidth - picsize_x) + '0 0.5 0' * (vid_conheight - picsize_y), spider_xhair, picsize, '1 1 1', autocvar_cl_vehicle_spiderbot_cross_alpha, DRAWFLAG_ADDITIVE);
1114                         }
1115                         
1116                         return true;
1117                 }
1118                 case VR_SETUP:
1119                 {
1120                         // Minigun1
1121                         AuxiliaryXhair[0].axh_image   = "gfx/vehicles/axh-ring.tga";
1122                         AuxiliaryXhair[0].axh_scale   = 0.25;
1123                         // Minigun2
1124                         AuxiliaryXhair[1].axh_image   = "gfx/vehicles/axh-ring.tga";
1125                         AuxiliaryXhair[1].axh_scale   = 0.25;
1126                         // Rocket
1127                         AuxiliaryXhair[2].axh_image   = "gfx/vehicles/axh-special1.tga";
1128                         AuxiliaryXhair[2].axh_scale   = 0.5;
1129                 
1130                         return true;
1131                 }
1132                 case VR_PRECACHE:
1133                 {
1134                         return true;
1135                 }
1136         }
1137
1138         return true;
1139 }
1140
1141 #endif // CSQC
1142 #endif // REGISTER_VEHICLE