]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/vehicles/sv_vehicles.qc
Impulses: migration pathway
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / sv_vehicles.qc
index d55f797443a96baa60cff7591a60b09566d0f6f0..a2cbbb7e2cb362276df61b03d15d19d65809857b 100644 (file)
@@ -1,5 +1,4 @@
 #include "sv_vehicles.qh"
-#include "../effects.qh"
 
 #if 0
 bool vehicle_send(entity to, int sf)
@@ -38,10 +37,10 @@ bool vehicle_send(entity to, int sf)
 }
 #endif
 
-bool SendAuxiliaryXhair(entity to, int sf)
+bool SendAuxiliaryXhair(entity this, entity to, int sf)
 {
 
-       WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
+       WriteHeader(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
 
        WriteByte(MSG_ENTITY, self.cnt);
 
@@ -88,13 +87,12 @@ void CSQCVehicleSetup(entity own, int vehicle_id)
 
        msg_entity = own;
 
-       WriteByte(MSG_ONE, SVC_TEMPENTITY);
-       WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
+       WriteHeader(MSG_ONE, TE_CSQC_VEHICLESETUP);
        WriteByte(MSG_ONE, vehicle_id);
 }
 
 vector targetdrone_getnewspot()
-{
+{SELFPARAM();
        vector spot;
        int i;
        for(i = 0; i < 100; ++i)
@@ -108,7 +106,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;
@@ -181,7 +179,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);
@@ -193,7 +191,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;
@@ -214,7 +212,7 @@ vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float
 
 // projectile handling
 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;
@@ -231,7 +229,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)
@@ -254,7 +252,7 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound,
                                                   float _dmg, float _radi, float _force,  float _size,
                                                   int _deahtype, float _projtype, float _health,
                                                   bool _cull, bool _clianim, entity _owner)
-{
+{SELFPARAM();
        entity proj;
 
        proj = spawn();
@@ -276,7 +274,7 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound,
        proj.use                          = vehicles_projectile_explode;
        proj.owner                      = self;
        proj.realowner          = _owner;
-       proj.think                      = SUB_Remove;
+       proj.think                      = SUB_Remove_self;
        proj.nextthink          = time + 30;
 
        if(_health)
@@ -289,10 +287,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)
-               Send_Effect(_mzlfx, proj.origin, proj.velocity, 1);
+               Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
 
        setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
 
@@ -302,15 +300,15 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound,
 }
 
 void vehicles_gib_explode()
-{
-       sound (self, CH_SHOTS, W_Sound("rocket_impact"), VOL_BASE, ATTEN_NORM);
-       Send_Effect("explosion_small", randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
-       Send_Effect("explosion_small", self.wp00.origin + '0 0 64', '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);
@@ -319,9 +317,9 @@ void vehicles_gib_think()
 }
 
 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;
@@ -369,8 +367,8 @@ bool 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, "");
@@ -397,7 +395,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;
@@ -456,15 +454,13 @@ void vehicles_reset_colors()
 
 void vehicles_clearreturn(entity veh)
 {
-       entity ret;
        // Remove "return helper", if any.
-       ret = findchain(classname, "vehicle_return");
-       while(ret)
+       for (entity ret = findchain(classname, "vehicle_return"); ret; ret = ret.chain)
        {
                if(ret.wp00 == veh)
                {
                        ret.classname   = "";
-                       ret.think          = SUB_Remove;
+                       ret.think          = SUB_Remove_self;
                        ret.nextthink   = time + 0.1;
 
                        if(ret.waypointsprite_attached)
@@ -472,14 +468,13 @@ void vehicles_clearreturn(entity veh)
 
                        return;
                }
-               ret = ret.chain;
        }
 }
 
 void vehicles_spawn();
 void vehicles_return()
-{
-       Send_Effect("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;
@@ -491,7 +486,7 @@ void vehicles_return()
 }
 
 void vehicles_showwp_goaway()
-{
+{SELFPARAM();
        if(self.waypointsprite_attached)
                WaypointSprite_Kill(self.waypointsprite_attached);
 
@@ -500,7 +495,7 @@ void vehicles_showwp_goaway()
 }
 
 void vehicles_showwp()
-{
+{SELFPARAM();
        entity oldself = world;
        vector rgb;
 
@@ -515,8 +510,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);
@@ -529,18 +524,18 @@ void vehicles_showwp()
                rgb = Team_ColorRGB(self.team);
        else
                rgb = '1 1 1';
-       entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_POWERUP);
+       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)
@@ -549,8 +544,7 @@ void vehicles_setreturn(entity veh)
 
        vehicles_clearreturn(veh);
 
-       ret = spawn();
-       ret.classname   = "vehicle_return";
+       ret = new(vehicle_return);
        ret.wp00           = veh;
        ret.team                = veh.team;
        ret.think          = vehicles_showwp;
@@ -565,14 +559,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;
 
@@ -583,7 +577,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;
@@ -598,26 +592,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;
        }
@@ -628,14 +622,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(EFFECT_SMOKE_SMALL, (self.origin + (randomvec() * 80)), '0 0 0', 1);
 
                if(self.vehicle_flags & VHF_DMGSHAKE)
                        self.velocity += randomvec() * 30;
@@ -650,26 +644,26 @@ void vehicles_painframe()
 }
 
 void vehicles_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
-{
+{SELFPARAM();
        self.dmg_time = time;
 
        // WEAPONTODO
-       if(DEATH_ISWEAPON(deathtype, WEP_VORTEX.m_id))
+       if(DEATH_ISWEAPON(deathtype, WEP_VORTEX))
                damage *= autocvar_g_vehicles_vortex_damagerate;
 
-       if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN.m_id))
+       if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
                damage *= autocvar_g_vehicles_machinegun_damagerate;
 
-       if(DEATH_ISWEAPON(deathtype, WEP_RIFLE.m_id))
+       if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
                damage *= autocvar_g_vehicles_rifle_damagerate;
 
-       if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER.m_id))
+       if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
                damage *= autocvar_g_vehicles_vaporizer_damagerate;
 
-       if(DEATH_ISWEAPON(deathtype, WEP_SEEKER.m_id))
+       if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
                damage *= autocvar_g_vehicles_tag_damagerate;
 
-       if(DEATH_WEAPONOFWEAPONDEATH(deathtype))
+       if(DEATH_WEAPONOF(deathtype) != WEP_Null)
                damage *= autocvar_g_vehicles_weapon_damagerate;
 
        self.enemy = attacker;
@@ -683,7 +677,7 @@ void vehicles_damage(entity inflictor, entity attacker, float damage, int deatht
                        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);
@@ -737,7 +731,8 @@ void vehicles_damage(entity inflictor, entity attacker, float damage, int deatht
 
                antilag_clear(self);
 
-               VEH_ACTION(self.vehicleid, VR_DEATH);
+               Vehicle info = get_vehicleinfo(self.vehicleid);
+               info.vr_death(info);
                vehicles_setreturn(self);
        }
 }
@@ -754,7 +749,7 @@ float vehicles_crushable(entity e)
 }
 
 void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
-{
+{SELFPARAM();
        if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
                return;
 
@@ -766,7 +761,7 @@ void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
                if(_minspeed < wc)
                {
                        float take = min(_speedfac * wc, _maxpain);
-                       Damage (self, world, world, take, DEATH_FALL, self.origin, '0 0 0');
+                       Damage (self, world, world, take, DEATH_FALL.m_id, self.origin, '0 0 0');
                        self.play_time = time + 0.25;
 
                        //dprint("wc: ", ftos(wc), "\n");
@@ -777,7 +772,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;
 
@@ -825,14 +820,13 @@ vector vehicles_findgoodexit(vector prefer_spot)
 }
 
 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;
        }
 
@@ -844,7 +838,7 @@ void vehicles_exit(bool eject)
                if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
                {
                        _vehicle.vehicle_exit(eject);
-                       self = _oldself;
+                       setself(this);
                        vehicles_exit_running = false;
                        return;
                }
@@ -854,7 +848,7 @@ void vehicles_exit(bool eject)
 
        _player = _vehicle.owner;
 
-       self = _vehicle;
+       setself(_vehicle);
 
        if (_player)
        {
@@ -908,7 +902,7 @@ void vehicles_exit(bool eject)
 
        _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;
 
@@ -918,15 +912,14 @@ void vehicles_exit(bool eject)
        vehicles_reset_colors();
        _vehicle.owner = world;
 
-       CSQCMODEL_AUTOINIT();
-
-       self = _oldself;
+       CSQCMODEL_AUTOINIT(self);
 
+       setself(this);
        vehicles_exit_running = false;
 }
 
 void vehicles_touch()
-{
+{SELFPARAM();
        if(MUTATOR_CALLHOOK(VehicleTouch, self, other))
                return;
 
@@ -939,13 +932,15 @@ void vehicles_touch()
                if(vehicles_crushable(other))
                {
                        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);
+                               Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_VH_CRUSH.m_id, '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;
        }
@@ -956,9 +951,14 @@ void vehicles_touch()
        vehicles_enter(other, self);
 }
 
-bool vehicle_impulse(int imp)
+bool vehicle_impulse(entity this, int imp)
 {
-       switch(imp)
+       entity v = this.vehicle;
+       if (!v) return false;
+       if (v.deadflag != DEAD_NO) return false;
+       bool(int) f = v.vehicles_impulse;
+       if (f && f(imp)) return true;
+       switch (imp)
        {
                case 17:
                {
@@ -966,12 +966,11 @@ bool vehicle_impulse(int imp)
                        return true;
                }
        }
-
        return false;
 }
 
 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;
@@ -988,8 +987,7 @@ void vehicles_enter(entity pl, entity veh)
        if(veh.vehicle_flags & VHF_MULTISLOT)
        if(veh.owner)
        {
-               entity oldself = self;
-               self = veh;
+               setself(veh);
                other = pl; // TODO: fix
 
                if(!veh.gunner1)
@@ -997,7 +995,7 @@ void vehicles_enter(entity pl, entity veh)
                if(veh.gun1.vehicle_enter)
                if(veh.gun1.vehicle_enter())
                {
-                       self = oldself;
+                       setself(this);
                        return;
                }
 
@@ -1006,11 +1004,11 @@ void vehicles_enter(entity pl, entity veh)
                if(veh.gun2.vehicle_enter)
                if(veh.gun2.vehicle_enter())
                {
-                       self = oldself;
+                       setself(this);
                        return;
                }
 
-               self = oldself;
+               setself(this);
        }
 
        if(teamplay)
@@ -1114,31 +1112,32 @@ void vehicles_enter(entity pl, entity veh)
 
        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);
+       Vehicle info = get_vehicleinfo(self.vehicleid);
+       info.vr_think(info);
 
-       CSQCMODEL_AUTOUPDATE();
+       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;
@@ -1169,7 +1168,7 @@ void vehicles_spawn()
        self.angles = self.pos2;
        setorigin(self, self.pos1);
        // Show it
-       Send_Effect("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;
@@ -1181,20 +1180,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);
 }
 
 bool vehicle_initialize(entity veh, bool nodrop)
-{
+{SELFPARAM();
        if(!autocvar_g_vehicles)
                return false;
 
        if(!veh.vehicleid)
                return false;
 
-       if(!veh.tur_head) { VEH_ACTION(veh.vehicleid, VR_PRECACHE); }
+       if(!veh.tur_head) {
+               Vehicle info = get_vehicleinfo(veh.vehicleid);
+               info.vr_precache(info);
+       }
 
        if(self.targetname && self.targetname != "")
        {
@@ -1224,15 +1227,15 @@ bool vehicle_initialize(entity veh, bool nodrop)
                self.team = 0;
 
        if(self.mdl == "" || !self.mdl)
-               setmodel(self, veh.model);
+               _setmodel(self, veh.model);
        else
-               setmodel(self, self.mdl);
+               _setmodel(self, self.mdl);
 
        self.vehicle_flags |= VHF_ISVEHICLE;
 
-       self.vehicle_viewport           = spawn();
-       self.vehicle_hudmodel           = spawn();
-       self.tur_head                           = spawn();
+       self.vehicle_viewport           = new(vehicle_viewport);
+       self.vehicle_hudmodel           = new(vehicle_hudmodel);
+       self.tur_head                           = new(tur_head);
        self.tur_head.owner                     = self;
        self.takedamage                         = DAMAGE_NO;
        self.bot_attack                         = true;
@@ -1257,12 +1260,12 @@ bool vehicle_initialize(entity veh, bool 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);
@@ -1287,7 +1290,8 @@ bool vehicle_initialize(entity veh, bool nodrop)
        self.pos2 = self.angles;
        self.tur_head.team = self.team;
 
-       VEH_ACTION(veh.vehicleid, VR_SETUP);
+       Vehicle info = get_vehicleinfo(veh.vehicleid);
+       info.vr_setup(info);
 
        if(self.active == ACTIVE_NOT)
                self.nextthink = 0; // wait until activated