Merge branch 'master' into TimePath/unified_weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle / racer.qc
1 #ifndef VEHICLE_RACER
2 #define VEHICLE_RACER
3
4 #include "racer_weapon.qc"
5
6 CLASS(Racer, Vehicle)
7 /* spawnflags */ ATTRIB(Racer, spawnflags, int, VHF_DMGSHAKE | VHF_DMGROLL);
8 /* mins       */ ATTRIB(Racer, mins, vector, '-120 -120 -40' * 0.5);
9 /* maxs       */ ATTRIB(Racer, maxs, vector, '120 120 40' * 0.5);
10 /* model          */ ATTRIB(Racer, mdl, string, "models/vehicles/wakizashi.dpm");
11 /* model          */ ATTRIB(Racer, model, string, "models/vehicles/wakizashi.dpm");
12 /* head_model */ ATTRIB(Racer, head_model, string, "null");
13 /* hud_model  */ ATTRIB(Racer, hud_model, string, "models/vehicles/wakizashi_cockpit.dpm");
14 /* tags       */ ATTRIB(Racer, tag_head, string, "");
15 /* tags       */ ATTRIB(Racer, tag_hud, string, "");
16 /* tags       */ ATTRIB(Racer, tag_view, string, "tag_viewport");
17 /* netname    */ ATTRIB(Racer, netname, string, "racer");
18 /* fullname   */ ATTRIB(Racer, vehicle_name, string, _("Racer"));
19 /* icon       */ ATTRIB(Racer, m_icon, string, "vehicle_racer");
20 ENDCLASS(Racer)
21 REGISTER_VEHICLE(RACER, NEW(Racer));
22
23 #endif
24
25 #ifdef IMPLEMENTATION
26
27 #include "racer_weapon.qc"
28
29 #ifdef SVQC
30 #include "../../effects/effects.qh"
31 #include "../../triggers/trigger/impulse.qh"
32
33 bool autocvar_g_vehicle_racer;
34
35 float autocvar_g_vehicle_racer_speed_afterburn;
36 float autocvar_g_vehicle_racer_afterburn_cost;
37
38 float autocvar_g_vehicle_racer_waterburn_cost;
39 float autocvar_g_vehicle_racer_waterburn_speed;
40
41 float autocvar_g_vehicle_racer_water_speed_forward;
42 float autocvar_g_vehicle_racer_water_speed_strafe;
43
44 float autocvar_g_vehicle_racer_pitchlimit = 30;
45
46 float autocvar_g_vehicle_racer_water_downforce = 0.03;
47 float autocvar_g_vehicle_racer_water_upforcedamper = 15;
48
49 float autocvar_g_vehicle_racer_anglestabilizer;
50 float autocvar_g_vehicle_racer_downforce;
51
52 float autocvar_g_vehicle_racer_speed_forward;
53 float autocvar_g_vehicle_racer_speed_strafe;
54 float autocvar_g_vehicle_racer_springlength;
55 float autocvar_g_vehicle_racer_upforcedamper;
56 float autocvar_g_vehicle_racer_friction;
57
58 float autocvar_g_vehicle_racer_water_time = 5;
59
60 float autocvar_g_vehicle_racer_hovertype;
61 float autocvar_g_vehicle_racer_hoverpower;
62
63 float autocvar_g_vehicle_racer_turnroll;
64 float autocvar_g_vehicle_racer_turnspeed;
65 float autocvar_g_vehicle_racer_pitchspeed;
66
67 float autocvar_g_vehicle_racer_energy;
68 float autocvar_g_vehicle_racer_energy_regen;
69 float autocvar_g_vehicle_racer_energy_regen_pause;
70
71 float autocvar_g_vehicle_racer_health;
72 float autocvar_g_vehicle_racer_health_regen;
73 float autocvar_g_vehicle_racer_health_regen_pause;
74
75 float autocvar_g_vehicle_racer_shield;
76 float autocvar_g_vehicle_racer_shield_regen;
77 float autocvar_g_vehicle_racer_shield_regen_pause;
78
79 float autocvar_g_vehicle_racer_rocket_locktarget;
80 float autocvar_g_vehicle_racer_rocket_locking_time;
81 float autocvar_g_vehicle_racer_rocket_locking_releasetime;
82 float autocvar_g_vehicle_racer_rocket_locked_time;
83
84 float autocvar_g_vehicle_racer_respawntime;
85
86 float autocvar_g_vehicle_racer_blowup_radius;
87 float autocvar_g_vehicle_racer_blowup_coredamage;
88 float autocvar_g_vehicle_racer_blowup_edgedamage;
89 float autocvar_g_vehicle_racer_blowup_forceintensity;
90
91 float autocvar_g_vehicle_racer_bouncefactor;
92 float autocvar_g_vehicle_racer_bouncestop;
93 vector autocvar_g_vehicle_racer_bouncepain;
94
95 .float racer_watertime;
96
97 var vector racer_force_from_tag(string tag_name, float spring_length, float max_power);
98
99 void racer_align4point(float _delta)
100 {SELFPARAM();
101         vector push_vector;
102         float fl_push, fr_push, bl_push, br_push;
103
104         push_vector  = racer_force_from_tag("tag_engine_fr", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
105         fr_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_fl", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
109         fl_push   = force_fromtag_normpower;
110         //vehicles_sweap_collision(force_fromtag_origin, self.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
111
112         push_vector += racer_force_from_tag("tag_engine_br", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
113         br_push   = force_fromtag_normpower;
114         //vehicles_sweap_collision(force_fromtag_origin, self.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
115
116         push_vector += racer_force_from_tag("tag_engine_bl", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
117         bl_push   = force_fromtag_normpower;
118         //vehicles_sweap_collision(force_fromtag_origin, self.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
119
120         self.velocity += push_vector * _delta;
121
122         float uforce = autocvar_g_vehicle_racer_upforcedamper;
123
124         int cont = pointcontents(self.origin - '0 0 64');
125         if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
126         {
127                 uforce = autocvar_g_vehicle_racer_water_upforcedamper;
128
129                 if(self.owner.BUTTON_CROUCH && time < self.air_finished)
130                         self.velocity_z += 30;
131                 else
132                         self.velocity_z += 200;
133         }
134
135
136         // Anti ocilation
137         if(self.velocity_z > 0)
138                 self.velocity_z *= 1 - uforce * _delta;
139
140         push_vector_x =  (fl_push - bl_push);
141         push_vector_x += (fr_push - br_push);
142         push_vector_x *= 360;
143
144         push_vector_z = (fr_push - fl_push);
145         push_vector_z += (br_push - bl_push);
146         push_vector_z *= 360;
147
148         // Apply angle diffrance
149         self.angles_z += push_vector_z * _delta;
150         self.angles_x += push_vector_x * _delta;
151
152         // Apply stabilizer
153         self.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * _delta);
154         self.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * _delta);
155 }
156
157 void racer_fire_rocket_aim(string tagname, entity trg)
158 {
159         SELFPARAM();
160         vector v = gettaginfo(self, gettagindex(self, tagname));
161         racer_fire_rocket(v, v_forward, trg);
162 }
163
164 float racer_frame()
165 {SELFPARAM();
166         entity player, racer;
167         vector df;
168         float ftmp;
169
170         if(intermission_running)
171         {
172                 self.vehicle.velocity = '0 0 0';
173                 self.vehicle.avelocity = '0 0 0';
174                 return 1;
175         }
176
177         player  = self;
178         racer   = self.vehicle;
179         setself(racer);
180
181         vehicles_painframe();
182
183         if(pointcontents(racer.origin) != CONTENT_WATER)
184                 racer.air_finished = time + autocvar_g_vehicle_racer_water_time;
185
186         if(racer.deadflag != DEAD_NO)
187         {
188                 setself(player);
189                 player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
190                 return 1;
191         }
192
193         racer_align4point(PHYS_INPUT_TIMELENGTH);
194
195         player.BUTTON_ZOOM = player.BUTTON_CROUCH = 0;
196
197         crosshair_trace(player);
198
199         racer.angles_x *= -1;
200
201         // Yaw
202         ftmp = autocvar_g_vehicle_racer_turnspeed * PHYS_INPUT_TIMELENGTH;
203         ftmp = bound(-ftmp, shortangle_f(player.v_angle_y - racer.angles_y, racer.angles_y), ftmp);
204         racer.angles_y = anglemods(racer.angles_y + ftmp);
205
206         // Roll
207         racer.angles_z += -ftmp * autocvar_g_vehicle_racer_turnroll * PHYS_INPUT_TIMELENGTH;
208
209         // Pitch
210         ftmp = autocvar_g_vehicle_racer_pitchspeed  * PHYS_INPUT_TIMELENGTH;
211         ftmp = bound(-ftmp, shortangle_f(player.v_angle_x - racer.angles_x, racer.angles_x), ftmp);
212         racer.angles_x = bound(-autocvar_g_vehicle_racer_pitchlimit, anglemods(racer.angles_x + ftmp), autocvar_g_vehicle_racer_pitchlimit);
213
214         makevectors(racer.angles);
215         racer.angles_x *= -1;
216
217         //ftmp = racer.velocity_z;
218         df = racer.velocity * -autocvar_g_vehicle_racer_friction;
219         //racer.velocity_z = ftmp;
220
221         int cont = pointcontents(racer.origin);
222         if(vlen(player.movement) != 0)
223         {
224                 if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
225                 {
226                         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); }
227                         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); }
228                 }
229                 else
230                 {
231                         if(player.movement_x) { df += v_forward * ((player.movement_x > 0) ? autocvar_g_vehicle_racer_speed_forward : -autocvar_g_vehicle_racer_speed_forward); }
232                         if(player.movement_y) { df += v_right * ((player.movement_y > 0) ? autocvar_g_vehicle_racer_speed_strafe : -autocvar_g_vehicle_racer_speed_strafe); }
233                 }
234
235 #ifdef SVQC
236                 if(self.sound_nexttime < time || self.sounds != 1)
237                 {
238                         self.sounds = 1;
239                         self.sound_nexttime = time + 10.922667; //soundlength("vehicles/racer_move.wav");
240                         sound (self, CH_TRIGGER_SINGLE, SND_VEH_RACER_MOVE, VOL_VEHICLEENGINE, ATTEN_NORM);
241                 }
242 #endif
243         }
244 #ifdef SVQC
245         else
246         {
247                 if(self.sound_nexttime < time || self.sounds != 0)
248                 {
249                         self.sounds = 0;
250                         self.sound_nexttime = time + 11.888604; //soundlength("vehicles/racer_idle.wav");
251                         sound (self, CH_TRIGGER_SINGLE, SND_VEH_RACER_IDLE, VOL_VEHICLEENGINE, ATTEN_NORM);
252                 }
253         }
254 #endif
255
256         // Afterburn
257         if (PHYS_INPUT_BUTTON_JUMP(player) && racer.vehicle_energy >= (autocvar_g_vehicle_racer_afterburn_cost * PHYS_INPUT_TIMELENGTH))
258         {
259 #ifdef SVQC
260                 if(time - racer.wait > 0.2)
261                         pointparticles(particleeffectnum(EFFECT_RACER_BOOSTER), self.origin - v_forward * 32, v_forward  * vlen(self.velocity), 1);
262 #endif
263
264                 racer.wait = time;
265
266                 if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
267                 {
268                         racer.vehicle_energy -= autocvar_g_vehicle_racer_waterburn_cost * PHYS_INPUT_TIMELENGTH;
269                         df += (v_forward * autocvar_g_vehicle_racer_waterburn_speed);
270                 }
271                 else
272                 {
273                         racer.vehicle_energy -= autocvar_g_vehicle_racer_afterburn_cost * PHYS_INPUT_TIMELENGTH;
274                         df += (v_forward * autocvar_g_vehicle_racer_speed_afterburn);
275                 }
276
277 #ifdef SVQC
278                 if(racer.invincible_finished < time)
279                 {
280                         traceline(racer.origin, racer.origin - '0 0 256', MOVE_NORMAL, self);
281                         if(trace_fraction != 1.0)
282                                 pointparticles(particleeffectnum(EFFECT_SMOKE_SMALL), trace_endpos, '0 0 0', 1);
283
284                         racer.invincible_finished = time + 0.1 + (random() * 0.1);
285                 }
286
287                 if(racer.strength_finished < time)
288                 {
289                         racer.strength_finished = time + 10.922667; //soundlength("vehicles/racer_boost.wav");
290                         sound (racer.tur_head, CH_TRIGGER_SINGLE, SND_VEH_RACER_BOOST, VOL_VEHICLEENGINE, ATTEN_NORM);
291                 }
292 #endif
293         }
294         else
295         {
296                 racer.strength_finished = 0;
297                 sound (racer.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM);
298         }
299
300         if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
301                 racer.racer_watertime = time;
302
303         float dforce = autocvar_g_vehicle_racer_downforce;
304         if(time - racer.racer_watertime <= 3)
305                 dforce = autocvar_g_vehicle_racer_water_downforce;
306
307         df -= v_up * (vlen(racer.velocity) * dforce);
308         player.movement = racer.velocity += df * PHYS_INPUT_TIMELENGTH;
309
310 #ifdef SVQC
311         Weapon wep1 = WEP_RACER;
312         if (!forbidWeaponUse(player))
313         if (player.BUTTON_ATCK)
314         if (wep1.wr_checkammo1(wep1))
315         {
316                 string tagname = (racer.cnt)
317                     ? (racer.cnt = 0, "tag_fire1")
318                     : (racer.cnt = 1, "tag_fire2");
319                 vector org = gettaginfo(self, gettagindex(self, tagname));
320                 w_shotorg = org;
321                 w_shotdir = v_forward;
322                 // Fix z-aim (for chase mode)
323                 crosshair_trace(player);
324                 w_shotdir.z = normalize(trace_endpos - org).z * 0.5;
325                 wep1.wr_think(wep1, self, true, false);
326         }
327
328         if(autocvar_g_vehicle_racer_rocket_locktarget)
329         {
330                 vehicles_locktarget((1 / autocvar_g_vehicle_racer_rocket_locking_time) * frametime,
331                                                  (1 / autocvar_g_vehicle_racer_rocket_locking_releasetime) * frametime,
332                                                  autocvar_g_vehicle_racer_rocket_locked_time);
333
334                 if(self.lock_target)
335                 {
336                         if(racer.lock_strength == 1)
337                                 UpdateAuxiliaryXhair(player, real_origin(self.lock_target), '1 0 0', 0);
338                         else if(self.lock_strength > 0.5)
339                                 UpdateAuxiliaryXhair(player, real_origin(self.lock_target), '0 1 0', 0);
340                         else if(self.lock_strength < 0.5)
341                                 UpdateAuxiliaryXhair(player, real_origin(self.lock_target), '0 0 1', 0);
342                 }
343         }
344
345         if(!forbidWeaponUse(player))
346         if(time > racer.delay)
347         if(player.BUTTON_ATCK2)
348         {
349                 racer.misc_bulletcounter += 1;
350                 racer.delay = time + 0.3;
351
352                 if(racer.misc_bulletcounter == 1)
353                 {
354                         racer_fire_rocket_aim("tag_rocket_r", (racer.lock_strength == 1 && racer.lock_target) ? racer.lock_target : world);
355                         player.vehicle_ammo2 = 50;
356                 }
357                 else if(racer.misc_bulletcounter == 2)
358                 {
359                         racer_fire_rocket_aim("tag_rocket_l", (racer.lock_strength == 1 && racer.lock_target) ? racer.lock_target : world);
360                         racer.lock_strength  = 0;
361                         racer.lock_target       = world;
362                         racer.misc_bulletcounter = 0;
363                         racer.delay = time + autocvar_g_vehicle_racer_rocket_refire;
364                         racer.lip = time;
365                         player.vehicle_ammo2 = 0;
366                 }
367         }
368         else if(racer.misc_bulletcounter == 0)
369                 player.vehicle_ammo2 = 100;
370
371         player.vehicle_reload2 = bound(0, 100 * ((time - racer.lip) / (racer.delay - racer.lip)), 100);
372
373         if(racer.vehicle_flags  & VHF_SHIELDREGEN)
374                 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);
375
376         if(racer.vehicle_flags  & VHF_HEALTHREGEN)
377                 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);
378
379         if(racer.vehicle_flags  & VHF_ENERGYREGEN)
380                 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);
381
382
383         VEHICLE_UPDATE_PLAYER(player, health, racer);
384         VEHICLE_UPDATE_PLAYER(player, energy, racer);
385
386         if(racer.vehicle_flags & VHF_HASSHIELD)
387                 VEHICLE_UPDATE_PLAYER(player, shield, racer);
388
389         player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
390 #endif
391
392         setorigin(player,racer.origin + '0 0 32');
393         player.velocity = racer.velocity;
394
395         setself(player);
396         return 1;
397 }
398
399 void racer_think()
400 {SELFPARAM();
401         self.nextthink = time;
402
403         float pushdeltatime = time - self.lastpushtime;
404         if (pushdeltatime > 0.15) pushdeltatime = 0;
405         self.lastpushtime = time;
406         if(!pushdeltatime) return;
407
408         tracebox(self.origin, self.mins, self.maxs, self.origin - ('0 0 1' * autocvar_g_vehicle_racer_springlength), MOVE_NOMONSTERS, self);
409
410         vector df = self.velocity * -autocvar_g_vehicle_racer_friction;
411         df_z += (1 - trace_fraction) * autocvar_g_vehicle_racer_hoverpower + sin(time * 2) * (autocvar_g_vehicle_racer_springlength * 2);
412
413         float forced = autocvar_g_vehicle_racer_upforcedamper;
414
415         int cont = pointcontents(self.origin - '0 0 64');
416         if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
417         {
418                 forced = autocvar_g_vehicle_racer_water_upforcedamper;
419                 self.velocity_z += 200;
420         }
421
422         self.velocity += df * pushdeltatime;
423         if(self.velocity_z > 0)
424                 self.velocity_z *= 1 - forced * pushdeltatime;
425
426         self.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * pushdeltatime);
427         self.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * pushdeltatime);
428
429         CSQCMODEL_AUTOUPDATE(self);
430 }
431
432 void racer_exit(float eject)
433 {SELFPARAM();
434         vector spot;
435
436         self.think        = racer_think;
437         self.nextthink  = time;
438         self.movetype   = MOVETYPE_BOUNCE;
439         sound (self.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM);
440
441         if(!self.owner)
442                 return;
443
444         makevectors(self.angles);
445         if(eject)
446         {
447                 spot = self.origin + v_forward * 100 + '0 0 64';
448                 spot = vehicles_findgoodexit(spot);
449                 setorigin(self.owner , spot);
450                 self.owner.velocity = (v_up + v_forward * 0.25) * 750;
451                 self.owner.oldvelocity = self.owner.velocity;
452         }
453         else
454         {
455                 if(vlen(self.velocity) > 2 * autocvar_sv_maxairspeed)
456                 {
457                         self.owner.velocity = normalize(self.velocity) * autocvar_sv_maxairspeed * 2;
458                         self.owner.velocity_z += 200;
459                         spot = self.origin + v_forward * 32 + '0 0 32';
460                         spot = vehicles_findgoodexit(spot);
461                 }
462                 else
463                 {
464                         self.owner.velocity = self.velocity * 0.5;
465                         self.owner.velocity_z += 10;
466                         spot = self.origin - v_forward * 200 + '0 0 32';
467                         spot = vehicles_findgoodexit(spot);
468                 }
469                 self.owner.oldvelocity = self.owner.velocity;
470                 setorigin(self.owner , spot);
471         }
472         antilag_clear(self.owner);
473         self.owner = world;
474 }
475
476 void racer_blowup()
477 {SELFPARAM();
478         self.deadflag   = DEAD_DEAD;
479         self.vehicle_exit(VHEF_NORMAL);
480
481         RadiusDamage (self, self.enemy, autocvar_g_vehicle_racer_blowup_coredamage,
482                                         autocvar_g_vehicle_racer_blowup_edgedamage,
483                                         autocvar_g_vehicle_racer_blowup_radius, world, world,
484                                         autocvar_g_vehicle_racer_blowup_forceintensity,
485                                         DEATH_VH_WAKI_DEATH, world);
486
487         self.nextthink  = time + autocvar_g_vehicle_racer_respawntime;
488         self.think        = vehicles_spawn;
489         self.movetype   = MOVETYPE_NONE;
490         self.effects    = EF_NODRAW;
491         self.solid = SOLID_NOT;
492
493         self.colormod  = '0 0 0';
494         self.avelocity = '0 0 0';
495         self.velocity  = '0 0 0';
496
497         setorigin(self, self.pos1);
498 }
499
500 void racer_blowup_think()
501 {SELFPARAM();
502         self.nextthink = time;
503
504         if(time >= self.delay)
505                 racer_blowup();
506
507         CSQCMODEL_AUTOUPDATE(self);
508 }
509
510 void racer_deadtouch()
511 {SELFPARAM();
512         self.avelocity_x *= 0.7;
513         self.cnt -= 1;
514         if(self.cnt <= 0)
515                 racer_blowup();
516 }
517
518 spawnfunc(vehicle_racer)
519 {
520         if(!autocvar_g_vehicle_racer) { remove(self); return; }
521         if(!vehicle_initialize(VEH_RACER, false)) { remove(self); return; }
522 }
523
524 #endif // SVQC
525
526 #ifdef CSQC
527 #if 0
528 void racer_draw()
529 {SELFPARAM();
530         float pushdeltatime = time - self.lastpushtime;
531         if (pushdeltatime > 0.15) pushdeltatime = 0;
532         self.lastpushtime = time;
533         if(!pushdeltatime) return;
534
535         tracebox(self.move_origin, self.mins, self.maxs, self.move_origin - ('0 0 1' * getstatf(STAT_VEH_RACER_SPRINGLENGTH)), MOVE_NOMONSTERS, self);
536
537         vector df = self.move_velocity * -getstatf(STAT_VEH_RACER_FRICTION);
538         df_z += (1 - trace_fraction) * getstatf(STAT_VEH_RACER_HOVERPOWER) + sin(time * 2) * (getstatf(STAT_VEH_RACER_SPRINGLENGTH) * 2);
539
540         float forced = getstatf(STAT_VEH_RACER_UPFORCEDAMPER);
541
542         int cont = pointcontents(self.move_origin - '0 0 64');
543         if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
544         {
545                 forced = getstatf(STAT_VEH_RACER_WATER_UPFORCEDAMPER);
546                 self.move_velocity_z += 200;
547         }
548
549         self.move_velocity += df * pushdeltatime;
550         if(self.move_velocity_z > 0)
551                 self.move_velocity_z *= 1 - forced * pushdeltatime;
552
553         self.move_angles_x *= 1 - (getstatf(STAT_VEH_RACER_ANGLESTABILIZER) * pushdeltatime);
554         self.move_angles_z *= 1 - (getstatf(STAT_VEH_RACER_ANGLESTABILIZER) * pushdeltatime);
555
556         Movetype_Physics_MatchServer(false);
557 }
558 #endif
559 #endif
560
561                 METHOD(Racer, vr_impact, void(Racer thisveh))
562                 {
563                 #ifdef SVQC
564                         if(autocvar_g_vehicle_racer_bouncepain)
565                                 vehicles_impact(autocvar_g_vehicle_racer_bouncepain_x, autocvar_g_vehicle_racer_bouncepain_y, autocvar_g_vehicle_racer_bouncepain_z);
566                 #endif
567                 }
568
569                 METHOD(Racer, vr_enter, void(Racer thisveh))
570                 {
571                 #ifdef SVQC
572                         self.movetype = MOVETYPE_BOUNCE;
573                         self.owner.vehicle_health = (self.vehicle_health / autocvar_g_vehicle_racer_health)  * 100;
574                         self.owner.vehicle_shield = (self.vehicle_shield / autocvar_g_vehicle_racer_shield)  * 100;
575
576                         if(self.owner.flagcarried)
577                            setorigin(self.owner.flagcarried, '-190 0 96');
578                 #elif defined(CSQC)
579
580                         self.move_movetype = MOVETYPE_BOUNCE;
581                 #endif
582                 }
583
584                 METHOD(Racer, vr_spawn, void(Racer thisveh))
585                 {
586                 #ifdef SVQC
587                         if(self.scale != 0.5)
588                         {
589                                 if(autocvar_g_vehicle_racer_hovertype != 0)
590                                         racer_force_from_tag = vehicles_force_fromtag_maglev;
591                                 else
592                                         racer_force_from_tag = vehicles_force_fromtag_hover;
593
594                                 // FIXME: this be hakkz, fix the models insted (scale body, add tag_viewport to the hudmodel).
595                                 self.scale = 0.5;
596                                 setattachment(self.vehicle_hudmodel, self, "");
597                                 setattachment(self.vehicle_viewport, self, "tag_viewport");
598
599                                 self.mass                          = 900;
600                         }
601
602                         self.think                = racer_think;
603                         self.nextthink    = time;
604                         self.vehicle_health = autocvar_g_vehicle_racer_health;
605                         self.vehicle_shield = autocvar_g_vehicle_racer_shield;
606
607                         self.movetype     = MOVETYPE_TOSS;
608                         self.solid                = SOLID_SLIDEBOX;
609                         self.delay                = time;
610                         self.scale                = 0.5;
611
612                         self.PlayerPhysplug = racer_frame;
613
614                         self.bouncefactor = autocvar_g_vehicle_racer_bouncefactor;
615                         self.bouncestop = autocvar_g_vehicle_racer_bouncestop;
616                         self.damageforcescale = 0.5;
617                         self.vehicle_health = autocvar_g_vehicle_racer_health;
618                         self.vehicle_shield = autocvar_g_vehicle_racer_shield;
619                 #endif
620                 }
621
622                 METHOD(Racer, vr_death, void(Racer thisveh))
623                 {
624                 #ifdef SVQC
625                         self.SendEntity         = func_null; // stop networking this racer (for now)
626                         self.health                     = 0;
627                         self.event_damage       = func_null;
628                         self.solid                      = SOLID_CORPSE;
629                         self.takedamage         = DAMAGE_NO;
630                         self.deadflag           = DEAD_DYING;
631                         self.movetype           = MOVETYPE_BOUNCE;
632                         self.wait                       = time;
633                         self.delay                      = 2 + time + random() * 3;
634                         self.cnt                        = 1 + random() * 2;
635                         self.touch                      = racer_deadtouch;
636
637                         Send_Effect(EFFECT_EXPLOSION_MEDIUM, self.origin, '0 0 0', 1);
638
639                         if(random() < 0.5)
640                                 self.avelocity_z = 32;
641                         else
642                                 self.avelocity_z = -32;
643
644                         self.avelocity_x = -vlen(self.velocity) * 0.2;
645                         self.velocity += '0 0 700';
646                         self.colormod = '-0.5 -0.5 -0.5';
647
648                         self.think = racer_blowup_think;
649                         self.nextthink = time;
650                 #endif
651                 }
652
653 #ifdef CSQC
654                 METHOD(Racer, vr_hud, void(Racer thisveh))
655                 {
656                         Vehicles_drawHUD(VEH_RACER.m_icon, "vehicle_racer_weapon1", "vehicle_racer_weapon2",
657                                                          "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
658                                                          "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color,
659                                                          vCROSS_GUIDE);
660                 }
661 #endif
662                 METHOD(Racer, vr_setup, void(Racer thisveh))
663                 {
664                 #ifdef SVQC
665                         self.vehicle_exit = racer_exit;
666                 #endif
667
668                 #ifdef SVQC
669                         // we have no need to network energy
670                         if(autocvar_g_vehicle_racer_energy)
671                         if(autocvar_g_vehicle_racer_energy_regen)
672                                 self.vehicle_flags |= VHF_ENERGYREGEN;
673
674                         if(autocvar_g_vehicle_racer_shield)
675                                 self.vehicle_flags |= VHF_HASSHIELD;
676
677                         if(autocvar_g_vehicle_racer_shield_regen)
678                                 self.vehicle_flags |= VHF_SHIELDREGEN;
679
680                         if(autocvar_g_vehicle_racer_health_regen)
681                                 self.vehicle_flags |= VHF_HEALTHREGEN;
682
683                         self.respawntime = autocvar_g_vehicle_racer_respawntime;
684                         self.vehicle_health = autocvar_g_vehicle_racer_health;
685                         self.vehicle_shield = autocvar_g_vehicle_racer_shield;
686                         self.max_health = self.vehicle_health;
687                 #endif
688
689                 #ifdef CSQC
690                         AuxiliaryXhair[0].axh_image = vCROSS_LOCK; // Rocket
691                 #endif
692                 }
693
694 #endif