new digging properties calculation

This commit is contained in:
darkrose 2014-01-18 23:32:17 +10:00
parent 183da97b52
commit 257a9e5ed4
8 changed files with 646 additions and 385 deletions

File diff suppressed because it is too large Load Diff

View File

@ -59,6 +59,8 @@ void content_toolitem_init()
f->name = "WPick";
f->description = "Wooden Pick";
f->type = TT_PICK;
f->hardness = 30.;
f->dig_time = 1.5;
crafting::setPickRecipe(CONTENT_WOOD,CONTENT_TOOLITEM_WPICK);
crafting::setPickRecipe(CONTENT_JUNGLEWOOD,CONTENT_TOOLITEM_WPICK);
@ -69,6 +71,8 @@ void content_toolitem_init()
f->name = "STPick";
f->description = "Stone Pick";
f->type = TT_PICK;
f->hardness = 100.;
f->dig_time = 0.75;
crafting::setPickRecipe(CONTENT_ROUGHSTONE,CONTENT_TOOLITEM_STPICK);
i = CONTENT_TOOLITEM_STEELPICK;
@ -78,6 +82,8 @@ void content_toolitem_init()
f->name = "SteelPick";
f->description = "Steel Pick";
f->type = TT_PICK;
f->hardness = 333.;
f->dig_time = 0.5;
crafting::setPickRecipe(CONTENT_CRAFTITEM_STEEL_INGOT,CONTENT_TOOLITEM_STEELPICK);
i = CONTENT_TOOLITEM_MESEPICK;
@ -87,6 +93,8 @@ void content_toolitem_init()
f->name = "MesePick";
f->description = "Mese Pick";
f->type = TT_PICK;
f->hardness = 1337.;
f->dig_time = 0.;
crafting::setPickRecipe(CONTENT_MESE,CONTENT_TOOLITEM_MESEPICK);
i = CONTENT_TOOLITEM_WSHOVEL;
@ -96,6 +104,8 @@ void content_toolitem_init()
f->name = "WShovel";
f->description = "Wooden Shovel";
f->type = TT_SHOVEL;
f->hardness = 50.;
f->dig_time = 0.4;
crafting::setShovelRecipe(CONTENT_WOOD,CONTENT_TOOLITEM_WSHOVEL);
crafting::setShovelRecipe(CONTENT_JUNGLEWOOD,CONTENT_TOOLITEM_WSHOVEL);
@ -106,6 +116,8 @@ void content_toolitem_init()
f->name = "STShovel";
f->description = "Stone Shovel";
f->type = TT_SHOVEL;
f->hardness = 150.;
f->dig_time = 0.2;
crafting::setShovelRecipe(CONTENT_ROUGHSTONE,CONTENT_TOOLITEM_STSHOVEL);
i = CONTENT_TOOLITEM_STEELSHOVEL;
@ -115,6 +127,8 @@ void content_toolitem_init()
f->name = "SteelShovel";
f->description = "Steel Shovel";
f->type = TT_SHOVEL;
f->hardness = 400.;
f->dig_time = 0.15;
crafting::setShovelRecipe(CONTENT_CRAFTITEM_STEEL_INGOT,CONTENT_TOOLITEM_STEELSHOVEL);
i = CONTENT_TOOLITEM_WAXE;
@ -124,6 +138,8 @@ void content_toolitem_init()
f->name = "WAxe";
f->description = "Wooden Axe";
f->type = TT_AXE;
f->hardness = 30.;
f->dig_time = 1.5;
crafting::setAxeRecipe(CONTENT_WOOD,CONTENT_TOOLITEM_WAXE);
crafting::setAxeRecipe(CONTENT_JUNGLEWOOD,CONTENT_TOOLITEM_WAXE);
@ -134,6 +150,8 @@ void content_toolitem_init()
f->name = "STAxe";
f->description = "Stone Axe";
f->type = TT_AXE;
f->hardness = 100.;
f->dig_time = 0.75;
crafting::setAxeRecipe(CONTENT_ROUGHSTONE,CONTENT_TOOLITEM_STAXE);
i = CONTENT_TOOLITEM_STEELAXE;
@ -143,6 +161,8 @@ void content_toolitem_init()
f->name = "SteelAxe";
f->description = "Steel Axe";
f->type = TT_AXE;
f->hardness = 333.;
f->dig_time = 0.5;
crafting::setAxeRecipe(CONTENT_CRAFTITEM_STEEL_INGOT,CONTENT_TOOLITEM_STEELAXE);
i = CONTENT_TOOLITEM_WSWORD;
@ -152,6 +172,8 @@ void content_toolitem_init()
f->name = "WSword";
f->description = "Wooden Sword";
f->type = TT_SWORD;
f->hardness = 20.;
f->dig_time = 1.5;
crafting::setSwordRecipe(CONTENT_WOOD,CONTENT_TOOLITEM_WSWORD);
crafting::setSwordRecipe(CONTENT_JUNGLEWOOD,CONTENT_TOOLITEM_WSWORD);
@ -162,6 +184,8 @@ void content_toolitem_init()
f->name = "STSword";
f->description = "Stone Sword";
f->type = TT_SWORD;
f->hardness = 50.;
f->dig_time = 1.0;
crafting::setSwordRecipe(CONTENT_ROUGHSTONE,CONTENT_TOOLITEM_STSWORD);
i = CONTENT_TOOLITEM_STEELSWORD;
@ -171,6 +195,8 @@ void content_toolitem_init()
f->name = "SteelSword";
f->description = "Steel Sword";
f->type = TT_SWORD;
f->hardness = 80.;
f->dig_time = 0.5;
crafting::setSwordRecipe(CONTENT_CRAFTITEM_STEEL_INGOT,CONTENT_TOOLITEM_STEELSWORD);
i = CONTENT_TOOLITEM_STEELSHEARS;
@ -180,6 +206,8 @@ void content_toolitem_init()
f->name = "Shears";
f->description = "Steel Shears";
f->type = TT_SHEAR;
f->hardness = 333.;
f->dig_time = 0.5;
crafting::setShearsRecipe(CONTENT_CRAFTITEM_STEEL_INGOT,CONTENT_TOOLITEM_STEELSHEARS);
i = CONTENT_TOOLITEM_WBUCKET;
@ -190,6 +218,8 @@ void content_toolitem_init()
f->description = "Wooden Bucket";
f->liquids_pointable = true;
f->type = TT_BUCKET;
f->hardness = 30.;
f->dig_time = 0.0;
crafting::setURecipe(CONTENT_CRAFTITEM_STICK,CONTENT_TOOLITEM_WBUCKET);
i = CONTENT_TOOLITEM_TINBUCKET;
@ -200,6 +230,8 @@ void content_toolitem_init()
f->description = "Tin Bucket";
f->liquids_pointable = true;
f->type = TT_BUCKET;
f->hardness = 50.;
f->dig_time = 0.0;
crafting::setURecipe(CONTENT_CRAFTITEM_TIN_INGOT,CONTENT_TOOLITEM_TINBUCKET);
i = CONTENT_TOOLITEM_WBUCKET_WATER;
@ -226,6 +258,8 @@ void content_toolitem_init()
f->description = "Steel Bucket";
f->liquids_pointable = true;
f->type = TT_BUCKET;
f->hardness = 80.;
f->dig_time = 0.0;
crafting::setURecipe(CONTENT_CRAFTITEM_STEEL_INGOT,CONTENT_TOOLITEM_STEELBUCKET);
i = CONTENT_TOOLITEM_STEELBUCKET_WATER;

View File

@ -35,6 +35,10 @@ struct ToolItemFeatures {
bool liquids_pointable;
// the type of this tool
ToolType type;
// the hardness of this tool
f32 hardness;
// the dig time of this tool
f32 dig_time;
ToolItemFeatures():
content(CONTENT_IGNORE),
@ -46,7 +50,9 @@ struct ToolItemFeatures {
edible(0),
drop_count(-1),
liquids_pointable(false),
type(TT_NONE)
type(TT_NONE),
hardness(0.),
dig_time(3.)
{}
};

View File

@ -1720,7 +1720,6 @@ void the_game(
MapNode n = client.getNode(nodepos);
// Get tool name. Default is "" = bare hands
std::string toolname = "";
content_t toolid = CONTENT_IGNORE;
InventoryList *mlist = local_inventory.getList("main");
if(mlist != NULL)
@ -1729,21 +1728,17 @@ void the_game(
if(item && (std::string)item->getName() == "ToolItem")
{
ToolItem *titem = (ToolItem*)item;
toolname = titem->getToolName();
toolid = titem->getContent();
}
}
// Get digging properties for material and tool
content_t material = n.getContent();
DiggingProperties prop = getDiggingProperties(material, toolname);
DiggingProperties prop = getDiggingProperties(material, toolid);
float dig_time_complete = 0.0;
if (
prop.diggable == false
|| content_toolitem_features(toolid).type == TT_SPECIAL
) {
if (prop.diggable == false) {
dig_time_complete = 10000000.0;
client.clearTempMod(nodepos);
}else{

View File

@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "light.h"
#include "exceptions.h"
#include "serialization.h"
#include "materials.h"
#ifndef SERVER
#include "tile.h"
#endif
@ -42,6 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
typedef u16 content_t;
#define MAX_CONTENT 0xfff
#include "materials.h"
/*
Initializes all kind of stuff in here.
@ -121,6 +121,18 @@ enum LiquidType
LIQUID_SOURCE
};
/*
Material Type
*/
enum ContentMaterialType {
CMT_AIR,
CMT_WOOD,
CMT_STONE,
CMT_LIQUID,
CMT_PLANT,
CMT_DIRT
};
struct MapNode;
class NodeMetadata;
@ -231,8 +243,10 @@ struct ContentFeatures
// Amount of light the node emits
u8 light_source;
// Digging properties for different tools
DiggingPropertiesList digging_properties;
// the material type (stone, wood, etc)
ContentMaterialType type;
// the hardness of the node
f32 hardness;
u32 damage_per_second;
@ -292,7 +306,8 @@ struct ContentFeatures
liquid_alternative_source = CONTENT_IGNORE;
liquid_viscosity = 0;
light_source = 0;
digging_properties.clear();
type = CMT_AIR;
hardness = 1.0;
damage_per_second = 0;
}

View File

@ -1,20 +1,51 @@
#include "materials.h"
#include "mapnode.h"
#include "content_toolitem.h"
// NOTE: DEPRECATED
DiggingPropertiesList * getDiggingPropertiesList(u16 content)
DiggingProperties getDiggingProperties(content_t content, content_t tool)
{
return &content_features(content).digging_properties;
}
DiggingProperties getDiggingProperties(u16 content, const std::string &tool)
{
DiggingPropertiesList *mprop = getDiggingPropertiesList(content);
if(mprop == NULL)
// Not diggable
return DiggingProperties();
return mprop->get(tool);
ToolItemFeatures t_features = content_toolitem_features(tool);
ContentFeatures &c_features = content_features(content);
f32 time = t_features.dig_time*c_features.hardness;
f32 wear = 0;
if (t_features.hardness && c_features.hardness)
wear = 65535/t_features.hardness*c_features.hardness;
f32 diggable = true;
if (c_features.type == CMT_STONE && t_features.type != TT_PICK) {
diggable = false;
}else{
switch (t_features.type) {
case TT_SPECIAL:
diggable = false;
break;
case TT_AXE:
if (c_features.type != CMT_WOOD && c_features.type != CMT_PLANT)
time *= 10.;
break;
case TT_PICK:
if (c_features.type != CMT_STONE)
time *= 2.;
break;
case TT_SHOVEL:
if (c_features.type != CMT_DIRT)
time *= 10.;
break;
case TT_SWORD:
case TT_SHEAR:
if (c_features.type != CMT_PLANT)
time *= 10.;
break;
case TT_BUCKET:
if (c_features.type != CMT_LIQUID)
time = 10.;
break;
case TT_NONE:
default:
break;
}
}
return DiggingProperties(diggable,time,wear);
}

View File

@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common_irrlicht.h"
#include <string>
#include "mapnode.h"
struct DiggingProperties
{
@ -96,8 +97,8 @@ private:
core::map<std::string, DiggingProperties> m_digging_properties;
};
// For getting the default properties, set tool=""
DiggingProperties getDiggingProperties(u16 material, const std::string &tool);
// For getting the default properties, set tool=CONTENT_IGNORE
DiggingProperties getDiggingProperties(content_t material, content_t toolid);
#endif

View File

@ -3043,14 +3043,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if(item && (std::string)item->getName() == "ToolItem")
{
ToolItem *titem = (ToolItem*)item;
std::string toolname = titem->getToolName();
// Get digging properties for material and tool
DiggingProperties prop =
getDiggingProperties(material, toolname);
DiggingProperties prop = getDiggingProperties(material, titem->getContent());
if(prop.diggable == false)
{
if (prop.diggable == false) {
infostream<<"Server: WARNING: Player digged"
<<" with impossible material + tool"
<<" combination"<<std::endl;
@ -3059,9 +3055,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
bool weared_out = titem->addWear(prop.wear);
if(weared_out)
{
mlist->deleteItem(item_i);
}
}
}