• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

What's the reasoning behind getDeathPenalty's static cast to u_INT32_?

Exeus

Advanced OT User
Joined
Oct 8, 2012
Messages
859
Reaction score
198
So, we have Player:getDeathPenalty() (lua) which internally calls Player::getLostPercent() in player.cpp which returns double like 0.031804801590335649
and then cpp -> lua proxy multiplies it by 100 (which is fair) but then rounds it to uint32? why????

luascript.cpp

Code:
int LuaScriptInterface::luaPlayerGetDeathPenalty(lua_State* L)
{
    // player:getDeathPenalty()
    Player* player = getUserdata<Player>(L, 1);
    if (player) {
        lua_pushnumber(L, static_cast<uint32_t>(player->getLostPercent() * 100)); // what the fuck
    } else {
        lua_pushnil(L);
    }
    return 1;
}


player.cpp

Code:
double Player::getLostPercent() const
{
    int32_t blessingCount = std::bitset<5>(blessings).count();

    // some bullshit removed to increase readability

    double lossPercent;
    if (level >= 25) {
        double tmpLevel = level + (levelPercent / 100.);
        lossPercent = static_cast<double>((tmpLevel + 50) * 50 * ((tmpLevel * tmpLevel) - (5 * tmpLevel) + 8)) / experience;
    } else {
        lossPercent = 10;
    }

    if (isPromoted()) {
        lossPercent *= 0.7;
    }

    return lossPercent * pow(0.92, blessingCount) / 100;
}
 
Last edited:
Because getLostPercent() is the internal multiplier for the loss percentage, deathPenalty is multiplied back up to 100 and rounded to a whole number for a "human-readable" percentage.
 
@Delusion

How's e.g 3.1 less "human readable"? You can always round to n-th place after comma (dot).

I think it's confusing AF, cuz generally when something is "%" then it isn't only pretty, rounded int.
 

Similar threads

Back
Top