mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
Cleanup
This commit is contained in:
parent
8493d0cded
commit
a5b72ce593
@ -19,7 +19,7 @@ SHeroName::SHeroName() : heroId(-1)
|
||||
|
||||
PlayerInfo::PlayerInfo(): canHumanPlay(false), canComputerPlay(false),
|
||||
aiTactic(EAiTactic::RANDOM), isFactionRandom(false), mainCustomHeroPortrait(-1), mainCustomHeroId(-1), hasMainTown(false),
|
||||
generateHeroAtMainTown(false), team(255), hasRandomHero(false), /* following are unused */ generateHero(false), p7(0), powerPlaceholders(-1)
|
||||
generateHeroAtMainTown(false), team(TeamID::NO_TEAM), hasRandomHero(false), /* following are unused */ generateHero(false), p7(0), powerPlaceholders(-1)
|
||||
{
|
||||
allowedFactions = VLC->townh->getAllowedFactions();
|
||||
}
|
||||
@ -326,7 +326,7 @@ bool CMap::isCoastalTile(const int3 & pos) const
|
||||
if(!isInTheMap(pos))
|
||||
{
|
||||
logGlobal->errorStream() << "Coastal check outside of map :"<<pos;
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(isWaterTile(pos))
|
||||
@ -334,14 +334,14 @@ bool CMap::isCoastalTile(const int3 & pos) const
|
||||
|
||||
for (auto & dir : dirs)
|
||||
{
|
||||
const int3 hlp = pos + dir;
|
||||
|
||||
const int3 hlp = pos + dir;
|
||||
|
||||
if(!isInTheMap(hlp))
|
||||
continue;
|
||||
const TerrainTile &hlpt = getTile(hlp);
|
||||
if(hlpt.isWater())
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ struct DLL_LINKAGE PlayerInfo
|
||||
bool hasMainTown; /// The default value is false.
|
||||
bool generateHeroAtMainTown; /// The default value is false.
|
||||
int3 posOfMainTown;
|
||||
TeamID team; /// The default value is 255 representing that the player belongs to no team.
|
||||
TeamID team; /// The default value NO_TEAM
|
||||
bool hasRandomHero; /// Player has a random hero
|
||||
|
||||
bool generateHero; /// Unused.
|
||||
|
@ -337,9 +337,10 @@ void CMapLoaderJson::readPlayerInfo(PlayerInfo& info, const JsonNode& input)
|
||||
{
|
||||
//allowed factions
|
||||
|
||||
info.isFactionRandom = input["randomFaction"].Bool();
|
||||
info.canComputerPlay = input["canComputerPlay"].Bool();
|
||||
info.canHumanPlay = input["canHumanPlay"].Bool();
|
||||
// info.isFactionRandom =
|
||||
|
||||
info.canComputerPlay = true;
|
||||
info.canHumanPlay = input["canPlay"].String() != "AIOnly";
|
||||
|
||||
//placedHeroes
|
||||
|
||||
@ -347,13 +348,11 @@ void CMapLoaderJson::readPlayerInfo(PlayerInfo& info, const JsonNode& input)
|
||||
|
||||
info.generateHeroAtMainTown = input["generateHeroAtMainTown"].Bool();
|
||||
|
||||
info.hasRandomHero = input["randomHero"].Bool();
|
||||
|
||||
//mainHero
|
||||
|
||||
//mainHeroPortrait
|
||||
|
||||
info.mainCustomHeroName = input["mainHeroName"].String();
|
||||
//mainCustomHeroName
|
||||
}
|
||||
|
||||
void CMapLoaderJson::readTeams(const JsonNode& input)
|
||||
@ -387,10 +386,20 @@ void CMapLoaderJson::readTeams(const JsonNode& input)
|
||||
PlayerColor player = PlayerColor(vstd::find_pos(MapHeaderDetail::playerColorNames, playerData.String()));
|
||||
if(player.isValidPlayer())
|
||||
{
|
||||
map->players[player.getNum()].team = TeamID(team);
|
||||
if(map->players[player.getNum()].canAnyonePlay())
|
||||
{
|
||||
map->players[player.getNum()].team = TeamID(team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(PlayerInfo & player : map->players)
|
||||
{
|
||||
if(player.canAnyonePlay() && player.team == TeamID::NO_TEAM)
|
||||
player.team = TeamID(mapHeader->howManyTeams++);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -635,24 +644,15 @@ void CMapSaverJson::writePlayerInfo(const PlayerInfo & info, JsonNode & output)
|
||||
{
|
||||
//allowed factions
|
||||
|
||||
output["randomFaction"].Bool() = info.isFactionRandom;
|
||||
|
||||
output["canComputerPlay"].Bool() = info.canComputerPlay;
|
||||
output["canHumanPlay"].Bool() = info.canHumanPlay;
|
||||
|
||||
//plasedHeroes
|
||||
output["canPlay"].String() = info.canHumanPlay ? "PlayerOrAI" : "AIOnly";
|
||||
|
||||
//mainTown
|
||||
|
||||
output["generateHeroAtMainTown"].Bool() = info.generateHeroAtMainTown;
|
||||
|
||||
output["randomHero"].Bool() = info.hasRandomHero;
|
||||
|
||||
//mainHero
|
||||
|
||||
//mainHeroPortrait
|
||||
|
||||
output["mainHeroName"].String() = info.mainCustomHeroName;
|
||||
//towns
|
||||
//heroes
|
||||
}
|
||||
|
||||
void CMapSaverJson::writeTeams(JsonNode& output)
|
||||
@ -667,16 +667,19 @@ void CMapSaverJson::writeTeams(JsonNode& output)
|
||||
{
|
||||
const PlayerInfo & player = map->players.at(idx);
|
||||
int team = player.team.getNum();
|
||||
if(vstd::isbetween(team, 0, map->howManyTeams-1))
|
||||
if(vstd::isbetween(team, 0, map->howManyTeams-1) && player.canAnyonePlay())
|
||||
teamsData.at(team).insert(PlayerColor(idx));
|
||||
}
|
||||
|
||||
//just an optimization but breaks test
|
||||
#if 0
|
||||
//remove single-member teams
|
||||
vstd::erase_if(teamsData, [](std::set<PlayerColor> & elem) -> bool
|
||||
{
|
||||
return elem.size() <= 1;
|
||||
});
|
||||
#endif
|
||||
|
||||
//construct output
|
||||
dest.setType(JsonNode::DATA_VECTOR);
|
||||
|
||||
for(const std::set<PlayerColor> & teamData : teamsData)
|
||||
|
Loading…
x
Reference in New Issue
Block a user