add SurroundMap.resize(...)

This commit is contained in:
MihailRis 2024-09-10 23:02:15 +03:00
parent ab110ab8bf
commit 80d8a6738b
2 changed files with 15 additions and 4 deletions

View File

@ -4,9 +4,9 @@
#include <cstring>
#include <stdexcept>
SurroundMap::SurroundMap(int loadDistance, int8_t maxLevel)
: areaMap((loadDistance + maxLevel) * 2 + 1,
(loadDistance + maxLevel) * 2 + 1),
SurroundMap::SurroundMap(int maxLevelRadius, int8_t maxLevel)
: areaMap((maxLevelRadius + maxLevel) * 2 + 1,
(maxLevelRadius + maxLevel) * 2 + 1),
levelCallbacks(maxLevel),
maxLevel(maxLevel)
{}
@ -43,6 +43,11 @@ void SurroundMap::upgrade(int x, int y, int8_t level) {
}
}
void SurroundMap::resize(int maxLevelRadius) {
areaMap.resize((maxLevelRadius + maxLevel) * 2 + 1,
(maxLevelRadius + maxLevel) * 2 + 1);
}
void SurroundMap::completeAt(int x, int y) {
if (!areaMap.isInside(x - maxLevel + 1, y - maxLevel + 1) ||
!areaMap.isInside(x + maxLevel - 1, y + maxLevel - 1)) {

View File

@ -23,7 +23,7 @@ private:
void upgrade(int x, int y, int8_t level);
public:
SurroundMap(int loadDistance, int8_t maxLevel);
SurroundMap(int maxLevelRadius, int8_t maxLevel);
/// @brief Callback called on point level increments
void setLevelCallback(int8_t level, LevelCallback callback);
@ -38,7 +38,13 @@ public:
/// @brief Set map area center
void setCenter(int x, int y);
void resize(int maxLevelRadius);
/// @brief Get level at position
/// @throws std::invalid_argument - position is out of area
int8_t at(int x, int y);
const util::AreaMap2D<int8_t>& getArea() const {
return areaMap;
}
};