From f2651babf6ed91d9fa38fd1468014b731a09154c Mon Sep 17 00:00:00 2001 From: div0 Date: Fri, 25 Jan 2008 15:49:14 +0000 Subject: [PATCH] enhanced the RPN calculator a bit; improved extendmatchtime/reducematchtime git-svn-id: svn://svn.icculus.org/nexuiz/trunk@3274 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/default.cfg | 4 +-- data/qcsrc/common/gamecommand.qc | 46 ++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/data/default.cfg b/data/default.cfg index ffb8f249d..29bd47d34 100644 --- a/data/default.cfg +++ b/data/default.cfg @@ -864,8 +864,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_increment add dup timelimit_max sub dup sgn 0.5 mul 0.5 add mul sub def" -alias reducematchtime "sv_cmd rpn /timelimit timelimit timelimit_decrement sub dup timelimit_min sub dup sgn 0.5 mul 0.5 sub mul add def" +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 endmatch "timelimit -1" // useful keybind to maximize the chat area temporarily diff --git a/data/qcsrc/common/gamecommand.qc b/data/qcsrc/common/gamecommand.qc index 1ae2cfeba..4cb3435e5 100644 --- a/data/qcsrc/common/gamecommand.qc +++ b/data/qcsrc/common/gamecommand.qc @@ -58,8 +58,11 @@ float GameCommand_Generic(string command) print(" x x exch --------------------------> x x : swap the top two\n"); print(" /cvarname load --------------------> x : loads a cvar\n"); print(" /cvarname x def -------------------> : writes to a cvar\n"); - print(" f f add|sub|mul|div|mod -----------> f : adds/... two numbers\n"); + print(" f f add|sub|mul|div|mod|max|min ---> f : adds/... two numbers\n"); + print(" f f eq|ne|gt|ge|lt|le -------------> f : compares two numbers\n"); print(" f neg|abs|sgn|rand ----------------> f : negates/... a number\n"); + print(" f f f bound -----------------------> f : bounds the middle number\n"); + print(" f1 f2 b when ----------------------> f : f1 if b, f2 otherwise\n"); print(" s s union|intersection|difference -> s : set operations\n"); print(" s shuffle -------------------------> s : randomly arrange elements\n"); print(" Set operations operate on 'such''strings' like g_maplist.\n"); @@ -164,7 +167,7 @@ float GameCommand_Generic(string command) { float rpnpos; string rpncmd; - float f2; + float f2, f3; rpn_sp = 0; rpn_error = FALSE; for(rpnpos = 1; rpnpos < argc; ++rpnpos) @@ -231,6 +234,45 @@ float GameCommand_Generic(string command) rpn_set("0"); } else if(rpncmd == "neg" || rpncmd == "~") { rpn_setf(-rpn_getf()); + } else if(rpncmd == "max") { + f = rpn_popf(); + f2 = rpn_getf(); + rpn_setf(max(f2, f)); + } else if(rpncmd == "min") { + f = rpn_popf(); + f2 = rpn_getf(); + rpn_setf(min(f2, f)); + } else if(rpncmd == "bound") { + f = rpn_popf(); + f2 = rpn_popf(); + f3 = rpn_getf(); + rpn_setf(bound(f3, f2, f)); + } else if(rpncmd == "when") { + f = rpn_popf(); + f2 = rpn_popf(); + f3 = rpn_getf(); + if(f) + rpn_setf(f3); + else + rpn_setf(f2); + } else if(rpncmd == ">" || rpncmd == "gt") { + f = rpn_popf(); + rpn_setf(rpn_getf() > f); + } else if(rpncmd == "<" || rpncmd == "lt") { + f = rpn_popf(); + rpn_setf(rpn_getf() < f); + } else if(rpncmd == "==" || rpncmd == "eq") { + f = rpn_popf(); + rpn_setf(rpn_getf() == f); + } else if(rpncmd == ">=" || rpncmd == "ge") { + f = rpn_popf(); + rpn_setf(rpn_getf() >= f); + } else if(rpncmd == "<=" || rpncmd == "le") { + f = rpn_popf(); + rpn_setf(rpn_getf() <= f); + } else if(rpncmd == "!=" || rpncmd == "ne") { + f = rpn_popf(); + rpn_setf(rpn_getf() != f); } else if(rpncmd == "rand") { rpn_setf(ceil(random() * rpn_getf()) - 1); } else if(rpncmd == "union") { -- 2.39.2