1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

CArtifactsOfHero: use shared_ptr for SCommonPart

This commit is contained in:
Arseniy Shestakov 2016-08-30 07:05:31 +03:00
parent b8f4fdc2f2
commit 0236309d25
6 changed files with 9 additions and 9 deletions

View File

@ -595,7 +595,7 @@ CArtifactsOfHero::CArtifactsOfHero(std::map<ArtifactPosition, CArtPlace *> ArtWo
{
if(createCommonPart)
{
commonInfo = new CArtifactsOfHero::SCommonPart;
commonInfo = std::make_shared<CArtifactsOfHero::SCommonPart>();
commonInfo->participants.insert(this);
}
@ -622,7 +622,7 @@ CArtifactsOfHero::CArtifactsOfHero(const Point& position, bool createCommonPart
{
if(createCommonPart)
{
commonInfo = new CArtifactsOfHero::SCommonPart;
commonInfo = std::make_shared<CArtifactsOfHero::SCommonPart>();
commonInfo->participants.insert(this);
}

View File

@ -107,7 +107,8 @@ public:
std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
void reset();
} * commonInfo; //when we have more than one CArtifactsOfHero in one window with exchange possibility, we use this (eg. in exchange window); to be provided externally
};
std::shared_ptr<SCommonPart> commonInfo; //when we have more than one CArtifactsOfHero in one window with exchange possibility, we use this (eg. in exchange window); to be provided externally
bool updateState; // Whether the commonInfo should be updated on setHero or not.

View File

@ -169,7 +169,7 @@ bool CGarrisonSlot::highlightOrDropArtifact()
bool artSelected = false;
if (CWindowWithArtifacts* chw = dynamic_cast<CWindowWithArtifacts*>(GH.topInt())) //dirty solution
{
const CArtifactsOfHero::SCommonPart *commonInfo = chw->artSets.front()->commonInfo;
const std::shared_ptr<CArtifactsOfHero::SCommonPart> commonInfo = chw->artSets.front()->commonInfo;
if (const CArtifactInstance *art = commonInfo->src.art)
{
const CGHeroInstance *srcHero = commonInfo->src.AOH->getHero();

View File

@ -47,7 +47,7 @@ const TBonusListPtr CHeroWithMaybePickedArtifact::getAllBonuses(const CSelector
TBonusListPtr heroBonuses = hero->getAllBonuses(selector, limit, hero);
TBonusListPtr bonusesFromPickedUpArtifact;
CArtifactsOfHero::SCommonPart *cp = cww->artSets.size() ? cww->artSets.front()->commonInfo : nullptr;
std::shared_ptr<CArtifactsOfHero::SCommonPart> cp = cww->artSets.size() ? cww->artSets.front()->commonInfo : nullptr;
if(cp && cp->src.art && cp->src.valid() && cp->src.AOH && cp->src.AOH->getHero() == hero)
{
bonusesFromPickedUpArtifact = cp->src.art->getAllBonuses(selector, limit, hero);
@ -317,7 +317,7 @@ void CHeroWindow::commanderWindow()
{
//TODO: allow equipping commander artifacts by drag / drop
//bool artSelected = false;
const CArtifactsOfHero::SCommonPart *commonInfo = artSets.front()->commonInfo;
const std::shared_ptr<CArtifactsOfHero::SCommonPart> commonInfo = artSets.front()->commonInfo;
if (const CArtifactInstance *art = commonInfo->src.art)
{

View File

@ -390,7 +390,7 @@ void CTradeWindow::initItems(bool Left)
BLOCK_CAPTURING;
arts = new CArtifactsOfHero(Point(pos.x+xOffset, pos.y+yOffset));
arts->commonInfo = new CArtifactsOfHero::SCommonPart;
arts->commonInfo = std::make_shared<CArtifactsOfHero::SCommonPart>();
arts->commonInfo->participants.insert(arts);
arts->recActions = 255;
arts->setHero(hero);

View File

@ -908,7 +908,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
prepareBackground();
artifs[0] = new CArtifactsOfHero(Point(-334, 150));
artifs[0]->commonInfo = new CArtifactsOfHero::SCommonPart;
artifs[0]->commonInfo = std::make_shared<CArtifactsOfHero::SCommonPart>();
artifs[0]->commonInfo->participants.insert(artifs[0]);
artifs[0]->setHero(heroInst[0]);
artifs[1] = new CArtifactsOfHero(Point(96, 150));
@ -1004,7 +1004,6 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
CExchangeWindow::~CExchangeWindow() //d-tor
{
delete artifs[0]->commonInfo;
artifs[0]->commonInfo = nullptr;
artifs[1]->commonInfo = nullptr;
}