]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapnode_contentfeatures.h
Create framework for getting rid of global definitions of node/tool/item/whatever...
[dragonfireclient.git] / src / mapnode_contentfeatures.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 MAPNODE_CONTENTFEATURES_HEADER
21 #define MAPNODE_CONTENTFEATURES_HEADER
22
23 #include "common_irrlicht.h"
24 #include <string>
25 #include "mapnode.h"
26 #ifndef SERVER
27 #include "tile.h"
28 #endif
29 #include "materials.h" // MaterialProperties
30 class ITextureSource;
31
32 /*
33         Content feature list
34         
35         Used for determining properties of MapNodes by content type without
36         storing such properties in the nodes itself.
37 */
38
39 /*
40         Initialize content feature table.
41
42         Must be called before accessing the table.
43 */
44 void init_contentfeatures(ITextureSource *tsrc);
45
46 enum ContentParamType
47 {
48         CPT_NONE,
49         CPT_LIGHT,
50         CPT_MINERAL,
51         // Direction for chests and furnaces and such
52         CPT_FACEDIR_SIMPLE
53 };
54
55 enum LiquidType
56 {
57         LIQUID_NONE,
58         LIQUID_FLOWING,
59         LIQUID_SOURCE
60 };
61
62 enum NodeBoxType
63 {
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)
67 };
68
69 struct NodeBox
70 {
71         enum NodeBoxType type;
72         // NODEBOX_REGULAR (no parameters)
73         // NODEBOX_FIXED
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
79
80         NodeBox():
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)
88         {}
89 };
90
91 struct MapNode;
92 class NodeMetadata;
93
94 struct ContentFeatures
95 {
96 #ifndef SERVER
97         /*
98                 0: up
99                 1: down
100                 2: right
101                 3: left
102                 4: back
103                 5: front
104         */
105         TileSpec tiles[6];
106         
107         video::ITexture *inventory_texture;
108
109         // Used currently for flowing liquids
110         u8 vertex_alpha;
111         // Post effect color, drawn when the camera is inside the node.
112         video::SColor post_effect_color;
113         // Special irrlicht material, used sometimes
114         video::SMaterial *special_material;
115         video::SMaterial *special_material2;
116         AtlasPointer *special_atlas;
117 #endif
118
119         // List of all block textures that have been used (value is dummy)
120         // Used for texture atlas making.
121         // Exists on server too for cleaner code in content_mapnode.cpp.
122         core::map<std::string, bool> used_texturenames;
123         
124         // Type of MapNode::param1
125         ContentParamType param_type;
126         // True for all ground-like things like stone and mud, false for eg. trees
127         bool is_ground_content;
128         bool light_propagates;
129         bool sunlight_propagates;
130         u8 solidness; // Used when choosing which face is drawn
131         u8 visual_solidness; // When solidness=0, this tells how it looks like
132         // This is used for collision detection.
133         // Also for general solidness queries.
134         bool walkable;
135         // Player can point to these
136         bool pointable;
137         // Player can dig these
138         bool diggable;
139         // Player can climb these
140         bool climbable;
141         // Player can build on these
142         bool buildable_to;
143         // If true, param2 is set to direction when placed. Used for torches.
144         // NOTE: the direction format is quite inefficient and should be changed
145         bool wall_mounted;
146         // If true, node is equivalent to air. Torches are, air is. Water is not.
147         // Is used for example to check whether a mud block can have grass on.
148         bool air_equivalent;
149         // Whether this content type often contains mineral.
150         // Used for texture atlas creation.
151         // Currently only enabled for CONTENT_STONE.
152         bool often_contains_mineral;
153         
154         // Inventory item string as which the node appears in inventory when dug.
155         // Mineral overrides this.
156         std::string dug_item;
157
158         // Extra dug item and its rarity
159         std::string extra_dug_item;
160         s32 extra_dug_item_rarity;
161
162         // Initial metadata is cloned from this
163         NodeMetadata *initial_metadata;
164         
165         // Whether the node is non-liquid, source liquid or flowing liquid
166         enum LiquidType liquid_type;
167         // If the content is liquid, this is the flowing version of the liquid.
168         content_t liquid_alternative_flowing;
169         // If the content is liquid, this is the source version of the liquid.
170         content_t liquid_alternative_source;
171         // Viscosity for fluid flow, ranging from 1 to 7, with
172         // 1 giving almost instantaneous propagation and 7 being
173         // the slowest possible
174         u8 liquid_viscosity;
175         
176         // Amount of light the node emits
177         u8 light_source;
178         
179         u32 damage_per_second;
180
181         NodeBox selection_box;
182
183         MaterialProperties material;
184         
185         // NOTE: Move relevant properties to here from elsewhere
186
187         void reset()
188         {
189 #ifndef SERVER
190                 inventory_texture = NULL;
191                 
192                 vertex_alpha = 255;
193                 post_effect_color = video::SColor(0, 0, 0, 0);
194                 special_material = NULL;
195                 special_material2 = NULL;
196                 special_atlas = NULL;
197 #endif
198                 param_type = CPT_NONE;
199                 is_ground_content = false;
200                 light_propagates = false;
201                 sunlight_propagates = false;
202                 solidness = 2;
203                 visual_solidness = 0;
204                 walkable = true;
205                 pointable = true;
206                 diggable = true;
207                 climbable = false;
208                 buildable_to = false;
209                 wall_mounted = false;
210                 air_equivalent = false;
211                 often_contains_mineral = false;
212                 dug_item = "";
213                 initial_metadata = NULL;
214                 liquid_type = LIQUID_NONE;
215                 liquid_alternative_flowing = CONTENT_IGNORE;
216                 liquid_alternative_source = CONTENT_IGNORE;
217                 liquid_viscosity = 0;
218                 light_source = 0;
219                 damage_per_second = 0;
220                 selection_box = NodeBox();
221                 material = MaterialProperties();
222         }
223
224         ContentFeatures()
225         {
226                 reset();
227         }
228
229         ~ContentFeatures();
230         
231         /*
232                 Quickhands for simple materials
233         */
234         
235 #ifdef SERVER
236         void setTexture(ITextureSource *tsrc, u16 i, std::string name,
237                         u8 alpha=255)
238         {}
239         void setAllTextures(ITextureSource *tsrc, std::string name, u8 alpha=255)
240         {}
241 #else
242         void setTexture(ITextureSource *tsrc,
243                         u16 i, std::string name, u8 alpha=255);
244
245         void setAllTextures(ITextureSource *tsrc,
246                         std::string name, u8 alpha=255)
247         {
248                 for(u16 i=0; i<6; i++)
249                 {
250                         setTexture(tsrc, i, name, alpha);
251                 }
252                 // Force inventory texture too
253                 setInventoryTexture(name, tsrc);
254         }
255 #endif
256
257 #ifndef SERVER
258         void setTile(u16 i, const TileSpec &tile)
259         {
260                 tiles[i] = tile;
261         }
262         void setAllTiles(const TileSpec &tile)
263         {
264                 for(u16 i=0; i<6; i++)
265                 {
266                         setTile(i, tile);
267                 }
268         }
269 #endif
270
271 #ifdef SERVER
272         void setInventoryTexture(std::string imgname,
273                         ITextureSource *tsrc)
274         {}
275         void setInventoryTextureCube(std::string top,
276                         std::string left, std::string right, ITextureSource *tsrc)
277         {}
278 #else
279         void setInventoryTexture(std::string imgname, ITextureSource *tsrc);
280         
281         void setInventoryTextureCube(std::string top,
282                         std::string left, std::string right, ITextureSource *tsrc);
283 #endif
284 };
285
286 /*
287         Call this to access the ContentFeature list
288 */
289 ContentFeatures & content_features(content_t i);
290 ContentFeatures & content_features(MapNode &n);
291
292 /*
293         Here is a bunch of DEPRECATED functions.
294 */
295
296 /*
297         If true, the material allows light propagation and brightness is stored
298         in param.
299         NOTE: Don't use, use "content_features(m).whatever" instead
300 */
301 inline bool light_propagates_content(content_t m)
302 {
303         return content_features(m).light_propagates;
304 }
305 /*
306         If true, the material allows lossless sunlight propagation.
307         NOTE: It doesn't seem to go through torches regardlessly of this
308         NOTE: Don't use, use "content_features(m).whatever" instead
309 */
310 inline bool sunlight_propagates_content(content_t m)
311 {
312         return content_features(m).sunlight_propagates;
313 }
314 /*
315         On a node-node surface, the material of the node with higher solidness
316         is used for drawing.
317         0: Invisible
318         1: Transparent
319         2: Opaque
320         NOTE: Don't use, use "content_features(m).whatever" instead
321 */
322 inline u8 content_solidness(content_t m)
323 {
324         return content_features(m).solidness;
325 }
326 // Objects collide with walkable contents
327 // NOTE: Don't use, use "content_features(m).whatever" instead
328 inline bool content_walkable(content_t m)
329 {
330         return content_features(m).walkable;
331 }
332 // NOTE: Don't use, use "content_features(m).whatever" instead
333 inline bool content_liquid(content_t m)
334 {
335         return content_features(m).liquid_type != LIQUID_NONE;
336 }
337 // NOTE: Don't use, use "content_features(m).whatever" instead
338 inline bool content_flowing_liquid(content_t m)
339 {
340         return content_features(m).liquid_type == LIQUID_FLOWING;
341 }
342 // NOTE: Don't use, use "content_features(m).whatever" instead
343 inline bool content_liquid_source(content_t m)
344 {
345         return content_features(m).liquid_type == LIQUID_SOURCE;
346 }
347 // CONTENT_WATER || CONTENT_WATERSOURCE -> CONTENT_WATER
348 // CONTENT_LAVA || CONTENT_LAVASOURCE -> CONTENT_LAVA
349 // NOTE: Don't use, use "content_features(m).whatever" instead
350 inline content_t make_liquid_flowing(content_t m)
351 {
352         u8 c = content_features(m).liquid_alternative_flowing;
353         assert(c != CONTENT_IGNORE);
354         return c;
355 }
356 // Pointable contents can be pointed to in the map
357 // NOTE: Don't use, use "content_features(m).whatever" instead
358 inline bool content_pointable(content_t m)
359 {
360         return content_features(m).pointable;
361 }
362 // NOTE: Don't use, use "content_features(m).whatever" instead
363 inline bool content_diggable(content_t m)
364 {
365         return content_features(m).diggable;
366 }
367 // NOTE: Don't use, use "content_features(m).whatever" instead
368 inline bool content_buildable_to(content_t m)
369 {
370         return content_features(m).buildable_to;
371 }
372
373
374 #endif
375