Skip to content

Commit

Permalink
improve: check parent on decay
Browse files Browse the repository at this point in the history
  • Loading branch information
luan committed Sep 17, 2023
1 parent db3a913 commit aef87fc
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/items/containers/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::shared_ptr<Container> Container::create(std::shared_ptr<Tile> tile) {
Container::~Container() {
if (getID() == ITEM_BROWSEFIELD) {
for (std::shared_ptr<Item> item : itemlist) {
item->setParent(parent);
item->setParent(m_parent);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/items/containers/depot/depotchest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void DepotChest::postRemoveNotification(std::shared_ptr<Thing> thing, std::share
}

std::shared_ptr<Cylinder> DepotChest::getParent() {
auto parentLocked = parent.lock();
auto parentLocked = m_parent.lock();
if (parentLocked && parentLocked->getParent()) {
return parentLocked->getParent()->getParent();
}
Expand Down
2 changes: 1 addition & 1 deletion src/items/containers/depot/depotchest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DepotChest final : public Container {

std::shared_ptr<Cylinder> getParent() override;
std::shared_ptr<Cylinder> getRealParent() override {
return parent.lock();
return m_parent.lock();
}

private:
Expand Down
4 changes: 2 additions & 2 deletions src/items/containers/depot/depotlocker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ ReturnValue DepotLocker::queryAdd(int32_t, const std::shared_ptr<Thing> &, uint3
}

void DepotLocker::postAddNotification(std::shared_ptr<Thing> thing, std::shared_ptr<Cylinder> oldParent, int32_t index, CylinderLink_t) {
auto parentLocked = parent.lock();
auto parentLocked = m_parent.lock();
if (parentLocked) {
parentLocked->postAddNotification(thing, oldParent, index, LINK_PARENT);
}
}

void DepotLocker::postRemoveNotification(std::shared_ptr<Thing> thing, std::shared_ptr<Cylinder> newParent, int32_t index, CylinderLink_t) {
auto parentLocked = parent.lock();
auto parentLocked = m_parent.lock();
if (parentLocked) {
parentLocked->postRemoveNotification(thing, newParent, index, LINK_PARENT);
}
Expand Down
2 changes: 1 addition & 1 deletion src/items/containers/inbox/inbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void Inbox::postRemoveNotification(std::shared_ptr<Thing> thing, std::shared_ptr
}

std::shared_ptr<Cylinder> Inbox::getParent() {
auto parentLocked = parent.lock();
auto parentLocked = m_parent.lock();
if (parentLocked) {
return parentLocked->getParent();
}
Expand Down
2 changes: 1 addition & 1 deletion src/items/containers/inbox/inbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Inbox final : public Container {

std::shared_ptr<Cylinder> getParent() override;
std::shared_ptr<Cylinder> getRealParent() override {
return parent.lock();
return m_parent.lock();
}

private:
Expand Down
2 changes: 1 addition & 1 deletion src/items/containers/rewards/reward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ void Reward::postRemoveNotification(std::shared_ptr<Thing> thing, std::shared_pt
}

std::shared_ptr<Cylinder> Reward::getParent() {
return parent.lock();
return m_parent.lock();
}
2 changes: 1 addition & 1 deletion src/items/containers/rewards/reward.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ class Reward : public Container {

std::shared_ptr<Cylinder> getParent() final;
std::shared_ptr<Cylinder> getRealParent() final {
return parent.lock();
return m_parent.lock();
}
};
4 changes: 2 additions & 2 deletions src/items/containers/rewards/rewardchest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ ReturnValue RewardChest::queryAdd(int32_t, const std::shared_ptr<Thing> &, uint3
}

void RewardChest::postAddNotification(std::shared_ptr<Thing> thing, std::shared_ptr<Cylinder> oldParent, int32_t index, CylinderLink_t) {
auto parentLocked = parent.lock();
auto parentLocked = m_parent.lock();
if (parentLocked) {
parentLocked->postAddNotification(thing, oldParent, index, LINK_PARENT);
}
}

void RewardChest::postRemoveNotification(std::shared_ptr<Thing> thing, std::shared_ptr<Cylinder> newParent, int32_t index, CylinderLink_t) {
auto parentLocked = parent.lock();
auto parentLocked = m_parent.lock();
if (parentLocked) {
parentLocked->postRemoveNotification(thing, newParent, index, LINK_PARENT);
}
Expand Down
14 changes: 9 additions & 5 deletions src/items/item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,18 +564,22 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject {
bool hasMarketAttributes() const;

std::shared_ptr<Cylinder> getParent() override {
return parent.lock();
return m_parent.lock();
}
void setParent(std::weak_ptr<Cylinder> cylinder) override {
parent = cylinder;
m_parent = cylinder;
}
void resetParent() {
parent.reset();
m_parent.reset();
}
std::shared_ptr<Cylinder> getTopParent();
std::shared_ptr<Tile> getTile() override;
bool isRemoved() override {
return parent.expired() || getParent()->isRemoved();
auto parent = getParent();
if (parent) {
return parent->isRemoved();
}
return true;
}

bool isInsideDepot(bool includeInbox = false);
Expand Down Expand Up @@ -676,7 +680,7 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject {
void checkDecayMapItemOnMove();

protected:
std::weak_ptr<Cylinder> parent;
std::weak_ptr<Cylinder> m_parent;

uint16_t id; // the same id as in ItemType
uint8_t count = 1; // number of stacked items
Expand Down

0 comments on commit aef87fc

Please sign in to comment.