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