2024-09-28 20:50:26 +02:00
|
|
|
/*
|
|
|
|
* BattleHexArray.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "BattleHexArray.h"
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
BattleHexArray::BattleHexArray(std::initializer_list<BattleHex> initList) noexcept
|
|
|
|
: BattleHexArray()
|
|
|
|
{
|
2025-01-13 14:12:00 +01:00
|
|
|
for(const auto & hex : initList)
|
2024-09-28 20:50:26 +02:00
|
|
|
{
|
|
|
|
insert(hex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-02 23:56:04 +01:00
|
|
|
void BattleHexArray::insert(const BattleHexArray & other) noexcept
|
2024-09-28 20:50:26 +02:00
|
|
|
{
|
2025-01-13 14:12:00 +01:00
|
|
|
for(const auto & hex : other)
|
2024-09-28 20:50:26 +02:00
|
|
|
{
|
2025-01-02 23:56:04 +01:00
|
|
|
insert(hex);
|
2024-11-10 21:04:14 +01:00
|
|
|
}
|
2025-01-02 23:56:04 +01:00
|
|
|
}
|
2024-11-10 21:04:14 +01:00
|
|
|
|
2025-01-02 23:56:04 +01:00
|
|
|
void BattleHexArray::clear() noexcept
|
|
|
|
{
|
2025-01-13 14:12:00 +01:00
|
|
|
for(const auto & hex : internalStorage)
|
|
|
|
presenceFlags[hex.toInt()] = false;
|
2025-01-02 23:56:04 +01:00
|
|
|
|
|
|
|
internalStorage.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
BattleHexArray::ArrayOfBattleHexArrays BattleHexArray::precalculateNeighbouringTiles()
|
2024-11-04 13:27:19 +01:00
|
|
|
{
|
2024-12-04 21:37:31 +01:00
|
|
|
BattleHexArray::ArrayOfBattleHexArrays ret;
|
2024-11-04 13:27:19 +01:00
|
|
|
|
|
|
|
for(si16 hex = 0; hex < GameConstants::BFIELD_SIZE; hex++)
|
|
|
|
{
|
2025-01-02 23:56:04 +01:00
|
|
|
BattleHexArray hexes;
|
|
|
|
|
|
|
|
for(auto dir : BattleHex::hexagonalDirections())
|
|
|
|
hexes.checkAndPush(BattleHex(hex).cloneInDirection(dir, false));
|
2024-11-04 13:27:19 +01:00
|
|
|
|
|
|
|
size_t index = 0;
|
|
|
|
ret[hex].resize(hexes.size());
|
|
|
|
for(auto neighbour : hexes)
|
|
|
|
ret[hex].set(index++, neighbour);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2024-11-10 21:04:14 +01:00
|
|
|
}
|
|
|
|
|
2025-01-02 23:56:04 +01:00
|
|
|
BattleHexArray::ArrayOfBattleHexArrays BattleHexArray::precalculateAllNeighbouringTiles()
|
2024-11-10 21:04:14 +01:00
|
|
|
{
|
2024-12-06 19:59:05 +01:00
|
|
|
ArrayOfBattleHexArrays ret;
|
2024-11-10 21:04:14 +01:00
|
|
|
|
2025-01-02 23:56:04 +01:00
|
|
|
for(si16 hex = 0; hex < GameConstants::BFIELD_SIZE; hex++)
|
|
|
|
{
|
|
|
|
ret[hex].resize(6);
|
|
|
|
|
|
|
|
for(auto dir : BattleHex::hexagonalDirections())
|
|
|
|
ret[hex].set(dir, BattleHex(hex).cloneInDirection(dir, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2025-01-06 23:05:45 +01:00
|
|
|
BattleHexArray::ArrayOfBattleHexArrays BattleHexArray::precalculateNeighbouringTilesDoubleWide(BattleSide side)
|
2025-01-02 23:56:04 +01:00
|
|
|
{
|
|
|
|
ArrayOfBattleHexArrays ret;
|
|
|
|
|
|
|
|
for(si16 h = 0; h < GameConstants::BFIELD_SIZE; h++)
|
2024-12-04 21:37:31 +01:00
|
|
|
{
|
2024-12-06 19:59:05 +01:00
|
|
|
BattleHexArray hexes;
|
2025-01-02 23:56:04 +01:00
|
|
|
BattleHex hex(h);
|
2024-11-10 21:04:14 +01:00
|
|
|
|
2024-12-06 19:59:05 +01:00
|
|
|
if(side == BattleSide::ATTACKER)
|
2024-12-04 21:37:31 +01:00
|
|
|
{
|
2025-01-02 23:56:04 +01:00
|
|
|
const BattleHex otherHex = h - 1;
|
2024-11-10 21:04:14 +01:00
|
|
|
|
2024-12-06 19:59:05 +01:00
|
|
|
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));
|
2024-12-04 21:37:31 +01:00
|
|
|
|
2024-12-06 19:59:05 +01:00
|
|
|
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)
|
|
|
|
{
|
2025-01-02 23:56:04 +01:00
|
|
|
const BattleHex otherHex = h + 1;
|
2024-12-04 21:37:31 +01:00
|
|
|
|
2024-12-06 19:59:05 +01:00
|
|
|
hexes.checkAndPush(hex.cloneInDirection(BattleHex::EDir::TOP_LEFT, false));
|
2024-12-04 21:37:31 +01:00
|
|
|
|
2024-12-06 19:59:05 +01:00
|
|
|
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));
|
2024-12-04 21:37:31 +01:00
|
|
|
|
2024-12-06 19:59:05 +01:00
|
|
|
hexes.checkAndPush(hex.cloneInDirection(BattleHex::EDir::BOTTOM_LEFT, false));
|
|
|
|
hexes.checkAndPush(hex.cloneInDirection(BattleHex::EDir::LEFT, false));
|
2024-12-04 21:37:31 +01:00
|
|
|
}
|
2025-01-02 23:56:04 +01:00
|
|
|
ret[h] = std::move(hexes);
|
2024-11-10 21:04:14 +01:00
|
|
|
}
|
|
|
|
|
2024-12-06 19:59:05 +01:00
|
|
|
return ret;
|
2024-11-10 21:04:14 +01:00
|
|
|
}
|
|
|
|
|
2025-01-02 23:56:04 +01:00
|
|
|
const BattleHexArray::ArrayOfBattleHexArrays BattleHexArray::neighbouringTiles = precalculateNeighbouringTiles();
|
|
|
|
const BattleHexArray::ArrayOfBattleHexArrays BattleHexArray::allNeighbouringTiles = precalculateAllNeighbouringTiles();
|
2025-01-06 23:05:45 +01:00
|
|
|
const std::map<BattleSide, BattleHexArray::ArrayOfBattleHexArrays> BattleHexArray::neighbouringTilesDoubleWide =
|
2024-09-28 20:50:26 +02:00
|
|
|
{
|
2025-01-06 23:05:45 +01:00
|
|
|
{ BattleSide::ATTACKER, precalculateNeighbouringTilesDoubleWide(BattleSide::ATTACKER) },
|
|
|
|
{ BattleSide::DEFENDER, precalculateNeighbouringTilesDoubleWide(BattleSide::DEFENDER) }
|
2025-01-02 23:56:04 +01:00
|
|
|
};
|
2024-11-04 13:27:19 +01:00
|
|
|
|
2025-01-29 23:02:51 +00:00
|
|
|
VCMI_LIB_NAMESPACE_END
|