]> git.lizzy.rs Git - minetest.git/blob - src/materials.cpp
minecraft-like crafting
[minetest.git] / src / materials.cpp
1 #include "materials.h"
2
3 #define MATERIAL_PROPERTIES_COUNT 256
4
5 // These correspond to the CONTENT_* constants
6 MaterialProperties g_material_properties[MATERIAL_PROPERTIES_COUNT];
7
8 bool g_material_properties_initialized = false;
9
10 void setStoneLikeDiggingProperties(u8 material, float toughness)
11 {
12         g_material_properties[material].setDiggingProperties("",
13                         DiggingProperties(true, 15.0*toughness, 0));
14         g_material_properties[material].setDiggingProperties("WPick",
15                         DiggingProperties(true, 2.0*toughness, 65535./20.*toughness));
16         g_material_properties[material].setDiggingProperties("STPick",
17                         DiggingProperties(true, 1.0*toughness, 65535./50.*toughness));
18 }
19
20 void initializeMaterialProperties()
21 {
22         /*
23                 Now, the g_material_properties array is already initialized
24                 by the constructors to such that no digging is possible.
25
26                 Add some digging properties to them.
27         */
28         
29         setStoneLikeDiggingProperties(CONTENT_STONE, 1.0);
30
31         g_material_properties[CONTENT_GRASS].setDiggingProperties("",
32                         DiggingProperties(true, 0.5, 0));
33
34         g_material_properties[CONTENT_TORCH].setDiggingProperties("",
35                         DiggingProperties(true, 0.0, 0));
36
37         g_material_properties[CONTENT_TREE].setDiggingProperties("",
38                         DiggingProperties(true, 1.5, 0));
39
40         g_material_properties[CONTENT_LEAVES].setDiggingProperties("",
41                         DiggingProperties(true, 0.5, 0));
42
43         g_material_properties[CONTENT_GRASS_FOOTSTEPS].setDiggingProperties("",
44                         DiggingProperties(true, 0.5, 0));
45
46         setStoneLikeDiggingProperties(CONTENT_MESE, 0.5);
47
48         g_material_properties[CONTENT_MUD].setDiggingProperties("",
49                         DiggingProperties(true, 0.5, 0));
50
51         setStoneLikeDiggingProperties(CONTENT_COALSTONE, 1.5);
52
53         g_material_properties[CONTENT_WOOD].setDiggingProperties("",
54                         DiggingProperties(true, 1.0, 0));
55
56
57         g_material_properties_initialized = true;
58 }
59
60 MaterialProperties * getMaterialProperties(u8 material)
61 {
62         assert(g_material_properties_initialized);
63         return &g_material_properties[material];
64 }
65
66 DiggingProperties getDiggingProperties(u8 material, const std::string &tool)
67 {
68         MaterialProperties *mprop = getMaterialProperties(material);
69         if(mprop == NULL)
70                 // Not diggable
71                 return DiggingProperties();
72         
73         return mprop->getDiggingProperties(tool);
74 }
75