mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-15 00:05:02 +02:00
BattleStart pack now uses unique_ptr
This commit is contained in:
@ -754,7 +754,7 @@ void ApplyFirstClientNetPackVisitor::visitBattleStart(BattleStart & pack)
|
||||
|
||||
void ApplyClientNetPackVisitor::visitBattleStart(BattleStart & pack)
|
||||
{
|
||||
cl.battleStarted(pack.info);
|
||||
cl.battleStarted(pack.info.get());
|
||||
}
|
||||
|
||||
void ApplyFirstClientNetPackVisitor::visitBattleNextRound(BattleNextRound & pack)
|
||||
|
@ -156,10 +156,10 @@ struct RangeGenerator
|
||||
std::function<int()> myRand;
|
||||
};
|
||||
|
||||
BattleInfo * BattleInfo::setupBattle(const int3 & tile, TerrainId terrain, const BattleField & battlefieldType, BattleSideArray<const CArmedInstance *> armies, BattleSideArray<const CGHeroInstance *> heroes, const BattleLayout & layout, const CGTownInstance * town)
|
||||
std::unique_ptr<BattleInfo> BattleInfo::setupBattle(const int3 & tile, TerrainId terrain, const BattleField & battlefieldType, BattleSideArray<const CArmedInstance *> armies, BattleSideArray<const CGHeroInstance *> heroes, const BattleLayout & layout, const CGTownInstance * town)
|
||||
{
|
||||
CMP_stack cmpst;
|
||||
auto * currentBattle = new BattleInfo(layout);
|
||||
auto currentBattle = std::make_unique<BattleInfo>(layout);
|
||||
|
||||
for(auto i : { BattleSide::LEFT_SIDE, BattleSide::RIGHT_SIDE})
|
||||
currentBattle->sides[i].init(heroes[i], armies[i]);
|
||||
|
@ -154,7 +154,7 @@ public:
|
||||
const CGHeroInstance * getHero(const PlayerColor & player) const; //returns fighting hero that belongs to given player
|
||||
|
||||
void localInit();
|
||||
static BattleInfo * setupBattle(const int3 & tile, TerrainId, const BattleField & battlefieldType, BattleSideArray<const CArmedInstance *> armies, BattleSideArray<const CGHeroInstance *> heroes, const BattleLayout & layout, const CGTownInstance * town);
|
||||
static std::unique_ptr<BattleInfo> setupBattle(const int3 & tile, TerrainId, const BattleField & battlefieldType, BattleSideArray<const CArmedInstance *> armies, BattleSideArray<const CGHeroInstance *> heroes, const BattleLayout & layout, const CGTownInstance * town);
|
||||
|
||||
BattleSide whatSide(const PlayerColor & player) const;
|
||||
|
||||
|
@ -62,8 +62,6 @@ class DLL_LINKAGE CMap : public CMapHeader, public GameCallbackHolder
|
||||
|
||||
std::unique_ptr<GameSettings> gameSettings;
|
||||
|
||||
/// Central lists of items in game. Position of item in the vectors below is their (instance) id.
|
||||
std::vector< std::shared_ptr<CGObjectInstance> > objects;
|
||||
/// All quests that are currently present on map
|
||||
std::vector<std::shared_ptr<CQuest>> quests;
|
||||
/// All artifacts that exists on map, whether on map, in hero inventory, or stored in some object
|
||||
@ -78,6 +76,10 @@ class DLL_LINKAGE CMap : public CMapHeader, public GameCallbackHolder
|
||||
std::vector<ObjectInstanceID> heroesOnMap;
|
||||
|
||||
public:
|
||||
/// Central lists of items in game. Position of item in the vectors below is their (instance) id.
|
||||
/// TODO: make private
|
||||
std::vector< std::shared_ptr<CGObjectInstance> > objects;
|
||||
|
||||
explicit CMap(IGameCallback *cb);
|
||||
~CMap();
|
||||
void initTerrain();
|
||||
|
@ -2005,11 +2005,10 @@ void BattleStart::applyGs(CGameState *gs)
|
||||
{
|
||||
assert(battleID == gs->nextBattleID);
|
||||
|
||||
gs->currentBattles.emplace_back(info);
|
||||
|
||||
info->battleID = gs->nextBattleID;
|
||||
info->localInit();
|
||||
|
||||
gs->currentBattles.push_back(std::move(info));
|
||||
gs->nextBattleID = BattleID(gs->nextBattleID.getNum() + 1);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "PacksForClient.h"
|
||||
#include "../battle/BattleHexArray.h"
|
||||
#include "../battle/BattleAction.h"
|
||||
#include "../battle/BattleInfo.h"
|
||||
#include "../texts/MetaString.h"
|
||||
|
||||
class CClient;
|
||||
@ -30,7 +31,7 @@ struct DLL_LINKAGE BattleStart : public CPackForClient
|
||||
void applyGs(CGameState * gs) override;
|
||||
|
||||
BattleID battleID = BattleID::NONE;
|
||||
BattleInfo * info = nullptr;
|
||||
std::unique_ptr<BattleInfo> info;
|
||||
|
||||
void visitTyped(ICPackVisitor & visitor) override;
|
||||
|
||||
|
@ -44,25 +44,19 @@ public:
|
||||
static std::vector<int> getObjectIndexes(const CMap & map)
|
||||
{
|
||||
std::vector<int> result;
|
||||
for(int i = 0; i < map.objects.size(); ++i)
|
||||
{
|
||||
if(auto obj = dynamic_cast<T*>(map.objects.at(i).get()))
|
||||
result.push_back(i);
|
||||
}
|
||||
for(const auto & obj : map.getObjects<T>())
|
||||
result.push_back(obj->id.getNum());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static int getObjectByPos(const CMap & map, const int3 & pos)
|
||||
{
|
||||
for(int i = 0; i < map.objects.size(); ++i)
|
||||
{
|
||||
if(auto obj = dynamic_cast<T*>(map.objects.at(i).get()))
|
||||
{
|
||||
for(const auto & obj : map.getObjects<T>())
|
||||
if(obj->pos == pos)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return obj->id.getNum();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -200,10 +200,10 @@ public:
|
||||
|
||||
//send info about battles
|
||||
|
||||
BattleInfo * battle = BattleInfo::setupBattle(tile, terrain, terType, armedInstancies, heroes, layout, nullptr);
|
||||
auto battle = BattleInfo::setupBattle(tile, terrain, terType, armedInstancies, heroes, layout, nullptr);
|
||||
|
||||
BattleStart bs;
|
||||
bs.info = battle;
|
||||
bs.info = std::move(battle);
|
||||
ASSERT_EQ(gameState->currentBattles.size(), 0);
|
||||
gameCallback->sendAndApply(bs);
|
||||
ASSERT_EQ(gameState->currentBattles.size(), 1);
|
||||
|
Reference in New Issue
Block a user