]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapnode_contentfeatures.h
New kind of tool speed and wear calculation thingy
[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
31 /*
32         Content feature list
33         
34         Used for determining properties of MapNodes by content type without
35         storing such properties in the nodes itself.
36 */
37
38 /*
39         Initialize content feature table.
40
41         Must be called before accessing the table.
42 */
43 void init_contentfeatures();
44
45 enum ContentParamType
46 {
47         CPT_NONE,
48         CPT_LIGHT,
49         CPT_MINERAL,
50         // Direction for chests and furnaces and such
51         CPT_FACEDIR_SIMPLE
52 };
53
54 enum LiquidType
55 {
56         LIQUID_NONE,
57         LIQUID_FLOWING,
58         LIQUID_SOURCE
59 };
60
61 enum NodeBoxType
62 {
63         NODEBOX_REGULAR, // Regular block; allows buildable_to
64         NODEBOX_FIXED, // Static separately defined box
65         NODEBOX_WALLMOUNTED, // Box for wall_mounted nodes; (top, bottom, side)
66 };
67
68 struct NodeBox
69 {
70         enum NodeBoxType type;
71         // NODEBOX_REGULAR (no parameters)
72         // NODEBOX_FIXED
73         core::aabbox3d<f32> fixed;
74         // NODEBOX_WALLMOUNTED
75         core::aabbox3d<f32> wall_top;
76         core::aabbox3d<f32> wall_bottom;
77         core::aabbox3d<f32> wall_side; // being at the -X side
78
79         NodeBox():
80                 type(NODEBOX_REGULAR),
81                 // default is rail-like
82                 fixed(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
83                 // default is sign/ladder-like
84                 wall_top(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2),
85                 wall_bottom(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
86                 wall_side(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2)
87         {}
88 };
89
90 struct MapNode;
91 class NodeMetadata;
92
93 struct ContentFeatures
94 {
95 #ifndef SERVER
96         /*
97                 0: up
98                 1: down
99                 2: right
100                 3: left
101                 4: back
102                 5: front
103         */
104         TileSpec tiles[6];
105         
106         video::ITexture *inventory_texture;
107
108         // Used currently for flowing liquids
109         u8 vertex_alpha;
110         // Post effect color, drawn when the camera is inside the node.
111         video::SColor post_effect_color;
112         // Special irrlicht material, used sometimes
113         video::SMaterial *special_material;
114         video::SMaterial *special_material2;
115         AtlasPointer *special_atlas;
116 #endif
117
118         // List of all block textures that have been used (value is dummy)
119         // Used for texture atlas making.
120         // Exists on server too for cleaner code in content_mapnode.cpp.
121         core::map<std::string, bool> used_texturenames;
122         
123         // Type of MapNode::param1
124         ContentParamType param_type;
125         // True for all ground-like things like stone and mud, false for eg. trees
126         bool is_ground_content;
127         bool light_propagates;
128         bool sunlight_propagates;
129         u8 solidness; // Used when choosing which face is drawn
130         u8 visual_solidness; // When solidness=0, this tells how it looks like
131         // This is used for collision detection.
132         // Also for general solidness queries.
133         bool walkable;
134         // Player can point to these
135         bool pointable;
136         // Player can dig these
137         bool diggable;
138         // Player can climb these
139         bool climbable;
140         // Player can build on these
141         bool buildable_to;
142         // If true, param2 is set to direction when placed. Used for torches.
143         // NOTE: the direction format is quite inefficient and should be changed
144         bool wall_mounted;
145         // If true, node is equivalent to air. Torches are, air is. Water is not.
146         // Is used for example to check whether a mud block can have grass on.
147         bool air_equivalent;
148         // Whether this content type often contains mineral.
149         // Used for texture atlas creation.
150         // Currently only enabled for CONTENT_STONE.
151         bool often_contains_mineral;
152         
153         // Inventory item string as which the node appears in inventory when dug.
154         // Mineral overrides this.
155         std::string dug_item;
156
157         // Extra dug item and its rarity
158         std::string extra_dug_item;
159         s32 extra_dug_item_rarity;
160
161         // Initial metadata is cloned from this
162         NodeMetadata *initial_metadata;
163         
164         // Whether the node is non-liquid, source liquid or flowing liquid
165         enum LiquidType liquid_type;
166         // If the content is liquid, this is the flowing version of the liquid.
167         content_t liquid_alternative_flowing;
168         // If the content is liquid, this is the source version of the liquid.
169         content_t liquid_alternative_source;
170         // Viscosity for fluid flow, ranging from 1 to 7, with
171         // 1 giving almost instantaneous propagation and 7 being
172         // the slowest possible
173         u8 liquid_viscosity;
174         
175         // Amount of light the node emits
176         u8 light_source;
177         
178         u32 damage_per_second;
179
180         NodeBox selection_box;
181
182         MaterialProperties material;
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                 damage_per_second = 0;
219                 selection_box = NodeBox();
220                 material = MaterialProperties();
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