-#include "materials.h"
-#include "mapnode.h"
-#include "mapnode_contentfeatures.h"
-
+/*
+Minetest-c55
+Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
-struct ToolProperties
-{
- // time = basetime + sum(feature here * feature in MaterialProperties)
- float basetime;
- float dt_weight;
- float dt_crackiness;
- float dt_crumbliness;
- float dt_cuttability;
- float basedurability;
- float dd_weight;
- float dd_crackiness;
- float dd_crumbliness;
- float dd_cuttability;
-
- ToolProperties(float a=0.75, float b=0, float c=0, float d=0, float e=0,
- float f=50, float g=0, float h=0, float i=0, float j=0):
- basetime(a),
- dt_weight(b),
- dt_crackiness(c),
- dt_crumbliness(d),
- dt_cuttability(e),
- basedurability(f),
- dd_weight(g),
- dd_crackiness(h),
- dd_crumbliness(i),
- dd_cuttability(j)
- {}
-};
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
-ToolProperties getToolProperties(const std::string &toolname)
-{
- // weight, crackiness, crumbleness, cuttability
- if(toolname == "WPick")
- return ToolProperties(2.0, 0,-1,2,0, 50, 0,0,0,0);
- else if(toolname == "STPick")
- return ToolProperties(1.5, 0,-1,2,0, 100, 0,0,0,0);
- else if(toolname == "SteelPick")
- return ToolProperties(1.0, 0,-1,2,0, 300, 0,0,0,0);
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
- else if(toolname == "MesePick")
- return ToolProperties(0, 0,0,0,0, 1337, 0,0,0,0);
-
- else if(toolname == "WShovel")
- return ToolProperties(1.5, 0.5,2,-1.5,0.3, 50, 0,0,0,0);
- else if(toolname == "STShovel")
- return ToolProperties(1.0, 0.5,2,-1.5,0.1, 100, 0,0,0,0);
- else if(toolname == "SteelShovel")
- return ToolProperties(0.6, 0.5,2,-1.5,0.0, 300, 0,0,0,0);
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
- // weight, crackiness, crumbleness, cuttability
- else if(toolname == "WAxe")
- return ToolProperties(2.0, 0.5,-0.2,1,-0.5, 50, 0,0,0,0);
- else if(toolname == "STAxe")
- return ToolProperties(1.5, 0.5,-0.2,1,-0.5, 100, 0,0,0,0);
- else if(toolname == "SteelAxe")
- return ToolProperties(1.0, 0.5,-0.2,1,-0.5, 300, 0,0,0,0);
+#include "materials.h"
+#include "mapnode.h"
+#include "nodedef.h"
+#include "tooldef.h"
+#include "utility.h"
- else if(toolname == "WSword")
- return ToolProperties(3.0, 3,0,1,-1, 50, 0,0,0,0);
- else if(toolname == "STSword")
- return ToolProperties(2.5, 3,0,1,-1, 100, 0,0,0,0);
- else if(toolname == "SteelSword")
- return ToolProperties(2.0, 3,0,1,-1, 300, 0,0,0,0);
+void MaterialProperties::serialize(std::ostream &os)
+{
+ writeU8(os, 0); // version
+ writeU8(os, diggability);
+ writeF1000(os, weight);
+ writeF1000(os, crackiness);
+ writeF1000(os, crumbliness);
+ writeF1000(os, cuttability);
+}
- // Properties of hand
- return ToolProperties(0.5, 1,0.4,-0.75,0, 50, 0,0,0,0);
+void MaterialProperties::deSerialize(std::istream &is)
+{
+ int version = readU8(is);
+ if(version != 0)
+ throw SerializationError("unsupported MaterialProperties version");
+ diggability = (enum Diggability)readU8(is);
+ weight = readF1000(is);
+ crackiness = readF1000(is);
+ crumbliness = readF1000(is);
+ cuttability = readF1000(is);
}
-DiggingProperties getDiggingProperties(u16 material, const std::string &tool)
+DiggingProperties getDiggingProperties(u16 content, ToolDiggingProperties *tp,
+ INodeDefManager *nodemgr)
{
- MaterialProperties &mp = content_features(material).material;
+ assert(tp);
+ const MaterialProperties &mp = nodemgr->get(content).material;
if(mp.diggability == DIGGABLE_NOT)
return DiggingProperties(false, 0, 0);
if(mp.diggability == DIGGABLE_CONSTANT)
return DiggingProperties(true, mp.constant_time, 0);
- ToolProperties tp = getToolProperties(tool);
-
- float time = tp.basetime;
- time += tp.dt_weight * mp.weight;
- time += tp.dt_crackiness * mp.crackiness;
- time += tp.dt_crumbliness * mp.crumbliness;
- time += tp.dt_cuttability * mp.cuttability;
+ float time = tp->basetime;
+ time += tp->dt_weight * mp.weight;
+ time += tp->dt_crackiness * mp.crackiness;
+ time += tp->dt_crumbliness * mp.crumbliness;
+ time += tp->dt_cuttability * mp.cuttability;
if(time < 0.2)
time = 0.2;
- float durability = tp.basedurability;
- durability += tp.dd_weight * mp.weight;
- durability += tp.dd_crackiness * mp.crackiness;
- durability += tp.dd_crumbliness * mp.crumbliness;
- durability += tp.dd_cuttability * mp.cuttability;
+ float durability = tp->basedurability;
+ durability += tp->dd_weight * mp.weight;
+ durability += tp->dd_crackiness * mp.crackiness;
+ durability += tp->dd_crumbliness * mp.crumbliness;
+ durability += tp->dd_cuttability * mp.cuttability;
if(durability < 1)
durability = 1;