/* * CRmgTemplateZone.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" #include "CRmgTemplateZone.h" #include "../VCMI_Lib.h" #include "../CTownHandler.h" CRmgTemplateZone::CTownInfo::CTownInfo() : townCount(0), castleCount(0), townDensity(0), castleDensity(0) { } int CRmgTemplateZone::CTownInfo::getTownCount() const { return townCount; } void CRmgTemplateZone::CTownInfo::setTownCount(int value) { if(value < 0) throw std::runtime_error("Negative value for town count not allowed."); townCount = value; } int CRmgTemplateZone::CTownInfo::getCastleCount() const { return castleCount; } void CRmgTemplateZone::CTownInfo::setCastleCount(int value) { if(value < 0) throw std::runtime_error("Negative value for castle count not allowed."); castleCount = value; } int CRmgTemplateZone::CTownInfo::getTownDensity() const { return townDensity; } void CRmgTemplateZone::CTownInfo::setTownDensity(int value) { if(value < 0) throw std::runtime_error("Negative value for town density not allowed."); townDensity = value; } int CRmgTemplateZone::CTownInfo::getCastleDensity() const { return castleDensity; } void CRmgTemplateZone::CTownInfo::setCastleDensity(int value) { if(value < 0) throw std::runtime_error("Negative value for castle density not allowed."); castleDensity = value; } CRmgTemplateZone::CRmgTemplateZone() : id(0), type(ETemplateZoneType::PLAYER_START), size(1), townsAreSameType(false), matchTerrainToTown(true) { townTypes = getDefaultTownTypes(); terrainTypes = getDefaultTerrainTypes(); } TRmgTemplateZoneId CRmgTemplateZone::getId() const { return id; } void CRmgTemplateZone::setId(TRmgTemplateZoneId value) { if(value <= 0) throw std::runtime_error("Zone id should be greater than 0."); id = value; } ETemplateZoneType::ETemplateZoneType CRmgTemplateZone::getType() const { return type; } void CRmgTemplateZone::setType(ETemplateZoneType::ETemplateZoneType value) { type = value; } int CRmgTemplateZone::getSize() const { return size; } void CRmgTemplateZone::setSize(int value) { if(value <= 0) throw std::runtime_error("Zone size needs to be greater than 0."); size = value; } boost::optional CRmgTemplateZone::getOwner() const { return owner; } void CRmgTemplateZone::setOwner(boost::optional value) { if(!(*value >= 0 && *value <= PlayerColor::PLAYER_LIMIT_I)) throw std::runtime_error("Owner has to be in range 0 to max player count."); owner = value; } const CRmgTemplateZone::CTownInfo & CRmgTemplateZone::getPlayerTowns() const { return playerTowns; } void CRmgTemplateZone::setPlayerTowns(const CTownInfo & value) { playerTowns = value; } const CRmgTemplateZone::CTownInfo & CRmgTemplateZone::getNeutralTowns() const { return neutralTowns; } void CRmgTemplateZone::setNeutralTowns(const CTownInfo & value) { neutralTowns = value; } bool CRmgTemplateZone::getTownsAreSameType() const { return townsAreSameType; } void CRmgTemplateZone::setTownsAreSameType(bool value) { townsAreSameType = value; } const std::set & CRmgTemplateZone::getTownTypes() const { return townTypes; } void CRmgTemplateZone::setTownTypes(const std::set & value) { townTypes = value; } std::set CRmgTemplateZone::getDefaultTownTypes() const { std::set defaultTowns; auto towns = VLC->townh->getDefaultAllowed(); for(int i = 0; i < towns.size(); ++i) { if(towns[i]) defaultTowns.insert(i); } return defaultTowns; } bool CRmgTemplateZone::getMatchTerrainToTown() const { return matchTerrainToTown; } void CRmgTemplateZone::setMatchTerrainToTown(bool value) { matchTerrainToTown = value; } const std::set & CRmgTemplateZone::getTerrainTypes() const { return terrainTypes; } void CRmgTemplateZone::setTerrainTypes(const std::set & value) { assert(value.find(ETerrainType::WRONG) == value.end() && value.find(ETerrainType::BORDER) == value.end() && value.find(ETerrainType::WATER) == value.end() && value.find(ETerrainType::ROCK) == value.end()); terrainTypes = value; } std::set CRmgTemplateZone::getDefaultTerrainTypes() const { std::set terTypes; static const ETerrainType::EETerrainType allowedTerTypes[] = { ETerrainType::DIRT, ETerrainType::SAND, ETerrainType::GRASS, ETerrainType::SNOW, ETerrainType::SWAMP, ETerrainType::ROUGH, ETerrainType::SUBTERRANEAN, ETerrainType::LAVA }; for(auto & allowedTerType : allowedTerTypes) terTypes.insert(allowedTerType); return terTypes; } boost::optional CRmgTemplateZone::getTerrainTypeLikeZone() const { return terrainTypeLikeZone; } void CRmgTemplateZone::setTerrainTypeLikeZone(boost::optional value) { terrainTypeLikeZone = value; } boost::optional CRmgTemplateZone::getTownTypeLikeZone() const { return townTypeLikeZone; } void CRmgTemplateZone::setTownTypeLikeZone(boost::optional value) { townTypeLikeZone = value; }