1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Contains returns false instead of true for invalid hexes

This commit is contained in:
MichalZr6
2025-02-08 14:57:20 +01:00
parent f7305fd1c2
commit 4b0fe811ac

View File

@@ -77,7 +77,7 @@ public:
void insert(const BattleHex & hex) noexcept
{
if(contains(hex))
if(!isValidToInsert(hex))
return;
presenceFlags.set(hex.toInt());
@@ -86,6 +86,9 @@ public:
void set(size_type index, const BattleHex & hex)
{
if(!isValidToInsert(hex))
return;
if(index >= internalStorage.size())
{
logGlobal->error("Invalid BattleHexArray::set index parameter. It is " + std::to_string(index)
@@ -94,9 +97,6 @@ public:
+ " and current size is " + std::to_string(internalStorage.size()));
}
if(contains(hex))
return;
presenceFlags.set(hex.toInt());
internalStorage[index] = hex;
}
@@ -198,7 +198,7 @@ public:
{
static const BattleHexArray invalid;
if (hex.isValid())
if(hex.isValid())
return allNeighbouringTiles[hex.toInt()];
else
return invalid;
@@ -209,7 +209,7 @@ public:
{
static const BattleHexArray invalid;
if (hex.isValid())
if(hex.isValid())
return neighbouringTiles[hex.toInt()];
else
return invalid;
@@ -223,13 +223,23 @@ public:
return neighbouringTilesDoubleWide.at(side)[hex.toInt()];
}
/// note: returns true when param is ivalid BattleHex
[[nodiscard]] inline bool isValidToInsert(const BattleHex & hex) const noexcept
{
if(!hex.isValid())
return false;
if(contains(hex))
return false;
return true;
}
[[nodiscard]] inline bool contains(const BattleHex & hex) const noexcept
{
if(hex.isValid())
return presenceFlags.test(hex.toInt());
return true;
return false;
}
template <typename Serializer>