2014-11-18 21:04:19 +01:00
|
|
|
/************************************************************************
|
|
|
|
* Minetest-c55
|
|
|
|
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
*
|
|
|
|
* nodemetadata.h
|
|
|
|
* voxelands - 3d voxel world sandbox game
|
|
|
|
* Copyright (C) Lisa 'darkrose' Milne 2014 <lisa@ltmnet.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
|
|
|
* for Voxelands.
|
|
|
|
************************************************************************/
|
2013-04-15 14:42:24 +02:00
|
|
|
|
|
|
|
#ifndef NODEMETADATA_HEADER
|
|
|
|
#define NODEMETADATA_HEADER
|
|
|
|
|
|
|
|
#include "common_irrlicht.h"
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
2014-03-02 11:44:02 +01:00
|
|
|
#include <map>
|
2014-05-28 14:31:39 +02:00
|
|
|
#include <vector>
|
2014-05-29 13:42:18 +02:00
|
|
|
#include "mapnode.h"
|
2014-03-02 11:44:02 +01:00
|
|
|
|
|
|
|
class Player;
|
2013-04-15 14:42:24 +02:00
|
|
|
|
2013-10-27 08:00:18 +01:00
|
|
|
#define ENERGY_MAX 16
|
|
|
|
|
2013-04-15 14:42:24 +02:00
|
|
|
/*
|
|
|
|
Used for storing:
|
|
|
|
|
|
|
|
Oven:
|
|
|
|
- Item that is being burned
|
|
|
|
- Burning time
|
|
|
|
- Item stack that is being heated
|
|
|
|
- Result item stack
|
|
|
|
|
|
|
|
Sign:
|
|
|
|
- Text
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Inventory;
|
2014-02-15 04:35:24 +01:00
|
|
|
class ServerEnvironment;
|
2013-04-15 14:42:24 +02:00
|
|
|
|
|
|
|
class NodeMetadata
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef NodeMetadata* (*Factory)(std::istream&);
|
|
|
|
|
|
|
|
NodeMetadata();
|
|
|
|
virtual ~NodeMetadata();
|
|
|
|
|
|
|
|
static NodeMetadata* deSerialize(std::istream &is);
|
|
|
|
void serialize(std::ostream &os);
|
|
|
|
|
|
|
|
// This usually is the CONTENT_ value
|
|
|
|
virtual u16 typeId() const = 0;
|
|
|
|
virtual NodeMetadata* clone() = 0;
|
|
|
|
virtual void serializeBody(std::ostream &os) = 0;
|
2014-10-24 13:52:03 +02:00
|
|
|
virtual std::wstring infoText() {return L"";}
|
2015-01-22 15:11:59 +01:00
|
|
|
virtual std::string getText() {return "";}
|
2013-04-15 14:42:24 +02:00
|
|
|
virtual Inventory* getInventory() {return NULL;}
|
|
|
|
// This is called always after the inventory is modified, before
|
|
|
|
// the changes are copied elsewhere
|
|
|
|
virtual void inventoryModified(){}
|
|
|
|
// A step in time. Returns true if metadata changed.
|
2014-02-15 04:35:24 +01:00
|
|
|
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env) {return false;}
|
2014-09-23 15:31:05 +02:00
|
|
|
virtual bool stepCircuit(float dtime, v3s16 pos, ServerEnvironment *env) {return false;}
|
2013-04-15 14:42:24 +02:00
|
|
|
virtual bool nodeRemovalDisabled(){return false;}
|
|
|
|
// Used to make custom inventory menus.
|
|
|
|
// See format in guiInventoryMenu.cpp.
|
2015-10-03 21:10:02 +02:00
|
|
|
virtual std::string getDrawSpecString(Player *player){return "";}
|
2014-01-11 09:50:31 +01:00
|
|
|
// the node owner - if not "" then only the owner can dig the node
|
2013-04-15 14:42:24 +02:00
|
|
|
virtual std::string getOwner(){ return std::string(""); }
|
|
|
|
virtual void setOwner(std::string t){ }
|
2014-01-11 09:50:31 +01:00
|
|
|
// the inventory owner - if not "" then only the owner can modify
|
|
|
|
virtual std::string getInventoryOwner(){ return std::string(""); }
|
|
|
|
virtual void setInventoryOwner(std::string t){ }
|
2014-03-02 13:33:40 +01:00
|
|
|
// receive data from the client. Returns true if metadata changed.
|
|
|
|
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player) {return false;}
|
2014-03-19 22:29:21 +01:00
|
|
|
// import data from another nodemetadata. Returns true if metadata changed.
|
|
|
|
virtual bool import(NodeMetadata *meta) {return false;}
|
2014-05-28 14:31:39 +02:00
|
|
|
// get nodeboxes for CDT_NODEBOX_META
|
2014-11-17 17:11:11 +01:00
|
|
|
virtual std::vector<NodeBox> getNodeBoxes(MapNode &n) {return std::vector<NodeBox>();}
|
2013-10-27 08:00:18 +01:00
|
|
|
// used by tnt to arm it, but also for future circuitry
|
|
|
|
// level is the amount of power
|
|
|
|
// powersrc is the generator or such that created the power
|
|
|
|
// signalsrc is the node that sent this node the energise signal
|
|
|
|
// pos is the position of this node
|
|
|
|
// returns false if propogation was stopped
|
|
|
|
virtual bool energise(u8 level, v3s16 powersrc, v3s16 signalsrc, v3s16 pos) {return false;}
|
|
|
|
virtual u8 getEnergy() {return 0;}
|
2014-08-14 21:06:10 +02:00
|
|
|
virtual std::map<v3s16, u8> *getSources() {return NULL;}
|
2013-04-15 14:42:24 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void registerType(u16 id, Factory f);
|
|
|
|
private:
|
2013-04-15 15:09:42 +02:00
|
|
|
static core::map<u16, Factory> m_types;
|
2013-04-15 14:42:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
List of metadata of all the nodes of a block
|
|
|
|
*/
|
|
|
|
|
|
|
|
class NodeMetadataList
|
|
|
|
{
|
|
|
|
public:
|
2015-10-04 19:54:07 +02:00
|
|
|
NodeMetadataList();
|
2013-04-15 14:42:24 +02:00
|
|
|
~NodeMetadataList();
|
|
|
|
|
|
|
|
void serialize(std::ostream &os);
|
|
|
|
void deSerialize(std::istream &is);
|
|
|
|
|
|
|
|
// Get pointer to data
|
2015-10-04 19:54:07 +02:00
|
|
|
NodeMetadata *get(v3s16 p);
|
|
|
|
NodeMetadata *getClone(v3s16 p);
|
2013-04-15 14:42:24 +02:00
|
|
|
// Deletes data
|
|
|
|
void remove(v3s16 p);
|
|
|
|
// Deletes old data and sets a new one
|
|
|
|
void set(v3s16 p, NodeMetadata *d);
|
|
|
|
|
|
|
|
// A step in time. Returns true if something changed.
|
2014-08-14 21:06:10 +02:00
|
|
|
bool step(float dtime, v3s16 blockpos_nodes, ServerEnvironment *env);
|
2014-09-23 15:31:05 +02:00
|
|
|
bool stepCircuit(float dtime, v3s16 blockpos_nodes, ServerEnvironment *env);
|
2013-04-15 14:42:24 +02:00
|
|
|
|
|
|
|
private:
|
2013-04-15 15:09:42 +02:00
|
|
|
core::map<v3s16, NodeMetadata*> m_data;
|
2015-10-04 19:54:07 +02:00
|
|
|
JMutex m_mutex;
|
2013-04-15 14:42:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|