]> git.lizzy.rs Git - dragonfireclient.git/blob - src/materials.h
better debug output in segfaults and stack overflows in windows
[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         }
58
59         void setDiggingProperties(const std::string toolname,
60                         const DiggingProperties &prop)
61         {
62                 m_digging_properties[toolname] = prop;
63         }
64
65         DiggingProperties getDiggingProperties(const std::string toolname)
66         {
67                 core::map<std::string, DiggingProperties>::Node *n;
68                 n = m_digging_properties.find(toolname);
69                 if(n == NULL)
70                 {
71                         // Not diggable by this tool, try to get defaults
72                         n = m_digging_properties.find("");
73                         if(n == NULL)
74                         {
75                                 // Not diggable at all
76                                 return DiggingProperties();
77                         }
78                 }
79                 // Return found properties
80                 return n->getValue();
81         }
82
83 private:
84         // toolname="": default properties (digging by hand)
85         // Key is toolname
86         core::map<std::string, DiggingProperties> m_digging_properties;
87 };
88
89 void initializeMaterialProperties();
90
91 // Material correspond to the CONTENT_* constants
92 MaterialProperties * getMaterialProperties(u8 material);
93 // For getting the default properties, set tool=""
94 DiggingProperties getDiggingProperties(u8 material, const std::string &tool);
95
96 #endif
97