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

Obstacles won't be generated around unguarded objects.

This commit is contained in:
DjWarmonger 2014-06-04 20:59:01 +02:00
parent 464ffc4afa
commit c470b9606b
3 changed files with 15 additions and 8 deletions

View File

@ -104,13 +104,13 @@
{ {
"type" : "playerStart", "size" : 3, "owner" : 2, "type" : "playerStart", "size" : 3, "owner" : 2,
"playerTowns" : { "castles" : 1 }, "playerTowns" : { "castles" : 1 },
"treaureLikeZone" : 1 "treasureLikeZone" : 1
}, },
"3" : "3" :
{ {
"type" : "playerStart", "size" : 3, "owner" : 3, "type" : "playerStart", "size" : 3, "owner" : 3,
"playerTowns" : { "castles" : 1 }, "playerTowns" : { "castles" : 1 },
"treaureLikeZone" : 1 "treasureLikeZone" : 1
}, },
"4" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "1", "treasure" : {"min" : 3000, "max": 10000} }, "4" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "1", "treasure" : {"min" : 3000, "max": 10000} },
"5" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "1", "treasureLikeZone" : 4}, "5" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "1", "treasureLikeZone" : 4},

View File

@ -412,7 +412,7 @@ void CRmgTemplateZone::addRequiredObject(CGObjectInstance * obj, si32 strength)
requiredObjects.push_back(std::make_pair(obj, strength)); requiredObjects.push_back(std::make_pair(obj, strength));
} }
void CRmgTemplateZone::addMonster(CMapGenerator* gen, int3 &pos, si32 strength) bool CRmgTemplateZone::addMonster(CMapGenerator* gen, int3 &pos, si32 strength)
{ {
//precalculate actual (randomized) monster strength based on this post //precalculate actual (randomized) monster strength based on this post
//http://forum.vcmi.eu/viewtopic.php?p=12426#12426 //http://forum.vcmi.eu/viewtopic.php?p=12426#12426
@ -430,7 +430,7 @@ void CRmgTemplateZone::addMonster(CMapGenerator* gen, int3 &pos, si32 strength)
strength = strength1 + strength2; strength = strength1 + strength2;
if (strength < 2000) if (strength < 2000)
return; //no guard at all return false; //no guard at all
CreatureID creId = CreatureID::NONE; CreatureID creId = CreatureID::NONE;
int amount = 0; int amount = 0;
@ -455,6 +455,7 @@ void CRmgTemplateZone::addMonster(CMapGenerator* gen, int3 &pos, si32 strength)
guard->putStack(SlotID(0), hlp); guard->putStack(SlotID(0), hlp);
placeObject(gen, guard, pos); placeObject(gen, guard, pos);
return true;
} }
bool CRmgTemplateZone::createTreasurePile (CMapGenerator* gen, int3 &pos) bool CRmgTemplateZone::createTreasurePile (CMapGenerator* gen, int3 &pos)
@ -903,7 +904,6 @@ bool CRmgTemplateZone::guardObject(CMapGenerator* gen, CGObjectInstance* object,
if (gen->isPossible(pos)) if (gen->isPossible(pos))
{ {
tiles.push_back(pos); tiles.push_back(pos);
gen->setOccupied(pos, ETileType::BLOCKED);
}; };
}); });
if ( ! tiles.size()) if ( ! tiles.size())
@ -912,9 +912,16 @@ bool CRmgTemplateZone::guardObject(CMapGenerator* gen, CGObjectInstance* object,
return false; return false;
} }
auto guard_tile = *RandomGeneratorUtil::nextItem(tiles, gen->rand); auto guard_tile = *RandomGeneratorUtil::nextItem(tiles, gen->rand);
gen->setOccupied (guard_tile, ETileType::USED);
addMonster (gen, guard_tile, str); if (addMonster (gen, guard_tile, str)) //do not lace obstacles aroudn unguarded object
{
for (auto pos : tiles)
gen->setOccupied(pos, ETileType::BLOCKED);
gen->setOccupied (guard_tile, ETileType::USED);
}
else
gen->setOccupied (guard_tile, ETileType::FREE);
return true; return true;
} }

View File

@ -128,7 +128,7 @@ public:
std::set<int3> getTileInfo () const; std::set<int3> getTileInfo () const;
void addRequiredObject(CGObjectInstance * obj, si32 guardStrength=0); void addRequiredObject(CGObjectInstance * obj, si32 guardStrength=0);
void addMonster(CMapGenerator* gen, int3 &pos, si32 strength); bool addMonster(CMapGenerator* gen, int3 &pos, si32 strength);
bool createTreasurePile (CMapGenerator* gen, int3 &pos); bool createTreasurePile (CMapGenerator* gen, int3 &pos);
bool fill(CMapGenerator* gen); bool fill(CMapGenerator* gen);
void createBorder(CMapGenerator* gen); void createBorder(CMapGenerator* gen);