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

View File

@ -60,6 +60,7 @@ void CJsonRmgTemplateLoader::loadTemplates()
zone->setPlayerTowns(parseTemplateZoneTowns(zoneNode["playerTowns"]));
zone->setNeutralTowns(parseTemplateZoneTowns(zoneNode["neutralTowns"]));
zone->setTownTypes(parseTownTypes(zoneNode["townTypes"].Vector(), zone->getDefaultTownTypes()));
if (!zoneNode["matchTerrainToTown"].isNull()) //default : true
zone->setMatchTerrainToTown(zoneNode["matchTerrainToTown"].Bool());
zone->setTerrainTypes(parseTerrainTypes(zoneNode["terrainTypes"].Vector(), zone->getDefaultTerrainTypes()));
zone->setTownsAreSameType((zoneNode["townsAreSameType"].Bool()));
@ -109,9 +110,11 @@ void CJsonRmgTemplateLoader::loadTemplates()
const auto & zoneNode = zonePair.second;
//TODO: do these lines even do anything?
if(!zoneNode["terrainTypeLikeZone"].isNull()) zone->setTerrainTypeLikeZone(boost::lexical_cast<int>(zoneNode["terrainTypeLikeZone"].String()));
if(!zoneNode["townTypeLikeZone"].isNull()) zone->setTownTypeLikeZone(boost::lexical_cast<int>(zoneNode["townTypeLikeZone"].String()));
if (!zoneNode["terrainTypeLikeZone"].isNull())
zone->setTerrainTypes (zones[zoneNode["terrainTypeLikeZone"].Float()]->getTerrainTypes());
if (!zoneNode["townTypeLikeZone"].isNull())
zone->setTownTypes (zones[zoneNode["townTypeLikeZone"].Float()]->getTownTypes());
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> terTypes;
if (terTypeStrings.empty()) //nothing was specified
return defaultTerrainTypes;
for(const auto & node : terTypeStrings)
{
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),
townsAreSameType(false), matchTerrainToTown(true), totalDensity(0)
terrainType (ETerrainType::GRASS), townType(0), townsAreSameType(false), matchTerrainToTown(true), totalDensity(0)
{
townTypes = getDefaultTownTypes();
terrainTypes = getDefaultTerrainTypes();
@ -248,32 +248,14 @@ void CRmgTemplateZone::setTerrainTypes(const std::set<ETerrainType> & value)
std::set<ETerrainType> CRmgTemplateZone::getDefaultTerrainTypes() const
{
std::set<ETerrainType> 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);
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<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)
{
connections.push_back (otherZone);
@ -710,13 +692,8 @@ bool CRmgTemplateZone::createTreasurePile (CMapGenerator* gen, int3 &pos)
else //we did not place eveyrthing successfully
return false;
}
bool CRmgTemplateZone::fill(CMapGenerator* gen)
void CRmgTemplateZone::initTownType (CMapGenerator* gen)
{
addAllPossibleObjects (gen);
int townId = 0;
if ((type == ETemplateZoneType::CPU_START) || (type == ETemplateZoneType::PLAYER_START))
{
logGlobal->infoStream() << "Preparing playing zone";
@ -727,12 +704,12 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
PlayerColor player(player_id);
auto town = new CGTownInstance();
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)
townId = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand); // all possible towns, skip neutral
if(townType == CMapGenOptions::CPlayerSettings::RANDOM_TOWN)
townType = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand); // all possible towns, skip neutral
town->subID = townId;
town->subID = townType;
town->tempOwner = player;
town->builtBuildings.insert(BuildingID::FORT);
town->builtBuildings.insert(BuildingID::DEFAULT);
@ -743,7 +720,7 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
// Update player info
playerInfo.allowedFactions.clear();
playerInfo.allowedFactions.insert(townId);
playerInfo.allowedFactions.insert (townType);
playerInfo.hasMainTown = true;
playerInfo.posOfMainTown = town->pos - int3(2, 0, 0);
playerInfo.generateHeroAtMainTown = true;
@ -767,14 +744,24 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
else
{
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";
}
}
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
std::vector<int3> tiles;
for (auto tile : tileinfo)
@ -782,7 +769,14 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
tiles.push_back (tile);
}
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";
for(const auto &obj : requiredObjects)

View File

@ -115,10 +115,6 @@ public:
const std::set<ETerrainType> & getTerrainTypes() const; /// Default: all
void setTerrainTypes(const std::set<ETerrainType> & value);
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;
void setCenter(const float3 &f);
@ -132,6 +128,8 @@ public:
bool addMonster(CMapGenerator* gen, int3 &pos, si32 strength);
bool createTreasurePile (CMapGenerator* gen, int3 &pos);
bool fill(CMapGenerator* gen);
void initTownType (CMapGenerator* gen);
void initTerrainType (CMapGenerator* gen);
void createBorder(CMapGenerator* gen);
void fractalize(CMapGenerator* gen);
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;
bool matchTerrainToTown;
std::set<ETerrainType> terrainTypes;
boost::optional<TRmgTemplateZoneId> terrainTypeLikeZone, townTypeLikeZone;
si32 townType;
ETerrainType terrainType;
ui16 totalDensity;
std::vector<CTreasureInfo> treasureInfo;