//===== heRO Server =========================================================================================
//= Useful (?) Functions
//===== By ==================================================================================================
//= Gianluca
//===== Revision ============================================================================================
//= GM-Garr
//===== Version =============================================================================================
//= 1.0 -
//===== Description: ========================================================================================
//= Just some math and bitmask functions that may be useful
//
//===== Variables used by the script ============================\\
//=
//===== Functions ===============================================\\
//= Abs Return the absolute value of a number. e.g. Abs(3) = 3; Abs(-3) = 3;
//= popcount Return the number of bits set on a value sent. e.g. popcount(5) = 2; //5 = 0b...00101
//= Logx Return the truncated value of logarithm on base x of a value sent. eg Logx(2,8) = 3;
//= Get_Rep Change player reputation on some faction.
//===============================================================
function script Abs {
if(getarg(0) >= 0) return getarg(0);
return (-getarg(0));
}
function script popcount {
for(.@i = 0; .@i < 32; ++.@i)
.@v += ((getarg(0)&(1 << .@i)) != 0);
return .@v;
}
function script Logx {
.@base = getarg(0,10);
.@value = getarg(1);
if(.@base < 2){
debugmes "Error with Logx function. Attempt to use invalid base.";
logmes "Error with Logx function. Attempt to use invalid base.";
return -1;
}
if(.@value < 1){
debugmes "Error with Logx function. Attempt to use invalid value.";
logmes "Error with Logx function. Attempt to use invalid value.";
return -1;
}
while((.@value/.@base) > 0){
.@value /= .@base;
++.@result;
}
return .@result;
}
function script Get_Rep { //Get_Rep(Town Index, Value);
setarray .@Towns$, "Porings", "Fairies", "Orcs", "Lutia People";
.@index = getarg(0);
.@value = getarg(1);
Town_Rep[.@index] += .@value;
if(Town_Rep[.@index] > 10000) Town_Rep[.@index] = 10000;
if(Town_Rep[.@index] < -10000) Town_Rep[.@index] = -10000;
dispbottom "You "+((.@value > 0)? "got":"lost")+" "+callfunc("Abs", .@value)+" reputation with the "+.@Towns$[.@index]+ ".";
return;
}