mirror of
https://github.com/vcmi/vcmi.git
synced 2026-06-19 22:57:37 +02:00
Merge pull request #6410 from mrhaandi/fix-next-obstacle-id
Add CBattleInfoEssentials::nextObstacleId
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user