]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/unit/racer.qc
Merge branch 'master' into Mario/vehicles
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / unit / racer.qc
1 #ifdef REGISTER_VEHICLE
2 REGISTER_VEHICLE(
3 /* VEH_##id   */ RACER,
4 /* function   */ v_racer,
5 /* spawnflags */ VHF_DMGSHAKE | VHF_DMGROLL,
6 /* mins,maxs  */ '-120 -120 -40' * 0.5, '120 120 40' * 0.5,
7 /* model          */ "models/vehicles/wakizashi.dpm",
8 /* head_model */ "null",
9 /* hud_model  */ "models/vehicles/wakizashi_cockpit.dpm",
10 /* tags           */ "", "", "tag_viewport",
11 /* netname        */ "racer",
12 /* fullname   */ _("Racer")
13 );
14 #else
15 #ifdef SVQC
16 float autocvar_g_vehicle_racer;
17
18 float autocvar_g_vehicle_racer_speed_afterburn;
19 float autocvar_g_vehicle_racer_afterburn_cost;
20
21 float autocvar_g_vehicle_racer_waterburn_cost;
22 float autocvar_g_vehicle_racer_waterburn_speed;
23
24 float autocvar_g_vehicle_racer_water_speed_forward;
25 float autocvar_g_vehicle_racer_water_speed_strafe;
26
27 float autocvar_g_vehicle_racer_anglestabilizer;
28 float autocvar_g_vehicle_racer_downforce;
29
30 float autocvar_g_vehicle_racer_speed_forward;
31 float autocvar_g_vehicle_racer_speed_strafe;
32 float autocvar_g_vehicle_racer_springlength;
33 float autocvar_g_vehicle_racer_upforcedamper;
34 float autocvar_g_vehicle_racer_friction;
35
36 float autocvar_g_vehicle_racer_hovertype;
37 float autocvar_g_vehicle_racer_hoverpower;
38
39 float autocvar_g_vehicle_racer_turnroll;
40 float autocvar_g_vehicle_racer_turnspeed;
41 float autocvar_g_vehicle_racer_pitchspeed;
42
43 float autocvar_g_vehicle_racer_energy;
44 float autocvar_g_vehicle_racer_energy_regen;
45 float autocvar_g_vehicle_racer_energy_regen_pause;
46
47 float autocvar_g_vehicle_racer_health;
48 float autocvar_g_vehicle_racer_health_regen;
49 float autocvar_g_vehicle_racer_health_regen_pause;
50
51 float autocvar_g_vehicle_racer_shield;
52 float autocvar_g_vehicle_racer_shield_regen;
53 float autocvar_g_vehicle_racer_shield_regen_pause;
54
55 float autocvar_g_vehicle_racer_cannon_cost;
56 float autocvar_g_vehicle_racer_cannon_damage;
57 float autocvar_g_vehicle_racer_cannon_radius;
58 float autocvar_g_vehicle_racer_cannon_refire;
59 float autocvar_g_vehicle_racer_cannon_speed;
60 float autocvar_g_vehicle_racer_cannon_spread;
61 float autocvar_g_vehicle_racer_cannon_force;
62
63 float autocvar_g_vehicle_racer_rocket_accel;
64 float autocvar_g_vehicle_racer_rocket_damage;
65 float autocvar_g_vehicle_racer_rocket_radius;
66 float autocvar_g_vehicle_racer_rocket_force;
67 float autocvar_g_vehicle_racer_rocket_refire;
68 float autocvar_g_vehicle_racer_rocket_speed;
69 float autocvar_g_vehicle_racer_rocket_turnrate;
70
71 float autocvar_g_vehicle_racer_rocket_locktarget;
72 float autocvar_g_vehicle_racer_rocket_locking_time;
73 float autocvar_g_vehicle_racer_rocket_locking_releasetime;
74 float autocvar_g_vehicle_racer_rocket_locked_time;
75 float autocvar_g_vehicle_racer_rocket_locked_maxangle;
76 float autocvar_g_vehicle_racer_rocket_climbspeed;
77
78 float autocvar_g_vehicle_racer_respawntime;
79
80 float autocvar_g_vehicle_racer_blowup_radius;
81 float autocvar_g_vehicle_racer_blowup_coredamage;
82 float autocvar_g_vehicle_racer_blowup_edgedamage;
83 float autocvar_g_vehicle_racer_blowup_forceintensity;
84
85 float autocvar_g_vehicle_racer_bouncefactor;
86 float autocvar_g_vehicle_racer_bouncestop;
87 vector autocvar_g_vehicle_racer_bouncepain;
88
89 var vector racer_force_from_tag(string tag_name, float spring_length, float max_power);
90
91 void racer_align4point(float _delta)
92 {
93         vector push_vector;
94         float fl_push, fr_push, bl_push, br_push;
95
96         push_vector  = racer_force_from_tag("tag_engine_fr", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
97         fr_push   = force_fromtag_normpower;
98         //vehicles_sweap_collision(force_fromtag_origin, self.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
99
100         push_vector += racer_force_from_tag("tag_engine_fl", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
101         fl_push   = force_fromtag_normpower;
102         //vehicles_sweap_collision(force_fromtag_origin, self.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
103
104         push_vector += racer_force_from_tag("tag_engine_br", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
105         br_push   = force_fromtag_normpower;
106         //vehicles_sweap_collision(force_fromtag_origin, self.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
107
108         push_vector += racer_force_from_tag("tag_engine_bl", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
109         bl_push   = force_fromtag_normpower;
110         //vehicles_sweap_collision(force_fromtag_origin, self.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
111
112         self.velocity += push_vector * _delta;
113         
114         if(pointcontents(self.origin - '0 0 64') == CONTENT_WATER)
115         if(self.owner.BUTTON_CROUCH && time < self.air_finished)
116                 self.velocity_z += 30;
117         else
118                 self.velocity_z += 200;
119
120         // Anti ocilation
121         if(self.velocity_z > 0)
122                 self.velocity_z *= 1 - autocvar_g_vehicle_racer_upforcedamper * _delta;
123
124         push_vector_x =  (fl_push - bl_push);
125         push_vector_x += (fr_push - br_push);
126         push_vector_x *= 360;
127
128         push_vector_z = (fr_push - fl_push);
129         push_vector_z += (br_push - bl_push);
130         push_vector_z *= 360;
131
132         // Apply angle diffrance
133         self.angles_z += push_vector_z * _delta;
134         self.angles_x += push_vector_x * _delta;
135
136         // Apply stabilizer
137         self.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * _delta);
138         self.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * _delta);
139 }
140
141 void racer_fire_cannon(string tagname)
142 {
143         vector v;
144         entity bolt;
145
146         v = gettaginfo(self, gettagindex(self, tagname));
147         bolt = vehicles_projectile("wakizashi_gun_muzzleflash", "weapons/lasergun_fire.wav",
148                                                    v, normalize(v_forward + randomvec() * autocvar_g_vehicle_racer_cannon_spread) * autocvar_g_vehicle_racer_cannon_speed,
149                                                    autocvar_g_vehicle_racer_cannon_damage, autocvar_g_vehicle_racer_cannon_radius, autocvar_g_vehicle_racer_cannon_force,  0,
150                                                    DEATH_VH_WAKI_GUN, PROJECTILE_WAKICANNON, 0, TRUE, TRUE, self.owner);
151
152         // Fix z-aim (for chase mode)
153         v = normalize(trace_endpos - bolt.origin);
154         v_forward_z = v_z * 0.5;
155         bolt.velocity = v_forward * autocvar_g_vehicle_racer_cannon_speed;
156 }
157
158 void racer_rocket_groundhugger()
159 {
160         vector olddir, newdir;
161         float oldvel, newvel;
162
163         self.nextthink  = time;
164
165         if(self.owner.deadflag != DEAD_NO || self.cnt < time)
166         {
167                 self.use();
168                 return;
169         }
170
171         if(!self.realowner.vehicle)
172         {
173                 UpdateCSQCProjectile(self);
174                 return;
175         }
176
177         olddir = normalize(self.velocity);
178         oldvel = vlen(self.velocity);
179         newvel = oldvel + self.lip;
180
181         tracebox(self.origin, self.mins, self.maxs, self.origin + olddir * 64, MOVE_WORLDONLY,self);
182         if(trace_fraction <= 0.5)
183         {
184                 // Hitting somethign soon, just speed ahead
185                 self.velocity = olddir * newvel;
186                 UpdateCSQCProjectile(self);
187                 return;
188         }
189
190         traceline(trace_endpos, trace_endpos - '0 0 64', MOVE_NORMAL, self);
191         if(trace_fraction != 1.0)
192         {
193                 newdir = normalize(trace_endpos + '0 0 64' - self.origin) * autocvar_g_vehicle_racer_rocket_turnrate;
194                 self.velocity = normalize(olddir + newdir) * newvel;
195         }
196         else
197         {
198                 self.velocity = olddir * newvel;
199                 self.velocity_z -= 1600 * sys_frametime; // 2x grav looks better for this one
200         }
201         
202         if(pointcontents(self.origin - '0 0 32') == CONTENT_WATER)
203                 self.velocity_z += 200;
204
205         UpdateCSQCProjectile(self);
206         return;
207 }
208
209 void racer_rocket_tracker()
210 {
211         vector olddir, newdir;
212         float oldvel, newvel;
213
214         self.nextthink  = time;
215
216         if (self.owner.deadflag != DEAD_NO || self.cnt < time)
217         {
218                 self.use();
219                 return;
220         }
221
222         if(!self.realowner.vehicle)
223         {
224                 UpdateCSQCProjectile(self);
225                 return;
226         }
227
228         olddir = normalize(self.velocity);
229         oldvel = vlen(self.velocity);
230         newvel = oldvel + self.lip;
231         makevectors(vectoangles(olddir));
232
233         float time_to_impact = min(vlen(self.enemy.origin - self.origin) / vlen(self.velocity), 1);
234         vector predicted_origin = self.enemy.origin + self.enemy.velocity * time_to_impact;
235
236         traceline(self.origin, self.origin + v_forward * 64 - '0 0 32', MOVE_NORMAL, self);
237         newdir = normalize(predicted_origin - self.origin);
238
239         //vector
240         float height_diff = predicted_origin_z - self.origin_z;
241
242         if(vlen(newdir - v_forward) > autocvar_g_vehicle_racer_rocket_locked_maxangle)
243         {
244                 //bprint("Target lost!\n");
245                 //dprint("OF:", ftos(vlen(newdir - v_forward)), "\n");
246                 self.think = racer_rocket_groundhugger;
247                 return;
248         }
249
250         if(trace_fraction != 1.0 && trace_ent != self.enemy)
251                 newdir_z += 16 * sys_frametime;
252
253         self.velocity = normalize(olddir + newdir * autocvar_g_vehicle_racer_rocket_turnrate) * newvel;
254         self.velocity_z -= 800 * sys_frametime;
255         self.velocity_z += max(height_diff, autocvar_g_vehicle_racer_rocket_climbspeed) * sys_frametime ;
256
257         UpdateCSQCProjectile(self);
258         return;
259 }
260
261 void racer_fire_rocket(string tagname, entity trg)
262 {
263         vector v = gettaginfo(self, gettagindex(self, tagname));
264         entity rocket = rocket = vehicles_projectile("wakizashi_rocket_launch", "weapons/rocket_fire.wav",
265                                                    v, v_forward * autocvar_g_vehicle_racer_rocket_speed,
266                                                    autocvar_g_vehicle_racer_rocket_damage, autocvar_g_vehicle_racer_rocket_radius, autocvar_g_vehicle_racer_rocket_force, 3,
267                                                    DEATH_VH_WAKI_ROCKET, PROJECTILE_WAKIROCKET, 20, FALSE, FALSE, self.owner);
268
269         rocket.lip                        = autocvar_g_vehicle_racer_rocket_accel * sys_frametime;
270         rocket.wait                      = autocvar_g_vehicle_racer_rocket_turnrate;
271         rocket.nextthink                = time;
272         rocket.enemy                    = trg;
273         rocket.cnt                        = time + 15;
274
275         if(trg)
276                 rocket.think                    = racer_rocket_tracker;
277         else
278                 rocket.think                    = racer_rocket_groundhugger;
279 }
280
281 float racer_frame()
282 {
283         entity player, racer;
284         vector df;
285         float ftmp;
286
287         if(intermission_running)
288         {
289                 self.vehicle.velocity = '0 0 0';
290                 return 1;
291         }
292
293         player  = self;
294         racer   = self.vehicle;
295         self    = racer;
296
297         vehicles_painframe();
298
299         if(pointcontents(racer.origin) != CONTENT_WATER)
300                 racer.air_finished = time + 5;
301
302         if(racer.deadflag != DEAD_NO)
303         {
304                 self = player;
305                 player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
306                 return 1;
307         }
308
309         racer_align4point(frametime);
310
311         player.BUTTON_ZOOM = player.BUTTON_CROUCH = 0;
312
313         crosshair_trace(player);
314
315         racer.angles_x *= -1;
316
317         // Yaw
318         ftmp = autocvar_g_vehicle_racer_turnspeed * frametime;
319         ftmp = bound(-ftmp, shortangle_f(player.v_angle_y - racer.angles_y, racer.angles_y), ftmp);
320         racer.angles_y = anglemods(racer.angles_y + ftmp);
321
322         // Roll
323         racer.angles_z += -ftmp * autocvar_g_vehicle_racer_turnroll * frametime;
324
325         // Pitch
326         ftmp = autocvar_g_vehicle_racer_pitchspeed  * frametime;
327         ftmp = bound(-ftmp, shortangle_f(player.v_angle_x - racer.angles_x, racer.angles_x), ftmp);
328         racer.angles_x = bound(-30, anglemods(racer.angles_x + ftmp), 30);
329
330         makevectors(racer.angles);
331         racer.angles_x *= -1;
332
333         //ftmp = racer.velocity_z;
334         df = racer.velocity * -autocvar_g_vehicle_racer_friction;
335         //racer.velocity_z = ftmp;
336
337         if(vlen(player.movement) != 0)
338         {
339                 if(pointcontents(racer.origin) == CONTENT_WATER)
340                 {
341                         if(player.movement_x) { df += v_forward * ((player.movement_x > 0) ? autocvar_g_vehicle_racer_water_speed_forward : -autocvar_g_vehicle_racer_water_speed_forward); }
342                         if(player.movement_y) { df += v_right * ((player.movement_y > 0) ? autocvar_g_vehicle_racer_water_speed_strafe : -autocvar_g_vehicle_racer_water_speed_strafe); }
343                 }
344                 else
345                 {
346                         if(player.movement_x) { df += v_forward * ((player.movement_x > 0) ? autocvar_g_vehicle_racer_speed_forward : -autocvar_g_vehicle_racer_speed_forward); }
347                         if(player.movement_y) { df += v_right * ((player.movement_y > 0) ? autocvar_g_vehicle_racer_speed_strafe : -autocvar_g_vehicle_racer_speed_strafe); }
348                 }
349
350                 if(self.sound_nexttime < time || self.sounds != 1)
351                 {
352                         self.sounds = 1;
353                         self.sound_nexttime = time + 10.922667; //soundlength("vehicles/racer_move.wav");
354                         sound (self, CH_TRIGGER_SINGLE, "vehicles/racer_move.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
355                 }
356         }
357         else
358         {
359                 if(self.sound_nexttime < time || self.sounds != 0)
360                 {
361                         self.sounds = 0;
362                         self.sound_nexttime = time + 11.888604; //soundlength("vehicles/racer_idle.wav");
363                         sound (self, CH_TRIGGER_SINGLE, "vehicles/racer_idle.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
364                 }
365         }
366
367         // Afterburn
368         if (player.BUTTON_JUMP && racer.vehicle_energy >= (autocvar_g_vehicle_racer_afterburn_cost * frametime))
369         {
370                 if(time - racer.wait > 0.2)
371                         pointparticles(particleeffectnum("wakizashi_booster_smoke"), self.origin - v_forward * 32, v_forward  * vlen(self.velocity), 1);
372
373                 racer.wait = time;
374
375                 if(pointcontents(racer.origin) == CONTENT_WATER)
376                 {
377                         racer.vehicle_energy -= autocvar_g_vehicle_racer_waterburn_cost * frametime;
378                         df += (v_forward * autocvar_g_vehicle_racer_waterburn_speed);
379                 }
380                 else
381                 {
382                         racer.vehicle_energy -= autocvar_g_vehicle_racer_afterburn_cost * frametime;
383                         df += (v_forward * autocvar_g_vehicle_racer_speed_afterburn);
384                 }
385
386                 if(racer.invincible_finished < time)
387                 {
388                         traceline(racer.origin, racer.origin - '0 0 256', MOVE_NORMAL, self);
389                         if(trace_fraction != 1.0)
390                                 pointparticles(particleeffectnum("smoke_small"), trace_endpos, '0 0 0', 1);
391
392                         racer.invincible_finished = time + 0.1 + (random() * 0.1);
393                 }
394
395                 if(racer.strength_finished < time)
396                 {
397                         racer.strength_finished = time + 10.922667; //soundlength("vehicles/racer_boost.wav");
398                         sound (racer.tur_head, CH_TRIGGER_SINGLE, "vehicles/racer_boost.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
399                 }
400         }
401         else
402         {
403                 racer.strength_finished = 0;
404                 sound (racer.tur_head, CH_TRIGGER_SINGLE, "misc/null.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
405         }
406
407         df -= v_up * (vlen(racer.velocity) * autocvar_g_vehicle_racer_downforce);
408         player.movement = racer.velocity += df * frametime;
409
410         if(!forbidWeaponUse(player))
411         if(player.BUTTON_ATCK)
412         if(time > racer.attack_finished_single)
413         if(racer.vehicle_energy >= autocvar_g_vehicle_racer_cannon_cost)
414         {
415                 racer.vehicle_energy -= autocvar_g_vehicle_racer_cannon_cost;
416                 racer.wait = time;
417
418                 crosshair_trace(player);
419                 if(racer.cnt)
420                 {
421                         racer_fire_cannon("tag_fire1");
422                         racer.cnt = 0;
423                 }
424                 else
425                 {
426                         racer_fire_cannon("tag_fire2");
427                         racer.cnt = 1;
428                 }
429                 racer.attack_finished_single = time + autocvar_g_vehicle_racer_cannon_refire;
430         }
431
432         if(autocvar_g_vehicle_racer_rocket_locktarget)
433         {
434                 vehicles_locktarget((1 / autocvar_g_vehicle_racer_rocket_locking_time) * frametime,
435                                                  (1 / autocvar_g_vehicle_racer_rocket_locking_releasetime) * frametime,
436                                                  autocvar_g_vehicle_racer_rocket_locked_time);
437
438                 if(self.lock_target)
439                 {
440                         if(racer.lock_strength == 1)
441                                 UpdateAuxiliaryXhair(player, real_origin(self.lock_target), '1 0 0', 0);
442                         else if(self.lock_strength > 0.5)
443                                 UpdateAuxiliaryXhair(player, real_origin(self.lock_target), '0 1 0', 0);
444                         else if(self.lock_strength < 0.5)
445                                 UpdateAuxiliaryXhair(player, real_origin(self.lock_target), '0 0 1', 0);
446                 }
447         }
448
449         if(!forbidWeaponUse(player))
450         if(time > racer.delay)
451         if(player.BUTTON_ATCK2)
452         {
453                 racer.misc_bulletcounter += 1;
454                 racer.delay = time + 0.3;
455
456                 if(racer.misc_bulletcounter == 1)
457                         racer_fire_rocket("tag_rocket_r", (racer.lock_strength == 1 && racer.lock_target) ? racer.lock_target : world);
458                 else if(racer.misc_bulletcounter == 2)
459                 {
460                         racer_fire_rocket("tag_rocket_l", (racer.lock_strength == 1 && racer.lock_target) ? racer.lock_target : world);
461                         racer.lock_strength  = 0;
462                         racer.lock_target       = world;
463                         racer.misc_bulletcounter = 0;
464
465                         racer.delay = time + autocvar_g_vehicle_racer_rocket_refire;
466                         racer.lip = time;
467                 }
468         }
469         player.vehicle_reload1 = bound(0, 100 * ((time - racer.lip) / (racer.delay - racer.lip)), 100);
470
471         if(racer.vehicle_flags  & VHF_SHIELDREGEN)
472                 vehicles_regen(racer.dmg_time, vehicle_shield, autocvar_g_vehicle_racer_shield, autocvar_g_vehicle_racer_shield_regen_pause, autocvar_g_vehicle_racer_shield_regen, frametime, TRUE);
473
474         if(racer.vehicle_flags  & VHF_HEALTHREGEN)
475                 vehicles_regen(racer.dmg_time, vehicle_health, autocvar_g_vehicle_racer_health, autocvar_g_vehicle_racer_health_regen_pause, autocvar_g_vehicle_racer_health_regen, frametime, FALSE);
476
477         if(racer.vehicle_flags  & VHF_ENERGYREGEN)
478                 vehicles_regen(racer.wait, vehicle_energy, autocvar_g_vehicle_racer_energy, autocvar_g_vehicle_racer_energy_regen_pause, autocvar_g_vehicle_racer_energy_regen, frametime, FALSE);
479
480
481         VEHICLE_UPDATE_PLAYER(player, health, racer);
482         VEHICLE_UPDATE_PLAYER(player, energy, racer);
483
484         if(racer.vehicle_flags & VHF_HASSHIELD)
485                 VEHICLE_UPDATE_PLAYER(player, shield, racer);
486
487         player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
488         setorigin(player,racer.origin + '0 0 32');
489         player.velocity = racer.velocity;
490
491         self = player;
492         return 1;
493 }
494
495 void racer_think()
496 {
497         self.nextthink = time;
498
499         float pushdeltatime = time - self.lastpushtime;
500         if (pushdeltatime > 0.15) pushdeltatime = 0;
501         self.lastpushtime = time;
502         if(!pushdeltatime) return;
503
504         tracebox(self.origin, self.mins, self.maxs, self.origin - ('0 0 1' * autocvar_g_vehicle_racer_springlength), MOVE_NOMONSTERS, self);
505
506         vector df = self.velocity * -autocvar_g_vehicle_racer_friction;
507         df_z += (1 - trace_fraction) * autocvar_g_vehicle_racer_hoverpower + sin(time * 2) * (autocvar_g_vehicle_racer_springlength * 2);
508
509         if(pointcontents(self.origin - '0 0 64') == CONTENT_WATER)
510                 self.velocity_z += 200;
511
512         self.velocity += df * pushdeltatime;
513         if(self.velocity_z > 0)
514                 self.velocity_z *= 1 - autocvar_g_vehicle_racer_upforcedamper * pushdeltatime;
515
516         self.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * pushdeltatime);
517         self.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * pushdeltatime);
518         
519         CSQCMODEL_AUTOUPDATE();
520 }
521
522 void racer_exit(float eject)
523 {
524         vector spot;
525
526         self.think        = racer_think;
527         self.nextthink  = time;
528         self.movetype   = MOVETYPE_BOUNCE;
529         sound (self.tur_head, CH_TRIGGER_SINGLE, "misc/null.wav", VOL_VEHICLEENGINE, ATTEN_NORM);
530
531         if(!self.owner)
532                 return;
533
534         makevectors(self.angles);
535         if(eject)
536         {
537                 spot = self.origin + v_forward * 100 + '0 0 64';
538                 spot = vehicles_findgoodexit(spot);
539                 setorigin(self.owner , spot);
540                 self.owner.velocity = (v_up + v_forward * 0.25) * 750;
541                 self.owner.oldvelocity = self.owner.velocity;
542         }
543         else
544         {
545                 if(vlen(self.velocity) > 2 * autocvar_sv_maxairspeed)
546                 {
547                         self.owner.velocity = normalize(self.velocity) * autocvar_sv_maxairspeed * 2;
548                         self.owner.velocity_z += 200;
549                         spot = self.origin + v_forward * 32 + '0 0 32';
550                         spot = vehicles_findgoodexit(spot);
551                 }
552                 else
553                 {
554                         self.owner.velocity = self.velocity * 0.5;
555                         self.owner.velocity_z += 10;
556                         spot = self.origin - v_forward * 200 + '0 0 32';
557                         spot = vehicles_findgoodexit(spot);
558                 }
559                 self.owner.oldvelocity = self.owner.velocity;
560                 setorigin(self.owner , spot);
561         }
562         antilag_clear(self.owner);
563         self.owner = world;
564 }
565
566 void racer_blowup()
567 {
568         self.deadflag   = DEAD_DEAD;
569         self.vehicle_exit(VHEF_NORMAL);
570
571         RadiusDamage (self, self.enemy, autocvar_g_vehicle_racer_blowup_coredamage,
572                                         autocvar_g_vehicle_racer_blowup_edgedamage,
573                                         autocvar_g_vehicle_racer_blowup_radius, world,
574                                         autocvar_g_vehicle_racer_blowup_forceintensity,
575                                         DEATH_VH_WAKI_DEATH, world);
576
577         self.nextthink  = time + autocvar_g_vehicle_racer_respawntime;
578         self.think        = vehicles_spawn;
579         self.movetype   = MOVETYPE_NONE;
580         self.effects    = EF_NODRAW;
581
582         self.colormod  = '0 0 0';
583         self.avelocity = '0 0 0';
584         self.velocity  = '0 0 0';
585
586         setorigin(self, self.pos1);
587 }
588
589 void racer_blowup_think()
590 {
591         self.nextthink = time;
592         
593         if(time >= self.delay)
594                 racer_blowup();
595         
596         CSQCMODEL_AUTOUPDATE();
597 }
598
599 void racer_deadtouch()
600 {
601         self.avelocity_x *= 0.7;
602         self.cnt -= 1;
603         if(self.cnt <= 0)
604                 racer_blowup();
605 }
606
607 void spawnfunc_vehicle_racer()
608 {
609         if(!autocvar_g_vehicle_racer) { remove(self); return; }
610         if(!vehicle_initialize(VEH_RACER, FALSE)) { remove(self); return; }
611 }
612
613 float v_racer(float req)
614 {
615         switch(req)
616         {
617                 case VR_IMPACT:
618                 {
619                         if(autocvar_g_vehicle_racer_bouncepain)
620                                 vehicles_impact(autocvar_g_vehicle_racer_bouncepain_x, autocvar_g_vehicle_racer_bouncepain_y, autocvar_g_vehicle_racer_bouncepain_z);
621                         return TRUE;
622                 }
623                 case VR_ENTER:
624                 {
625                         self.movetype = MOVETYPE_BOUNCE;
626                         self.owner.vehicle_health = (self.vehicle_health / autocvar_g_vehicle_racer_health)  * 100;
627                         self.owner.vehicle_shield = (self.vehicle_shield / autocvar_g_vehicle_racer_shield)  * 100;
628
629                         if(self.owner.flagcarried)
630                            setorigin(self.owner.flagcarried, '-190 0 96');
631                            
632                         return TRUE;
633                 }
634                 case VR_THINK:
635                 {
636                         return TRUE;
637                 }
638                 case VR_DEATH:
639                 {
640                         self.health                     = 0;
641                         self.event_damage       = func_null;
642                         self.solid                      = SOLID_CORPSE;
643                         self.takedamage         = DAMAGE_NO;
644                         self.deadflag           = DEAD_DYING;
645                         self.movetype           = MOVETYPE_BOUNCE;
646                         self.wait                       = time;
647                         self.delay                      = 2 + time + random() * 3;
648                         self.cnt                        = 1 + random() * 2;
649                         self.touch                      = racer_deadtouch;
650
651                         pointparticles(particleeffectnum("explosion_medium"), self.origin, '0 0 0', 1);
652
653                         if(random() < 0.5)
654                                 self.avelocity_z = 32;
655                         else
656                                 self.avelocity_z = -32;
657
658                         self.avelocity_x = -vlen(self.velocity) * 0.2;
659                         self.velocity += '0 0 700';
660                         self.colormod = '-0.5 -0.5 -0.5';
661
662                         self.think = racer_blowup_think;
663                         self.nextthink = time;
664         
665                         return TRUE;
666                 }
667                 case VR_SPAWN:
668                 {
669                         if(self.scale != 0.5)
670                         {
671                                 if(autocvar_g_vehicle_racer_hovertype != 0)
672                                         racer_force_from_tag = vehicles_force_fromtag_maglev;
673                                 else
674                                         racer_force_from_tag = vehicles_force_fromtag_hover;
675
676                                 // FIXME: this be hakkz, fix the models insted (scale body, add tag_viewport to the hudmodel).
677                                 self.scale = 0.5;
678                                 setattachment(self.vehicle_hudmodel, self, "");
679                                 setattachment(self.vehicle_viewport, self, "tag_viewport");
680
681                                 self.mass                          = 900;
682                         }
683
684                         self.think                = racer_think;
685                         self.nextthink    = time;
686                         self.vehicle_health = autocvar_g_vehicle_racer_health;
687                         self.vehicle_shield = autocvar_g_vehicle_racer_shield;
688
689                         self.movetype     = MOVETYPE_TOSS;
690                         self.solid                = SOLID_SLIDEBOX;
691                         self.delay                = time;
692                         self.scale                = 0.5;
693                         
694                         self.PlayerPhysplug = racer_frame;
695                         
696                         self.bouncefactor = autocvar_g_vehicle_racer_bouncefactor;
697                         self.bouncestop = autocvar_g_vehicle_racer_bouncestop;
698                         self.damageforcescale = 0.5;
699                         self.vehicle_health = autocvar_g_vehicle_racer_health;
700                         self.vehicle_shield = autocvar_g_vehicle_racer_shield;
701                         
702                         return TRUE;
703                 }
704                 case VR_SETUP:
705                 {
706                         if(autocvar_g_vehicle_racer_energy)
707                         if(autocvar_g_vehicle_racer_energy_regen)
708                                 self.vehicle_flags |= VHF_ENERGYREGEN;
709
710                         if(autocvar_g_vehicle_racer_shield)
711                                 self.vehicle_flags |= VHF_HASSHIELD;
712
713                         if(autocvar_g_vehicle_racer_shield_regen)
714                                 self.vehicle_flags |= VHF_SHIELDREGEN;
715
716                         if(autocvar_g_vehicle_racer_health_regen)
717                                 self.vehicle_flags |= VHF_HEALTHREGEN;
718                                 
719                         self.vehicle_exit = racer_exit;
720                         self.respawntime = autocvar_g_vehicle_racer_respawntime;
721                         self.vehicle_health = autocvar_g_vehicle_racer_health;
722                         self.vehicle_shield = autocvar_g_vehicle_racer_shield;
723                         self.max_health = self.vehicle_health;
724                                 
725                         return TRUE;
726                 }
727                 case VR_PRECACHE:
728                 {
729                         precache_sound ("weapons/lasergun_fire.wav");
730                         precache_sound ("weapons/rocket_fire.wav");
731
732                         precache_sound ("vehicles/racer_idle.wav");
733                         precache_sound ("vehicles/racer_move.wav");
734                         precache_sound ("vehicles/racer_boost.wav");
735
736                         precache_model ("models/vhshield.md3");
737                         precache_model ("models/vehicles/wakizashi.dpm");
738                         precache_model ("models/vehicles/wakizashi_cockpit.dpm");
739                         return TRUE;
740                 }
741         }
742
743         return TRUE;
744 }
745
746 #endif // SVQC
747 #ifdef CSQC
748
749 #define waki_ico "gfx/vehicles/waki.tga"
750 #define waki_eng "gfx/vehicles/waki_e.tga"
751 #define waki_gun "gfx/vehicles/waki_guns.tga"
752 #define waki_rkt "gfx/vehicles/waki_rockets.tga"
753 #define waki_xhair "gfx/vehicles/axh-special1.tga"
754
755 float v_racer(float req)
756 {
757         switch(req)
758         {
759                 case VR_HUD:
760                 {
761                         if(autocvar_r_letterbox)
762                                 return TRUE;
763
764                         vector picsize, hudloc = '0 0 0', pic2size, picloc;
765
766                         // Fetch health & ammo stats
767                         HUD_GETVEHICLESTATS
768
769                         picsize = draw_getimagesize(hud_bg) * autocvar_cl_vehicles_hudscale;
770                         hudloc_y = vid_conheight - picsize_y;
771                         hudloc_x = vid_conwidth * 0.5 - picsize_x * 0.5;
772
773                         drawpic(hudloc, hud_bg, picsize, '1 1 1', autocvar_cl_vehicles_hudalpha, DRAWFLAG_NORMAL);
774
775                         shield  *= 0.01;
776                         vh_health  *= 0.01;
777                         energy  *= 0.01;
778                         reload1 *= 0.01;
779
780                         pic2size = draw_getimagesize(waki_ico) * (autocvar_cl_vehicles_hudscale * 0.8);
781                         picloc = picsize * 0.5 - pic2size * 0.5;
782                         if(vh_health < 0.25)
783                                 drawpic(hudloc + picloc, waki_ico, pic2size,  '1 0 0' + '0 1 1' * sin(time * 8),  1, DRAWFLAG_NORMAL);
784                         else
785                                 drawpic(hudloc + picloc, waki_ico, pic2size,  '1 1 1' * vh_health  + '1 0 0' * (1 - vh_health),  1, DRAWFLAG_NORMAL);
786                         drawpic(hudloc + picloc, waki_eng, pic2size, '1 1 1' * energy   + '1 0 0' * (1 - energy),   1, DRAWFLAG_NORMAL);
787                         drawpic(hudloc + picloc, waki_gun, pic2size, '1 1 1' * energy   + '1 0 0' * (1 - energy),   1, DRAWFLAG_NORMAL);
788                         drawpic(hudloc + picloc, waki_rkt, pic2size,  '1 1 1' * reload1 + '1 0 0' * (1 - reload1), 1, DRAWFLAG_NORMAL);
789                         drawpic(hudloc + picloc, hud_sh, pic2size,  '1 1 1', shield, DRAWFLAG_NORMAL);
790
791                 // Health bar
792                         picsize = draw_getimagesize(hud_hp_bar) * autocvar_cl_vehicles_hudscale;
793                         picloc = '69 69 0' * autocvar_cl_vehicles_hudscale;
794                         drawsetcliparea(hudloc_x + picloc_x + (picsize_x * (1 - vh_health)), 0, vid_conwidth, vid_conheight);
795                         drawpic(hudloc + picloc, hud_hp_bar, picsize, '1 1 1', 1 , DRAWFLAG_NORMAL);
796                         drawresetcliparea();
797                 // ..  and icon
798                         picsize = draw_getimagesize(hud_hp_ico) * autocvar_cl_vehicles_hudscale;
799                         picloc = '37 65 0' * autocvar_cl_vehicles_hudscale;
800                         if(vh_health < 0.25)
801                         {
802                                 if(alarm1time < time)
803                                 {
804                                         alarm1time = time + 2;
805                                         vehicle_alarm(self, CH_PAIN_SINGLE, "vehicles/alarm.wav");
806                                 }
807
808                                 drawpic(hudloc + picloc, hud_hp_ico, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
809                         }
810                         else
811                         {
812                                 drawpic(hudloc + picloc, hud_hp_ico, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
813                                 if(alarm1time)
814                                 {
815                                         vehicle_alarm(self, CH_PAIN_SINGLE, "misc/null.wav");
816                                         alarm1time = 0;
817                                 }
818                         }
819
820
821                 // Shield bar
822                         picsize = draw_getimagesize(hud_sh_bar) * autocvar_cl_vehicles_hudscale;
823                         picloc = '69 140 0' * autocvar_cl_vehicles_hudscale;
824                         drawsetcliparea(hudloc_x + picloc_x + (picsize_x * (1 - shield)), 0, vid_conwidth, vid_conheight);
825                         drawpic(hudloc + picloc, hud_sh_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
826                         drawresetcliparea();
827                 // ..  and icon
828                         picloc = '40 136 0' * autocvar_cl_vehicles_hudscale;
829                         picsize = draw_getimagesize(hud_sh_ico) * autocvar_cl_vehicles_hudscale;
830                         if(shield < 0.25)
831                         {
832                                 if(alarm2time < time)
833                                 {
834                                         alarm2time = time + 1;
835                                         vehicle_alarm(self, CH_TRIGGER_SINGLE, "vehicles/alarm_shield.wav");
836                                 }
837                                 drawpic(hudloc + picloc, hud_sh_ico, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
838                         }
839                         else
840                         {
841                                 drawpic(hudloc + picloc, hud_sh_ico, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
842                                 if(alarm2time)
843                                 {
844                                         vehicle_alarm(self, CH_TRIGGER_SINGLE, "misc/null.wav");
845                                         alarm2time = 0;
846                                 }
847                         }
848
849                 // Gun bar
850                         picsize = draw_getimagesize(hud_ammo1_bar) * autocvar_cl_vehicles_hudscale;
851                         picloc = '450 69 0' * autocvar_cl_vehicles_hudscale;
852                         drawsetcliparea(hudloc_x + picloc_x, picloc_y, picsize_x * energy, vid_conheight);
853                         drawpic(hudloc + picloc, hud_ammo1_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
854                         drawresetcliparea();
855                 // ..  and icon
856                         picsize = draw_getimagesize(hud_ammo1_ico) * autocvar_cl_vehicles_hudscale;
857                         picloc = '664 60 0' * autocvar_cl_vehicles_hudscale;
858                         if(energy < 0.2)
859                                 drawpic(hudloc + picloc, hud_ammo1_ico, picsize, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
860                         else
861                                 drawpic(hudloc + picloc, hud_ammo1_ico, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
862
863                 // Bomb bar
864                         picsize = draw_getimagesize(hud_ammo2_bar) * autocvar_cl_vehicles_hudscale;
865                         picloc = '450 140 0' * autocvar_cl_vehicles_hudscale;
866                         drawsetcliparea(hudloc_x + picloc_x, hudloc_y + picloc_y, picsize_x * reload1, vid_conheight);
867                         drawpic(hudloc + picloc, hud_ammo2_bar, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
868                         drawresetcliparea();
869                 // ..  and icon
870                         pic2size = draw_getimagesize(hud_ammo2_ico) * autocvar_cl_vehicles_hudscale;
871                         picloc = '664 130 0' * autocvar_cl_vehicles_hudscale;
872                         if(reload1 != 1)
873                                 drawpic(hudloc + picloc, hud_ammo2_ico, pic2size, '1 0 0' + '0 1 1' * sin(time * 8), 1, DRAWFLAG_NORMAL);
874                         else
875                                 drawpic(hudloc + picloc, hud_ammo2_ico, pic2size, '1 1 1', 1, DRAWFLAG_NORMAL);
876
877                         if (scoreboard_showscores)
878                                 HUD_DrawScoreboard();
879                         else
880                         {
881                                 picsize = draw_getimagesize(waki_xhair);
882                                 picsize_x *= 0.5;
883                                 picsize_y *= 0.5;
884
885
886                                 drawpic('0.5 0 0' * (vid_conwidth - picsize_x) + '0 0.5 0' * (vid_conheight - picsize_y), waki_xhair, picsize, '1 1 1', 1, DRAWFLAG_NORMAL);
887                         }
888                         return TRUE;
889                 }
890                 case VR_SETUP:
891                 {
892                         AuxiliaryXhair[0].axh_image = "gfx/vehicles/axh-bracket.tga";
893                         AuxiliaryXhair[0].axh_scale = 0.25;
894                         return TRUE;
895                 }
896                 case VR_PRECACHE:
897                 {
898                         precache_model ("models/vhshield.md3");
899                         precache_model ("models/vehicles/wakizashi.dpm");
900                         precache_model ("models/vehicles/wakizashi_cockpit.dpm");
901                         return TRUE;
902                 }
903         }
904
905         return TRUE;
906 }
907
908 #endif // CSQC
909 #endif // REGISTER_VEHICLE