Fix and tune things, add tool "recharge" animation, add dummyball
[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 struct ToolCapabilities
53 {
54         float full_punch_interval;
55         int max_drop_level;
56         std::map<std::string, ToolGroupCap> groupcaps;
57
58         ToolCapabilities(
59                         float full_punch_interval_=1.4,
60                         int max_drop_level_=1,
61                         std::map<std::string, ToolGroupCap> groupcaps_ =
62                                         std::map<std::string, ToolGroupCap>()
63         ):
64                 full_punch_interval(full_punch_interval_),
65                 max_drop_level(max_drop_level_),
66                 groupcaps(groupcaps_)
67         {}
68
69         void serialize(std::ostream &os) const;
70         void deSerialize(std::istream &is);
71 };
72
73 struct DigParams
74 {
75         bool diggable;
76         // Digging time in seconds
77         float time;
78         // Caused wear
79         u16 wear;
80
81         DigParams(bool a_diggable=false, float a_time=0, u16 a_wear=0):
82                 diggable(a_diggable),
83                 time(a_time),
84                 wear(a_wear)
85         {}
86 };
87
88 DigParams getDigParams(const ItemGroupList &groups,
89                 const ToolCapabilities *tp, float time_from_last_punch);
90
91 DigParams getDigParams(const ItemGroupList &groups,
92                 const ToolCapabilities *tp);
93
94 struct HitParams
95 {
96         s16 hp;
97         s16 wear;
98
99         HitParams(s16 hp_=0, s16 wear_=0):
100                 hp(hp_),
101                 wear(wear_)
102         {}
103 };
104
105 HitParams getHitParams(const ItemGroupList &groups,
106                 const ToolCapabilities *tp, float time_from_last_punch);
107
108 HitParams getHitParams(const ItemGroupList &groups,
109                 const ToolCapabilities *tp);
110
111 struct PunchDamageResult
112 {
113         bool did_punch;
114         int damage;
115         int wear;
116
117         PunchDamageResult():
118                 did_punch(false),
119                 damage(0),
120                 wear(0)
121         {}
122 };
123
124 struct ItemStack;
125
126 PunchDamageResult getPunchDamage(
127                 const ItemGroupList &armor_groups,
128                 const ToolCapabilities *toolcap,
129                 const ItemStack *punchitem,
130                 float time_from_last_punch
131 );
132
133 #endif
134