]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/vehicles/sv_vehicles.qc
Merge branch 'terencehill/hud_smooth_weapon_switch' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / sv_vehicles.qc
index ccda73209095ba3158535e6527623b97933b4aad..6f1d2d91842857a3ff07a26ca8a212a16a154d68 100644 (file)
@@ -208,13 +208,13 @@ void vehicles_projectile_damage(entity this, entity inflictor, entity attacker,
        {
                this.takedamage = DAMAGE_NO;
                this.event_damage = func_null;
-               this.think = this.use;
+               setthink(this, adaptor_think2use);
                this.nextthink = time;
        }
 }
 
-void vehicles_projectile_explode()
-{SELFPARAM();
+void vehicles_projectile_explode(entity this)
+{
        if(self.owner && other != world)
        {
                if(other == self.owner.vehicle)
@@ -224,7 +224,7 @@ void vehicles_projectile_explode()
                        return;
        }
 
-       PROJECTILE_TOUCH;
+       PROJECTILE_TOUCH(this);
 
        self.event_damage = func_null;
        RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, world, self.shot_force, self.totalfrags, other);
@@ -232,6 +232,11 @@ void vehicles_projectile_explode()
        remove (self);
 }
 
+void vehicles_projectile_explode_use(entity this, entity actor, entity trigger)
+{
+       WITHSELF(this, vehicles_projectile_explode(this));
+}
+
 entity vehicles_projectile(entity this, string _mzlfx, Sound _mzlsound,
                                                   vector _org, vector _vel,
                                                   float _dmg, float _radi, float _force,  float _size,
@@ -256,11 +261,11 @@ entity vehicles_projectile(entity this, string _mzlfx, Sound _mzlsound,
        proj.bot_dodge          = true;
        proj.bot_dodgerating  = _dmg;
        proj.velocity            = _vel;
-       proj.touch                      = vehicles_projectile_explode;
-       proj.use                          = vehicles_projectile_explode;
+       settouch(proj, vehicles_projectile_explode);
+       proj.use                          = vehicles_projectile_explode_use;
        proj.owner                      = this;
        proj.realowner          = _owner;
-       proj.think                      = SUB_Remove_self;
+       setthink(proj, SUB_Remove);
        proj.nextthink          = time + 30;
 
        if(_health)
@@ -285,16 +290,16 @@ entity vehicles_projectile(entity this, string _mzlfx, Sound _mzlsound,
        return proj;
 }
 
-void vehicles_gib_explode()
-{SELFPARAM();
+void vehicles_gib_explode(entity this)
+{
        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();
+void vehicles_gib_think(entity this)
+{
        self.alpha -= 0.1;
        if(self.cnt >= time)
                remove(self);
@@ -320,14 +325,14 @@ entity vehicle_tossgib(entity this, entity _template, vector _vel, string _tag,
 
        if(_explode)
        {
-               _gib.think = vehicles_gib_explode;
+               setthink(_gib, vehicles_gib_explode);
                _gib.nextthink = time + random() * _explode;
-               _gib.touch = vehicles_gib_explode;
+               settouch(_gib, vehicles_gib_explode);
        }
        else
        {
                _gib.cnt = time + _maxtime;
-               _gib.think = vehicles_gib_think;
+               setthink(_gib, vehicles_gib_think);
                _gib.nextthink = time + _maxtime - 1;
                _gib.alpha = 1;
        }
@@ -437,7 +442,7 @@ void vehicles_clearreturn(entity veh)
                if(ret.wp00 == veh)
                {
                        ret.classname   = "";
-                       ret.think          = SUB_Remove_self;
+                       setthink(ret, SUB_Remove);
                        ret.nextthink   = time + 0.1;
 
                        if(ret.waypointsprite_attached)
@@ -448,12 +453,12 @@ void vehicles_clearreturn(entity veh)
        }
 }
 
-void vehicles_spawn();
-void vehicles_return()
-{SELFPARAM();
+void vehicles_spawn(entity this);
+void vehicles_return(entity this)
+{
        Send_Effect(EFFECT_TELEPORT, self.wp00.origin + '0 0 64', '0 0 0', 1);
 
-       self.wp00.think  = vehicles_spawn;
+       setthink(self.wp00, vehicles_spawn);
        self.wp00.nextthink = time;
 
        if(self.waypointsprite_attached)
@@ -462,8 +467,8 @@ void vehicles_return()
        remove(self);
 }
 
-void vehicles_showwp_goaway()
-{SELFPARAM();
+void vehicles_showwp_goaway(entity this)
+{
        if(self.waypointsprite_attached)
                WaypointSprite_Kill(self.waypointsprite_attached);
 
@@ -471,48 +476,45 @@ void vehicles_showwp_goaway()
 
 }
 
-void vehicles_showwp()
-{SELFPARAM();
-       entity oldself = world;
+void vehicles_showwp(entity this)
+{
        vector rgb;
 
-       if(self.cnt)
+       entity ent = this;
+
+       if(ent.cnt)
        {
-               self.think        = vehicles_return;
-               self.nextthink  = self.cnt;
+               setthink(ent, vehicles_return);
+               ent.nextthink = ent.cnt;
        }
        else
        {
-               self.think        = vehicles_return;
-               self.nextthink  = time +1;
-
-               oldself = self;
-               setself(spawn());
-               setmodel(self, MDL_Null);
-               self.team = oldself.wp00.team;
-               self.wp00 = oldself.wp00;
-               setorigin(self, oldself.wp00.pos1);
-
-               self.nextthink = time + 5;
-               self.think = vehicles_showwp_goaway;
+               setthink(ent, vehicles_return);
+               ent.nextthink  = time + 1;
+
+               ent = spawn();
+               setmodel(ent, MDL_Null);
+               ent.team = this.wp00.team;
+               ent.wp00 = this.wp00;
+               setorigin(ent, this.wp00.pos1);
+
+               ent.nextthink = time + 5;
+               setthink(ent, vehicles_showwp_goaway);
        }
 
-       if(teamplay && self.team)
-               rgb = Team_ColorRGB(self.team);
+       if(teamplay && ent.team)
+               rgb = Team_ColorRGB(ent.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_Vehicle);
+       entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, ent, '0 0 64', world, 0, ent, waypointsprite_attached, true, RADARICON_Vehicle);
        wp.colormod = rgb;
-       if(self.waypointsprite_attached)
+       if(ent.waypointsprite_attached)
        {
-               WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
+               WaypointSprite_UpdateRule(ent.waypointsprite_attached, ent.wp00.team, SPRITERULE_DEFAULT);
                if(this == NULL)
-                       WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
-               WaypointSprite_Ping(self.waypointsprite_attached);
+                       WaypointSprite_UpdateBuildFinished(ent.waypointsprite_attached, ent.nextthink);
+               WaypointSprite_Ping(ent.waypointsprite_attached);
        }
-
-       if(this)
-               setself(this);
 }
 
 void vehicles_setreturn(entity veh)
@@ -524,7 +526,7 @@ void vehicles_setreturn(entity veh)
        ret = new(vehicle_return);
        ret.wp00           = veh;
        ret.team                = veh.team;
-       ret.think          = vehicles_showwp;
+       setthink(ret, vehicles_showwp);
 
        if(IS_DEAD(veh))
        {
@@ -541,29 +543,29 @@ void vehicles_setreturn(entity veh)
 
 }
 
-void vehicle_use()
-{SELFPARAM();
-       LOG_TRACE("vehicle ",self.netname, " used by ", activator.classname, "\n");
+void vehicle_use(entity this, entity actor, entity trigger)
+{
+       LOG_TRACE("vehicle ",this.netname, " used by ", actor.classname, "\n");
 
-       self.tur_head.team = activator.team;
+       this.tur_head.team = actor.team;
 
-       if(self.tur_head.team == 0)
-               self.active = ACTIVE_NOT;
+       if(this.tur_head.team == 0)
+               this.active = ACTIVE_NOT;
        else
-               self.active = ACTIVE_ACTIVE;
+               this.active = ACTIVE_ACTIVE;
 
-       if(self.active == ACTIVE_ACTIVE && !IS_DEAD(self) && !gameover)
+       if(this.active == ACTIVE_ACTIVE && !IS_DEAD(this) && !gameover)
        {
-               LOG_TRACE("Respawning vehicle: ", self.netname, "\n");
-               if(self.effects & EF_NODRAW)
+               LOG_TRACE("Respawning vehicle: ", this.netname, "\n");
+               if(this.effects & EF_NODRAW)
                {
-                       self.think = vehicles_spawn;
-                       self.nextthink = time + 3;
+                       setthink(this, vehicles_spawn);
+                       this.nextthink = time + 3;
                }
                else
                {
-                       vehicles_setreturn(self);
-                       vehicles_reset_colors(self);
+                       vehicles_setreturn(this);
+                       vehicles_reset_colors(this);
                }
        }
 }
@@ -583,8 +585,8 @@ void vehicles_regen(entity this, float timer, .float regen_field, float field_ma
        }
 }
 
-void shieldhit_think()
-{SELFPARAM();
+void shieldhit_think(entity this)
+{
        self.alpha -= 0.1;
        if (self.alpha <= 0)
        {
@@ -663,7 +665,7 @@ void vehicles_damage(entity this, entity inflictor, entity attacker, float damag
                        setattachment(this.vehicle_shieldent, this, "");
                        setorigin(this.vehicle_shieldent, real_origin(this) - this.origin);
                        this.vehicle_shieldent.scale       = 256 / vlen(this.maxs - this.mins);
-                       this.vehicle_shieldent.think       = shieldhit_think;
+                       setthink(this.vehicle_shieldent, shieldhit_think);
                }
 
                this.vehicle_shieldent.colormod = '1 1 1';
@@ -820,7 +822,6 @@ void vehicles_exit(bool eject)
                if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
                {
                        _vehicle.vehicle_exit(eject);
-                       setself(this);
                        vehicles_exit_running = false;
                        return;
                }
@@ -900,8 +901,8 @@ void vehicles_exit(bool eject)
        vehicles_exit_running = false;
 }
 
-void vehicles_touch()
-{SELFPARAM();
+void vehicles_touch(entity this)
+{
        if(MUTATOR_CALLHOOK(VehicleTouch, self, other))
                return;
 
@@ -953,9 +954,6 @@ bool vehicle_impulse(entity this, int imp)
 
 void vehicles_enter(entity pl, entity veh)
 {
-    SELFPARAM();
-       entity oldself = self;
-
    // Remove this when bots know how to use vehicles
        if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
                return;
@@ -1084,17 +1082,15 @@ void vehicles_enter(entity pl, entity veh)
 
        MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
 
-       setself(veh);
        CSQCModel_UnlinkEntity(veh);
        Vehicle info = Vehicles_from(veh.vehicleid);
-       info.vr_enter(info, veh);
-       setself(oldself);
+       WITHSELF(veh, info.vr_enter(info, veh));
 
        antilag_clear(pl, CS(pl));
 }
 
-void vehicles_think()
-{SELFPARAM();
+void vehicles_think(entity this)
+{
        self.nextthink = time;
 
        if(self.owner)
@@ -1109,15 +1105,15 @@ void vehicles_think()
 }
 
 // initialization
-void vehicles_spawn()
-{SELFPARAM();
+void vehicles_spawn(entity this)
+{
        LOG_TRACE("Spawning vehicle: ", self.classname, "\n");
 
        // disown & reset
        self.vehicle_hudmodel.viewmodelforclient = self;
 
        self.owner                              = world;
-       self.touch                              = vehicles_touch;
+       settouch(self, vehicles_touch);
        self.event_damage               = vehicles_damage;
        self.iscreature                 = true;
        self.teleportable               = false; // no teleporting for vehicles, too buggy
@@ -1130,7 +1126,7 @@ void vehicles_spawn()
        self.flags                              = FL_NOTARGET;
        self.avelocity                  = '0 0 0';
        self.velocity                   = '0 0 0';
-       self.think                              = vehicles_think;
+       setthink(self, vehicles_think);
        self.nextthink                  = time;
 
        // Reset locking
@@ -1165,6 +1161,9 @@ bool vehicle_initialize(entity this, Vehicle info, bool nodrop)
        if(!info.vehicleid)
                return false;
 
+       if(!this.tur_head)
+               info.vr_precache(info);
+
        if(this.targetname && this.targetname != "")
        {
                this.vehicle_controller = find(world, target, this.targetname);
@@ -1211,8 +1210,8 @@ bool vehicle_initialize(entity this, Vehicle info, bool nodrop)
        this.vehicleid                          = info.vehicleid;
        this.PlayerPhysplug                     = info.PlayerPhysplug;
        this.event_damage                       = func_null;
-       this.touch                                      = vehicles_touch;
-       this.think                                      = vehicles_spawn;
+       settouch(this, vehicles_touch);
+       setthink(this, vehicles_spawn);
        this.nextthink                          = time;
        this.effects                            = EF_NODRAW;
        this.dphitcontentsmask          = DPCONTENTS_BODY | DPCONTENTS_SOLID;