|
@@ -74,80 +74,50 @@ BattleHexArray::ArrayOfBattleHexArrays BattleHexArray::calculateNeighbouringTile
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-BattleHexArray BattleHexArray::generateNeighbouringTiles(BattleHex hex)
|
|
|
-{
|
|
|
- BattleHexArray ret;
|
|
|
- for(auto dir : BattleHex::hexagonalDirections())
|
|
|
- ret.checkAndPush(hex.cloneInDirection(dir, false));
|
|
|
-
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-const BattleHexArray & BattleHexArray::getNeighbouringTilesDblWide(BattleHex pos, BattleSide side)
|
|
|
+BattleHexArray::ArrayOfBattleHexArrays BattleHexArray::calculateNeighbouringTilesDblWide(BattleSide side)
|
|
|
{
|
|
|
- static std::array<ArrayOfBattleHexArrays, 2> ret; // 2 -> only two valid sides: ATTACKER and DEFENDER
|
|
|
- size_t sideIdx = static_cast<size_t>(side);
|
|
|
- static bool initialized[2] = { false, false };
|
|
|
+ ArrayOfBattleHexArrays ret;
|
|
|
|
|
|
- if(!initialized[sideIdx])
|
|
|
+ for(BattleHex hex = 0; hex < GameConstants::BFIELD_SIZE; hex.hex++)
|
|
|
{
|
|
|
- // first run, need to initialize
|
|
|
+ BattleHexArray hexes;
|
|
|
|
|
|
- for(BattleHex hex = 0; hex < GameConstants::BFIELD_SIZE; hex.hex++)
|
|
|
+ if(side == BattleSide::ATTACKER)
|
|
|
{
|
|
|
- BattleHexArray hexes;
|
|
|
+ const BattleHex otherHex = hex - 1;
|
|
|
|
|
|
- if(side == BattleSide::ATTACKER)
|
|
|
- {
|
|
|
- const BattleHex otherHex = hex - 1;
|
|
|
+ for(auto dir = static_cast<BattleHex::EDir>(0); dir <= static_cast<BattleHex::EDir>(4); dir = static_cast<BattleHex::EDir>(dir + 1))
|
|
|
+ hexes.checkAndPush(hex.cloneInDirection(dir, false));
|
|
|
|
|
|
- for(auto dir = static_cast<BattleHex::EDir>(0); dir <= static_cast<BattleHex::EDir>(4); dir = static_cast<BattleHex::EDir>(dir + 1))
|
|
|
- hexes.checkAndPush(hex.cloneInDirection(dir, false));
|
|
|
-
|
|
|
- hexes.checkAndPush(otherHex.cloneInDirection(BattleHex::EDir::BOTTOM_LEFT, false));
|
|
|
- hexes.checkAndPush(otherHex.cloneInDirection(BattleHex::EDir::LEFT, false));
|
|
|
- hexes.checkAndPush(otherHex.cloneInDirection(BattleHex::EDir::TOP_LEFT, false));
|
|
|
- }
|
|
|
- else if(side == BattleSide::DEFENDER)
|
|
|
- {
|
|
|
- const BattleHex otherHex = hex + 1;
|
|
|
+ hexes.checkAndPush(otherHex.cloneInDirection(BattleHex::EDir::BOTTOM_LEFT, false));
|
|
|
+ hexes.checkAndPush(otherHex.cloneInDirection(BattleHex::EDir::LEFT, false));
|
|
|
+ hexes.checkAndPush(otherHex.cloneInDirection(BattleHex::EDir::TOP_LEFT, false));
|
|
|
+ }
|
|
|
+ else if(side == BattleSide::DEFENDER)
|
|
|
+ {
|
|
|
+ const BattleHex otherHex = hex + 1;
|
|
|
|
|
|
- hexes.checkAndPush(hex.cloneInDirection(BattleHex::EDir::TOP_LEFT, false));
|
|
|
+ hexes.checkAndPush(hex.cloneInDirection(BattleHex::EDir::TOP_LEFT, false));
|
|
|
|
|
|
- for(auto dir = static_cast<BattleHex::EDir>(0); dir <= static_cast<BattleHex::EDir>(4); dir = static_cast<BattleHex::EDir>(dir + 1))
|
|
|
- hexes.checkAndPush(otherHex.cloneInDirection(dir, false));
|
|
|
+ for(auto dir = static_cast<BattleHex::EDir>(0); dir <= static_cast<BattleHex::EDir>(4); dir = static_cast<BattleHex::EDir>(dir + 1))
|
|
|
+ hexes.checkAndPush(otherHex.cloneInDirection(dir, false));
|
|
|
|
|
|
- hexes.checkAndPush(hex.cloneInDirection(BattleHex::EDir::BOTTOM_LEFT, false));
|
|
|
- hexes.checkAndPush(hex.cloneInDirection(BattleHex::EDir::LEFT, false));
|
|
|
- }
|
|
|
- ret[sideIdx][hex.hex] = std::move(hexes);
|
|
|
+ hexes.checkAndPush(hex.cloneInDirection(BattleHex::EDir::BOTTOM_LEFT, false));
|
|
|
+ hexes.checkAndPush(hex.cloneInDirection(BattleHex::EDir::LEFT, false));
|
|
|
}
|
|
|
- initialized[sideIdx] = true;
|
|
|
+ ret[hex.hex] = std::move(hexes);
|
|
|
}
|
|
|
|
|
|
- return ret[sideIdx][pos.hex];
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
-const BattleHexArray & BattleHexArray::getClosestTilesCache(BattleHex pos, BattleSide side)
|
|
|
+BattleHexArray BattleHexArray::generateNeighbouringTiles(BattleHex hex)
|
|
|
{
|
|
|
- assert(!neighbouringTilesCache.empty());
|
|
|
-
|
|
|
- static std::array<BattleHexArray, 2> ret;
|
|
|
- static bool initialized = false;
|
|
|
- size_t sideIdx = static_cast<size_t>(side);
|
|
|
-
|
|
|
- if(!initialized)
|
|
|
- {
|
|
|
- ret[sideIdx].resize(GameConstants::BFIELD_SIZE);
|
|
|
-
|
|
|
- for(si16 hex = 0; hex < GameConstants::BFIELD_SIZE; hex++)
|
|
|
- {
|
|
|
- ret[sideIdx].set(hex, neighbouringTilesCache[hex].getClosestTile(BattleSide::ATTACKER, hex));
|
|
|
- }
|
|
|
- initialized = true;
|
|
|
- }
|
|
|
-
|
|
|
- return ret[sideIdx];
|
|
|
+ BattleHexArray ret;
|
|
|
+ for(auto dir : BattleHex::hexagonalDirections())
|
|
|
+ ret.checkAndPush(hex.cloneInDirection(dir, false));
|
|
|
+
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
void BattleHexArray::merge(const BattleHexArray & other) noexcept
|
|
@@ -177,5 +147,8 @@ void BattleHexArray::clear() noexcept
|
|
|
}
|
|
|
|
|
|
const BattleHexArray::ArrayOfBattleHexArrays BattleHexArray::neighbouringTilesCache = calculateNeighbouringTiles();
|
|
|
+const std::map<BattleSide, BattleHexArray::ArrayOfBattleHexArrays> BattleHexArray::neighbouringTilesDblWide =
|
|
|
+ { { BattleSide::ATTACKER, calculateNeighbouringTilesDblWide(BattleSide::ATTACKER) },
|
|
|
+ { BattleSide::DEFENDER, calculateNeighbouringTilesDblWide(BattleSide::DEFENDER) } };
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|