diff options
author | mekolat <mekolat@users.noreply.github.com> | 2015-09-24 23:28:47 +0000 |
---|---|---|
committer | mekolat <mekolat@users.noreply.github.com> | 2015-09-26 21:22:04 +0000 |
commit | 69f5372502cb99fb9fe7f53ecd59ff2377237a5b (patch) | |
tree | 120c45ad8835ee8e5b57761d049ea2ded820e0c8 | |
parent | f78d7fea310ba0b3d587e7409ea0b56e5bc9dbd0 (diff) | |
download | tmwa-69f5372502cb99fb9fe7f53ecd59ff2377237a5b.tar.gz tmwa-69f5372502cb99fb9fe7f53ecd59ff2377237a5b.tar.bz2 tmwa-69f5372502cb99fb9fe7f53ecd59ff2377237a5b.tar.xz tmwa-69f5372502cb99fb9fe7f53ecd59ff2377237a5b.zip |
add arithmetic mean builtin
-rw-r--r-- | src/map/script-fun.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 23702e5..2407b37 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -371,6 +371,18 @@ void builtin_min(ScriptState *st) } static +void builtin_average(ScriptState *st) +{ + int total, i; + total = conv_num(st, &AARG(0)); + + for (i = 1; HARG(i); i++) + total += conv_num(st, &AARG(i)); + + push_int<ScriptDataInt>(st->stack, (total / i)); +} + +static void builtin_sqrt(ScriptState *st) { push_int<ScriptDataInt>(st->stack, static_cast<int>(sqrt(conv_num(st, &AARG(0))))); @@ -3449,6 +3461,7 @@ BuiltinFunction builtin_functions[] = BUILTIN(if_then_else, "iii"_s, '.'), BUILTIN(max, "e?*"_s, 'i'), BUILTIN(min, "ii*"_s, 'i'), + BUILTIN(average, "ii*"_s, 'i'), BUILTIN(sqrt, "i"_s, 'i'), BUILTIN(cbrt, "i"_s, 'i'), BUILTIN(pow, "ii"_s, 'i'), |