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

Fix few cases of tempOwner initialization.

This commit is contained in:
AlexVinS
2016-02-14 12:13:30 +03:00
parent 709dd833d5
commit 800f32c4cb
4 changed files with 19 additions and 10 deletions

View File

@ -373,19 +373,22 @@ void CGObjectInstance::readJsonOptions(const JsonNode & json)
void CGObjectInstance::writeOwner(JsonNode & json) const
{
if(tempOwner != PlayerColor::UNFLAGGABLE)
if(tempOwner.isValidPlayer())
{
PlayerColor p (tempOwner);
if(p.isValidPlayer())
json["owner"].String() = GameConstants::PLAYER_COLOR_NAMES[p.getNum()];
json["owner"].String() = GameConstants::PLAYER_COLOR_NAMES[tempOwner.getNum()];
}
}
void CGObjectInstance::readOwner(const JsonNode & json)
{
tempOwner = PlayerColor::NEUTRAL;//this method assumes that object is ownable
if(json["owner"].getType() == JsonNode::DATA_STRING)
{
tempOwner = PlayerColor(vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, json["owner"].String()));
auto rawOwner = vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, json["owner"].String());
if(rawOwner >=0)
tempOwner = PlayerColor(rawOwner);
else
logGlobal->errorStream() << "Invalid owner :" << json["owner"].String();
}
}