Merge branch 'master' into Mario/strength_stat_field
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle / racer.qc
1 #include "racer.qh"
2
3 #ifdef GAMEQC
4
5 #ifdef SVQC
6 #include <common/mapobjects/trigger/impulse.qh>
7
8 bool autocvar_g_vehicle_racer = true;
9
10 float autocvar_g_vehicle_racer_thinkrate = 0.05; // TODO: any higher causes it to sink in liquids
11
12 float autocvar_g_vehicle_racer_speed_afterburn = 3000;
13 // energy consumed per second
14 float autocvar_g_vehicle_racer_afterburn_cost = 130;
15
16 float autocvar_g_vehicle_racer_waterburn_cost = 5;
17 float autocvar_g_vehicle_racer_waterburn_speed = 750;
18
19 float autocvar_g_vehicle_racer_water_speed_forward = 600;
20 float autocvar_g_vehicle_racer_water_speed_strafe = 600;
21
22 float autocvar_g_vehicle_racer_pitchlimit = 30;
23
24 float autocvar_g_vehicle_racer_water_downforce = 0.03;
25 float autocvar_g_vehicle_racer_water_upforcedamper = 15;
26
27 float autocvar_g_vehicle_racer_anglestabilizer = 1.75;
28 float autocvar_g_vehicle_racer_downforce = 0.01;
29
30 float autocvar_g_vehicle_racer_speed_forward = 650;
31 float autocvar_g_vehicle_racer_speed_strafe = 650;
32 float autocvar_g_vehicle_racer_springlength = 90;
33 float autocvar_g_vehicle_racer_upforcedamper = 2;
34 float autocvar_g_vehicle_racer_friction = 0.45;
35
36 float autocvar_g_vehicle_racer_water_time = 5;
37
38 //float autocvar_g_vehicle_racer_collision_multiplier = 0.05;
39
40 // 0 = hover, != 0 = maglev
41 int autocvar_g_vehicle_racer_hovertype = 0;
42 // NOTE!! x 4 (4 engines)
43 float autocvar_g_vehicle_racer_hoverpower = 8000;
44
45 float autocvar_g_vehicle_racer_turnroll = 30;
46 float autocvar_g_vehicle_racer_turnspeed = 220;
47 float autocvar_g_vehicle_racer_pitchspeed = 125;
48
49 float autocvar_g_vehicle_racer_energy = 100;
50 float autocvar_g_vehicle_racer_energy_regen = 90;
51 float autocvar_g_vehicle_racer_energy_regen_pause = 0.35;
52
53 float autocvar_g_vehicle_racer_health = 200;
54 float autocvar_g_vehicle_racer_health_regen = 0;
55 float autocvar_g_vehicle_racer_health_regen_pause = 0;
56
57 float autocvar_g_vehicle_racer_shield = 100;
58 float autocvar_g_vehicle_racer_shield_regen = 30;
59 float autocvar_g_vehicle_racer_shield_regen_pause = 1;
60
61 bool autocvar_g_vehicle_racer_rocket_locktarget = true;
62 float autocvar_g_vehicle_racer_rocket_locking_time = 0.35;
63 float autocvar_g_vehicle_racer_rocket_locking_releasetime = 0.5;
64 float autocvar_g_vehicle_racer_rocket_locked_time = 4;
65
66 float autocvar_g_vehicle_racer_respawntime = 35;
67
68 float autocvar_g_vehicle_racer_blowup_radius = 250;
69 float autocvar_g_vehicle_racer_blowup_coredamage = 250;
70 float autocvar_g_vehicle_racer_blowup_edgedamage = 15;
71 float autocvar_g_vehicle_racer_blowup_forceintensity = 250;
72
73 // Factor of old velocity to keep after collision
74 float autocvar_g_vehicle_racer_bouncefactor = 0.25;
75 // if != 0, New veloctiy after bounce = 0 if new velocity < this
76 float autocvar_g_vehicle_racer_bouncestop = 0;
77 // "minspeed_for_pain speedchange_to_pain_factor max_damage"
78 vector autocvar_g_vehicle_racer_bouncepain = '200 0.15 150';
79
80 .float racer_watertime;
81
82 var .vector(entity this, string tag_name, float spring_length, float max_power) racer_force_from_tag;
83
84 void racer_align4point(entity this, entity player, float _delta)
85 {
86         vector push_vector;
87         float fl_push, fr_push, bl_push, br_push;
88
89         push_vector  = this.racer_force_from_tag(this, "tag_engine_fr", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
90         fr_push   = force_fromtag_normpower;
91         //vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
92
93         push_vector += this.racer_force_from_tag(this, "tag_engine_fl", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
94         fl_push   = force_fromtag_normpower;
95         //vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
96
97         push_vector += this.racer_force_from_tag(this, "tag_engine_br", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
98         br_push   = force_fromtag_normpower;
99         //vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
100
101         push_vector += this.racer_force_from_tag(this, "tag_engine_bl", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
102         bl_push   = force_fromtag_normpower;
103         //vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
104
105         this.velocity += push_vector * _delta;
106
107         float uforce = autocvar_g_vehicle_racer_upforcedamper;
108
109         int cont = pointcontents(this.origin - '0 0 64');
110         if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
111         {
112                 uforce = autocvar_g_vehicle_racer_water_upforcedamper;
113
114                 if(PHYS_INPUT_BUTTON_CROUCH(player) && time < this.air_finished)
115                         this.velocity_z += 30;
116                 else
117                         this.velocity_z += 200;
118         }
119
120
121         // Anti ocilation
122         if(this.velocity_z > 0)
123                 this.velocity_z *= 1 - uforce * _delta;
124
125         push_vector_x =  (fl_push - bl_push);
126         push_vector_x += (fr_push - br_push);
127         push_vector_x *= 360;
128
129         push_vector_z = (fr_push - fl_push);
130         push_vector_z += (br_push - bl_push);
131         push_vector_z *= 360;
132
133         // Apply angle diffrance
134         this.angles_z += push_vector_z * _delta;
135         this.angles_x += push_vector_x * _delta;
136
137         // Apply stabilizer
138         this.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * _delta);
139         this.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * _delta);
140 }
141
142 void racer_fire_rocket_aim(entity this, entity player, string tagname, entity trg)
143 {
144         vector v = gettaginfo(this, gettagindex(this, tagname));
145         racer_fire_rocket(player, v, v_forward, trg);
146 }
147
148 bool racer_frame(entity this, float dt)
149 {
150         entity player = this;
151         entity vehic = player.vehicle;
152         return = true;
153
154         if(game_stopped)
155         {
156                 vehic.solid = SOLID_NOT;
157                 vehic.takedamage = DAMAGE_NO;
158                 set_movetype(vehic, MOVETYPE_NONE);
159                 return;
160         }
161
162         vehicles_frame(vehic, player);
163
164         int cont = Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(vehic.origin));
165         if(!(cont & DPCONTENTS_WATER))
166                 vehic.air_finished = 0;
167         else if (!vehic.air_finished)
168                 vehic.air_finished = time + autocvar_g_vehicle_racer_water_time;
169
170         if(IS_DEAD(vehic))
171         {
172                 PHYS_INPUT_BUTTON_ATCK(player) = PHYS_INPUT_BUTTON_ATCK2(player) = false;
173                 return;
174         }
175
176         racer_align4point(vehic, player, dt);
177
178         PHYS_INPUT_BUTTON_ZOOM(player) = PHYS_INPUT_BUTTON_CROUCH(player) = false;
179
180         vehic.angles_x *= -1;
181
182         // Yaw
183         float ftmp = autocvar_g_vehicle_racer_turnspeed * dt;
184         ftmp = bound(-ftmp, shortangle_f(player.v_angle_y - vehic.angles_y, vehic.angles_y), ftmp);
185         vehic.angles_y = anglemods(vehic.angles_y + ftmp);
186
187         // Roll
188         vehic.angles_z += -ftmp * autocvar_g_vehicle_racer_turnroll * dt;
189
190         // Pitch
191         ftmp = autocvar_g_vehicle_racer_pitchspeed  * dt;
192         ftmp = bound(-ftmp, shortangle_f(player.v_angle_x - vehic.angles_x, vehic.angles_x), ftmp);
193         vehic.angles_x = bound(-autocvar_g_vehicle_racer_pitchlimit, anglemods(vehic.angles_x + ftmp), autocvar_g_vehicle_racer_pitchlimit);
194
195         makevectors(vehic.angles);
196         vehic.angles_x *= -1;
197
198         //ftmp = vehic.velocity_z;
199         vector df = vehic.velocity * -autocvar_g_vehicle_racer_friction;
200         //vehic.velocity_z = ftmp;
201
202         if(CS(player).movement)
203         {
204                 if(cont & DPCONTENTS_LIQUIDSMASK)
205                 {
206                         if(CS(player).movement_x) { df += v_forward * ((CS(player).movement_x > 0) ? autocvar_g_vehicle_racer_water_speed_forward : -autocvar_g_vehicle_racer_water_speed_forward); }
207                         if(CS(player).movement_y) { df += v_right * ((CS(player).movement_y > 0) ? autocvar_g_vehicle_racer_water_speed_strafe : -autocvar_g_vehicle_racer_water_speed_strafe); }
208                 }
209                 else
210                 {
211                         if(CS(player).movement_x) { df += v_forward * ((CS(player).movement_x > 0) ? autocvar_g_vehicle_racer_speed_forward : -autocvar_g_vehicle_racer_speed_forward); }
212                         if(CS(player).movement_y) { df += v_right * ((CS(player).movement_y > 0) ? autocvar_g_vehicle_racer_speed_strafe : -autocvar_g_vehicle_racer_speed_strafe); }
213                 }
214
215 #ifdef SVQC
216                 if(vehic.sound_nexttime < time || vehic.sounds != 1)
217                 {
218                         vehic.sounds = 1;
219                         vehic.sound_nexttime = time + 10.922667; //soundlength("vehicles/racer_move.wav");
220                         sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RACER_MOVE, VOL_VEHICLEENGINE, ATTEN_NORM);
221                 }
222 #endif
223         }
224 #ifdef SVQC
225         else
226         {
227                 if(vehic.sound_nexttime < time || vehic.sounds != 0)
228                 {
229                         vehic.sounds = 0;
230                         vehic.sound_nexttime = time + 11.888604; //soundlength("vehicles/racer_idle.wav");
231                         sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RACER_IDLE, VOL_VEHICLEENGINE, ATTEN_NORM);
232                 }
233         }
234 #endif
235
236         // Afterburn
237         if (PHYS_INPUT_BUTTON_JUMP(player) && vehic.vehicle_energy >= (autocvar_g_vehicle_racer_afterburn_cost * dt))
238         {
239 #ifdef SVQC
240                 if(time - vehic.wait > 0.2)
241                         pointparticles(EFFECT_RACER_BOOSTER, vehic.origin - v_forward * 32, v_forward  * vlen(vehic.velocity), 1);
242 #endif
243
244                 vehic.wait = time;
245
246                 if(cont & DPCONTENTS_LIQUIDSMASK)
247                 {
248                         vehic.vehicle_energy -= autocvar_g_vehicle_racer_waterburn_cost * dt;
249                         df += (v_forward * autocvar_g_vehicle_racer_waterburn_speed);
250                 }
251                 else
252                 {
253                         vehic.vehicle_energy -= autocvar_g_vehicle_racer_afterburn_cost * dt;
254                         df += (v_forward * autocvar_g_vehicle_racer_speed_afterburn);
255                 }
256
257 #ifdef SVQC
258                 if(vehic.invincible_finished < time)
259                 {
260                         traceline(vehic.origin, vehic.origin - '0 0 256', MOVE_NORMAL, vehic);
261                         if(trace_fraction != 1.0)
262                                 pointparticles(EFFECT_SMOKE_SMALL, trace_endpos, '0 0 0', 1);
263
264                         vehic.invincible_finished = time + 0.1 + (random() * 0.1);
265                 }
266
267                 // NOTE: reusing .strength_finished here as a sound delay counter
268                 if(vehic.strength_finished < time)
269                 {
270                         vehic.strength_finished = time + 10.922667; //soundlength("vehicles/racer_boost.wav");
271                         sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_VEH_RACER_BOOST, VOL_VEHICLEENGINE, ATTEN_NORM);
272                 }
273 #endif
274         }
275         else
276         {
277                 vehic.strength_finished = 0;
278                 sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM);
279         }
280
281         if(cont & DPCONTENTS_LIQUIDSMASK)
282                 vehic.racer_watertime = time;
283
284         float dforce = autocvar_g_vehicle_racer_downforce;
285         if(time - vehic.racer_watertime <= 3)
286                 dforce = autocvar_g_vehicle_racer_water_downforce;
287
288         df -= v_up * (vlen(vehic.velocity) * dforce);
289         CS(player).movement = vehic.velocity += df * dt;
290
291 #ifdef SVQC
292
293         Weapon wep1 = WEP_RACER;
294         .entity weaponentity = weaponentities[0]; // TODO: unhardcode
295         if (!weaponLocked(player) && !weaponUseForbidden(player))
296         if (PHYS_INPUT_BUTTON_ATCK(player))
297         if (wep1.wr_checkammo1(wep1, vehic, weaponentity))
298         {
299                 wep1.wr_think(wep1, vehic, weaponentity, 1);
300         }
301
302         if(autocvar_g_vehicle_racer_rocket_locktarget)
303         {
304                 if(time >= vehic.vehicle_last_trace)
305                 {
306                         crosshair_trace(player);
307
308                         vehicles_locktarget(vehic, (1 / autocvar_g_vehicle_racer_rocket_locking_time) * dt,
309                                                          (1 / autocvar_g_vehicle_racer_rocket_locking_releasetime) * dt,
310                                                          autocvar_g_vehicle_racer_rocket_locked_time);
311
312                         vehic.vehicle_last_trace = time + autocvar_g_vehicle_racer_thinkrate;
313                 }
314
315                 if(vehic.lock_target)
316                 {
317                         if(vehic.lock_strength == 1)
318                                 UpdateAuxiliaryXhair(player, real_origin(vehic.lock_target), '1 0 0', 0);
319                         else if(vehic.lock_strength > 0.5)
320                                 UpdateAuxiliaryXhair(player, real_origin(vehic.lock_target), '0 1 0', 0);
321                         else if(vehic.lock_strength < 0.5)
322                                 UpdateAuxiliaryXhair(player, real_origin(vehic.lock_target), '0 0 1', 0);
323                 }
324         }
325
326         if(!weaponLocked(player))
327         if(time > vehic.delay)
328         if(PHYS_INPUT_BUTTON_ATCK2(player))
329         {
330                 vehic.misc_bulletcounter += 1;
331                 vehic.delay = time + 0.3;
332
333                 if(vehic.misc_bulletcounter == 1)
334                 {
335                         racer_fire_rocket_aim(vehic, player, "tag_rocket_r", (vehic.lock_strength == 1 && vehic.lock_target) ? vehic.lock_target : NULL);
336                         player.vehicle_ammo2 = 50;
337                 }
338                 else if(vehic.misc_bulletcounter == 2)
339                 {
340                         racer_fire_rocket_aim(vehic, player, "tag_rocket_l", (vehic.lock_strength == 1 && vehic.lock_target) ? vehic.lock_target : NULL);
341                         vehic.lock_strength  = 0;
342                         vehic.lock_target       = NULL;
343                         vehic.misc_bulletcounter = 0;
344                         vehic.delay = time + autocvar_g_vehicle_racer_rocket_refire;
345                         vehic.lip = time;
346                         player.vehicle_ammo2 = 0;
347                 }
348         }
349         else if(vehic.misc_bulletcounter == 0)
350                 player.vehicle_ammo2 = 100;
351
352         player.vehicle_reload2 = bound(0, 100 * ((time - vehic.lip) / (vehic.delay - vehic.lip)), 100);
353
354         if(vehic.vehicle_flags & VHF_SHIELDREGEN)
355                 vehicles_regen(vehic, vehic.dmg_time, vehicle_shield, autocvar_g_vehicle_racer_shield, autocvar_g_vehicle_racer_shield_regen_pause, autocvar_g_vehicle_racer_shield_regen, dt, true);
356
357         if(vehic.vehicle_flags & VHF_HEALTHREGEN)
358                 vehicles_regen_resource(vehic, vehic.dmg_time, vehicle_health, autocvar_g_vehicle_racer_health, autocvar_g_vehicle_racer_health_regen_pause, autocvar_g_vehicle_racer_health_regen, dt, false, RES_HEALTH);
359
360         if(vehic.vehicle_flags & VHF_ENERGYREGEN)
361                 vehicles_regen(vehic, vehic.wait, vehicle_energy, autocvar_g_vehicle_racer_energy, autocvar_g_vehicle_racer_energy_regen_pause, autocvar_g_vehicle_racer_energy_regen, dt, false);
362
363         VEHICLE_UPDATE_PLAYER_RESOURCE(player, vehic, health, racer, RES_HEALTH);
364         VEHICLE_UPDATE_PLAYER(player, vehic, energy, racer);
365
366         if(vehic.vehicle_flags & VHF_HASSHIELD)
367                 VEHICLE_UPDATE_PLAYER(player, vehic, shield, racer);
368
369         PHYS_INPUT_BUTTON_ATCK(player) = PHYS_INPUT_BUTTON_ATCK2(player) = false;
370 #endif
371
372         setorigin(player, vehic.origin + '0 0 32');
373         player.oldorigin = player.origin; // negate fall damage
374         player.velocity = vehic.velocity;
375 }
376
377 void racer_think(entity this)
378 {
379         float dt = autocvar_g_vehicle_racer_thinkrate;
380
381         this.nextthink = time + dt;
382
383         tracebox(this.origin, this.mins, this.maxs, this.origin - ('0 0 1' * autocvar_g_vehicle_racer_springlength), MOVE_NOMONSTERS, this);
384
385         vector df = this.velocity * -autocvar_g_vehicle_racer_friction;
386         df_z += (1 - trace_fraction) * autocvar_g_vehicle_racer_hoverpower + sin(time * 2) * (autocvar_g_vehicle_racer_springlength * 2);
387
388         float forced = autocvar_g_vehicle_racer_upforcedamper;
389
390         //int cont = pointcontents(this.origin - '0 0 64');
391         traceline(this.origin - '0 0 64', this.origin - '0 0 64', MOVE_NOMONSTERS, this);
392         //if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
393         if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
394         {
395                 forced = autocvar_g_vehicle_racer_water_upforcedamper;
396                 this.velocity_z += 200;
397         }
398
399         this.velocity += df * dt;
400         if(this.velocity_z > 0)
401                 this.velocity_z *= 1 - forced * dt;
402
403         this.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * dt);
404         this.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * dt);
405
406         CSQCMODEL_AUTOUPDATE(this);
407 }
408
409 void racer_exit(entity this, int eject)
410 {
411         vector spot;
412
413         setthink(this, racer_think);
414         this.nextthink  = time;
415         set_movetype(this, MOVETYPE_BOUNCE);
416         sound (this.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM);
417
418         if(!this.owner)
419                 return;
420
421         makevectors(this.angles);
422         if(eject)
423         {
424                 spot = this.origin + v_forward * 100 + '0 0 64';
425                 spot = vehicles_findgoodexit(this, this.owner, spot);
426                 setorigin(this.owner, spot);
427                 this.owner.velocity = (v_up + v_forward * 0.25) * 750;
428                 this.owner.oldvelocity = this.owner.velocity;
429         }
430         else
431         {
432                 if(vdist(this.velocity, >, 2 * autocvar_sv_maxairspeed))
433                 {
434                         this.owner.velocity = normalize(this.velocity) * autocvar_sv_maxairspeed * 2;
435                         this.owner.velocity_z += 200;
436                         spot = this.origin + v_forward * 32 + '0 0 32';
437                         spot = vehicles_findgoodexit(this, this.owner, spot);
438                 }
439                 else
440                 {
441                         this.owner.velocity = this.velocity * 0.5;
442                         this.owner.velocity_z += 10;
443                         spot = this.origin - v_forward * 200 + '0 0 32';
444                         spot = vehicles_findgoodexit(this, this.owner, spot);
445                 }
446                 this.owner.oldvelocity = this.owner.velocity;
447                 setorigin(this.owner , spot);
448         }
449         antilag_clear(this.owner, CS(this.owner));
450         this.owner = NULL;
451 }
452
453 void racer_blowup(entity this)
454 {
455         this.deadflag = DEAD_DEAD;
456         this.vehicle_exit(this, VHEF_NORMAL);
457
458         RadiusDamage (this, this.enemy, autocvar_g_vehicle_racer_blowup_coredamage,
459                                         autocvar_g_vehicle_racer_blowup_edgedamage,
460                                         autocvar_g_vehicle_racer_blowup_radius, NULL, NULL,
461                                         autocvar_g_vehicle_racer_blowup_forceintensity,
462                                         DEATH_VH_WAKI_DEATH.m_id, DMG_NOWEP, NULL);
463
464         this.nextthink  = time + autocvar_g_vehicle_racer_respawntime;
465         setthink(this, vehicles_spawn);
466         set_movetype(this, MOVETYPE_NONE);
467         this.effects    = EF_NODRAW;
468         this.solid = SOLID_NOT;
469
470         this.colormod  = '0 0 0';
471         this.avelocity = '0 0 0';
472         this.velocity  = '0 0 0';
473
474         setorigin(this, this.pos1);
475 }
476
477 void racer_blowup_think(entity this)
478 {
479         this.nextthink = time;
480
481         if(time >= this.delay)
482                 racer_blowup(this);
483
484         //CSQCMODEL_AUTOUPDATE(this);
485 }
486
487 void racer_deadtouch(entity this, entity toucher)
488 {
489         this.avelocity_x *= 0.7;
490         this.cnt -= 1;
491         if(this.cnt <= 0)
492                 racer_blowup(this);
493 }
494
495 spawnfunc(vehicle_racer)
496 {
497         if(!autocvar_g_vehicle_racer) { delete(this); return; }
498         if(!vehicle_initialize(this, VEH_RACER, false)) { delete(this); return; }
499 }
500
501 #endif // SVQC
502
503 METHOD(Racer, vr_impact, void(Racer thisveh, entity instance))
504 {
505 #ifdef SVQC
506     if(autocvar_g_vehicle_racer_bouncepain)
507         vehicles_impact(instance, autocvar_g_vehicle_racer_bouncepain_x, autocvar_g_vehicle_racer_bouncepain_y, autocvar_g_vehicle_racer_bouncepain_z);
508 #endif
509 }
510
511 METHOD(Racer, vr_enter, void(Racer thisveh, entity instance))
512 {
513     set_movetype(instance, MOVETYPE_BOUNCE);
514 #ifdef SVQC
515     instance.owner.vehicle_health = (GetResource(instance, RES_HEALTH) / autocvar_g_vehicle_racer_health)  * 100;
516     instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_racer_shield)  * 100;
517
518     if(instance.owner.flagcarried)
519        setorigin(instance.owner.flagcarried, '-190 0 96');
520 #endif
521 }
522
523 METHOD(Racer, vr_spawn, void(Racer thisveh, entity instance))
524 {
525 #ifdef SVQC
526     if(autocvar_g_vehicle_racer_hovertype != 0)
527         instance.racer_force_from_tag = vehicles_force_fromtag_maglev;
528     else
529         instance.racer_force_from_tag = vehicles_force_fromtag_hover;
530
531     setthink(instance, racer_think);
532     instance.nextthink    = time;
533     SetResourceExplicit(instance, RES_HEALTH, autocvar_g_vehicle_racer_health);
534     instance.vehicle_shield = autocvar_g_vehicle_racer_shield;
535
536     set_movetype(instance, MOVETYPE_TOSS);
537     instance.solid                = SOLID_SLIDEBOX;
538     instance.delay                = time;
539     instance.scale                = 0.5; // FIXME: this be hakkz, fix the models insted (scale body, add tag_viewport to the hudmodel).
540     instance.mass                 = 900;
541
542     setattachment(instance.vehicle_hudmodel, instance, "");
543     setattachment(instance.vehicle_viewport, instance, "tag_viewport");
544
545     instance.PlayerPhysplug = racer_frame;
546
547     instance.bouncefactor = autocvar_g_vehicle_racer_bouncefactor;
548     instance.bouncestop = autocvar_g_vehicle_racer_bouncestop;
549     instance.damageforcescale = 0.5;
550     SetResourceExplicit(instance, RES_HEALTH, autocvar_g_vehicle_racer_health);
551     instance.vehicle_shield = autocvar_g_vehicle_racer_shield;
552 #endif
553 }
554
555 METHOD(Racer, vr_death, void(Racer thisveh, entity instance))
556 {
557 #ifdef SVQC
558     setSendEntity(instance, func_null); // stop networking this racer (for now)
559     SetResourceExplicit(instance, RES_HEALTH, 0);
560     instance.event_damage       = func_null;
561     instance.solid                      = SOLID_CORPSE;
562     instance.takedamage         = DAMAGE_NO;
563     instance.deadflag           = DEAD_DYING;
564     set_movetype(instance, MOVETYPE_BOUNCE);
565     instance.wait                       = time;
566     instance.delay                      = 2 + time + random() * 3;
567     instance.cnt                        = 1 + random() * 2;
568     settouch(instance, racer_deadtouch);
569
570     Send_Effect(EFFECT_EXPLOSION_MEDIUM, instance.origin, '0 0 0', 1);
571
572     if(random() < 0.5)
573         instance.avelocity_z = 32;
574     else
575         instance.avelocity_z = -32;
576
577     instance.avelocity_x = -vlen(instance.velocity) * 0.2;
578     instance.velocity += '0 0 700';
579     instance.colormod = '-0.5 -0.5 -0.5';
580
581     setthink(instance, racer_blowup_think);
582     instance.nextthink = time;
583 #endif
584 }
585
586 #ifdef CSQC
587 METHOD(Racer, vr_hud, void(Racer thisveh))
588 {
589     Vehicles_drawHUD(VEH_RACER.m_icon, "vehicle_racer_weapon1", "vehicle_racer_weapon2",
590                      "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
591                      "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
592 }
593 METHOD(Racer, vr_crosshair, void(Racer thisveh, entity player))
594 {
595     Vehicles_drawCrosshair(vCROSS_GUIDE);
596 }
597 #endif
598 METHOD(Racer, vr_setup, void(Racer thisveh, entity instance))
599 {
600 #ifdef SVQC
601     instance.vehicle_exit = racer_exit;
602
603     // we have no need to network energy
604     if(autocvar_g_vehicle_racer_energy && autocvar_g_vehicle_racer_energy_regen)
605         instance.vehicle_flags |= VHF_ENERGYREGEN;
606
607     if(autocvar_g_vehicle_racer_shield)
608         instance.vehicle_flags |= VHF_HASSHIELD;
609
610     if(autocvar_g_vehicle_racer_shield_regen)
611         instance.vehicle_flags |= VHF_SHIELDREGEN;
612
613     if(autocvar_g_vehicle_racer_health_regen)
614         instance.vehicle_flags |= VHF_HEALTHREGEN;
615
616     instance.respawntime = autocvar_g_vehicle_racer_respawntime;
617     SetResourceExplicit(instance, RES_HEALTH, autocvar_g_vehicle_racer_health);
618     instance.vehicle_shield = autocvar_g_vehicle_racer_shield;
619     instance.max_health = GetResource(instance, RES_HEALTH);
620 #endif
621
622 #ifdef CSQC
623     AuxiliaryXhair[0].axh_image = vCROSS_LOCK; // Rocket
624 #endif
625 }
626
627 #endif