Skip to content

Commit

Permalink
Revert "Add a new method to check if Thing has a parent (otland#4810)"
Browse files Browse the repository at this point in the history
This reverts commit 427f32a.
  • Loading branch information
ArturKnopik committed Nov 7, 2024
1 parent 3bca716 commit c5f6876
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 60 deletions.
6 changes: 1 addition & 5 deletions data/npc/lib/npcsystem/keywordhandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ if not KeywordHandler then
end

-- Returns the parent of this node or nil if no such node exists.
function KeywordNode:hasParent()
return self.parent ~= nil
end

function KeywordNode:getParent()
return self.parent
end
Expand Down Expand Up @@ -125,7 +121,7 @@ if not KeywordHandler then
return true
end

if node:hasParent() then
if node:getParent() then
node = node:getParent() -- Search through the parent.
local ret = self:processNodeMessage(node, cid, message)
if ret then
Expand Down
16 changes: 8 additions & 8 deletions src/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ void Container::addThing(int32_t index, Thing* thing)
ammoCount += item->getItemCount();

// send change to client
if (hasParent() && (getParent() != VirtualCylinder::virtualCylinder)) {
if (getParent() && (getParent() != VirtualCylinder::virtualCylinder)) {
onAddContainerItem(item);
}
}
Expand All @@ -499,7 +499,7 @@ void Container::addItemBack(Item* item)
ammoCount += item->getItemCount();

// send change to client
if (hasParent() && (getParent() != VirtualCylinder::virtualCylinder)) {
if (getParent() && (getParent() != VirtualCylinder::virtualCylinder)) {
onAddContainerItem(item);
}
}
Expand All @@ -525,7 +525,7 @@ void Container::updateThing(Thing* thing, uint16_t itemId, uint32_t count)
updateItemWeight(-oldWeight + item->getWeight());

// send change to client
if (hasParent()) {
if (getParent()) {
onUpdateContainerItem(index, item, item);
}
}
Expand All @@ -551,7 +551,7 @@ void Container::replaceThing(uint32_t index, Thing* thing)
ammoCount += item->getItemCount();

// send change to client
if (hasParent()) {
if (getParent()) {
onUpdateContainerItem(index, replacedItem, item);
}

Expand Down Expand Up @@ -580,7 +580,7 @@ void Container::removeThing(Thing* thing, uint32_t count)
updateItemWeight(-oldWeight + item->getWeight());

// send change to client
if (hasParent()) {
if (getParent()) {
onUpdateContainerItem(index, item, item);
}
} else {
Expand All @@ -589,7 +589,7 @@ void Container::removeThing(Thing* thing, uint32_t count)
ammoCount -= item->getItemCount();

// send change to client
if (hasParent()) {
if (getParent()) {
onRemoveContainerItem(index, item);
}

Expand Down Expand Up @@ -657,7 +657,7 @@ void Container::postAddNotification(Thing* thing, const Cylinder* oldParent, int
topParent->postAddNotification(thing, oldParent, index, LINK_TOPPARENT);
} else if (topParent == this) {
// let the tile class notify surrounding players
if (topParent->hasParent()) {
if (topParent->getParent()) {
topParent->getParent()->postAddNotification(thing, oldParent, index, LINK_NEAR);
}
} else {
Expand All @@ -672,7 +672,7 @@ void Container::postRemoveNotification(Thing* thing, const Cylinder* newParent,
topParent->postRemoveNotification(thing, newParent, index, LINK_TOPPARENT);
} else if (topParent == this) {
// let the tile class notify surrounding players
if (topParent->hasParent()) {
if (topParent->getParent()) {
topParent->getParent()->postRemoveNotification(thing, newParent, index, LINK_NEAR);
}
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class Container : public Item, public Cylinder
virtual StoreInbox* getStoreInbox() { return nullptr; }
virtual const StoreInbox* getStoreInbox() const { return nullptr; }

bool hasParent() const override;

Attr_ReadValue readAttr(AttrTypes_t attr, PropStream& propStream) override;
bool unserializeItemNode(OTB::Loader& loader, const OTB::Node& node, PropStream& propStream) override;

Expand All @@ -69,6 +67,7 @@ class Container : public Item, public Cylinder

std::string getName(bool addArticle = false) const;

bool hasParent() const;
void addItem(Item* item);
Item* getItemByIndex(size_t index) const;
bool isHoldingItem(const Item* item) const;
Expand Down
1 change: 0 additions & 1 deletion src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ class Creature : virtual public Thing
bool registerCreatureEvent(const std::string& name);
bool unregisterCreatureEvent(const std::string& name);

bool hasParent() const override { return getParent(); }
Cylinder* getParent() const override final { return tile; }
void setParent(Cylinder* cylinder) override final
{
Expand Down
1 change: 0 additions & 1 deletion src/depotchest.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class DepotChest final : public Container
// overrides
bool canRemove() const override { return false; }

bool hasParent() const override { return getParent(); }
Cylinder* getParent() const override;
Cylinder* getRealParent() const override { return parent; }

Expand Down
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ Player* Game::getPlayerByAccount(uint32_t acc)
bool Game::internalPlaceCreature(Creature* creature, const Position& pos, bool extendedPos /*=false*/,
bool forced /*= false*/)
{
if (creature->hasParent()) {
if (creature->getParent()) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/housetile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void HouseTile::addThing(int32_t index, Thing* thing)
{
Tile::addThing(index, thing);

if (!thing->hasParent()) {
if (!thing->getParent()) {
return;
}

Expand All @@ -30,7 +30,7 @@ void HouseTile::internalAddThing(uint32_t index, Thing* thing)
{
Tile::internalAddThing(index, thing);

if (!thing->hasParent()) {
if (!thing->getParent()) {
return;
}

Expand Down
1 change: 0 additions & 1 deletion src/inbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Inbox final : public Container
// overrides
bool canRemove() const override { return false; }

bool hasParent() const override { return getParent(); }
Cylinder* getParent() const override;
Cylinder* getRealParent() const override { return parent; }
};
Expand Down
2 changes: 1 addition & 1 deletion src/iomapserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool IOMapSerialize::loadItem(PropStream& propStream, Cylinder* parent)
}

Tile* tile = nullptr;
if (!parent->hasParent()) {
if (!parent->getParent()) {
tile = parent->getTile();
}

Expand Down
8 changes: 4 additions & 4 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ Cylinder* Item::getTopParent()
return prevaux;
}

while (aux->hasParent()) {
while (aux->getParent()) {
prevaux = aux;
aux = aux->getParent();
}
Expand All @@ -280,7 +280,7 @@ const Cylinder* Item::getTopParent() const
return prevaux;
}

while (aux->hasParent()) {
while (aux->getParent()) {
prevaux = aux;
aux = aux->getParent();
}
Expand All @@ -295,7 +295,7 @@ Tile* Item::getTile()
{
Cylinder* cylinder = getTopParent();
// get root cylinder
if (cylinder && cylinder->hasParent()) {
if (cylinder && cylinder->getParent()) {
cylinder = cylinder->getParent();
}
return dynamic_cast<Tile*>(cylinder);
Expand All @@ -305,7 +305,7 @@ const Tile* Item::getTile() const
{
const Cylinder* cylinder = getTopParent();
// get root cylinder
if (cylinder && cylinder->hasParent()) {
if (cylinder && cylinder->getParent()) {
cylinder = cylinder->getParent();
}
return dynamic_cast<const Tile*>(cylinder);
Expand Down
1 change: 0 additions & 1 deletion src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,6 @@ class Item : virtual public Thing
}
}

bool hasParent() const override { return getParent(); }
Cylinder* getParent() const override { return parent; }
void setParent(Cylinder* cylinder) override { parent = cylinder; }
Cylinder* getTopParent();
Expand Down
30 changes: 1 addition & 29 deletions src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,6 @@ void LuaScriptInterface::registerFunctions()

registerMethod(L, "Item", "isItem", LuaScriptInterface::luaItemIsItem);

registerMethod(L, "Item", "hasParent", LuaScriptInterface::luaItemHasParent);
registerMethod(L, "Item", "getParent", LuaScriptInterface::luaItemGetParent);
registerMethod(L, "Item", "getTopParent", LuaScriptInterface::luaItemGetTopParent);

Expand Down Expand Up @@ -2672,7 +2671,6 @@ void LuaScriptInterface::registerFunctions()
registerMethod(L, "Creature", "canSeeGhostMode", LuaScriptInterface::luaCreatureCanSeeGhostMode);
registerMethod(L, "Creature", "canSeeInvisibility", LuaScriptInterface::luaCreatureCanSeeInvisibility);

registerMethod(L, "Creature", "hasParent", LuaScriptInterface::luaCreatureHasParent);
registerMethod(L, "Creature", "getParent", LuaScriptInterface::luaCreatureGetParent);

registerMethod(L, "Creature", "getId", LuaScriptInterface::luaCreatureGetId);
Expand Down Expand Up @@ -3693,7 +3691,7 @@ int LuaScriptInterface::luaDoPlayerAddItem(lua_State* L)
}

if (--itemCount == 0) {
if (newItem->hasParent()) {
if (newItem->getParent()) {
uint32_t uid = tfs::lua::getScriptEnv()->addThing(newItem);
lua_pushnumber(L, uid);
return 1;
Expand Down Expand Up @@ -6630,19 +6628,6 @@ int LuaScriptInterface::luaItemIsItem(lua_State* L)
return 1;
}

int LuaScriptInterface::luaItemHasParent(lua_State* L)
{
// item:hasParent()
Item* item = tfs::lua::getUserdata<Item>(L, 1);
if (!item) {
lua_pushnil(L);
return 1;
}

tfs::lua::pushBoolean(L, item->hasParent());
return 1;
}

int LuaScriptInterface::luaItemGetParent(lua_State* L)
{
// item:getParent()
Expand Down Expand Up @@ -8035,19 +8020,6 @@ int LuaScriptInterface::luaCreatureCanSeeInvisibility(lua_State* L)
return 1;
}

int LuaScriptInterface::luaCreatureHasParent(lua_State* L)
{
// creature:hasParent()
Creature* creature = tfs::lua::getUserdata<Creature>(L, 1);
if (!creature) {
lua_pushnil(L);
return 1;
}

tfs::lua::pushBoolean(L, creature->hasParent());
return 1;
}

int LuaScriptInterface::luaCreatureGetParent(lua_State* L)
{
// creature:getParent()
Expand Down
2 changes: 0 additions & 2 deletions src/luascript.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ class LuaScriptInterface

static int luaItemIsItem(lua_State* L);

static int luaItemHasParent(lua_State* L);
static int luaItemGetParent(lua_State* L);
static int luaItemGetTopParent(lua_State* L);

Expand Down Expand Up @@ -542,7 +541,6 @@ class LuaScriptInterface
static int luaCreatureCanSeeGhostMode(lua_State* L);
static int luaCreatureCanSeeInvisibility(lua_State* L);

static int luaCreatureHasParent(lua_State* L);
static int luaCreatureGetParent(lua_State* L);

static int luaCreatureGetId(lua_State* L);
Expand Down
1 change: 0 additions & 1 deletion src/thing.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Thing

virtual std::string getDescription(int32_t lookDistance) const = 0;

virtual bool hasParent() const { return false; }
virtual Cylinder* getParent() const { return nullptr; }
virtual Cylinder* getRealParent() const { return getParent(); }

Expand Down
2 changes: 1 addition & 1 deletion src/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ ReturnValue Tile::queryAdd(int32_t, const Thing& thing, uint32_t, uint32_t flags
}
}

if (!player->hasParent() && hasFlag(TILESTATE_NOLOGOUT)) {
if (!player->getParent() && hasFlag(TILESTATE_NOLOGOUT)) {
// player is trying to login to a "no logout" tile
return RETURNVALUE_NOTPOSSIBLE;
}
Expand Down

0 comments on commit c5f6876

Please sign in to comment.