aboutsummaryrefslogtreecommitdiff
path: root/src/materials.cpp
blob: d89b1e07950aced430c3cff2730f15dfdac422dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "materials.h"
#include "mapnode.h"
#include "nodedef.h"
#include "tooldef.h"

DiggingProperties getDiggingProperties(u16 content, ToolDiggingProperties *tp,
		INodeDefManager *nodemgr)
{
	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);

	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;
	if(durability < 1)
		durability = 1;

	float wear = 1.0 / durability;
	u16 wear_i = wear/65535.;
	return DiggingProperties(true, time, wear_i);
}