aboutsummaryrefslogtreecommitdiff
path: root/src/cavegen.cpp
Commit message (Expand)AuthorAge
* Mgvalleys / cavegen: Place riverbed nodes under river waterparamat2016-07-21
* Change internal type for seeds to s32kwolekr2016-06-04
* Disallow external linkage for default Cavegen NoiseParamskwolekr2016-05-27
* Cavegen: Move V5-style caves to CavesNoiseIntersectionkwolekr2016-05-27
* Cavegen: Minor misc. fixeskwolekr2016-05-27
* Fix undefined evaluation order when constructing random vectorskwolekr2016-05-27
* Cavegen: Re-add small caves to CavesRandomWalkkwolekr2016-05-27
* Cavegen: Remove CavesRandomWalk dependency on Mapgenkwolekr2016-05-27
* Cavegen: Merge instances of repetitive surface level-finding codekwolekr2016-05-27
* Cavegen: Remove CavesV6 dependency on Mapgenkwolekr2016-05-27
* Cavegen: Rename CaveV6 to CavesV6kwolekr2016-05-27
* Cavegen: Merge CaveV5 and CaveV7 into CavesRandomWalkkwolekr2016-05-27
* Mapgen: Various fixes and improvementsparamat2016-01-11
* Cavegen: Make mgfractal use mgv5 cavegenparamat2015-11-09
* Fractal mapgen: Add seabed and large pseudorandom cavesparamat2015-10-07
* Cavegen V6: Make all caves consistent with 0.4.12 stableparamat2015-08-03
* Cavegen: Mgv6: No small caves entirely above groundparamat2015-07-19
* Cavegen: Cleanup code. Define constant for MGV7_LAVA_DEPTHparamat2015-07-01
* Cavegen: Remove now unnecessary checks for water, lava, iceparamat2015-04-07
* Cavegen, mgv5: Cleanup codeparamat2015-03-04
* Mgv6: Add heightmap. Do not make large caves that are entirely above groundparamat2015-03-02
* Mgv5: Remove blobgen. Remove crumble and wetness noisesparamat2015-02-21
* Cavegen: Fix copy & paste error (solves #2020)kwolekr2014-12-28
* Add flags and lacunarity as new noise parameterskwolekr2014-12-07
* Rewrite generate notification mechanismkwolekr2014-12-06
* Huge overhaul of the entire MapgenParams systemkwolekr2014-02-03
* Add map feature generation notify Lua APIkwolekr2013-12-14
* Cavegen: Fix possible out-of-bounds heightmap accesskwolekr2013-12-01
* Cavegen: Respect is_ground_content MapNode setting; fix some code formatting ...kwolekr2013-11-29
* Mapgen V7: Huge rewrite, also tweaks to cavegen et al.kwolekr2013-07-06
* Cavegen: Prevent caves from occuring above ground level, and superfluous mixi...kwolekr2013-07-01
* Cavegen: fix division by 0 with abnormal max tunnel diameter sizeskwolekr2013-06-23
* Enhance caves for mgv7, add ravineskwolekr2013-04-27
* Class-ify caves & move to cavegen.cpp, fix cave regression, add caves to Mapg...kwolekr2013-04-21
s. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef INVENTORY_HEADER #define INVENTORY_HEADER #include <iostream> #include <sstream> #include <string> #include <vector> #include "common_irrlicht.h" #include "debug.h" #include "itemdef.h" struct ToolCapabilities; struct ItemStack { ItemStack(): name(""), count(0), wear(0), metadata("") {} ItemStack(std::string name_, u16 count_, u16 wear, std::string metadata_, IItemDefManager *itemdef); ~ItemStack() {} // Serialization void serialize(std::ostream &os) const; void deSerialize(std::istream &is, IItemDefManager *itemdef); void deSerialize(const std::string &s, IItemDefManager *itemdef); // Returns the string used for inventory std::string getItemString() const; /* Quantity methods */ bool empty() const { return count == 0; } void clear() { name = ""; count = 0; wear = 0; metadata = ""; } void add(u16 n) { count += n; } void remove(u16 n) { assert(count >= n); count -= n; if(count == 0) clear(); // reset name, wear and metadata too } // Maximum size of a stack u16 getStackMax(IItemDefManager *itemdef) const { s16 max = itemdef->get(name).stack_max; return (max >= 0) ? max : 0; } // Number of items that can be added to this stack u16 freeSpace(IItemDefManager *itemdef) const { u16 max = getStackMax(itemdef); if(count > max) return 0; return max - count; } // Returns false if item is not known and cannot be used bool isKnown(IItemDefManager *itemdef) const { return itemdef->isKnown(name); } // Returns a pointer to the item definition struct, // or a fallback one (name="unknown") if the item is unknown. const ItemDefinition& getDefinition( IItemDefManager *itemdef) const { return itemdef->get(name); } // Get tool digging properties, or those of the hand if not a tool const ToolCapabilities& getToolCapabilities( IItemDefManager *itemdef) const { ToolCapabilities *cap; cap = itemdef->get(name).tool_capabilities; if(cap == NULL) cap = itemdef->get("").tool_capabilities; assert(cap != NULL); return *cap; } // Wear out (only tools) // Returns true if the item is (was) a tool bool addWear(s32 amount, IItemDefManager *itemdef) { if(getDefinition(itemdef).type == ITEM_TOOL) { if(amount > 65535 - wear) clear(); else if(amount < -wear) wear = 0; else wear += amount; return true; } else { return false; } } // If possible, adds newitem to this item. // If cannot be added at all, returns the item back. // If can be added partly, decremented item is returned back. // If can be added fully, empty item is returned. ItemStack addItem(const ItemStack &newitem, IItemDefManager *itemdef); // Checks whether newitem could be added. // If restitem is non-NULL, it receives the part of newitem that // would be left over after adding. bool itemFits(const ItemStack &newitem, ItemStack *restitem, // may be NULL IItemDefManager *itemdef) const; // Takes some items. // If there are not enough, takes as many as it can. // Returns empty item if couldn't take any. ItemStack takeItem(u32 takecount); // Similar to takeItem, but keeps this ItemStack intact. ItemStack peekItem(u32 peekcount) const; /* Properties */ std::string name; u16 count; u16 wear; std::string metadata; }; class InventoryList { public: InventoryList(std::string name, u32 size, IItemDefManager *itemdef); ~InventoryList(); void clearItems(); void setSize(u32 newsize); void serialize(std::ostream &os) const; void deSerialize(std::istream &is); InventoryList(const InventoryList &other); InventoryList & operator = (const InventoryList &other); const std::string &getName() const; u32 getSize() const; // Count used slots u32 getUsedSlots() const; u32 getFreeSlots() const; // Get reference to item const ItemStack& getItem(u32 i) const; ItemStack& getItem(u32 i); // Returns old item. Parameter can be an empty item. ItemStack changeItem(u32 i, const ItemStack &newitem); // Delete item void deleteItem(u32 i); // Adds an item to a suitable place. Returns leftover item (possibly empty). ItemStack addItem(const ItemStack &newitem); // If possible, adds item to given slot. // If cannot be added at all, returns the item back. // If can be added partly, decremented item is returned back. // If can be added fully, empty item is returned. ItemStack addItem(u32 i, const ItemStack &newitem); // Checks whether the item could be added to the given slot // If restitem is non-NULL, it receives the part of newitem that // would be left over after adding. bool itemFits(const u32 i, const ItemStack &newitem, ItemStack *restitem = NULL) const; // Checks whether there is room for a given item bool roomForItem(const ItemStack &item) const; // Checks whether the given count of the given item name // exists in this inventory list. bool containsItem(const ItemStack &item) const; // Removes the given count of the given item name from // this inventory list. Walks the list in reverse order. // If not as many items exist as requested, removes as // many as possible. // Returns the items that were actually removed. ItemStack removeItem(const ItemStack &item); // Takes some items from a slot. // If there are not enough, takes as many as it can. // Returns empty item if couldn't take any. ItemStack takeItem(u32 i, u32 takecount); // Similar to takeItem, but keeps the slot intact. ItemStack peekItem(u32 i, u32 peekcount) const; // Move an item to a different list (or a different stack in the same list) // count is the maximum number of items to move (0 for everything) void moveItem(u32 i, InventoryList *dest, u32 dest_i, u32 count = 0); private: std::vector<ItemStack> m_items; u32 m_size; std::string m_name; IItemDefManager *m_itemdef; }; class Inventory { public: ~Inventory(); void clear(); Inventory(IItemDefManager *itemdef); Inventory(const Inventory &other); Inventory & operator = (const Inventory &other); void serialize(std::ostream &os) const; void deSerialize(std::istream &is); InventoryList * addList(const std::string &name, u32 size); InventoryList * getList(const std::string &name); const InventoryList * getList(const std::string &name) const; bool deleteList(const std::string &name); // A shorthand for adding items. Returns leftover item (possibly empty). ItemStack addItem(const std::string &listname, const ItemStack &newitem) { InventoryList *list = getList(listname); if(list == NULL) return newitem; return list->addItem(newitem); } private: // -1 if not found const s32 getListIndex(const std::string &name) const; std::vector<InventoryList*> m_lists; IItemDefManager *m_itemdef; }; #endif