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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser 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 "irrlichttypes.h"
31 #include "itemgroup.h"
32 #include "sound.h" // SimpleSoundSpec
33 class IItemDefManager;
43 enum ContentParamType2
48 // Flowing liquid properties
50 // Direction for chests and furnaces and such
52 // Direction for signs, torches and such
65 NODEBOX_REGULAR, // Regular block; allows buildable_to
66 NODEBOX_FIXED, // Static separately defined box
67 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
72 enum NodeBoxType type;
73 // NODEBOX_REGULAR (no parameters)
75 core::aabbox3d<f32> fixed;
76 // NODEBOX_WALLMOUNTED
77 core::aabbox3d<f32> wall_top;
78 core::aabbox3d<f32> wall_bottom;
79 core::aabbox3d<f32> wall_side; // being at the -X side
82 type(NODEBOX_REGULAR),
83 // default is rail-like
84 fixed(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
85 // default is sign/ladder-like
86 wall_top(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2),
87 wall_bottom(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
88 wall_side(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2)
91 void serialize(std::ostream &os) const;
92 void deSerialize(std::istream &is);
99 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
101 enum TileAnimationType{
103 TAT_VERTICAL_FRAMES=1,
108 bool backface_culling; // Takes effect only in special cases
110 enum TileAnimationType type;
111 int aspect_w; // width for aspect ratio
112 int aspect_h; // height for aspect ratio
113 float length; // seconds
119 backface_culling = true;
120 animation.type = TAT_NONE;
121 animation.aspect_w = 1;
122 animation.aspect_h = 1;
123 animation.length = 1.0;
126 void serialize(std::ostream &os) const;
127 void deSerialize(std::istream &is);
132 NDT_NORMAL, // A basic solid block
133 NDT_AIRLIKE, // Nothing is drawn
134 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
135 NDT_FLOWINGLIQUID, // A very special kind of thing
136 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
137 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
138 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
146 #define CF_SPECIAL_COUNT 2
148 struct ContentFeatures
155 // up down right left back front
158 // - Currently used for flowing liquids
159 TileSpec special_tiles[CF_SPECIAL_COUNT];
160 u8 solidness; // Used when choosing which face is drawn
161 u8 visual_solidness; // When solidness=0, this tells how it looks like
162 bool backface_culling;
165 // Server-side cached callback existence for fast skipping
166 bool has_on_construct;
167 bool has_on_destruct;
168 bool has_after_destruct;
174 std::string name; // "" = undefined node
175 ItemGroupList groups; // Same as in itemdef
178 enum NodeDrawType drawtype;
179 float visual_scale; // Misc. scale parameter
181 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
184 // Post effect color, drawn when the camera is inside the node.
185 video::SColor post_effect_color;
186 // Type of MapNode::param1
187 ContentParamType param_type;
188 // Type of MapNode::param2
189 ContentParamType2 param_type_2;
190 // True for all ground-like things like stone and mud, false for eg. trees
191 bool is_ground_content;
192 bool light_propagates;
193 bool sunlight_propagates;
194 // This is used for collision detection.
195 // Also for general solidness queries.
197 // Player can point to these
199 // Player can dig these
201 // Player can climb these
203 // Player can build on these
205 // Whether the node is non-liquid, source liquid or flowing liquid
206 enum LiquidType liquid_type;
207 // If the content is liquid, this is the flowing version of the liquid.
208 std::string liquid_alternative_flowing;
209 // If the content is liquid, this is the source version of the liquid.
210 std::string liquid_alternative_source;
211 // Viscosity for fluid flow, ranging from 1 to 7, with
212 // 1 giving almost instantaneous propagation and 7 being
213 // the slowest possible
215 // Amount of light the node emits
217 u32 damage_per_second;
218 NodeBox selection_box;
219 // Compatibility with old maps
220 // Set to true if paramtype used to be 'facedir_simple'
221 bool legacy_facedir_simple;
222 // Set to true if wall_mounted used to be set to true
223 bool legacy_wallmounted;
226 SimpleSoundSpec sound_footstep;
227 SimpleSoundSpec sound_dig;
228 SimpleSoundSpec sound_dug;
237 void serialize(std::ostream &os);
238 void deSerialize(std::istream &is);
243 bool isLiquid() const{
244 return (liquid_type != LIQUID_NONE);
246 bool sameLiquid(const ContentFeatures &f) const{
247 if(!isLiquid() || !f.isLiquid()) return false;
248 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
252 class INodeDefManager
256 virtual ~INodeDefManager(){}
257 // Get node definition
258 virtual const ContentFeatures& get(content_t c) const=0;
259 virtual const ContentFeatures& get(const MapNode &n) const=0;
260 virtual bool getId(const std::string &name, content_t &result) const=0;
261 virtual content_t getId(const std::string &name) const=0;
262 // Allows "group:name" in addition to regular node names
263 virtual void getIds(const std::string &name, std::set<content_t> &result)
265 virtual const ContentFeatures& get(const std::string &name) const=0;
267 virtual void serialize(std::ostream &os)=0;
270 class IWritableNodeDefManager : public INodeDefManager
273 IWritableNodeDefManager(){}
274 virtual ~IWritableNodeDefManager(){}
275 virtual IWritableNodeDefManager* clone()=0;
276 // Get node definition
277 virtual const ContentFeatures& get(content_t c) const=0;
278 virtual const ContentFeatures& get(const MapNode &n) const=0;
279 virtual bool getId(const std::string &name, content_t &result) const=0;
280 virtual content_t getId(const std::string &name) const=0;
281 // Allows "group:name" in addition to regular node names
282 virtual void getIds(const std::string &name, std::set<content_t> &result)
284 // If not found, returns the features of CONTENT_IGNORE
285 virtual const ContentFeatures& get(const std::string &name) const=0;
287 // Register node definition
288 virtual void set(content_t c, const ContentFeatures &def)=0;
289 // Register node definition by name (allocate an id)
290 // If returns CONTENT_IGNORE, could not allocate id
291 virtual content_t set(const std::string &name,
292 const ContentFeatures &def)=0;
293 // If returns CONTENT_IGNORE, could not allocate id
294 virtual content_t allocateDummy(const std::string &name)=0;
297 Update item alias mapping.
298 Call after updating item definitions.
300 virtual void updateAliases(IItemDefManager *idef)=0;
303 Update tile textures to latest return values of TextueSource.
304 Call after updating the texture atlas of a TextureSource.
306 virtual void updateTextures(ITextureSource *tsrc)=0;
308 virtual void serialize(std::ostream &os)=0;
309 virtual void deSerialize(std::istream &is)=0;
312 IWritableNodeDefManager* createNodeDefManager();