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

Placing towns according to template.

This commit is contained in:
DjWarmonger 2014-06-15 21:23:32 +02:00
parent 8e66b7168a
commit 60df94a3f5
2 changed files with 88 additions and 4 deletions

View File

@ -290,7 +290,7 @@
"5" :
{
"type" : "treasure", "size" : 40,
"neutralTowns" : { "towns" : 2 },
"neutralTowns" : { "castles" : 2 },
"terrainTypes" : [ "sand" ], "matchTerrainToTown" : false,
"monsters" : "strong",
"mines" : {"gold" : 4},

View File

@ -710,28 +710,35 @@ bool CRmgTemplateZone::createTreasurePile (CMapGenerator* gen, int3 &pos)
}
void CRmgTemplateZone::initTownType (CMapGenerator* gen)
{
//FIXME: handle case that this player is not present -> towns should be set to neutral
int totalTowns = 0;
if ((type == ETemplateZoneType::CPU_START) || (type == ETemplateZoneType::PLAYER_START))
{
//set zone types to player faction, generate main town
logGlobal->infoStream() << "Preparing playing zone";
int player_id = *owner - 1;
auto & playerInfo = gen->map->players[player_id];
if (playerInfo.canAnyonePlay())
{
PlayerColor player(player_id);
auto town = new CGTownInstance();
town->ID = Obj::TOWN;
townType = gen->mapGenOptions->getPlayersSettings().find(player)->second.getStartingTown();
if(townType == CMapGenOptions::CPlayerSettings::RANDOM_TOWN)
townType = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand); // all possible towns, skip neutral
auto town = new CGTownInstance();
town->ID = Obj::TOWN;
town->subID = townType;
town->tempOwner = player;
town->builtBuildings.insert(BuildingID::FORT);
town->builtBuildings.insert(BuildingID::DEFAULT);
placeObject(gen, town, getPos() + town->getVisitableOffset()); //towns are big objects and should be centered around visitable position
totalTowns++;
logGlobal->traceStream() << "Fill player info " << player_id;
// Update player info
@ -741,6 +748,42 @@ void CRmgTemplateZone::initTownType (CMapGenerator* gen)
playerInfo.posOfMainTown = town->pos - int3(2, 0, 0);
playerInfo.generateHeroAtMainTown = true;
//now create actual towns
for (int i = 1; i < playerTowns.getCastleCount(); i++)
{
auto town = new CGTownInstance();
town->ID = Obj::TOWN;
if (townsAreSameType)
town->subID = townType;
else
town->subID = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand); //TODO: check allowed town types for this zone
town->tempOwner = player;
town->builtBuildings.insert(BuildingID::FORT);
town->builtBuildings.insert(BuildingID::DEFAULT);
addRequiredObject (town);
totalTowns++;
}
for (int i = 0; i < playerTowns.getTownCount(); i++)
{
auto town = new CGTownInstance();
town->ID = Obj::TOWN;
if (townsAreSameType)
town->subID = townType;
else
town->subID = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand); //TODO: check allowed town types for this zone
town->tempOwner = player;
town->builtBuildings.insert(BuildingID::DEFAULT);
addRequiredObject (town);
totalTowns++;
}
//requiredObjects.push_back(town);
}
else
@ -754,6 +797,47 @@ void CRmgTemplateZone::initTownType (CMapGenerator* gen)
{
townType = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand);
}
for (int i = 0; i < neutralTowns.getCastleCount(); i++)
{
auto town = new CGTownInstance();
town->ID = Obj::TOWN;
if (townsAreSameType || totalTowns == 0) //first town must match zone type
town->subID = townType;
else
town->subID = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand); //TODO: check allowed town types for this zone
town->tempOwner = PlayerColor::NEUTRAL;
town->builtBuildings.insert(BuildingID::FORT);
town->builtBuildings.insert(BuildingID::DEFAULT);
if (!totalTowns) //first town in zone goes in the middle
placeObject(gen, town, getPos() + town->getVisitableOffset());
else
addRequiredObject (town);
totalTowns++;
}
for (int i = 0; i < neutralTowns.getTownCount(); i++)
{
auto town = new CGTownInstance();
town->ID = Obj::TOWN;
if (townsAreSameType || totalTowns == 0)
town->subID = townType;
else
town->subID = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand); //TODO: check allowed town types for this zone
town->tempOwner = PlayerColor::NEUTRAL;
town->builtBuildings.insert(BuildingID::DEFAULT);
if (!totalTowns)
placeObject(gen, town, getPos() + town->getVisitableOffset());
else
addRequiredObject (town);
totalTowns++;
}
}
void CRmgTemplateZone::initTerrainType (CMapGenerator* gen)