From c447528402f903a5ca3e8eec0ad36b52815b992c Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Sat, 15 Dec 2018 18:00:20 -0200 Subject: log2 function, golbarez rewards, main quest restriction, gift count --- npc/functions/math.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'npc/functions') diff --git a/npc/functions/math.txt b/npc/functions/math.txt index 004125c7b..a7be729a3 100644 --- a/npc/functions/math.txt +++ b/npc/functions/math.txt @@ -38,3 +38,31 @@ function script lognbaselvl { return .@ret; } + +// log2() +// returns the log base 2 of the passed integer, up to 20 (2**20=1.048.576) (round down always) + +function script log2 { + .@v=abs(getarg(0)); + .@ok=0; + .@i=0; + + freeloop(true); + while (!.@ok) { + // exact match + if (2**.@i == .@v) { + .@ok=1; + // inexact match, or limit exceeded + } if (2**.@i >= .@v || .@i > 20) { + .@ok=1; + .@i-=1; // round down + // not yet + } else { + .@i+=1; + } + } + freeloop(false); + + return .@i; +} + -- cgit v1.2.3-60-g2f50