]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/g_world.qc
Monsters!
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_world.qc
index f699ababc19af8f4e8bd324574a7b386b6b2c769..bacdce4170d68244ef8871e6bd88dc8a7313e1f1 100644 (file)
@@ -1,3 +1,7 @@
+#define LATENCY_THINKRATE 10
+.float latency_sum;
+.float latency_cnt;
+.float latency_time;
 entity pingplreport;
 void PingPLReport_Think()
 {
@@ -18,6 +22,15 @@ void PingPLReport_Think()
                WriteShort(MSG_BROADCAST, max(1, e.ping));
                WriteByte(MSG_BROADCAST, ceil(e.ping_packetloss * 255));
                WriteByte(MSG_BROADCAST, ceil(e.ping_movementloss * 255));
+
+               // record latency times for clients throughout the match so we can report it to playerstats
+               if(time > (e.latency_time + LATENCY_THINKRATE))
+               {
+                       e.latency_sum += e.ping;
+                       e.latency_cnt += 1;
+                       e.latency_time = time;
+                       //print("sum: ", ftos(e.latency_sum), ", cnt: ", ftos(e.latency_cnt), ", avg: ", ftos(e.latency_sum / e.latency_cnt), ".\n");
+               }
        }
        else
        {
@@ -45,7 +58,7 @@ float world_initialized;
 string GetMapname();
 string GetGametype();
 void GotoNextMap(float reinit);
-void ShuffleMaplist()
+void ShuffleMaplist();
 float(float reinit) DoNextMapOverride;
 
 void SetDefaultAlpha()
@@ -251,6 +264,7 @@ void cvar_changes_init()
                BADCVAR("g_freezetag");
                BADCVAR("g_keepaway");
                BADCVAR("g_keyhunt");
+               BADCVAR("g_td");
                BADCVAR("g_keyhunt_teams");
                BADCVAR("g_keyhunt_teams");
                BADCVAR("g_lms");
@@ -295,12 +309,12 @@ void cvar_changes_init()
                BADCVAR("g_balance_kill_delay");
                BADCVAR("g_ca_point_leadlimit");
                BADCVAR("g_ctf_captimerecord_always");
-               BADCVAR("g_ctf_flag_capture_effects");
                BADCVAR("g_ctf_flag_glowtrails");
-               BADCVAR("g_ctf_flag_pickup_effects");
+               BADCVAR("g_ctf_flag_pickup_verbosename");
                BADCVAR("g_domination_point_leadlimit");
                BADCVAR("g_forced_respawn");
                BADCVAR("g_keyhunt_point_leadlimit");
+               BADPREFIX("g_mod_");
                BADCVAR("g_nexball_goalleadlimit");
                BADCVAR("g_runematch_point_leadlimit");
                BADCVAR("leadlimit_and_fraglimit");
@@ -347,7 +361,8 @@ void cvar_changes_init()
                BADCVAR("gametype");
                BADCVAR("g_antilag");
                BADCVAR("g_balance_teams");
-               BADCVAR("g_balance_teams_force");
+               BADCVAR("g_balance_teams_prevent_imbalance");
+               BADCVAR("g_balance_teams_scorefactor");
                BADCVAR("g_ban_sync_trusted_servers");
                BADCVAR("g_ban_sync_uri");
                BADCVAR("g_ctf_ignore_frags");
@@ -367,7 +382,6 @@ void cvar_changes_init()
                BADCVAR("g_maplist_votable_nodetail");
                BADCVAR("g_maplist_votable_suggestions");
                BADCVAR("g_maxplayers");
-               BADCVAR("g_minstagib");
                BADCVAR("g_mirrordamage");
                BADCVAR("g_nexball_goallimit");
                BADCVAR("g_powerups");
@@ -414,6 +428,11 @@ void cvar_changes_init()
                BADPREFIX("g_warmup_");
                BADPREFIX("sv_ready_restart_");
 
+               // mutators that announce themselves properly to the server browser
+               BADCVAR("g_minstagib");
+               BADCVAR("g_new_toys");
+               BADCVAR("g_nix");
+
                if(autocvar_g_minstagib)
                {
                        BADCVAR("g_grappling_hook");
@@ -533,8 +552,8 @@ void spawnfunc___init_dedicated_server(void)
        self.classname = "worldspawn"; // safeguard against various stuff ;)
 
        // needs to be done so early because of the constants they create
-       RegisterWeapons();
-       RegisterGametypes();
+       CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
+       CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
 
        MapInfo_Enumerate();
        MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
@@ -542,7 +561,6 @@ void spawnfunc___init_dedicated_server(void)
 
 void Map_MarkAsRecent(string m);
 float world_already_spawned;
-void RegisterWeapons();
 void Nagger_Init();
 void ClientInit_Spawn();
 void WeaponStats_Init();
@@ -580,8 +598,8 @@ void spawnfunc_worldspawn (void)
        }
 
        // needs to be done so early because of the constants they create
-       RegisterWeapons();
-       RegisterGametypes();
+       CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
+       CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
 
        ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
 
@@ -633,6 +651,8 @@ void spawnfunc_worldspawn (void)
 
        Map_MarkAsRecent(mapname);
 
+       PlayerStats_Init(); // we need this to be initiated before InitGameplayMode
+
        precache_model ("null"); // we need this one before InitGameplayMode
        InitGameplayMode();
        readlevelcvars();
@@ -763,7 +783,7 @@ void spawnfunc_worldspawn (void)
 
        WeaponStats_Init();
 
-       addstat(STAT_WEAPONS, AS_INT, weapons);
+       WEPSET_ADDSTAT();
        addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
        addstat(STAT_SWITCHINGWEAPON, AS_INT, switchingweapon);
        addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
@@ -801,21 +821,38 @@ void spawnfunc_worldspawn (void)
                addstat(STAT_FROZEN, AS_INT, freezetag_frozen);
                addstat(STAT_REVIVE_PROGRESS, AS_FLOAT, freezetag_revive_progress);
        }
+       
+       if(g_td)
+       {
+               addstat(STAT_CURRENT_WAVE, AS_FLOAT, stat_current_wave);
+               addstat(STAT_TOTALWAVES, AS_FLOAT, stat_totalwaves);
+       }
+       
+       // freeze attacks
+       addstat(STAT_FROZEN, AS_INT, frozen);
+       addstat(STAT_REVIVE_PROGRESS, AS_FLOAT, revive_progress);
 
        // g_movementspeed hack
        addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
        addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
        addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
        addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
-       
+
        // secrets
        addstat(STAT_SECRETS_TOTAL, AS_FLOAT, stat_secrets_total);
        addstat(STAT_SECRETS_FOUND, AS_FLOAT, stat_secrets_found);
        
+       // monsters
+       addstat(STAT_MONSTERS_TOTAL, AS_FLOAT, stat_monsters_total);
+       addstat(STAT_MONSTERS_KILLED, AS_FLOAT, stat_monsters_killed);
+
+       // misc
+       addstat(STAT_RESPAWN_TIME, AS_FLOAT, stat_respawn_time);
+
        next_pingtime = time + 5;
 
        detect_maptype();
-       
+
        // set up information replies for clients and server to use
        lsmaps_reply = "^7Maps available: ";
        lsnewmaps_reply = "^7Maps without a record set: ";
@@ -828,18 +865,18 @@ void spawnfunc_worldspawn (void)
                                        col = "^2";
                                else
                                        col = "^3";
-                                       
+
                                ++j;
-                               
+
                                lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
-                               
+
                                if(g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
                                        lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
                                else if(g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
                                        lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
                        }
        }
-       
+
        lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
        lsnewmaps_reply = strzone(strcat(((!g_race && !g_cts) ? "Need to be playing race or CTS for lsnewmaps to work." : lsnewmaps_reply), "\n"));
 
@@ -862,9 +899,11 @@ void spawnfunc_worldspawn (void)
 
        for(i = 0; i < 10; ++i)
        {
-               records_reply[i] = strzone(getrecords(i));
+               s = getrecords(i);
+               if (s)
+                       records_reply[i] = strzone(s);
        }
-       
+
        ladder_reply = strzone(getladder());
 
        rankings_reply = strzone(getrankings());
@@ -906,7 +945,29 @@ void spawnfunc_worldspawn (void)
                cvar_set("sv_curl_serverpackages", substring(s, 1, -1));
        }
 
-       PlayerStats_Init();
+       // MOD AUTHORS: change this, and possibly remove a few of the blocks below to ignore certain changes
+       modname = "Xonotic";
+       // physics/balance/config changes that count as mod
+       if(cvar_string("g_mod_physics") != cvar_defstring("g_mod_physics"))
+               modname = cvar_string("g_mod_physics");
+       if(cvar_string("g_mod_balance") != cvar_defstring("g_mod_balance"))
+               modname = cvar_string("g_mod_balance");
+       if(cvar_string("g_mod_config") != cvar_defstring("g_mod_config"))
+               modname = cvar_string("g_mod_config");
+       // weird mutators that deserve to count as mod
+       if(autocvar_g_minstagib)
+               modname = "MinstaGib";
+       if(autocvar_g_monsters)
+               modname = "Monsters";
+       // extra mutators that deserve to count as mod
+       MUTATOR_CALLHOOK(SetModname);
+       // weird game types that deserve to count as mod
+       if(g_cts)
+               modname = "CTS";
+       // save it for later
+       modname = strzone(modname);
+
+       WinningConditionHelper(); // set worldstatus
 
        world_initialized = 1;
 }
@@ -1228,7 +1289,7 @@ float DoNextMapOverride(float reinit)
                alreadychangedlevel = TRUE;
                return TRUE;
        }
-       if (autocvar_samelevel) // if samelevel is set, stay on same level
+       if (!reinit && autocvar_samelevel) // if samelevel is set, stay on same level
        {
                localcmd("restart\n");
                alreadychangedlevel = TRUE;
@@ -1242,7 +1303,7 @@ float DoNextMapOverride(float reinit)
                        alreadychangedlevel = TRUE;
                        return TRUE;
                }
-       if(autocvar_lastlevel)
+       if(!reinit && autocvar_lastlevel)
        {
                cvar_settemp_restore();
                localcmd("set lastlevel 0\ntogglemenu 1\n");
@@ -1303,10 +1364,10 @@ float mapvote_initialized;
 void IntermissionThink()
 {
        FixIntermissionClient(self);
-       
+
        float server_screenshot = (autocvar_sv_autoscreenshot && self.cvar_cl_autoscreenshot);
        float client_screenshot = (self.cvar_cl_autoscreenshot == 2);
-       
+
        if( (server_screenshot || client_screenshot)
                && ((self.autoscreenshot > 0) && (time > self.autoscreenshot)) )
        {
@@ -1414,6 +1475,8 @@ void DumpStats(float final)
                print(s, "\n");
        if(to_eventlog)
                GameLogEcho(s);
+
+       file = -1;
        if(to_file)
        {
                file = fopen(autocvar_sv_logscores_filename, FILE_APPEND);
@@ -1514,7 +1577,7 @@ void FixIntermissionClient(entity e)
        }
 }
 
-
+void minstagib_stop_countdown(entity e);
 /*
 go to the next level for deathmatch
 only called if a time or frag limit has expired
@@ -1558,6 +1621,7 @@ void NextLevel()
        GameLogClose();
 
        FOR_EACH_PLAYER(other) {
+               minstagib_stop_countdown(other);
                FixIntermissionClient(other);
                if(other.winning)
                        bprint(other.netname, " ^7wins.\n");
@@ -1566,6 +1630,8 @@ void NextLevel()
        if(autocvar_g_campaign)
                CampaignPreIntermission();
 
+       MUTATOR_CALLHOOK(MatchEnd);
+
        localcmd("\nsv_hook_gameend\n");
 }
 
@@ -1604,7 +1670,7 @@ float InitiateSuddenDeath()
        // - for this timelimit_overtime needs to be >0 of course
        // - also check the winning condition calculated in the previous frame and only add normal overtime
        //   again, if at the point at which timelimit would be extended again, still no winner was found
-       if ((checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < autocvar_timelimit_overtimes) && autocvar_timelimit_overtime && !(g_race && !g_race_qualifying))
+       if (!autocvar_g_campaign && (checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < autocvar_timelimit_overtimes) && autocvar_timelimit_overtime && !(g_race && !g_race_qualifying))
        {
                return 1; // need to call InitiateOvertime later
        }
@@ -1612,7 +1678,10 @@ float InitiateSuddenDeath()
        {
                if(!checkrules_suddendeathend)
                {
-                       checkrules_suddendeathend = time + 60 * autocvar_timelimit_suddendeath;
+                       if(autocvar_g_campaign)
+                               checkrules_suddendeathend = time; // no suddendeath in campaign
+                       else
+                               checkrules_suddendeathend = time + 60 * autocvar_timelimit_suddendeath;
                        if(g_race && !g_race_qualifying)
                                race_StartCompleting();
                }
@@ -1946,6 +2015,9 @@ float WinningCondition_Scores(float limit, float leadlimit)
                        limitreached = (limitreached || leadlimitreached);
        }
 
+       if(limit)
+               game_completion_ratio = max(game_completion_ratio, bound(0, WinningConditionHelper_topscore / limit, 1));
+
        return GetWinningCode(
                WinningConditionHelper_topscore && limitreached,
                WinningConditionHelper_equality
@@ -1976,7 +2048,6 @@ float WinningCondition_Race(float fraglimit)
                return WINNING_STARTSUDDENDEATHOVERTIME;
        else
                return WINNING_NEVER;
-       return wc;
 }
 
 float WinningCondition_QualifyingThenRace(float limit)
@@ -2041,10 +2112,14 @@ float WinningCondition_RanOutOfSpawns()
        else if(team1_score + team2_score + team3_score + team4_score == 1)
        {
                float t, i;
-               if(team1_score) t = COLOR_TEAM1;
-               if(team2_score) t = COLOR_TEAM2;
-               if(team3_score) t = COLOR_TEAM3;
-               if(team4_score) t = COLOR_TEAM4;
+               if(team1_score)
+                       t = COLOR_TEAM1;
+               else if(team2_score)
+                       t = COLOR_TEAM2;
+               else if(team3_score)
+                       t = COLOR_TEAM3;
+               else // if(team4_score)
+                       t = COLOR_TEAM4;
                CheckAllowedTeams(world);
                for(i = 0; i < MAX_TEAMSCORE; ++i)
                {
@@ -2061,6 +2136,36 @@ float WinningCondition_RanOutOfSpawns()
                return WINNING_NO;
 }
 
+// TD winning condition:
+// game terminates if there are no generators (or 1 dies if td_dontend is TRUE)
+float gensurvived;
+float WinningCondition_TowerDefense()
+{
+       WinningConditionHelper(); // set worldstatus
+
+       if(inWarmupStage)
+               return WINNING_NO;
+
+       // first check if the game has ended
+       if(gendestroyed == TRUE) // FALSE means either generator hasen't spawned yet, or mapper didn't add one
+       if(td_gencount < 1 || !td_dont_end)
+       {
+               ClearWinners();
+               dprint("Everyone lost, ending game.\n");
+               return WINNING_YES;
+       }
+       
+       if(gensurvived)
+       {
+               ClearWinners();
+               SetWinners(winning, 4);
+               return WINNING_YES;
+       }
+
+       // Two or more teams remain
+       return WINNING_NO;
+}
+
 /*
 ============
 CheckRules_World
@@ -2113,9 +2218,6 @@ void CheckRules_World()
                leadlimit = 0; // no leadlimit for now
        }
 
-       if(g_onslaught)
-               timelimit = 0; // ONS has its own overtime rule
-
        if(timelimit > 0)
        {
                timelimit += game_starttime;
@@ -2127,9 +2229,17 @@ void CheckRules_World()
                return;
        }
 
+       if(g_onslaught)
+               timelimit = 0; // ONS has its own overtime rule
+
        float wantovertime;
        wantovertime = 0;
 
+       if(timelimit > game_starttime)
+               game_completion_ratio = (time - game_starttime) / (timelimit - game_starttime);
+       else
+               game_completion_ratio = 0;
+
        if(checkrules_suddendeathend)
        {
                if(!checkrules_suddendeathwarning)
@@ -2211,6 +2321,10 @@ void CheckRules_World()
        {
                checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
        }
+       else if(g_td)
+       {
+               checkrules_status = WinningCondition_TowerDefense(); // TODO make these mutator hooks?
+       }
        else
        {
                checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
@@ -2287,7 +2401,7 @@ string MapVote_Suggest(string m)
        if(mapvote_initialized)
                return "Can't suggest - voting is already in progress!";
        m = MapInfo_FixName(m);
-       if(!m)
+       if not(m)
                return "The map you suggested is not available on this server.";
        if(!autocvar_g_maplist_votable_suggestions_override_mostrecent)
                if(Map_IsRecent(m))
@@ -2332,6 +2446,7 @@ void MapVote_AddVotable(string nextMap, float isSuggestion)
        mapvote_maps[mapvote_count] = strzone(nextMap);
        mapvote_maps_suggested[mapvote_count] = isSuggestion;
 
+       pakfile = string_null;
        for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
        {
                mapfile = strcat(mapvote_screenshot_dirs[i], "/", mapvote_maps[i]);
@@ -2837,11 +2952,12 @@ float RedirectionThink()
        clients_found = 0;
        FOR_EACH_REALCLIENT(self)
        {
+               // TODO add timer
                print("Redirecting: sending connect command to ", self.netname, "\n");
                if(redirection_target == "self")
-                       stuffcmd(self, "\ndisconnect; reconnect\n");
+                       stuffcmd(self, "\ndisconnect; defer ", ftos(autocvar_quit_and_redirect_timer), " reconnect\n");
                else
-                       stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
+                       stuffcmd(self, strcat("\ndisconnect; defer ", ftos(autocvar_quit_and_redirect_timer), " \"connect ", redirection_target, "\"\n"));
                ++clients_found;
        }