]> git.lizzy.rs Git - dragonfireclient.git/blob - src/materials.cpp
comments
[dragonfireclient.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         
15         g_material_properties[material].setDiggingProperties("WPick",
16                         DiggingProperties(true, 1.5*toughness, 65535./30.*toughness));
17         g_material_properties[material].setDiggingProperties("STPick",
18                         DiggingProperties(true, 0.7*toughness, 65535./100.*toughness));
19
20         /*g_material_properties[material].setDiggingProperties("MesePick",
21                         DiggingProperties(true, 0.0*toughness, 65535./20.*toughness));*/
22 }
23
24 void initializeMaterialProperties()
25 {
26         /*
27                 Now, the g_material_properties array is already initialized
28                 by the constructors to such that no digging is possible.
29
30                 Add some digging properties to them.
31         */
32         
33         setStoneLikeDiggingProperties(CONTENT_STONE, 1.0);
34
35         g_material_properties[CONTENT_GRASS].setDiggingProperties("",
36                         DiggingProperties(true, 0.5, 0));
37
38         g_material_properties[CONTENT_TORCH].setDiggingProperties("",
39                         DiggingProperties(true, 0.0, 0));
40
41         g_material_properties[CONTENT_TREE].setDiggingProperties("",
42                         DiggingProperties(true, 1.5, 0));
43
44         g_material_properties[CONTENT_LEAVES].setDiggingProperties("",
45                         DiggingProperties(true, 0.5, 0));
46
47         g_material_properties[CONTENT_GRASS_FOOTSTEPS].setDiggingProperties("",
48                         DiggingProperties(true, 0.5, 0));
49
50         setStoneLikeDiggingProperties(CONTENT_MESE, 0.5);
51
52         g_material_properties[CONTENT_MUD].setDiggingProperties("",
53                         DiggingProperties(true, 0.5, 0));
54
55         setStoneLikeDiggingProperties(CONTENT_COALSTONE, 1.5);
56
57         g_material_properties[CONTENT_WOOD].setDiggingProperties("",
58                         DiggingProperties(true, 1.0, 0));
59         
60         /*
61                 Add MesePick to everything
62         */
63         for(u16 i=0; i<MATERIAL_PROPERTIES_COUNT; i++)
64         {
65                 g_material_properties[i].setDiggingProperties("MesePick",
66                                 DiggingProperties(true, 0.0, 65535./1337));
67         }
68
69         g_material_properties_initialized = true;
70 }
71
72 MaterialProperties * getMaterialProperties(u8 material)
73 {
74         assert(g_material_properties_initialized);
75         return &g_material_properties[material];
76 }
77
78 DiggingProperties getDiggingProperties(u8 material, const std::string &tool)
79 {
80         MaterialProperties *mprop = getMaterialProperties(material);
81         if(mprop == NULL)
82                 // Not diggable
83                 return DiggingProperties();
84         
85         return mprop->getDiggingProperties(tool);
86 }
87