1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Remove bitmasks of PlayerColor's. Add encode/decode methods

This commit is contained in:
Ivan Savenko
2023-08-25 21:40:19 +03:00
parent f79492e5b0
commit a30e7ba321
13 changed files with 56 additions and 142 deletions

View File

@ -443,8 +443,9 @@ void CGPandoraBox::serializeJsonOptions(JsonSerializeFormat & handler)
void CGEvent::onHeroVisit( const CGHeroInstance * h ) const
{
if(!(availableFor & (1 << h->tempOwner.getNum())))
if(availableFor.count(h->tempOwner) == 0)
return;
if(cb->getPlayerSettings(h->tempOwner)->isControlledByHuman())
{
if(humanActivate)
@ -490,20 +491,7 @@ void CGEvent::serializeJsonOptions(JsonSerializeFormat & handler)
handler.serializeBool<bool>("aIActivable", computerActivate, true, false, false);
handler.serializeBool<bool>("humanActivable", humanActivate, true, false, true);
handler.serializeBool<bool>("removeAfterVisit", removeAfterVisit, true, false, false);
{
auto decodePlayer = [](const std::string & id)->si32
{
return vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, id);
};
auto encodePlayer = [](si32 idx)->std::string
{
return GameConstants::PLAYER_COLOR_NAMES[idx];
};
handler.serializeIdArray<ui8, PlayerColor::PLAYER_LIMIT_I>("availableFor", availableFor, GameConstants::ALL_PLAYERS, decodePlayer, encodePlayer);
}
handler.serializeIdArray("availableFor", availableFor);
}
VCMI_LIB_NAMESPACE_END