From 582e450bad08006dff141216351b81d3eb9270b7 Mon Sep 17 00:00:00 2001 From: darkrose Date: Thu, 22 Sep 2011 19:11:48 +1000 Subject: added locking chests - clean patch --- src/map.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index 7de79c75d..a8e7235cf 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -28,6 +28,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "porting.h" #include "mapgen.h" #include "nodemetadata.h" +#include "content_nodemeta.h" +#include "content_mapnode.h" /* SQLite format specification: @@ -890,7 +892,7 @@ void Map::updateLighting(core::map & a_blocks, /* */ void Map::addNodeAndUpdate(v3s16 p, MapNode n, - core::map &modified_blocks) + core::map &modified_blocks, std::string &player_name) { /*PrintInfo(m_dout); m_dout<clone(); + /* lockable chest, insert the owner's name */ + if (meta->typeId() == CONTENT_LOCKABLE_CHEST) + { + LockingChestNodeMetadata *lcm = (LockingChestNodeMetadata*)meta; + lcm->setOwner(player_name); + } setNodeMetadata(p, meta); } + else if (n.getContent() == CONTENT_LOCKABLE_CHEST) + { + LockingChestNodeMetadata *lcm = new LockingChestNodeMetadata(); + lcm->setOwner(player_name); + setNodeMetadata(p, (NodeMetadata*)lcm); + } /* If node is under sunlight and doesn't let sunlight through, @@ -1290,7 +1304,8 @@ bool Map::addNodeWithEvent(v3s16 p, MapNode n) bool succeeded = true; try{ core::map modified_blocks; - addNodeAndUpdate(p, n, modified_blocks); + std::string st = std::string(""); + addNodeAndUpdate(p, n, modified_blocks, st); // Copy modified_blocks to event for(core::map::Iterator -- cgit v1.2.3 From 8b875d71d1ab928e9866914b886ff58cf8a38192 Mon Sep 17 00:00:00 2001 From: darkrose Date: Fri, 23 Sep 2011 18:04:48 +1000 Subject: remove content_* things from map.cpp --- src/content_nodemeta.h | 4 ++-- src/map.cpp | 15 +-------------- src/nodemetadata.h | 3 +++ 3 files changed, 6 insertions(+), 16 deletions(-) (limited to 'src/map.cpp') diff --git a/src/content_nodemeta.h b/src/content_nodemeta.h index af3374124..e20334312 100644 --- a/src/content_nodemeta.h +++ b/src/content_nodemeta.h @@ -77,8 +77,8 @@ public: virtual bool nodeRemovalDisabled(); virtual std::string getInventoryDrawSpecString(); - std::string getOwner(){ return m_text; } - void setOwner(std::string t){ m_text = t; } + virtual std::string getOwner(){ return m_text; } + virtual void setOwner(std::string t){ m_text = t; } private: Inventory *m_inventory; diff --git a/src/map.cpp b/src/map.cpp index a8e7235cf..32675f08d 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -28,8 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "porting.h" #include "mapgen.h" #include "nodemetadata.h" -#include "content_nodemeta.h" -#include "content_mapnode.h" /* SQLite format specification: @@ -1016,20 +1014,9 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n, if(meta_proto) { NodeMetadata *meta = meta_proto->clone(); - /* lockable chest, insert the owner's name */ - if (meta->typeId() == CONTENT_LOCKABLE_CHEST) - { - LockingChestNodeMetadata *lcm = (LockingChestNodeMetadata*)meta; - lcm->setOwner(player_name); - } + meta->setOwner(player_name); setNodeMetadata(p, meta); } - else if (n.getContent() == CONTENT_LOCKABLE_CHEST) - { - LockingChestNodeMetadata *lcm = new LockingChestNodeMetadata(); - lcm->setOwner(player_name); - setNodeMetadata(p, (NodeMetadata*)lcm); - } /* If node is under sunlight and doesn't let sunlight through, diff --git a/src/nodemetadata.h b/src/nodemetadata.h index de682f9b6..d81ade96c 100644 --- a/src/nodemetadata.h +++ b/src/nodemetadata.h @@ -65,6 +65,9 @@ public: // Used to make custom inventory menus. // See format in guiInventoryMenu.cpp. virtual std::string getInventoryDrawSpecString(){return "";} + // primarily used for locking chests, but others can play too + virtual std::string getOwner(){ return std::string(""); } + virtual void setOwner(std::string t){ } protected: static void registerType(u16 id, Factory f); -- cgit v1.2.3