]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/g_world.qc
Remove uses of WITHSELF
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_world.qc
index 7a606c3af2665407ea5bb449be8a30dbf1d242d2..7cb5f69803fb097918f2e7382e64cc91a572df7c 100644 (file)
 #include "../common/util.qh"
 #include "../common/items/all.qh"
 #include "../common/weapons/all.qh"
+#include "../common/state.qh"
 
 const float LATENCY_THINKRATE = 10;
 .float latency_sum;
 .float latency_cnt;
 .float latency_time;
 entity pingplreport;
-void PingPLReport_Think()
-{SELFPARAM();
+void PingPLReport_Think(entity this)
+{
        float delta;
        entity e;
 
        delta = 3 / maxclients;
        if(delta < sys_frametime)
                delta = 0;
-       self.nextthink = time + delta;
+       this.nextthink = time + delta;
 
-       e = edict_num(self.cnt + 1);
+       e = edict_num(this.cnt + 1);
        if(IS_REAL_CLIENT(e))
        {
                WriteHeader(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
-               WriteByte(MSG_BROADCAST, self.cnt);
+               WriteByte(MSG_BROADCAST, this.cnt);
                WriteShort(MSG_BROADCAST, max(1, e.ping));
                WriteByte(MSG_BROADCAST, ceil(e.ping_packetloss * 255));
                WriteByte(MSG_BROADCAST, ceil(e.ping_movementloss * 255));
@@ -71,17 +72,17 @@ void PingPLReport_Think()
        else
        {
                WriteHeader(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
-               WriteByte(MSG_BROADCAST, self.cnt);
+               WriteByte(MSG_BROADCAST, this.cnt);
                WriteShort(MSG_BROADCAST, 0);
                WriteByte(MSG_BROADCAST, 0);
                WriteByte(MSG_BROADCAST, 0);
        }
-       self.cnt = (self.cnt + 1) % maxclients;
+       this.cnt = (this.cnt + 1) % maxclients;
 }
 void PingPLReport_Spawn()
 {
        pingplreport = new_pure(pingplreport);
-       pingplreport.think = PingPLReport_Think;
+       setthink(pingplreport, PingPLReport_Think);
        pingplreport.nextthink = time;
 }
 
@@ -103,8 +104,8 @@ void SetDefaultAlpha()
        }
 }
 
-void GotoFirstMap()
-{SELFPARAM();
+void GotoFirstMap(entity this)
+{
        float n;
        if(autocvar__sv_init)
        {
@@ -128,11 +129,11 @@ void GotoFirstMap()
 
        if(time < 5)
        {
-               self.nextthink = time;
+               this.nextthink = time;
        }
        else
        {
-               self.nextthink = time + 1;
+               this.nextthink = time + 1;
                LOG_INFO("Waiting for _sv_init being set to 1 by initialization scripts...\n");
        }
 }
@@ -412,6 +413,7 @@ void cvar_changes_init()
                BADCVAR("sv_autotaunt");
                BADCVAR("sv_curl_defaulturl");
                BADCVAR("sv_defaultcharacter");
+               BADCVAR("sv_defaultcharacterskin");
                BADCVAR("sv_defaultplayercolors");
                BADCVAR("sv_defaultplayermodel");
                BADCVAR("sv_defaultplayerskin");
@@ -510,23 +512,23 @@ entity randomseed;
 bool RandomSeed_Send(entity this, entity to, int sf)
 {
        WriteHeader(MSG_ENTITY, ENT_CLIENT_RANDOMSEED);
-       WriteShort(MSG_ENTITY, self.cnt);
+       WriteShort(MSG_ENTITY, this.cnt);
        return true;
 }
-void RandomSeed_Think()
-{SELFPARAM();
-       self.cnt = bound(0, floor(random() * 65536), 65535);
-       self.nextthink = time + 5;
+void RandomSeed_Think(entity this)
+{
+       this.cnt = bound(0, floor(random() * 65536), 65535);
+       this.nextthink = time + 5;
 
-       self.SendFlags |= 1;
+       this.SendFlags |= 1;
 }
 void RandomSeed_Spawn()
-{SELFPARAM();
+{
        randomseed = new_pure(randomseed);
-       randomseed.think = RandomSeed_Think;
+       setthink(randomseed, RandomSeed_Think);
        Net_LinkEntity(randomseed, false, 0, RandomSeed_Send);
 
-       WITH(entity, self, randomseed, randomseed.think()); // sets random seed and nextthink
+       getthink(randomseed)(randomseed); // sets random seed and nextthink
 }
 
 spawnfunc(__init_dedicated_server)
@@ -541,12 +543,12 @@ spawnfunc(__init_dedicated_server)
        remove = remove_unsafely;
 
        entity e = spawn();
-       e.think = GotoFirstMap;
+       setthink(e, GotoFirstMap);
        e.nextthink = time; // this is usually 1 at this point
 
        e = new(info_player_deathmatch);  // safeguard against player joining
 
-       self.classname = "worldspawn"; // safeguard against various stuff ;)
+       this.classname = "worldspawn"; // safeguard against various stuff ;)
 
        // needs to be done so early because of the constants they create
        static_init();
@@ -561,6 +563,18 @@ void __init_dedicated_server_shutdown() {
        MapInfo_Shutdown();
 }
 
+void SetLimits(int fraglimit_override, int leadlimit_override, float timelimit_override, float qualifying_override)
+{
+       if(!autocvar_g_campaign)
+       {
+               if(fraglimit_override >= 0) cvar_set("fraglimit", ftos(fraglimit_override));
+               if(timelimit_override >= 0) cvar_set("timelimit", ftos(timelimit_override));
+               if(leadlimit_override >= 0) cvar_set("leadlimit", ftos(leadlimit_override));
+               if(qualifying_override >= 0) cvar_set("g_race_qualifying_timelimit", ftos(qualifying_override));
+       }
+       limits_are_set = true;
+}
+
 void Map_MarkAsRecent(string m);
 float world_already_spawned;
 void Nagger_Init();
@@ -571,9 +585,8 @@ spawnfunc(worldspawn)
 {
        server_is_dedicated = boolean(stof(cvar_defstring("is_dedicated")));
 
+    bool wantrestart = false;
        {
-               bool wantrestart = false;
-
                if (!server_is_dedicated)
                {
                        // force unloading of server pk3 files when starting a listen server
@@ -717,10 +730,16 @@ spawnfunc(worldspawn)
        readlevelcvars();
        GrappleHookInit();
 
+       if(!limits_are_set)
+               SetLimits(autocvar_fraglimit_override, autocvar_leadlimit_override, autocvar_timelimit_override, -1);
+
+       if(warmup_limit == 0)
+               warmup_limit = (autocvar_timelimit > 0) ? autocvar_timelimit * 60 : autocvar_timelimit;
+
        player_count = 0;
        bot_waypoints_for_items = autocvar_g_waypoints_for_items;
        if(bot_waypoints_for_items == 1)
-               if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
+               if(this.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
                        bot_waypoints_for_items = 0;
 
        precache();
@@ -741,7 +760,7 @@ spawnfunc(worldspawn)
                s = ":gameinfo:mutators:LIST";
 
                MUTATOR_CALLHOOK(BuildMutatorsString, s);
-               s = ret_string;
+               s = M_ARGV(0, string);
 
                // initialiation stuff, not good in the mutator system
                if(!autocvar_g_use_ammunition)
@@ -848,7 +867,7 @@ spawnfunc(worldspawn)
 
        CheatInit();
 
-       localcmd("\n_sv_hook_gamestart ", GetGametype(), "\n");
+       if (!wantrestart) localcmd("\n_sv_hook_gamestart ", GetGametype(), "\n");
 
        // fill sv_curl_serverpackages from .serverpackage files
        if (autocvar_sv_curl_serverpackages_auto)
@@ -896,15 +915,15 @@ spawnfunc(worldspawn)
        // save it for later
        modname = strzone(modname);
 
-       WinningConditionHelper(); // set worldstatus
+       WinningConditionHelper(this); // set worldstatus
 
        world_initialized = 1;
 }
 
 spawnfunc(light)
 {
-       //makestatic (self); // Who the f___ did that?
-       remove(self);
+       //makestatic (this); // Who the f___ did that?
+       remove(this);
 }
 
 string GetGametype()
@@ -1277,18 +1296,18 @@ When the player presses attack or jump, change to the next level
 ============
 */
 .float autoscreenshot;
-void IntermissionThink()
-{SELFPARAM();
-       FixIntermissionClient(self);
+void IntermissionThink(entity this)
+{
+       FixIntermissionClient(this);
 
-       float server_screenshot = (autocvar_sv_autoscreenshot && self.cvar_cl_autoscreenshot);
-       float client_screenshot = (self.cvar_cl_autoscreenshot == 2);
+       float server_screenshot = (autocvar_sv_autoscreenshot && this.cvar_cl_autoscreenshot);
+       float client_screenshot = (this.cvar_cl_autoscreenshot == 2);
 
        if( (server_screenshot || client_screenshot)
-               && ((self.autoscreenshot > 0) && (time > self.autoscreenshot)) )
+               && ((this.autoscreenshot > 0) && (time > this.autoscreenshot)) )
        {
-               self.autoscreenshot = -1;
-               if(IS_REAL_CLIENT(self)) { stuffcmd(self, sprintf("\nscreenshot screenshots/autoscreenshot/%s-%s.jpg; echo \"^5A screenshot has been taken at request of the server.\"\n", GetMapname(), strftime(false, "%s"))); }
+               this.autoscreenshot = -1;
+               if(IS_REAL_CLIENT(this)) { stuffcmd(this, sprintf("\nscreenshot screenshots/autoscreenshot/%s-%s.jpg; echo \"^5A screenshot has been taken at request of the server.\"\n", GetMapname(), strftime(false, "%s"))); }
                return;
        }
 
@@ -1296,7 +1315,7 @@ void IntermissionThink()
                return;
 
        if(!mapvote_initialized)
-               if (time < intermission_exittime + 10 && !(PHYS_INPUT_BUTTON_ATCK(self) || PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_ATCK2(self) || PHYS_INPUT_BUTTON_HOOK(self) || PHYS_INPUT_BUTTON_USE(self)))
+               if (time < intermission_exittime + 10 && !(PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_ATCK2(this) || PHYS_INPUT_BUTTON_HOOK(this) || PHYS_INPUT_BUTTON_USE(this)))
                        return;
 
        MapVote_Start();
@@ -1413,7 +1432,7 @@ void DumpStats(float final)
        FOREACH_CLIENT(IS_REAL_CLIENT(it) || (IS_BOT_CLIENT(it) && autocvar_sv_logscores_bots), LAMBDA(
                s = strcat(":player:see-labels:", GetPlayerScoreString(it, 0), ":");
                s = strcat(s, ftos(rint(time - it.jointime)), ":");
-               if(IS_PLAYER(it) || MUTATOR_CALLHOOK(GetPlayerStatus, it, s))
+               if(IS_PLAYER(it) || MUTATOR_CALLHOOK(GetPlayerStatus, it))
                        s = strcat(s, ftos(it.team), ":");
                else
                        s = strcat(s, "spectator:");
@@ -1543,9 +1562,7 @@ void NextLevel()
                        bprint(it.netname, " ^7wins.\n");
        ));
 
-       entity oldself = self;
        target_music_kill();
-       self = oldself;
 
        if(autocvar_g_campaign)
                CampaignPreIntermission();
@@ -1562,13 +1579,13 @@ CheckRules_Player
 Exit deathmatch games upon conditions
 ============
 */
-void CheckRules_Player()
-{SELFPARAM();
+void CheckRules_Player(entity this)
+{
        if (gameover)   // someone else quit the game already
                return;
 
-       if(!IS_DEAD(self))
-               self.play_time += frametime;
+       if(!IS_DEAD(this))
+               this.play_time += frametime;
 
        // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
        //   (div0: and that in CheckRules_World please)
@@ -1665,7 +1682,7 @@ float WinningCondition_Scores(float limit, float leadlimit)
        float limitreached;
 
        // TODO make everything use THIS winning condition (except LMS)
-       WinningConditionHelper();
+       WinningConditionHelper(NULL);
 
        if(teamplay)
        {
@@ -1911,7 +1928,7 @@ void CheckRules_World()
        if(checkrules_status == WINNING_YES)
                bprint("Hey! Someone ran out of spawns!\n");
        else if(MUTATOR_CALLHOOK(CheckRules_World, checkrules_status, timelimit, fraglimit))
-               checkrules_status = ret_float;
+               checkrules_status = M_ARGV(0, float);
        else
                checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
 
@@ -2008,7 +2025,7 @@ void EndFrame()
 float redirection_timeout;
 float redirection_nextthink;
 float RedirectionThink()
-{SELFPARAM();
+{
        float clients_found;
 
        if(redirection_target == "")
@@ -2031,13 +2048,12 @@ float RedirectionThink()
 
        clients_found = 0;
        FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
-               setself(it);
                // TODO add timer
-               LOG_INFO("Redirecting: sending connect command to ", self.netname, "\n");
+               LOG_INFO("Redirecting: sending connect command to ", it.netname, "\n");
                if(redirection_target == "self")
-                       stuffcmd(self, "\ndisconnect; defer ", ftos(autocvar_quit_and_redirect_timer), " reconnect\n");
+                       stuffcmd(it, "\ndisconnect; defer ", ftos(autocvar_quit_and_redirect_timer), " reconnect\n");
                else
-                       stuffcmd(self, strcat("\ndisconnect; defer ", ftos(autocvar_quit_and_redirect_timer), " \"connect ", redirection_target, "\"\n"));
+                       stuffcmd(it, strcat("\ndisconnect; defer ", ftos(autocvar_quit_and_redirect_timer), " \"connect ", redirection_target, "\"\n"));
                ++clients_found;
        ));