1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Handling "terrain type" and "match terrain to town" options.

This commit is contained in:
DjWarmonger 2014-06-14 17:14:59 +02:00
parent 6cbcfbf0a9
commit 93b44de63c
4 changed files with 62 additions and 61 deletions

View File

@ -9,7 +9,7 @@
"1" : "1" :
{ {
"type" : "playerStart", "size" : 1, "owner" : 1, "type" : "playerStart", "size" : 1, "owner" : 1,
"playerTowns" : { "castles" : 1 }, "neutralTowns" : { "towns" : 1 }, "townsAreSameType" : true, "playerTowns" : { "castles" : 1 }, "neutralTowns" : { "towns" : 1 }, "townsAreSameType" : true
"treasure" : [ "treasure" : [
{"min" : 2100, "max": 3000, "density" : 5}, {"min" : 2100, "max": 3000, "density" : 5},
{"min" : 300, "max": 1500, "density" : 10} {"min" : 300, "max": 1500, "density" : 10}
@ -35,7 +35,8 @@
}, },
"5" : "5" :
{ {
"type" : "treasure", "size" : 2, "terrainTypes" : [ "sand" ], "neutralTowns" : { "castles" : 1 }, "type" : "treasure", "size" : 2, "terrainTypes" : [ "sand" ], "matchTerrainToTown" : false,
"neutralTowns" : { "castles" : 1 },
"treasure" : [ "treasure" : [
{"min" : 9000, "max": 10000, "density" : 3}, {"min" : 9000, "max": 10000, "density" : 3},
{"min" : 6000, "max": 10000, "density" : 15} {"min" : 6000, "max": 10000, "density" : 15}
@ -73,7 +74,7 @@
}, },
"3" : "3" :
{ {
"type" : "treasure", "size" : 2, "neutralTowns" : { "towns" : 1 }, "townTypeLikeZone" : "1", "type" : "treasure", "size" : 2, "neutralTowns" : { "towns" : 1 }, "townTypeLikeZone" : 1,
"treasure" : [ "treasure" : [
{"min" : 2000, "max": 4000, "density" : 15}, {"min" : 2000, "max": 4000, "density" : 15},
{"min" : 4000, "max": 5000, "density" : 5} {"min" : 4000, "max": 5000, "density" : 5}
@ -81,7 +82,7 @@
}, },
"4" : "4" :
{ {
"type" : "treasure", "size" : 2, "neutralTowns" : { "towns" : 1 }, "townTypeLikeZone" : "2", "type" : "treasure", "size" : 2, "neutralTowns" : { "towns" : 1 }, "townTypeLikeZone" : 2,
"treasureLikeZone" : 3 "treasureLikeZone" : 3
}, },
"5" : "5" :
@ -130,15 +131,15 @@
"playerTowns" : { "castles" : 1 }, "playerTowns" : { "castles" : 1 },
"treasureLikeZone" : 1 "treasureLikeZone" : 1
}, },
"4" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "1", "treasure" : [ "4" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : 1, "treasure" : [
{"min" : 3000, "max": 10000, "density" : 12}, {"min" : 3000, "max": 10000, "density" : 12},
{"min" : 6000, "max": 10000, "density" : 6} {"min" : 6000, "max": 10000, "density" : 6}
]}, ]},
"5" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "1", "treasureLikeZone" : 4}, "5" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : 1, "treasureLikeZone" : 4},
"6" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "2", "treasureLikeZone" : 4 }, "6" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : 2, "treasureLikeZone" : 4 },
"7" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "2", "treasureLikeZone" : 4 }, "7" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : 2, "treasureLikeZone" : 4 },
"8" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "3", "treasureLikeZone" : 4 }, "8" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : 3, "treasureLikeZone" : 4 },
"9" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "3", "treasureLikeZone" : 4 }, "9" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : 3, "treasureLikeZone" : 4 },
"10" : { "type" : "treasure", "size" : 1, "neutralTowns" : { "towns" : 1 }, "treasure" : [ "10" : { "type" : "treasure", "size" : 1, "neutralTowns" : { "towns" : 1 }, "treasure" : [
{"min" : 21000, "max": 25000, "density" : 3}, {"min" : 21000, "max": 25000, "density" : 3},
{"min" : 10000, "max": 21000, "density" : 10} {"min" : 10000, "max": 21000, "density" : 10}
@ -188,8 +189,8 @@
"type" : "cpuStart", "size" : 3, "owner" : 4, "type" : "cpuStart", "size" : 3, "owner" : 4,
"playerTowns" : { "castles" : 1 } "playerTowns" : { "castles" : 1 }
}, },
"5" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "3" }, "5" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : 3 },
"6" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "4" } "6" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : 4 }
}, },
"connections" : "connections" :
[ [
@ -243,14 +244,14 @@
{ {
"type" : "treasure", "size" : 40, "type" : "treasure", "size" : 40,
"neutralTowns" : { "towns" : 2 }, "neutralTowns" : { "towns" : 2 },
"terrainTypes" : [ "sand" ], "terrainTypes" : [ "sand" ], "matchTerrainToTown" : false,
"treasure" : [ "treasure" : [
{"min" : 35000, "max": 55000, "density" : 3}, {"min" : 35000, "max": 55000, "density" : 3},
{"min" : 25000, "max": 35000, "density" : 10}, {"min" : 25000, "max": 35000, "density" : 10},
{"min" : 10000, "max": 25000, "density" : 10} {"min" : 10000, "max": 25000, "density" : 10}
] ]
} }
} },
"connections" : "connections" :
[ [
{ "a" : "1", "b" : "5", "guard" : 45000 }, { "a" : "1", "b" : "5", "guard" : 45000 },

View File

@ -60,7 +60,8 @@ void CJsonRmgTemplateLoader::loadTemplates()
zone->setPlayerTowns(parseTemplateZoneTowns(zoneNode["playerTowns"])); zone->setPlayerTowns(parseTemplateZoneTowns(zoneNode["playerTowns"]));
zone->setNeutralTowns(parseTemplateZoneTowns(zoneNode["neutralTowns"])); zone->setNeutralTowns(parseTemplateZoneTowns(zoneNode["neutralTowns"]));
zone->setTownTypes(parseTownTypes(zoneNode["townTypes"].Vector(), zone->getDefaultTownTypes())); zone->setTownTypes(parseTownTypes(zoneNode["townTypes"].Vector(), zone->getDefaultTownTypes()));
zone->setMatchTerrainToTown(zoneNode["matchTerrainToTown"].Bool()); if (!zoneNode["matchTerrainToTown"].isNull()) //default : true
zone->setMatchTerrainToTown(zoneNode["matchTerrainToTown"].Bool());
zone->setTerrainTypes(parseTerrainTypes(zoneNode["terrainTypes"].Vector(), zone->getDefaultTerrainTypes())); zone->setTerrainTypes(parseTerrainTypes(zoneNode["terrainTypes"].Vector(), zone->getDefaultTerrainTypes()));
zone->setTownsAreSameType((zoneNode["townsAreSameType"].Bool())); zone->setTownsAreSameType((zoneNode["townsAreSameType"].Bool()));
@ -109,9 +110,11 @@ void CJsonRmgTemplateLoader::loadTemplates()
const auto & zoneNode = zonePair.second; const auto & zoneNode = zonePair.second;
//TODO: do these lines even do anything? if (!zoneNode["terrainTypeLikeZone"].isNull())
if(!zoneNode["terrainTypeLikeZone"].isNull()) zone->setTerrainTypeLikeZone(boost::lexical_cast<int>(zoneNode["terrainTypeLikeZone"].String())); zone->setTerrainTypes (zones[zoneNode["terrainTypeLikeZone"].Float()]->getTerrainTypes());
if(!zoneNode["townTypeLikeZone"].isNull()) zone->setTownTypeLikeZone(boost::lexical_cast<int>(zoneNode["townTypeLikeZone"].String()));
if (!zoneNode["townTypeLikeZone"].isNull())
zone->setTownTypes (zones[zoneNode["townTypeLikeZone"].Float()]->getTownTypes());
if (!zoneNode["treasureLikeZone"].isNull()) if (!zoneNode["treasureLikeZone"].isNull())
{ {
@ -231,6 +234,9 @@ std::set<TFaction> CJsonRmgTemplateLoader::parseTownTypes(const JsonVector & tow
std::set<ETerrainType> CJsonRmgTemplateLoader::parseTerrainTypes(const JsonVector & terTypeStrings, const std::set<ETerrainType> & defaultTerrainTypes) const std::set<ETerrainType> CJsonRmgTemplateLoader::parseTerrainTypes(const JsonVector & terTypeStrings, const std::set<ETerrainType> & defaultTerrainTypes) const
{ {
std::set<ETerrainType> terTypes; std::set<ETerrainType> terTypes;
if (terTypeStrings.empty()) //nothing was specified
return defaultTerrainTypes;
for(const auto & node : terTypeStrings) for(const auto & node : terTypeStrings)
{ {
const auto & terTypeStr = node.String(); const auto & terTypeStr = node.String();

View File

@ -121,7 +121,7 @@ void CTileInfo::setTerrainType(ETerrainType value)
} }
CRmgTemplateZone::CRmgTemplateZone() : id(0), type(ETemplateZoneType::PLAYER_START), size(1), CRmgTemplateZone::CRmgTemplateZone() : id(0), type(ETemplateZoneType::PLAYER_START), size(1),
townsAreSameType(false), matchTerrainToTown(true), totalDensity(0) terrainType (ETerrainType::GRASS), townType(0), townsAreSameType(false), matchTerrainToTown(true), totalDensity(0)
{ {
townTypes = getDefaultTownTypes(); townTypes = getDefaultTownTypes();
terrainTypes = getDefaultTerrainTypes(); terrainTypes = getDefaultTerrainTypes();
@ -248,32 +248,14 @@ void CRmgTemplateZone::setTerrainTypes(const std::set<ETerrainType> & value)
std::set<ETerrainType> CRmgTemplateZone::getDefaultTerrainTypes() const std::set<ETerrainType> CRmgTemplateZone::getDefaultTerrainTypes() const
{ {
std::set<ETerrainType> terTypes; std::set<ETerrainType> terTypes;
static const ETerrainType::EETerrainType allowedTerTypes[] = { ETerrainType::DIRT, ETerrainType::SAND, ETerrainType::GRASS, ETerrainType::SNOW, static const ETerrainType::EETerrainType allowedTerTypes[] = {ETerrainType::DIRT, ETerrainType::SAND, ETerrainType::GRASS, ETerrainType::SNOW,
ETerrainType::SWAMP, ETerrainType::ROUGH, ETerrainType::SUBTERRANEAN, ETerrainType::LAVA }; ETerrainType::SWAMP, ETerrainType::ROUGH, ETerrainType::SUBTERRANEAN, ETerrainType::LAVA};
for(auto & allowedTerType : allowedTerTypes) terTypes.insert(allowedTerType); for (auto & allowedTerType : allowedTerTypes)
terTypes.insert(allowedTerType);
return terTypes; return terTypes;
} }
boost::optional<TRmgTemplateZoneId> CRmgTemplateZone::getTerrainTypeLikeZone() const
{
return terrainTypeLikeZone;
}
void CRmgTemplateZone::setTerrainTypeLikeZone(boost::optional<TRmgTemplateZoneId> value)
{
terrainTypeLikeZone = value;
}
boost::optional<TRmgTemplateZoneId> CRmgTemplateZone::getTownTypeLikeZone() const
{
return townTypeLikeZone;
}
void CRmgTemplateZone::setTownTypeLikeZone(boost::optional<TRmgTemplateZoneId> value)
{
townTypeLikeZone = value;
}
void CRmgTemplateZone::addConnection(TRmgTemplateZoneId otherZone) void CRmgTemplateZone::addConnection(TRmgTemplateZoneId otherZone)
{ {
connections.push_back (otherZone); connections.push_back (otherZone);
@ -710,13 +692,8 @@ bool CRmgTemplateZone::createTreasurePile (CMapGenerator* gen, int3 &pos)
else //we did not place eveyrthing successfully else //we did not place eveyrthing successfully
return false; return false;
} }
void CRmgTemplateZone::initTownType (CMapGenerator* gen)
bool CRmgTemplateZone::fill(CMapGenerator* gen)
{ {
addAllPossibleObjects (gen);
int townId = 0;
if ((type == ETemplateZoneType::CPU_START) || (type == ETemplateZoneType::PLAYER_START)) if ((type == ETemplateZoneType::CPU_START) || (type == ETemplateZoneType::PLAYER_START))
{ {
logGlobal->infoStream() << "Preparing playing zone"; logGlobal->infoStream() << "Preparing playing zone";
@ -727,12 +704,12 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
PlayerColor player(player_id); PlayerColor player(player_id);
auto town = new CGTownInstance(); auto town = new CGTownInstance();
town->ID = Obj::TOWN; town->ID = Obj::TOWN;
townId = gen->mapGenOptions->getPlayersSettings().find(player)->second.getStartingTown(); townType = gen->mapGenOptions->getPlayersSettings().find(player)->second.getStartingTown();
if(townId == CMapGenOptions::CPlayerSettings::RANDOM_TOWN) if(townType == CMapGenOptions::CPlayerSettings::RANDOM_TOWN)
townId = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand); // all possible towns, skip neutral townType = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand); // all possible towns, skip neutral
town->subID = townId; town->subID = townType;
town->tempOwner = player; town->tempOwner = player;
town->builtBuildings.insert(BuildingID::FORT); town->builtBuildings.insert(BuildingID::FORT);
town->builtBuildings.insert(BuildingID::DEFAULT); town->builtBuildings.insert(BuildingID::DEFAULT);
@ -743,7 +720,7 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
// Update player info // Update player info
playerInfo.allowedFactions.clear(); playerInfo.allowedFactions.clear();
playerInfo.allowedFactions.insert(townId); playerInfo.allowedFactions.insert (townType);
playerInfo.hasMainTown = true; playerInfo.hasMainTown = true;
playerInfo.posOfMainTown = town->pos - int3(2, 0, 0); playerInfo.posOfMainTown = town->pos - int3(2, 0, 0);
playerInfo.generateHeroAtMainTown = true; playerInfo.generateHeroAtMainTown = true;
@ -767,14 +744,24 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
else else
{ {
type = ETemplateZoneType::TREASURE; type = ETemplateZoneType::TREASURE;
townId = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand); townType = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand);
logGlobal->infoStream() << "Skipping this zone cause no player"; logGlobal->infoStream() << "Skipping this zone cause no player";
} }
} }
else //no player else //no player
{ {
townId = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand); townType = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand);
} }
}
void CRmgTemplateZone::initTerrainType (CMapGenerator* gen)
{
if (matchTerrainToTown)
terrainType = VLC->townh->factions[townType]->nativeTerrain;
else
terrainType = *RandomGeneratorUtil::nextItem(terrainTypes, gen->rand);
//paint zone with matching terrain //paint zone with matching terrain
std::vector<int3> tiles; std::vector<int3> tiles;
for (auto tile : tileinfo) for (auto tile : tileinfo)
@ -782,7 +769,14 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
tiles.push_back (tile); tiles.push_back (tile);
} }
gen->editManager->getTerrainSelection().setSelection(tiles); gen->editManager->getTerrainSelection().setSelection(tiles);
gen->editManager->drawTerrain(VLC->townh->factions[townId]->nativeTerrain, &gen->rand); gen->editManager->drawTerrain(terrainType, &gen->rand);
}
bool CRmgTemplateZone::fill(CMapGenerator* gen)
{
addAllPossibleObjects (gen);
initTownType(gen);
initTerrainType(gen);
logGlobal->infoStream() << "Creating required objects"; logGlobal->infoStream() << "Creating required objects";
for(const auto &obj : requiredObjects) for(const auto &obj : requiredObjects)

View File

@ -115,10 +115,6 @@ public:
const std::set<ETerrainType> & getTerrainTypes() const; /// Default: all const std::set<ETerrainType> & getTerrainTypes() const; /// Default: all
void setTerrainTypes(const std::set<ETerrainType> & value); void setTerrainTypes(const std::set<ETerrainType> & value);
std::set<ETerrainType> getDefaultTerrainTypes() const; std::set<ETerrainType> getDefaultTerrainTypes() const;
boost::optional<TRmgTemplateZoneId> getTerrainTypeLikeZone() const;
void setTerrainTypeLikeZone(boost::optional<TRmgTemplateZoneId> value);
boost::optional<TRmgTemplateZoneId> getTownTypeLikeZone() const;
void setTownTypeLikeZone(boost::optional<TRmgTemplateZoneId> value);
float3 getCenter() const; float3 getCenter() const;
void setCenter(const float3 &f); void setCenter(const float3 &f);
@ -132,6 +128,8 @@ public:
bool addMonster(CMapGenerator* gen, int3 &pos, si32 strength); bool addMonster(CMapGenerator* gen, int3 &pos, si32 strength);
bool createTreasurePile (CMapGenerator* gen, int3 &pos); bool createTreasurePile (CMapGenerator* gen, int3 &pos);
bool fill(CMapGenerator* gen); bool fill(CMapGenerator* gen);
void initTownType (CMapGenerator* gen);
void initTerrainType (CMapGenerator* gen);
void createBorder(CMapGenerator* gen); void createBorder(CMapGenerator* gen);
void fractalize(CMapGenerator* gen); void fractalize(CMapGenerator* gen);
bool crunchPath (CMapGenerator* gen, const int3 &src, const int3 &dst, TRmgTemplateZoneId zone, std::set<int3>* clearedTiles = nullptr); bool crunchPath (CMapGenerator* gen, const int3 &src, const int3 &dst, TRmgTemplateZoneId zone, std::set<int3>* clearedTiles = nullptr);
@ -156,7 +154,9 @@ private:
std::set<TFaction> townTypes; std::set<TFaction> townTypes;
bool matchTerrainToTown; bool matchTerrainToTown;
std::set<ETerrainType> terrainTypes; std::set<ETerrainType> terrainTypes;
boost::optional<TRmgTemplateZoneId> terrainTypeLikeZone, townTypeLikeZone;
si32 townType;
ETerrainType terrainType;
ui16 totalDensity; ui16 totalDensity;
std::vector<CTreasureInfo> treasureInfo; std::vector<CTreasureInfo> treasureInfo;