]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/vehicles/sv_vehicles.qc
Vehicles: always show smoke when low on health, even when empty
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / sv_vehicles.qc
index 73ff86b4bef3d04c253ec25ad3ea92b37bbe8e12..53ed9bf4cc682f0111088d99d02ec18b07042b3e 100644 (file)
@@ -1,5 +1,4 @@
 #include "sv_vehicles.qh"
-#include "../effects/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)
-{SELFPARAM();
+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,8 +87,7 @@ 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);
 }
 
@@ -109,7 +107,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)
+       if(self.lock_target && IS_DEAD(self.lock_target))
        {
                self.lock_target        = world;
                self.lock_strength  = 0;
@@ -133,7 +131,7 @@ void vehicles_locktarget(float incr, float decr, float _lock_time)
                if(SAME_TEAM(trace_ent, self))
                        trace_ent = world;
 
-               if(trace_ent.deadflag != DEAD_NO)
+               if(IS_DEAD(trace_ent))
                        trace_ent = world;
 
                if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent)))
@@ -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,7 +287,7 @@ 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);
@@ -303,7 +301,7 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound,
 
 void vehicles_gib_explode()
 {SELFPARAM();
-       sound (self, CH_SHOTS, W_Sound("rocket_impact"), VOL_BASE, ATTEN_NORM);
+       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);
@@ -322,7 +320,8 @@ entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, b
 {SELFPARAM();
        entity _gib = spawn();
        _setmodel(_gib, _template.model);
-       setorigin(_gib, gettaginfo(self, gettagindex(self, _tag)));
+       vector org = gettaginfo(self, gettagindex(self, _tag));
+       setorigin(_gib, org);
        _gib.velocity = _vel;
        _gib.movetype = MOVETYPE_TOSS;
        _gib.solid = SOLID_CORPSE;
@@ -456,15 +455,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,7 +469,6 @@ void vehicles_clearreturn(entity veh)
 
                        return;
                }
-               ret = ret.chain;
        }
 }
 
@@ -529,7 +525,7 @@ 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)
        {
@@ -549,13 +545,12 @@ 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;
 
-       if(veh.deadflag != DEAD_NO)
+       if(IS_DEAD(veh))
        {
                ret.cnt          = time + veh.respawntime;
                ret.nextthink   = min(time + veh.respawntime, time + veh.respawntime - 5);
@@ -581,7 +576,7 @@ void vehicle_use()
        else
                self.active = ACTIVE_ACTIVE;
 
-       if(self.active == ACTIVE_ACTIVE && self.deadflag == DEAD_NO && !gameover)
+       if(self.active == ACTIVE_ACTIVE && !IS_DEAD(self) && !gameover)
        {
                LOG_TRACE("Respawning vehicle: ", self.netname, "\n");
                if(self.effects & EF_NODRAW)
@@ -627,49 +622,54 @@ void shieldhit_think()
        }
 }
 
-void vehicles_painframe()
-{SELFPARAM();
-       if(self.owner.vehicle_health <= 50)
-       if(self.pain_frame < time)
+void vehicles_painframe(entity this)
+{
+       int myhealth = ((this.owner) ? this.owner.vehicle_health : ((this.vehicle_health / this.max_health) * 100));
+
+       if(myhealth <= 50)
+       if(this.pain_frame < time)
        {
-               float _ftmp;
-               _ftmp = self.owner.vehicle_health / 50;
-               self.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
-               pointparticles(particleeffectnum(EFFECT_SMOKE_SMALL), (self.origin + (randomvec() * 80)), '0 0 0', 1);
+               float _ftmp = myhealth / 50;
+               this.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
+               pointparticles(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
 
-               if(self.vehicle_flags & VHF_DMGSHAKE)
-                       self.velocity += randomvec() * 30;
+               if(this.vehicle_flags & VHF_DMGSHAKE)
+                       this.velocity += randomvec() * 30;
 
-               if(self.vehicle_flags & VHF_DMGROLL)
-                       if(self.vehicle_flags & VHF_DMGHEADROLL)
-                               self.tur_head.angles += randomvec();
+               if(this.vehicle_flags & VHF_DMGROLL)
+                       if(this.vehicle_flags & VHF_DMGHEADROLL)
+                               this.tur_head.angles += randomvec();
                        else
-                               self.angles += randomvec();
-
+                               this.angles += randomvec();
        }
 }
 
+void vehicles_frame(entity this, entity actor)
+{
+       vehicles_painframe(this);
+}
+
 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;
@@ -737,7 +737,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);
        }
 }
@@ -766,7 +767,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");
@@ -781,7 +782,7 @@ vector vehicles_findgoodexit(vector prefer_spot)
        //vector exitspot;
        float mysize;
 
-       tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, prefer_spot, MOVE_NORMAL, self.owner);
+       tracebox(self.origin + '0 0 32', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), prefer_spot, MOVE_NORMAL, self.owner);
        if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
                return prefer_spot;
 
@@ -794,7 +795,7 @@ vector vehicles_findgoodexit(vector prefer_spot)
                v = randomvec();
                v_z = 0;
                v = v2 + normalize(v) * mysize;
-               tracebox(v2, PL_MIN, PL_MAX, v, MOVE_NORMAL, self.owner);
+               tracebox(v2, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, MOVE_NORMAL, self.owner);
                if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
                        return v;
        }
@@ -869,7 +870,7 @@ void vehicles_exit(bool eject)
                        WriteAngle(MSG_ONE, 0);
                }
 
-               setsize(_player, PL_MIN,PL_MAX);
+               setsize(_player, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
 
                _player.takedamage              = DAMAGE_AIM;
                _player.solid                   = SOLID_SLIDEBOX;
@@ -879,10 +880,10 @@ void vehicles_exit(bool eject)
                _player.alpha                   = 1;
                _player.PlayerPhysplug  = func_null;
                _player.vehicle                 = world;
-               _player.view_ofs                = PL_VIEW_OFS;
+               _player.view_ofs                = STAT(PL_VIEW_OFS, NULL);
                _player.event_damage    = PlayerDamage;
                _player.hud                             = HUD_NORMAL;
-               _player.switchweapon    = _vehicle.switchweapon;
+               PS(_player).m_switchweapon = _vehicle.m_switchweapon;
                _player.last_vehiclecheck = time + 3;
                _player.vehicle_enter_delay = time + 2;
 
@@ -890,7 +891,7 @@ void vehicles_exit(bool eject)
        }
        _vehicle.flags |= FL_NOTARGET;
 
-       if(_vehicle.deadflag == DEAD_NO)
+       if(!IS_DEAD(_vehicle))
                _vehicle.avelocity = '0 0 0';
 
        _vehicle.tur_head.nodrawtoclient = world;
@@ -907,7 +908,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;
 
@@ -937,13 +938,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;
        }
@@ -954,17 +957,21 @@ void vehicles_touch()
        vehicles_enter(other, self);
 }
 
-bool vehicle_impulse(int imp)
-{SELFPARAM();
-       switch(imp)
+bool vehicle_impulse(entity this, int imp)
+{
+       entity v = this.vehicle;
+       if (!v) return false;
+       if (IS_DEAD(v)) return false;
+       bool(int) f = v.vehicles_impulse;
+       if (f && f(imp)) return true;
+       switch (imp)
        {
-               case 17:
+               case IMP_weapon_drop.impulse:
                {
                        stuffcmd(self, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
                        return true;
                }
        }
-
        return false;
 }
 
@@ -977,8 +984,8 @@ void vehicles_enter(entity pl, entity veh)
        if((!IS_PLAYER(pl))
        || (veh.phase >= time)
        || (pl.vehicle_enter_delay >= time)
-       || (pl.frozen)
-       || (pl.deadflag != DEAD_NO)
+       || (STAT(FROZEN, pl))
+       || (IS_DEAD(pl))
        || (pl.vehicle)
        ) { return; }
 
@@ -1015,9 +1022,7 @@ void vehicles_enter(entity pl, entity veh)
        if(DIFF_TEAM(pl, veh))
        if(autocvar_g_vehicles_steal)
        {
-               entity head;
-               FOR_EACH_PLAYER(head) if(SAME_TEAM(head, veh))
-                       Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_VEHICLE_STEAL);
+               FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, veh), LAMBDA(Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_VEHICLE_STEAL)));
 
                Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
 
@@ -1044,10 +1049,10 @@ void vehicles_enter(entity pl, entity veh)
 
        veh.vehicle_hudmodel.viewmodelforclient = pl;
 
-       tracebox(pl.origin, PL_MIN, PL_MAX, pl.origin, false, pl);
+       tracebox(pl.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), pl.origin, false, pl);
        pl.crouch = false;
-       pl.view_ofs = PL_VIEW_OFS;
-       setsize (pl, PL_MIN, PL_MAX);
+       pl.view_ofs = STAT(PL_VIEW_OFS, NULL);
+       setsize (pl, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
 
        veh.event_damage        = vehicles_damage;
        veh.nextthink           = 0;
@@ -1062,7 +1067,7 @@ void vehicles_enter(entity pl, entity veh)
        veh.colormap            = pl.colormap;
        if(veh.tur_head)
                veh.tur_head.colormap = pl.colormap;
-       veh.switchweapon = pl.switchweapon;
+       veh.m_switchweapon = PS(pl).m_switchweapon;
        pl.hud = veh.vehicleid;
        pl.PlayerPhysplug = veh.PlayerPhysplug;
 
@@ -1076,8 +1081,8 @@ void vehicles_enter(entity pl, entity veh)
        //veh.exteriormodeltoclient = veh.owner;
        //veh.tur_head.exteriormodeltoclient = veh.owner;
 
-       pl.flags &= ~FL_ONGROUND;
-       veh.flags &= ~FL_ONGROUND;
+       UNSET_ONGROUND(pl);
+       UNSET_ONGROUND(veh);
 
        veh.team = pl.team;
        veh.flags -= FL_NOTARGET;
@@ -1112,8 +1117,9 @@ void vehicles_enter(entity pl, entity veh)
        MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
 
        setself(veh);
-       CSQCModel_UnlinkEntity();
-       VEH_ACTION(veh.vehicleid, VR_ENTER);
+       CSQCModel_UnlinkEntity(veh);
+       Vehicle info = get_vehicleinfo(veh.vehicleid);
+       info.vr_enter(info);
        setself(this);
 
        antilag_clear(pl);
@@ -1126,7 +1132,10 @@ void vehicles_think()
        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);
+
+       vehicles_painframe(self);
 
        CSQCMODEL_AUTOUPDATE(self);
 }
@@ -1170,14 +1179,12 @@ void vehicles_spawn()
        if(self.vehicle_controller)
                self.team = self.vehicle_controller.team;
 
-       entity head; // remove hooks (if any)
-       FOR_EACH_PLAYER(head)
-       if(head.hook.aiment == self)
-               RemoveGrapplingHook(head);
+       FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == self, LAMBDA(RemoveGrapplingHook(it)));
 
        vehicles_reset_colors();
 
-       VEH_ACTION(self.vehicleid, VR_SPAWN);
+       Vehicle info = get_vehicleinfo(self.vehicleid);
+       info.vr_spawn(info);
 
        CSQCMODEL_AUTOINIT(self);
 }
@@ -1190,7 +1197,10 @@ bool vehicle_initialize(entity veh, bool nodrop)
        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 != "")
        {
@@ -1226,9 +1236,9 @@ bool vehicle_initialize(entity veh, bool nodrop)
 
        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;
@@ -1283,7 +1293,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