Skip to content

Commit

Permalink
classes: Refactor toNetValue() for better diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaffeine committed Nov 24, 2024
1 parent 0431d08 commit 0bbd530
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/game/infclass/classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ enum PLAYERCLASS
PLAYERCLASS_UNDEAD,
PLAYERCLASS_TANK,
END_INFECTEDCLASS,

NB_PLAYERCLASS,
NB_HUMANCLASS = END_HUMANCLASS - START_HUMANCLASS - 1,
NB_INFECTEDCLASS = END_INFECTEDCLASS - START_INFECTEDCLASS - 1,
};

}

int toNetValue(EPlayerClass C)
{
constexpr int HumanClassOffset = PLAYERCLASS_MERCENARY - static_cast<int>(EPlayerClass::Mercenary);
static_assert(static_cast<int>(AllHumanClasses.Last()) + HumanClassOffset < END_HUMANCLASS,
"Added human class requires extra code to preserve network compatibilty");

if (C == EPlayerClass::None)
return PLAYERCLASS_NONE;

Expand All @@ -56,7 +56,6 @@ int toNetValue(EPlayerClass C)
}
else
{
constexpr int HumanClassOffset = PLAYERCLASS_MERCENARY - static_cast<int>(EPlayerClass::Mercenary);
return Value + HumanClassOffset;
}
}
Expand Down

0 comments on commit 0bbd530

Please sign in to comment.