Digging and placing sounds
[oweals/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         std::string main_group;
86
87         DigParams(bool a_diggable=false, float a_time=0, u16 a_wear=0,
88                         std::string a_main_group=""):
89                 diggable(a_diggable),
90                 time(a_time),
91                 wear(a_wear),
92                 main_group(a_main_group)
93         {}
94 };
95
96 DigParams getDigParams(const ItemGroupList &groups,
97                 const ToolCapabilities *tp, float time_from_last_punch);
98
99 DigParams getDigParams(const ItemGroupList &groups,
100                 const ToolCapabilities *tp);
101
102 struct HitParams
103 {
104         s16 hp;
105         s16 wear;
106         std::string main_group;
107
108         HitParams(s16 hp_=0, s16 wear_=0, std::string main_group_=""):
109                 hp(hp_),
110                 wear(wear_),
111                 main_group(main_group_)
112         {}
113 };
114
115 HitParams getHitParams(const ItemGroupList &groups,
116                 const ToolCapabilities *tp, float time_from_last_punch);
117
118 HitParams getHitParams(const ItemGroupList &groups,
119                 const ToolCapabilities *tp);
120
121 struct PunchDamageResult
122 {
123         bool did_punch;
124         int damage;
125         int wear;
126         std::string main_group;
127
128         PunchDamageResult():
129                 did_punch(false),
130                 damage(0),
131                 wear(0)
132         {}
133 };
134
135 struct ItemStack;
136
137 PunchDamageResult getPunchDamage(
138                 const ItemGroupList &armor_groups,
139                 const ToolCapabilities *toolcap,
140                 const ItemStack *punchitem,
141                 float time_from_last_punch
142 );
143
144 #endif
145