mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-17 11:56:46 +02:00
CArtifactsOfHero: use shared_ptr for SCommonPart
This commit is contained in:
parent
b8f4fdc2f2
commit
0236309d25
@ -595,7 +595,7 @@ CArtifactsOfHero::CArtifactsOfHero(std::map<ArtifactPosition, CArtPlace *> ArtWo
|
|||||||
{
|
{
|
||||||
if(createCommonPart)
|
if(createCommonPart)
|
||||||
{
|
{
|
||||||
commonInfo = new CArtifactsOfHero::SCommonPart;
|
commonInfo = std::make_shared<CArtifactsOfHero::SCommonPart>();
|
||||||
commonInfo->participants.insert(this);
|
commonInfo->participants.insert(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,7 +622,7 @@ CArtifactsOfHero::CArtifactsOfHero(const Point& position, bool createCommonPart
|
|||||||
{
|
{
|
||||||
if(createCommonPart)
|
if(createCommonPart)
|
||||||
{
|
{
|
||||||
commonInfo = new CArtifactsOfHero::SCommonPart;
|
commonInfo = std::make_shared<CArtifactsOfHero::SCommonPart>();
|
||||||
commonInfo->participants.insert(this);
|
commonInfo->participants.insert(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,8 @@ public:
|
|||||||
std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
|
std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
|
||||||
|
|
||||||
void reset();
|
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.
|
bool updateState; // Whether the commonInfo should be updated on setHero or not.
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ bool CGarrisonSlot::highlightOrDropArtifact()
|
|||||||
bool artSelected = false;
|
bool artSelected = false;
|
||||||
if (CWindowWithArtifacts* chw = dynamic_cast<CWindowWithArtifacts*>(GH.topInt())) //dirty solution
|
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)
|
if (const CArtifactInstance *art = commonInfo->src.art)
|
||||||
{
|
{
|
||||||
const CGHeroInstance *srcHero = commonInfo->src.AOH->getHero();
|
const CGHeroInstance *srcHero = commonInfo->src.AOH->getHero();
|
||||||
|
@ -47,7 +47,7 @@ const TBonusListPtr CHeroWithMaybePickedArtifact::getAllBonuses(const CSelector
|
|||||||
TBonusListPtr heroBonuses = hero->getAllBonuses(selector, limit, hero);
|
TBonusListPtr heroBonuses = hero->getAllBonuses(selector, limit, hero);
|
||||||
TBonusListPtr bonusesFromPickedUpArtifact;
|
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)
|
if(cp && cp->src.art && cp->src.valid() && cp->src.AOH && cp->src.AOH->getHero() == hero)
|
||||||
{
|
{
|
||||||
bonusesFromPickedUpArtifact = cp->src.art->getAllBonuses(selector, limit, hero);
|
bonusesFromPickedUpArtifact = cp->src.art->getAllBonuses(selector, limit, hero);
|
||||||
@ -317,7 +317,7 @@ void CHeroWindow::commanderWindow()
|
|||||||
{
|
{
|
||||||
//TODO: allow equipping commander artifacts by drag / drop
|
//TODO: allow equipping commander artifacts by drag / drop
|
||||||
//bool artSelected = false;
|
//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)
|
if (const CArtifactInstance *art = commonInfo->src.art)
|
||||||
{
|
{
|
||||||
|
@ -390,7 +390,7 @@ void CTradeWindow::initItems(bool Left)
|
|||||||
|
|
||||||
BLOCK_CAPTURING;
|
BLOCK_CAPTURING;
|
||||||
arts = new CArtifactsOfHero(Point(pos.x+xOffset, pos.y+yOffset));
|
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->commonInfo->participants.insert(arts);
|
||||||
arts->recActions = 255;
|
arts->recActions = 255;
|
||||||
arts->setHero(hero);
|
arts->setHero(hero);
|
||||||
|
@ -908,7 +908,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
|||||||
prepareBackground();
|
prepareBackground();
|
||||||
|
|
||||||
artifs[0] = new CArtifactsOfHero(Point(-334, 150));
|
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]->commonInfo->participants.insert(artifs[0]);
|
||||||
artifs[0]->setHero(heroInst[0]);
|
artifs[0]->setHero(heroInst[0]);
|
||||||
artifs[1] = new CArtifactsOfHero(Point(96, 150));
|
artifs[1] = new CArtifactsOfHero(Point(96, 150));
|
||||||
@ -1004,7 +1004,6 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
|||||||
|
|
||||||
CExchangeWindow::~CExchangeWindow() //d-tor
|
CExchangeWindow::~CExchangeWindow() //d-tor
|
||||||
{
|
{
|
||||||
delete artifs[0]->commonInfo;
|
|
||||||
artifs[0]->commonInfo = nullptr;
|
artifs[0]->commonInfo = nullptr;
|
||||||
artifs[1]->commonInfo = nullptr;
|
artifs[1]->commonInfo = nullptr;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user