Replace all direct assignments to self with setself(e)
authorTimePath <andrew.hardaker1995@gmail.com>
Mon, 31 Aug 2015 02:23:43 +0000 (12:23 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Mon, 31 Aug 2015 02:24:14 +0000 (12:24 +1000)
78 files changed:
qcsrc/client/damage.qc
qcsrc/client/hud.qc
qcsrc/client/rubble.qc
qcsrc/client/scoreboard.qc
qcsrc/client/view.qc
qcsrc/common/minigames/cl_minigames_hud.qc
qcsrc/common/minigames/sv_minigames.qc
qcsrc/common/monsters/spawn.qc
qcsrc/common/monsters/sv_monsters.qc
qcsrc/common/movetypes/movetypes.qc
qcsrc/common/movetypes/push.qc
qcsrc/common/mutators/mutator/itemstime.qc
qcsrc/common/triggers/func/door.qc
qcsrc/common/triggers/func/train.qc
qcsrc/common/triggers/misc/laser.qc
qcsrc/common/triggers/platforms.qc
qcsrc/common/triggers/subs.qc
qcsrc/common/triggers/subs.qh
qcsrc/common/triggers/target/music.qc
qcsrc/common/triggers/target/spawn.qc
qcsrc/common/triggers/teleporters.qc
qcsrc/common/triggers/trigger/jumppads.qc
qcsrc/common/triggers/trigger/keylock.qc
qcsrc/common/triggers/trigger/magicear.qc
qcsrc/common/triggers/trigger/relay_activators.qc
qcsrc/common/triggers/trigger/teleport.qc
qcsrc/common/triggers/triggers.qc
qcsrc/common/turrets/sv_turrets.qc
qcsrc/common/turrets/targettrigger.qc
qcsrc/common/turrets/unit/phaser.qc
qcsrc/common/util-post.qh
qcsrc/common/vehicles/sv_vehicles.qc
qcsrc/common/vehicles/unit/bumblebee.qc
qcsrc/common/vehicles/unit/racer.qc
qcsrc/common/vehicles/unit/raptor.qc
qcsrc/common/vehicles/unit/spiderbot.qc
qcsrc/common/weapons/weapon/arc.qc
qcsrc/common/weapons/weapon/blaster.qc
qcsrc/common/weapons/weapon/minelayer.qc
qcsrc/common/weapons/weapon/porto.qc
qcsrc/common/weapons/weapon/seeker.qc
qcsrc/common/weapons/weapon/tuba.qc
qcsrc/csqcmodellib/cl_player.qc
qcsrc/server/anticheat.qc
qcsrc/server/bot/bot.qc
qcsrc/server/cheats.qc
qcsrc/server/cl_client.qc
qcsrc/server/cl_player.qc
qcsrc/server/command/sv_cmd.qc
qcsrc/server/command/vote.qc
qcsrc/server/g_damage.qc
qcsrc/server/g_world.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/mutators/events.qh
qcsrc/server/mutators/gamemode_assault.qc
qcsrc/server/mutators/gamemode_ca.qc
qcsrc/server/mutators/gamemode_ctf.qc
qcsrc/server/mutators/gamemode_domination.qc
qcsrc/server/mutators/gamemode_freezetag.qc
qcsrc/server/mutators/gamemode_lms.qc
qcsrc/server/mutators/gamemode_nexball.qc
qcsrc/server/mutators/gamemode_onslaught.qc
qcsrc/server/mutators/gamemode_tdm.qc
qcsrc/server/mutators/mutator_buffs.qc
qcsrc/server/mutators/mutator_instagib.qc
qcsrc/server/mutators/mutator_overkill.qc
qcsrc/server/mutators/mutator_superspec.qc
qcsrc/server/mutators/sandbox.qc
qcsrc/server/race.qc
qcsrc/server/spawnpoints.qc
qcsrc/server/sv_main.qc
qcsrc/server/t_items.qc
qcsrc/server/weapons/common.qc
qcsrc/server/weapons/selection.qc
qcsrc/server/weapons/spawning.qc
qcsrc/server/weapons/throwing.qc
qcsrc/server/weapons/weaponsystem.qc
qcsrc/warpzonelib/server.qc

index 8cb410d..5d5de15 100644 (file)
@@ -159,8 +159,9 @@ void Ent_DamageInfo(float isNew)
        else
                forcemul = 1;
 
-       for(self = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); self; self = self.chain)
+       for(entity e = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); e; e = e.chain)
        {
+               setself(e);
                // attached ents suck
                if(self.tag_entity)
                        continue;
@@ -211,8 +212,7 @@ void Ent_DamageInfo(float isNew)
                if(self.isplayermodel)
                        hitplayer = true; // this impact damaged a player
        }
-
-       self = oldself;
+       setself(oldself);
 
        if(DEATH_ISVEHICLE(w_deathtype))
        {
index cbef453..9a0f87b 100644 (file)
@@ -413,7 +413,7 @@ void HUD_Weapons(void)
                weapon_cnt = 0;
                for(i = WEP_FIRST; i <= WEP_LAST; ++i)
                {
-                       self = get_weaponinfo(i);
+                       setself(get_weaponinfo(i));
                        if(self.impulse >= 0)
                        {
                                weaponorder[weapon_cnt] = self;
@@ -673,7 +673,7 @@ void HUD_Weapons(void)
        for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
        {
                // retrieve information about the current weapon to be drawn
-               self = weaponorder[i];
+               setself(weaponorder[i]);
                weapon_id = self.impulse;
                isCurrent = (self.weapon == switchweapon);
 
index 11f5476..8035fd7 100644 (file)
@@ -6,12 +6,9 @@ void RubbleLimit(string cname, float limit, void() deleteproc)
 {SELFPARAM();
        entity e;
        entity oldest;
-       entity oldself;
        float c;
        float oldesttime;
 
-       oldself = self;
-
        // remove rubble of the same type if it's at the limit
        // remove multiple rubble if the limit has been decreased
        while(1)
@@ -42,9 +39,8 @@ void RubbleLimit(string cname, float limit, void() deleteproc)
                        break;
 
                // delete this oldest one and search again
-               self = oldest;
-               deleteproc();
-               self = oldself;
+               SELFCALL(oldest, deleteproc());
+               SELFCALL_DONE();
        }
 }
 
index 7d2a425..407c087 100644 (file)
@@ -984,7 +984,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
        int disownedcnt = 0;
        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
        {
-               self = get_weaponinfo(i);
+               setself(get_weaponinfo(i));
                if(!self.weapon)
                        continue;
 
@@ -1052,7 +1052,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
        int column;
        for(i = WEP_FIRST, column = 0; i <= WEP_LAST; ++i)
        {
-               self = get_weaponinfo(i);
+               setself(get_weaponinfo(i));
                if (!self.weapon)
                        continue;
                weapon_stats = weapon_accuracy[i-WEP_FIRST];
index 3039c04..f53dbd6 100644 (file)
@@ -1466,11 +1466,10 @@ void CSQC_UpdateView(float w, float h)
           mousepos = mousepos*0.5 + getmousepos();
         */
 
-       e = self;
-       for(self = world; (self = nextent(self)); )
-               if(self.draw)
-                       self.draw();
-       self = e;
+       for(entity e = NULL; (e = nextent(e)); ) if (e.draw) {
+               SELFCALL(e, e.draw());
+               SELFCALL_DONE();
+       }
 
        addentities(MASK_NORMAL | MASK_ENGINE | MASK_ENGINEVIEWMODELS);
        renderscene();
@@ -1805,11 +1804,10 @@ void CSQC_UpdateView(float w, float h)
          } else */
 
        // draw 2D entities
-       e = self;
-       for(self = world; (self = nextent(self)); )
-               if(self.draw2d)
-                       self.draw2d();
-       self = e;
+       for (entity e = NULL; (e = nextent(e)); ) if (e.draw2d) {
+               SELFCALL(e, e.draw2d());
+               SELFCALL_DONE();
+       }
        Draw_ShowNames_All();
 
        scoreboard_active = HUD_WouldDrawScoreboard();
index 9ad706d..cedb98b 100644 (file)
@@ -107,10 +107,8 @@ void HUD_MinigameMenu_Click(entity menuitem)
 {SELFPARAM();
        if ( menuitem )
        {
-               entity e = self;
-               self = menuitem;
-               menuitem.use();
-               self = e;
+               SELFCALL(menuitem, menuitem.use());
+               SELFCALL_DONE();
        }
 }
 
index db4209d..95619a2 100644 (file)
@@ -150,10 +150,8 @@ int minigame_addplayer(entity minigame_session, entity player)
 
                if ( !IS_OBSERVER(player) && autocvar_sv_minigames_observer )
                {
-                       entity e = self;
-                       self = player;
-                       PutObserverInServer();
-                       self = e;
+                       SELFCALL(player, PutObserverInServer());
+                       SELFCALL_DONE();
                }
                if ( autocvar_sv_minigames_observer == 2 )
                        player.team_forced = -1;
index 2ed974b..9e9810b 100644 (file)
@@ -64,10 +64,8 @@ entity spawnmonster (string monster, float monster_id, entity spawnedby, entity
        }
        
        // Monster_Spawn checks if monster is valid
-       entity oldself = self;
-       self = e;
-       Monster_Spawn(monster_id);
-       self = oldself;
+       SELFCALL(e, Monster_Spawn(monster_id));
+       SELFCALL_DONE();
 
        return e;
 }
index 17bb1ba..124fb7e 100644 (file)
@@ -47,7 +47,7 @@ void monster_dropitem()
 
        if(e && e.monster_loot)
        {
-               self = e;
+               setself(e);
                e.noalign = true;
                e.monster_loot();
                e.gravity = 1;
@@ -58,7 +58,7 @@ void monster_dropitem()
                e.item_spawnshieldtime = time + 0.7;
                e.classname = "droppedweapon"; // use weapon handling to remove it on touch
                SUB_SetFade(e, time + autocvar_g_monsters_drop_time, 1);
-               self = oldself;
+               setself(oldself);
        }
 }
 
@@ -198,7 +198,7 @@ void monster_changeteam(entity ent, float newteam)
 void Monster_Delay_Action()
 {SELFPARAM();
        entity oldself = self;
-       self = self.owner;
+       setself(self.owner);
        if(Monster_ValidTarget(self, self.enemy)) { oldself.use(); }
 
        if(oldself.cnt > 0)
index 74716dd..b3158b5 100644 (file)
@@ -322,7 +322,6 @@ void _Movetype_CheckWaterTransition(entity ent)  // SV_CheckWaterTransition
 
 void _Movetype_Impact(entity oth)  // SV_Impact
 {SELFPARAM();
-       entity oldself = self;
        entity oldother = other;
 
        if(self.move_touch)
@@ -337,11 +336,10 @@ void _Movetype_Impact(entity oth)  // SV_Impact
        if(oth.move_touch)
        {
                other = self;
-               self = oth;
 
-               self.move_touch();
+               SELFCALL(oth, oth.move_touch());
+               SELFCALL_DONE();
 
-               self = oldself;
                other = oldother;
        }
 }
@@ -355,7 +353,7 @@ void _Movetype_LinkEdict_TouchAreaGrid()  // SV_LinkEdict_TouchAreaGrid
        {
                if(e.move_touch && boxesoverlap(e.absmin, e.absmax, oldself.absmin, oldself.absmax))
                {
-                       self = e;
+                       setself(e);
                        other = oldself;
 
                        trace_allsolid = false;
@@ -373,7 +371,7 @@ void _Movetype_LinkEdict_TouchAreaGrid()  // SV_LinkEdict_TouchAreaGrid
        }
 
        other = oldother;
-       self = oldself;
+       setself(oldself);
 }
 
 void _Movetype_LinkEdict(bool touch_triggers)  // SV_LinkEdict
index 506edb5..29ac255 100644 (file)
@@ -93,26 +93,22 @@ void _Movetype_PushMove(float dt)  // SV_PushMove
                        if (check.move_movetype == 32)  // MOVETYPE_PHYSICS
                        {
                                check.move_origin = check.move_origin + move;
-                               entity oldself = self;
-                               self = check;
-                               _Movetype_LinkEdict(true);
-                               self = oldself;
+                               SELFCALL(check, _Movetype_LinkEdict(true));
+                               SELFCALL_DONE();
                                continue;
                        }
 
                        // try moving the contacted entity
                        self.solid = SOLID_NOT;
-                       entity oldself = self;
-                       self = check;
-                       if (!_Movetype_PushEntity(move, true))
+                       bool flag = SELFCALL(check, _Movetype_PushEntity(move, true));
+                       SELFCALL_DONE();
+                       if (!flag)
                        {
-                               self = oldself;
                                // entity "check" got teleported
                                check.move_angles_y += trace_fraction * moveangle.y;
                                self.solid = savesolid;
                                continue;  // pushed enough
                        }
-                       self = oldself;
                        // FIXME: turn players specially
                        check.move_angles_y += trace_fraction * moveangle.y;
                        self.solid = savesolid;
index ad6228d..d7ca5a3 100644 (file)
@@ -154,9 +154,10 @@ MUTATOR_HOOKFUNCTION(itemstime, reset_map_global)
     Item_ItemsTime_ResetTimes();
     // ALL the times need to be reset before .reset()ing each item
     // since Item_Reset schedules respawn of superweapons and powerups
-    for (self = world; (self = nextent(self)); )
-    if (IS_NOT_A_CLIENT(self))
+    for (entity e = NULL; (e = nextent(e)); )
+    if (IS_NOT_A_CLIENT(e))
     {
+        setself(e);
         if (self.reset)
             Item_ItemsTime_SetTime(self, 0);
     }
index 9688214..12e3c4d 100644 (file)
@@ -236,9 +236,9 @@ void door_fire()
                                {
                                        door_rotating_go_down ();
                                }
-                               self = self.enemy;
+                               setself(self.enemy);
                        } while ( (self != starte) && (self != world) );
-                       self = oself;
+                       setself(oself);
                        return;
                }
        }
@@ -265,29 +265,24 @@ void door_fire()
                                door_rotating_go_up ();
                        }
                }
-               self = self.enemy;
+               setself(self.enemy);
        } while ( (self != starte) && (self != world) );
-       self = oself;
+       setself(oself);
 }
 
 void door_use()
 {SELFPARAM();
-       entity oself;
-
        //dprint("door_use (model: ");dprint(self.model);dprint(")\n");
 
        if (self.owner)
        {
-               oself = self;
-               self = self.owner;
-               door_fire ();
-               self = oself;
+               SELFCALL(self.owner, door_fire());
+               SELFCALL_DONE();
        }
 }
 
 void door_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
 {SELFPARAM();
-       entity oself;
        if(self.spawnflags & DOOR_NOSPLASH)
                if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
                        return;
@@ -301,12 +296,10 @@ void door_damage(entity inflictor, entity attacker, float damage, int deathtype,
 
        if (self.health <= 0)
        {
-               oself = self;
-               self = self.owner;
-               self.health = self.max_health;
-               self.takedamage = DAMAGE_NO;    // wil be reset upon return
-               door_use ();
-               self = oself;
+               self.owner.health = self.owner.max_health;
+               self.owner.takedamage = DAMAGE_NO;      // wil be reset upon return
+               SELFCALL(self.owner, door_use());
+               SELFCALL_DONE();
        }
 }
 
@@ -465,7 +458,7 @@ void door_trigger_touch()
 
        activator = other;
 
-       self = self.owner;
+       setself(self.owner);
        door_use ();
 }
 
index f6059f7..d06efdd 100644 (file)
@@ -2,11 +2,8 @@
 void() train_next;
 void train_wait()
 {SELFPARAM();
-       entity oldself;
-       oldself = self;
-       self = self.enemy;
-       SUB_UseTargets();
-       self = oldself;
+       SELFCALL(self.enemy, SUB_UseTargets());
+       SELFCALL_DONE();
        self.enemy = world;
 
        // if turning is enabled, the train will turn toward the next point while waiting
index 5dde1b4..1961214 100644 (file)
@@ -59,7 +59,6 @@ void misc_laser_init()
 void misc_laser_think()
 {SELFPARAM();
        vector o;
-       entity oldself;
        entity hitent;
        vector hitloc;
 
@@ -98,11 +97,9 @@ void misc_laser_think()
                        {
                                self.count = 1;
 
-                               oldself = self;
-                               self = self.enemy;
-                               activator = self.pusher;
-                               SUB_UseTargets();
-                               self = oldself;
+                               activator = self.enemy.pusher;
+                               SELFCALL(self.enemy, SUB_UseTargets());
+                               SELFCALL_DONE();
                        }
                }
                else
@@ -111,11 +108,9 @@ void misc_laser_think()
                        {
                                self.count = 0;
 
-                               oldself = self;
-                               self = self.enemy;
-                               activator = self.pusher;
-                               SUB_UseTargets();
-                               self = oldself;
+                               activator = self.enemy.pusher;
+                               SELFCALL(self.enemy, SUB_UseTargets());
+                               SELFCALL_DONE();
                        }
                }
        }
index bf18419..b4f3874 100644 (file)
@@ -107,7 +107,7 @@ void plat_center_touch()
                return;
 #endif
 
-       self = self.enemy;
+       setself(self.enemy);
        if (self.state == 2)
                plat_go_up ();
        else if (self.state == 1)
@@ -127,7 +127,7 @@ void plat_outside_touch()
                return;
 #endif
 
-       self = self.enemy;
+       setself(self.enemy);
        if (self.state == 1)
                plat_go_down ();
 }
index 0fa48b8..f70108e 100644 (file)
@@ -144,7 +144,7 @@ void SUB_CalcMove_controller_think (void)
                // derivative: delta + 2 * delta2 (e.g. for angle positioning)
                oldself = self;
                self.owner.SUB_THINK = self.think1;
-               self = self.owner;
+               setself(self.owner);
                remove(oldself);
                self.SUB_THINK();
        }
@@ -238,9 +238,9 @@ void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeedtype, float
        self.SUB_NEXTTHINK = self.SUB_LTIME + traveltime;
 
        // invoke controller
-       self = controller;
+       setself(controller);
        self.think();
-       self = self.owner;
+       setself(self.owner);
 }
 
 void SUB_CalcMove (vector tdest, float tspeedtype, float tspeed, void() func)
@@ -294,14 +294,8 @@ void SUB_CalcMove (vector tdest, float tspeedtype, float tspeed, void() func)
 
 void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeedtype, float tspeed, void() func)
 {SELFPARAM();
-       entity  oldself;
-
-       oldself = self;
-       self = ent;
-
-       SUB_CalcMove (tdest, tspeedtype, tspeed, func);
-
-       self = oldself;
+       SELFCALL(ent, SUB_CalcMove (tdest, tspeedtype, tspeed, func));
+       SELFCALL_DONE();
 }
 
 /*
@@ -369,12 +363,6 @@ void SUB_CalcAngleMove (vector destangle, float tspeedtype, float tspeed, void()
 
 void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeedtype, float tspeed, void() func)
 {SELFPARAM();
-       entity  oldself;
-
-       oldself = self;
-       self = ent;
-
-       SUB_CalcAngleMove (destangle, tspeedtype, tspeed, func);
-
-       self = oldself;
+       SELFCALL(ent, SUB_CalcAngleMove (destangle, tspeedtype, tspeed, func));
+       SELFCALL_DONE();
 }
index b9ae06f..ec9eb76 100644 (file)
        void SUB_SETORIGIN(entity s, vector v)
        {SELFPARAM();
                s.move_origin = v;
-               entity oldself = self;
-               self = s;
-               _Movetype_LinkEdict(true);
-               self = oldself;
+               SELFCALL(s, _Movetype_LinkEdict(true));
+               SELFCALL_DONE();
        }
 
 #endif
index 091603d..488ed09 100644 (file)
@@ -59,8 +59,9 @@ void spawnfunc_target_music()
 }
 void TargetMusic_RestoreGame()
 {SELFPARAM();
-       for(self = world; (self = find(self, classname, "target_music")); )
+       for(entity e = world; (e = find(e, classname, "target_music")); )
        {
+               setself(e);
                if(self.targetname == "")
                        target_music_sendto(MSG_INIT, 1);
                else
index 020e404..38eabba 100644 (file)
@@ -38,7 +38,6 @@ void target_spawn_edit_entity(entity e, string msg, entity kt, entity t2, entity
        string key, value, valuefield, valueoffset, valueoffsetrandom;
        entity valueent;
        vector data, data2;
-       entity oldself;
        entity oldactivator;
 
        n = tokenize_console(msg);
@@ -220,15 +219,11 @@ void target_spawn_edit_entity(entity e, string msg, entity kt, entity t2, entity
                                value = strcat("target_spawn_helper", value);
                        putentityfieldstring(target_spawn_spawnfunc_field, e, value);
 
-                       oldself = self;
                        oldactivator = activator;
 
-                       self = e;
                        activator = act;
-
-                       self.target_spawn_spawnfunc();
-
-                       self = oldself;
+                       SELFCALL(e, e.target_spawn_spawnfunc());
+                       SELFCALL_DONE();
                        activator = oldactivator;
 
                        // We called an external function, so we have to re-tokenize msg.
index 7d76b3f..4b3861b 100644 (file)
@@ -229,10 +229,8 @@ void WarpZone_PostTeleportPlayer_Callback(entity pl)
        Reset_ArcBeam(pl, v_forward);
        UpdateCSQCProjectileAfterTeleport(pl);
        {
-               entity oldself = self;
-               self = pl;
-               anticheat_fixangle();
-               self = oldself;
+               SELFCALL(pl, anticheat_fixangle());
+               SELFCALL_DONE();
        }
        // "disown" projectiles after teleport
        if(pl.owner)
index 31bd98e..52a8798 100644 (file)
@@ -218,12 +218,9 @@ void trigger_push_touch()
 
        if(self.enemy.target)
        {
-               entity oldself;
-               oldself = self;
                activator = other;
-               self = self.enemy;
-               SUB_UseTargets();
-               self = oldself;
+               SELFCALL(self.enemy, SUB_UseTargets());
+               SELFCALL_DONE();
        }
 
        if (other.flags & FL_PROJECTILE)
index 8d6d174..1c2bd70 100644 (file)
@@ -11,13 +11,13 @@ void trigger_keylock_trigger(string s)
        for(t = world; (t = find(t, targetname, s)); )
                if(t.use)
                {
-                       self = t;
+                       setself(t);
                        other = stemp;
                        activator = atemp;
                        self.use();
                }
 
-       self = stemp;
+       setself(stemp);
        other = otemp;
        activator = atemp;
 }
index 7ca8587..0c8a7d3 100644 (file)
@@ -5,7 +5,6 @@ string trigger_magicear_processmessage(entity ear, entity source, float teamsay,
 {SELFPARAM();
        float domatch, dotrigger, matchstart, l;
        string s, msg;
-       entity oldself;
        string savemessage;
 
        magicear_matched = false;
@@ -29,14 +28,13 @@ string trigger_magicear_processmessage(entity ear, entity source, float teamsay,
 
                if(dotrigger)
                {
-                       oldself = self;
                        activator = source;
-                       self = ear;
+                       setself(ear);
                        savemessage = self.message;
                        self.message = string_null;
                        SUB_UseTargets();
                        self.message = savemessage;
-                       self = oldself;
+                       setself(this);
                }
 
                if(ear.netname != "")
@@ -120,14 +118,13 @@ string trigger_magicear_processmessage(entity ear, entity source, float teamsay,
 
        if(dotrigger)
        {
-               oldself = self;
                activator = source;
-               self = ear;
+               setself(ear);
                savemessage = self.message;
                self.message = string_null;
                SUB_UseTargets();
                self.message = savemessage;
-               self = oldself;
+               setself(this);
        }
 
        if(ear.spawnflags & 16)
index e25253b..b765151 100644 (file)
@@ -1,28 +1,24 @@
 #ifdef SVQC
 void relay_activators_use()
 {SELFPARAM();
-       entity trg, os;
-
-       os = self;
-
-       for(trg = world; (trg = find(trg, targetname, os.target)); )
+       for(entity trg = world; (trg = find(trg, targetname, this.target)); )
        {
-               self = trg;
+               setself(trg);
                if (trg.setactive)
-                       trg.setactive(os.cnt);
+                       trg.setactive(this.cnt);
                else
                {
                        //bprint("Not using setactive\n");
-                       if(os.cnt == ACTIVE_TOGGLE)
+                       if(this.cnt == ACTIVE_TOGGLE)
                                if(trg.active == ACTIVE_ACTIVE)
                                        trg.active = ACTIVE_NOT;
                                else
                                        trg.active = ACTIVE_ACTIVE;
                        else
-                               trg.active = os.cnt;
+                               trg.active = this.cnt;
                }
        }
-       self = os;
+       setself(this);
 }
 
 void spawnfunc_relay_activate()
index 5adc150..36c4cd2 100644 (file)
@@ -10,7 +10,6 @@ void trigger_teleport_use()
 
 void Teleport_Touch (void)
 {SELFPARAM();
-       entity oldself;
        string s;
 
        if (self.active != ACTIVE_ACTIVE)
@@ -38,18 +37,15 @@ void Teleport_Touch (void)
        if(IS_PLAYER(other))
                RemoveGrapplingHook(other);
 
-       entity e;
-       e = Simple_TeleportPlayer(self, other);
+       entity e = Simple_TeleportPlayer(self, other);
 
        activator = other;
        s = self.target; self.target = string_null;
        SUB_UseTargets();
        if (!self.target) self.target = s;
 
-       oldself = self;
-       self = e;
-       SUB_UseTargets();
-       self = oldself;
+       SELFCALL(e, SUB_UseTargets());
+       SELFCALL_DONE();
 }
 
 void spawnfunc_trigger_teleport()
index 09c9fcd..bd67c14 100644 (file)
@@ -223,7 +223,7 @@ void SUB_UseTargets()
                                {
                                        if (t.classname == "func_clientwall" || t.classname == "func_clientillusionary")
                                                t.antiwall_flag = aw_flag;
-                                       self = t;
+                                       setself(t);
                                        other = stemp;
                                        activator = act;
                                        self.use();
@@ -234,14 +234,14 @@ void SUB_UseTargets()
 
        if(stemp.target_random && RandomSelection_chosen_ent)
        {
-               self = RandomSelection_chosen_ent;
+               setself(RandomSelection_chosen_ent);
                other = stemp;
                activator = act;
                self.use();
        }
 
        activator = act;
-       self = stemp;
+       setself(stemp);
        other = otemp;
 }
 
index a551ddd..d03ee2a 100644 (file)
@@ -498,7 +498,7 @@ void turret_do_updates(entity t_turret)
        entity oldself;
 
        oldself = self;
-       self = t_turret;
+       setself(t_turret);
 
        enemy_pos = real_origin(self.enemy);
 
@@ -527,7 +527,7 @@ void turret_do_updates(entity t_turret)
        self.tur_impactent                       = trace_ent;
        self.tur_impacttime                     = vlen(self.tur_shotorg - trace_endpos) / self.shot_speed;
 
-       self = oldself;
+       setself(oldself);
 }
 
 /**
index 21e45a5..98c23c4 100644 (file)
@@ -5,15 +5,14 @@ void turret_targettrigger_touch()
 {SELFPARAM();
     entity e;
     if (self.cnt > time) return;
-    entity oldself;
-    oldself = self;
+    entity oldself = this;
 
     e = find(world, targetname, self.target);
     while (e)
     {
         if (e.turret_flags & TUR_FLAG_RECIEVETARGETS)
         {
-            self = e;
+            setself(e);
             if(e.turret_addtarget)
                 e.turret_addtarget(other,oldself);
         }
@@ -23,7 +22,7 @@ void turret_targettrigger_touch()
 
     oldself.cnt = time + 0.5;
 
-    self = oldself;
+    setself(this);
 }
 
 /*QUAKED turret_targettrigger (.5 .5 .5) ?
index cbb0707..d188e99 100644 (file)
@@ -45,7 +45,7 @@ void beam_think()
     self.owner.attack_finished_single = time + frametime;
     entity oldself;
     oldself = self;
-    self = self.owner;
+    setself(self.owner);
     FireImoBeam (   self.tur_shotorg,
                     self.tur_shotorg + self.tur_shotdir_updated * self.target_range,
                     '-1 -1 -1' * self.shot_radius,
@@ -54,7 +54,7 @@ void beam_think()
                     oldself.shot_dmg,
                     0.75,
                     DEATH_TURRET_PHASER);
-    self = oldself;
+    setself(oldself);
     self.scale = vlen(self.owner.tur_shotorg - trace_endpos) / 256;
 
 }
index afec8ed..2789e12 100644 (file)
@@ -6,6 +6,7 @@
 // Step 1: auto oldself
 #if 1
 #define SELFPARAM() noref entity this = __self
+#define setself(s) (__self = s)
 #define self __self
 #define SELFCALL(s, f) (__self = s, f)
 #define SELFCALL_DONE() (__self = this)
@@ -14,6 +15,7 @@
 // Step 2: check SELFPARAM() is present for functions that use self
 #if 0
 #define SELFPARAM() [[alias("__self")]] noref entity this = __self
+#define setself(s) (__self = s)
 #define self this
 #define SELFCALL(s, f) (this = s, f)
 #define SELFCALL_DONE() (this = this)
index 894e063..0ed648f 100644 (file)
@@ -515,7 +515,7 @@ void vehicles_showwp()
                self.nextthink  = time +1;
 
                oldself = self;
-               self = spawn();
+               setself(spawn());
                setmodel(self, "null");
                self.team = oldself.wp00.team;
                self.wp00 = oldself.wp00;
@@ -540,7 +540,7 @@ void vehicles_showwp()
        }
 
        if(oldself != world)
-               self = oldself;
+               setself(oldself);
 }
 
 void vehicles_setreturn(entity veh)
@@ -844,7 +844,7 @@ void vehicles_exit(bool eject)
                if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
                {
                        _vehicle.vehicle_exit(eject);
-                       self = _oldself;
+                       setself(_oldself);
                        vehicles_exit_running = false;
                        return;
                }
@@ -854,7 +854,7 @@ void vehicles_exit(bool eject)
 
        _player = _vehicle.owner;
 
-       self = _vehicle;
+       setself(_vehicle);
 
        if (_player)
        {
@@ -920,8 +920,7 @@ void vehicles_exit(bool eject)
 
        CSQCMODEL_AUTOINIT(self);
 
-       self = _oldself;
-
+       setself(_oldself);
        vehicles_exit_running = false;
 }
 
@@ -989,7 +988,7 @@ void vehicles_enter(entity pl, entity veh)
        if(veh.owner)
        {
                entity oldself = self;
-               self = veh;
+               setself(veh);
                other = pl; // TODO: fix
 
                if(!veh.gunner1)
@@ -997,7 +996,7 @@ void vehicles_enter(entity pl, entity veh)
                if(veh.gun1.vehicle_enter)
                if(veh.gun1.vehicle_enter())
                {
-                       self = oldself;
+                       setself(oldself);
                        return;
                }
 
@@ -1006,11 +1005,11 @@ void vehicles_enter(entity pl, entity veh)
                if(veh.gun2.vehicle_enter)
                if(veh.gun2.vehicle_enter())
                {
-                       self = oldself;
+                       setself(oldself);
                        return;
                }
 
-               self = oldself;
+               setself(oldself);
        }
 
        if(teamplay)
@@ -1115,10 +1114,10 @@ void vehicles_enter(entity pl, entity veh)
        MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
 
        entity oldself = self;
-       self = veh;
+       setself(veh);
        CSQCModel_UnlinkEntity();
        VEH_ACTION(veh.vehicleid, VR_ENTER);
-       self = oldself;
+       setself(oldself);
 
        antilag_clear(pl);
 }
index 0bb776b..d88e3df 100644 (file)
@@ -115,7 +115,7 @@ float bumblebee_gunner_frame()
        entity vehic    = self.vehicle.owner;
        entity gun      = self.vehicle;
        entity gunner   = self;
-       self = vehic;
+       setself(vehic);
 
        vehic.solid = SOLID_NOT;
        //setorigin(gunner, vehic.origin);
@@ -216,7 +216,7 @@ float bumblebee_gunner_frame()
        gunner.BUTTON_ATCK = gunner.BUTTON_ATCK2 = gunner.BUTTON_CROUCH = 0;
        gunner.vehicle_energy = (gun.vehicle_energy / autocvar_g_vehicle_bumblebee_cannon_ammo) * 100;
 
-       self = gunner;
+       setself(gunner);
        return 1;
 }
 
@@ -440,11 +440,11 @@ float bumblebee_pilot_frame()
 
        pilot = self;
        vehic = self.vehicle;
-       self   = vehic;
+       setself(vehic);
 
        if(vehic.deadflag != DEAD_NO)
        {
-               self = pilot;
+               setself(pilot);
                pilot.BUTTON_ATCK = pilot.BUTTON_ATCK2 = 0;
                return 1;
        }
@@ -643,7 +643,7 @@ float bumblebee_pilot_frame()
        setorigin(pilot, vehic.origin + v_up * 48 + v_forward * 160);
 
        pilot.BUTTON_ATCK = pilot.BUTTON_ATCK2 = pilot.BUTTON_CROUCH = 0;
-       self = pilot;
+       setself(pilot);
 
        return 1;
 }
@@ -804,11 +804,11 @@ float v_bumblebee(float req)
                                entity oldself = self;
                                if(self.gunner1)
                                {
-                                       self = self.gunner1;
+                                       setself(self.gunner1);
                                        oldself.gun1.vehicle_exit(VHEF_EJECT);
                                        entity oldother = other;
                                        other = self;
-                                       self = oldself;
+                                       setself(oldself);
                                        self.phase = 0;
                                        self.touch();
                                        other = oldother;
@@ -817,11 +817,11 @@ float v_bumblebee(float req)
 
                                if(self.gunner2)
                                {
-                                       self = self.gunner2;
+                                       setself(self.gunner2);
                                        oldself.gun2.vehicle_exit(VHEF_EJECT);
                                        entity oldother = other;
                                        other = self;
-                                       self = oldself;
+                                       setself(oldself);
                                        self.phase = 0;
                                        self.touch();
                                        other = oldother;
@@ -843,16 +843,16 @@ float v_bumblebee(float req)
 
                        if(self.gunner1)
                        {
-                               self = self.gunner1;
+                               setself(self.gunner1);
                                oldself.gun1.vehicle_exit(VHEF_EJECT);
-                               self = oldself;
+                               setself(oldself);
                        }
 
                        if(self.gunner2)
                        {
-                               self = self.gunner2;
+                               setself(self.gunner2);
                                oldself.gun2.vehicle_exit(VHEF_EJECT);
-                               self = oldself;
+                               setself(oldself);
                        }
 
                        self.vehicle_exit(VHEF_EJECT);
index 1320d95..40dbfec 100644 (file)
@@ -324,7 +324,7 @@ float racer_frame()
 
        player  = self;
        racer   = self.vehicle;
-       self    = racer;
+       setself(racer);
 
        vehicles_painframe();
 
@@ -333,7 +333,7 @@ float racer_frame()
 
        if(racer.deadflag != DEAD_NO)
        {
-               self = player;
+               setself(player);
                player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
                return 1;
        }
@@ -545,7 +545,7 @@ float racer_frame()
        setorigin(player,racer.origin + '0 0 32');
        player.velocity = racer.velocity;
 
-       self = player;
+       setself(player);
        return 1;
 }
 
index 14da2b3..263da16 100644 (file)
@@ -320,7 +320,7 @@ float raptor_frame()
 
        player = self;
        raptor = self.vehicle;
-       self   = raptor;
+       setself(raptor);
 
        vehicles_painframe();
        /*
@@ -349,7 +349,7 @@ float raptor_frame()
 
        if(raptor.deadflag != DEAD_NO)
        {
-               self = player;
+               setself(player);
                player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
                return 1;
        }
@@ -642,7 +642,7 @@ float raptor_frame()
 
        player.BUTTON_ATCK = player.BUTTON_ATCK2 = player.BUTTON_CROUCH = 0;
 
-       self = player;
+       setself(player);
        return 1;
 }
 
@@ -652,7 +652,7 @@ float raptor_takeoff()
 
        player = self;
        raptor = self.vehicle;
-       self   = raptor;
+       setself(raptor);
 
        self.nextthink = time;
        CSQCMODEL_AUTOUPDATE(self);
@@ -698,7 +698,7 @@ float raptor_takeoff()
                VEHICLE_UPDATE_PLAYER(player, shield, raptor);
 
        player.BUTTON_ATCK = player.BUTTON_ATCK2 = player.BUTTON_CROUCH = 0;
-       self = player;
+       setself(player);
        return 1;
 }
 
index b08d1de..7060b78 100644 (file)
@@ -347,7 +347,7 @@ float spiderbot_frame()
 
        player = self;
        spider = self.vehicle;
-       self   = spider;
+       setself(spider);
 
        vehicles_painframe();
 
@@ -547,7 +547,7 @@ float spiderbot_frame()
                        vector v;
                        spider.misc_bulletcounter += 1;
 
-                       self = player;
+                       setself(player);
 
                        gun = (spider.misc_bulletcounter % 2) ? spider.gun1 : spider.gun2;
 
@@ -562,7 +562,7 @@ float spiderbot_frame()
                        //trailparticles(self, _particleeffectnum("spiderbot_minigun_trail"), v, trace_endpos);
                        pointparticles(particleeffectnum(EFFECT_SPIDERBOT_MINIGUN_MUZZLEFLASH), v, v_forward * 2500, 1);
 
-                       self = spider;
+                       setself(spider);
 
                        spider.vehicle_ammo1 -= autocvar_g_vehicle_spiderbot_minigun_ammo_cost;
                        spider.tur_head.attack_finished_single = time + autocvar_g_vehicle_spiderbot_minigun_refire;
@@ -607,7 +607,7 @@ float spiderbot_frame()
        if(self.vehicle_flags & VHF_HASSHIELD)
                VEHICLE_UPDATE_PLAYER(player, shield, spiderbot);
 
-       self = player;
+       setself(player);
        return 1;
 }
 
index 6548f08..5202090 100644 (file)
@@ -273,14 +273,14 @@ void W_Arc_Beam_Think(void)
 
                if(self == self.owner.arc_beam) { self.owner.arc_beam = world; }
                entity oldself = self;
-               self = self.owner;
+               setself(self.owner);
                if(!WEP_ACTION(WEP_ARC.m_id, WR_CHECKAMMO1) && !WEP_ACTION(WEP_ARC.m_id, WR_CHECKAMMO2))
                if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
                {
                        // note: this doesn't force the switch
                        W_SwitchToOtherWeapon(self);
                }
-               self = oldself;
+               setself(oldself);
                remove(self);
                return;
        }
@@ -593,10 +593,8 @@ void W_Arc_Beam(float burst)
        beam.beam_bursting = burst;
        Net_LinkEntity(beam, false, 0, W_Arc_Beam_Send);
 
-       entity oldself = self;
-       self = beam;
-       self.think();
-       self = oldself;
+       SELFCALL(beam, beam.think());
+       SELFCALL_DONE();
 }
 
 void Arc_Smoke()
index 9debcac..5c7fd8d 100644 (file)
@@ -141,11 +141,8 @@ void W_Blaster_Attack(
 
        if(time >= missile.nextthink)
        {
-               entity oldself;
-               oldself = self;
-               self = missile;
-               self.think();
-               self = oldself;
+               SELFCALL(missile, missile.think());
+               SELFCALL_DONE();
        }
 }
 bool W_Blaster(int request)
index 0524a13..7d65561 100644 (file)
@@ -100,7 +100,7 @@ void W_MineLayer_Stick(entity to)
        newmine.flags = self.flags;
 
        remove(self);
-       self = newmine;
+       setself(newmine);
 
        if(to)
                SetMovetypeFollow(self, to);
@@ -122,16 +122,14 @@ void W_MineLayer_Explode(void)
 
        if(self.realowner.weapon == WEP_MINE_LAYER.m_id)
        {
-               entity oldself;
-               oldself = self;
-               self = self.realowner;
+               setself(self.realowner);
                if(!WEP_ACTION(WEP_MINE_LAYER.m_id, WR_CHECKAMMO1))
                {
                        self.cnt = WEP_MINE_LAYER.m_id;
                        ATTACK_FINISHED(self) = time;
                        self.switchweapon = w_getbestweapon(self);
                }
-               self = oldself;
+               setself(this);
        }
        self.realowner.minelayer_mines -= 1;
        remove(self);
@@ -149,16 +147,14 @@ void W_MineLayer_DoRemoteExplode(void)
 
        if(self.realowner.weapon == WEP_MINE_LAYER.m_id)
        {
-               entity oldself;
-               oldself = self;
-               self = self.realowner;
+               setself(self.realowner);
                if(!WEP_ACTION(WEP_MINE_LAYER.m_id, WR_CHECKAMMO1))
                {
                        self.cnt = WEP_MINE_LAYER.m_id;
                        ATTACK_FINISHED(self) = time;
                        self.switchweapon = w_getbestweapon(self);
                }
-               self = oldself;
+               setself(this);
        }
        self.realowner.minelayer_mines -= 1;
        remove(self);
index 3903e08..bb47951 100644 (file)
@@ -95,11 +95,8 @@ void W_Porto_Remove(entity p)
 {SELFPARAM();
        if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
        {
-               entity oldself;
-               oldself = self;
-               self = p.porto_current;
-               W_Porto_Fail(1);
-               self = oldself;
+               SELFCALL(p.porto_current, W_Porto_Fail(1));
+               SELFCALL_DONE();
        }
 }
 
index 9708af0..eaba831 100644 (file)
@@ -426,7 +426,7 @@ void W_Seeker_Vollycontroller_Think(void) // TODO: Merge this with W_Seeker_Atta
        self.nextthink = time + WEP_CVAR(seeker, missile_delay) * W_WeaponRateFactor();
 
        oldself = self;
-       self = self.realowner;
+       setself(self.realowner);
 
        oldenemy = self.enemy;
        self.enemy = oldself.enemy;
@@ -450,7 +450,7 @@ void W_Seeker_Vollycontroller_Think(void) // TODO: Merge this with W_Seeker_Atta
        }
 
        self.enemy = oldenemy;
-       self = oldself;
+       setself(oldself);
 }
 
 void W_Seeker_Tracker_Think(void)
index 9baa0c6..05787ba 100644 (file)
@@ -336,10 +336,8 @@ void W_Tuba_NoteOn(float hittype)
        {
                if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument)
                {
-                       entity oldself = self;
-                       self = self.tuba_note;
-                       W_Tuba_NoteOff();
-                       self = oldself;
+                       SELFCALL(self.tuba_note, W_Tuba_NoteOff());
+                       SELFCALL_DONE();
                }
        }
 
@@ -406,10 +404,8 @@ bool W_Tuba(int req)
                        {
                                if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
                                {
-                                       entity oldself = self;
-                                       self = self.tuba_note;
-                                       W_Tuba_NoteOff();
-                                       self = oldself;
+                                       SELFCALL(self.tuba_note, W_Tuba_NoteOff());
+                                       SELFCALL_DONE();
                                }
                        }
 
index 945a27b..da10d10 100644 (file)
@@ -220,9 +220,8 @@ void CSQCPlayer_SetCamera()
 
        if(csqcplayer)
        {
-               entity oldself;
-               oldself = self;
-               self = csqcplayer;
+               entity oldself = self;
+               setself(csqcplayer);
 
                if(servercommandframe == 0 || clientcommandframe == 0)
                {
@@ -299,7 +298,7 @@ void CSQCPlayer_SetCamera()
                // relink
                setorigin(self, self.origin);
 
-               self = oldself;
+               setself(oldself);
        }
 
        entity view;
@@ -307,11 +306,9 @@ void CSQCPlayer_SetCamera()
 
        if(view && view != csqcplayer)
        {
-               entity oldself = self;
-               self = view;
-               InterpolateOrigin_Do();
+               SELFCALL(view, InterpolateOrigin_Do());
                self.view_ofs = '0 0 1' * getstati(STAT_VIEWHEIGHT);
-               self = oldself;
+               SELFCALL_DONE();
        }
 
        if(view)
index f795a1a..370ef84 100644 (file)
@@ -234,11 +234,12 @@ void anticheat_fixangle()
 
 void anticheat_endframe()
 {SELFPARAM();
-       entity oldself = self;
-       FOR_EACH_CLIENT(self)
-               if (self.fixangle)
-                       anticheat_fixangle();
-       self = oldself;
+       entity e;
+       FOR_EACH_CLIENT(e)
+               if (e.fixangle) {
+                       SELFCALL(e, anticheat_fixangle());
+                       SELFCALL_DONE();
+               }
        anticheat_div0_evade_evasion_delta += frametime * (0.5 + random());
 }
 
index 2a7081c..a6762c7 100644 (file)
 
 entity bot_spawn()
 {SELFPARAM();
-       entity oldself, bot;
-       bot = spawnclient();
+       entity bot = spawnclient();
        if (bot)
        {
                currentbots = currentbots + 1;
-               oldself = self;
-               self = bot;
+               setself(bot);
                bot_setnameandstuff();
                ClientConnect();
                PutClientInServer();
-               self = oldself;
+               setself(this);
        }
        return bot;
 }
index 62e968e..9981749 100644 (file)
@@ -373,10 +373,8 @@ float CheatCommand(float argc)
                                                e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
                                                e.angles = AnglesTransform_ApplyToAngles(e.angles, '-90 0 0'); // so unrotated models work
                                        }
-                                       oldself = self;
-                                       self = e;
-                                       spawnfunc_func_breakable();
-                                       self = oldself;
+                                       SELFCALL(e, spawnfunc_func_breakable());
+                                       SELFCALL_DONE();
                                        // now, is it valid?
                                        if(f == 0)
                                        {
@@ -698,29 +696,29 @@ float CheatCommand(float argc)
                case "usetarget":
                        IS_CHEAT(0, argc, 0);
                        e = self;
-                       self = spawn();
+                       setself(spawn());
                        self.target = argv(1);
                        activator = e;
                        SUB_UseTargets();
                        remove(self);
-                       self = e;
+                       setself(e);
                        DID_CHEAT();
                        break;
                case "killtarget":
                        IS_CHEAT(0, argc, 0);
                        e = self;
-                       self = spawn();
+                       setself(spawn());
                        self.killtarget = argv(1);
                        activator = e;
                        SUB_UseTargets();
                        remove(self);
-                       self = e;
+                       setself(e);
                        DID_CHEAT();
                        break;
                case "teleporttotarget":
                        IS_CHEAT(0, argc, 0);
                        e = self;
-                       self = spawn();
+                       setself(spawn());
                        setorigin(self, self.origin);
                        self.classname = "cheattriggerteleport";
                        self.target = argv(1);
@@ -729,11 +727,11 @@ float CheatCommand(float argc)
                        {
                                Simple_TeleportPlayer(self, e);
                                remove(self);
-                               self = e;
+                               setself(e);
                                DID_CHEAT();
                        }
                        else
-                               self = e;
+                               setself(e);
                        break;
        }
 
index 0cb1e49..80d7aad 100644 (file)
@@ -432,7 +432,7 @@ void PutClientInServer()
 
        if(IS_PLAYER(self))
        {
-               entity spot, oldself;
+               entity spot;
 
                accuracy_resend(self);
 
@@ -628,16 +628,13 @@ void PutClientInServer()
                                self.(weapon_load[j]) = e.reloading_ammo;
                }
 
-               oldself = self;
-               self = spot;
-                       activator = oldself;
-                               string s;
-                               s = self.target;
-                               self.target = string_null;
-                               SUB_UseTargets();
-                               self.target = s;
-                       activator = world;
-               self = oldself;
+               string s = spot.target;
+               spot.target = string_null;
+               activator = self;
+               SELFCALL(spot, SUB_UseTargets());
+               SELFCALL_DONE();
+               activator = world;
+               spot.target = s;
 
                Unfreeze(self);
 
@@ -734,17 +731,13 @@ void ClientInit_CheckUpdate()
 
 void ClientInit_Spawn()
 {SELFPARAM();
-       entity o;
-       entity e;
-       e = spawn();
+       entity e = spawn();
        e.classname = "clientinit";
        e.think = ClientInit_CheckUpdate;
        Net_LinkEntity(e, false, 0, ClientInit_SendEntity);
 
-       o = self;
-       self = e;
-       ClientInit_CheckUpdate();
-       self = o;
+       SELFCALL(e, ClientInit_CheckUpdate());
+       SELFCALL_DONE();
 }
 
 /*
@@ -854,7 +847,7 @@ void KillIndicator_Think()
 
        if(self.cnt <= 0)
        {
-               self = self.owner;
+               setself(self.owner);
                ClientKill_Now(); // no oldself needed
                return;
        }
@@ -1268,10 +1261,8 @@ void ClientConnect (void)
                sv_notice_join();
 
        for (entity e = world; (e = findfloat(e, init_for_player_needed, 1)); ) {
-               entity oldself = self;
-               self = e;
-               e.init_for_player(oldself);
-               self = oldself;
+               SELFCALL(e, e.init_for_player(this));
+               SELFCALL_DONE();
        }
 
        MUTATOR_CALLHOOK(ClientConnect, self);
@@ -2626,15 +2617,15 @@ void PlayerPreThink (void)
        {
                self.teamkill_soundtime = 0;
 
-               entity oldpusher, oldself;
-
-               oldself = self; self = self.teamkill_soundsource;
-               oldpusher = self.pusher; self.pusher = oldself;
+               entity oldself = self;
+               setself(self.teamkill_soundsource);
+               entity oldpusher = self.pusher;
+               self.pusher = oldself;
 
                PlayerSound(playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
 
                self.pusher = oldpusher;
-               self = oldself;
+               setself(oldself);
        }
 
        if(self.taunt_soundtime)
index 6f7c8c2..4c35cbb 100644 (file)
@@ -44,7 +44,7 @@ void CopyBody(float keepvelocity)
        if (self.effects & EF_NODRAW)
                return;
        oldself = self;
-       self = spawn();
+       setself(spawn());
        self.enemy = oldself;
        self.lip = oldself.lip;
        self.colormap = oldself.colormap;
@@ -114,7 +114,7 @@ void CopyBody(float keepvelocity)
        animdecide_load_if_needed(self);
        animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
 
-       self = oldself;
+       setself(oldself);
 }
 
 float player_getspecies()
index 136977d..6c3d4c6 100644 (file)
@@ -207,10 +207,10 @@ void GameCommand_allspec(float request, float argc)
 
                        FOR_EACH_REALPLAYER(client)
                        {
-                               self = client;
-                               if(self.caplayer)
-                                       self.caplayer = 0;
-                               PutObserverInServer();
+                               if (client.caplayer)
+                                       client.caplayer = 0;
+                               SELFCALL(client, PutObserverInServer());
+                               SELFCALL_DONE();
                                ++i;
                        }
                        if(i) { bprint(strcat("Successfully forced all (", ftos(i), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n")); }
@@ -240,8 +240,8 @@ void GameCommand_anticheat(float request, float argc)
 
                        if(accepted > 0)
                        {
-                               self = client;
-                               anticheat_report();
+                               SELFCALL(client, anticheat_report());
+                               SELFCALL_DONE();
                                return;
                        }
                        else
@@ -1039,10 +1039,10 @@ void GameCommand_moveplayer(float request, float argc)
                                        {
                                                if(!IS_SPEC(client) && !IS_OBSERVER(client))
                                                {
-                                                       self = client;
-                                                       if(self.caplayer)
-                                                               self.caplayer = 0;
-                                                       PutObserverInServer();
+                                                       if (client.caplayer)
+                                                               client.caplayer = 0;
+                                                       SELFCALL(client, PutObserverInServer());
+                                                       SELFCALL_DONE();
 
                                                        successful = strcat(successful, (successful ? ", " : ""), client.netname);
                                                }
@@ -1194,8 +1194,8 @@ void GameCommand_playerdemo(float request, float argc)
                                                        return;
                                                }
 
-                                               self = client;
-                                               playerdemo_open_read(argv(next_token));
+                                               SELFCALL(client, playerdemo_open_read(argv(next_token)));
+                                               SELFCALL_DONE();
                                                return;
                                        }
 
@@ -1210,8 +1210,8 @@ void GameCommand_playerdemo(float request, float argc)
                                                        return;
                                                }
 
-                                               self = client;
-                                               playerdemo_open_write(argv(next_token));
+                                               SELFCALL(client, playerdemo_open_write(argv(next_token)));
+                                               SELFCALL_DONE();
                                                return;
                                        }
 
@@ -1409,7 +1409,7 @@ void GameCommand_shuffleteams(float request)
                                                                continue; // not a player, move on to next random slot
 
                                                        if(VerifyClientNumber(shuffleteams_players[z]))
-                                                               self = edict_num(shuffleteams_players[z]);
+                                                               setself(edict_num(shuffleteams_players[z]));
 
                                                        if(self.team != team_color)
                                                                MoveToTeam(self, team_color, 6);
index 4d6c6ae..bd0b086 100644 (file)
@@ -349,51 +349,60 @@ void VoteThink()
 // Resets the state of all clients, items, weapons, waypoints, ... of the map.
 void reset_map(float dorespawn)
 {SELFPARAM();
-       entity oldself;
-       oldself = self;
 
        if(time <= game_starttime && round_handler_IsActive())
                round_handler_Reset(game_starttime);
 
        MUTATOR_CALLHOOK(reset_map_global);
 
-       for(self = world; (self = nextent(self)); )
-       if(IS_NOT_A_CLIENT(self))
+       for(entity e = world; (e = nextent(e)); )
        {
-               if(self.reset)
+               setself(e);
+               if(IS_NOT_A_CLIENT(self))
                {
-                       self.reset();
-                       continue;
-               }
+                       if(self.reset)
+                       {
+                               self.reset();
+                               continue;
+                       }
 
-               if(self.team_saved)
-                       self.team = self.team_saved;
+                       if(self.team_saved)
+                               self.team = self.team_saved;
 
-               if(self.flags & FL_PROJECTILE) // remove any projectiles left
-                       remove(self);
+                       if(self.flags & FL_PROJECTILE) // remove any projectiles left
+                               remove(self);
+               }
        }
 
        // Waypoints and assault start come LAST
-       for(self = world; (self = nextent(self)); )
-       if(IS_NOT_A_CLIENT(self))
+       for(entity e = world; (e = nextent(e)); )
        {
-               if(self.reset2)
+               setself(e);
+               if(IS_NOT_A_CLIENT(self))
                {
-                       self.reset2();
-                       continue;
+                       if(self.reset2)
+                       {
+                               self.reset2();
+                               continue;
+                       }
                }
        }
 
-       FOR_EACH_PLAYER(self)
-       if(self.frozen)
-               Unfreeze(self);
+       entity e;
+       FOR_EACH_PLAYER(e)
+       if(e.frozen)
+       {
+               SELFCALL(e, Unfreeze(self));
+               SELFCALL_DONE();
+       }
 
        // Moving the player reset code here since the player-reset depends
        // on spawnpoint entities which have to be reset first --blub
        if(dorespawn)
        if(!MUTATOR_CALLHOOK(reset_map_players))
-       FOR_EACH_CLIENT(self) // reset all players
+       FOR_EACH_CLIENT(e) // reset all players
        {
+               setself(e);
                /*
                only reset players if a restart countdown is active
                this can either be due to cvar sv_ready_restart_after_countdown having set
@@ -418,7 +427,7 @@ void reset_map(float dorespawn)
        if(g_keyhunt)
                kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round + (game_starttime - time), kh_StartRound);
 
-       self = oldself;
+       setself(this);
 }
 
 // Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown is set)
index 4331676..9300539 100644 (file)
@@ -142,17 +142,9 @@ void GiveFrags (entity attacker, entity targ, float f, int deathtype)
        }
 
        // FIXME fix the mess this is (we have REAL points now!)
-       entity oldself;
-       oldself = self;
-       self = attacker;
-       if(MUTATOR_CALLHOOK(GiveFragsForKill, attacker, targ, f))
+       if(MUTATOR_CALLHOOK(GiveFragsForKill, self, attacker, targ, f))
        {
                f = frag_score;
-               self = oldself;
-       }
-       else
-       {
-               self = oldself;
        }
 
        attacker.totalfrags += f;
@@ -584,11 +576,8 @@ void Freeze (entity targ, float freeze_time, float frozen_type, float show_waypo
        targ.iceblock = ice;
        targ.revival_time = 0;
 
-       entity oldself;
-       oldself = self;
-       self = ice;
-       Ice_Think();
-       self = oldself;
+       SELFCALL(ice, Ice_Think());
+       SELFCALL_DONE();
 
        RemoveGrapplingHook(targ);
 
@@ -635,9 +624,8 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, int d
        if (gameover || targ.killcount == -666)
                return;
 
-       entity oldself;
-       oldself = self;
-       self = targ;
+       entity oldself = self;
+       setself(targ);
         damage_targ = targ;
         damage_inflictor = inflictor;
         damage_attacker = attacker;
@@ -655,7 +643,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, int d
                if(IS_PLAYER(targ))
                        if(SAME_TEAM(targ, attacker))
                        {
-                               self = oldself;
+                               setself(oldself);
                                return;
                        }
        }
@@ -776,7 +764,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, int d
                        Send_Effect(EFFECT_TELEPORT, targ.origin, '0 0 0', 1);
 
                        entity oldself = self;
-                       self = targ;
+                       setself(targ);
                        entity spot = SelectSpawnPoint (false);
 
                        if(spot)
@@ -806,7 +794,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, int d
                                Send_Effect(EFFECT_TELEPORT, self.origin, '0 0 0', 1);
                        }
 
-                       self = oldself;
+                       setself(oldself);
                }
 
                if(!g_instagib)
@@ -923,7 +911,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, int d
        if (damage != 0 || (self.damageforcescale && vlen(force)))
        if (self.event_damage)
                self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
-       self = oldself;
+       setself(oldself);
 
        // apply mirror damage if any
        if(mirrordamage > 0 || mirrorforce > 0)
index 3233f24..4f3356b 100644 (file)
@@ -531,11 +531,8 @@ void RandomSeed_Spawn()
        randomseed.think = RandomSeed_Think;
        Net_LinkEntity(randomseed, false, 0, RandomSeed_Send);
 
-       entity oldself;
-       oldself = self;
-       self = randomseed;
-       self.think(); // sets random seed and nextthink
-       self = oldself;
+       SELFCALL(randomseed, randomseed.think()); // sets random seed and nextthink
+       SELFCALL_DONE();
 }
 
 void spawnfunc___init_dedicated_server(void)
@@ -1727,11 +1724,8 @@ float WinningCondition_Assault()
                        }
                        else
                        {
-                               entity oldself;
-                               oldself = self;
-                               self = ent;
-                               assault_new_round();
-                               self = oldself;
+                               SELFCALL(ent, assault_new_round());
+                               SELFCALL_DONE();
                        }
                }
        }
@@ -2206,15 +2200,16 @@ void EndFrame()
        anticheat_endframe();
 
        float altime;
-       FOR_EACH_REALCLIENT(self)
+       entity e_;
+       FOR_EACH_REALCLIENT(e_)
        {
-               entity e = IS_SPEC(self) ? self.enemy : self;
+               entity e = IS_SPEC(e_) ? e_.enemy : e_;
                if(e.typehitsound)
-                       self.typehit_time = time;
+                       e_.typehit_time = time;
                else if(e.damage_dealt)
                {
-                       self.hit_time = time;
-                       self.damage_dealt_total += ceil(e.damage_dealt);
+                       e_.hit_time = time;
+                       e_.damage_dealt_total += ceil(e.damage_dealt);
                }
        }
        altime = time + frametime * (1 + autocvar_g_antilag_nudge);
@@ -2223,14 +2218,18 @@ void EndFrame()
        // add another frametime because client shows everything with
        // 1 frame of lag (cl_nolerp 0). The last +1 however should not be
        // needed!
-       FOR_EACH_CLIENT(self)
+       FOR_EACH_CLIENT(e_)
        {
-               self.typehitsound = false;
-               self.damage_dealt = 0;
-               antilag_record(self, altime);
+               e_.typehitsound = false;
+               e_.damage_dealt = 0;
+               setself(e_);
+               antilag_record(e_, altime);
+       }
+       FOR_EACH_MONSTER(e_)
+       {
+               setself(e_);
+               antilag_record(e_, altime);
        }
-       FOR_EACH_MONSTER(self)
-               antilag_record(self, altime);
 }
 
 
@@ -2263,8 +2262,10 @@ float RedirectionThink()
        redirection_nextthink = time + 1;
 
        clients_found = 0;
-       FOR_EACH_REALCLIENT(self)
+       entity e;
+       FOR_EACH_REALCLIENT(e)
        {
+               setself(e);
                // TODO add timer
                LOG_INFO("Redirecting: sending connect command to ", self.netname, "\n");
                if(redirection_target == "self")
index 1ed405b..2b1f42f 100644 (file)
@@ -1178,47 +1178,45 @@ void InitializeEntitiesRun()
     startoflist = initialize_entity_first;
     initialize_entity_first = world;
     remove = remove_except_protected;
-    for (self = startoflist; self; self = self.initialize_entity_next)
+    for (entity e = startoflist; e; e = e.initialize_entity_next)
     {
-       self.remove_except_protected_forbidden = 1;
+               e.remove_except_protected_forbidden = 1;
     }
-    for (self = startoflist; self; )
+    for (entity e_ = startoflist; e_; )
     {
-        entity e;
-        var void(void) func;
-        e = self.initialize_entity_next;
-        func = self.initialize_entity;
-        self.initialize_entity_order = 0;
-        self.initialize_entity = func_null;
-        self.initialize_entity_next = world;
-       self.remove_except_protected_forbidden = 0;
-        if (self.classname == "initialize_entity")
+        setself(e_);
+        entity e = e_.initialize_entity_next;
+        var void(void) func = e_.initialize_entity;
+        e_.initialize_entity_order = 0;
+        e_.initialize_entity = func_null;
+        e_.initialize_entity_next = world;
+               e_.remove_except_protected_forbidden = 0;
+        if (e_.classname == "initialize_entity")
         {
-            entity e_old;
-            e_old = self.enemy;
-            builtin_remove(self);
-            self = e_old;
+            entity e_old = e_.enemy;
+            builtin_remove(e_);
+            e_ = e_old;
         }
-        //dprint("Delayed initialization: ", self.classname, "\n");
+        //dprint("Delayed initialization: ", e_.classname, "\n");
         if(func)
             func();
         else
         {
-            eprint(self);
-            backtrace(strcat("Null function in: ", self.classname, "\n"));
+            eprint(e_);
+            backtrace(strcat("Null function in: ", e_.classname, "\n"));
         }
-        self = e;
+        e_ = e;
     }
     remove = remove_unsafely;
 }
 
 void UncustomizeEntitiesRun()
 {SELFPARAM();
-    entity oldself;
-    oldself = self;
-    for (self = world; (self = findfloat(self, uncustomizeentityforclient_set, 1)); )
-        self.uncustomizeentityforclient();
-    self = oldself;
+    for (entity e = world; (e = findfloat(e, uncustomizeentityforclient_set, 1)); )
+    {
+        SELFCALL(e, e.uncustomizeentityforclient());
+        SELFCALL_DONE();
+    }
 }
 void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer)
 {
index 44f926f..881938f 100644 (file)
@@ -106,6 +106,7 @@ MUTATOR_HOOKABLE(PlayerJump, EV_PlayerJump);
 
 /** called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill */
 #define EV_GiveFragsForKill(i, o) \
+    /**/ i(entity, __self) \
     /** same as self */ i(entity, frag_attacker) \
     /**/ i(entity, frag_target) \
     /**/ i(float, frag_score) \
index 8915b89..163e423 100644 (file)
@@ -13,16 +13,16 @@ void assault_objective_use()
        //print("^2Activated objective ", self.targetname, "=", etos(self), "\n");
        //print("Activator is ", activator.classname, "\n");
 
-       entity oldself;
-       oldself = self;
-
-       for(self = world; (self = find(self, target, oldself.targetname)); )
+       for (entity e = world; (e = find(e, target, this.targetname)); )
        {
-               if(self.classname == "target_objective_decrease")
-                       target_objective_decrease_activate();
+               if (e.classname == "target_objective_decrease")
+               {
+                       SELFCALL(e, target_objective_decrease_activate());
+                       SELFCALL_DONE();
+               }
        }
 
-       self = oldself;
+       setself(this);
 }
 
 vector target_objective_spawn_evalfunc(entity player, entity spot, vector current)
@@ -73,7 +73,7 @@ void assault_objective_decrease_use()
                        entity oldself, oldactivator, head;
 
                        oldself = self;
-                       self = oldself.enemy;
+                       setself(oldself.enemy);
                        if(self.message)
                        FOR_EACH_PLAYER(head)
                                centerprint(head, self.message);
@@ -82,7 +82,7 @@ void assault_objective_decrease_use()
                        activator = oldself;
                        SUB_UseTargets();
                        activator = oldactivator;
-                       self = oldself;
+                       setself(oldself);
                }
        }
 }
@@ -170,26 +170,18 @@ void assault_roundstart_use()
        activator = self;
        SUB_UseTargets();
 
-       entity ent, oldself;
-
        //(Re)spawn all turrets
-       oldself = self;
-       ent = find(world, classname, "turret_main");
-       while(ent) {
+       for(entity ent = NULL; (ent = find(ent, classname, "turret_main")); ) {
                // Swap turret teams
                if(ent.team == NUM_TEAM_1)
                        ent.team = NUM_TEAM_2;
                else
                        ent.team = NUM_TEAM_1;
 
-               self = ent;
-
                // Dubbles as teamchange
-               turret_respawn();
-
-               ent = find(ent, classname, "turret_main");
+               SELFCALL(ent, turret_respawn());
+               SELFCALL_DONE();
        }
-       self = oldself;
 }
 
 void assault_wall_think()
@@ -214,26 +206,27 @@ void vehicles_clearreturn(entity veh);
 void vehicles_spawn();
 void assault_new_round()
 {SELFPARAM();
-    entity oldself;
        //bprint("ASSAULT: new round\n");
 
-       oldself = self;
        // Eject players from vehicles
-    FOR_EACH_PLAYER(self)
+       entity e;
+    FOR_EACH_PLAYER(e)
     {
-        if(self.vehicle)
-            vehicles_exit(VHEF_RELEASE);
+        if(e.vehicle)
+        {
+               SELFCALL(e, vehicles_exit(VHEF_RELEASE));
+            SELFCALL_DONE();
+        }
     }
 
-    self = findchainflags(vehicle_flags, VHF_ISVEHICLE);
-    while(self)
+    for (entity e_ = findchainflags(vehicle_flags, VHF_ISVEHICLE); e_; e_ = e_.chain)
     {
+       setself(e_);
         vehicles_clearreturn(self);
         vehicles_spawn();
-        self = self.chain;
     }
 
-    self = oldself;
+    setself(this);
 
        // up round counter
        self.winning = self.winning + 1;
index 204c4f8..570fc38 100644 (file)
@@ -189,8 +189,10 @@ MUTATOR_HOOKFUNCTION(ca_PutClientInServer)
 
 MUTATOR_HOOKFUNCTION(ca_reset_map_players)
 {SELFPARAM();
-       FOR_EACH_CLIENT(self)
+       entity e;
+       FOR_EACH_CLIENT(e)
        {
+               setself(e);
                self.killcount = 0;
                if(!self.caplayer && IS_BOT_CLIENT(self))
                {
index 55262c7..28775ea 100644 (file)
@@ -847,10 +847,10 @@ void ctf_FlagThink()
                                ctf_CheckFlagReturn(self, RETURN_SPEEDRUN);
 
                                tmp_entity = self;
-                               self = self.owner;
+                               setself(self.owner);
                                self.impulse = CHIMPULSE_SPEEDRUN; // move the player back to the waypoint they set
                                ImpulseCommands();
-                               self = tmp_entity;
+                               setself(tmp_entity);
                        }
                        if(autocvar_g_ctf_stalemate)
                        {
@@ -1093,7 +1093,7 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e
 {SELFPARAM();
        // declarations
        string teamname = Static_Team_ColorName_Lower(teamnumber);
-       self = flag; // for later usage with droptofloor()
+       setself(flag); // for later usage with droptofloor()
 
        // main setup
        flag.ctf_worldflagnext = ctf_worldflaglist; // link flag into ctf_worldflaglist
@@ -1197,7 +1197,7 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e
        else // drop to floor, automatically find a platform and set that as spawn origin
        {
                flag.noalign = false;
-               self = flag;
+               setself(flag);
                droptofloor();
                flag.movetype = MOVETYPE_TOSS;
        }
@@ -2382,16 +2382,15 @@ void ctf_ScoreRules(int teams)
 // code from here on is just to support maps that don't have flag and team entities
 void ctf_SpawnTeam (string teamname, int teamcolor)
 {SELFPARAM();
-       entity oldself;
-       oldself = self;
-       self = spawn();
+       entity oldself = self;
+       setself(spawn());
        self.classname = "ctf_team";
        self.netname = teamname;
        self.cnt = teamcolor;
 
        spawnfunc_ctf_team();
 
-       self = oldself;
+       setself(oldself);
 }
 
 void ctf_DelayedInit() // Do this check with a delay so we can wait for teams to be set up.
index aa49e83..21179e9 100644 (file)
@@ -410,8 +410,10 @@ MUTATOR_HOOKFUNCTION(dom_GetTeamCount)
 MUTATOR_HOOKFUNCTION(dom_ResetMap)
 {SELFPARAM();
        total_pps = 0, pps_red = 0, pps_blue = 0, pps_yellow = 0, pps_pink = 0;
-       FOR_EACH_PLAYER(self)
+       entity e;
+       FOR_EACH_PLAYER(e)
        {
+               setself(e);
                PutClientInServer();
                self.player_blocked = 1;
                if(IS_REAL_CLIENT(self))
@@ -542,9 +544,8 @@ void ScoreRules_dom(float teams)
 // code from here on is just to support maps that don't have control point and team entities
 void dom_spawnteam (string teamname, float teamcolor, string pointmodel, float pointskin, string capsound, string capnarration, string capmessage)
 {SELFPARAM();
-       entity oldself;
-       oldself = self;
-       self = spawn();
+       entity oldself = self;
+       setself(spawn());
        self.classname = "dom_team";
        self.netname = teamname;
        self.cnt = teamcolor;
@@ -564,20 +565,19 @@ void dom_spawnteam (string teamname, float teamcolor, string pointmodel, float p
        self.team = self.cnt + 1;
 
        //eprint(self);
-       self = oldself;
+       setself(oldself);
 }
 
 void dom_spawnpoint(vector org)
 {SELFPARAM();
-       entity oldself;
-       oldself = self;
-       self = spawn();
+       entity oldself = self;
+       setself(spawn());
        self.classname = "dom_controlpoint";
        self.think = spawnfunc_dom_controlpoint;
        self.nextthink = time;
        setorigin(self, org);
        spawnfunc_dom_controlpoint();
-       self = oldself;
+       setself(oldself);
 }
 
 // spawn some default teams if the map is not set up for domination
index 27c5e9c..e7790c9 100644 (file)
@@ -407,12 +407,14 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
 
 MUTATOR_HOOKFUNCTION(freezetag_reset_map_players)
 {SELFPARAM();
-       FOR_EACH_PLAYER(self)
+       entity e;
+       FOR_EACH_PLAYER(e)
        {
-               self.killcount = 0;
-               self.freezetag_frozen_timeout = -1;
+               e.killcount = 0;
+               e.freezetag_frozen_timeout = -1;
+               setself(e);
                PutClientInServer();
-               self.freezetag_frozen_timeout = 0;
+               e.freezetag_frozen_timeout = 0;
        }
        freezetag_count_alive_players();
        return 1;
index 0db687f..9c6033e 100644 (file)
@@ -36,10 +36,14 @@ MUTATOR_HOOKFUNCTION(lms_ResetMap)
 
 MUTATOR_HOOKFUNCTION(lms_ResetPlayers)
 {SELFPARAM();
+       entity e;
        if(restart_mapalreadyrestarted || (time < game_starttime))
-       FOR_EACH_CLIENT(self)
-       if(IS_PLAYER(self))
-               PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives());
+       FOR_EACH_CLIENT(e)
+       if(IS_PLAYER(e))
+       {
+               SELFCALL(e, PlayerScore_Add(e, SP_LMS_LIVES, LMS_NewPlayerLives()));
+               SELFCALL_DONE();
+       }
 
        return false;
 }
index 2194922..5b11699 100644 (file)
@@ -67,10 +67,10 @@ void nexball_setstatus(void)
                {
                        bprint("The ", Team_ColoredFullName(self.team), " held the ball for too long.\n");
                        oldself = self;
-                       self = self.ballcarried;
+                       setself(self.ballcarried);
                        DropBall(self, self.owner.origin, '0 0 0');
                        ResetBall();
-                       self = oldself;
+                       setself(oldself);
                }
                else
                        self.items |= IT_KEY1;
@@ -154,14 +154,14 @@ void GiveBall(entity plyr, entity ball)
        }
 
        ownr = self;
-       self = plyr;
+       setself(plyr);
        self.weaponentity.weapons = self.weapons;
        self.weaponentity.switchweapon = self.weapon;
        self.weapons = WEPSET_PORTO;
        WEP_ACTION(WEP_PORTO.m_id, WR_RESETPLAYER);
        self.switchweapon = WEP_PORTO.m_id;
        W_SwitchWeapon(WEP_PORTO.m_id);
-       self = ownr;
+       setself(ownr);
 }
 
 void DropBall(entity ball, vector org, vector vel)
index d96c143..c069dc1 100644 (file)
@@ -405,10 +405,10 @@ void ons_ControlPoint_Icon_Damage(entity inflictor, entity attacker, float damag
 
                // Use targets now (somebody make sure this is in the right place..)
                oself = self;
-               self = self.owner;
+               setself(self.owner);
                activator = self;
                SUB_UseTargets ();
-               self = oself;
+               setself(oself);
 
                self.owner.waslinked = self.owner.islinked;
                if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
@@ -479,10 +479,10 @@ void ons_ControlPoint_Icon_Think()
                        self.owner.team = 0;
 
                oself = self;
-               self = self.owner;
+               setself(self.owner);
                activator = self;
                SUB_UseTargets ();
-               self = oself;
+               setself(oself);
 
                self.owner.team = t;
 
@@ -546,10 +546,10 @@ void ons_ControlPoint_Icon_BuildThink()
 
                // Use targets now (somebody make sure this is in the right place..)
                oself = self;
-               self = self.owner;
+               setself(self.owner);
                activator = self;
                SUB_UseTargets ();
-               self = oself;
+               setself(oself);
 
                self.SendFlags |= CPSF_SETUP;
        }
@@ -737,7 +737,7 @@ void ons_DelayedControlPoint_Setup(void)
 void ons_ControlPoint_Setup(entity cp)
 {SELFPARAM();
        // declarations
-       self = cp; // for later usage with droptofloor()
+       setself(cp); // for later usage with droptofloor()
 
        // main setup
        cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
@@ -790,7 +790,7 @@ void ons_ControlPoint_Setup(entity cp)
        {
                setorigin(cp, cp.origin + '0 0 20');
                cp.noalign = false;
-               self = cp;
+               setself(cp);
                droptofloor();
                cp.movetype = MOVETYPE_TOSS;
        }
@@ -1002,7 +1002,7 @@ void ons_GeneratorSetup(entity gen) // called when spawning a generator entity o
 {SELFPARAM();
        // declarations
        int teamnumber = gen.team;
-       self = gen; // for later usage with droptofloor()
+       setself(gen); // for later usage with droptofloor()
 
        // main setup
        gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
@@ -1046,7 +1046,7 @@ void ons_GeneratorSetup(entity gen) // called when spawning a generator entity o
        gen.colormap = 1024 + (teamnumber - 1) * 17;
 
        // generator placement
-       self = gen;
+       setself(gen);
        droptofloor();
 
        // waypointsprites
@@ -1703,11 +1703,13 @@ bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effe
 
 MUTATOR_HOOKFUNCTION(ons_ResetMap)
 {SELFPARAM();
-       FOR_EACH_PLAYER(self)
+       entity e;
+       FOR_EACH_PLAYER(e)
        {
-               self.ons_roundlost = false;
-               self.ons_deathloc = '0 0 0';
-               PutClientInServer();
+               e.ons_roundlost = false;
+               e.ons_deathloc = '0 0 0';
+               SELFCALL(e, PutClientInServer());
+               SELFCALL_DONE();
        }
        return false;
 }
index e9a95c1..996857d 100644 (file)
@@ -19,16 +19,14 @@ void spawnfunc_tdm_team()
 // code from here on is just to support maps that don't have team entities
 void tdm_SpawnTeam (string teamname, float teamcolor)
 {SELFPARAM();
-       entity oldself;
-       oldself = self;
-       self = spawn();
+       setself(spawn());
        self.classname = "tdm_team";
        self.netname = teamname;
        self.cnt = teamcolor;
 
        spawnfunc_tdm_team();
 
-       self = oldself;
+       setself(this);
 }
 
 void tdm_DelayedInit()
index 365c43a..62e4d9f 100644 (file)
@@ -337,8 +337,7 @@ void buff_Init(entity ent)
 
        entity buff = buff_FirstFromFlags(self.buffs);
 
-       entity oldself = self;
-       self = ent;
+       setself(ent);
        if(!self.buffs || buff_Available(buff))
                buff_NewType(self, 0);
 
@@ -375,7 +374,7 @@ void buff_Init(entity ent)
        if(cvar("g_buffs_random_location") || (self.spawnflags & 64))
                buff_Respawn(self);
 
-       self = oldself;
+       setself(this);
 }
 
 void buff_Init_Compat(entity ent, entity replacement)
@@ -784,13 +783,12 @@ MUTATOR_HOOKFUNCTION(buffs_PlayerThink)
                for(other = world; (other = findflags(other, flags, FL_ITEM)); )
                if(boxesoverlap(self.absmin - pickup_size, self.absmax + pickup_size, other.absmin, other.absmax))
                {
-                       entity oldself = self;
-                       self = other;
-                       other = oldself;
+                       setself(other);
+                       other = this;
                        if(self.touch)
                                self.touch();
                        other = self;
-                       self = oldself;
+                       setself(this);
                }
        }
 
index c4ddfa1..30810c8 100644 (file)
@@ -337,11 +337,8 @@ MUTATOR_HOOKFUNCTION(instagib_FilterItem)
        {
                entity e = spawn();
                setorigin(e, self.origin);
-               entity oldself;
-               oldself = self;
-               self = e;
-               spawnfunc_item_minst_cells();
-               self = oldself;
+               SELFCALL(e, spawnfunc_item_minst_cells());
+               SELFCALL_DONE();
                return true;
        }
 
index 5410d6c..364fa01 100644 (file)
@@ -81,7 +81,7 @@ MUTATOR_HOOKFUNCTION(ok_PlayerDies)
                other = world;
        }
 
-       self = spawn();
+       setself(spawn());
        self.ok_item = true;
        self.noalign = true;
        self.pickup_anyway = true;
@@ -93,7 +93,7 @@ MUTATOR_HOOKFUNCTION(ok_PlayerDies)
        self.velocity = '0 0 200' + normalize(targ.origin - self.origin) * 500;
        self.classname = "droppedweapon"; // hax
        SUB_SetFade(self, time + 5, 1);
-       self = oldself;
+       setself(oldself);
 
        self.ok_lastwep = self.switchweapon;
 
index ea66e7d..1bb5872 100644 (file)
@@ -103,8 +103,10 @@ MUTATOR_HOOKFUNCTION(superspec_ItemTouch)
        entity _oldself = self;
        entity _item = self;
 
-       FOR_EACH_SPEC(self)
+       entity e;
+       FOR_EACH_SPEC(e)
        {
+               setself(e);
                if(self.superspec_flags & SSF_ITEMMSG)
                        if(superspec_filteritem(self, _item))
                        {
@@ -116,7 +118,7 @@ MUTATOR_HOOKFUNCTION(superspec_ItemTouch)
                                {
                                        _spectate(other);
 
-                                       self = _oldself;
+                                       setself(_oldself);
                                        return MUT_ITEMTOUCH_CONTINUE;
                                }
                        }
@@ -146,7 +148,7 @@ MUTATOR_HOOKFUNCTION(superspec_ItemTouch)
                }
        }
 
-       self = _oldself;
+       setself(_oldself);
 
        return MUT_ITEMTOUCH_CONTINUE;
 }
@@ -488,11 +490,11 @@ MUTATOR_HOOKFUNCTION(superspec_ClientConnect)
 
 MUTATOR_HOOKFUNCTION(superspec_PlayerDies)
 {SELFPARAM();
-       entity _old_self = self;
-
-       FOR_EACH_SPEC(self)
+       entity e;
+       FOR_EACH_SPEC(e)
        {
-               if(self.autospec_flags & ASF_FOLLOWKILLER && IS_PLAYER(frag_attacker) && self.enemy == _old_self)
+               setself(e);
+               if(self.autospec_flags & ASF_FOLLOWKILLER && IS_PLAYER(frag_attacker) && self.enemy == this)
                {
                        if(self.autospec_flags & ASF_SHOWWHAT)
                                superspec_msg("", "", self, sprintf("^7Following %s^7 due to followkiller\n", frag_attacker.netname), 2);
@@ -501,7 +503,7 @@ MUTATOR_HOOKFUNCTION(superspec_PlayerDies)
                }
        }
 
-       self = _old_self;
+       setself(this);
        return false;
 }
 
index a5d925d..430271d 100644 (file)
@@ -143,8 +143,7 @@ entity sandbox_ObjectSpawn(float database)
 {SELFPARAM();
        // spawn a new object with default properties
 
-       entity e, oldself;
-       e = spawn();
+       entity e = spawn();
        e.classname = "object";
        e.takedamage = DAMAGE_AIM;
        e.damageforcescale = 1;
@@ -179,10 +178,8 @@ entity sandbox_ObjectSpawn(float database)
                e.angles_y = self.v_angle.y;
        }
 
-       oldself = self;
-       self = e;
-       CSQCMODEL_AUTOINIT(self);
-       self = oldself;
+       SELFCALL(e, CSQCMODEL_AUTOINIT(e));
+       SELFCALL_DONE();
 
        object_count += 1;
        return e;
index e32f8b0..111303e 100644 (file)
@@ -577,7 +577,7 @@ void checkpoint_passed()
        {
                // do not allow portalling through checkpoints
                trace_plane_normal = normalize(-1 * other.velocity);
-               self = other;
+               setself(other);
                W_Porto_Fail(0);
                return;
        }
@@ -747,7 +747,7 @@ void trigger_race_checkpoint_verify()
        qual = g_race_qualifying;
 
        oldself = self;
-       self = spawn();
+       setself(spawn());
        self.classname = "player";
 
        if(g_race)
@@ -895,7 +895,7 @@ void trigger_race_checkpoint_verify()
                                }
        }
        remove(self);
-       self = oldself;
+       setself(oldself);
 }
 
 vector trigger_race_checkpoint_spawn_evalfunc(entity player, entity spot, vector current)
@@ -1075,7 +1075,6 @@ void spawnfunc_info_player_race (void)
 void race_ClearRecords()
 {SELFPARAM();
        float i;
-       entity e;
 
        for(i = 0; i < MAX_CHECKPOINTS; ++i)
        {
@@ -1085,15 +1084,14 @@ void race_ClearRecords()
                race_checkpoint_recordholders[i] = string_null;
        }
 
-       e = self;
-       FOR_EACH_CLIENT(self)
+       entity e;
+       FOR_EACH_CLIENT(e)
        {
-               float p;
-               p = self.race_place;
-               race_PreparePlayer();
-               self.race_place = p;
+               float p = e.race_place;
+               SELFCALL(e, race_PreparePlayer());
+               SELFCALL_DONE();
+               e.race_place = p;
        }
-       self = e;
 }
 
 void race_ImposePenaltyTime(entity pl, float penalty, string reason)
index 928be46..177e4bc 100644 (file)
@@ -258,10 +258,8 @@ vector Spawn_Score(entity spot, float mindist, float teamcheck)
                        ++found;
                        if(ent.spawn_evalfunc)
                        {
-                               entity oldself = self;
-                               self = ent;
-                               spawn_score = ent.spawn_evalfunc(oldself, spot, spawn_score);
-                               self = oldself;
+                               spawn_score = SELFCALL(ent, ent.spawn_evalfunc(this, spot, spawn_score));
+                               SELFCALL_DONE();
                                if(spawn_score.x < 0)
                                        return spawn_score;
                        }
index bfcf7ca..948e2d3 100644 (file)
 
 void CreatureFrame (void)
 {SELFPARAM();
-       entity oldself;
        float dm;
 
-       oldself = self;
-       for(self = world; (self = findfloat(self, damagedbycontents, true)); )
+       for(entity e = world; (e = findfloat(e, damagedbycontents, true)); )
        {
+               setself(e);
                if (self.movetype == MOVETYPE_NOCLIP) { continue; }
 
                float vehic = IS_VEHICLE(self);
@@ -169,7 +168,7 @@ void CreatureFrame (void)
 
         self.oldvelocity = self.velocity;
        }
-       self = oldself;
+       setself(this);
 }
 
 
@@ -218,8 +217,7 @@ void StartFrame (void)
        }
 #endif
 
-       entity e;
-       for(e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )
+       for(entity e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); )
                CSQCProjectile_Check(e);
 
        if(RedirectionThink())
@@ -264,8 +262,9 @@ void StartFrame (void)
 
        bot_serverframe();
 
-       FOR_EACH_PLAYER(self)
-               self.porto_forbidden = max(0, self.porto_forbidden - 1);
+       entity e;
+       FOR_EACH_PLAYER(e)
+               e.porto_forbidden = max(0, e.porto_forbidden - 1);
 
        anticheat_startframe();
 
index 49f0b10..fc131e5 100644 (file)
@@ -479,14 +479,14 @@ void Item_RespawnCountdown (void)
                {
                        entity e;
                        entity it = self;
-                       self = self.waypointsprite_attached;
+                       setself(self.waypointsprite_attached);
                        FOR_EACH_REALCLIENT(e)
                                if(self.waypointsprite_visible_for_player(e))
                                {
                                        msg_entity = e;
                                        soundto(MSG_ONE, it, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTEN_NORM);        // play respawn sound
                                }
-                       self = it;
+                       setself(it);
 
                        WaypointSprite_Ping(self.waypointsprite_attached);
                        //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
index f841fec..db71293 100644 (file)
 
 void W_GiveWeapon (entity e, float wep)
 {SELFPARAM();
-       entity oldself;
 
        if (!wep)
                return;
 
        e.weapons |= WepSet_FromWeapon(wep);
 
-       oldself = self;
-       self = e;
+       setself(e);
 
        if(IS_PLAYER(other))
                { Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_WEAPON_GOT, wep); }
 
-       self = oldself;
+       setself(this);
 }
 
 void W_PlayStrengthSound(entity player) // void W_PlayStrengthSound
index f7fc6f9..83323f4 100644 (file)
@@ -48,7 +48,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                        else
                        {
                                oldself = self;
-                               self = cl;
+                               setself(cl);
                                f = WEP_ACTION(wpn, WR_CHECKAMMO1);
                                f = f + WEP_ACTION(wpn, WR_CHECKAMMO2);
 
@@ -58,7 +58,7 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
                                for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
                                        f = 1;
 
-                               self = oldself;
+                               setself(oldself);
                        }
                        if (!f)
                        {
index 73ce1de..57302ee 100644 (file)
@@ -76,7 +76,7 @@ void weapon_defaultspawnfunc(float wpn)
                                        e = get_weaponinfo(j);
                                        if(e.netname == s)
                                        {
-                                               self = spawn();
+                                               setself(spawn());
                                                copyentity(oldself, self);
                                                self.classname = "replacedweapon";
                                                weapon_defaultspawnfunc(j);
@@ -88,7 +88,7 @@ void weapon_defaultspawnfunc(float wpn)
                                        LOG_INFO("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
                                }
                        }
-                       self = oldself;
+                       setself(oldself);
                }
                if(t >= 1) // always the case!
                {
index 5c3b11d..25f4649 100644 (file)
@@ -31,12 +31,11 @@ void thrown_wep_think()
 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
 {SELFPARAM();
-       entity oldself, wep;
        float thisammo, i;
        string s;
        var .int ammotype = (get_weaponinfo(wpn)).ammo_field;
 
-       wep = spawn();
+       entity wep = spawn();
 
        setorigin(wep, org);
        wep.classname = "droppedweapon";
@@ -75,10 +74,8 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
                }
        }
 
-       oldself = self;
-       self = wep;
-       weapon_defaultspawnfunc(wpn);
-       self = oldself;
+       SELFCALL(wep, weapon_defaultspawnfunc(wpn));
+       SELFCALL_DONE();
        if(startitem_failed)
                return string_null;
        wep.glowmod = own.weaponentity_glowmod;
index 8be3a66..b725cbd 100644 (file)
@@ -270,16 +270,13 @@ void CL_WeaponEntity_SetModel(string name)
 
 vector CL_Weapon_GetShotOrg(float wpn)
 {SELFPARAM();
-       entity wi, oldself;
-       vector ret;
-       wi = get_weaponinfo(wpn);
-       oldself = self;
-       self = spawn();
+       entity wi = get_weaponinfo(wpn);
+       setself(spawn());
        CL_WeaponEntity_SetModel(wi.mdl);
-       ret = self.movedir;
+       vector ret = self.movedir;
        CL_WeaponEntity_SetModel("");
        remove(self);
-       self = oldself;
+       setself(this);
        return ret;
 }
 
@@ -972,9 +969,8 @@ void W_Reload(float sent_ammo_min, string sent_sound)
 
 void W_DropEvent(float event, entity player, float weapon_type, entity weapon_item)
 {SELFPARAM();
-       entity oldself = self;
-       self = player;
+       setself(player);
        weapon_dropevent_item = weapon_item;
        WEP_ACTION(weapon_type, event);
-       self = oldself;
+       setself(this);
 }
index 8d5a6b6..ba17091 100644 (file)
@@ -206,13 +206,13 @@ void WarpZone_Touch (void)
                if (!self.target3) self.target3 = save2;
 
                oldself = self;
-               self = self.enemy;
+               setself(self.enemy);
                save1 = self.target; self.target = string_null;
                save2 = self.target2; self.target2 = string_null;
                SUB_UseTargets();
                if (!self.target) self.target = save1;
                if (!self.target2) self.target2 = save2;
-               self = oldself;
+               setself(oldself);
        }
        else
        {
@@ -758,17 +758,15 @@ void spawnfunc_func_camera(void)
 }
 void WarpZones_Reconnect()
 {SELFPARAM();
-       entity e;
-       e = self;
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                WarpZone_InitStep_ClearTarget();
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                WarpZone_InitStep_FindTarget();
-       for(self = warpzone_camera_first; self; self = self.warpzone_next)
+       for(setself(warpzone_camera_first); self; setself(self.warpzone_next))
                WarpZoneCamera_InitStep_FindTarget();
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                WarpZone_InitStep_FinalizeTransform();
-       self = e;
+       setself(this);
 }
 
 void WarpZone_Think()
@@ -781,13 +779,13 @@ void WarpZone_Think()
                entity oldself;
                oldself = self;
                WarpZone_InitStep_UpdateTransform();
-               self = self.enemy;
+               setself(self.enemy);
                WarpZone_InitStep_UpdateTransform();
-               self = oldself;
+               setself(oldself);
                WarpZone_InitStep_FinalizeTransform();
-               self = self.enemy;
+               setself(self.enemy);
                WarpZone_InitStep_FinalizeTransform();
-               self = oldself;
+               setself(oldself);
                self.warpzone_save_origin = self.origin;
                self.warpzone_save_angles = self.angles;
                self.warpzone_save_eorigin = self.enemy.origin;
@@ -802,14 +800,13 @@ void WarpZone_StartFrame()
        if(warpzone_initialized == 0)
        {
                warpzone_initialized = 1;
-               e = self;
-               for(self = warpzone_first; self; self = self.warpzone_next)
+               for(setself(warpzone_first); self; setself(self.warpzone_next))
                        WarpZone_InitStep_FindOriginTarget();
-               for(self = warpzone_position_first; self; self = self.warpzone_next)
+               for(setself(warpzone_position_first); self; setself(self.warpzone_next))
                        WarpZonePosition_InitStep_FindTarget();
-               for(self = warpzone_first; self; self = self.warpzone_next)
+               for(setself(warpzone_first); self; setself(self.warpzone_next))
                        WarpZone_InitStep_UpdateTransform();
-               self = e;
+               setself(this);
                WarpZones_Reconnect();
                WarpZone_PostInitialize_Callback();
        }
@@ -830,14 +827,14 @@ void WarpZone_StartFrame()
 
                                // warpzones
                                if(warpzone_warpzones_exist) {
-                               self = WarpZone_Find(e.origin + e.mins, e.origin + e.maxs);
+                               setself(WarpZone_Find(e.origin + e.mins, e.origin + e.maxs));
                                if(self)
                                if(!WarpZoneLib_ExactTrigger_Touch())
                                        if(WarpZone_PlaneDist(self, e.origin + e.view_ofs) <= 0)
                                                WarpZone_Teleport(self, e, -1, 0); } // NOT triggering targets by this!
 
                                // teleporters
-                               self = Teleport_Find(e.origin + e.mins, e.origin + e.maxs);
+                               setself(Teleport_Find(e.origin + e.mins, e.origin + e.maxs));
                                if(self)
                                if(!WarpZoneLib_ExactTrigger_Touch())
                                        Simple_TeleportPlayer(self, other); // NOT triggering targets by this!
@@ -852,7 +849,7 @@ void WarpZone_StartFrame()
                        break;
                }
        }
-       self = oldself;
+       setself(oldself);
        other = oldother;
 }
 
@@ -872,23 +869,23 @@ void trigger_warpzone_reconnect_use()
        e = self;
        // NOTE: this matches for target, not targetname, but of course
        // targetname must be set too on the other entities
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                self.warpzone_reconnecting = ((e.target == "" || self.target == e.target) && !((e.spawnflags & 1) && (visible_to_some_client(self) || visible_to_some_client(self.enemy))));
-       for(self = warpzone_camera_first; self; self = self.warpzone_next)
+       for(setself(warpzone_camera_first); self; setself(self.warpzone_next))
                self.warpzone_reconnecting = ((e.target == "" || self.target == e.target) && !((e.spawnflags & 1) && visible_to_some_client(self)));
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                if(self.warpzone_reconnecting)
                        WarpZone_InitStep_ClearTarget();
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                if(self.warpzone_reconnecting)
                        WarpZone_InitStep_FindTarget();
-       for(self = warpzone_camera_first; self; self = self.warpzone_next)
+       for(setself(warpzone_camera_first); self; setself(self.warpzone_next))
                if(self.warpzone_reconnecting)
                        WarpZoneCamera_InitStep_FindTarget();
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                if(self.warpzone_reconnecting || self.enemy.warpzone_reconnecting)
                        WarpZone_InitStep_FinalizeTransform();
-       self = e;
+       setself(e);
 }
 
 void spawnfunc_trigger_warpzone_reconnect()