]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/vehicles/sv_vehicles.qc
Radar icons: fix colour
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / sv_vehicles.qc
index bcfbf88752b4324ed15c914c66dddf278ebf6c84..7108e80770cf20e235a8ca81799e56bbfda79fcd 100644 (file)
@@ -1,9 +1,44 @@
-// =========================
-//  SVQC Vehicle Properties
-// =========================
+#include "sv_vehicles.qh"
+#include "../effects/effects.qh"
 
+#if 0
+bool vehicle_send(entity to, int sf)
+{
+       WriteByte(MSG_ENTITY, ENT_CLIENT_VEHICLE);
+       WriteByte(MSG_ENTITY, sf);
+
+       if(sf & VSF_SPAWN)
+       {
+               WriteByte(MSG_ENTITY, self.vehicleid);
+       }
+
+       if(sf & VSF_SETUP)
+       {
+               // send stuff?
+       }
+
+       if(sf & VSF_ENTER)
+       {
+               // player handles the .vehicle stuff, we need only set ourselves up for driving
+
+               // send stuff?
+       }
+
+       if(sf & VSF_EXIT)
+       {
+               // senf stuff?
+       }
+
+       if(sf & VSF_PRECACHE)
+       {
+               // send stuff?!
+       }
 
-float SendAuxiliaryXhair(entity to, float sf)
+       return true;
+}
+#endif
+
+bool SendAuxiliaryXhair(entity this, entity to, int sf)
 {
 
        WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
@@ -18,10 +53,10 @@ float SendAuxiliaryXhair(entity to, float sf)
        WriteByte(MSG_ENTITY, rint(self.colormod_y * 255));
        WriteByte(MSG_ENTITY, rint(self.colormod_z * 255));
 
-       return TRUE;
+       return true;
 }
 
-void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, float axh_id)
+void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, int axh_id)
 {
        if(!IS_REAL_CLIENT(own))
                return;
@@ -37,7 +72,7 @@ void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, float axh_id)
                axh.cnt                          = axh_id;
                axh.drawonlytoclient    = own;
                axh.owner                          = own;
-               Net_LinkEntity(axh, FALSE, 0, SendAuxiliaryXhair);
+               Net_LinkEntity(axh, false, 0, SendAuxiliaryXhair);
        }
 
        setorigin(axh, loc);
@@ -46,7 +81,7 @@ void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, float axh_id)
        own.(AuxiliaryXhair[axh_id]) = axh;
 }
 
-void CSQCVehicleSetup(entity own, float vehicle_id)
+void CSQCVehicleSetup(entity own, int vehicle_id)
 {
        if(!IS_REAL_CLIENT(own))
                return;
@@ -59,9 +94,9 @@ void CSQCVehicleSetup(entity own, float vehicle_id)
 }
 
 vector targetdrone_getnewspot()
-{
+{SELFPARAM();
        vector spot;
-       float i;
+       int i;
        for(i = 0; i < 100; ++i)
        {
                spot = self.origin + randomvec() * 1024;
@@ -73,7 +108,7 @@ vector targetdrone_getnewspot()
 }
 
 void vehicles_locktarget(float incr, float decr, float _lock_time)
-{
+{SELFPARAM();
        if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
        {
                self.lock_target        = world;
@@ -101,10 +136,10 @@ void vehicles_locktarget(float incr, float decr, float _lock_time)
                if(trace_ent.deadflag != DEAD_NO)
                        trace_ent = world;
 
-               if(!((trace_ent.vehicle_flags & VHF_ISVEHICLE) || (trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET)))
+               if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent)))
                        trace_ent = world;
 
-               if(trace_ent.alpha <= 0.5 && trace_ent.alpha)
+               if(trace_ent.alpha <= 0.5 && trace_ent.alpha != 0)
                        trace_ent = world; // invisible
        }
 
@@ -146,7 +181,7 @@ void vehicles_locktarget(float incr, float decr, float _lock_time)
 }
 
 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
-{
+{SELFPARAM();
        force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
        v_forward  = normalize(v_forward) * -1;
        traceline(force_fromtag_origin, force_fromtag_origin - (v_forward  * spring_length), MOVE_NORMAL, self);
@@ -158,7 +193,7 @@ vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float
 }
 
 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
-{
+{SELFPARAM();
 
        force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
        v_forward  = normalize(v_forward) * -1;
@@ -178,8 +213,8 @@ vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float
 }
 
 // projectile handling
-void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
-{
+void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
+{SELFPARAM();
        // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
        if(inflictor.owner == self.owner)
                return;
@@ -196,7 +231,7 @@ void vehicles_projectile_damage(entity inflictor, entity attacker, float damage,
 }
 
 void vehicles_projectile_explode()
-{
+{SELFPARAM();
        if(self.owner && other != world)
        {
                if(other == self.owner.vehicle)
@@ -209,7 +244,7 @@ void vehicles_projectile_explode()
        PROJECTILE_TOUCH;
 
        self.event_damage = func_null;
-       RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, self.shot_force, self.totalfrags, other);
+       RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, world, self.shot_force, self.totalfrags, other);
 
        remove (self);
 }
@@ -217,9 +252,9 @@ void vehicles_projectile_explode()
 entity vehicles_projectile(string _mzlfx, string _mzlsound,
                                                   vector _org, vector _vel,
                                                   float _dmg, float _radi, float _force,  float _size,
-                                                  float _deahtype, float _projtype, float _health,
-                                                  float _cull, float _clianim, entity _owner)
-{
+                                                  int _deahtype, float _projtype, float _health,
+                                                  bool _cull, bool _clianim, entity _owner)
+{SELFPARAM();
        entity proj;
 
        proj = spawn();
@@ -234,7 +269,7 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound,
        proj.solid                      = SOLID_BBOX;
        proj.movetype            = MOVETYPE_FLYMISSILE;
        proj.flags                      = FL_PROJECTILE;
-       proj.bot_dodge          = TRUE;
+       proj.bot_dodge          = true;
        proj.bot_dodgerating  = _dmg;
        proj.velocity            = _vel;
        proj.touch                      = vehicles_projectile_explode;
@@ -254,11 +289,10 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound,
                proj.flags                 = FL_PROJECTILE | FL_NOTARGET;
 
        if(_mzlsound)
-               sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
+               _sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
 
        if(_mzlfx)
-               pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1);
-
+               Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
 
        setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
 
@@ -268,14 +302,15 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound,
 }
 
 void vehicles_gib_explode()
-{
-       sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
-       pointparticles(particleeffectnum("explosion_small"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
+{SELFPARAM();
+       sound (self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
+       Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
+       Send_Effect(EFFECT_EXPLOSION_SMALL, self.wp00.origin + '0 0 64', '0 0 0', 1);
        remove(self);
 }
 
 void vehicles_gib_think()
-{
+{SELFPARAM();
        self.alpha -= 0.1;
        if(self.cnt >= time)
                remove(self);
@@ -283,10 +318,10 @@ void vehicles_gib_think()
                self.nextthink = time + 0.1;
 }
 
-entity vehicle_tossgib(entity _template, vector _vel, string _tag, float _burn, float _explode, float _maxtime, vector _rot)
-{
+entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
+{SELFPARAM();
        entity _gib = spawn();
-       setmodel(_gib, _template.model);
+       _setmodel(_gib, _template.model);
        setorigin(_gib, gettaginfo(self, gettagindex(self, _tag)));
        _gib.velocity = _vel;
        _gib.movetype = MOVETYPE_TOSS;
@@ -314,12 +349,12 @@ entity vehicle_tossgib(entity _template, vector _vel, string _tag, float _burn,
        return _gib;
 }
 
-float vehicle_addplayerslot(   entity _owner,
+bool vehicle_addplayerslot(    entity _owner,
                                                                entity _slot,
-                                                               float _hud,
+                                                               int _hud,
                                                                string _hud_model,
-                                                               float() _framefunc,
-                                                               void(float) _exitfunc, float() _enterfunc)
+                                                               bool() _framefunc,
+                                                               void(bool) _exitfunc, float() _enterfunc)
 {
        if(!(_owner.vehicle_flags & VHF_MULTISLOT))
                _owner.vehicle_flags |= VHF_MULTISLOT;
@@ -334,13 +369,13 @@ float vehicle_addplayerslot(      entity _owner,
        _slot.vehicle_hudmodel.viewmodelforclient = _slot;
        _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
 
-       setmodel(_slot.vehicle_hudmodel, _hud_model);
-       setmodel(_slot.vehicle_viewport, "null");
+       _setmodel(_slot.vehicle_hudmodel, _hud_model);
+       setmodel(_slot.vehicle_viewport, MDL_Null);
 
        setattachment(_slot.vehicle_hudmodel, _slot, "");
        setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
 
-       return TRUE;
+       return true;
 }
 
 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
@@ -352,7 +387,7 @@ vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string
        vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
        vtmp = vectoangles(normalize(_target - vtag));
        vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
-       vtmp = AnglesTransform_Normalize(vtmp, TRUE);
+       vtmp = AnglesTransform_Normalize(vtmp, true);
        ftmp = _aimspeed * frametime;
        vtmp_y = bound(-ftmp, vtmp_y, ftmp);
        vtmp_x = bound(-ftmp, vtmp_x, ftmp);
@@ -362,7 +397,7 @@ vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string
 }
 
 void vehicles_reset_colors()
-{
+{SELFPARAM();
        entity e;
        float _effects = 0, _colormap;
        vector _glowmod, _colormod;
@@ -443,8 +478,8 @@ void vehicles_clearreturn(entity veh)
 
 void vehicles_spawn();
 void vehicles_return()
-{
-       pointparticles(particleeffectnum("teleport"), self.wp00.origin + '0 0 64', '0 0 0', 1);
+{SELFPARAM();
+       Send_Effect(EFFECT_TELEPORT, self.wp00.origin + '0 0 64', '0 0 0', 1);
 
        self.wp00.think  = vehicles_spawn;
        self.wp00.nextthink = time;
@@ -456,7 +491,7 @@ void vehicles_return()
 }
 
 void vehicles_showwp_goaway()
-{
+{SELFPARAM();
        if(self.waypointsprite_attached)
                WaypointSprite_Kill(self.waypointsprite_attached);
 
@@ -465,7 +500,7 @@ void vehicles_showwp_goaway()
 }
 
 void vehicles_showwp()
-{
+{SELFPARAM();
        entity oldself = world;
        vector rgb;
 
@@ -480,8 +515,8 @@ void vehicles_showwp()
                self.nextthink  = time +1;
 
                oldself = self;
-               self = spawn();
-               setmodel(self, "null");
+               setself(spawn());
+               setmodel(self, MDL_Null);
                self.team = oldself.wp00.team;
                self.wp00 = oldself.wp00;
                setorigin(self, oldself.wp00.pos1);
@@ -494,17 +529,18 @@ void vehicles_showwp()
                rgb = Team_ColorRGB(self.team);
        else
                rgb = '1 1 1';
-       WaypointSprite_Spawn("vehicle", 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
+       entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Vehicle);
+       wp.colormod = rgb;
        if(self.waypointsprite_attached)
        {
                WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
-               if(oldself == world)
+               if(this == NULL)
                        WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
                WaypointSprite_Ping(self.waypointsprite_attached);
        }
 
-       if(oldself != world)
-               self = oldself;
+       if(this)
+               setself(this);
 }
 
 void vehicles_setreturn(entity veh)
@@ -529,14 +565,14 @@ void vehicles_setreturn(entity veh)
                ret.nextthink   = min(time + veh.respawntime, time + veh.respawntime - 1);
        }
 
-       setmodel(ret, "null");
+       setmodel(ret, MDL_Null);
        setorigin(ret, veh.pos1 + '0 0 96');
 
 }
 
 void vehicle_use()
-{
-       dprint("vehicle ",self.netname, " used by ", activator.classname, "\n");
+{SELFPARAM();
+       LOG_TRACE("vehicle ",self.netname, " used by ", activator.classname, "\n");
 
        self.tur_head.team = activator.team;
 
@@ -547,7 +583,7 @@ void vehicle_use()
 
        if(self.active == ACTIVE_ACTIVE && self.deadflag == DEAD_NO && !gameover)
        {
-               dprint("Respawning vehicle: ", self.netname, "\n");
+               LOG_TRACE("Respawning vehicle: ", self.netname, "\n");
                if(self.effects & EF_NODRAW)
                {
                        self.think = vehicles_spawn;
@@ -562,26 +598,26 @@ void vehicle_use()
 }
 
 void vehicles_regen(float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
-{
-       if(self.regen_field < field_max)
+{SELFPARAM();
+       if(self.(regen_field) < field_max)
        if(timer + rpause < time)
        {
                if(_healthscale)
                        regen = regen * (self.vehicle_health / self.max_health);
 
-               self.regen_field = min(self.regen_field + regen * delta_time, field_max);
+               self.(regen_field) = min(self.(regen_field) + regen * delta_time, field_max);
 
                if(self.owner)
-                       self.owner.regen_field = (self.regen_field / field_max) * 100;
+                       self.owner.(regen_field) = (self.(regen_field) / field_max) * 100;
        }
 }
 
 void shieldhit_think()
-{
+{SELFPARAM();
        self.alpha -= 0.1;
        if (self.alpha <= 0)
        {
-               //setmodel(self, "");
+               // setmodel(self, MDL_Null);
                self.alpha = -1;
                self.effects |= EF_NODRAW;
        }
@@ -592,14 +628,14 @@ void shieldhit_think()
 }
 
 void vehicles_painframe()
-{
+{SELFPARAM();
        if(self.owner.vehicle_health <= 50)
        if(self.pain_frame < time)
        {
                float _ftmp;
                _ftmp = self.owner.vehicle_health / 50;
                self.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
-               pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
+               pointparticles(particleeffectnum(EFFECT_SMOKE_SMALL), (self.origin + (randomvec() * 80)), '0 0 0', 1);
 
                if(self.vehicle_flags & VHF_DMGSHAKE)
                        self.velocity += randomvec() * 30;
@@ -613,25 +649,29 @@ void vehicles_painframe()
        }
 }
 
-void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
-{
+void vehicles_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
+{SELFPARAM();
        self.dmg_time = time;
 
-       if(DEATH_ISWEAPON(deathtype, WEP_NEX))
-               damage *= autocvar_g_vehicles_nex_damagerate;
+       // WEAPONTODO
+       if(DEATH_ISWEAPON(deathtype, WEP_VORTEX.m_id))
+               damage *= autocvar_g_vehicles_vortex_damagerate;
 
-       if(DEATH_ISWEAPON(deathtype, WEP_UZI))
-               damage *= autocvar_g_vehicles_uzi_damagerate;
+       if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN.m_id))
+               damage *= autocvar_g_vehicles_machinegun_damagerate;
 
-       if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
+       if(DEATH_ISWEAPON(deathtype, WEP_RIFLE.m_id))
                damage *= autocvar_g_vehicles_rifle_damagerate;
 
-       if(DEATH_ISWEAPON(deathtype, WEP_MINSTANEX))
-               damage *= autocvar_g_vehicles_minstanex_damagerate;
+       if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER.m_id))
+               damage *= autocvar_g_vehicles_vaporizer_damagerate;
 
-       if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
+       if(DEATH_ISWEAPON(deathtype, WEP_SEEKER.m_id))
                damage *= autocvar_g_vehicles_tag_damagerate;
 
+       if(DEATH_WEAPONOFWEAPONDEATH(deathtype))
+               damage *= autocvar_g_vehicles_weapon_damagerate;
+
        self.enemy = attacker;
 
        self.pain_finished = time;
@@ -643,7 +683,7 @@ void vehicles_damage(entity inflictor, entity attacker, float damage, float deat
                        self.vehicle_shieldent = spawn();
                        self.vehicle_shieldent.effects = EF_LOWPRECISION;
 
-                       setmodel(self.vehicle_shieldent, "models/vhshield.md3");
+                       setmodel(self.vehicle_shieldent, MDL_VEH_SHIELD);
                        setattachment(self.vehicle_shieldent, self, "");
                        setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
                        self.vehicle_shieldent.scale       = 256 / vlen(self.maxs - self.mins);
@@ -697,24 +737,25 @@ void vehicles_damage(entity inflictor, entity attacker, float damage, float deat
 
                antilag_clear(self);
 
-               VEH_ACTION(self.vehicleid, VR_DEATH);
+               Vehicle info = get_vehicleinfo(self.vehicleid);
+               info.vr_death(info);
                vehicles_setreturn(self);
        }
 }
 
 float vehicles_crushable(entity e)
 {
-       if(IS_PLAYER(e))
-               return TRUE;
+       if(IS_PLAYER(e) && time >= e.vehicle_enter_delay)
+               return true;
 
-       if(e.flags & FL_MONSTER)
-               return TRUE;
+       if(IS_MONSTER(e))
+               return true;
 
-       return FALSE;
+       return false;
 }
 
 void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
-{
+{SELFPARAM();
        if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
                return;
 
@@ -737,7 +778,7 @@ void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
 
 // vehicle enter/exit handling
 vector vehicles_findgoodexit(vector prefer_spot)
-{
+{SELFPARAM();
        //vector exitspot;
        float mysize;
 
@@ -784,19 +825,18 @@ vector vehicles_findgoodexit(vector prefer_spot)
        return self.origin;
 }
 
-void vehicles_exit(float eject)
-{
+void vehicles_exit(bool eject)
+{SELFPARAM();
        entity _vehicle;
        entity _player;
-       entity _oldself = self;
 
        if(vehicles_exit_running)
        {
-               dprint("^1vehicles_exit allready running! this is not good..\n");
+               LOG_TRACE("^1vehicles_exit allready running! this is not good..\n");
                return;
        }
 
-       vehicles_exit_running = TRUE;
+       vehicles_exit_running = true;
        if(IS_CLIENT(self))
        {
                _vehicle = self.vehicle;
@@ -804,8 +844,8 @@ void vehicles_exit(float eject)
                if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
                {
                        _vehicle.vehicle_exit(eject);
-                       self = _oldself;
-                       vehicles_exit_running = FALSE;
+                       setself(this);
+                       vehicles_exit_running = false;
                        return;
                }
        }
@@ -814,7 +854,7 @@ void vehicles_exit(float eject)
 
        _player = _vehicle.owner;
 
-       self = _vehicle;
+       setself(_vehicle);
 
        if (_player)
        {
@@ -845,6 +885,7 @@ void vehicles_exit(float eject)
                _player.hud                             = HUD_NORMAL;
                _player.switchweapon    = _vehicle.switchweapon;
                _player.last_vehiclecheck = time + 3;
+               _player.vehicle_enter_delay = time + 2;
 
                CSQCVehicleSetup(_player, HUD_NORMAL);
        }
@@ -863,15 +904,11 @@ void vehicles_exit(float eject)
 
        WaypointSprite_Kill(_vehicle.wps_intruder);
 
-       vh_player = _player;
-       vh_vehicle = _vehicle;
-       MUTATOR_CALLHOOK(VehicleExit);
-       _player = vh_player;
-       _vehicle = vh_vehicle;
+       MUTATOR_CALLHOOK(VehicleExit, _player, _vehicle);
 
        _vehicle.team = _vehicle.tur_head.team;
 
-       sound (_vehicle, CH_TRIGGER_SINGLE, "misc/null.wav", 1, ATTEN_NORM);
+       sound (_vehicle, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM);
        _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;
        _vehicle.phase = time + 1;
 
@@ -881,16 +918,15 @@ void vehicles_exit(float eject)
        vehicles_reset_colors();
        _vehicle.owner = world;
 
-       CSQCMODEL_AUTOINIT();
+       CSQCMODEL_AUTOINIT(self);
 
-       self = _oldself;
-
-       vehicles_exit_running = FALSE;
+       setself(this);
+       vehicles_exit_running = false;
 }
 
 void vehicles_touch()
-{
-       if(MUTATOR_CALLHOOK(VehicleTouch))
+{SELFPARAM();
+       if(MUTATOR_CALLHOOK(VehicleTouch, self, other))
                return;
 
        // Vehicle currently in use
@@ -901,14 +937,16 @@ void vehicles_touch()
                if((self.origin_z + self.maxs_z) > (other.origin_z))
                if(vehicles_crushable(other))
                {
-                       if(vlen(self.velocity) != 0)
+                       if(vlen(self.velocity) >= 30)
                                Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_VH_CRUSH, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force);
 
                        return; // Dont do selfdamage when hitting "soft targets".
                }
 
-               if(self.play_time < time)
-                       VEH_ACTION(self.vehicleid, VR_IMPACT);
+               if(self.play_time < time) {
+                       Vehicle info = get_vehicleinfo(self.vehicleid);
+                       info.vr_impact(info);
+               }
 
                return;
        }
@@ -919,57 +957,60 @@ void vehicles_touch()
        vehicles_enter(other, self);
 }
 
-void vehicles_enter(entity pl, entity veh)
-{
-   // Remove this when bots know how to use vehicles
-       if (IS_BOT_CLIENT(pl))
-       if (autocvar_g_vehicles_allow_bots)
-               dprint("Bot enters vehicle\n"); // This is where we need to disconnect (some, all?) normal bot AI and hand over to vehicle's _aiframe()
-       else
-               return;
-
-       if(!IS_PLAYER(pl))
-               return;
-
-       if(veh.phase > time)
-               return;
+bool vehicle_impulse(int imp)
+{SELFPARAM();
+       switch(imp)
+       {
+               case 17:
+               {
+                       stuffcmd(self, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
+                       return true;
+               }
+       }
 
-       if(pl.frozen)
-               return;
+       return false;
+}
 
-       if(pl.deadflag != DEAD_NO)
+void vehicles_enter(entity pl, entity veh)
+{SELFPARAM();
+   // Remove this when bots know how to use vehicles
+       if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
                return;
 
-       if(pl.vehicle)
-               return;
+       if((!IS_PLAYER(pl))
+       || (veh.phase >= time)
+       || (pl.vehicle_enter_delay >= time)
+       || (pl.frozen)
+       || (pl.deadflag != DEAD_NO)
+       || (pl.vehicle)
+       ) { return; }
 
-       if(autocvar_g_vehicles_enter) // skip if we're using regular touch code
+       if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
        if(veh.vehicle_flags & VHF_MULTISLOT)
        if(veh.owner)
        {
-               entity oldself = self;
-               self = veh;
+               setself(veh);
                other = pl; // TODO: fix
 
                if(!veh.gunner1)
-               if(veh.gun1.phase <= time)
+               if(time >= veh.gun1.phase)
                if(veh.gun1.vehicle_enter)
                if(veh.gun1.vehicle_enter())
                {
-                       self = oldself;
+                       setself(this);
                        return;
                }
 
                if(!veh.gunner2)
-               if(veh.gun2.phase <= time)
+               if(time >= veh.gun2.phase)
                if(veh.gun2.vehicle_enter)
                if(veh.gun2.vehicle_enter())
                {
-                       self = oldself;
+                       setself(this);
                        return;
                }
 
-               self = oldself;
+               setself(this);
        }
 
        if(teamplay)
@@ -983,8 +1024,10 @@ void vehicles_enter(entity pl, entity veh)
 
                Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
 
-               if(autocvar_g_vehicles_steal_show_waypoint)
-                       WaypointSprite_Spawn("intruder", 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, TRUE, RADARICON_DANGER, Team_ColorRGB(pl.team));
+               if (autocvar_g_vehicles_steal_show_waypoint) {
+                       entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
+                       wp.colormod = Team_ColorRGB(pl.team);
+               }
        }
        else return;
 
@@ -1004,8 +1047,8 @@ void vehicles_enter(entity pl, entity veh)
 
        veh.vehicle_hudmodel.viewmodelforclient = pl;
 
-       tracebox(pl.origin, PL_MIN, PL_MAX, pl.origin, FALSE, pl);
-       pl.crouch = FALSE;
+       tracebox(pl.origin, PL_MIN, PL_MAX, pl.origin, false, pl);
+       pl.crouch = false;
        pl.view_ofs = PL_VIEW_OFS;
        setsize (pl, PL_MIN, PL_MAX);
 
@@ -1015,7 +1058,7 @@ void vehicles_enter(entity pl, entity veh)
        pl.takedamage           = DAMAGE_NO;
        pl.solid                        = SOLID_NOT;
        pl.movetype                     = MOVETYPE_NOCLIP;
-       pl.teleportable         = FALSE;
+       pl.teleportable         = false;
        pl.alpha                        = -1;
        pl.event_damage         = func_null;
        pl.view_ofs                     = '0 0 0';
@@ -1030,6 +1073,7 @@ void vehicles_enter(entity pl, entity veh)
        pl.vehicle_ammo2 = veh.vehicle_ammo2;
        pl.vehicle_reload1 = veh.vehicle_reload1;
        pl.vehicle_reload2 = veh.vehicle_reload2;
+       pl.vehicle_energy = veh.vehicle_energy;
 
        // Cant do this, hides attached objects too.
        //veh.exteriormodeltoclient = veh.owner;
@@ -1068,35 +1112,34 @@ void vehicles_enter(entity pl, entity veh)
 
        CSQCVehicleSetup(pl, veh.vehicleid);
 
-       vh_player = pl;
-       vh_vehicle = veh;
-       MUTATOR_CALLHOOK(VehicleEnter);
+       MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
 
-       entity oldself = self;
-       self = veh;
-       CSQCModel_UnlinkEntity();
-       VEH_ACTION(veh.vehicleid, VR_ENTER);
-       self = oldself;
+       setself(veh);
+       CSQCModel_UnlinkEntity(veh);
+       Vehicle info = get_vehicleinfo(veh.vehicleid);
+       info.vr_enter(info);
+       setself(this);
 
        antilag_clear(pl);
 }
 
 void vehicles_think()
-{
+{SELFPARAM();
        self.nextthink = time;
-       
+
        if(self.owner)
                self.owner.vehicle_weapon2mode = self.vehicle_weapon2mode;
-       
-       VEH_ACTION(self.vehicleid, VR_THINK);
 
-       CSQCMODEL_AUTOUPDATE();
+       Vehicle info = get_vehicleinfo(self.vehicleid);
+       info.vr_think(info);
+
+       CSQCMODEL_AUTOUPDATE(self);
 }
 
 // initialization
 void vehicles_spawn()
-{
-       dprint("Spawning vehicle: ", self.classname, "\n");
+{SELFPARAM();
+       LOG_TRACE("Spawning vehicle: ", self.classname, "\n");
 
        // disown & reset
        self.vehicle_hudmodel.viewmodelforclient = self;
@@ -1104,14 +1147,14 @@ void vehicles_spawn()
        self.owner                              = world;
        self.touch                              = vehicles_touch;
        self.event_damage               = vehicles_damage;
-       self.iscreature                 = TRUE;
-       self.teleportable               = FALSE; // no teleporting for vehicles, too buggy
-       self.damagedbycontents  = TRUE;
+       self.iscreature                 = true;
+       self.teleportable               = false; // no teleporting for vehicles, too buggy
+       self.damagedbycontents  = true;
        self.movetype                   = MOVETYPE_WALK;
        self.solid                              = SOLID_SLIDEBOX;
        self.takedamage                 = DAMAGE_AIM;
        self.deadflag                   = DEAD_NO;
-       self.bot_attack                 = TRUE;
+       self.bot_attack                 = true;
        self.flags                              = FL_NOTARGET;
        self.avelocity                  = '0 0 0';
        self.velocity                   = '0 0 0';
@@ -1127,7 +1170,7 @@ void vehicles_spawn()
        self.angles = self.pos2;
        setorigin(self, self.pos1);
        // Show it
-       pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
+       Send_Effect(EFFECT_TELEPORT, self.origin + '0 0 64', '0 0 0', 1);
 
        if(self.vehicle_controller)
                self.team = self.vehicle_controller.team;
@@ -1139,22 +1182,24 @@ void vehicles_spawn()
 
        vehicles_reset_colors();
 
-       VEH_ACTION(self.vehicleid, VR_SPAWN);
+       Vehicle info = get_vehicleinfo(self.vehicleid);
+       info.vr_spawn(info);
 
-       CSQCMODEL_AUTOINIT();
+       CSQCMODEL_AUTOINIT(self);
 }
 
-float vehicle_initialize(float vehicle_id, float nodrop)
-{
+bool vehicle_initialize(entity veh, bool nodrop)
+{SELFPARAM();
        if(!autocvar_g_vehicles)
-               return FALSE;
-
-       entity veh = get_vehicleinfo(vehicle_id);
+               return false;
 
        if(!veh.vehicleid)
-               return FALSE;
-       
-       if(!veh.tur_head) { VEH_ACTION(vehicle_id, VR_PRECACHE); }
+               return false;
+
+       if(!veh.tur_head) {
+               Vehicle info = get_vehicleinfo(veh.vehicleid);
+               info.vr_precache(info);
+       }
 
        if(self.targetname && self.targetname != "")
        {
@@ -1183,20 +1228,23 @@ float vehicle_initialize(float vehicle_id, float nodrop)
        if(self.team && (!teamplay || !autocvar_g_vehicles_teams))
                self.team = 0;
 
-       self.vehicle_flags |= VHF_ISVEHICLE;
+       if(self.mdl == "" || !self.mdl)
+               _setmodel(self, veh.model);
+       else
+               _setmodel(self, self.mdl);
 
-       setmodel(self, veh.model);
+       self.vehicle_flags |= VHF_ISVEHICLE;
 
        self.vehicle_viewport           = spawn();
        self.vehicle_hudmodel           = spawn();
        self.tur_head                           = spawn();
        self.tur_head.owner                     = self;
        self.takedamage                         = DAMAGE_NO;
-       self.bot_attack                         = TRUE;
-       self.iscreature                         = TRUE;
-       self.teleportable                       = FALSE; // no teleporting for vehicles, too buggy
-       self.damagedbycontents          = TRUE;
-       self.vehicleid                          = vehicle_id;
+       self.bot_attack                         = true;
+       self.iscreature                         = true;
+       self.teleportable                       = false; // no teleporting for vehicles, too buggy
+       self.damagedbycontents          = true;
+       self.vehicleid                          = veh.vehicleid;
        self.PlayerPhysplug                     = veh.PlayerPhysplug;
        self.event_damage                       = func_null;
        self.touch                                      = vehicles_touch;
@@ -1214,12 +1262,12 @@ float vehicle_initialize(float vehicle_id, float nodrop)
        if(autocvar_g_fullbrightplayers)
                self.effects |= EF_FULLBRIGHT;
 
-       setmodel(self.vehicle_hudmodel, veh.hud_model);
-       setmodel(self.vehicle_viewport, "null");
+       _setmodel(self.vehicle_hudmodel, veh.hud_model);
+       setmodel(self.vehicle_viewport, MDL_Null);
 
        if(veh.head_model != "")
        {
-               setmodel(self.tur_head, veh.head_model);
+               _setmodel(self.tur_head, veh.head_model);
                setattachment(self.tur_head, self, veh.tag_head);
                setattachment(self.vehicle_hudmodel, self.tur_head, veh.tag_hud);
                setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
@@ -1244,7 +1292,8 @@ float vehicle_initialize(float vehicle_id, float nodrop)
        self.pos2 = self.angles;
        self.tur_head.team = self.team;
 
-       VEH_ACTION(vehicle_id, VR_SETUP);
+       Vehicle info = get_vehicleinfo(veh.vehicleid);
+       info.vr_setup(info);
 
        if(self.active == ACTIVE_NOT)
                self.nextthink = 0; // wait until activated
@@ -1254,7 +1303,7 @@ float vehicle_initialize(float vehicle_id, float nodrop)
                self.nextthink = time + game_starttime;
 
        if(MUTATOR_CALLHOOK(VehicleSpawn))
-               return FALSE;
+               return false;
 
-       return TRUE;
+       return true;
 }