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