]> git.lizzy.rs Git - dragonfireclient.git/blob - src/tool.h
C++11 patchset 2: remove util/cpp11.h and util/cpp11_container.h (#5821)
[dragonfireclient.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 "itemgroup.h"
27
28 struct ToolGroupCap
29 {
30         std::unordered_map<int, float> times;
31         int maxlevel;
32         int uses;
33
34         ToolGroupCap():
35                 maxlevel(1),
36                 uses(20)
37         {}
38
39         bool getTime(int rating, float *time) const
40         {
41                 std::unordered_map<int, float>::const_iterator i = times.find(rating);
42                 if (i == times.end()) {
43                         *time = 0;
44                         return false;
45                 }
46                 *time = i->second;
47                 return true;
48         }
49 };
50
51
52 typedef std::unordered_map<std::string, struct ToolGroupCap> ToolGCMap;
53 typedef std::unordered_map<std::string, s16> DamageGroup;
54
55 struct ToolCapabilities
56 {
57         float full_punch_interval;
58         int max_drop_level;
59         ToolGCMap groupcaps;
60         DamageGroup damageGroups;
61
62         ToolCapabilities(
63                         float full_punch_interval_=1.4,
64                         int max_drop_level_=1,
65                         const ToolGCMap &groupcaps_ = ToolGCMap(),
66                         const DamageGroup &damageGroups_ = DamageGroup()
67         ):
68                 full_punch_interval(full_punch_interval_),
69                 max_drop_level(max_drop_level_),
70                 groupcaps(groupcaps_),
71                 damageGroups(damageGroups_)
72         {}
73
74         void serialize(std::ostream &os, u16 version) 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.0f, u16 a_wear = 0,
88                         const 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
107         HitParams(s16 hp_=0, s16 wear_=0):
108                 hp(hp_),
109                 wear(wear_)
110         {}
111 };
112
113 HitParams getHitParams(const ItemGroupList &armor_groups,
114                 const ToolCapabilities *tp, float time_from_last_punch);
115
116 HitParams getHitParams(const ItemGroupList &armor_groups,
117                 const ToolCapabilities *tp);
118
119 struct PunchDamageResult
120 {
121         bool did_punch;
122         int damage;
123         int wear;
124
125         PunchDamageResult():
126                 did_punch(false),
127                 damage(0),
128                 wear(0)
129         {}
130 };
131
132 struct ItemStack;
133
134 PunchDamageResult getPunchDamage(
135                 const ItemGroupList &armor_groups,
136                 const ToolCapabilities *toolcap,
137                 const ItemStack *punchitem,
138                 float time_from_last_punch
139 );
140
141 #endif
142