Falling sand and gravel
[oweals/minetest.git] / src / materials.h
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 #ifndef MATERIALS_HEADER
21 #define MATERIALS_HEADER
22
23 /*
24         Material properties
25 */
26
27 #include "common_irrlicht.h"
28 #include <string>
29 #include <iostream>
30
31 enum Diggability
32 {
33         DIGGABLE_NOT,
34         DIGGABLE_NORMAL,
35         DIGGABLE_CONSTANT
36 };
37
38 struct MaterialProperties
39 {
40         // Values can be anything. 0 is normal.
41         
42         enum Diggability diggability;
43
44         // Constant time for DIGGABLE_CONSTANT
45         float constant_time;
46
47         // Weight; the amount of stuff in the block. Not realistic.
48         float weight;
49         // Rock; wood a bit.
50         // A Pickaxe manages high crackiness well.
51         float crackiness;
52         // Sand is extremely crumble; dirt is quite crumble.
53         // A shovel is good for crumbly stuff. Pickaxe is horrible.
54         float crumbliness;
55         // An axe is best for cuttable heavy stuff.
56         // Sword is best for cuttable light stuff.
57         float cuttability;
58         // If high, ignites easily
59         float flammability;
60
61         MaterialProperties():
62                 diggability(DIGGABLE_NOT),
63                 constant_time(0.5),
64                 weight(0),
65                 crackiness(0),
66                 crumbliness(0),
67                 cuttability(0),
68                 flammability(0)
69         {}
70
71         void serialize(std::ostream &os);
72         void deSerialize(std::istream &is);
73 };
74
75 struct DiggingProperties
76 {
77         DiggingProperties():
78                 diggable(false),
79                 time(0.0),
80                 wear(0)
81         {
82         }
83         DiggingProperties(bool a_diggable, float a_time, u16 a_wear):
84                 diggable(a_diggable),
85                 time(a_time),
86                 wear(a_wear)
87         {
88         }
89         bool diggable;
90         // Digging time in seconds
91         float time;
92         // Caused wear
93         u16 wear;
94 };
95
96 class ToolDiggingProperties;
97 class INodeDefManager;
98
99 DiggingProperties getDiggingProperties(u16 content, ToolDiggingProperties *tp,
100                 INodeDefManager *nodemgr);
101
102 #endif
103