Understanding the "BuildplayerLevelInfo" function

So, looking through the engine, I found this particular piece of code.

void ObjectMgr::BuildPlayerLevelInfo(uint8 race, uint8 _class, uint8 level, PlayerLevelInfo* info) const
{
// base data (last known level)
*info = _playerInfo[race][_class]->levelInfo[sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)-1];

// if conversion from uint32 to uint8 causes unexpected behaviour, change lvl to uint32
for (uint8 lvl = sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)-1; lvl < level; ++lvl)
{
    switch (_class)
    {
        case CLASS_WARRIOR:
            info->stats[STAT_STRENGTH]  += (lvl > 23 ? 2: (lvl > 1  ? 1: 0));
            info->stats[STAT_STAMINA]   += (lvl > 23 ? 2: (lvl > 1  ? 1: 0));
            info->stats[STAT_AGILITY]   += (lvl > 36 ? 1: (lvl > 6 && (lvl%2) ? 1: 0));
            info->stats[STAT_INTELLECT] += (lvl > 9 && !(lvl%2) ? 1: 0);
            info->stats[STAT_SPIRIT]    += (lvl > 9 && !(lvl%2) ? 1: 0);
            break;
    }
}

}
Located within the ObjectMgr.cpp.

I understand that it defines the stats, but I don’t understand how this math is supposed to work.

“[…] In C-descended languages, “?” is part of the ?: operator, which is used to evaluate simple boolean conditions. In C# 2.0, the “?” modifier and the “??” operator are used to handle nullable data types.[…]” - Quoted from the “Question mark” article on Wikipedia

So if I understand it right, than:

  • Over level 23, 2 is used in the caluclation, while over level 1 number 1 is used… while I don’t understand the 0 at the end. But that doesn’t make remotely sense.

So I hope someone can sheet some lights on this topic for me, please. Thanks in advance!

Nested ?: operators are evil.

info->stats[STAT_STRENGTH] += (lvl > 23 ? 2: (lvl > 1 ? 1: 0));can be written as

if (lvl > 23)
info->stats[STAT_STRENGTH] += 2;
else if (lvl > 1)
info->stats[STAT_STRENGTH] += 1;
else // should never happen
info->stats[STAT_STRENGTH] += 0;
and

info->stats[STAT_AGILITY] += (lvl > 36 ? 1: (lvl > 6 && (lvl%2) ? 1: 0));to

if (lvl > 36)
     info->stats[STAT_AGILITY] += 1;
else if (lvl > 6 && isEven(lvl)) // isEven returns true if number is divisible by 2 (0,2,4,6,8,etc)
     info->stats[STAT_AGILITY] += 1;
else
     info->stats[STAT_AGILITY] += 0;

That makes a lot more sense than I was thinking lol. Thanks xD

This helped me out a lot. Thanks, appreciating it!

The fuck is this code doing there…

I have no idea actually. I tried to understand it in the first place /emoticons/default_smile.png