cc2401a0d49637e043396798d7f6d7112677bb53
[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
28 struct ToolGroupCap
29 {
30         std::map<int, float> times;
31         float maxwear;
32         int maxlevel;
33
34         ToolGroupCap():
35                 maxwear(0.05),
36                 maxlevel(1)
37         {}
38
39         bool getTime(int rating, float *time) const
40         {
41                 std::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 struct ToolCapabilities
52 {
53         float full_punch_interval;
54         int max_drop_level;
55         std::map<std::string, ToolGroupCap> groupcaps;
56
57         ToolCapabilities(
58                         float full_punch_interval_=3.0,
59                         int max_drop_level_=1,
60                         std::map<std::string, ToolGroupCap> groupcaps_ =
61                                         std::map<std::string, ToolGroupCap>()
62         ):
63                 full_punch_interval(full_punch_interval_),
64                 max_drop_level(max_drop_level_),
65                 groupcaps(groupcaps_)
66         {}
67
68         void serialize(std::ostream &os) const;
69         void deSerialize(std::istream &is);
70 };
71
72 struct DigParams
73 {
74         bool diggable;
75         // Digging time in seconds
76         float time;
77         // Caused wear
78         u16 wear;
79
80         DigParams(bool a_diggable=false, float a_time=0, u16 a_wear=0):
81                 diggable(a_diggable),
82                 time(a_time),
83                 wear(a_wear)
84         {}
85 };
86
87 DigParams getDigParams(const std::map<std::string, int> &groups,
88                 const ToolCapabilities *tp, float time_from_last_punch);
89
90 DigParams getDigParams(const std::map<std::string, int> &groups,
91                 const ToolCapabilities *tp);
92
93 struct HitParams
94 {
95         s16 hp;
96         s16 wear;
97
98         HitParams(s16 hp_=0, s16 wear_=0):
99                 hp(hp_),
100                 wear(wear_)
101         {}
102 };
103
104 HitParams getHitParams(const std::map<std::string, int> &groups,
105                 const ToolCapabilities *tp, float time_from_last_punch);
106
107 HitParams getHitParams(const std::map<std::string, int> &groups,
108                 const ToolCapabilities *tp);
109
110 #endif
111