Merge pull request #6410 from mrhaandi/fix-next-obstacle-id

Add CBattleInfoEssentials::nextObstacleId
This commit is contained in:
Ivan Savenko
2025-12-08 20:45:23 +02:00
committed by GitHub
4 changed files with 14 additions and 12 deletions
+11
View File
@@ -44,6 +44,17 @@ int32_t CBattleInfoEssentials::battleGetEnchanterCounter(BattleSide side) const
return getBattle()->getEnchanterCounter(side);
}
int32_t CBattleInfoEssentials::nextObstacleId() const
{
int32_t maxId = -1;
for (const auto & obstacle : getBattle()->getAllObstacles())
{
if (obstacle->uniqueID > maxId)
maxId = obstacle->uniqueID;
}
return maxId + 1;
}
std::vector<std::shared_ptr<const CObstacleInstance>> CBattleInfoEssentials::battleGetAllObstacles(std::optional<BattleSide> perspective) const
{
std::vector<std::shared_ptr<const CObstacleInstance> > ret;
+1
View File
@@ -43,6 +43,7 @@ public:
BattleField battleGetBattlefieldType() const override;
int32_t battleGetEnchanterCounter(BattleSide side) const;
int32_t nextObstacleId() const; //returns next available obstacle ID
std::vector<std::shared_ptr<const CObstacleInstance>> battleGetAllObstacles(std::optional<BattleSide> perspective = std::nullopt) const; //returns all obstacles on the battlefield
std::shared_ptr<const CObstacleInstance> battleGetObstacleByID(uint32_t ID) const;
+1 -6
View File
@@ -139,12 +139,7 @@ void Moat::placeObstacles(ServerCallback * server, const Mechanics * m, const Ef
BattleObstaclesChanged pack;
pack.battleID = m->battle()->getBattle()->getBattleID();
auto all = m->battle()->battleGetAllObstacles(BattleSide::ALL_KNOWING);
int obstacleIdToGive = 1;
for(auto & one : all)
if(one->uniqueID >= obstacleIdToGive)
obstacleIdToGive = one->uniqueID + 1;
int obstacleIdToGive = m->battle()->nextObstacleId();
for(const auto & destination : moatHexes) //Moat hexes can be different obstacles
{
+1 -6
View File
@@ -275,12 +275,7 @@ void Obstacle::placeObstacles(ServerCallback * server, const Mechanics * m, cons
BattleObstaclesChanged pack;
pack.battleID = m->battle()->getBattle()->getBattleID();
auto all = m->battle()->battleGetAllObstacles(BattleSide::ALL_KNOWING);
int obstacleIdToGive = 1;
for(auto & one : all)
if(one->uniqueID >= obstacleIdToGive)
obstacleIdToGive = one->uniqueID + 1;
int obstacleIdToGive = m->battle()->nextObstacleId();
for(const Destination & destination : target)
{