1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Experiments with object distance.

This commit is contained in:
DjWarmonger 2014-07-25 17:10:16 +02:00
parent 1dd88d394f
commit 67d8a24f0b
4 changed files with 17 additions and 16 deletions

View File

@ -440,7 +440,7 @@ CTileInfo CMapGenerator::getTile(const int3& tile) const
return tiles[tile.x][tile.y][tile.z];
}
void CMapGenerator::setNearestObjectDistance(int3 &tile, int value)
void CMapGenerator::setNearestObjectDistance(int3 &tile, float value)
{
if (!map->isInTheMap(tile))
throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));
@ -448,7 +448,7 @@ void CMapGenerator::setNearestObjectDistance(int3 &tile, int value)
tiles[tile.x][tile.y][tile.z].setNearestObjectDistance(value);
}
int CMapGenerator::getNearestObjectDistance(const int3 &tile) const
float CMapGenerator::getNearestObjectDistance(const int3 &tile) const
{
if (!map->isInTheMap(tile))
throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));

View File

@ -74,8 +74,8 @@ public:
void setOccupied(const int3 &tile, ETileType::ETileType state);
CTileInfo getTile(const int3 & tile) const;
int getNearestObjectDistance(const int3 &tile) const;
void setNearestObjectDistance(int3 &tile, int value);
float getNearestObjectDistance(const int3 &tile) const;
void setNearestObjectDistance(int3 &tile, float value);
int getNextMonlithIndex();
int getPrisonsRemaning() const;

View File

@ -86,14 +86,14 @@ CTileInfo::CTileInfo():nearestObjectDistance(INT_MAX), terrain(ETerrainType::WRO
occupied = ETileType::POSSIBLE; //all tiles are initially possible to place objects or passages
}
int CTileInfo::getNearestObjectDistance() const
float CTileInfo::getNearestObjectDistance() const
{
return nearestObjectDistance;
}
void CTileInfo::setNearestObjectDistance(int value)
void CTileInfo::setNearestObjectDistance(float value)
{
nearestObjectDistance = std::max(0, value); //never negative (or unitialized)
nearestObjectDistance = std::max<float>(0, value); //never negative (or unitialized)
}
bool CTileInfo::shouldBeBlocked() const
{
@ -1077,7 +1077,8 @@ bool CRmgTemplateZone::createRequiredObjects(CMapGenerator* gen)
void CRmgTemplateZone::createTreasures(CMapGenerator* gen)
{
const double minDistance = 3;
const double minDistance = std::max<float>(15.0f / sqrt(totalDensity), 2);
//distance lower than 2 causes objects to overlap and crash
do {
@ -1197,10 +1198,10 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
return true;
}
bool CRmgTemplateZone::findPlaceForTreasurePile(CMapGenerator* gen, si32 min_dist, int3 &pos)
bool CRmgTemplateZone::findPlaceForTreasurePile(CMapGenerator* gen, float min_dist, int3 &pos)
{
//si32 min_dist = sqrt(tileinfo.size()/density);
int best_distance = 0;
float best_distance = 0;
bool result = false;
//logGlobal->infoStream() << boost::format("Min dist for density %f is %d") % density % min_dist;
@ -1385,7 +1386,7 @@ void CRmgTemplateZone::placeObject(CMapGenerator* gen, CGObjectInstance* object,
for(auto tile : possibleTiles) //don't need to mark distance for not possible tiles
{
si32 d = pos.dist2dSQ(tile); //optimization, only relative distance is interesting
gen->setNearestObjectDistance(tile, std::min(d, gen->getNearestObjectDistance(tile)));
gen->setNearestObjectDistance(tile, std::min<float>(d, gen->getNearestObjectDistance(tile)));
}
}
}

View File

@ -40,8 +40,8 @@ public:
CTileInfo();
int getNearestObjectDistance() const;
void setNearestObjectDistance(int value);
float getNearestObjectDistance() const;
void setNearestObjectDistance(float value);
bool isBlocked() const;
bool shouldBeBlocked() const;
bool isPossible() const;
@ -52,7 +52,7 @@ public:
void setTerrainType(ETerrainType value);
private:
int nearestObjectDistance;
float nearestObjectDistance;
ETileType::ETileType occupied;
ETerrainType terrain;
};
@ -215,7 +215,7 @@ private:
void addAllPossibleObjects (CMapGenerator* gen); //add objects, including zone-specific, to possibleObjects
bool isAccessibleFromAnywhere (CMapGenerator* gen, ObjectTemplate &appearance, int3 &tile, const std::set<int3> &tilesBlockedByObject) const;
bool findPlaceForObject(CMapGenerator* gen, CGObjectInstance* obj, si32 min_dist, int3 &pos);
bool findPlaceForTreasurePile(CMapGenerator* gen, si32 min_dist, int3 &pos);
bool findPlaceForTreasurePile(CMapGenerator* gen, float min_dist, int3 &pos);
bool canObstacleBePlacedHere(CMapGenerator* gen, ObjectTemplate &temp, int3 &pos);
void checkAndPlaceObject(CMapGenerator* gen, CGObjectInstance* object, const int3 &pos);
void placeObject(CMapGenerator* gen, CGObjectInstance* object, const int3 &pos, bool updateDistance = true);