From b8d0dfac5fa87c766cb2382643eb0e9365553e81 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Thu, 16 Nov 2017 00:03:27 +0300 Subject: [PATCH] [Map format] fixed player options "canPlay" field --- lib/mapping/MapFormatJson.cpp | 54 ++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/lib/mapping/MapFormatJson.cpp b/lib/mapping/MapFormatJson.cpp index 4154772a4..73840273b 100644 --- a/lib/mapping/MapFormatJson.cpp +++ b/lib/mapping/MapFormatJson.cpp @@ -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 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())