]> git.lizzy.rs Git - dragonfireclient.git/blob - src/nodedef.h
dece63fcd90a7645bb26939ffab2af3153c501b3
[dragonfireclient.git] / src / nodedef.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #ifndef NODEDEF_HEADER
21 #define NODEDEF_HEADER
22
23 #include "common_irrlicht.h"
24 #include <string>
25 #include <set>
26 #include "mapnode.h"
27 #ifndef SERVER
28 #include "tile.h"
29 #endif
30 #include "materials.h" // MaterialProperties
31 class ITextureSource;
32
33 /*
34         TODO: Rename to nodedef.h
35 */
36
37 #if 0
38
39 /*
40         Content feature list
41         
42         Used for determining properties of MapNodes by content type without
43         storing such properties in the nodes itself.
44 */
45
46 /*
47         Initialize content feature table.
48
49         Must be called before accessing the table.
50 */
51 void init_contentfeatures(ITextureSource *tsrc);
52
53 #endif
54
55 enum ContentParamType
56 {
57         CPT_NONE,
58         CPT_LIGHT,
59         CPT_MINERAL,
60         // Direction for chests and furnaces and such
61         CPT_FACEDIR_SIMPLE
62 };
63
64 enum LiquidType
65 {
66         LIQUID_NONE,
67         LIQUID_FLOWING,
68         LIQUID_SOURCE
69 };
70
71 enum NodeBoxType
72 {
73         NODEBOX_REGULAR, // Regular block; allows buildable_to
74         NODEBOX_FIXED, // Static separately defined box
75         NODEBOX_WALLMOUNTED, // Box for wall_mounted nodes; (top, bottom, side)
76 };
77
78 struct NodeBox
79 {
80         enum NodeBoxType type;
81         // NODEBOX_REGULAR (no parameters)
82         // NODEBOX_FIXED
83         core::aabbox3d<f32> fixed;
84         // NODEBOX_WALLMOUNTED
85         core::aabbox3d<f32> wall_top;
86         core::aabbox3d<f32> wall_bottom;
87         core::aabbox3d<f32> wall_side; // being at the -X side
88
89         NodeBox():
90                 type(NODEBOX_REGULAR),
91                 // default is rail-like
92                 fixed(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
93                 // default is sign/ladder-like
94                 wall_top(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2),
95                 wall_bottom(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
96                 wall_side(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2)
97         {}
98 };
99
100 struct MapNode;
101 class NodeMetadata;
102
103 struct ContentFeatures
104 {
105 #ifndef SERVER
106         /*
107                 0: up
108                 1: down
109                 2: right
110                 3: left
111                 4: back
112                 5: front
113         */
114         TileSpec tiles[6];
115         
116         video::ITexture *inventory_texture;
117
118         // Used currently for flowing liquids
119         u8 vertex_alpha;
120         // Post effect color, drawn when the camera is inside the node.
121         video::SColor post_effect_color;
122         // Special irrlicht material, used sometimes
123         video::SMaterial *special_material;
124         video::SMaterial *special_material2;
125         AtlasPointer *special_atlas;
126 #endif
127
128         // List of all block textures that have been used (value is dummy)
129         // Used for texture atlas making.
130         // Exists on server too for cleaner code in content_mapnode.cpp.
131         std::set<std::string> used_texturenames;
132         
133         // Type of MapNode::param1
134         ContentParamType param_type;
135         // True for all ground-like things like stone and mud, false for eg. trees
136         bool is_ground_content;
137         bool light_propagates;
138         bool sunlight_propagates;
139         u8 solidness; // Used when choosing which face is drawn
140         u8 visual_solidness; // When solidness=0, this tells how it looks like
141         // This is used for collision detection.
142         // Also for general solidness queries.
143         bool walkable;
144         // Player can point to these
145         bool pointable;
146         // Player can dig these
147         bool diggable;
148         // Player can climb these
149         bool climbable;
150         // Player can build on these
151         bool buildable_to;
152         // If true, param2 is set to direction when placed. Used for torches.
153         // NOTE: the direction format is quite inefficient and should be changed
154         bool wall_mounted;
155         // If true, node is equivalent to air. Torches are, air is. Water is not.
156         // Is used for example to check whether a mud block can have grass on.
157         bool air_equivalent;
158         // Whether this content type often contains mineral.
159         // Used for texture atlas creation.
160         // Currently only enabled for CONTENT_STONE.
161         bool often_contains_mineral;
162         
163         // Inventory item string as which the node appears in inventory when dug.
164         // Mineral overrides this.
165         std::string dug_item;
166
167         // Extra dug item and its rarity
168         std::string extra_dug_item;
169         s32 extra_dug_item_rarity;
170
171         // Initial metadata is cloned from this
172         NodeMetadata *initial_metadata;
173         
174         // Whether the node is non-liquid, source liquid or flowing liquid
175         enum LiquidType liquid_type;
176         // If the content is liquid, this is the flowing version of the liquid.
177         content_t liquid_alternative_flowing;
178         // If the content is liquid, this is the source version of the liquid.
179         content_t liquid_alternative_source;
180         // Viscosity for fluid flow, ranging from 1 to 7, with
181         // 1 giving almost instantaneous propagation and 7 being
182         // the slowest possible
183         u8 liquid_viscosity;
184         
185         // Amount of light the node emits
186         u8 light_source;
187         
188         u32 damage_per_second;
189
190         NodeBox selection_box;
191
192         MaterialProperties material;
193         
194         // NOTE: Move relevant properties to here from elsewhere
195
196         void reset()
197         {
198 #ifndef SERVER
199                 inventory_texture = NULL;
200                 
201                 vertex_alpha = 255;
202                 post_effect_color = video::SColor(0, 0, 0, 0);
203                 special_material = NULL;
204                 special_material2 = NULL;
205                 special_atlas = NULL;
206 #endif
207                 used_texturenames.clear();
208                 param_type = CPT_NONE;
209                 is_ground_content = false;
210                 light_propagates = false;
211                 sunlight_propagates = false;
212                 solidness = 2;
213                 visual_solidness = 0;
214                 walkable = true;
215                 pointable = true;
216                 diggable = true;
217                 climbable = false;
218                 buildable_to = false;
219                 wall_mounted = false;
220                 air_equivalent = false;
221                 often_contains_mineral = false;
222                 dug_item = "";
223                 initial_metadata = NULL;
224                 liquid_type = LIQUID_NONE;
225                 liquid_alternative_flowing = CONTENT_IGNORE;
226                 liquid_alternative_source = CONTENT_IGNORE;
227                 liquid_viscosity = 0;
228                 light_source = 0;
229                 damage_per_second = 0;
230                 selection_box = NodeBox();
231                 material = MaterialProperties();
232         }
233
234         ContentFeatures()
235         {
236                 reset();
237         }
238
239         ~ContentFeatures();
240         
241         /*
242                 Quickhands for simple materials
243         */
244         
245 #ifdef SERVER
246         void setTexture(ITextureSource *tsrc, u16 i, std::string name,
247                         u8 alpha=255)
248         {}
249         void setAllTextures(ITextureSource *tsrc, std::string name, u8 alpha=255)
250         {}
251 #else
252         void setTexture(ITextureSource *tsrc,
253                         u16 i, std::string name, u8 alpha=255);
254
255         void setAllTextures(ITextureSource *tsrc,
256                         std::string name, u8 alpha=255)
257         {
258                 for(u16 i=0; i<6; i++)
259                 {
260                         setTexture(tsrc, i, name, alpha);
261                 }
262                 // Force inventory texture too
263                 setInventoryTexture(name, tsrc);
264         }
265 #endif
266
267 #ifndef SERVER
268         void setTile(u16 i, const TileSpec &tile)
269         { tiles[i] = tile; }
270         void setAllTiles(const TileSpec &tile)
271         { for(u16 i=0; i<6; i++) setTile(i, tile); }
272 #endif
273
274 #ifdef SERVER
275         void setInventoryTexture(std::string imgname,
276                         ITextureSource *tsrc)
277         {}
278         void setInventoryTextureCube(std::string top,
279                         std::string left, std::string right, ITextureSource *tsrc)
280         {}
281 #else
282         void setInventoryTexture(std::string imgname, ITextureSource *tsrc);
283         
284         void setInventoryTextureCube(std::string top,
285                         std::string left, std::string right, ITextureSource *tsrc);
286 #endif
287
288         /*
289                 Some handy methods
290         */
291         bool isLiquid() const{
292                 return (liquid_type != LIQUID_NONE);
293         }
294         bool sameLiquid(const ContentFeatures &f) const{
295                 if(!isLiquid() || !f.isLiquid()) return false;
296                 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
297         }
298 };
299
300 class INodeDefManager
301 {
302 public:
303         INodeDefManager(){}
304         virtual ~INodeDefManager(){}
305         // Get node definition
306         virtual const ContentFeatures& get(content_t c) const=0;
307         virtual const ContentFeatures& get(const MapNode &n) const=0;
308 };
309
310 class IWritableNodeDefManager : public INodeDefManager
311 {
312 public:
313         IWritableNodeDefManager(){}
314         virtual ~IWritableNodeDefManager(){}
315         virtual IWritableNodeDefManager* clone()=0;
316         // Get node definition
317         virtual const ContentFeatures& get(content_t c) const=0;
318         virtual const ContentFeatures& get(const MapNode &n) const=0;
319                 
320         // Register node definition
321         virtual void set(content_t c, const ContentFeatures &def)=0;
322         virtual ContentFeatures* getModifiable(content_t c)=0;
323 };
324
325 // If textures not actually available (server), tsrc can be NULL
326 IWritableNodeDefManager* createNodeDefManager(ITextureSource *tsrc);
327
328
329 #endif
330