MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / anchorsValid

Method anchorsValid

source/game/StarObjectDatabase.cpp:43–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43bool ObjectOrientation::anchorsValid(World const* world, Vec2I const& position) const {
44 if (!world)
45 return false;
46
47 if (anchors.size() == 0)
48 return true;
49
50 auto materialDatabase = Root::singleton().materialDatabase();
51
52 auto anchorValid = [&](Anchor const& anchor) -> bool {
53 auto space = position + anchor.position;
54 if (!world->isTileConnectable(space, anchor.layer))
55 return false;
56 if (anchor.tilled) {
57 if (!materialDatabase->isTilledMod(world->mod(space, anchor.layer)))
58 return false;
59 }
60 if (anchor.soil) {
61 if (!materialDatabase->isSoil(world->material(space, anchor.layer)))
62 return false;
63 }
64 if (anchor.material) {
65 if (world->material(space, anchor.layer) != *anchor.material)
66 return false;
67 }
68 return true;
69 };
70
71 bool anyValid = false;
72 for (auto anchor : anchors) {
73 auto valid = anchorValid(anchor);
74 if (valid)
75 anyValid = true;
76 else if (!anchorAny)
77 return false;
78 }
79 return anyValid;
80}
81
82size_t ObjectConfig::findValidOrientation(World const* world, Vec2I const& position, Maybe<Direction> directionAffinity) const {
83 // If we are given a direction affinity, try and find an orientation with a

Callers 2

checkBrokenMethod · 0.80
findValidOrientationMethod · 0.80

Calls 8

singletonClass · 0.85
materialDatabaseMethod · 0.80
isTilledModMethod · 0.80
isSoilMethod · 0.80
sizeMethod · 0.45
isTileConnectableMethod · 0.45
modMethod · 0.45
materialMethod · 0.45

Tested by

no test coverage detected