* possibly improved water flow, by flyx86
[oweals/minetest.git] / src / content_mapnode.cpp
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 // For g_settings
21 #include "main.h"
22
23 #include "content_mapnode.h"
24 #include "mapnode.h"
25 #include "content_nodemeta.h"
26
27 // TODO: Get rid of these and set up some attributes like toughness,
28 //       fluffyness, and a funciton to calculate time and durability loss
29 //       (and sound? and whatever else) from them
30 void setStoneLikeDiggingProperties(DiggingPropertiesList &list, float toughness);
31 void setDirtLikeDiggingProperties(DiggingPropertiesList &list, float toughness);
32 void setWoodLikeDiggingProperties(DiggingPropertiesList &list, float toughness);
33
34 void content_mapnode_init()
35 {
36         // Read some settings
37         bool new_style_water = g_settings.getBool("new_style_water");
38         bool new_style_leaves = g_settings.getBool("new_style_leaves");
39         bool invisible_stone = g_settings.getBool("invisible_stone");
40
41         u8 i;
42         ContentFeatures *f = NULL;
43
44         i = CONTENT_STONE;
45         f = &content_features(i);
46         f->setAllTextures("stone.png");
47         f->setInventoryTextureCube("stone.png", "stone.png", "stone.png");
48         f->param_type = CPT_MINERAL;
49         f->is_ground_content = true;
50         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 1";
51         setStoneLikeDiggingProperties(f->digging_properties, 1.0);
52         if(invisible_stone)
53                 f->solidness = 0; // For debugging, hides regular stone
54         
55         i = CONTENT_GRASS;
56         f = &content_features(i);
57         f->setAllTextures("mud.png^grass_side.png");
58         f->setTexture(0, "grass.png");
59         f->setTexture(1, "mud.png");
60         f->param_type = CPT_MINERAL;
61         f->is_ground_content = true;
62         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
63         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
64         
65         i = CONTENT_GRASS_FOOTSTEPS;
66         f = &content_features(i);
67         f->setAllTextures("mud.png^grass_side.png");
68         f->setTexture(0, "grass_footsteps.png");
69         f->setTexture(1, "mud.png");
70         f->param_type = CPT_MINERAL;
71         f->is_ground_content = true;
72         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
73         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
74         
75         i = CONTENT_MUD;
76         f = &content_features(i);
77         f->setAllTextures("mud.png");
78         f->setInventoryTextureCube("mud.png", "mud.png", "mud.png");
79         f->param_type = CPT_MINERAL;
80         f->is_ground_content = true;
81         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
82         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
83         
84         i = CONTENT_SAND;
85         f = &content_features(i);
86         f->setAllTextures("sand.png");
87         f->setInventoryTextureCube("sand.png", "sand.png", "sand.png");
88         f->param_type = CPT_MINERAL;
89         f->is_ground_content = true;
90         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
91         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
92         
93         i = CONTENT_GRAVEL;
94         f = &content_features(i);
95         f->setAllTextures("gravel.png");
96         f->setInventoryTextureCube("gravel.png", "gravel.png", "gravel.png");
97         f->param_type = CPT_MINERAL;
98         f->is_ground_content = true;
99         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
100         setDirtLikeDiggingProperties(f->digging_properties, 1.75);
101         
102         i = CONTENT_SANDSTONE;
103         f = &content_features(i);
104         f->setAllTextures("sandstone.png");
105         f->setInventoryTextureCube("sandstone.png", "sandstone.png", "sandstone.png");
106         f->param_type = CPT_MINERAL;
107         f->is_ground_content = true;
108         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_SAND)+" 1";
109         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
110
111         i = CONTENT_CLAY;
112         f = &content_features(i);
113         f->setAllTextures("clay.png");
114         f->setInventoryTextureCube("clay.png", "clay.png", "clay.png");
115         f->param_type = CPT_MINERAL;
116         f->is_ground_content = true;
117         f->dug_item = std::string("CraftItem lump_of_clay 4");
118         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
119
120         i = CONTENT_BRICK;
121         f = &content_features(i);
122         f->setAllTextures("brick.png");
123         f->setInventoryTextureCube("brick.png", "brick.png", "brick.png");
124         f->param_type = CPT_MINERAL;
125         f->is_ground_content = true;
126         f->dug_item = std::string("CraftItem clay_brick 4");
127         setStoneLikeDiggingProperties(f->digging_properties, 1.0);
128
129         i = CONTENT_TREE;
130         f = &content_features(i);
131         f->setAllTextures("tree.png");
132         f->setTexture(0, "tree_top.png");
133         f->setTexture(1, "tree_top.png");
134         f->param_type = CPT_MINERAL;
135         f->is_ground_content = true;
136         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
137         setWoodLikeDiggingProperties(f->digging_properties, 1.0);
138         
139         i = CONTENT_LEAVES;
140         f = &content_features(i);
141         f->light_propagates = true;
142         //f->param_type = CPT_MINERAL;
143         f->param_type = CPT_LIGHT;
144         f->is_ground_content = true;
145         if(new_style_leaves)
146         {
147                 f->solidness = 0; // drawn separately, makes no faces
148                 f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png");
149         }
150         else
151         {
152                 f->setAllTextures("[noalpha:leaves.png");
153         }
154         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
155         setWoodLikeDiggingProperties(f->digging_properties, 0.15);
156
157         i = CONTENT_CACTUS;
158         f = &content_features(i);
159         f->setAllTextures("cactus_side.png");
160         f->setTexture(0, "cactus_top.png");
161         f->setTexture(1, "cactus_top.png");
162         f->setInventoryTextureCube("cactus_top.png", "cactus_side.png", "cactus_side.png");
163         f->param_type = CPT_MINERAL;
164         f->is_ground_content = true;
165         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
166         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
167
168         i = CONTENT_PAPYRUS;
169         f = &content_features(i);
170         f->setInventoryTexture("papyrus.png");
171         f->light_propagates = true;
172         f->param_type = CPT_LIGHT;
173         f->is_ground_content = true;
174         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
175         f->solidness = 0; // drawn separately, makes no faces
176         f->walkable = false;
177         setWoodLikeDiggingProperties(f->digging_properties, 0.25);
178
179         i = CONTENT_BOOKSHELF;
180         f = &content_features(i);
181         f->setAllTextures("bookshelf.png");
182         f->setTexture(0, "wood.png");
183         f->setTexture(1, "wood.png");
184         // FIXME: setInventoryTextureCube() only cares for the first texture
185         f->setInventoryTextureCube("bookshelf.png", "bookshelf.png", "bookshelf.png");
186         //f->setInventoryTextureCube("wood.png", "bookshelf.png", "bookshelf.png");
187         f->param_type = CPT_MINERAL;
188         f->is_ground_content = true;
189         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
190
191         i = CONTENT_GLASS;
192         f = &content_features(i);
193         f->light_propagates = true;
194         f->param_type = CPT_LIGHT;
195         f->is_ground_content = true;
196         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
197         f->solidness = 0; // drawn separately, makes no faces
198         f->setInventoryTextureCube("glass.png", "glass.png", "glass.png");
199         setWoodLikeDiggingProperties(f->digging_properties, 0.15);
200
201         i = CONTENT_FENCE;
202         f = &content_features(i);
203         f->light_propagates = true;
204         f->param_type = CPT_LIGHT;
205         f->is_ground_content = true;
206         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
207         f->solidness = 0; // drawn separately, makes no faces
208         f->air_equivalent = true; // grass grows underneath
209         f->setInventoryTexture("item_fence.png");
210         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
211
212         i = CONTENT_RAIL;
213         f = &content_features(i);
214         f->setInventoryTexture("rail.png");
215         f->light_propagates = true;
216         f->param_type = CPT_LIGHT;
217         f->is_ground_content = true;
218         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
219         f->solidness = 0; // drawn separately, makes no faces
220         f->air_equivalent = true; // grass grows underneath
221         f->walkable = false;
222         setDirtLikeDiggingProperties(f->digging_properties, 0.75);
223
224         // Deprecated
225         i = CONTENT_COALSTONE;
226         f = &content_features(i);
227         //f->translate_to = new MapNode(CONTENT_STONE, MINERAL_COAL);
228         f->setAllTextures("stone.png^mineral_coal.png");
229         f->is_ground_content = true;
230         setStoneLikeDiggingProperties(f->digging_properties, 1.5);
231         
232         i = CONTENT_WOOD;
233         f = &content_features(i);
234         f->setAllTextures("wood.png");
235         f->setInventoryTextureCube("wood.png", "wood.png", "wood.png");
236         f->is_ground_content = true;
237         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
238         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
239         
240         i = CONTENT_MESE;
241         f = &content_features(i);
242         f->setAllTextures("mese.png");
243         f->setInventoryTextureCube("mese.png", "mese.png", "mese.png");
244         f->is_ground_content = true;
245         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
246         setStoneLikeDiggingProperties(f->digging_properties, 0.5);
247         
248         i = CONTENT_CLOUD;
249         f = &content_features(i);
250         f->setAllTextures("cloud.png");
251         f->setInventoryTextureCube("cloud.png", "cloud.png", "cloud.png");
252         f->is_ground_content = true;
253         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
254         
255         i = CONTENT_AIR;
256         f = &content_features(i);
257         f->param_type = CPT_LIGHT;
258         f->light_propagates = true;
259         f->sunlight_propagates = true;
260         f->solidness = 0;
261         f->walkable = false;
262         f->pointable = false;
263         f->diggable = false;
264         f->buildable_to = true;
265         f->air_equivalent = true;
266         
267         i = CONTENT_WATER;
268         f = &content_features(i);
269         f->setInventoryTextureCube("water.png", "water.png", "water.png");
270         f->param_type = CPT_LIGHT;
271         f->light_propagates = true;
272         f->solidness = 0; // Drawn separately, makes no faces
273         f->walkable = false;
274         f->pointable = false;
275         f->diggable = false;
276         f->buildable_to = true;
277         f->liquid_type = LIQUID_FLOWING;
278         f->liquid_alternative_flowing = CONTENT_WATER;
279         f->liquid_alternative_source = CONTENT_WATERSOURCE;
280         
281         i = CONTENT_WATERSOURCE;
282         f = &content_features(i);
283         //f->setInventoryTexture("water.png");
284         f->setInventoryTextureCube("water.png", "water.png", "water.png");
285         if(new_style_water)
286         {
287                 f->solidness = 0; // drawn separately, makes no faces
288         }
289         else // old style
290         {
291                 f->solidness = 1;
292
293                 TileSpec t;
294                 if(g_texturesource)
295                         t.texture = g_texturesource->getTexture("water.png");
296                 
297                 t.alpha = WATER_ALPHA;
298                 t.material_type = MATERIAL_ALPHA_VERTEX;
299                 t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
300                 f->setAllTiles(t);
301         }
302         f->param_type = CPT_LIGHT;
303         f->light_propagates = true;
304         f->walkable = false;
305         f->pointable = false;
306         f->diggable = false;
307         f->buildable_to = true;
308         f->liquid_type = LIQUID_SOURCE;
309         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
310         f->liquid_alternative_flowing = CONTENT_WATER;
311         f->liquid_alternative_source = CONTENT_WATERSOURCE;
312         
313         i = CONTENT_TORCH;
314         f = &content_features(i);
315         f->setInventoryTexture("torch_on_floor.png");
316         f->param_type = CPT_LIGHT;
317         f->light_propagates = true;
318         f->sunlight_propagates = true;
319         f->solidness = 0; // drawn separately, makes no faces
320         f->walkable = false;
321         f->wall_mounted = true;
322         f->air_equivalent = true;
323         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
324         f->light_source = LIGHT_MAX-1;
325         f->digging_properties.set("", DiggingProperties(true, 0.0, 0));
326         
327         i = CONTENT_SIGN_WALL;
328         f = &content_features(i);
329         f->setInventoryTexture("sign_wall.png");
330         f->param_type = CPT_LIGHT;
331         f->light_propagates = true;
332         f->sunlight_propagates = true;
333         f->solidness = 0; // drawn separately, makes no faces
334         f->walkable = false;
335         f->wall_mounted = true;
336         f->air_equivalent = true;
337         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
338         if(f->initial_metadata == NULL)
339                 f->initial_metadata = new SignNodeMetadata("Some sign");
340         f->digging_properties.set("", DiggingProperties(true, 0.5, 0));
341         
342         i = CONTENT_CHEST;
343         f = &content_features(i);
344         f->param_type = CPT_FACEDIR_SIMPLE;
345         f->setAllTextures("chest_side.png");
346         f->setTexture(0, "chest_top.png");
347         f->setTexture(1, "chest_top.png");
348         f->setTexture(5, "chest_front.png"); // Z-
349         f->setInventoryTexture("chest_top.png");
350         //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
351         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
352         if(f->initial_metadata == NULL)
353                 f->initial_metadata = new ChestNodeMetadata();
354         setWoodLikeDiggingProperties(f->digging_properties, 1.0);
355         
356         i = CONTENT_FURNACE;
357         f = &content_features(i);
358         f->param_type = CPT_FACEDIR_SIMPLE;
359         f->setAllTextures("furnace_side.png");
360         f->setTexture(5, "furnace_front.png"); // Z-
361         f->setInventoryTexture("furnace_front.png");
362         //f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
363         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 6";
364         if(f->initial_metadata == NULL)
365                 f->initial_metadata = new FurnaceNodeMetadata();
366         setStoneLikeDiggingProperties(f->digging_properties, 3.0);
367         
368         i = CONTENT_COBBLE;
369         f = &content_features(i);
370         f->setAllTextures("cobble.png");
371         f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png");
372         f->param_type = CPT_NONE;
373         f->is_ground_content = true;
374         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
375         setStoneLikeDiggingProperties(f->digging_properties, 0.9);
376
377         i = CONTENT_MOSSYCOBBLE;
378         f = &content_features(i);
379         f->setAllTextures("mossycobble.png");
380         f->setInventoryTextureCube("mossycobble.png", "mossycobble.png", "mossycobble.png");
381         f->param_type = CPT_NONE;
382         f->is_ground_content = true;
383         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
384         setStoneLikeDiggingProperties(f->digging_properties, 0.8);
385         
386         i = CONTENT_STEEL;
387         f = &content_features(i);
388         f->setAllTextures("steel_block.png");
389         f->setInventoryTextureCube("steel_block.png", "steel_block.png",
390                         "steel_block.png");
391         f->param_type = CPT_NONE;
392         f->is_ground_content = true;
393         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
394         setStoneLikeDiggingProperties(f->digging_properties, 5.0);
395         
396         // NOTE: Remember to add frequently used stuff to the texture atlas in tile.cpp
397         
398
399         /*
400                 Add MesePick to everything
401         */
402         for(u16 i=0; i<256; i++)
403         {
404                 content_features(i).digging_properties.set("MesePick",
405                                 DiggingProperties(true, 0.0, 65535./1337));
406         }
407
408 }
409
410 void setStoneLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
411 {
412         list.set("",
413                         DiggingProperties(true, 15.0*toughness, 0));
414         
415         list.set("WPick",
416                         DiggingProperties(true, 1.3*toughness, 65535./30.*toughness));
417         list.set("STPick",
418                         DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
419         list.set("SteelPick",
420                         DiggingProperties(true, 0.50*toughness, 65535./333.*toughness));
421
422         /*list.set("MesePick",
423                         DiggingProperties(true, 0.0*toughness, 65535./20.*toughness));*/
424 }
425
426 void setDirtLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
427 {
428         list.set("",
429                         DiggingProperties(true, 0.75*toughness, 0));
430         
431         list.set("WShovel",
432                         DiggingProperties(true, 0.4*toughness, 65535./50.*toughness));
433         list.set("STShovel",
434                         DiggingProperties(true, 0.2*toughness, 65535./150.*toughness));
435         list.set("SteelShovel",
436                         DiggingProperties(true, 0.15*toughness, 65535./400.*toughness));
437 }
438
439 void setWoodLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
440 {
441         list.set("",
442                         DiggingProperties(true, 3.0*toughness, 0));
443         
444         list.set("WAxe",
445                         DiggingProperties(true, 1.5*toughness, 65535./30.*toughness));
446         list.set("STAxe",
447                         DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
448         list.set("SteelAxe",
449                         DiggingProperties(true, 0.5*toughness, 65535./333.*toughness));
450 }
451
452