示例#1
0
    public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random)
    {
        var selected = base.CanSelect(socket, propTransform, model, random);

        if (!selected)
        {
            return(false);
        }

        // Further filter near the door positions
        if (model is GridDungeonModel)
        {
            var  gridModel     = model as GridDungeonModel;
            var  position      = Matrix.GetTranslation(ref propTransform);
            var  gridSize      = gridModel.Config.GridCellSize;
            var  x             = Mathf.FloorToInt(position.x / gridSize.x);
            var  z             = Mathf.FloorToInt(position.z / gridSize.z);
            var  cellInfo      = gridModel.GetGridCellLookup(x, z);
            bool isRoom        = cellInfo.CellType == CellType.Room;
            bool containsStair = gridModel.ContainsStairAtLocation(x, z);
            return(isRoom && !containsStair);
        }

        return(false);
    }
 public override bool ProcessSpatialConstraint(SpatialConstraint constraint, PropSocket socket, DungeonModel model, List <PropSocket> levelSockets, out Matrix4x4 outOffset)
 {
     outOffset = Matrix4x4.identity;
     if (constraint is SpatialConstraintGrid7x7)
     {
         return(Process7x7(constraint as SpatialConstraintGrid7x7, socket, model, ref outOffset));
     }
     if (constraint is SpatialConstraintGrid5x5)
     {
         return(Process5x5(constraint as SpatialConstraintGrid5x5, socket, model, ref outOffset));
     }
     if (constraint is SpatialConstraintGrid3x3)
     {
         return(Process3x3(constraint as SpatialConstraintGrid3x3, socket, model, ref outOffset));
     }
     if (constraint is SpatialConstraintGrid2x2)
     {
         return(Process2x2(constraint as SpatialConstraintGrid2x2, socket, model, ref outOffset));
     }
     if (constraint is SpatialConstraintGrid1x2)
     {
         return(Process1x2(constraint as SpatialConstraintGrid1x2, socket, model, ref outOffset));
     }
     return(false);
 }
	public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale) {
		base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);
		
		var angle = random.Range(0, 1) * 180;
		var rotation = Quaternion.Euler(0, angle, 0);
		outRotation = rotation;
	}
    public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale)
    {
        base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

        // Apply a small random transform to avoid z-fighting
        outPosition = random.OnUnitSphere() * movementDistance;
    }
        bool Process3x3(SpatialConstraintGrid3x3 constraint, PropSocket socket, DungeonModel model)
        {
            var isaacModel = model as GridDungeonModel;

            if (isaacModel == null)
            {
                return(false);
            }

            for (int dx = -1; dx <= 1; dx++)
            {
                for (int dz = -1; dz <= 1; dz++)
                {
                    var cx             = dx + 1;
                    var cz             = 2 - (dz + 1);
                    var index          = cz * 3 + cx;
                    var constraintType = constraint.cells[index];
                    var adjacentPos    = socket.gridPosition + new IntVector(dx, 0, dz);
                    var occupied       = IsOccupied(adjacentPos);
                    if (occupied && constraintType.CellType == SpatialConstraintGridCellType.Empty)
                    {
                        // Expected an empty cell and got an occupied cell
                        return(false);
                    }
                    if (!occupied && constraintType.CellType == SpatialConstraintGridCellType.Occupied)
                    {
                        // Expected an occupied cell and got an empty cell
                        return(false);
                    }
                }
            }

            // All tests passed
            return(true);
        }
示例#6
0
        public static void DrawMarker(PropSocket marker, Color color, bool mode2D)
        {
            var start = Matrix.GetTranslation(ref marker.Transform);
            var end   = start + new Vector3(0, 0.2f, 0);

            DrawLine(start, end, color, 0, false, mode2D);
        }
	public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale) {
		base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);
		
		var rx = random.Range(-maxAngle, maxAngle);
		var ry = random.Range(-maxAngle, maxAngle);
		var rz = random.Range(-maxAngle, maxAngle);
	
		outRotation = Quaternion.Euler(rx, ry, rz);
	}
 public override bool ProcessSpatialConstraint(SpatialConstraint constraint, PropSocket socket, DungeonModel model, List <PropSocket> levelSockets, out Matrix4x4 outOffset)
 {
     outOffset = Matrix4x4.identity;
     if (constraint is SpatialConstraintGrid3x3)
     {
         return(Process3x3(constraint as SpatialConstraintGrid3x3, socket, model));
     }
     return(false);
 }
示例#9
0
    public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale)
    {
        base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

        var angle    = random.Range(0, 1) * 90;
        var rotation = Quaternion.Euler(0, angle, 0);

        outRotation = rotation;
    }
	public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random) {
		var rotation = Matrix.GetRotation(ref socket.Transform);
		var baseDirection = new Vector3(1, 0, 0);
		var direction = rotation * baseDirection;
		foreach (var testDirection in validDirections) {
			var dot = Vector3.Dot(direction, testDirection);
			if (dot > 0.707f) return true;
		}
		return false;
	}
	public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random) {
		if (model is GridDungeonModel) {
			var gridModel = model as GridDungeonModel;
			var cell = gridModel.GetCell(socket.cellId);
			if (cell == null) return false;
			return cell.CellType == CellType.Room;
		} else {
			return false;
		}
	}
    public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale)
    {
        base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

        var rx = random.Range(-maxAngle, maxAngle);
        var ry = random.Range(-maxAngle, maxAngle);
        var rz = random.Range(-maxAngle, maxAngle);

        outRotation = Quaternion.Euler(rx, ry, rz);
    }
示例#13
0
    public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale)
    {
        var halfWidth = tileWidth / 2.0f;

        outPosition = new Vector3(
            random.Range(-halfWidth, halfWidth), 0,
            random.Range(-halfWidth, halfWidth));

        outRotation = Quaternion.Euler(0, random.Range(0, 360), 0);
        outScale    = Vector3.one;
    }
	public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale) {
		base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);
		
		var angle = random.NextFloat() * 360;
		var rotation = Quaternion.Euler(0, angle, 0);
		outRotation = rotation;

		var variation = new Vector3(0.25f, -1, 0.25f);
		outPosition = Vector3.Scale (random.OnUnitSphere(), variation);


	}
示例#15
0
 public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random)
 {
     if (model is GridDungeonModel)
     {
         var gridModel = model as GridDungeonModel;
         var cell      = gridModel.GetCell(socket.cellId);
         if (cell != null)
         {
             return(cell.CellType == CellType.Room);
         }
     }
     return(false);
 }
示例#16
0
    public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale)
    {
        base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

        var angle    = random.NextFloat() * 360;
        var rotation = Quaternion.Euler(0, angle, 0);

        outRotation = rotation;

        var variation = new Vector3(0.25f, -1, 0.25f);

        outPosition = Vector3.Scale(random.OnUnitSphere(), variation);
    }
        Wall2DMarkerInfo GetMarker2D(PropSocket prop, string markerName, Vector3 gridSize)
        {
            var position = Matrix.GetTranslation(ref prop.Transform);
            var x        = Mathf.FloorToInt(position.x / gridSize.x);
            var z        = Mathf.FloorToInt(position.z / gridSize.z);

            var rotation = Matrix.GetRotation(ref prop.Transform);
            var offset   = rotation * new Vector3(0, 0, 1);

            if (wallPushType == WallPushType.WallsInside)
            {
                if (offset.z > 0.5f)
                {
                    z--;
                }
                if (offset.x > 0.5f)
                {
                    x--;
                }
            }
            else if (wallPushType == WallPushType.WallsOutside)
            {
                if (offset.z < -0.5f)
                {
                    z--;
                }
                if (offset.x < -0.5f)
                {
                    x--;
                }
            }


            var gridPosition   = new IntVector(x, 0, z);
            var wall2DPosition = gridPosition * gridSize;

            wall2DPosition  += gridSize / 2.0f;
            wall2DPosition.y = 0;



            var markerInfo = new Wall2DMarkerInfo();

            markerInfo.transform    = Matrix4x4.TRS(wall2DPosition, Quaternion.identity, Vector3.one);
            markerInfo.gridPosition = gridPosition;
            markerInfo.cellId       = prop.cellId;
            markerInfo.markerName   = markerName;
            return(markerInfo);
        }
        bool Process1x2(SpatialConstraintGrid1x2 constraint, PropSocket socket, DungeonModel model, ref Matrix4x4 outOffset)
        {
            var gridModel = model as GridDungeonModel;

            if (gridModel == null)
            {
                return(false);
            }
            var gridSize = gridModel.Config.GridCellSize;

            var     markerRotation = Matrix.GetRotation(ref socket.Transform);
            var     markerPosition = Matrix.GetTranslation(ref socket.Transform);
            Vector3 leftOffset, rightOffset;
            float   offset = gridSize.x;

            leftOffset  = markerRotation * new Vector3(-offset, 0, 0);
            rightOffset = markerRotation * new Vector3(0, 0, 0);

            var left  = MathUtils.RoundToIntVector(MathUtils.Divide(markerPosition + leftOffset, gridSize));
            var right = MathUtils.RoundToIntVector(MathUtils.Divide(markerPosition + rightOffset, gridSize));

            var leftOccupied  = groundPositions.ContainsKey(left);
            var rightOccupied = groundPositions.ContainsKey(right);

            var  occupied = new bool[] { leftOccupied, rightOccupied };
            var  cells    = new SpatialConstraintGridCell[] { constraint.left, constraint.right };
            bool valid    = false;

            if (CheckValidity(cells, occupied))
            {
                valid = true;
            }

            cells = new SpatialConstraintGridCell[] { constraint.right, constraint.left };
            if (CheckValidity(cells, occupied))
            {
                valid = true;
            }

            if (!valid)
            {
                return(false);
            }

            var rotation = Quaternion.identity; // Quaternion.Euler(0, offsetRotY, 0);

            outOffset = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
            return(true);
        }
	public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random) {
		if (model is GridDungeonModel) {
			var gridModel = model as GridDungeonModel;
			var config = gridModel.Config as GridDungeonConfig;
			var cellSize = config.GridCellSize;

			var position = Matrix.GetTranslation(ref propTransform);
			var gridPositionF = MathUtils.Divide (position, cellSize);
			var gridPosition = MathUtils.ToIntVector(gridPositionF);
			var cellInfo = gridModel.GetGridCellLookup(gridPosition.x, gridPosition.z);
			return !cellInfo.ContainsDoor;
		} else {
			return false;
		}
	}
示例#20
0
    public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale)
    {
        base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

        var angle    = random.Range(0.0f, Mathf.PI * 2);
        var rotation = Quaternion.Euler(0, angle, 0);

        outRotation = rotation;

        float cellSize     = 20;
        float halfCellSize = cellSize / 2.0f;

        outPosition.x = random.Range(-halfCellSize, halfCellSize);
        outPosition.z = random.Range(-halfCellSize, halfCellSize);
    }
	public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale) {
		base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

		var terrain = Terrain.activeTerrain;
		if (terrain == null) {
			return;
		}

		var position = Matrix.GetTranslation(ref propTransform);
		var currentY = position.y;
		var targetY = LandscapeDataRasterizer.GetHeight(terrain, position.x, position.z);

		outPosition.y = targetY - currentY;

	}
    public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random)
    {
        var rotation      = Matrix.GetRotation(ref socket.Transform);
        var baseDirection = new Vector3(1, 0, 0);
        var direction     = rotation * baseDirection;

        foreach (var testDirection in validDirections)
        {
            var dot = Vector3.Dot(direction, testDirection);
            if (dot > 0.707f)
            {
                return(true);
            }
        }
        return(false);
    }
        bool Process3x3(SpatialConstraintGrid3x3 constraint, PropSocket socket, DungeonModel model)
        {
            var roomId     = socket.cellId;
            var isaacModel = model as IsaacDungeonModel;

            if (isaacModel == null)
            {
                return(false);
            }

            var room = IsaacBuilderUtils.GetRoom(isaacModel, roomId);

            if (room == null)
            {
                return(false);
            }

            int x, z;

            GetLayoutPosition(room, isaacModel, socket.Transform, out x, out z);

            for (int dx = -1; dx <= 1; dx++)
            {
                for (int dz = -1; dz <= 1; dz++)
                {
                    var  cx             = dx + 1;
                    var  cz             = 2 - (dz + 1);
                    var  index          = cz * 3 + cx;
                    var  constraintType = constraint.cells[index];
                    var  mapTileType    = IsaacBuilderUtils.GetTileAt(x + dx, z + dz, room.layout);
                    bool empty          = (mapTileType.tileType != IsaacRoomTileType.Floor);
                    if (empty && constraintType.CellType == SpatialConstraintGridCellType.Occupied)
                    {
                        // Expected an occupied cell and got an empty cell
                        return(false);
                    }
                    if (!empty && constraintType.CellType == SpatialConstraintGridCellType.Empty)
                    {
                        // Expected an empty cell and got an occupied cell
                        return(false);
                    }
                }
            }

            // All tests passed
            return(true);
        }
示例#24
0
    public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale)
    {
        base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

        var terrain = Terrain.activeTerrain;

        if (terrain == null)
        {
            return;
        }

        var position = Matrix.GetTranslation(ref propTransform);
        var currentY = position.y;
        var targetY  = LandscapeDataRasterizer.GetHeight(terrain, position.x, position.z);

        outPosition.y = targetY - currentY;
    }
示例#25
0
    public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random)
    {
        if (model is GridDungeonModel)
        {
            var gridModel = model as GridDungeonModel;
            var config    = gridModel.Config as GridDungeonConfig;
            var cellSize  = config.GridCellSize;

            var position      = Matrix.GetTranslation(ref propTransform);
            var gridPositionF = MathUtils.Divide(position, cellSize);
            var gridPosition  = MathUtils.ToIntVector(gridPositionF);
            var cellInfo      = gridModel.GetGridCellLookup(gridPosition.x, gridPosition.z);
            return(!cellInfo.ContainsDoor);
        }
        else
        {
            return(false);
        }
    }
示例#26
0
        public bool ProcessSpatialConstraint(SpatialConstraintProcessorContext context, out Matrix4x4 outOffset, out PropSocket[] outMarkersToRemove)
        {
            outOffset = Matrix4x4.identity;
            var domain = GetDomain(context);

            if (context.constraintAsset != null && context.constraintAsset.Graph != null)
            {
                Matrix4x4[] rotationFrames;
                if (context.constraintAsset.rotateToFit)
                {
                    rotationFrames = new Matrix4x4[]
                    {
                        Matrix4x4.identity,
                        Matrix4x4.Rotate(Quaternion.Euler(0, 90, 0)),
                        Matrix4x4.Rotate(Quaternion.Euler(0, 180, 0)),
                        Matrix4x4.Rotate(Quaternion.Euler(0, 270, 0)),
                    };
                }
                else
                {
                    rotationFrames = new Matrix4x4[]
                    {
                        Matrix4x4.identity
                    };
                }

                foreach (var rotationFrame in rotationFrames)
                {
                    if (ProcessSpatialConstraintFrame(context, domain, rotationFrame, out outMarkersToRemove))
                    {
                        if (context.constraintAsset.applyFitRotation)
                        {
                            outOffset = rotationFrame;
                        }
                        return(true);
                    }
                }
            }

            outMarkersToRemove = new PropSocket[0];
            return(false);
        }
	public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale) {
		base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

		// Get the ground location at this position
		if (model is GridDungeonModel) {
			var gridModel = model as GridDungeonModel;
			var positionWorld = Matrix.GetTranslation(ref propTransform);
			var gridCoord = MathUtils.WorldToGrid(positionWorld, gridModel.Config.GridCellSize);
			var cellInfo = gridModel.GetGridCellLookup(gridCoord.x, gridCoord.z);
			if (cellInfo.CellType != CellType.Unknown) {
				var cell = gridModel.GetCell(socket.cellId);
				var config = gridModel.Config as GridDungeonConfig;
				var cellY = cell.Bounds.Location.y * config.GridCellSize.y;
				var markerY = Matrix.GetTranslation(ref propTransform).y;
				var deltaY = cellY - markerY;
				outPosition.y = deltaY;
			}
		}

	}
示例#28
0
    public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale)
    {
        base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

        // Get the ground location at this position
        if (model is GridDungeonModel)
        {
            var gridModel     = model as GridDungeonModel;
            var config        = gridModel.Config as GridDungeonConfig;
            var positionWorld = Matrix.GetTranslation(ref propTransform);
            var gridCoord     = MathUtils.WorldToGrid(positionWorld, config.GridCellSize);
            var cellInfo      = gridModel.GetGridCellLookup(gridCoord.x, gridCoord.z);
            if (cellInfo.CellType != CellType.Unknown)
            {
                var cell    = gridModel.GetCell(socket.cellId);
                var cellY   = cell.Bounds.Location.y * config.GridCellSize.y;
                var markerY = Matrix.GetTranslation(ref propTransform).y;
                var deltaY  = cellY - markerY;
                outPosition.y = deltaY;
            }
        }
    }
    public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random)
    {
        var selected = base.CanSelect(socket, propTransform, model, random);

        if (!selected)
        {
            return(false);
        }

        // Further filter near the door positions
        var cellId = socket.cellId;

        if (model is GridDungeonModel)
        {
            var gridModel = model as GridDungeonModel;
            foreach (var door in gridModel.Doors)
            {
                if (door.AdjacentCells.Length == 2)
                {
                    if (door.AdjacentCells[0] == cellId || door.AdjacentCells[1] == cellId)
                    {
                        return(false);
                    }
                }
            }
            // Check if a door exists in this location
            //gridModel.DoorManager.ContainsDoorBetweenCells

            var cell = gridModel.GetCell(socket.cellId);
            if (cell == null)
            {
                return(false);
            }
        }

        return(true);
    }
	public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random) {
		var selected = base.CanSelect(socket, propTransform, model, random);
		if (!selected) return false;

		// Further filter near the door positions
		var cellId = socket.cellId;
		if (model is GridDungeonModel) {
			var gridModel = model as GridDungeonModel;
			foreach (var door in gridModel.Doors) {
				if (door.AdjacentCells.Length == 2) {
					if (door.AdjacentCells[0] == cellId || door.AdjacentCells[1] == cellId) {
						return false;
					}
				}
			}
			// Check if a door exists in this location
			//gridModel.DoorManager.ContainsDoorBetweenCells

			var cell = gridModel.GetCell(socket.cellId);
			if (cell == null) return false;
		}

		return true;
	}
 public abstract bool ProcessSpatialConstraint(SpatialConstraint constraint, PropSocket socket, DungeonModel model, List <PropSocket> levelSockets, out Matrix4x4 outOffset);
        bool Process2x2(SpatialConstraintGrid2x2 constraint, PropSocket socket, DungeonModel model, ref Matrix4x4 outOffset)
        {
            var gridModel = model as GridDungeonModel;

            if (gridModel == null)
            {
                return(false);
            }

            int rotationsRequired = constraint.rotateToFit ? 4 : 1;

            SpatialConstraintGridCell[] constraintCells = constraint.cells;
            for (int rotIndex = 0; rotIndex < rotationsRequired; rotIndex++)
            {
                int baseCellId = -1;
                if (groundPositions.ContainsKey(socket.gridPosition))
                {
                    baseCellId = groundPositions[socket.gridPosition];
                }
                CellType baseCellType = GetCellTypeFromId(baseCellId, gridModel);

                bool isValid = true;
                for (int i = 0; i < constraintCells.Length; i++)
                {
                    var constraintType = constraintCells[i];
                    if (constraintType.CellType == SpatialConstraintGridCellType.DontCare)
                    {
                        continue;
                    }
                    int dx = i % 2;
                    int dz = i / 2;
                    dx += -1;
                    dz += -1;   // bring to -1..0 range

                    var adjacentPos = socket.gridPosition + new IntVector(dx, 0, dz);
                    int adjacentCellId;
                    var occupied = IsOccupied(adjacentPos, out adjacentCellId);

                    CellType adjacentCellType = GetCellTypeFromId(adjacentCellId, gridModel);

                    if (occupied && adjacentCellType != baseCellType && !mergeRoomCorridor)
                    {
                        //occupied = false;
                    }

                    if (adjacentCellType == CellType.Unknown)
                    {
                        occupied = false;
                    }

                    if (occupied && constraintType.CellType == SpatialConstraintGridCellType.Empty)
                    {
                        // Expected an empty cell and got an occupied cell
                        isValid = false;
                        break;
                    }
                    if (!occupied && constraintType.CellType == SpatialConstraintGridCellType.Occupied)
                    {
                        // Expected an occupied cell and got an empty cell
                        isValid = false;
                        break;
                    }
                }

                if (isValid)
                {
                    int        rotationAngle = 90 * rotIndex;
                    Quaternion rotation      = Quaternion.Euler(0, rotationAngle, 0);
                    outOffset = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
                    return(true);
                }
                constraintCells = Rotate2x2(constraintCells);
            }


            // All tests failed
            return(false);
        }
示例#33
0
        public static Vector3 GetRuleNodeWorldPosition(SCRuleNode ruleNode, SCReferenceNode referenceNode, PropSocket marker, Vector3 gridSize, ref Matrix4x4 rotationFrame)
        {
            var scGraph = ruleNode.Graph as SpatialConstraintGraph;
            var relativeToMarkerRotation = scGraph.asset.checkRelativeToMarkerRotation;

            var markerTransform = marker.Transform;

            Vector2 offset2D = (ruleNode.Bounds.center - referenceNode.Bounds.center) / SCBaseDomainNode.TileSize;
            Vector3 offset   = new Vector3(offset2D.x, 0, offset2D.y);

            if (relativeToMarkerRotation)
            {
                offset = RotateVector(offset, markerTransform);
            }
            offset = RotateVector(offset, rotationFrame);

            // Find the world position of the marker and the location to search (relative to the spatial constraint node from the SC reference node)
            var baseMarkerPosition = Matrix.GetTranslation(ref marker.Transform);
            var ruleNodePosition   = baseMarkerPosition + Vector3.Scale(offset, gridSize);

            return(ruleNodePosition);
        }
示例#34
0
        bool ProcessSpatialConstraintFrame(SpatialConstraintProcessorContext context, SpatialConstraintRuleDomain domain, Matrix4x4 rotationFrame, out PropSocket[] outMarkersToRemove)
        {
            var nodes = context.constraintAsset.Graph.Nodes.Where(node => node is SCRuleNode);

            outMarkersToRemove = new PropSocket[0];

            if (nodes.Count() == 0)
            {
                // No rules specified.  Return true by default
                return(true);
            }

            var nodeWorldPositions = new Dictionary <SCRuleNode, Vector3>();

            foreach (var node in nodes)
            {
                var ruleNode = node as SCRuleNode;

                var nodePosition = SpatialConstraintProcessorUtils.GetRuleNodeWorldPosition(ruleNode, domain.referenceNode,
                                                                                            context.marker, domain.gridSize, ref rotationFrame);
                nodeWorldPositions.Add(ruleNode, nodePosition);

                var constraints = ruleNode.constraints.Where(c => c != null);
                if (constraints.Count() == 0)
                {
                    continue;
                }

                bool allRulesPassed       = true;
                bool atleastOneRulePassed = false;

                foreach (var constraint in constraints)
                {
                    var ruleContext = new ConstraintRuleContext();
                    ruleContext.processorContext      = context;
                    ruleContext.domain                = domain;
                    ruleContext.ruleNode              = ruleNode;
                    ruleContext.rotationFrame         = rotationFrame;
                    ruleContext.ruleNodeWorldPosition = nodePosition;


                    bool success = constraint.Process(ruleContext);
                    if (constraint.inverseRule)
                    {
                        success = !success;
                    }

                    allRulesPassed       &= success;
                    atleastOneRulePassed |= success;
                }

                if (ruleNode.constraintEvaluationMode == SCRuleNodeEvaluationMode.AllRulesMustPass && !allRulesPassed)
                {
                    return(false);
                }
                else if (ruleNode.constraintEvaluationMode == SCRuleNodeEvaluationMode.AtleastOneRuleShouldPass && !atleastOneRulePassed)
                {
                    return(false);
                }
            }

            // The spatial constraint setup has passed
            // Process removal rules
            var markersToRemove = new List <PropSocket>();

            foreach (var node in nodes)
            {
                var ruleNode = node as SCRuleNode;
                if (ruleNode.exclusionRuleMarkersToRemove.Length == 0)
                {
                    continue;
                }

                var   radius         = ruleNode.exclusionRuleSearchRadius;
                float searchRadiusSq = radius * radius;
                var   nodePosition3D = nodeWorldPositions[ruleNode];
                var   searchPosition = SpatialConstraintProcessorUtils.GetPosition2D(nodePosition3D);
                foreach (var markerToRemove in ruleNode.exclusionRuleMarkersToRemove)
                {
                    var markerSearchSpace = context.levelMarkers.GetMarkersInSearchArea(searchPosition, radius);
                    foreach (var candidateMarker in markerSearchSpace)
                    {
                        var candidateMarkerName = candidateMarker.SocketType;
                        if (ruleNode.exclusionRuleMarkersToRemove.Contains(candidateMarkerName))
                        {
                            var   candidateMarkerPosition = SpatialConstraintProcessorUtils.GetPosition2D(Matrix.GetTranslation(ref candidateMarker.Transform));
                            float distanceSq = (searchPosition - candidateMarkerPosition).sqrMagnitude;
                            if (distanceSq < searchRadiusSq)
                            {
                                markersToRemove.Add(candidateMarker);
                            }
                        }
                    }
                }
            }
            outMarkersToRemove = markersToRemove.ToArray();

            return(true);
        }
	public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random) {
		return (socket.gridPosition.x + socket.gridPosition.z) % 2 == 0;
	}
        bool Process7x7(SpatialConstraintGrid7x7 constraint, PropSocket socket, DungeonModel model, ref Matrix4x4 outOffset)
        {
            var gridModel = model as GridDungeonModel;

            if (gridModel == null)
            {
                return(false);
            }

            int rotationsRequired = constraint.rotateToFit ? 4 : 1;

            SpatialConstraintGridCell[] constraintCells = constraint.cells;
            for (int rotIndex = 0; rotIndex < rotationsRequired; rotIndex++)
            {
                int baseCellId = -1;
                if (groundPositions.ContainsKey(socket.gridPosition))
                {
                    baseCellId = groundPositions[socket.gridPosition];
                }
                CellType baseCellType = GetCellTypeFromId(baseCellId, gridModel);

                bool isValid = true;
                for (int dx = -3; dx <= 3; dx++)
                {
                    for (int dz = -3; dz <= 3; dz++)
                    {
                        var cx             = dx + 3;
                        var cz             = 6 - (dz + 3);
                        var index          = cz * 7 + cx;
                        var constraintType = constraintCells[index];
                        var adjacentPos    = socket.gridPosition + new IntVector(dx, 0, dz);
                        int adjacentCellId;
                        var occupied = IsOccupied(adjacentPos, out adjacentCellId);

                        CellType adjacentCellType = GetCellTypeFromId(adjacentCellId, gridModel);

                        if (occupied && adjacentCellType != baseCellType && !mergeRoomCorridor)
                        {
                            occupied = false;
                        }

                        if (occupied && constraintType.CellType == SpatialConstraintGridCellType.Empty)
                        {
                            // Expected an empty cell and got an occupied cell
                            isValid = false;
                            break;
                        }
                        if (!occupied && constraintType.CellType == SpatialConstraintGridCellType.Occupied)
                        {
                            // Expected an occupied cell and got an empty cell
                            isValid = false;
                            break;
                        }
                    }
                    if (!isValid)
                    {
                        break;
                    }
                }
                if (isValid)
                {
                    int        rotationAngle = -90 * rotIndex;
                    Quaternion rotation      = Quaternion.Euler(0, rotationAngle, 0);
                    outOffset = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
                    return(true);
                }
                constraintCells = Rotate7x7(constraintCells);
            }


            // All tests failed
            return(false);
        }
 public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random)
 {
     return((socket.gridPosition.x + socket.gridPosition.z) % 2 == 0);
 }