From: Rudolf Polzer Date: Tue, 25 Jan 2011 06:47:48 +0000 (+0100) Subject: change extend/reducematchtime from an rpn alias into QC logic X-Git-Tag: xonotic-v0.5.0~316^2~17 X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=d7cca4c6d0a76ece4262414d5675f9f1da13af59;hp=369c41ba58307ed13e4d7c954c4ce50ff750f714 change extend/reducematchtime from an rpn alias into QC logic --- diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index d4bce3e6c0..8fa273a1d0 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -1500,8 +1500,8 @@ set timelimit_increment 5 set timelimit_decrement 5 set timelimit_min 5 set timelimit_max 60 -alias extendmatchtime "sv_cmd rpn /timelimit timelimit timelimit_max timelimit timelimit_increment add bound def" -alias reducematchtime "sv_cmd rpn /timelimit timelimit timelimit_decrement sub timelimit_min timelimit bound def" +alias extendmatchtime "sv_cmd extendmatchtime" +alias reducematchtime "sv_cmd reducematchtime" alias endmatch "timelimit -1" // useful keybind to maximize the chat area temporarily diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index 26ea84446d..cb22f99496 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -1186,6 +1186,10 @@ float autocvar_teamplay_lockonrestart; float autocvar_teamplay_mode; #define autocvar_timelimit cvar("timelimit") #define autocvar_timelimit_override cvar("timelimit_override") +float autocvar_timelimit_increment; +float autocvar_timelimit_decrement; +float autocvar_timelimit_min; +float autocvar_timelimit_max; float autocvar_timelimit_overtime; float autocvar_timelimit_overtimes; float autocvar_timelimit_suddendeath; diff --git a/qcsrc/server/gamecommand.qc b/qcsrc/server/gamecommand.qc index 5957e82bc1..b15e6988f4 100644 --- a/qcsrc/server/gamecommand.qc +++ b/qcsrc/server/gamecommand.qc @@ -626,6 +626,47 @@ void make_mapinfo_Think() } } +void changematchtime(float delta, float mi, float ma) +{ + float cur; + float new; + float lim; + + if(delta == 0) + return; + if(autocvar_timelimit < 0) + return; + + if(mi <= 10) + mi = 10; // at least ten sec in the future + cur = time - game_starttime; + if(cur > 0) + mi += cur; // from current time! + + lim = autocvar_timelimit * 60; + + if(delta > 0) + { + if(lim == 0) + return; // cannot increase any further + else if(lim < ma) + new = min(ma, lim + delta); + else // already above maximum: FAIL + return; + } + else + { + if(lim == 0) // infinite: try reducing to max, if we are allowed to + new = max(mi, ma); + else if(lim > mi) // above minimum: decrease + new = max(mi, lim + delta); + else // already below minimum: FAIL + return; + } + + cvar_set("timelimit", ftos(new)); +} + void GameCommand(string command) { float argc; @@ -653,6 +694,8 @@ void GameCommand(string command) print(" cvar_changes\n"); print(" cvar_purechanges\n"); print(" find classname\n"); + print(" extendmatchtime\n"); + print(" reducematchtime\n"); GameCommand_Vote("help", world); GameCommand_Ban("help"); GameCommand_Generic("help"); @@ -1379,6 +1422,18 @@ void GameCommand(string command) return; } + if(argv(0) == "extendmatchtime") + { + changematchtime(autocvar_timelimit_increment* 60, autocvar_timelimit_min*60, autocvar_timelimit_max*60); + return; + } + + if(argv(0) == "reducematchtime") + { + changematchtime(autocvar_timelimit_decrement*-60, autocvar_timelimit_min*60, autocvar_timelimit_max*60); + return; + } + print("Invalid command. For a list of supported commands, try sv_cmd help.\n"); }