]> git.lizzy.rs Git - minetest.git/blob - src/tool.h
401bb1f53a16f4d0a6ef688814f8b50799ebeb57
[minetest.git] / src / tool.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 TOOL_HEADER
21 #define TOOL_HEADER
22
23 #include "common_irrlicht.h"
24 #include <string>
25 #include <iostream>
26 #include <map>
27 #include "itemgroup.h"
28
29 struct ToolGroupCap
30 {
31         std::map<int, float> times;
32         float maxwear;
33         int maxlevel;
34
35         ToolGroupCap():
36                 maxwear(0.05),
37                 maxlevel(1)
38         {}
39
40         bool getTime(int rating, float *time) const
41         {
42                 std::map<int, float>::const_iterator i = times.find(rating);
43                 if(i == times.end()){
44                         *time = 0;
45                         return false;
46                 }
47                 *time = i->second;
48                 return true;
49         }
50 };
51
52
53 // CLANG SUCKS DONKEY BALLS
54 typedef std::map<std::string, struct ToolGroupCap> ToolGCMap;
55
56 struct ToolCapabilities
57 {
58         float full_punch_interval;
59         int max_drop_level;
60         // CLANG SUCKS DONKEY BALLS
61         ToolGCMap groupcaps;
62
63         ToolCapabilities(
64                         float full_punch_interval_=1.4,
65                         int max_drop_level_=1,
66                         // CLANG SUCKS DONKEY BALLS
67                         ToolGCMap groupcaps_=ToolGCMap()
68         ):
69                 full_punch_interval(full_punch_interval_),
70                 max_drop_level(max_drop_level_),
71                 groupcaps(groupcaps_)
72         {}
73
74         void serialize(std::ostream &os) const;
75         void deSerialize(std::istream &is);
76 };
77
78 struct DigParams
79 {
80         bool diggable;
81         // Digging time in seconds
82         float time;
83         // Caused wear
84         u16 wear;
85
86         DigParams(bool a_diggable=false, float a_time=0, u16 a_wear=0):
87                 diggable(a_diggable),
88                 time(a_time),
89                 wear(a_wear)
90         {}
91 };
92
93 DigParams getDigParams(const ItemGroupList &groups,
94                 const ToolCapabilities *tp, float time_from_last_punch);
95
96 DigParams getDigParams(const ItemGroupList &groups,
97                 const ToolCapabilities *tp);
98
99 struct HitParams
100 {
101         s16 hp;
102         s16 wear;
103
104         HitParams(s16 hp_=0, s16 wear_=0):
105                 hp(hp_),
106                 wear(wear_)
107         {}
108 };
109
110 HitParams getHitParams(const ItemGroupList &groups,
111                 const ToolCapabilities *tp, float time_from_last_punch);
112
113 HitParams getHitParams(const ItemGroupList &groups,
114                 const ToolCapabilities *tp);
115
116 struct PunchDamageResult
117 {
118         bool did_punch;
119         int damage;
120         int wear;
121
122         PunchDamageResult():
123                 did_punch(false),
124                 damage(0),
125                 wear(0)
126         {}
127 };
128
129 struct ItemStack;
130
131 PunchDamageResult getPunchDamage(
132                 const ItemGroupList &armor_groups,
133                 const ToolCapabilities *toolcap,
134                 const ItemStack *punchitem,
135                 float time_from_last_punch
136 );
137
138 #endif
139