3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef NODEDEF_HEADER
21 #define NODEDEF_HEADER
23 #include "common_irrlicht.h"
31 #include "itemgroup.h"
32 class IItemDefManager;
42 enum ContentParamType2
47 // Flowing liquid properties
49 // Direction for chests and furnaces and such
51 // Direction for signs, torches and such
64 NODEBOX_REGULAR, // Regular block; allows buildable_to
65 NODEBOX_FIXED, // Static separately defined box
66 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
71 enum NodeBoxType type;
72 // NODEBOX_REGULAR (no parameters)
74 core::aabbox3d<f32> fixed;
75 // NODEBOX_WALLMOUNTED
76 core::aabbox3d<f32> wall_top;
77 core::aabbox3d<f32> wall_bottom;
78 core::aabbox3d<f32> wall_side; // being at the -X side
81 type(NODEBOX_REGULAR),
82 // default is rail-like
83 fixed(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
84 // default is sign/ladder-like
85 wall_top(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2),
86 wall_bottom(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
87 wall_side(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2)
90 void serialize(std::ostream &os) const;
91 void deSerialize(std::istream &is);
100 bool backface_culling;
102 MaterialSpec(const std::string &tname_="", bool backface_culling_=true):
104 backface_culling(backface_culling_)
107 void serialize(std::ostream &os) const;
108 void deSerialize(std::istream &is);
113 NDT_NORMAL, // A basic solid block
114 NDT_AIRLIKE, // Nothing is drawn
115 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
116 NDT_FLOWINGLIQUID, // A very special kind of thing
117 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
118 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
119 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
127 #define CF_SPECIAL_COUNT 2
129 struct ContentFeatures
136 // up down right left back front
138 // Special material/texture
139 // - Currently used for flowing liquids
140 video::SMaterial *special_materials[CF_SPECIAL_COUNT];
141 AtlasPointer *special_aps[CF_SPECIAL_COUNT];
142 u8 solidness; // Used when choosing which face is drawn
143 u8 visual_solidness; // When solidness=0, this tells how it looks like
144 bool backface_culling;
151 std::string name; // "" = undefined node
152 ItemGroupList groups; // Same as in itemdef
155 enum NodeDrawType drawtype;
156 float visual_scale; // Misc. scale parameter
157 std::string tname_tiles[6];
158 MaterialSpec mspec_special[CF_SPECIAL_COUNT]; // Use setter methods
161 // Post effect color, drawn when the camera is inside the node.
162 video::SColor post_effect_color;
163 // Type of MapNode::param1
164 ContentParamType param_type;
165 // Type of MapNode::param2
166 ContentParamType2 param_type_2;
167 // True for all ground-like things like stone and mud, false for eg. trees
168 bool is_ground_content;
169 bool light_propagates;
170 bool sunlight_propagates;
171 // This is used for collision detection.
172 // Also for general solidness queries.
174 // Player can point to these
176 // Player can dig these
178 // Player can climb these
180 // Player can build on these
182 // Metadata name of node (eg. "furnace")
183 std::string metadata_name;
184 // Whether the node is non-liquid, source liquid or flowing liquid
185 enum LiquidType liquid_type;
186 // If the content is liquid, this is the flowing version of the liquid.
187 std::string liquid_alternative_flowing;
188 // If the content is liquid, this is the source version of the liquid.
189 std::string liquid_alternative_source;
190 // Viscosity for fluid flow, ranging from 1 to 7, with
191 // 1 giving almost instantaneous propagation and 7 being
192 // the slowest possible
194 // Amount of light the node emits
196 u32 damage_per_second;
197 NodeBox selection_box;
198 // Compatibility with old maps
199 // Set to true if paramtype used to be 'facedir_simple'
200 bool legacy_facedir_simple;
201 // Set to true if wall_mounted used to be set to true
202 bool legacy_wallmounted;
211 void serialize(std::ostream &os);
212 void deSerialize(std::istream &is);
217 bool isLiquid() const{
218 return (liquid_type != LIQUID_NONE);
220 bool sameLiquid(const ContentFeatures &f) const{
221 if(!isLiquid() || !f.isLiquid()) return false;
222 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
226 class INodeDefManager
230 virtual ~INodeDefManager(){}
231 // Get node definition
232 virtual const ContentFeatures& get(content_t c) const=0;
233 virtual const ContentFeatures& get(const MapNode &n) const=0;
234 virtual bool getId(const std::string &name, content_t &result) const=0;
235 virtual content_t getId(const std::string &name) const=0;
236 virtual const ContentFeatures& get(const std::string &name) const=0;
238 virtual void serialize(std::ostream &os)=0;
241 class IWritableNodeDefManager : public INodeDefManager
244 IWritableNodeDefManager(){}
245 virtual ~IWritableNodeDefManager(){}
246 virtual IWritableNodeDefManager* clone()=0;
247 // Get node definition
248 virtual const ContentFeatures& get(content_t c) const=0;
249 virtual const ContentFeatures& get(const MapNode &n) const=0;
250 virtual bool getId(const std::string &name, content_t &result) const=0;
251 virtual content_t getId(const std::string &name) const=0;
252 // If not found, returns the features of CONTENT_IGNORE
253 virtual const ContentFeatures& get(const std::string &name) const=0;
255 // Register node definition
256 virtual void set(content_t c, const ContentFeatures &def)=0;
257 // Register node definition by name (allocate an id)
258 // If returns CONTENT_IGNORE, could not allocate id
259 virtual content_t set(const std::string &name,
260 const ContentFeatures &def)=0;
261 // If returns CONTENT_IGNORE, could not allocate id
262 virtual content_t allocateDummy(const std::string &name)=0;
265 Update item alias mapping.
266 Call after updating item definitions.
268 virtual void updateAliases(IItemDefManager *idef)=0;
271 Update tile textures to latest return values of TextueSource.
272 Call after updating the texture atlas of a TextureSource.
274 virtual void updateTextures(ITextureSource *tsrc)=0;
276 virtual void serialize(std::ostream &os)=0;
277 virtual void deSerialize(std::istream &is)=0;
280 IWritableNodeDefManager* createNodeDefManager();