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