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