2013-08-17 15:46:48 +03:00
|
|
|
/*
|
|
|
|
* CMapGenOptions.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
2023-07-08 10:26:10 +02:00
|
|
|
#include "CMapGenOptions.h"
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2024-07-21 12:49:40 +02:00
|
|
|
#include "../entities/faction/CTownHandler.h"
|
|
|
|
#include "../entities/faction/CFaction.h"
|
2023-05-24 01:05:59 +02:00
|
|
|
#include "../mapping/CMapHeader.h"
|
2013-08-17 15:46:48 +03:00
|
|
|
#include "CRmgTemplateStorage.h"
|
|
|
|
#include "CRmgTemplate.h"
|
|
|
|
#include "../VCMI_Lib.h"
|
2024-02-29 13:45:08 +02:00
|
|
|
#include "serializer/JsonSerializeFormat.h"
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2024-06-01 17:28:17 +02:00
|
|
|
#include <vstd/RNG.h>
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
CMapGenOptions::CMapGenOptions()
|
|
|
|
: width(CMapHeader::MAP_SIZE_MIDDLE), height(CMapHeader::MAP_SIZE_MIDDLE), hasTwoLevels(true),
|
2023-10-28 20:30:38 +02:00
|
|
|
humanOrCpuPlayerCount(RANDOM_SIZE), teamCount(RANDOM_SIZE), compOnlyPlayerCount(RANDOM_SIZE), compOnlyTeamCount(RANDOM_SIZE),
|
|
|
|
waterContent(EWaterContent::RANDOM), monsterStrength(EMonsterStrength::RANDOM), mapTemplate(nullptr),
|
|
|
|
customizedPlayers(false)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2023-08-01 08:23:09 +02:00
|
|
|
initPlayersMap();
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
si32 CMapGenOptions::getWidth() const
|
|
|
|
{
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::setWidth(si32 value)
|
|
|
|
{
|
|
|
|
assert(value >= 1);
|
|
|
|
width = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
si32 CMapGenOptions::getHeight() const
|
|
|
|
{
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::setHeight(si32 value)
|
|
|
|
{
|
|
|
|
assert(value >= 1);
|
|
|
|
height = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMapGenOptions::getHasTwoLevels() const
|
|
|
|
{
|
|
|
|
return hasTwoLevels;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::setHasTwoLevels(bool value)
|
|
|
|
{
|
|
|
|
hasTwoLevels = value;
|
|
|
|
}
|
|
|
|
|
2023-10-28 20:30:38 +02:00
|
|
|
si8 CMapGenOptions::getHumanOrCpuPlayerCount() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2023-10-28 20:30:38 +02:00
|
|
|
return humanOrCpuPlayerCount;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2023-10-28 20:30:38 +02:00
|
|
|
void CMapGenOptions::setHumanOrCpuPlayerCount(si8 value)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2014-07-26 15:20:33 +03:00
|
|
|
assert((value >= 1 && value <= PlayerColor::PLAYER_LIMIT_I) || value == RANDOM_SIZE);
|
2023-10-28 20:30:38 +02:00
|
|
|
humanOrCpuPlayerCount = value;
|
2015-05-27 18:58:14 +02:00
|
|
|
|
2023-10-28 20:30:38 +02:00
|
|
|
// Use template player limit, if any
|
|
|
|
auto playerLimit = getPlayerLimit();
|
|
|
|
auto possibleCompPlayersCount = playerLimit - std::max<si8>(0, humanOrCpuPlayerCount);
|
2015-05-27 11:30:46 +02:00
|
|
|
if (compOnlyPlayerCount > possibleCompPlayersCount)
|
2023-10-28 20:30:38 +02:00
|
|
|
{
|
2015-03-14 21:19:24 +02:00
|
|
|
setCompOnlyPlayerCount(possibleCompPlayersCount);
|
2023-10-28 20:30:38 +02:00
|
|
|
}
|
2015-05-27 11:30:46 +02:00
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
resetPlayersMap();
|
|
|
|
}
|
|
|
|
|
2023-10-29 22:25:39 +02:00
|
|
|
si8 CMapGenOptions::getMinPlayersCount(bool withTemplateLimit) const
|
2023-10-28 20:30:38 +02:00
|
|
|
{
|
|
|
|
auto totalPlayers = 0;
|
|
|
|
si8 humans = getHumanOrCpuPlayerCount();
|
|
|
|
si8 cpus = getCompOnlyPlayerCount();
|
2023-10-29 22:25:39 +02:00
|
|
|
|
|
|
|
if (humans == RANDOM_SIZE && cpus == RANDOM_SIZE)
|
|
|
|
{
|
|
|
|
totalPlayers = 2;
|
|
|
|
}
|
|
|
|
else if (humans == RANDOM_SIZE)
|
|
|
|
{
|
|
|
|
totalPlayers = cpus + 1; // Must add at least 1 player
|
|
|
|
}
|
|
|
|
else if (cpus == RANDOM_SIZE)
|
|
|
|
{
|
|
|
|
totalPlayers = humans;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
totalPlayers = humans + cpus;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (withTemplateLimit && mapTemplate)
|
|
|
|
{
|
|
|
|
auto playersRange = mapTemplate->getPlayers();
|
|
|
|
|
|
|
|
//New template can also impose higher limit than current settings
|
|
|
|
vstd::amax(totalPlayers, playersRange.minValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can't play without at least 2 players
|
|
|
|
vstd::amax(totalPlayers, 2);
|
|
|
|
return totalPlayers;
|
|
|
|
}
|
|
|
|
|
|
|
|
si8 CMapGenOptions::getMaxPlayersCount(bool withTemplateLimit) const
|
|
|
|
{
|
|
|
|
// Max number of players possible with current settings
|
|
|
|
auto totalPlayers = 0;
|
|
|
|
si8 humans = getHumanOrCpuPlayerCount();
|
|
|
|
si8 cpus = getCompOnlyPlayerCount();
|
2023-10-28 20:30:38 +02:00
|
|
|
if (humans == RANDOM_SIZE || cpus == RANDOM_SIZE)
|
|
|
|
{
|
|
|
|
totalPlayers = PlayerColor::PLAYER_LIMIT_I;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
totalPlayers = humans + cpus;
|
|
|
|
}
|
2023-10-29 22:25:39 +02:00
|
|
|
|
|
|
|
if (withTemplateLimit && mapTemplate)
|
|
|
|
{
|
|
|
|
auto playersRange = mapTemplate->getPlayers();
|
|
|
|
|
|
|
|
//New template can also impose higher limit than current settings
|
|
|
|
vstd::amin(totalPlayers, playersRange.maxValue());
|
|
|
|
}
|
|
|
|
|
2023-10-28 20:30:38 +02:00
|
|
|
assert (totalPlayers <= PlayerColor::PLAYER_LIMIT_I);
|
|
|
|
assert (totalPlayers >= 2);
|
|
|
|
return totalPlayers;
|
|
|
|
}
|
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
si8 CMapGenOptions::getTeamCount() const
|
|
|
|
{
|
|
|
|
return teamCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::setTeamCount(si8 value)
|
|
|
|
{
|
2023-10-28 20:30:38 +02:00
|
|
|
assert(getHumanOrCpuPlayerCount() == RANDOM_SIZE || (value >= 0 && value < getHumanOrCpuPlayerCount()) || value == RANDOM_SIZE);
|
2013-08-17 15:46:48 +03:00
|
|
|
teamCount = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
si8 CMapGenOptions::getCompOnlyPlayerCount() const
|
|
|
|
{
|
|
|
|
return compOnlyPlayerCount;
|
|
|
|
}
|
|
|
|
|
2023-10-28 20:30:38 +02:00
|
|
|
si8 CMapGenOptions::getPlayerLimit() const
|
|
|
|
{
|
2023-10-29 22:25:39 +02:00
|
|
|
//How many players could we set with current template, ignoring other settings
|
2023-10-28 20:30:38 +02:00
|
|
|
si8 playerLimit = PlayerColor::PLAYER_LIMIT_I;
|
|
|
|
if (auto temp = getMapTemplate())
|
|
|
|
{
|
2023-10-29 22:25:39 +02:00
|
|
|
playerLimit = static_cast<si8>(temp->getPlayers().maxValue());
|
2023-10-28 20:30:38 +02:00
|
|
|
}
|
|
|
|
return playerLimit;
|
|
|
|
}
|
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
void CMapGenOptions::setCompOnlyPlayerCount(si8 value)
|
|
|
|
{
|
2023-10-30 22:07:14 +02:00
|
|
|
assert(value == RANDOM_SIZE || (getHumanOrCpuPlayerCount() == RANDOM_SIZE || (value >= 0 && value <= getPlayerLimit() - getHumanOrCpuPlayerCount())));
|
2013-08-17 15:46:48 +03:00
|
|
|
compOnlyPlayerCount = value;
|
2015-05-27 18:58:14 +02:00
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
resetPlayersMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
si8 CMapGenOptions::getCompOnlyTeamCount() const
|
|
|
|
{
|
|
|
|
return compOnlyTeamCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::setCompOnlyTeamCount(si8 value)
|
|
|
|
{
|
|
|
|
assert(value == RANDOM_SIZE || compOnlyPlayerCount == RANDOM_SIZE || (value >= 0 && value <= std::max(compOnlyPlayerCount - 1, 0)));
|
|
|
|
compOnlyTeamCount = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
EWaterContent::EWaterContent CMapGenOptions::getWaterContent() const
|
|
|
|
{
|
|
|
|
return waterContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::setWaterContent(EWaterContent::EWaterContent value)
|
|
|
|
{
|
|
|
|
waterContent = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
EMonsterStrength::EMonsterStrength CMapGenOptions::getMonsterStrength() const
|
|
|
|
{
|
|
|
|
return monsterStrength;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::setMonsterStrength(EMonsterStrength::EMonsterStrength value)
|
|
|
|
{
|
2018-07-26 12:06:55 +02:00
|
|
|
monsterStrength = value;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2023-08-01 08:23:09 +02:00
|
|
|
void CMapGenOptions::initPlayersMap()
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2015-07-18 20:14:45 +02:00
|
|
|
|
2023-04-09 17:26:32 +02:00
|
|
|
std::map<PlayerColor, FactionID> rememberTownTypes;
|
2022-12-17 06:19:16 +02:00
|
|
|
std::map<PlayerColor, TeamID> rememberTeam;
|
2015-07-18 20:14:45 +02:00
|
|
|
|
2023-02-11 18:05:02 +02:00
|
|
|
for(const auto & p : players)
|
2015-07-18 20:14:45 +02:00
|
|
|
{
|
|
|
|
auto town = p.second.getStartingTown();
|
2023-11-02 17:12:58 +02:00
|
|
|
if (town != FactionID::RANDOM)
|
2023-04-09 17:26:32 +02:00
|
|
|
rememberTownTypes[p.first] = FactionID(town);
|
2022-12-17 06:19:16 +02:00
|
|
|
rememberTeam[p.first] = p.second.getTeam();
|
2015-07-18 20:14:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
players.clear();
|
2023-10-28 20:30:38 +02:00
|
|
|
int realPlayersCnt = getHumanOrCpuPlayerCount();
|
2015-03-14 21:19:24 +02:00
|
|
|
|
2023-10-29 11:05:24 +02:00
|
|
|
// Initialize settings for all color even if not present
|
2023-10-28 20:30:38 +02:00
|
|
|
for(int color = 0; color < getPlayerLimit(); ++color)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
CPlayerSettings player;
|
2015-07-18 20:14:45 +02:00
|
|
|
auto pc = PlayerColor(color);
|
|
|
|
player.setColor(pc);
|
2023-10-28 20:30:38 +02:00
|
|
|
|
2015-03-14 21:19:24 +02:00
|
|
|
auto playerType = EPlayerType::AI;
|
2023-10-28 20:30:38 +02:00
|
|
|
// Color doesn't have to be continuous. Player colors can later be changed manually
|
|
|
|
if (getHumanOrCpuPlayerCount() != RANDOM_SIZE && color < realPlayersCnt)
|
2018-10-27 18:18:08 +02:00
|
|
|
{
|
|
|
|
playerType = EPlayerType::HUMAN;
|
2018-10-28 17:36:11 +02:00
|
|
|
}
|
2023-10-28 20:30:38 +02:00
|
|
|
else if((getHumanOrCpuPlayerCount() != RANDOM_SIZE && color >= realPlayersCnt)
|
|
|
|
|| (compOnlyPlayerCount != RANDOM_SIZE && color >= (PlayerColor::PLAYER_LIMIT_I - compOnlyPlayerCount)))
|
2015-03-14 21:19:24 +02:00
|
|
|
{
|
2023-08-01 08:23:09 +02:00
|
|
|
playerType = EPlayerType::COMP_ONLY;
|
|
|
|
}
|
|
|
|
player.setPlayerType(playerType);
|
|
|
|
|
2023-10-28 20:30:38 +02:00
|
|
|
players[pc] = player;
|
2023-08-01 08:23:09 +02:00
|
|
|
}
|
2023-10-28 20:30:38 +02:00
|
|
|
savePlayersMap();
|
2023-08-01 08:23:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::resetPlayersMap()
|
|
|
|
{
|
2023-10-28 20:30:38 +02:00
|
|
|
// Called when number of player changes
|
2023-10-30 08:48:51 +02:00
|
|
|
// But do not update info about already made selections
|
2023-08-01 08:23:09 +02:00
|
|
|
|
2023-10-28 20:30:38 +02:00
|
|
|
savePlayersMap();
|
2023-08-01 08:23:09 +02:00
|
|
|
|
2023-10-29 22:25:39 +02:00
|
|
|
int realPlayersCnt = getMaxPlayersCount();
|
2023-10-26 10:31:41 +02:00
|
|
|
|
2023-10-29 22:25:39 +02:00
|
|
|
//Trim the number of AI players, then CPU-only players, finally human players
|
|
|
|
auto eraseLastPlayer = [this](EPlayerType playerType) -> bool
|
2023-08-01 08:23:09 +02:00
|
|
|
{
|
2023-10-29 22:25:39 +02:00
|
|
|
for (auto it = players.rbegin(); it != players.rend(); ++it)
|
2023-08-01 08:23:09 +02:00
|
|
|
{
|
2023-10-29 22:25:39 +02:00
|
|
|
if (it->second.getPlayerType() == playerType)
|
2023-08-01 08:23:09 +02:00
|
|
|
{
|
2023-10-29 22:25:39 +02:00
|
|
|
players.erase(it->first);
|
|
|
|
return true;
|
2023-08-01 08:23:09 +02:00
|
|
|
}
|
|
|
|
}
|
2023-10-29 22:25:39 +02:00
|
|
|
return false; //Can't earse any player of this type
|
|
|
|
};
|
|
|
|
|
|
|
|
while (players.size() > realPlayersCnt)
|
2023-10-28 20:30:38 +02:00
|
|
|
{
|
2024-06-17 15:35:58 +02:00
|
|
|
if (eraseLastPlayer(EPlayerType::AI))
|
|
|
|
continue;
|
|
|
|
if (eraseLastPlayer(EPlayerType::COMP_ONLY))
|
|
|
|
continue;
|
|
|
|
if (eraseLastPlayer(EPlayerType::HUMAN))
|
|
|
|
continue;
|
2023-10-28 20:30:38 +02:00
|
|
|
}
|
2023-08-01 08:23:09 +02:00
|
|
|
|
|
|
|
//First colors from the list are assigned to human players, then to CPU players
|
|
|
|
std::vector<PlayerColor> availableColors;
|
2023-10-28 20:30:38 +02:00
|
|
|
for (ui8 color = 0; color < PlayerColor::PLAYER_LIMIT_I; color++)
|
2023-08-01 08:23:09 +02:00
|
|
|
{
|
|
|
|
availableColors.push_back(PlayerColor(color));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto removeUsedColors = [this, &availableColors](EPlayerType playerType)
|
|
|
|
{
|
|
|
|
for (auto& player : players)
|
|
|
|
{
|
|
|
|
if (player.second.getPlayerType() == playerType)
|
|
|
|
{
|
2023-10-29 22:25:39 +02:00
|
|
|
vstd::erase(availableColors, player.second.getColor());
|
2023-08-01 08:23:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
removeUsedColors(EPlayerType::HUMAN);
|
|
|
|
removeUsedColors(EPlayerType::COMP_ONLY);
|
|
|
|
//removeUsedColors(EPlayerType::AI);
|
|
|
|
|
2023-10-28 20:30:38 +02:00
|
|
|
//Assign unused colors to remaining AI players
|
|
|
|
while (players.size() < realPlayersCnt && !availableColors.empty())
|
|
|
|
{
|
|
|
|
auto color = availableColors.front();
|
|
|
|
players[color].setColor(color);
|
2023-11-28 16:37:21 +02:00
|
|
|
setPlayerTypeForStandardPlayer(color, EPlayerType::AI);
|
2023-10-28 20:30:38 +02:00
|
|
|
availableColors.erase(availableColors.begin());
|
2023-08-01 08:23:09 +02:00
|
|
|
|
2023-10-28 20:30:38 +02:00
|
|
|
if (vstd::contains(savedPlayerSettings, color))
|
|
|
|
{
|
|
|
|
setPlayerTeam(color, savedPlayerSettings.at(color).getTeam());
|
|
|
|
// TODO: setter
|
|
|
|
players[color].setStartingTown(savedPlayerSettings.at(color).getStartingTown());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-11-08 16:13:08 +02:00
|
|
|
logGlobal->warn("Adding settings for player %s", color);
|
2023-10-28 20:30:38 +02:00
|
|
|
// Usually, all players should be initialized in initPlayersMap()
|
|
|
|
CPlayerSettings settings;
|
|
|
|
players[color] = settings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<TeamID> occupiedTeams;
|
|
|
|
for(auto & player : players)
|
|
|
|
{
|
|
|
|
auto team = player.second.getTeam();
|
|
|
|
if (team != TeamID::NO_TEAM)
|
|
|
|
{
|
|
|
|
occupiedTeams.insert(team);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO: Handle situation when we remove a player and remaining players belong to only one team
|
|
|
|
|
|
|
|
for(auto & player : players)
|
|
|
|
{
|
|
|
|
if (player.second.getTeam() == TeamID::NO_TEAM)
|
|
|
|
{
|
|
|
|
//Find first unused team
|
|
|
|
for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
|
|
|
|
{
|
|
|
|
TeamID team(i);
|
|
|
|
if(!occupiedTeams.count(team))
|
|
|
|
{
|
|
|
|
player.second.setTeam(team);
|
|
|
|
occupiedTeams.insert(team);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::savePlayersMap()
|
|
|
|
{
|
|
|
|
//Only save already configured players
|
|
|
|
for (const auto& player : players)
|
|
|
|
{
|
|
|
|
savedPlayerSettings[player.first] = player.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::map<PlayerColor, CMapGenOptions::CPlayerSettings> & CMapGenOptions::getSavedPlayersMap() const
|
|
|
|
{
|
|
|
|
return savedPlayerSettings;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::map<PlayerColor, CMapGenOptions::CPlayerSettings> & CMapGenOptions::getPlayersSettings() const
|
|
|
|
{
|
|
|
|
return players;
|
|
|
|
}
|
|
|
|
|
2023-11-02 17:48:48 +02:00
|
|
|
void CMapGenOptions::setStartingTownForPlayer(const PlayerColor & color, FactionID town)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
auto it = players.find(color);
|
2023-10-28 20:30:38 +02:00
|
|
|
assert(it != players.end());
|
2013-08-17 15:46:48 +03:00
|
|
|
it->second.setStartingTown(town);
|
|
|
|
}
|
|
|
|
|
2024-01-13 14:08:36 +02:00
|
|
|
void CMapGenOptions::setStartingHeroForPlayer(const PlayerColor & color, HeroTypeID hero)
|
|
|
|
{
|
|
|
|
auto it = players.find(color);
|
|
|
|
assert(it != players.end());
|
|
|
|
it->second.setStartingHero(hero);
|
|
|
|
}
|
|
|
|
|
2023-05-20 13:29:55 +02:00
|
|
|
void CMapGenOptions::setPlayerTypeForStandardPlayer(const PlayerColor & color, EPlayerType playerType)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2023-10-28 20:30:38 +02:00
|
|
|
// FIXME: Why actually not set it to COMP_ONLY? Ie. when swapping human to another color?
|
2013-08-17 15:46:48 +03:00
|
|
|
assert(playerType != EPlayerType::COMP_ONLY);
|
|
|
|
auto it = players.find(color);
|
2023-10-28 20:30:38 +02:00
|
|
|
assert(it != players.end());
|
2013-08-17 15:46:48 +03:00
|
|
|
it->second.setPlayerType(playerType);
|
2023-10-28 20:30:38 +02:00
|
|
|
customizedPlayers = true;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const CRmgTemplate * CMapGenOptions::getMapTemplate() const
|
|
|
|
{
|
|
|
|
return mapTemplate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::setMapTemplate(const CRmgTemplate * value)
|
|
|
|
{
|
2023-10-29 11:05:24 +02:00
|
|
|
if (mapTemplate == value)
|
|
|
|
{
|
|
|
|
//Does not trigger during deserialization
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
mapTemplate = value;
|
2022-12-14 02:37:11 +02:00
|
|
|
//validate & adapt options according to template
|
|
|
|
if(mapTemplate)
|
|
|
|
{
|
|
|
|
if(!mapTemplate->matchesSize(int3(getWidth(), getHeight(), 1 + getHasTwoLevels())))
|
|
|
|
{
|
|
|
|
auto sizes = mapTemplate->getMapSizes();
|
|
|
|
setWidth(sizes.first.x);
|
|
|
|
setHeight(sizes.first.y);
|
|
|
|
setHasTwoLevels(sizes.first.z - 1);
|
|
|
|
}
|
2023-10-29 22:25:39 +02:00
|
|
|
|
|
|
|
si8 maxPlayerCount = getMaxPlayersCount(false);
|
|
|
|
si8 minPlayerCount = getMinPlayersCount(false);
|
|
|
|
|
|
|
|
// Neither setting can fit within the template range
|
|
|
|
if(!mapTemplate->getPlayers().isInRange(minPlayerCount) &&
|
|
|
|
!mapTemplate->getPlayers().isInRange(maxPlayerCount))
|
|
|
|
{
|
2023-10-28 20:30:38 +02:00
|
|
|
setHumanOrCpuPlayerCount(RANDOM_SIZE);
|
2022-12-14 02:37:11 +02:00
|
|
|
setCompOnlyPlayerCount(RANDOM_SIZE);
|
2023-10-29 22:25:39 +02:00
|
|
|
}
|
2022-12-14 02:37:11 +02:00
|
|
|
if(!mapTemplate->getWaterContentAllowed().count(getWaterContent()))
|
|
|
|
setWaterContent(EWaterContent::RANDOM);
|
2023-10-30 08:48:51 +02:00
|
|
|
|
|
|
|
resetPlayersMap(); // Update teams and player count
|
2022-12-14 02:37:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::setMapTemplate(const std::string & name)
|
|
|
|
{
|
|
|
|
if(!name.empty())
|
|
|
|
setMapTemplate(VLC->tplh->getTemplate(name));
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2023-07-08 08:44:10 +02:00
|
|
|
void CMapGenOptions::setRoadEnabled(const RoadId & roadType, bool enable)
|
2022-12-17 01:52:40 +02:00
|
|
|
{
|
2023-07-08 08:44:10 +02:00
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
enabledRoads.insert(roadType);
|
|
|
|
}
|
2022-12-17 01:52:40 +02:00
|
|
|
else
|
2023-07-08 08:44:10 +02:00
|
|
|
{
|
|
|
|
enabledRoads.erase(roadType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMapGenOptions::isRoadEnabled(const RoadId & roadType) const
|
|
|
|
{
|
|
|
|
return enabledRoads.count(roadType);
|
2022-12-17 01:52:40 +02:00
|
|
|
}
|
|
|
|
|
2023-07-08 08:44:10 +02:00
|
|
|
bool CMapGenOptions::isRoadEnabled() const
|
2022-12-17 01:52:40 +02:00
|
|
|
{
|
2023-07-08 08:44:10 +02:00
|
|
|
return !enabledRoads.empty();
|
2022-12-17 01:52:40 +02:00
|
|
|
}
|
|
|
|
|
2023-02-11 18:05:02 +02:00
|
|
|
void CMapGenOptions::setPlayerTeam(const PlayerColor & color, const TeamID & team)
|
2022-12-17 01:52:40 +02:00
|
|
|
{
|
|
|
|
auto it = players.find(color);
|
2023-10-28 20:30:38 +02:00
|
|
|
assert(it != players.end());
|
2022-12-17 01:52:40 +02:00
|
|
|
it->second.setTeam(team);
|
2023-10-28 20:30:38 +02:00
|
|
|
customizedPlayers = true;
|
2022-12-17 01:52:40 +02:00
|
|
|
}
|
|
|
|
|
2024-06-01 17:28:17 +02:00
|
|
|
void CMapGenOptions::finalize(vstd::RNG & rand)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2022-08-09 07:54:32 +02:00
|
|
|
logGlobal->info("RMG map: %dx%d, %s underground", getWidth(), getHeight(), getHasTwoLevels() ? "WITH" : "NO");
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->info("RMG settings: players %d, teams %d, computer players %d, computer teams %d, water %d, monsters %d",
|
2023-10-28 20:30:38 +02:00
|
|
|
static_cast<int>(getHumanOrCpuPlayerCount()), static_cast<int>(getTeamCount()), static_cast<int>(getCompOnlyPlayerCount()),
|
2017-08-12 14:43:41 +02:00
|
|
|
static_cast<int>(getCompOnlyTeamCount()), static_cast<int>(getWaterContent()), static_cast<int>(getMonsterStrength()));
|
2014-07-15 17:44:07 +03:00
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
if(!mapTemplate)
|
|
|
|
{
|
2014-03-17 22:51:07 +03:00
|
|
|
mapTemplate = getPossibleTemplate(rand);
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
2014-09-18 15:29:57 +03:00
|
|
|
assert(mapTemplate);
|
2022-08-09 07:54:32 +02:00
|
|
|
|
|
|
|
logGlobal->info("RMG template name: %s", mapTemplate->getName());
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2023-10-29 22:25:39 +02:00
|
|
|
auto maxPlayers = getMaxPlayersCount();
|
2023-10-28 20:30:38 +02:00
|
|
|
if (getHumanOrCpuPlayerCount() == RANDOM_SIZE)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
auto possiblePlayers = mapTemplate->getPlayers().getNumbers();
|
2024-06-17 15:35:58 +02:00
|
|
|
int requiredPlayers = countHumanPlayers() + countCompOnlyPlayers();
|
2015-06-01 21:57:43 +02:00
|
|
|
//ignore all non-randomized players, make sure these players will not be missing after roll
|
2024-06-17 15:35:58 +02:00
|
|
|
possiblePlayers.erase(possiblePlayers.begin(), possiblePlayers.lower_bound(requiredPlayers));
|
2023-10-29 22:25:39 +02:00
|
|
|
|
|
|
|
vstd::erase_if(possiblePlayers, [maxPlayers](int i)
|
|
|
|
{
|
|
|
|
return i > maxPlayers;
|
|
|
|
});
|
2013-08-17 15:46:48 +03:00
|
|
|
assert(!possiblePlayers.empty());
|
2023-10-28 20:30:38 +02:00
|
|
|
setHumanOrCpuPlayerCount (*RandomGeneratorUtil::nextItem(possiblePlayers, rand));
|
2013-08-17 15:46:48 +03:00
|
|
|
updatePlayers();
|
|
|
|
}
|
|
|
|
if(teamCount == RANDOM_SIZE)
|
|
|
|
{
|
2023-10-28 20:30:38 +02:00
|
|
|
teamCount = rand.nextInt(getHumanOrCpuPlayerCount() - 1);
|
2014-05-24 23:10:46 +03:00
|
|
|
if (teamCount == 1)
|
|
|
|
teamCount = 0;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
if(compOnlyPlayerCount == RANDOM_SIZE)
|
|
|
|
{
|
2023-10-29 22:25:39 +02:00
|
|
|
// Use remaining range
|
|
|
|
auto presentPlayers = getHumanOrCpuPlayerCount();
|
|
|
|
auto possiblePlayers = mapTemplate->getPlayers().getNumbers();
|
|
|
|
vstd::erase_if(possiblePlayers, [maxPlayers, presentPlayers](int i)
|
|
|
|
{
|
|
|
|
return i > (maxPlayers - presentPlayers);
|
|
|
|
});
|
2023-10-30 20:47:59 +02:00
|
|
|
if (possiblePlayers.empty())
|
|
|
|
{
|
|
|
|
compOnlyPlayerCount = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
compOnlyPlayerCount = *RandomGeneratorUtil::nextItem(possiblePlayers, rand);
|
|
|
|
}
|
2013-08-17 15:46:48 +03:00
|
|
|
updateCompOnlyPlayers();
|
|
|
|
}
|
|
|
|
if(compOnlyTeamCount == RANDOM_SIZE)
|
|
|
|
{
|
2014-03-17 22:51:07 +03:00
|
|
|
compOnlyTeamCount = rand.nextInt(std::max(compOnlyPlayerCount - 1, 0));
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(waterContent == EWaterContent::RANDOM)
|
|
|
|
{
|
2022-06-28 10:05:30 +02:00
|
|
|
auto allowedContent = mapTemplate->getWaterContentAllowed();
|
|
|
|
|
2023-02-11 18:05:02 +02:00
|
|
|
if(!allowedContent.empty())
|
2022-06-28 10:05:30 +02:00
|
|
|
{
|
|
|
|
waterContent = *RandomGeneratorUtil::nextItem(mapTemplate->getWaterContentAllowed(), rand);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
waterContent = EWaterContent::NONE;
|
|
|
|
}
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
2022-06-28 10:05:30 +02:00
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
if(monsterStrength == EMonsterStrength::RANDOM)
|
|
|
|
{
|
2014-06-04 11:16:08 +03:00
|
|
|
monsterStrength = static_cast<EMonsterStrength::EMonsterStrength>(rand.nextInt(EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG));
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
2014-06-03 09:57:20 +03:00
|
|
|
|
2014-09-18 15:29:57 +03:00
|
|
|
assert (vstd::iswithin(waterContent, EWaterContent::NONE, EWaterContent::ISLANDS));
|
|
|
|
assert (vstd::iswithin(monsterStrength, EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG));
|
|
|
|
|
2017-08-10 18:39:27 +02:00
|
|
|
logGlobal->trace("Player config:");
|
2023-01-23 01:58:41 +02:00
|
|
|
int cpuOnlyPlayers = 0;
|
2023-02-11 18:05:02 +02:00
|
|
|
for(const auto & player : players)
|
2015-06-01 21:57:43 +02:00
|
|
|
{
|
|
|
|
std::string playerType;
|
|
|
|
switch (player.second.getPlayerType())
|
|
|
|
{
|
|
|
|
case EPlayerType::AI:
|
|
|
|
playerType = "AI";
|
|
|
|
break;
|
|
|
|
case EPlayerType::COMP_ONLY:
|
|
|
|
playerType = "computer only";
|
|
|
|
cpuOnlyPlayers++;
|
|
|
|
break;
|
|
|
|
case EPlayerType::HUMAN:
|
|
|
|
playerType = "human only";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
}
|
2017-08-10 19:17:10 +02:00
|
|
|
logGlobal->trace("Player %d: %s", player.second.getColor(), playerType);
|
2015-06-01 21:57:43 +02:00
|
|
|
}
|
2023-12-10 10:50:25 +02:00
|
|
|
logGlobal->info("Final player config: %d total, %d cpu-only", players.size(), cpuOnlyPlayers);
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::updatePlayers()
|
|
|
|
{
|
2023-10-28 20:30:38 +02:00
|
|
|
// Remove non-human players only from the end of the players map if necessary
|
2013-08-17 15:46:48 +03:00
|
|
|
for(auto itrev = players.end(); itrev != players.begin();)
|
|
|
|
{
|
|
|
|
auto it = itrev;
|
|
|
|
--it;
|
2024-06-17 15:35:58 +02:00
|
|
|
if (players.size() == getHumanOrCpuPlayerCount())
|
|
|
|
break;
|
|
|
|
|
2023-10-28 20:30:38 +02:00
|
|
|
if(it->second.getPlayerType() != EPlayerType::HUMAN)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
players.erase(it);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
--itrev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::updateCompOnlyPlayers()
|
|
|
|
{
|
|
|
|
// Remove comp only players only from the end of the players map if necessary
|
|
|
|
for(auto itrev = players.end(); itrev != players.begin();)
|
|
|
|
{
|
|
|
|
auto it = itrev;
|
|
|
|
--it;
|
2023-10-28 20:30:38 +02:00
|
|
|
if (players.size() <= getHumanOrCpuPlayerCount()) break;
|
2013-08-17 15:46:48 +03:00
|
|
|
if(it->second.getPlayerType() == EPlayerType::COMP_ONLY)
|
|
|
|
{
|
|
|
|
players.erase(it);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
--itrev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add some comp only players if necessary
|
2023-10-28 20:30:38 +02:00
|
|
|
int compOnlyPlayersToAdd = static_cast<int>(getHumanOrCpuPlayerCount() - players.size());
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2015-05-27 18:58:14 +02:00
|
|
|
if (compOnlyPlayersToAdd < 0)
|
|
|
|
{
|
2023-10-28 20:30:38 +02:00
|
|
|
logGlobal->error("Incorrect number of players to add. Requested players %d, current players %d", humanOrCpuPlayerCount, players.size());
|
2015-05-27 18:58:14 +02:00
|
|
|
assert (compOnlyPlayersToAdd < 0);
|
|
|
|
}
|
2013-08-17 15:46:48 +03:00
|
|
|
for(int i = 0; i < compOnlyPlayersToAdd; ++i)
|
|
|
|
{
|
|
|
|
CPlayerSettings pSettings;
|
|
|
|
pSettings.setPlayerType(EPlayerType::COMP_ONLY);
|
|
|
|
pSettings.setColor(getNextPlayerColor());
|
|
|
|
players[pSettings.getColor()] = pSettings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int CMapGenOptions::countHumanPlayers() const
|
|
|
|
{
|
|
|
|
return static_cast<int>(boost::count_if(players, [](const std::pair<PlayerColor, CPlayerSettings> & pair)
|
|
|
|
{
|
|
|
|
return pair.second.getPlayerType() == EPlayerType::HUMAN;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2015-06-01 21:57:43 +02:00
|
|
|
int CMapGenOptions::countCompOnlyPlayers() const
|
|
|
|
{
|
|
|
|
return static_cast<int>(boost::count_if(players, [](const std::pair<PlayerColor, CPlayerSettings> & pair)
|
|
|
|
{
|
|
|
|
return pair.second.getPlayerType() == EPlayerType::COMP_ONLY;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
PlayerColor CMapGenOptions::getNextPlayerColor() const
|
|
|
|
{
|
|
|
|
for(PlayerColor i = PlayerColor(0); i < PlayerColor::PLAYER_LIMIT; i.advance(1))
|
|
|
|
{
|
|
|
|
if(!players.count(i))
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2017-08-10 18:39:27 +02:00
|
|
|
logGlobal->error("Failed to get next player color");
|
2015-05-27 18:58:14 +02:00
|
|
|
assert(false);
|
2013-08-17 15:46:48 +03:00
|
|
|
return PlayerColor(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMapGenOptions::checkOptions() const
|
|
|
|
{
|
|
|
|
if(mapTemplate)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-06-01 17:28:17 +02:00
|
|
|
return !getPossibleTemplates().empty();
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-28 20:30:38 +02:00
|
|
|
bool CMapGenOptions::arePlayersCustomized() const
|
|
|
|
{
|
|
|
|
return customizedPlayers;
|
|
|
|
}
|
|
|
|
|
2022-09-17 13:04:01 +02:00
|
|
|
std::vector<const CRmgTemplate *> CMapGenOptions::getPossibleTemplates() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2022-05-28 15:03:50 +02:00
|
|
|
int3 tplSize(width, height, (hasTwoLevels ? 2 : 1));
|
2022-05-31 11:25:39 +02:00
|
|
|
auto humanPlayers = countHumanPlayers();
|
2022-09-17 13:04:01 +02:00
|
|
|
|
2022-05-31 11:25:39 +02:00
|
|
|
auto templates = VLC->tplh->getTemplates();
|
2022-09-17 13:04:01 +02:00
|
|
|
|
2022-05-31 11:25:39 +02:00
|
|
|
vstd::erase_if(templates, [this, &tplSize, humanPlayers](const CRmgTemplate * tmpl)
|
|
|
|
{
|
|
|
|
if(!tmpl->matchesSize(tplSize))
|
|
|
|
return true;
|
2022-09-17 13:04:01 +02:00
|
|
|
|
2022-05-31 11:25:39 +02:00
|
|
|
if(!tmpl->isWaterContentAllowed(getWaterContent()))
|
|
|
|
return true;
|
2022-09-17 13:04:01 +02:00
|
|
|
|
2023-10-29 22:25:39 +02:00
|
|
|
auto humanOrCpuPlayerCount = getHumanOrCpuPlayerCount();
|
|
|
|
auto compOnlyPlayerCount = getCompOnlyPlayerCount();
|
|
|
|
// Check if total number of players fall inside given range
|
|
|
|
|
|
|
|
if(humanOrCpuPlayerCount != CMapGenOptions::RANDOM_SIZE && compOnlyPlayerCount != CMapGenOptions::RANDOM_SIZE)
|
|
|
|
{
|
|
|
|
if (!tmpl->getPlayers().isInRange(humanOrCpuPlayerCount + compOnlyPlayerCount))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(humanOrCpuPlayerCount != CMapGenOptions::RANDOM_SIZE)
|
|
|
|
{
|
|
|
|
// We can always add any number CPU players, but not subtract
|
|
|
|
if (!(humanOrCpuPlayerCount <= tmpl->getPlayers().maxValue()))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(compOnlyPlayerCount != CMapGenOptions::RANDOM_SIZE)
|
2022-05-31 11:25:39 +02:00
|
|
|
{
|
2023-10-29 22:25:39 +02:00
|
|
|
//We must fit at least one more human player, but can add any number
|
|
|
|
if (!(compOnlyPlayerCount < tmpl->getPlayers().maxValue()))
|
2022-05-31 11:25:39 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Human players shouldn't be banned when playing with random player count
|
2023-10-29 22:25:39 +02:00
|
|
|
if(humanPlayers > tmpl->getPlayers().minValue())
|
2022-05-31 11:25:39 +02:00
|
|
|
return true;
|
|
|
|
}
|
2022-09-17 13:04:01 +02:00
|
|
|
|
2022-05-31 11:25:39 +02:00
|
|
|
return false;
|
|
|
|
});
|
2022-09-17 13:04:01 +02:00
|
|
|
|
|
|
|
return templates;
|
|
|
|
}
|
|
|
|
|
2024-06-01 17:28:17 +02:00
|
|
|
const CRmgTemplate * CMapGenOptions::getPossibleTemplate(vstd::RNG & rand) const
|
2022-09-17 13:04:01 +02:00
|
|
|
{
|
|
|
|
auto templates = getPossibleTemplates();
|
|
|
|
|
2022-05-28 15:03:50 +02:00
|
|
|
if(templates.empty())
|
2013-08-17 15:46:48 +03:00
|
|
|
return nullptr;
|
2022-05-28 15:03:50 +02:00
|
|
|
|
|
|
|
return *RandomGeneratorUtil::nextItem(templates, rand);
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2024-01-13 14:08:36 +02:00
|
|
|
CMapGenOptions::CPlayerSettings::CPlayerSettings() : color(0), startingTown(FactionID::RANDOM), startingHero(HeroTypeID::RANDOM), playerType(EPlayerType::AI), team(TeamID::NO_TEAM)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerColor CMapGenOptions::CPlayerSettings::getColor() const
|
|
|
|
{
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2023-02-11 18:05:02 +02:00
|
|
|
void CMapGenOptions::CPlayerSettings::setColor(const PlayerColor & value)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
assert(value >= PlayerColor(0) && value < PlayerColor::PLAYER_LIMIT);
|
|
|
|
color = value;
|
|
|
|
}
|
|
|
|
|
2023-11-02 17:12:58 +02:00
|
|
|
FactionID CMapGenOptions::CPlayerSettings::getStartingTown() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
return startingTown;
|
|
|
|
}
|
|
|
|
|
2023-11-02 17:12:58 +02:00
|
|
|
void CMapGenOptions::CPlayerSettings::setStartingTown(FactionID value)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2023-11-02 17:12:58 +02:00
|
|
|
assert(value >= FactionID::RANDOM);
|
|
|
|
if(value != FactionID::RANDOM)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2023-11-02 17:12:58 +02:00
|
|
|
assert(value < FactionID(VLC->townh->size()));
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
assert((*VLC->townh)[value]->town != nullptr);
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
startingTown = value;
|
|
|
|
}
|
|
|
|
|
2024-01-13 14:08:36 +02:00
|
|
|
HeroTypeID CMapGenOptions::CPlayerSettings::getStartingHero() const
|
|
|
|
{
|
|
|
|
return startingHero;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenOptions::CPlayerSettings::setStartingHero(HeroTypeID value)
|
|
|
|
{
|
|
|
|
assert(value == HeroTypeID::RANDOM || value.toEntity(VLC) != nullptr);
|
|
|
|
startingHero = value;
|
|
|
|
}
|
|
|
|
|
2023-05-20 13:29:55 +02:00
|
|
|
EPlayerType CMapGenOptions::CPlayerSettings::getPlayerType() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
return playerType;
|
|
|
|
}
|
|
|
|
|
2023-05-20 13:29:55 +02:00
|
|
|
void CMapGenOptions::CPlayerSettings::setPlayerType(EPlayerType value)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
playerType = value;
|
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
2022-12-17 01:52:40 +02:00
|
|
|
TeamID CMapGenOptions::CPlayerSettings::getTeam() const
|
|
|
|
{
|
|
|
|
return team;
|
|
|
|
}
|
|
|
|
|
2023-02-11 18:05:02 +02:00
|
|
|
void CMapGenOptions::CPlayerSettings::setTeam(const TeamID & value)
|
2022-12-17 01:52:40 +02:00
|
|
|
{
|
|
|
|
team = value;
|
|
|
|
}
|
|
|
|
|
2024-02-29 13:45:08 +02:00
|
|
|
void CMapGenOptions::serializeJson(JsonSerializeFormat & handler)
|
|
|
|
{
|
|
|
|
handler.serializeInt("width", width);
|
|
|
|
handler.serializeInt("height", height);
|
|
|
|
handler.serializeBool("haswoLevels", hasTwoLevels);
|
|
|
|
handler.serializeInt("humanOrCpuPlayerCount", humanOrCpuPlayerCount);
|
|
|
|
handler.serializeInt("teamCount", teamCount);
|
|
|
|
handler.serializeInt("compOnlyPlayerCount", compOnlyPlayerCount);
|
|
|
|
handler.serializeInt("compOnlyTeamCount", compOnlyTeamCount);
|
|
|
|
handler.serializeInt("waterContent", waterContent);
|
|
|
|
handler.serializeInt("monsterStrength", monsterStrength);
|
|
|
|
|
|
|
|
std::string templateName;
|
|
|
|
if(mapTemplate && handler.saving)
|
|
|
|
{
|
|
|
|
templateName = mapTemplate->getId();
|
|
|
|
}
|
|
|
|
handler.serializeString("templateName", templateName);
|
|
|
|
if(!handler.saving)
|
|
|
|
{
|
|
|
|
setMapTemplate(templateName);
|
|
|
|
}
|
|
|
|
|
|
|
|
handler.serializeIdArray("roads", enabledRoads);
|
|
|
|
if (!handler.saving)
|
|
|
|
{
|
2024-02-29 14:04:48 +02:00
|
|
|
// Player settings won't be saved
|
2024-02-29 13:45:08 +02:00
|
|
|
resetPlayersMap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|