1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-25 21:38:59 +02:00

Refacoring, tweaks.

This commit is contained in:
DjWarmonger 2014-07-03 09:39:26 +02:00
parent abd6fe73dd
commit cc8d484775
2 changed files with 35 additions and 78 deletions

View File

@ -1,4 +1,6 @@
0.95 -> 0.next
0.96 0> 0.next
0.95 -> 0.96 (Jul 01 2014)
GENERAL:
* (linux) now VCMI follows XDG specifications. See http://forum.vcmi.eu/viewtopic.php?t=858
@ -15,7 +17,7 @@ SPELLS:
* New configuration format: http://wiki.vcmi.eu/index.php?title=Spell_Format
RANDOM MAP GENERATOR
* Towns form mods cna be used
* Towns from mods can be used
* Reading connections, terrains, towns and mines from template
* Zone placement
* Zone borders and connections, fractalized paths inside zones

View File

@ -726,10 +726,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;
auto addNewTowns = [&totalTowns, gen, this](int count, bool hasFort, PlayerColor player)
{
for (int i = 0; i < count; i++)
{
auto town = new CGTownInstance();
town->ID = Obj::TOWN;
if (this->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;
if (hasFort)
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++;
}
};
if ((type == ETemplateZoneType::CPU_START) || (type == ETemplateZoneType::PLAYER_START))
{
//set zone types to player faction, generate main town
@ -765,40 +790,8 @@ void CRmgTemplateZone::initTownType (CMapGenerator* gen)
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++;
}
addNewTowns (playerTowns.getCastleCount() - 1, true, player);
addNewTowns (playerTowns.getTownCount(), false, player);
//requiredObjects.push_back(town);
}
@ -814,46 +807,8 @@ 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++;
}
addNewTowns (neutralTowns.getCastleCount(), true, PlayerColor::NEUTRAL);
addNewTowns (neutralTowns.getTownCount(), false, PlayerColor::NEUTRAL);
}
void CRmgTemplateZone::initTerrainType (CMapGenerator* gen)
@ -1200,7 +1155,7 @@ void CRmgTemplateZone::placeObject(CMapGenerator* gen, CGObjectInstance* object,
}
for(auto tile : tileinfo)
{
si32 d = pos.dist2d(tile);
si32 d = pos.dist2dSQ(tile); //optimization, only relative distance is interesting
gen->setNearestObjectDistance(tile, std::min(d, gen->getNearestObjectDistance(tile)));
}
}