Exemple #1
0
        public void BuildWaypoints(DungeonModel model, LevelMarkerList markers)
        {
            // Destroy all existing waypoints
            DestroyAllWaypoints();

            if (model is GridDungeonModel)
            {
                BuildGridWaypoints(model as GridDungeonModel, markers);
            }
            else if (model is SimpleCityDungeonModel)
            {
                BuildCityWaypoints(model as SimpleCityDungeonModel);
            }
            else
            {
                Debug.LogWarning("Waypoint generator does not support model of type: " + model.GetType());
                return;
            }
        }
    public override void OnDungeonMarkersEmitted(Dungeon dungeon, DungeonModel model, LevelMarkerList markers)
    {
        var terrain = Terrain.activeTerrain;

        if (terrain == null)
        {
            return;
        }

        foreach (var marker in markers)
        {
            var clampedPosition = GetClampedPosition(ref marker.Transform, terrain);
            Matrix.SetTranslation(ref marker.Transform, clampedPosition);
        }
    }
Exemple #3
0
    public override void OnDungeonMarkersEmitted(Dungeon dungeon, DungeonModel model, LevelMarkerList markers)
    {
        var config   = dungeon.Config as GridDungeonConfig;
        var gridSize = config.GridCellSize;

        var SpatialPartition = new HashSet <IntVector>();
        var markersToRemove  = new List <PropSocket>();

        foreach (var marker in markers)
        {
            if (marker.SocketType == markerName)
            {
                // Check if a marker with this name has already been encountered before in this spatial cell
                var markerLocation = Matrix.GetTranslation(ref marker.Transform);
                int sx             = Mathf.FloorToInt(markerLocation.x / gridSize.x);
                int sz             = Mathf.FloorToInt(markerLocation.z / gridSize.z);
                var spatialKey     = new IntVector(sx, 0, sz);

                if (SpatialPartition.Contains(spatialKey))
                {
                    // We have found a marker within this cell before. remove it from the list
                    markersToRemove.Add(marker);
                    continue;
                }

                // Register it so we can remove duplicates later
                SpatialPartition.Add(spatialKey);
            }
        }

        // Remove all the markers that were marked for removal
        foreach (var markerToRemove in markersToRemove)
        {
            markers.Remove(markerToRemove);
        }
    }
Exemple #4
0
        public override void OnDungeonMarkersEmitted(Dungeon dungeon, DungeonModel model, LevelMarkerList markers)
        {
            var config = dungeon.Config as CircularCityDungeonConfig;

            if (config == null)
            {
                return;
            }

            foreach (var marker in markers)
            {
                var position           = Matrix.GetTranslation(ref marker.Transform);
                var distanceFromCenter = position.magnitude;

                float t = (distanceFromCenter - config.startRadius) / (config.endRadius - config.startRadius);
                t = Mathf.Clamp01(t);
                t = 1 - t;

                if (curve != null)
                {
                    t = curve.Evaluate(t);
                }


                var scaleMultiplier = minScale + (maxScale - minScale) * t;
                var rotation        = Matrix.GetRotation(ref marker.Transform);
                var scale           = Matrix.GetScale(ref marker.Transform);
                scale            = Vector3.Scale(scale, new Vector3(1, scaleMultiplier, 1));
                marker.Transform = Matrix4x4.TRS(position, rotation, scale);
            }
        }
Exemple #5
0
        void BuildGridWaypoints(GridDungeonModel gridModel, LevelMarkerList markers)
        {
            mode2D = gridModel.Config.Mode2D;

            // Destroy all existing waypoints
            DestroyAllWaypoints();

            var cellToWaypoint = new Dictionary <int, Waypoint>();

            int idCounter = 1;

            var wall2DPositions = new HashSet <IntVector>();

            if (mode2D)
            {
                foreach (var marker in markers)
                {
                    if (marker.SocketType == DungeonConstants.ST_WALL2D)
                    {
                        wall2DPositions.Add(marker.gridPosition);
                    }
                }
            }

            // Create a waypoint on each cell
            foreach (var cell in gridModel.Cells)
            {
                if (mode2D)
                {
                    if (wall2DPositions.Contains(cell.Bounds.Location))
                    {
                        // Don't want to create a waypoint on a wall tile
                        continue;
                    }
                }
                var worldPos = MathUtils.GridToWorld(gridModel.Config.GridCellSize, cell.CenterF);
                worldPos += waypointOffset;
                if (mode2D)
                {
                    worldPos = FlipYZ(worldPos);
                }
                var waypointObject = Instantiate(waypointTemplate, worldPos, Quaternion.identity) as GameObject;
                waypointObject.transform.parent = waypointParent.transform;

                var waypoint = waypointObject.GetComponent <Waypoint>();
                waypoint.id = idCounter++;
                cellToWaypoint.Add(cell.Id, waypoint);
            }

            // Connect adjacent waypoints
            foreach (var cellId in cellToWaypoint.Keys)
            {
                var waypoint          = cellToWaypoint[cellId];
                var cell              = gridModel.GetCell(cellId);
                var adjacentWaypoints = new List <Waypoint>();
                var visited           = new HashSet <int>();
                foreach (var adjacentCellId in cell.AdjacentCells)
                {
                    if (visited.Contains(GetHash(cellId, adjacentCellId)))
                    {
                        continue;
                    }

                    var adjacentCell = gridModel.GetCell(adjacentCellId);
                    // add only if there is a direct path to it (through a door or stair or open space)
                    bool directPath = HasDirectPath(gridModel, cell, adjacentCell);
                    if (directPath)
                    {
                        if (cellToWaypoint.ContainsKey(adjacentCellId))
                        {
                            var adjacentWaypoint = cellToWaypoint[adjacentCellId];
                            adjacentWaypoints.Add(adjacentWaypoint);
                            visited.Add(GetHash(cellId, adjacentCellId));
                            visited.Add(GetHash(adjacentCellId, cellId));
                        }
                    }
                }
                waypoint.AdjacentWaypoints = adjacentWaypoints.ToArray();
            }
        }
Exemple #6
0
 public override void OnDungeonMarkersEmitted(Dungeon dungeon, DungeonModel model, LevelMarkerList markers)
 {
     BuildWaypoints(model, markers);
 }
    public override void OnDungeonMarkersEmitted(Dungeon dungeon, DungeonModel model, LevelMarkerList markers)
    {
        var cityModel = model as SimpleCityDungeonModel;
        var width     = cityModel.CityWidth;
        var height    = cityModel.CityHeight;
        var center    = Vector3.Scale(new Vector3(width / 2.0f, 0, height / 2.0f), new Vector3(cityModel.Config.CellSize.x, 0, cityModel.Config.CellSize.y));

        center += dungeon.transform.position;

        foreach (var marker in markers)
        {
            if (marker.SocketType == SimpleCityDungeonConstants.House)
            {
                var distanceFromCenter = (Matrix.GetTranslation(ref marker.Transform) - center).magnitude;
                foreach (var rangeInfo in skyscraperRanges)
                {
                    if (distanceFromCenter >= rangeInfo.startDistance && distanceFromCenter <= rangeInfo.endDistance)
                    {
                        marker.SocketType = rangeInfo.markerName;
                        break;
                    }
                }
            }
        }
    }
        void AddGround2DMarkers(List <Wall2DMarkerInfo> markerList, Dictionary <string, HashSet <IntVector> > occupied, LevelMarkerList gridMarkers, Vector3 gridSize)
        {
            var walls = GetHashSet(DungeonConstants.ST_WALL2D, occupied);

            foreach (var marker in gridMarkers)
            {
                if (marker.SocketType == DungeonConstants.ST_GROUND)
                {
                    // Make sure we don't have a wall here
                    if (walls.Contains(marker.gridPosition))
                    {
                        // Contains a wall here. We don't want a 2D ground here
                        continue;
                    }

                    var wall2D = new Wall2DMarkerInfo();
                    wall2D.cellId       = marker.cellId;
                    wall2D.gridPosition = marker.gridPosition;
                    wall2D.markerName   = DungeonConstants.ST_GROUND2D;
                    var position = marker.gridPosition * gridSize + gridSize / 2.0f;
                    wall2D.transform = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one);

                    RegisterMarker(wall2D, markerList, occupied);
                }
            }
        }
        void FixCornerWalls(List <Wall2DMarkerInfo> wall2DMarkers, LevelMarkerList gridMarkers, Dictionary <string, HashSet <IntVector> > occupied, Vector3 gridSize)
        {
            HashSet <IntVector> wall2DPositions = GetHashSet(DungeonConstants.ST_WALL2D, occupied);
            HashSet <IntVector> door2DPositions = GetHashSet(DungeonConstants.ST_DOOR2D, occupied);

            {
                HashSet <IntVector> door2DPositions90 = GetHashSet(DungeonConstants.ST_DOOR2D_90, occupied);
                foreach (var door90Pos in door2DPositions90)
                {
                    door2DPositions.Add(door90Pos);
                }
            }


            if (occupied.ContainsKey(DungeonConstants.ST_DOOR2D))
            {
                door2DPositions = occupied[DungeonConstants.ST_DOOR2D];
            }
            else
            {
                door2DPositions = new HashSet <IntVector>();
            }

            foreach (var marker in gridMarkers)
            {
                if (marker.SocketType == DungeonConstants.ST_GROUND)
                {
                    if (wallPushType == WallPushType.WallsInside)
                    {
                        var center       = marker.gridPosition;
                        var insertCorner = false;
                        if (!wall2DPositions.Contains(center))
                        {
                            insertCorner = HasValidCornerNeighbors(wall2DPositions, door2DPositions, center, -1, 0, 0, 1) ||
                                           HasValidCornerNeighbors(wall2DPositions, door2DPositions, center, 0, 1, 1, 0) ||
                                           HasValidCornerNeighbors(wall2DPositions, door2DPositions, center, 1, 0, 0, -1) ||
                                           HasValidCornerNeighbors(wall2DPositions, door2DPositions, center, 0, -1, -1, 0);
                            if (insertCorner)
                            {
                                InsertCornerMarker(marker.cellId, marker.gridPosition, gridSize, wall2DMarkers, occupied);
                            }
                        }
                    }
                    else if (wallPushType == WallPushType.WallsOutside)
                    {
                        var center = marker.gridPosition;
                        if (!wall2DPositions.Contains(center))
                        {
                            if (HasValidCornerNeighbors(wall2DPositions, door2DPositions, center, -1, 0, 0, 1))
                            {
                                var corner = center + new IntVector(-1, 0, 1);
                                InsertCornerMarker(marker.cellId, corner, gridSize, wall2DMarkers, occupied);
                            }
                            if (HasValidCornerNeighbors(wall2DPositions, door2DPositions, center, 0, 1, 1, 0))
                            {
                                var corner = center + new IntVector(1, 0, 1);
                                InsertCornerMarker(marker.cellId, corner, gridSize, wall2DMarkers, occupied);
                            }
                            if (HasValidCornerNeighbors(wall2DPositions, door2DPositions, center, 1, 0, 0, -1))
                            {
                                var corner = center + new IntVector(1, 0, -1);
                                InsertCornerMarker(marker.cellId, corner, gridSize, wall2DMarkers, occupied);
                            }
                            if (HasValidCornerNeighbors(wall2DPositions, door2DPositions, center, 0, -1, -1, 0))
                            {
                                var corner = center + new IntVector(-1, 0, -1);
                                InsertCornerMarker(marker.cellId, corner, gridSize, wall2DMarkers, occupied);
                            }
                        }
                    }
                }
            }
        }