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