|
@@ -87,9 +87,9 @@ namespace KairoEngine.VoxelBuildingSystem
|
|
|
Vector3Int buildingPos = GetMouseBuildingPosition();
|
|
|
Vector3Int voxelPos = GetMouseVoxelPosition();
|
|
|
Vector3Int buildingRotation = rotationList[currentRotationIndex];
|
|
|
- if(!CanPlaceBuilding(voxelPos, currentBuildingTemplate, currentRotationIndex, true)) return;
|
|
|
+ if(!CanPlaceBuilding(buildingPos, currentBuildingTemplate, currentRotationIndex, true)) return;
|
|
|
Quaternion rotation = Quaternion.Euler(buildingRotation.x, buildingRotation.y, buildingRotation.z);
|
|
|
- Transform newBuilding = Instantiate(buildingTemplates[currentBuildingTemplate].prefab, voxelPos, rotation, this.transform);
|
|
|
+ Transform newBuilding = Instantiate(buildingTemplates[currentBuildingTemplate].prefab, buildingPos, rotation, this.transform);
|
|
|
BuildingBehaviour buildingBehaviour = newBuilding.GetComponent<BuildingBehaviour>();
|
|
|
if(buildingBehaviour == null)
|
|
|
{
|
|
@@ -97,10 +97,10 @@ namespace KairoEngine.VoxelBuildingSystem
|
|
|
Destroy(newBuilding);
|
|
|
return;
|
|
|
}
|
|
|
- buildingBehaviour.origin = voxelPos;
|
|
|
- buildings.Add(voxelPos, buildingBehaviour);
|
|
|
+ buildingBehaviour.origin = buildingPos;
|
|
|
+ buildings.Add(buildingPos, buildingBehaviour);
|
|
|
buildingList.Add(buildingBehaviour);
|
|
|
- List<Vector3Int> voxelPositions = GetBuildingVoxelList(voxelPos, currentBuildingTemplate, currentRotationIndex);
|
|
|
+ List<Vector3Int> voxelPositions = GetBuildingVoxelList(buildingPos, currentBuildingTemplate, currentRotationIndex);
|
|
|
for (int i = 0; i < voxelPositions.Count; i++)
|
|
|
{
|
|
|
VoxelBuildData block = chunkSystem.GetBlock(voxelPositions[i]);
|
|
@@ -127,17 +127,7 @@ namespace KairoEngine.VoxelBuildingSystem
|
|
|
|
|
|
public bool CanPlaceBuilding(Vector3Int voxelPos, int buildingTemplateIndex, int buildingRotationIndex = 0, bool debug = false)
|
|
|
{
|
|
|
- List<Vector3Int> voxelPositions = GetBuildingVoxelList(voxelPos, buildingTemplateIndex, buildingRotationIndex);
|
|
|
- for (int i = 0; i < voxelPositions.Count; i++)
|
|
|
- {
|
|
|
- VoxelBuildData block = chunkSystem.GetBlock(voxelPositions[i]);
|
|
|
- if(block.buildingIndex != -1)
|
|
|
- {
|
|
|
- if(debug) Debug.Log("Cannot place building, place is occupied.");
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
+ return EvaluateRuleset(voxelPos, buildingRotationIndex, buildingTemplateIndex);
|
|
|
}
|
|
|
|
|
|
public Vector3Int FindVoxelPosition(Vector3 pos)
|
|
@@ -152,7 +142,7 @@ namespace KairoEngine.VoxelBuildingSystem
|
|
|
{
|
|
|
Vector3Int voxelPos = FindVoxelPosition(pointerPosition);
|
|
|
Vector3Int rotationOffset = GetRotationOffset(currentRotationIndex, buildingTemplates[currentBuildingTemplate].size);
|
|
|
- return voxelPos + rotationOffset;
|
|
|
+ return voxelPos - rotationOffset;
|
|
|
}
|
|
|
|
|
|
public List<Vector3Int> GetBuildingVoxelList(Vector3Int offset, int buildingTemplateId, int buildingRotationIndex = 0)
|
|
@@ -308,6 +298,35 @@ namespace KairoEngine.VoxelBuildingSystem
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
+ #region Rules
|
|
|
+
|
|
|
+ public bool EvaluateRuleset(Vector3Int position, int rotationIndex, int templateIndex)
|
|
|
+ {
|
|
|
+ List<bool> results = new List<bool>();
|
|
|
+ BuildingTemplate template = buildingTemplates[currentBuildingTemplate];
|
|
|
+ for (int i = 0; i < template.rulesets.Count; i++)
|
|
|
+ {
|
|
|
+ results.Add(template.rulesets[i].Evaluate(this, templateIndex, position, rotationIndex));
|
|
|
+ }
|
|
|
+ if(template.rulesetCondition == ConditionType.AND)
|
|
|
+ {
|
|
|
+ foreach (var value in results)
|
|
|
+ {
|
|
|
+ if(value == false) return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ foreach (var value in results)
|
|
|
+ {
|
|
|
+ if(value == true) return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
|
|
|
public enum VoxelBuildingTool
|