3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #ifndef MAPNODE_CONTENTFEATURES_HEADER
21 #define MAPNODE_CONTENTFEATURES_HEADER
23 #include "common_irrlicht.h"
29 #include "materials.h" // MaterialProperties
34 Used for determining properties of MapNodes by content type without
35 storing such properties in the nodes itself.
39 Initialize content feature table.
41 Must be called before accessing the table.
43 void init_contentfeatures();
50 // Direction for chests and furnaces and such
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)
70 enum NodeBoxType type;
71 // NODEBOX_REGULAR (no parameters)
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
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)
93 struct ContentFeatures
106 video::ITexture *inventory_texture;
108 // Used currently for flowing liquids
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;
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;
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.
134 // Player can point to these
136 // Player can dig these
138 // Player can climb these
140 // Player can build on these
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
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.
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;
153 // Inventory item string as which the node appears in inventory when dug.
154 // Mineral overrides this.
155 std::string dug_item;
157 // Extra dug item and its rarity
158 std::string extra_dug_item;
159 s32 extra_dug_item_rarity;
161 // Initial metadata is cloned from this
162 NodeMetadata *initial_metadata;
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
175 // Amount of light the node emits
178 u32 damage_per_second;
180 NodeBox selection_box;
182 MaterialProperties material;
184 // NOTE: Move relevant properties to here from elsewhere
189 inventory_texture = NULL;
192 post_effect_color = video::SColor(0, 0, 0, 0);
193 special_material = NULL;
194 special_material2 = NULL;
195 special_atlas = NULL;
197 param_type = CPT_NONE;
198 is_ground_content = false;
199 light_propagates = false;
200 sunlight_propagates = false;
202 visual_solidness = 0;
207 buildable_to = false;
208 wall_mounted = false;
209 air_equivalent = false;
210 often_contains_mineral = false;
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;
218 damage_per_second = 0;
219 selection_box = NodeBox();
220 material = MaterialProperties();
231 Quickhands for simple materials
235 void setTexture(u16 i, std::string name, u8 alpha=255)
237 void setAllTextures(std::string name, u8 alpha=255)
240 void setTexture(u16 i, std::string name, u8 alpha=255);
242 void setAllTextures(std::string name, u8 alpha=255)
244 for(u16 i=0; i<6; i++)
246 setTexture(i, name, alpha);
248 // Force inventory texture too
249 setInventoryTexture(name);
254 void setTile(u16 i, const TileSpec &tile)
258 void setAllTiles(const TileSpec &tile)
260 for(u16 i=0; i<6; i++)
268 void setInventoryTexture(std::string imgname)
270 void setInventoryTextureCube(std::string top,
271 std::string left, std::string right)
274 void setInventoryTexture(std::string imgname);
276 void setInventoryTextureCube(std::string top,
277 std::string left, std::string right);
282 Call this to access the ContentFeature list
284 ContentFeatures & content_features(content_t i);
285 ContentFeatures & content_features(MapNode &n);
288 Here is a bunch of DEPRECATED functions.
292 If true, the material allows light propagation and brightness is stored
294 NOTE: Don't use, use "content_features(m).whatever" instead
296 inline bool light_propagates_content(content_t m)
298 return content_features(m).light_propagates;
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
305 inline bool sunlight_propagates_content(content_t m)
307 return content_features(m).sunlight_propagates;
310 On a node-node surface, the material of the node with higher solidness
315 NOTE: Don't use, use "content_features(m).whatever" instead
317 inline u8 content_solidness(content_t m)
319 return content_features(m).solidness;
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)
325 return content_features(m).walkable;
327 // NOTE: Don't use, use "content_features(m).whatever" instead
328 inline bool content_liquid(content_t m)
330 return content_features(m).liquid_type != LIQUID_NONE;
332 // NOTE: Don't use, use "content_features(m).whatever" instead
333 inline bool content_flowing_liquid(content_t m)
335 return content_features(m).liquid_type == LIQUID_FLOWING;
337 // NOTE: Don't use, use "content_features(m).whatever" instead
338 inline bool content_liquid_source(content_t m)
340 return content_features(m).liquid_type == LIQUID_SOURCE;
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)
347 u8 c = content_features(m).liquid_alternative_flowing;
348 assert(c != CONTENT_IGNORE);
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)
355 return content_features(m).pointable;
357 // NOTE: Don't use, use "content_features(m).whatever" instead
358 inline bool content_diggable(content_t m)
360 return content_features(m).diggable;
362 // NOTE: Don't use, use "content_features(m).whatever" instead
363 inline bool content_buildable_to(content_t m)
365 return content_features(m).buildable_to;