]> git.lizzy.rs Git - dragonfireclient.git/blob - src/materials.h
minecraft-like crafting
[dragonfireclient.git] / src / materials.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 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 #ifndef MATERIALS_HEADER
21 #define MATERIALS_HEADER
22
23 /*
24         Material properties
25 */
26
27 #include "common_irrlicht.h"
28 #include "inventory.h"
29 #include <string>
30
31 struct DiggingProperties
32 {
33         DiggingProperties():
34                 diggable(false),
35                 time(0.0),
36                 wear(0)
37         {
38         }
39         DiggingProperties(bool a_diggable, float a_time, u16 a_wear):
40                 diggable(a_diggable),
41                 time(a_time),
42                 wear(a_wear)
43         {
44         }
45         bool diggable;
46         // Digging time in seconds
47         float time;
48         // Caused wear
49         u16 wear;
50 };
51
52 class MaterialProperties
53 {
54 public:
55         MaterialProperties()
56         {
57                 dstream<<__FUNCTION_NAME<<std::endl;
58         }
59
60         void setDiggingProperties(const std::string toolname,
61                         const DiggingProperties &prop)
62         {
63                 m_digging_properties[toolname] = prop;
64         }
65
66         DiggingProperties getDiggingProperties(const std::string toolname)
67         {
68                 core::map<std::string, DiggingProperties>::Node *n;
69                 n = m_digging_properties.find(toolname);
70                 if(n == NULL)
71                 {
72                         // Not diggable by this tool, try to get defaults
73                         n = m_digging_properties.find("");
74                         if(n == NULL)
75                         {
76                                 // Not diggable at all
77                                 return DiggingProperties();
78                         }
79                 }
80                 // Return found properties
81                 return n->getValue();
82         }
83
84 private:
85         // toolname="": default properties (digging by hand)
86         // Key is toolname
87         core::map<std::string, DiggingProperties> m_digging_properties;
88 };
89
90 void initializeMaterialProperties();
91
92 // Material correspond to the CONTENT_* constants
93 MaterialProperties * getMaterialProperties(u8 material);
94 // For getting the default properties, set tool=""
95 DiggingProperties getDiggingProperties(u8 material, const std::string &tool);
96
97 #endif
98