Merge branch 'divVerent/simpler-clipped-rectangle' into 'master'
[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                 if(vehic.strength_finished < time)
268                 {
269                         vehic.strength_finished = time + 10.922667; //soundlength("vehicles/racer_boost.wav");
270                         sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_VEH_RACER_BOOST, VOL_VEHICLEENGINE, ATTEN_NORM);
271                 }
272 #endif
273         }
274         else
275         {
276                 vehic.strength_finished = 0;
277                 sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM);
278         }
279
280         if(cont & DPCONTENTS_LIQUIDSMASK)
281                 vehic.racer_watertime = time;
282
283         float dforce = autocvar_g_vehicle_racer_downforce;
284         if(time - vehic.racer_watertime <= 3)
285                 dforce = autocvar_g_vehicle_racer_water_downforce;
286
287         df -= v_up * (vlen(vehic.velocity) * dforce);
288         CS(player).movement = vehic.velocity += df * dt;
289
290 #ifdef SVQC
291
292         Weapon wep1 = WEP_RACER;
293         .entity weaponentity = weaponentities[0]; // TODO: unhardcode
294         if (!weaponLocked(player) && !weaponUseForbidden(player))
295         if (PHYS_INPUT_BUTTON_ATCK(player))
296         if (wep1.wr_checkammo1(wep1, vehic, weaponentity))
297         {
298                 wep1.wr_think(wep1, vehic, weaponentity, 1);
299         }
300
301         if(autocvar_g_vehicle_racer_rocket_locktarget)
302         {
303                 if(time >= vehic.vehicle_last_trace)
304                 {
305                         crosshair_trace(player);
306
307                         vehicles_locktarget(vehic, (1 / autocvar_g_vehicle_racer_rocket_locking_time) * dt,
308                                                          (1 / autocvar_g_vehicle_racer_rocket_locking_releasetime) * dt,
309                                                          autocvar_g_vehicle_racer_rocket_locked_time);
310
311                         vehic.vehicle_last_trace = time + autocvar_g_vehicle_racer_thinkrate;
312                 }
313
314                 if(vehic.lock_target)
315                 {
316                         if(vehic.lock_strength == 1)
317                                 UpdateAuxiliaryXhair(player, real_origin(vehic.lock_target), '1 0 0', 0);
318                         else if(vehic.lock_strength > 0.5)
319                                 UpdateAuxiliaryXhair(player, real_origin(vehic.lock_target), '0 1 0', 0);
320                         else if(vehic.lock_strength < 0.5)
321                                 UpdateAuxiliaryXhair(player, real_origin(vehic.lock_target), '0 0 1', 0);
322                 }
323         }
324
325         if(!weaponLocked(player))
326         if(time > vehic.delay)
327         if(PHYS_INPUT_BUTTON_ATCK2(player))
328         {
329                 vehic.misc_bulletcounter += 1;
330                 vehic.delay = time + 0.3;
331
332                 if(vehic.misc_bulletcounter == 1)
333                 {
334                         racer_fire_rocket_aim(vehic, player, "tag_rocket_r", (vehic.lock_strength == 1 && vehic.lock_target) ? vehic.lock_target : NULL);
335                         player.vehicle_ammo2 = 50;
336                 }
337                 else if(vehic.misc_bulletcounter == 2)
338                 {
339                         racer_fire_rocket_aim(vehic, player, "tag_rocket_l", (vehic.lock_strength == 1 && vehic.lock_target) ? vehic.lock_target : NULL);
340                         vehic.lock_strength  = 0;
341                         vehic.lock_target       = NULL;
342                         vehic.misc_bulletcounter = 0;
343                         vehic.delay = time + autocvar_g_vehicle_racer_rocket_refire;
344                         vehic.lip = time;
345                         player.vehicle_ammo2 = 0;
346                 }
347         }
348         else if(vehic.misc_bulletcounter == 0)
349                 player.vehicle_ammo2 = 100;
350
351         player.vehicle_reload2 = bound(0, 100 * ((time - vehic.lip) / (vehic.delay - vehic.lip)), 100);
352
353         if(vehic.vehicle_flags & VHF_SHIELDREGEN)
354                 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);
355
356         if(vehic.vehicle_flags & VHF_HEALTHREGEN)
357                 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);
358
359         if(vehic.vehicle_flags & VHF_ENERGYREGEN)
360                 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);
361
362         VEHICLE_UPDATE_PLAYER_RESOURCE(player, vehic, health, racer, RES_HEALTH);
363         VEHICLE_UPDATE_PLAYER(player, vehic, energy, racer);
364
365         if(vehic.vehicle_flags & VHF_HASSHIELD)
366                 VEHICLE_UPDATE_PLAYER(player, vehic, shield, racer);
367
368         PHYS_INPUT_BUTTON_ATCK(player) = PHYS_INPUT_BUTTON_ATCK2(player) = false;
369 #endif
370
371         setorigin(player, vehic.origin + '0 0 32');
372         player.oldorigin = player.origin; // negate fall damage
373         player.velocity = vehic.velocity;
374 }
375
376 void racer_think(entity this)
377 {
378         float dt = autocvar_g_vehicle_racer_thinkrate;
379
380         this.nextthink = time + dt;
381
382         tracebox(this.origin, this.mins, this.maxs, this.origin - ('0 0 1' * autocvar_g_vehicle_racer_springlength), MOVE_NOMONSTERS, this);
383
384         vector df = this.velocity * -autocvar_g_vehicle_racer_friction;
385         df_z += (1 - trace_fraction) * autocvar_g_vehicle_racer_hoverpower + sin(time * 2) * (autocvar_g_vehicle_racer_springlength * 2);
386
387         float forced = autocvar_g_vehicle_racer_upforcedamper;
388
389         //int cont = pointcontents(this.origin - '0 0 64');
390         traceline(this.origin - '0 0 64', this.origin - '0 0 64', MOVE_NOMONSTERS, this);
391         //if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
392         if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
393         {
394                 forced = autocvar_g_vehicle_racer_water_upforcedamper;
395                 this.velocity_z += 200;
396         }
397
398         this.velocity += df * dt;
399         if(this.velocity_z > 0)
400                 this.velocity_z *= 1 - forced * dt;
401
402         this.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * dt);
403         this.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * dt);
404
405         CSQCMODEL_AUTOUPDATE(this);
406 }
407
408 void racer_exit(entity this, int eject)
409 {
410         vector spot;
411
412         setthink(this, racer_think);
413         this.nextthink  = time;
414         set_movetype(this, MOVETYPE_BOUNCE);
415         sound (this.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM);
416
417         if(!this.owner)
418                 return;
419
420         makevectors(this.angles);
421         if(eject)
422         {
423                 spot = this.origin + v_forward * 100 + '0 0 64';
424                 spot = vehicles_findgoodexit(this, this.owner, spot);
425                 setorigin(this.owner, spot);
426                 this.owner.velocity = (v_up + v_forward * 0.25) * 750;
427                 this.owner.oldvelocity = this.owner.velocity;
428         }
429         else
430         {
431                 if(vdist(this.velocity, >, 2 * autocvar_sv_maxairspeed))
432                 {
433                         this.owner.velocity = normalize(this.velocity) * autocvar_sv_maxairspeed * 2;
434                         this.owner.velocity_z += 200;
435                         spot = this.origin + v_forward * 32 + '0 0 32';
436                         spot = vehicles_findgoodexit(this, this.owner, spot);
437                 }
438                 else
439                 {
440                         this.owner.velocity = this.velocity * 0.5;
441                         this.owner.velocity_z += 10;
442                         spot = this.origin - v_forward * 200 + '0 0 32';
443                         spot = vehicles_findgoodexit(this, this.owner, spot);
444                 }
445                 this.owner.oldvelocity = this.owner.velocity;
446                 setorigin(this.owner , spot);
447         }
448         antilag_clear(this.owner, CS(this.owner));
449         this.owner = NULL;
450 }
451
452 void racer_blowup(entity this)
453 {
454         this.deadflag = DEAD_DEAD;
455         this.vehicle_exit(this, VHEF_NORMAL);
456
457         RadiusDamage (this, this.enemy, autocvar_g_vehicle_racer_blowup_coredamage,
458                                         autocvar_g_vehicle_racer_blowup_edgedamage,
459                                         autocvar_g_vehicle_racer_blowup_radius, NULL, NULL,
460                                         autocvar_g_vehicle_racer_blowup_forceintensity,
461                                         DEATH_VH_WAKI_DEATH.m_id, DMG_NOWEP, NULL);
462
463         this.nextthink  = time + autocvar_g_vehicle_racer_respawntime;
464         setthink(this, vehicles_spawn);
465         set_movetype(this, MOVETYPE_NONE);
466         this.effects    = EF_NODRAW;
467         this.solid = SOLID_NOT;
468
469         this.colormod  = '0 0 0';
470         this.avelocity = '0 0 0';
471         this.velocity  = '0 0 0';
472
473         setorigin(this, this.pos1);
474 }
475
476 void racer_blowup_think(entity this)
477 {
478         this.nextthink = time;
479
480         if(time >= this.delay)
481                 racer_blowup(this);
482
483         //CSQCMODEL_AUTOUPDATE(this);
484 }
485
486 void racer_deadtouch(entity this, entity toucher)
487 {
488         this.avelocity_x *= 0.7;
489         this.cnt -= 1;
490         if(this.cnt <= 0)
491                 racer_blowup(this);
492 }
493
494 spawnfunc(vehicle_racer)
495 {
496         if(!autocvar_g_vehicle_racer) { delete(this); return; }
497         if(!vehicle_initialize(this, VEH_RACER, false)) { delete(this); return; }
498 }
499
500 #endif // SVQC
501
502 METHOD(Racer, vr_impact, void(Racer thisveh, entity instance))
503 {
504 #ifdef SVQC
505     if(autocvar_g_vehicle_racer_bouncepain)
506         vehicles_impact(instance, autocvar_g_vehicle_racer_bouncepain_x, autocvar_g_vehicle_racer_bouncepain_y, autocvar_g_vehicle_racer_bouncepain_z);
507 #endif
508 }
509
510 METHOD(Racer, vr_enter, void(Racer thisveh, entity instance))
511 {
512     set_movetype(instance, MOVETYPE_BOUNCE);
513 #ifdef SVQC
514     instance.owner.vehicle_health = (GetResource(instance, RES_HEALTH) / autocvar_g_vehicle_racer_health)  * 100;
515     instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_racer_shield)  * 100;
516
517     if(instance.owner.flagcarried)
518        setorigin(instance.owner.flagcarried, '-190 0 96');
519 #endif
520 }
521
522 METHOD(Racer, vr_spawn, void(Racer thisveh, entity instance))
523 {
524 #ifdef SVQC
525     if(autocvar_g_vehicle_racer_hovertype != 0)
526         instance.racer_force_from_tag = vehicles_force_fromtag_maglev;
527     else
528         instance.racer_force_from_tag = vehicles_force_fromtag_hover;
529
530     setthink(instance, racer_think);
531     instance.nextthink    = time;
532     SetResourceExplicit(instance, RES_HEALTH, autocvar_g_vehicle_racer_health);
533     instance.vehicle_shield = autocvar_g_vehicle_racer_shield;
534
535     set_movetype(instance, MOVETYPE_TOSS);
536     instance.solid                = SOLID_SLIDEBOX;
537     instance.delay                = time;
538     instance.scale                = 0.5; // FIXME: this be hakkz, fix the models insted (scale body, add tag_viewport to the hudmodel).
539     instance.mass                 = 900;
540
541     setattachment(instance.vehicle_hudmodel, instance, "");
542     setattachment(instance.vehicle_viewport, instance, "tag_viewport");
543
544     instance.PlayerPhysplug = racer_frame;
545
546     instance.bouncefactor = autocvar_g_vehicle_racer_bouncefactor;
547     instance.bouncestop = autocvar_g_vehicle_racer_bouncestop;
548     instance.damageforcescale = 0.5;
549     SetResourceExplicit(instance, RES_HEALTH, autocvar_g_vehicle_racer_health);
550     instance.vehicle_shield = autocvar_g_vehicle_racer_shield;
551 #endif
552 }
553
554 METHOD(Racer, vr_death, void(Racer thisveh, entity instance))
555 {
556 #ifdef SVQC
557     setSendEntity(instance, func_null); // stop networking this racer (for now)
558     SetResourceExplicit(instance, RES_HEALTH, 0);
559     instance.event_damage       = func_null;
560     instance.solid                      = SOLID_CORPSE;
561     instance.takedamage         = DAMAGE_NO;
562     instance.deadflag           = DEAD_DYING;
563     set_movetype(instance, MOVETYPE_BOUNCE);
564     instance.wait                       = time;
565     instance.delay                      = 2 + time + random() * 3;
566     instance.cnt                        = 1 + random() * 2;
567     settouch(instance, racer_deadtouch);
568
569     Send_Effect(EFFECT_EXPLOSION_MEDIUM, instance.origin, '0 0 0', 1);
570
571     if(random() < 0.5)
572         instance.avelocity_z = 32;
573     else
574         instance.avelocity_z = -32;
575
576     instance.avelocity_x = -vlen(instance.velocity) * 0.2;
577     instance.velocity += '0 0 700';
578     instance.colormod = '-0.5 -0.5 -0.5';
579
580     setthink(instance, racer_blowup_think);
581     instance.nextthink = time;
582 #endif
583 }
584
585 #ifdef CSQC
586 METHOD(Racer, vr_hud, void(Racer thisveh))
587 {
588     Vehicles_drawHUD(VEH_RACER.m_icon, "vehicle_racer_weapon1", "vehicle_racer_weapon2",
589                      "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
590                      "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
591 }
592 METHOD(Racer, vr_crosshair, void(Racer thisveh, entity player))
593 {
594     Vehicles_drawCrosshair(vCROSS_GUIDE);
595 }
596 #endif
597 METHOD(Racer, vr_setup, void(Racer thisveh, entity instance))
598 {
599 #ifdef SVQC
600     instance.vehicle_exit = racer_exit;
601
602     // we have no need to network energy
603     if(autocvar_g_vehicle_racer_energy && autocvar_g_vehicle_racer_energy_regen)
604         instance.vehicle_flags |= VHF_ENERGYREGEN;
605
606     if(autocvar_g_vehicle_racer_shield)
607         instance.vehicle_flags |= VHF_HASSHIELD;
608
609     if(autocvar_g_vehicle_racer_shield_regen)
610         instance.vehicle_flags |= VHF_SHIELDREGEN;
611
612     if(autocvar_g_vehicle_racer_health_regen)
613         instance.vehicle_flags |= VHF_HEALTHREGEN;
614
615     instance.respawntime = autocvar_g_vehicle_racer_respawntime;
616     SetResourceExplicit(instance, RES_HEALTH, autocvar_g_vehicle_racer_health);
617     instance.vehicle_shield = autocvar_g_vehicle_racer_shield;
618     instance.max_health = GetResource(instance, RES_HEALTH);
619 #endif
620
621 #ifdef CSQC
622     AuxiliaryXhair[0].axh_image = vCROSS_LOCK; // Rocket
623 #endif
624 }
625
626 #endif