2010-12-24 18:54:39 -05:00
|
|
|
#include "materials.h"
|
2011-06-17 15:20:15 -04:00
|
|
|
#include "mapnode.h"
|
2011-11-14 14:41:30 -05:00
|
|
|
#include "nodedef.h"
|
|
|
|
#include "tooldef.h"
|
2010-12-24 18:54:39 -05:00
|
|
|
|
2011-11-14 14:41:30 -05:00
|
|
|
DiggingProperties getDiggingProperties(u16 content, ToolDiggingProperties *tp,
|
|
|
|
INodeDefManager *nodemgr)
|
2010-12-24 18:54:39 -05:00
|
|
|
{
|
2011-11-13 17:19:48 -05:00
|
|
|
assert(tp);
|
2011-11-14 14:41:30 -05:00
|
|
|
const MaterialProperties &mp = nodemgr->get(content).material;
|
2011-11-13 08:45:38 -05:00
|
|
|
if(mp.diggability == DIGGABLE_NOT)
|
|
|
|
return DiggingProperties(false, 0, 0);
|
|
|
|
if(mp.diggability == DIGGABLE_CONSTANT)
|
|
|
|
return DiggingProperties(true, mp.constant_time, 0);
|
|
|
|
|
2011-11-13 17:19:48 -05:00
|
|
|
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;
|
2011-11-13 08:45:38 -05:00
|
|
|
if(time < 0.2)
|
|
|
|
time = 0.2;
|
|
|
|
|
2011-11-13 17:19:48 -05:00
|
|
|
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;
|
2011-11-13 08:45:38 -05:00
|
|
|
if(durability < 1)
|
|
|
|
durability = 1;
|
|
|
|
|
|
|
|
float wear = 1.0 / durability;
|
|
|
|
u16 wear_i = wear/65535.;
|
|
|
|
return DiggingProperties(true, time, wear_i);
|
2010-12-24 18:54:39 -05:00
|
|
|
}
|
|
|
|
|