1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Merge pull request #1168 from Nordsoft91/fix-obstacles-generation

Fix obstacles generation
This commit is contained in:
Andrii Danylchenko
2022-11-27 09:56:11 +02:00
committed by GitHub

View File

@@ -261,13 +261,12 @@ BattleInfo * BattleInfo::setupBattle(const int3 & tile, TerrainId terrain, const
auto * info = Obstacle(id).getInfo(); auto * info = Obstacle(id).getInfo();
return info && !info->isAbsoluteObstacle && info->isAppropriate(curB->terrainType, battlefieldType); return info && !info->isAbsoluteObstacle && info->isAppropriate(curB->terrainType, battlefieldType);
}; };
RangeGenerator obidgen(0, VLC->obstacleHandler->objects.size() - 1, ourRand);
if(r.rand(1,100) <= 40) //put cliff-like obstacle if(r.rand(1,100) <= 40) //put cliff-like obstacle
{ {
try try
{ {
RangeGenerator obidgen(0, VLC->obstacleHandler->objects.size() - 1, ourRand);
auto obstPtr = std::make_shared<CObstacleInstance>(); auto obstPtr = std::make_shared<CObstacleInstance>();
obstPtr->obstacleType = CObstacleInstance::ABSOLUTE_OBSTACLE; obstPtr->obstacleType = CObstacleInstance::ABSOLUTE_OBSTACLE;
obstPtr->ID = obidgen.getSuchNumber(appropriateAbsoluteObstacle); obstPtr->ID = obidgen.getSuchNumber(appropriateAbsoluteObstacle);
@@ -289,6 +288,7 @@ BattleInfo * BattleInfo::setupBattle(const int3 & tile, TerrainId terrain, const
{ {
while(tilesToBlock > 0) while(tilesToBlock > 0)
{ {
RangeGenerator obidgen(0, VLC->obstacleHandler->objects.size() - 1, ourRand);
auto tileAccessibility = curB->getAccesibility(); auto tileAccessibility = curB->getAccesibility();
const int obid = obidgen.getSuchNumber(appropriateUsualObstacle); const int obid = obidgen.getSuchNumber(appropriateUsualObstacle);
const ObstacleInfo &obi = *Obstacle(obid).getInfo(); const ObstacleInfo &obi = *Obstacle(obid).getInfo();