summaryrefslogtreecommitdiffstats
path: root/src/Generating/Prefab.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-04-17 17:31:29 +0200
committermadmaxoft <github@xoft.cz>2014-04-17 17:32:08 +0200
commitbe091800f8a39024935b9692a7dae5964979d997 (patch)
tree43f9e5ba65307ef695630d29e838d3f48daf00f6 /src/Generating/Prefab.cpp
parentMerge pull request #896 from axisd/master (diff)
downloadcuberite-be091800f8a39024935b9692a7dae5964979d997.tar
cuberite-be091800f8a39024935b9692a7dae5964979d997.tar.gz
cuberite-be091800f8a39024935b9692a7dae5964979d997.tar.bz2
cuberite-be091800f8a39024935b9692a7dae5964979d997.tar.lz
cuberite-be091800f8a39024935b9692a7dae5964979d997.tar.xz
cuberite-be091800f8a39024935b9692a7dae5964979d997.tar.zst
cuberite-be091800f8a39024935b9692a7dae5964979d997.zip
Diffstat (limited to '')
-rw-r--r--src/Generating/Prefab.cpp74
1 files changed, 73 insertions, 1 deletions
diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp
index 131b6acb2..b1964e2a0 100644
--- a/src/Generating/Prefab.cpp
+++ b/src/Generating/Prefab.cpp
@@ -105,13 +105,17 @@ cPrefab::cPrefab(const cPrefab::sDef & a_Def) :
m_Size(a_Def.m_SizeX, a_Def.m_SizeY, a_Def.m_SizeZ),
m_HitBox(0, 0, 0, a_Def.m_SizeX - 1, a_Def.m_SizeY - 1, a_Def.m_SizeZ - 1),
m_AllowedRotations(a_Def.m_AllowedRotations),
- m_MergeStrategy(a_Def.m_MergeStrategy)
+ m_MergeStrategy(a_Def.m_MergeStrategy),
+ m_ShouldExtendFloor(a_Def.m_ShouldExtendFloor),
+ m_DefaultWeight(a_Def.m_DefaultWeight),
+ m_AddWeightIfSame(a_Def.m_AddWeightIfSame)
{
m_BlockArea[0].Create(m_Size);
CharMap cm;
ParseCharMap(cm, a_Def.m_CharMap);
ParseBlockImage(cm, a_Def.m_Image);
ParseConnectors(a_Def.m_Connectors);
+ ParseDepthWeight(a_Def.m_DepthWeight);
// 1 CCW rotation:
if ((m_AllowedRotations & 0x01) != 0)
@@ -170,6 +174,26 @@ bool cPrefab::HasConnectorType(int a_ConnectorType) const
+int cPrefab::GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector) const
+{
+ // Use the default or per-depth weight:
+ cDepthWeight::const_iterator itr = m_DepthWeight.find(a_PlacedPiece.GetDepth() + 1);
+ int res = (itr == m_DepthWeight.end()) ? m_DefaultWeight : itr->second;
+
+ // If the piece is the same as the parent, apply the m_AddWeightIfSame modifier:
+ const cPiece * ParentPiece = &a_PlacedPiece.GetPiece();
+ const cPiece * ThisPiece = this;
+ if (ThisPiece == ParentPiece)
+ {
+ res += m_AddWeightIfSame;
+ }
+ return res;
+}
+
+
+
+
+
void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef)
{
ASSERT(a_CharMapDef != NULL);
@@ -277,6 +301,54 @@ void cPrefab::ParseConnectors(const char * a_ConnectorsDef)
+void cPrefab::ParseDepthWeight(const char * a_DepthWeightDef)
+{
+ // The member needn't be defined at all, if so, skip:
+ if (a_DepthWeightDef == NULL)
+ {
+ return;
+ }
+
+ // Split into individual records: "Record | Record | Record"
+ AStringVector Defs = StringSplitAndTrim(a_DepthWeightDef, "|");
+
+ // Add each record's contents:
+ for (AStringVector::const_iterator itr = Defs.begin(), end = Defs.end(); itr != end; ++itr)
+ {
+ // Split into components: "Depth : Weight"
+ AStringVector Components = StringSplitAndTrim(*itr, ":");
+ if (Components.size() != 2)
+ {
+ LOGWARNING("Bad prefab DepthWeight record: \"%s\", skipping.", itr->c_str());
+ continue;
+ }
+
+ // Parse depth:
+ int Depth = atoi(Components[0].c_str());
+ if ((Depth == 0) && (Components[0] != "0"))
+ {
+ LOGWARNING("Bad prefab DepthWeight record, cannot parse depth \"%s\", skipping.", Components[0].c_str());
+ continue;
+ }
+
+ // Parse weight:
+ int Weight = atoi(Components[1].c_str());
+ if ((Weight == 0) && (Components[1] != "0"))
+ {
+ LOGWARNING("Bad prefab DepthWeight record, cannot parse weight \"%s\", skipping.", Components[1].c_str());
+ continue;
+ }
+
+ // Save to map:
+ ASSERT(m_DepthWeight.find(Depth) == m_DepthWeight.end()); // Not a duplicate
+ m_DepthWeight[Depth] = Weight;
+ } // for itr - Defs[]
+}
+
+
+
+
+
cPiece::cConnectors cPrefab::GetConnectors(void) const
{
return m_Connectors;