mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
[Map format] fixed player options "canPlay" field
This commit is contained in:
parent
5a01aba9c8
commit
b8d0dfac5f
@ -102,10 +102,20 @@ namespace HeaderDetail
|
||||
"IMPOSSIBLE"
|
||||
};
|
||||
|
||||
enum class ECanPlay
|
||||
{
|
||||
NONE = 0,
|
||||
PLAYER_OR_AI = 1,
|
||||
PLAYER_ONLY = 2,
|
||||
AI_ONLY = 3
|
||||
};
|
||||
|
||||
static const std::vector<std::string> canPlayMap =
|
||||
{
|
||||
"AIOnly",
|
||||
"PlayerOrAI"
|
||||
"",
|
||||
"PlayerOrAI",
|
||||
"PlayerOnly",
|
||||
"AIOnly"
|
||||
};
|
||||
}
|
||||
|
||||
@ -420,12 +430,48 @@ void CMapFormatJson::serializePlayerInfo(JsonSerializeFormat & handler)
|
||||
info.canHumanPlay = false;
|
||||
continue;
|
||||
}
|
||||
info.canComputerPlay = true;
|
||||
}
|
||||
|
||||
serializeAllowedFactions(handler, info.allowedFactions);
|
||||
|
||||
handler.serializeEnum("canPlay", info.canHumanPlay, HeaderDetail::canPlayMap);
|
||||
HeaderDetail::ECanPlay canPlay = HeaderDetail::ECanPlay::NONE;
|
||||
|
||||
if(handler.saving)
|
||||
{
|
||||
if(info.canComputerPlay)
|
||||
{
|
||||
canPlay = info.canHumanPlay ? HeaderDetail::ECanPlay::PLAYER_OR_AI : HeaderDetail::ECanPlay::AI_ONLY;
|
||||
}
|
||||
else
|
||||
{
|
||||
canPlay = info.canHumanPlay ? HeaderDetail::ECanPlay::PLAYER_ONLY : HeaderDetail::ECanPlay::NONE;
|
||||
}
|
||||
}
|
||||
|
||||
handler.serializeEnum("canPlay", canPlay, HeaderDetail::canPlayMap);
|
||||
|
||||
if(!handler.saving)
|
||||
{
|
||||
switch(canPlay)
|
||||
{
|
||||
case HeaderDetail::ECanPlay::PLAYER_OR_AI:
|
||||
info.canComputerPlay = true;
|
||||
info.canHumanPlay = true;
|
||||
break;
|
||||
case HeaderDetail::ECanPlay::PLAYER_ONLY:
|
||||
info.canComputerPlay = false;
|
||||
info.canHumanPlay = true;
|
||||
break;
|
||||
case HeaderDetail::ECanPlay::AI_ONLY:
|
||||
info.canComputerPlay = true;
|
||||
info.canHumanPlay = false;
|
||||
break;
|
||||
default:
|
||||
info.canComputerPlay = false;
|
||||
info.canHumanPlay = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//saving whole structure only if position is valid
|
||||
if(!handler.saving || info.posOfMainTown.valid())
|
||||
|
Loading…
Reference in New Issue
Block a user