]> git.lizzy.rs Git - dragonfireclient.git/blob - src/nodedef.h
5e4e3378ca83311fdf4230e67d2e508a26e53266
[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         // 0     1     2     3     4     5
107         // up    down  right left  back  front 
108         TileSpec tiles[6];
109         
110         video::ITexture *inventory_texture;
111
112         // Post effect color, drawn when the camera is inside the node.
113         video::SColor post_effect_color;
114
115         // Special material/texture
116         // - Currently used for flowing liquids
117         video::SMaterial *special_material;
118         video::SMaterial *special_material2;
119         AtlasPointer *special_atlas;
120 #endif
121         
122         // Texture names
123         std::string tname_tiles[6];
124         std::string tname_inventory;
125         std::string tname_special;
126         u8 alpha;
127         bool backface_culling;
128
129         // List of all block textures that have been used (value is dummy)
130         // Used for texture atlas making.
131         // Exists on server too for cleaner code in content_mapnode.cpp.
132         std::set<std::string> used_texturenames;
133         
134         // Type of MapNode::param1
135         ContentParamType param_type;
136         // True for all ground-like things like stone and mud, false for eg. trees
137         bool is_ground_content;
138         bool light_propagates;
139         bool sunlight_propagates;
140         u8 solidness; // Used when choosing which face is drawn
141         u8 visual_solidness; // When solidness=0, this tells how it looks like
142         // This is used for collision detection.
143         // Also for general solidness queries.
144         bool walkable;
145         // Player can point to these
146         bool pointable;
147         // Player can dig these
148         bool diggable;
149         // Player can climb these
150         bool climbable;
151         // Player can build on these
152         bool buildable_to;
153         // If true, param2 is set to direction when placed. Used for torches.
154         // NOTE: the direction format is quite inefficient and should be changed
155         bool wall_mounted;
156         // If true, node is equivalent to air. Torches are, air is. Water is not.
157         // Is used for example to check whether a mud block can have grass on.
158         bool air_equivalent;
159         // Whether this content type often contains mineral.
160         // Used for texture atlas creation.
161         // Currently only enabled for CONTENT_STONE.
162         bool often_contains_mineral;
163         
164         // Inventory item string as which the node appears in inventory when dug.
165         // Mineral overrides this.
166         std::string dug_item;
167
168         // Extra dug item and its rarity
169         std::string extra_dug_item;
170         s32 extra_dug_item_rarity;
171
172         // Initial metadata is cloned from this
173         NodeMetadata *initial_metadata;
174         
175         // Whether the node is non-liquid, source liquid or flowing liquid
176         enum LiquidType liquid_type;
177         // If the content is liquid, this is the flowing version of the liquid.
178         content_t liquid_alternative_flowing;
179         // If the content is liquid, this is the source version of the liquid.
180         content_t liquid_alternative_source;
181         // Viscosity for fluid flow, ranging from 1 to 7, with
182         // 1 giving almost instantaneous propagation and 7 being
183         // the slowest possible
184         u8 liquid_viscosity;
185         
186         // Amount of light the node emits
187         u8 light_source;
188         
189         u32 damage_per_second;
190
191         NodeBox selection_box;
192
193         MaterialProperties material;
194         
195         // NOTE: Move relevant properties to here from elsewhere
196
197         void reset()
198         {
199                 // This isn't exactly complete due to lazyness
200                 // TODO: Make it completely reset everything
201 #ifndef SERVER
202                 inventory_texture = NULL;
203                 
204                 post_effect_color = video::SColor(0, 0, 0, 0);
205                 special_material = NULL;
206                 special_material2 = NULL;
207                 special_atlas = NULL;
208 #endif
209                 for(u32 i=0; i<6; i++)
210                         tname_tiles[i] = "";
211                 tname_inventory = "";
212                 tname_special = "";
213                 alpha = 255;
214                 backface_culling = true;
215                 used_texturenames.clear();
216                 param_type = CPT_NONE;
217                 is_ground_content = false;
218                 light_propagates = false;
219                 sunlight_propagates = false;
220                 solidness = 2;
221                 visual_solidness = 0;
222                 walkable = true;
223                 pointable = true;
224                 diggable = true;
225                 climbable = false;
226                 buildable_to = false;
227                 wall_mounted = false;
228                 air_equivalent = false;
229                 often_contains_mineral = false;
230                 dug_item = "";
231                 initial_metadata = NULL;
232                 liquid_type = LIQUID_NONE;
233                 liquid_alternative_flowing = CONTENT_IGNORE;
234                 liquid_alternative_source = CONTENT_IGNORE;
235                 liquid_viscosity = 0;
236                 light_source = 0;
237                 damage_per_second = 0;
238                 selection_box = NodeBox();
239                 material = MaterialProperties();
240         }
241
242         ContentFeatures()
243         {
244                 reset();
245         }
246
247         ~ContentFeatures();
248         
249         /*
250                 Quickhands for simple materials
251         */
252         
253         void setTexture(u16 i, std::string name);
254
255         void setAllTextures(std::string name, u8 alpha=255)
256         {
257                 for(u16 i=0; i<6; i++)
258                         setTexture(i, name);
259                 alpha = alpha;
260                 // Force inventory texture too
261                 setInventoryTexture(name);
262         }
263
264         void setInventoryTexture(std::string imgname);
265         void setInventoryTextureCube(std::string top,
266                         std::string left, std::string right);
267
268 #if 0
269 #ifndef SERVER
270         void setTile(u16 i, const TileSpec &tile)
271         { tiles[i] = tile; }
272         void setAllTiles(const TileSpec &tile)
273         { for(u16 i=0; i<6; i++) setTile(i, tile); }
274 #endif
275 #endif
276
277         /*
278                 Some handy methods
279         */
280         bool isLiquid() const{
281                 return (liquid_type != LIQUID_NONE);
282         }
283         bool sameLiquid(const ContentFeatures &f) const{
284                 if(!isLiquid() || !f.isLiquid()) return false;
285                 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
286         }
287 };
288
289 class INodeDefManager
290 {
291 public:
292         INodeDefManager(){}
293         virtual ~INodeDefManager(){}
294         // Get node definition
295         virtual const ContentFeatures& get(content_t c) const=0;
296         virtual const ContentFeatures& get(const MapNode &n) const=0;
297 };
298
299 class IWritableNodeDefManager : public INodeDefManager
300 {
301 public:
302         IWritableNodeDefManager(){}
303         virtual ~IWritableNodeDefManager(){}
304         virtual IWritableNodeDefManager* clone()=0;
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         // Register node definition
310         virtual void set(content_t c, const ContentFeatures &def)=0;
311         virtual ContentFeatures* getModifiable(content_t c)=0;
312
313         /*
314                 Update tile textures to latest return values of TextueSource.
315                 Call after updating the texture atlas of a TextureSource.
316         */
317         virtual void updateTextures(ITextureSource *tsrc)=0;
318 };
319
320 IWritableNodeDefManager* createNodeDefManager();
321
322 #endif
323