]> git.lizzy.rs Git - minetest-m13.git/blob - src/materials.h
f242dfd2afcf28382549e01a641c20dafd56d3ab
[minetest-m13.git] / src / materials.h
1 /*
2 Minetest-m13
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 ToolDiggingProperties
76 {
77         // time = basetime + sum(feature here * feature in MaterialProperties)
78         float full_punch_interval;
79         float basetime;
80         float dt_weight;
81         float dt_crackiness;
82         float dt_crumbliness;
83         float dt_cuttability;
84         float basedurability;
85         float dd_weight;
86         float dd_crackiness;
87         float dd_crumbliness;
88         float dd_cuttability;
89
90         ToolDiggingProperties(float full_punch_interval_=2.0,
91                         float a=0.75, float b=0, float c=0, float d=0, float e=0,
92                         float f=50, float g=0, float h=0, float i=0, float j=0);
93
94         void serialize(std::ostream &os);
95         void deSerialize(std::istream &is);
96 };
97
98 struct DiggingProperties
99 {
100         bool diggable;
101         // Digging time in seconds
102         float time;
103         // Caused wear
104         u16 wear;
105
106         DiggingProperties(bool a_diggable=false, float a_time=0, u16 a_wear=0):
107                 diggable(a_diggable),
108                 time(a_time),
109                 wear(a_wear)
110         {}
111 };
112
113 DiggingProperties getDiggingProperties(const MaterialProperties *mp,
114                 const ToolDiggingProperties *tp, float time_from_last_punch);
115
116 DiggingProperties getDiggingProperties(const MaterialProperties *mp,
117                 const ToolDiggingProperties *tp);
118
119 struct HittingProperties
120 {
121         s16 hp;
122         s16 wear;
123
124         HittingProperties(s16 hp_=0, s16 wear_=0):
125                 hp(hp_),
126                 wear(wear_)
127         {}
128 };
129
130 HittingProperties getHittingProperties(const MaterialProperties *mp,
131                 const ToolDiggingProperties *tp, float time_from_last_punch);
132
133 HittingProperties getHittingProperties(const MaterialProperties *mp,
134                 const ToolDiggingProperties *tp);
135
136 #endif
137