Ejemplo n.º 1
0
bool cPrefabPiecePool::ApplyPieceMetadataCubesetVer1(
	const AString & a_FileName,
	cLuaState & a_LuaState,
	const AString & a_PieceName,
	cPrefab * a_Prefab,
	bool a_LogWarnings
)
{
	// Push the Metadata table on top of the Lua stack:
	auto md = a_LuaState.WalkToValue("Metadata");
	if (!md.IsValid())
	{
		return false;
	}

	// Get the values:
	int AddWeightIfSame = 0, DefaultWeight = 100, MoveToGround = 0, ShouldExpandFloor = 0;
	AString DepthWeight, MergeStrategy;
	a_LuaState.GetNamedValue("AddWeightIfSame",   AddWeightIfSame);
	a_LuaState.GetNamedValue("DefaultWeight",     DefaultWeight);
	a_LuaState.GetNamedValue("DepthWeight",       DepthWeight);
	a_LuaState.GetNamedValue("MergeStrategy",     MergeStrategy);
	a_LuaState.GetNamedValue("MoveToGround",      MoveToGround);
	a_LuaState.GetNamedValue("ShouldExpandFloor", ShouldExpandFloor);

	// Apply the values:
	a_Prefab->SetAddWeightIfSame(AddWeightIfSame);
	a_Prefab->SetDefaultWeight(DefaultWeight);
	a_Prefab->ParseDepthWeight(DepthWeight.c_str());
	auto msmap = GetMergeStrategyMap();
	auto strategy = msmap.find(MergeStrategy);
	if (strategy == msmap.end())
	{
		CONDWARNING(a_LogWarnings, "Unknown merge strategy (\"%s\") specified for piece %s in file %s. Using msSpongePrint instead.",
			MergeStrategy.c_str(), a_PieceName.c_str(), a_FileName.c_str()
		);
		a_Prefab->SetMergeStrategy(cBlockArea::msSpongePrint);
	}
	else
	{
		a_Prefab->SetMergeStrategy(strategy->second);
	}
	a_Prefab->SetMoveToGround(MoveToGround != 0);
	a_Prefab->SetExtendFloor(ShouldExpandFloor != 0);

	return true;
}
Ejemplo n.º 2
0
bool cPrefabPiecePool::ReadPieceMetadataCubesetVer1(
	const AString & a_FileName,
	cLuaState & a_LuaState,
	const AString & a_PieceName,
	cPrefab * a_Prefab,
	bool a_LogWarnings
)
{
	// Push the Metadata table on top of the Lua stack:
	auto md = a_LuaState.WalkToValue("Metadata");
	if (!md.IsValid())
	{
		return false;
	}

	// Get the values:
	int AddWeightIfSame = 0, DefaultWeight = 100, MoveToGround = 0;
	AString DepthWeight, MergeStrategy, VerticalLimit, VerticalStrategy;
	a_LuaState.GetNamedValue("AddWeightIfSame",  AddWeightIfSame);
	a_LuaState.GetNamedValue("DefaultWeight",    DefaultWeight);
	a_LuaState.GetNamedValue("DepthWeight",      DepthWeight);
	a_LuaState.GetNamedValue("MergeStrategy",    MergeStrategy);
	a_LuaState.GetNamedValue("MoveToGround",     MoveToGround);
	a_LuaState.GetNamedValue("VerticalLimit",    VerticalLimit);
	a_LuaState.GetNamedValue("VerticalStrategy", VerticalStrategy);

	// Apply the values:
	a_Prefab->SetAddWeightIfSame(AddWeightIfSame);
	a_Prefab->SetDefaultWeight(DefaultWeight);
	a_Prefab->ParseDepthWeight(DepthWeight.c_str());
	auto msmap = GetMergeStrategyMap();
	auto strategy = msmap.find(MergeStrategy);
	if (strategy == msmap.end())
	{
		CONDWARNING(a_LogWarnings, "Unknown merge strategy (\"%s\") specified for piece %s in file %s. Using msSpongePrint instead.",
			MergeStrategy.c_str(), a_PieceName.c_str(), a_FileName.c_str()
		);
		a_Prefab->SetMergeStrategy(cBlockArea::msSpongePrint);
	}
	else
	{
		a_Prefab->SetMergeStrategy(strategy->second);
	}
	a_Prefab->SetMoveToGround(MoveToGround != 0);

	AString ExpandFloorStrategyStr;
	if (!a_LuaState.GetNamedValue("ExpandFloorStrategy", ExpandFloorStrategyStr))
	{
		// Check the older variant for ExpandFloorStrategy, ShouldExpandFloor:
		int ShouldExpandFloor;
		if (a_LuaState.GetNamedValue("ShouldExpandFloor", ShouldExpandFloor))
		{
			LOG("Piece \"%s\" in file \"%s\" is using the old \"ShouldExpandFloor\" attribute. Use the new \"ExpandFloorStrategy\" attribute instead for more options.",
				a_PieceName.c_str(), a_FileName.c_str()
			);
			a_Prefab->SetExtendFloorStrategy((ShouldExpandFloor != 0) ? cPrefab::efsRepeatBottomTillNonAir : cPrefab::efsNone);
		}
	}
	else
	{
		auto lcExpandFloorStrategyStr = StrToLower(ExpandFloorStrategyStr);
		if (lcExpandFloorStrategyStr == "repeatbottomtillnonair")
		{
			a_Prefab->SetExtendFloorStrategy(cPrefab::efsRepeatBottomTillNonAir);
		}
		else if (lcExpandFloorStrategyStr == "repeatbottomtillsolid")
		{
			a_Prefab->SetExtendFloorStrategy(cPrefab::efsRepeatBottomTillSolid);
		}
		else
		{
			if (lcExpandFloorStrategyStr != "none")
			{
				LOGWARNING("Piece \"%s\" in file \"%s\" is using an unknown \"ExpandFloorStrategy\" attribute value: \"%s\"",
					a_PieceName.c_str(), a_FileName.c_str(), ExpandFloorStrategyStr.c_str()
				);
			}
			a_Prefab->SetExtendFloorStrategy(cPrefab::efsNone);
		}
	}
	if (!VerticalLimit.empty())
	{
		if (!a_Prefab->SetVerticalLimitFromString(VerticalLimit, a_LogWarnings))
		{
			CONDWARNING(a_LogWarnings, "Unknown VerticalLimit (\"%s\") specified for piece %s in file %s. Using no limit instead.",
				VerticalLimit.c_str(), a_PieceName.c_str(), a_FileName.c_str()
			);
		}
	}
	a_Prefab->SetVerticalStrategyFromString(VerticalStrategy, a_LogWarnings);

	return true;
}