Skip to content

Commit

Permalink
Added floor(), ceil() and log() functions for usage in scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Streusel committed May 16, 2015
1 parent 6e3f2f6 commit b591530
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
28 changes: 28 additions & 0 deletions doc/script_commands.txt
Expand Up @@ -7646,6 +7646,34 @@ Example:

---------------------------------------


*floor(<number>)

Returns the number rounded down.

Example:
.@i = floor(2.5); // .@i will be 2

---------------------------------------

*ceil(<number>)

Returns the number rounded up.

Example:
.@i = ceil(2.5); // .@i will be 3

---------------------------------------

*log(<number>)

Returns log base 10 of the number.

Example:
.@i = log(100); // .@i will be 2

---------------------------------------

*sqrt(<number>)

Returns square-root of number.
Expand Down
50 changes: 40 additions & 10 deletions src/map/script.c
Expand Up @@ -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);
Expand All @@ -15486,7 +15513,7 @@ BUILDIN(sqrt)
return true;
}

BUILDIN(pow)
BUILDIN(pow) //[zBuffer]
{
double i, a, b;
a = script_getnum(st,2);
Expand All @@ -15496,7 +15523,7 @@ BUILDIN(pow)
return true;
}

BUILDIN(distance)
BUILDIN(distance) //[zBuffer]
{
int x0, y0, x1, y1;

Expand All @@ -15509,7 +15536,7 @@ BUILDIN(distance)
return true;
}

// <--- [zBuffer] List of mathematics commands
// <--- List of mathematics commands

BUILDIN(min)
{
Expand Down Expand Up @@ -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"),
Expand Down

1 comment on commit b591530

@Streusel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followup in c9f845f and 48ec81d

Please sign in to comment.