]> git.lizzy.rs Git - minetest.git/blob - src/tool.h
Add minetest.register_lbm() to run code on block load only
[minetest.git] / src / tool.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser 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 "irrlichttypes.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         int maxlevel;
33         int uses;
34
35         ToolGroupCap():
36                 maxlevel(1),
37                 uses(20)
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 typedef std::map<std::string, s16> DamageGroup;
56
57 struct ToolCapabilities
58 {
59         float full_punch_interval;
60         int max_drop_level;
61         // CLANG SUCKS DONKEY BALLS
62         ToolGCMap groupcaps;
63         DamageGroup damageGroups;
64
65         ToolCapabilities(
66                         float full_punch_interval_=1.4,
67                         int max_drop_level_=1,
68                         // CLANG SUCKS DONKEY BALLS
69                         ToolGCMap groupcaps_=ToolGCMap(),
70                         DamageGroup damageGroups_=DamageGroup()
71         ):
72                 full_punch_interval(full_punch_interval_),
73                 max_drop_level(max_drop_level_),
74                 groupcaps(groupcaps_),
75                 damageGroups(damageGroups_)
76         {}
77
78         void serialize(std::ostream &os, u16 version) const;
79         void deSerialize(std::istream &is);
80 };
81
82 struct DigParams
83 {
84         bool diggable;
85         // Digging time in seconds
86         float time;
87         // Caused wear
88         u16 wear;
89         std::string main_group;
90
91         DigParams(bool a_diggable=false, float a_time=0, u16 a_wear=0,
92                         std::string a_main_group=""):
93                 diggable(a_diggable),
94                 time(a_time),
95                 wear(a_wear),
96                 main_group(a_main_group)
97         {}
98 };
99
100 DigParams getDigParams(const ItemGroupList &groups,
101                 const ToolCapabilities *tp, float time_from_last_punch);
102
103 DigParams getDigParams(const ItemGroupList &groups,
104                 const ToolCapabilities *tp);
105
106 struct HitParams
107 {
108         s16 hp;
109         s16 wear;
110
111         HitParams(s16 hp_=0, s16 wear_=0):
112                 hp(hp_),
113                 wear(wear_)
114         {}
115 };
116
117 HitParams getHitParams(const ItemGroupList &armor_groups,
118                 const ToolCapabilities *tp, float time_from_last_punch);
119
120 HitParams getHitParams(const ItemGroupList &armor_groups,
121                 const ToolCapabilities *tp);
122
123 struct PunchDamageResult
124 {
125         bool did_punch;
126         int damage;
127         int wear;
128
129         PunchDamageResult():
130                 did_punch(false),
131                 damage(0),
132                 wear(0)
133         {}
134 };
135
136 struct ItemStack;
137
138 PunchDamageResult getPunchDamage(
139                 const ItemGroupList &armor_groups,
140                 const ToolCapabilities *toolcap,
141                 const ItemStack *punchitem,
142                 float time_from_last_punch
143 );
144
145 #endif
146