3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
22 #include "irrlichttypes.h"
25 #include "itemgroup.h"
26 #include <json/json.h>
28 struct ItemDefinition
;
32 std::unordered_map
<int, float> times
;
36 ToolGroupCap() = default;
38 bool getTime(int rating
, float *time
) const
40 std::unordered_map
<int, float>::const_iterator i
= times
.find(rating
);
41 if (i
== times
.end()) {
49 void toJson(Json::Value
&object
) const;
50 void fromJson(const Json::Value
&json
);
54 typedef std::unordered_map
<std::string
, struct ToolGroupCap
> ToolGCMap
;
55 typedef std::unordered_map
<std::string
, s16
> DamageGroup
;
57 struct ToolCapabilities
59 float full_punch_interval
;
62 DamageGroup damageGroups
;
63 int punch_attack_uses
;
66 float full_punch_interval_
= 1.4f
,
67 int max_drop_level_
= 1,
68 const ToolGCMap
&groupcaps_
= ToolGCMap(),
69 const DamageGroup
&damageGroups_
= DamageGroup(),
70 int punch_attack_uses_
= 0
72 full_punch_interval(full_punch_interval_
),
73 max_drop_level(max_drop_level_
),
74 groupcaps(groupcaps_
),
75 damageGroups(damageGroups_
),
76 punch_attack_uses(punch_attack_uses_
)
79 void serialize(std::ostream
&os
, u16 version
) const;
80 void deSerialize(std::istream
&is
);
81 void serializeJson(std::ostream
&os
) const;
82 void deserializeJson(std::istream
&is
);
88 // Digging time in seconds
92 std::string main_group
;
94 DigParams(bool a_diggable
= false, float a_time
= 0.0f
, u16 a_wear
= 0,
95 const std::string
&a_main_group
= ""):
99 main_group(a_main_group
)
103 DigParams
getDigParams(const ItemGroupList
&groups
,
104 const ToolCapabilities
*tp
);
111 HitParams(s16 hp_
= 0, u16 wear_
= 0):
117 HitParams
getHitParams(const ItemGroupList
&armor_groups
,
118 const ToolCapabilities
*tp
, float time_from_last_punch
);
120 HitParams
getHitParams(const ItemGroupList
&armor_groups
,
121 const ToolCapabilities
*tp
);
123 struct PunchDamageResult
125 bool did_punch
= false;
129 PunchDamageResult() = default;
134 PunchDamageResult
getPunchDamage(
135 const ItemGroupList
&armor_groups
,
136 const ToolCapabilities
*toolcap
,
137 const ItemStack
*punchitem
,
138 float time_from_last_punch
141 f32
getToolRange(const ItemDefinition
&def_selected
, const ItemDefinition
&def_hand
);