]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/vehicles/sv_vehicles.qc
Introduce touch accessors
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / sv_vehicles.qc
index 0748941eafa823b2582d9f9fc86e0ddc7a02f9d3..bfb735197069f74cd86834a98f0c9a14c3dfb340 100644 (file)
@@ -208,7 +208,7 @@ void vehicles_projectile_damage(entity this, entity inflictor, entity attacker,
        {
                this.takedamage = DAMAGE_NO;
                this.event_damage = func_null;
-               this.think = this.use;
+               this.think = adaptor_think2use;
                this.nextthink = time;
        }
 }
@@ -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());
+}
+
 entity vehicles_projectile(entity this, string _mzlfx, Sound _mzlsound,
                                                   vector _org, vector _vel,
                                                   float _dmg, float _radi, float _force,  float _size,
@@ -256,8 +261,8 @@ 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;
@@ -322,7 +327,7 @@ entity vehicle_tossgib(entity this, entity _template, vector _vel, string _tag,
        {
                _gib.think = vehicles_gib_explode;
                _gib.nextthink = time + random() * _explode;
-               _gib.touch = vehicles_gib_explode;
+               settouch(_gib, vehicles_gib_explode);
        }
        else
        {
@@ -473,46 +478,43 @@ void vehicles_showwp_goaway()
 
 void vehicles_showwp()
 {SELFPARAM();
-       entity oldself = world;
        vector rgb;
 
-       if(self.cnt)
+       entity ent = this;
+
+       if(ent.cnt)
        {
-               self.think        = vehicles_return;
-               self.nextthink  = self.cnt;
+               ent.think = 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;
+               ent.think         = 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;
+               ent.think = 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)
@@ -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;
+                       this.think = vehicles_spawn;
+                       this.nextthink = time + 3;
                }
                else
                {
-                       vehicles_setreturn(self);
-                       vehicles_reset_colors(self);
+                       vehicles_setreturn(this);
+                       vehicles_reset_colors(this);
                }
        }
 }
@@ -706,9 +708,9 @@ void vehicles_damage(entity this, entity inflictor, entity attacker, float damag
        {
                if(this.owner)
                        if(this.vehicle_flags & VHF_DEATHEJECT)
-                               WITH(entity, self, this, vehicles_exit(VHEF_EJECT));
+                               WITHSELF(this, vehicles_exit(VHEF_EJECT));
                        else
-                               WITH(entity, self, this, vehicles_exit(VHEF_RELEASE));
+                               WITHSELF(this, vehicles_exit(VHEF_RELEASE));
 
 
                antilag_clear(this, this);
@@ -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;
                }
@@ -953,8 +954,6 @@ bool vehicle_impulse(entity this, int imp)
 
 void vehicles_enter(entity pl, entity veh)
 {
-       entity oldself = self;
-
    // Remove this when bots know how to use vehicles
        if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
                return;
@@ -1083,11 +1082,9 @@ 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));
 }
@@ -1116,7 +1113,7 @@ void vehicles_spawn()
        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
@@ -1213,7 +1210,7 @@ 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;
+       settouch(this, vehicles_touch);
        this.think                                      = vehicles_spawn;
        this.nextthink                          = time;
        this.effects                            = EF_NODRAW;