From b5915307d91b8bd31c554c60b57791383f88edda Mon Sep 17 00:00:00 2001 From: Streusel Date: Fri, 15 May 2015 21:01:18 -0700 Subject: Added floor(), ceil() and log() functions for usage in scripts. --- doc/script_commands.txt | 28 +++++++++++++++++++++++++++ src/map/script.c | 50 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 831e0a744..13b154560 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -7646,6 +7646,34 @@ Example: --------------------------------------- + +*floor() + +Returns the number rounded down. + +Example: + .@i = floor(2.5); // .@i will be 2 + +--------------------------------------- + +*ceil() + +Returns the number rounded up. + +Example: + .@i = ceil(2.5); // .@i will be 3 + +--------------------------------------- + +*log() + +Returns log base 10 of the number. + +Example: + .@i = log(100); // .@i will be 2 + +--------------------------------------- + *sqrt() Returns square-root of number. diff --git a/src/map/script.c b/src/map/script.c index ed4f9e918..03f5b13a3 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -15476,8 +15476,35 @@ BUILDIN(compare) return true; } -// [zBuffer] List of mathematics commands ---> -BUILDIN(sqrt) +// List of mathematics commands ---> +BUILDIN(floor) +{ + double i, a; + i = script_getnum(st,2); + a = floor(i); + script_pushint(st,(int)a); + return true; +} + +BUILDIN(ceil) +{ + double i, a; + i = script_getnum(st,2); + a = ceil(i); + script_pushint(st,(int)a); + return true; +} + +BUILDIN(log) +{ + double i, a; + i = script_getnum(st,2); + a = log(i); + script_pushint(st,(int)a); + return true; +} + +BUILDIN(sqrt) //[zBuffer] { double i, a; i = script_getnum(st,2); @@ -15486,7 +15513,7 @@ BUILDIN(sqrt) return true; } -BUILDIN(pow) +BUILDIN(pow) //[zBuffer] { double i, a, b; a = script_getnum(st,2); @@ -15496,7 +15523,7 @@ BUILDIN(pow) return true; } -BUILDIN(distance) +BUILDIN(distance) //[zBuffer] { int x0, y0, x1, y1; @@ -15509,7 +15536,7 @@ BUILDIN(distance) return true; } -// <--- [zBuffer] List of mathematics commands +// <--- List of mathematics commands BUILDIN(min) { @@ -20052,11 +20079,14 @@ void script_parse_builtin(void) { BUILDIN_DEF(getiteminfo,"ii"), //[Lupus] returns Items Buy / sell Price, etc info BUILDIN_DEF(setiteminfo,"iii"), //[Lupus] set Items Buy / sell Price, etc info BUILDIN_DEF(getequipcardid,"ii"), //[Lupus] returns CARD ID or other info from CARD slot N of equipped item - // [zBuffer] List of mathematics commands ---> - BUILDIN_DEF(sqrt,"i"), - BUILDIN_DEF(pow,"ii"), - BUILDIN_DEF(distance,"iiii"), - // <--- [zBuffer] List of mathematics commands + // List of mathematics commands ---> + BUILDIN_DEF(floor,"i"), + BUILDIN_DEF(ceil,"i"), + BUILDIN_DEF(log,"i"), + BUILDIN_DEF(sqrt,"i"), //[zBuffer] + BUILDIN_DEF(pow,"ii"), //[zBuffer] + BUILDIN_DEF(distance,"iiii"), //[zBuffer] + // <--- List of mathematics commands BUILDIN_DEF(min, "i*"), BUILDIN_DEF(max, "i*"), BUILDIN_DEF(md5,"s"), -- cgit v1.2.3-70-g09d2