Beispiel #1
0
    public VirtualMap.DirectionType GetNextDirection(VirtualMap map, CellLocation location)
    {
        VirtualMap.DirectionType directionPicked = new VirtualMap.DirectionType();
        //right
        if (directionsPicked.Count == 0)         //nulla da fare
        {
            map.visitedAndBlockedCells.Add(location);
            return(VirtualMap.DirectionType.None);
        }
        else if (directionsPicked.Count == 1)         //solo una ne ho, non c'e nbisogno di fare altro
        {
            directionPicked = directionsPicked[0];
        }
        else if (directionsPicked.Contains(PreviousDirection)) //posso cambiare o meno
        {
            if (MustChangeDirection)                           //se sono qua ho almeno due direzioni, levo quella corrente, perche' un'altra ce ne deve essere
            {
                directionsPicked.Remove(PreviousDirection);
                int index = DungeonGenerator.Random.Instance.Next(0, directionsPicked.Count - 1);
                directionPicked = directionsPicked[index];
            }
            else
            {
                directionPicked = PreviousDirection;
            }
        }
        else         //devo cambiare per forza
        {
            int index = DungeonGenerator.Random.Instance.Next(0, directionsPicked.Count - 1);
            directionPicked = directionsPicked[index];
        }

        return(directionPicked);
    }
    public T GetPrefab(VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation = VirtualMap.DirectionType.None)
    {
        S[] type_choices = null;
        type_choices = GetVariations(cell_type, orientation);
        if (type_choices == null)
        {
            return(default(T));
        }

        // Get one with a weighted random
        int tot = 0;

        foreach (S choice in type_choices)
        {
            tot += choice.weight;
        }
        int rnd = DungeonGenerator.Random.Instance.Next(1, tot);
        //		Debug.Log(cell_type + " " + tot + " " + rnd);

        int current = 0;

        foreach (S choice in type_choices)
        {
            current += choice.weight;
            if (rnd <= current)
            {
                //				Debug.Log("YTYPE " + cell_type + " CHOICE: " + choice.choice);
                return(choice.choice);
            }
        }
        return(default(T));
    }
Beispiel #3
0
    override public void StartDigging(VirtualMap map, CellLocation starting_location, int directionChangeModifier)
    {
        CellLocation currentLocation = starting_location;

        map.MarkAsVisited(currentLocation);

        // Pick a starting previous direction
        VirtualMap.DirectionType previousDirection = VirtualMap.DirectionType.North;

        List <CellLocation> previousLocations = new List <CellLocation>();

        // Repeat until all cells have been visited
        while (!map.AllCellsVisited)
        {
            // Get a starting direction
            DirectionPicker          directionPicker = new DirectionPicker(map, currentLocation, directionChangeModifier, previousDirection);
            VirtualMap.DirectionType direction       = directionPicker.GetNextDirection(map, currentLocation);

            if (direction != VirtualMap.DirectionType.None)
            {
                // Create a corridor in the current cell and flag it as visited
                previousLocations.Add(currentLocation);
                previousDirection = direction;
                currentLocation   = map.CreateCorridor(currentLocation, direction);
                map.FlagCellAsVisited(currentLocation);
            }
            else
            {
                // Backtrack
                currentLocation = previousLocations[previousLocations.Count - 1];
                previousLocations.RemoveAt(previousLocations.Count - 1);
            }
        }
    }
    virtual protected T GetDefault(string defaultName, VirtualMap.DirectionType orientation)
    {
        T default_object = Resources.Load(defaultName, typeof(T)) as T;

        //if (default_object == null)	Debug.LogWarning ("No default for type " + defaultName + " could be found! Make sure to add a variation for it!");
        DaedalusDebugUtils.Assert(default_object != null, "No default of name " + defaultName + " could be found!", this);
        return(default_object);
    }
Beispiel #5
0
 // Get target starting_location from a valid cell/direction
 public CellLocation GetTargetLocation(CellLocation location, VirtualMap.DirectionType direction)
 {
     if (!HasAdjacentCellInDirection(location, direction))
     {
         return(new CellLocation(-1, -1));
     }
     else
     {
         return(GetNeighbourCellLocationOfSameType(location, direction));
     }
 }
Beispiel #6
0
    public DirectionPicker(VirtualMap map, CellLocation location, int changeDirectionModifier, VirtualMap.DirectionType previousDirection)
    {
        this.PreviousDirection       = previousDirection;
        this.PreviousLocation        = location;
        this.ChangeDirectionModifier = changeDirectionModifier;

        foreach (VirtualMap.DirectionType dir in map.directions)
        {
            if (map.HasAdjacentCellInDirection(location, dir) && !map.AdjacentCellInDirectionIsVisited(location, dir))
            {
                directionsPicked.Add(dir);
            }
        }
    }
Beispiel #7
0
    // Override the constructor for opening dead ends
    public DirectionPicker(VirtualMap map, CellLocation location, VirtualMap.DirectionType previousDirection)
    {
        this.PreviousDirection       = previousDirection;
        this.PreviousLocation        = location;
        this.ChangeDirectionModifier = 100;         // Always change the direction



        foreach (VirtualMap.DirectionType dir in map.directions)
        {
            if (map.HasAdjacentCellInDirection(location, dir) && (LINK_DEAD_ENDS_PASSING_ON_ROCKS || !map.AdjacentCellInDirectionIsRock(location, dir)))
            {
                directionsPicked.Add(dir);
            }
        }
    }
Beispiel #8
0
    override protected SpriteChoice[] GetVariations(VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation = VirtualMap.DirectionType.None)
    {
        SpriteChoice[] type_choices = null;
        switch (cell_type)
        {
        case VirtualCell.CellType.Fake3D_Corridor_WallAbove:                    type_choices = fake3DCorridorWallAbove;                         break;

        case VirtualCell.CellType.Fake3D_Corridor_WallFront:                    type_choices = fake3DCorridorWallFront;                         break;

        case VirtualCell.CellType.Fake3D_Room_WallAbove:                                type_choices = fake3DRoomWallAbove;                                     break;

        case VirtualCell.CellType.Fake3D_Room_WallFront:                                type_choices = fake3DRoomWallFront;                                     break;

//		case VirtualCell.CellType.DoorHorizontalTop:					type_choices = doorsHorizontalTop;					break;
        case VirtualCell.CellType.DoorHorizontalBottom:                                 type_choices = doorsHorizontalBottom;                           break;

        case VirtualCell.CellType.DoorVertical:                         type_choices = doorsVertical; break;

        default:                                                        type_choices = base.GetVariations(cell_type, orientation); break;
        }
        return(type_choices);
    }
    // Open dead ends by linking them to rooms
    private void OpenDeadEnds(VirtualMap map)
    {
        //		Console.WriteLine("DEAD END MOD: " + openDeadEndModifier);
        if (openDeadEndModifier == 0)
        {
            return;
        }

        IEnumerable <CellLocation> deads = map.DeadEndCellLocations;

        foreach (CellLocation deadEnd in deads)
        {
            if (DungeonGenerator.Random.Instance.Next(1, 99) < openDeadEndModifier)
            {
                CellLocation currentLocation = deadEnd;
                //				int count=0;
                do
                {
                    // Initialize the direction picker not to select the dead-end corridor direction
                    DirectionPicker directionPicker = new DirectionPicker(map, currentLocation, map.CalculateDeadEndCorridorDirection(currentLocation));
                    //                    Debug.Log("We have a dead and " + directionPicker);
                    VirtualMap.DirectionType direction = directionPicker.GetNextDirection(map, currentLocation);
                    //					Debug.Log("We choose dir " + direction);
                    if (direction == VirtualMap.DirectionType.None)
                    {
                        throw new InvalidOperationException("Could not remove the dead end!");
                    }
                    //						Debug.Log("Cannot go that way!");
                    else
                    {
                        // Create a corridor in the selected direction
                        currentLocation = map.CreateCorridor(currentLocation, direction);
                    }
                    //					count++;
                } while (map.IsDeadEnd(currentLocation) && currentLocation != deadEnd); // Stop when you intersect an existing corridor, or when you end back to the starting cell (that means we could not remove the dead end, happens with really small maps
                //				Debug.Log("Dead end removed");
            }
        }
    }
    override public void StartDigging(VirtualMap map, CellLocation starting_location, int directionChangeModifier)
    {
        CellLocation currentLocation = starting_location;

        map.MarkAsVisited(currentLocation);

        // Pick a previous direction
        VirtualMap.DirectionType previousDirection = VirtualMap.DirectionType.North;

        // Repeat until all cells have been visited
        while (!map.AllCellsVisited)
        {
            // Get a starting direction
            DirectionPicker directionPicker = new DirectionPicker(map, currentLocation, directionChangeModifier, previousDirection);

            VirtualMap.DirectionType direction = directionPicker.GetNextDirection(map, currentLocation);

            if (direction != VirtualMap.DirectionType.None)
            {
                // Create a corridor in the current cell and flag it as visited
                currentLocation = map.CreateCorridor(currentLocation, direction);
                map.FlagCellAsVisited(currentLocation);
                previousDirection = direction;
            }
            // or start from another visited cell
            // NOTE: This may be less performant!
            else
            {
                currentLocation = map.GetRandomVisitedCell(currentLocation);

                // No visited cell available: proceed from a random unvisited cell
                if (currentLocation.x == -1)
                {
                    currentLocation = map.PickRandomUnvisitedLocation();
                    map.MarkAsVisited(currentLocation);
                }
            }
        }
    }
Beispiel #11
0
    override protected Sprite GetDefault(string defaultName, VirtualMap.DirectionType orientation = VirtualMap.DirectionType.None)
    {
//		Debug.Log (defaultName);
        DaedalusDebugUtils.Assert(loadedSpritesDict.ContainsKey(defaultName), "Cannot find default texture asset " + defaultName);
        return(loadedSpritesDict[defaultName]);
    }
    // Control if we can open a door in the given direction. Open it if possible
    private bool CheckDoorCreation(VirtualMap map, VirtualRoom r, CellLocation start_floor_loc, VirtualMap.DirectionType direction)
    {
        bool         result        = false;
        CellLocation end_floor_loc = map.GetTargetLocation(start_floor_loc, direction);
        CellLocation passage       = map.GetNeighbourCellLocation(start_floor_loc, direction);

        // We get the ending floor and check its validity
        if (end_floor_loc.isValid() && !map.GetCell(end_floor_loc).IsRock())
        {
            // We check whether we are connecting to another room
            if (map.roomCells.Contains(end_floor_loc))
            {
                // Check if we skip creating the door
                if (DungeonGenerator.Random.Instance.Next(0, 100) > doorsDensityModifier && // We do not skip if we request more doors than needed
                    r.IsAlreadyConnectedToARoomAt(end_floor_loc, map))       // We skip if we are already connected
                {
                    return(result);
                }

                OpenRoomDoor(map, r, start_floor_loc, end_floor_loc, passage, direction);
            }
            else
            {
                // We need one door for each corridor segment that has been separated out by this room
                //		To do that, we also create a door if the ending floor is a dead end, effectively getting rid of the dead end
                //		Also, we create if the ending floor is a rock (i.e. 4 walls), which can happen if this room blocks out single floor cells!

                // We check if we need to skip
                if (CheckSkipDoorToCorridor(map, r, end_floor_loc))
                {
                    return(result);
                }

                // Debug.Log("Room " + r + " CREATING TO " + passage);

                OpenCorridorDoor(map, r, start_floor_loc, end_floor_loc, passage, direction);
            }

            result = true;
        }
        return(result);
    }
    /********************
    * Door Creation NEW
    ********************/

    public void OpenRoomDoor(VirtualMap map, VirtualRoom room, CellLocation start_floor_loc, CellLocation end_floor_loc, CellLocation passage_loc, VirtualMap.DirectionType direction)
    {
        //Debug.Log(room);
        // We update both this and the connected room
        foreach (VirtualRoom tr in map.rooms)
        {
            if (tr.containsLocation(end_floor_loc))
            {
                tr.AddDoorToAnotherRoom(passage_loc);
                room.AddDoorToAnotherRoom(passage_loc);
                tr.ConnectRoom(room);
                room.ConnectRoom(tr);
                break;
            }
        }
        OpenDoor(map, start_floor_loc, end_floor_loc, passage_loc, direction);
    }
    virtual protected S[] GetVariations(VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation)
    {
        S[] type_choices = null;
        switch (cell_type)
        {
        case VirtualCell.CellType.CorridorWall:         type_choices = corridorWallVariations;          break;

        case VirtualCell.CellType.CorridorFloor:        type_choices = corridorFloorVariations;         break;

        case VirtualCell.CellType.CorridorColumn:       type_choices = corridorColumnVariations;        break;

        case VirtualCell.CellType.RoomWall:             type_choices = roomWallVariations;                      break;

        case VirtualCell.CellType.RoomFloor:            type_choices = roomFloorVariations;                     break;

        case VirtualCell.CellType.RoomColumn:           type_choices = roomColumnVariations;            break;

        case VirtualCell.CellType.InsideRoomColumn:     type_choices = insideRoomColumnVariations;      break;

        case VirtualCell.CellType.Door:                         type_choices = doorVariations;                          break;

        case VirtualCell.CellType.RoomDoor:                     type_choices = roomDoorVariations;                      break;

        case VirtualCell.CellType.PassageColumn:        type_choices = passageColumnVariations;         break;

        case VirtualCell.CellType.Rock:                         type_choices = rockVariations;                          break;

        case VirtualCell.CellType.CorridorFloorU:       type_choices = corridorFloorUVariations;        break;

        case VirtualCell.CellType.CorridorFloorI:       type_choices = corridorFloorIVariations;        break;

        case VirtualCell.CellType.CorridorFloorL:       type_choices = corridorFloorLVariations;        break;

        case VirtualCell.CellType.CorridorFloorT:       type_choices = corridorFloorTVariations;        break;

        case VirtualCell.CellType.CorridorFloorX:       type_choices = corridorFloorXVariations;        break;

        case VirtualCell.CellType.RoomFloorInside:      type_choices = roomFloorInsideVariations;       break;

        case VirtualCell.CellType.RoomFloorBorder:      type_choices = roomFloorBorderVariations;       break;

        case VirtualCell.CellType.RoomFloorCorner:      type_choices = roomFloorCornerVariations;       break;

        case VirtualCell.CellType.PerimeterWall:        type_choices = perimeterWallVariations;         break;

        case VirtualCell.CellType.PerimeterColumn:      type_choices = perimeterColumnVariations;       break;

        case VirtualCell.CellType.CorridorWallO:        type_choices = corridorWallOVariations;         break;

        case VirtualCell.CellType.CorridorWallU:        type_choices = corridorWallUVariations;         break;

        case VirtualCell.CellType.CorridorWallI:        type_choices = corridorWallIVariations;         break;

        case VirtualCell.CellType.CorridorWallL:        type_choices = corridorWallLVariations;         break;

        case VirtualCell.CellType.CorridorWallT:        type_choices = corridorWallTVariations;         break;

        case VirtualCell.CellType.CorridorWallX:        type_choices = corridorWallXVariations;         break;

        case VirtualCell.CellType.RoomWallO:            type_choices = roomWallOVariations;                     break;

        case VirtualCell.CellType.RoomWallU:            type_choices = roomWallUVariations;                     break;

        case VirtualCell.CellType.RoomWallI:            type_choices = roomWallIVariations;                     break;

        case VirtualCell.CellType.RoomWallL:            type_choices = roomWallLVariations;                     break;

        case VirtualCell.CellType.RoomWallT:            type_choices = roomWallTVariations;                     break;

        case VirtualCell.CellType.RoomWallX:            type_choices = roomWallXVariations;                     break;

        default: Debug.LogError("No prefab for cell type " + cell_type); break;
        }
        return(type_choices);
    }
    protected void AddFillingFloors(VirtualMap map, VirtualCell conversion_cell)
    {
        if (conversion_cell.Type == VirtualCell.CellType.None)
        {
            return;
        }

        // Fill with floors
        VirtualCell.CellType     initial_type = conversion_cell.Type;
        VirtualMap.DirectionType initial_dir  = conversion_cell.Orientation;
        bool addedFloor = false;

        if (behaviour.fillWithFloors)
        {
            bool mayBeDirectional = false;
            if (CheckRoom(map, conversion_cell.location))
            {
                if (conversion_cell.IsDoor() || conversion_cell.IsEmpty())
                {
                    AddToCorrectRoom(map, conversion_cell.location);
                    conversion_cell.Type = VirtualCell.CellType.RoomFloor;
                    ConvertDirectionalRoomFloor(map, conversion_cell);
                    mayBeDirectional = true;
                }
                else
                {
                    conversion_cell.Type = VirtualCell.CellType.RoomFloor;
                }
            }
            else
            {
                if (conversion_cell.IsDoor() || conversion_cell.IsEmpty())
                {
                    conversion_cell.Type = VirtualCell.CellType.CorridorFloor;
                    ConvertDirectionalCorridorFloor(map, conversion_cell);
                    mayBeDirectional = true;
                }
                else
                {
                    conversion_cell.Type = VirtualCell.CellType.CorridorFloor;
                }
            }
            ConvertFloor(map, conversion_cell, mayBeDirectional);
            addedFloor = true;
        }
        else
        {
            // Special case: when not filling with floors AND we do not draw doors, we still need to place a floor underneath the empty passage representing the doors!
            if (conversion_cell.IsEmpty())                      // Decomment this if you want floors underneath doors ALWAYS: // || input_cell.IsDoor()){
            {
                conversion_cell.Type = VirtualCell.CellType.CorridorFloor;
                ConvertDirectionalCorridorFloor(map, conversion_cell);
                ConvertFloor(map, conversion_cell);
                addedFloor = true;
            }
        }

        if (addedFloor)
        {
            // The initial type is switched in, the floor becomes a subtype
            VirtualCell.CellType     new_subtype = conversion_cell.Type;
            VirtualMap.DirectionType new_dir     = conversion_cell.Orientation;
            conversion_cell.Type        = initial_type;
            conversion_cell.Orientation = initial_dir;
            conversion_cell.AddCellInstance(new_subtype, new_dir);
        }
    }
 public void OpenCorridorDoor(VirtualMap map, VirtualRoom room, CellLocation start_floor_loc, CellLocation end_floor_loc, CellLocation passage_loc, VirtualMap.DirectionType direction)
 {
     room.corridorExit++;
     room.corridorDoors.Add(passage_loc);
     OpenDoor(map, start_floor_loc, end_floor_loc, passage_loc, direction);
 }
    public void OpenDoor(VirtualMap map, CellLocation start_floor_loc, CellLocation end_floor_loc, CellLocation passage_loc, VirtualMap.DirectionType direction)
    {
        map.GetCell(passage_loc).Type        = VirtualCell.CellType.Door;
        map.GetCell(passage_loc).Orientation = direction;

        // We also connect the cells
        map.ConnectCells(start_floor_loc, end_floor_loc);
    }
Beispiel #18
0
    override public void CreateObject(VirtualMap map, MetricLocation l, VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation)
    {
        Texture2D tile_texture = null;

        tile_texture = behaviour.GetPrefab(cell_type);

        GameObject go = (GameObject)GameObject.Instantiate(behaviour.tilePrefab, new Vector3(l.x * behaviour.tileSize, 0, l.y * behaviour.tileSize), Quaternion.identity);

        var tempMaterial = new Material(go.transform.GetComponent <Renderer>().sharedMaterial);

        tempMaterial.SetTexture("_MainTex", tile_texture);
        tempMaterial.name = cell_type.ToString() + "_Material";
        go.transform.GetComponent <Renderer>().sharedMaterial = tempMaterial;

        if (createdMaterialsList == null)
        {
            createdMaterialsList = new List <Material>();
        }
        createdMaterialsList.Add(tempMaterial);

        go.name = cell_type.ToString();
        AddToMapGameObject(cell_type, go);


        go.transform.localEulerAngles = new Vector3(0, 0, 0);
        switch (orientation)
        {
        case VirtualMap.DirectionType.West:     go.transform.localEulerAngles = new Vector3(0, 0, 0);  break;

        case VirtualMap.DirectionType.North:    go.transform.localEulerAngles = new Vector3(0, 90, 0); break;

        case VirtualMap.DirectionType.East:     go.transform.localEulerAngles = new Vector3(0, 180, 0); break;

        case VirtualMap.DirectionType.South:    go.transform.localEulerAngles = new Vector3(0, 270, 0); break;
        }

        // Move walls up a bit
        if (VirtualCell.IsFloor(cell_type))
        {
            // Already good
        }
        else
        {
            go.transform.localPosition += Vector3.up * 0.01f;
        }
    }
Beispiel #19
0
 public void AddCellInstance(VirtualCell.CellType type, VirtualMap.DirectionType dir)
 {
     // TODO: Should we check if we add two times the same type?
     this.instances.Add(new CellInstance(type, dir));
 }
    override public void CreateObject(VirtualMap map, MetricLocation l, VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation)
    {
        GameObject prefab = behaviour.GetPrefab(cell_type);

        DaedalusDebugUtils.Assert(prefab != null, "No variation was chosen for " + cell_type);

//		Debug.Log (cell_type);
        GameObject go = (GameObject)GameObject.Instantiate(prefab, new Vector3(l.x * behaviour.tileSize, l.storey * (behaviour.wallHeight + behaviour.storeySeparationHeight), l.y * behaviour.tileSize), Quaternion.identity);

        go.name = cell_type.ToString();

        switch (orientation)
        {
        case VirtualMap.DirectionType.West:     go.transform.localEulerAngles = new Vector3(0, 180, 0); break;

        case VirtualMap.DirectionType.North:    go.transform.localEulerAngles = new Vector3(0, 270, 0); break;

        case VirtualMap.DirectionType.East:     break;

        case VirtualMap.DirectionType.South:    go.transform.localEulerAngles = new Vector3(0, 90, 0); break;
        }

        // Checking orientation and position for ceiling
        if (cell_type == VirtualCell.CellType.CorridorCeiling || cell_type == VirtualCell.CellType.RoomCeiling)
        {
            Vector3 tmpPos = go.transform.position;
            tmpPos.y += behaviour.wallHeight;
            go.transform.position = tmpPos;

            Vector3 tmpRot = go.transform.localEulerAngles;
            tmpRot.x = 180;
            go.transform.localEulerAngles = tmpRot;
        }

        bool isDynamicCell = GetIsDynamicCell(cell_type);

        AddToMapGameObject(cell_type, go, isDynamicCell, l.storey);
    }
    override public void CreateObject(VirtualMap map, MetricLocation l, VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation)
    {
        GameObject prefab = behaviour.GetPrefab(cell_type);

        DaedalusDebugUtils.Assert(prefab != null, "No variation was chosen for " + cell_type);

        GameObject go = (GameObject)GameObject.Instantiate(prefab, new Vector3(l.x * behaviour.tileSize, l.storey * (behaviour.wallHeight + behaviour.storeySeparationHeight), l.y * behaviour.tileSize), Quaternion.identity);

        go.name = cell_type.ToString();

        if (orientation == VirtualMap.DirectionType.None)
        {
            orientation = VirtualMap.DirectionType.North;
        }
        switch (orientation)
        {
        case VirtualMap.DirectionType.West:     go.transform.localEulerAngles = new Vector3(0, 180, 0);  break;

        case VirtualMap.DirectionType.North:    go.transform.localEulerAngles = new Vector3(0, 270, 0); break;

        case VirtualMap.DirectionType.East:     go.transform.localEulerAngles = new Vector3(0, 0, 0); break;

        case VirtualMap.DirectionType.South:    go.transform.localEulerAngles = new Vector3(0, 90, 0); break;
        }
        go.transform.localEulerAngles += new Vector3(0, 180, 0);                // Orientation fix


        AddToMapGameObject(cell_type, go, cell_type == VirtualCell.CellType.Door, l.storey);
    }
Beispiel #22
0
    // Create a corridor between one cell and another, digging the passage in-between.
    // This will make sure that the starting floor and the end floor become corridor floors, if they are ROCKS or NONEs
    public CellLocation CreateCorridor(CellLocation zero_starting_location, VirtualMap.DirectionType direction, int corridor_width = 1, bool makeDoor = false)
    {
        // NOTE: we do not drill room walls (unless we make doors)
        VirtualCell  cell;
        CellLocation target_location = default(CellLocation);

        // CHECK whether there is enough corridor space (NOTE: this only works for corridor_width=2)
        while (LocationIsOutsideBounds(GetNeighbourCellLocationAtStep(zero_starting_location, GetDirectionClockwise(direction, 1), (2 * (corridor_width - 1)))))
        {
            Debug.LogWarning("Decreasing corridor width to due to out of bounds problems!");
            corridor_width--;
        }

        for (int cw = 0; cw < corridor_width; cw++)
        {
            CellLocation starting_location = GetNeighbourCellLocationAtStep(zero_starting_location, GetDirectionClockwise(direction, 1), 2 * cw);

            // Starting
            cell = this.GetCell(starting_location);
            if (cell.IsRock() || cell.IsNone())
            {
                cell.Type = VirtualCell.CellType.CorridorFloor;
            }

            // Target
            target_location = GetTargetLocation(starting_location, direction);
            cell            = this.GetCell(target_location);
            //if (cell.IsFloor()) break; // NO! Already !
            if (cell.IsRock() || cell.IsNone())
            {
                cell.Type = VirtualCell.CellType.CorridorFloor;
            }


            //		cell.Orientation = direction;	// This is removed, because the directional tiles will take care of this instead

            // Connection passage
            CellLocation connection_location = GetNeighbourCellLocation(starting_location, direction);
            cell = this.GetCell(connection_location);
            if (cell.Type == VirtualCell.CellType.CorridorWall)
            {
                cell.Type = VirtualCell.CellType.EmptyPassage;
                ConnectCells(starting_location, target_location);
            }
            else if (cell.Type == VirtualCell.CellType.RoomWall && makeDoor && CheckDoorCreation(cw, corridor_width))
            {
                cell.Type        = VirtualCell.CellType.Door;
                cell.Orientation = direction;   // Force orientation for doors, or it will crash
                ConnectCells(starting_location, target_location);
            }
            //		cell.Orientation = direction;		// Setting this would just change randomly the direction of some walls in tilemaps. This is removed for now!

            // We also create walls around the digging, UNLESS there are already floors there (or out of bounds) (as we already have the walls)
            VirtualMap.DirectionType clockwise_dir         = GetDirectionClockwise(direction, 1);
            VirtualMap.DirectionType counter_clockwise_dir = GetDirectionClockwise(direction, -1);
            CellLocation             neigh_same_loc;

            // Sides back
            if (!IsInRoom(starting_location))
            {
                if (cw == corridor_width - 1)
                {
                    neigh_same_loc = this.GetNeighbourCellLocationOfSameType(starting_location, clockwise_dir);
                    if (LocationIsOutsideBounds(neigh_same_loc) ||
                        this.GetCell(neigh_same_loc).Type != VirtualCell.CellType.CorridorFloor)
                    {
                        VirtualCell other_cell = this.GetCell(this.GetNeighbourCellLocation(starting_location, clockwise_dir));
                        if (other_cell.Type == VirtualCell.CellType.EmptyPassage)
                        {
                            other_cell.Type = VirtualCell.CellType.CorridorWall;
                        }
                    }
                }

                if (cw == 0)
                {
                    neigh_same_loc = this.GetNeighbourCellLocationOfSameType(starting_location, counter_clockwise_dir);
                    if (LocationIsOutsideBounds(neigh_same_loc) ||
                        this.GetCell(neigh_same_loc).Type != VirtualCell.CellType.CorridorFloor)
                    {
                        VirtualCell other_cell = this.GetCell(this.GetNeighbourCellLocation(starting_location, counter_clockwise_dir));
                        if (other_cell.Type == VirtualCell.CellType.EmptyPassage)
                        {
                            other_cell.Type = VirtualCell.CellType.CorridorWall;
                        }
                    }
                }
            }

            // Sides front
            if (!IsInRoom(target_location))
            {
                if (cw == corridor_width - 1)
                {
                    neigh_same_loc = this.GetNeighbourCellLocationOfSameType(target_location, clockwise_dir);
                    if (LocationIsOutsideBounds(neigh_same_loc) ||
                        this.GetCell(neigh_same_loc).Type != VirtualCell.CellType.CorridorFloor)
                    {
                        VirtualCell other_cell = this.GetCell(this.GetNeighbourCellLocation(target_location, clockwise_dir));
                        if (other_cell.Type == VirtualCell.CellType.EmptyPassage)
                        {
                            other_cell.Type = VirtualCell.CellType.CorridorWall;
                        }
                    }
                }

                if (cw == 0)
                {
                    neigh_same_loc = this.GetNeighbourCellLocationOfSameType(target_location, counter_clockwise_dir);
                    if (LocationIsOutsideBounds(neigh_same_loc) ||
                        this.GetCell(neigh_same_loc).Type != VirtualCell.CellType.CorridorFloor)
                    {
                        VirtualCell other_cell = this.GetCell(this.GetNeighbourCellLocation(target_location, counter_clockwise_dir));
                        if (other_cell.Type == VirtualCell.CellType.EmptyPassage)
                        {
                            other_cell.Type = VirtualCell.CellType.CorridorWall;
                        }
                    }
                }
            }

            // Back
            if (!IsInRoom(starting_location))
            {
                neigh_same_loc = this.GetNeighbourCellLocationOfSameType(starting_location, GetDirectionOpposite(direction));
                if (LocationIsOutsideBounds(neigh_same_loc) ||
                    this.GetCell(neigh_same_loc).Type != VirtualCell.CellType.CorridorFloor)
                {
                    VirtualCell other_cell = this.GetCell(this.GetNeighbourCellLocation(starting_location, GetDirectionOpposite(direction)));
                    if (other_cell.Type == VirtualCell.CellType.EmptyPassage)
                    {
                        other_cell.Type = VirtualCell.CellType.CorridorWall;
                    }
                }
            }

            // Front
            if (!IsInRoom(target_location))
            {
                neigh_same_loc = this.GetNeighbourCellLocationOfSameType(target_location, direction);
                if (LocationIsOutsideBounds(neigh_same_loc) ||
                    this.GetCell(neigh_same_loc).Type != VirtualCell.CellType.CorridorFloor)
                {
                    VirtualCell other_cell = this.GetCell(this.GetNeighbourCellLocation(target_location, direction));
                    if (other_cell.Type == VirtualCell.CellType.EmptyPassage)
                    {
                        other_cell.Type = VirtualCell.CellType.CorridorWall;
                    }
                }
            }
        }


        return(target_location);
    }
    protected void BuildObject(VirtualMap map, CellLocation loc, int storey, VirtualCell.CellType type, VirtualMap.DirectionType dir)
    {
        if (type == VirtualCell.CellType.None || type == VirtualCell.CellType.EmptyPassage)
        {
            return;                                                                                             // TODO: Maybe this check should be in the physical map
        }
//				Debug.Log (loc + "  " + type);
        MetricLocation metricLocation = GetWorldLocation(loc, storey);

        physical_map.CreateObject(map, metricLocation, type, dir);
    }
    override protected GameObjectChoice[] GetVariations(VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation = VirtualMap.DirectionType.None)
    {
        if (orientation == VirtualMap.DirectionType.None)
        {
            orientation = VirtualMap.DirectionType.North;
        }
        // Treats floors as prefab sections
        GameObjectChoice[] type_choices = null;
        switch (cell_type)
        {
        case VirtualCell.CellType.CorridorFloorU:
            switch (orientation)
            {
            case VirtualMap.DirectionType.East: type_choices = sectionUVariations_E; break;

            case VirtualMap.DirectionType.North: type_choices = sectionUVariations_N; break;

            case VirtualMap.DirectionType.West: type_choices = sectionUVariations_W; break;

            case VirtualMap.DirectionType.South: type_choices = sectionUVariations_S; break;
            }
            break;

        case VirtualCell.CellType.CorridorFloorI:
            switch (orientation)
            {
            case VirtualMap.DirectionType.East: type_choices = sectionIVariations_WE; break;

            case VirtualMap.DirectionType.North: type_choices = sectionIVariations_NS; break;

            case VirtualMap.DirectionType.West: type_choices = sectionIVariations_WE; break;

            case VirtualMap.DirectionType.South: type_choices = sectionIVariations_NS; break;
            }
            break;

        case VirtualCell.CellType.CorridorFloorL:
            switch (orientation)
            {
            case VirtualMap.DirectionType.East: type_choices = sectionLVariations_SE; break;

            case VirtualMap.DirectionType.North: type_choices = sectionLVariations_NE; break;

            case VirtualMap.DirectionType.West:  type_choices = sectionLVariations_NW; break;

            case VirtualMap.DirectionType.South: type_choices = sectionLVariations_SW; break;
            }
            break;

        case VirtualCell.CellType.CorridorFloorT:
            switch (orientation)
            {
            case VirtualMap.DirectionType.East: type_choices = sectionTVariations_XE; break;

            case VirtualMap.DirectionType.North: type_choices = sectionTVariations_XN; break;

            case VirtualMap.DirectionType.West:  type_choices = sectionTVariations_XW; break;

            case VirtualMap.DirectionType.South: type_choices = sectionTVariations_XS; break;
            }
            break;

        case VirtualCell.CellType.CorridorFloorX: type_choices = sectionXVariations; break;

        default: type_choices = base.GetVariations(cell_type, orientation); break;
        }
        return(type_choices);
    }
Beispiel #25
0
    override public void CreateObject(VirtualMap map, MetricLocation l, VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation)
    {
        GameObject prefab = behaviour.GetPrefab(cell_type);

        DaedalusDebugUtils.Assert(prefab != null, "No variation was chosen for " + cell_type);

        GameObject go = (GameObject)GameObject.Instantiate(prefab, new Vector3(l.x * behaviour.tileSize, 0, l.y * behaviour.tileSize), Quaternion.identity);

        go.name = cell_type.ToString();

        if (orientation == VirtualMap.DirectionType.None)
        {
            orientation = VirtualMap.DirectionType.North;
        }
        switch (orientation)
        {
        case VirtualMap.DirectionType.West:     go.transform.localEulerAngles = new Vector3(90, 0, 0);  break;

        case VirtualMap.DirectionType.North:    go.transform.localEulerAngles = new Vector3(90, 90, 0); break;

        case VirtualMap.DirectionType.East:     go.transform.localEulerAngles = new Vector3(90, 180, 0); break;

        case VirtualMap.DirectionType.South:    go.transform.localEulerAngles = new Vector3(90, 270, 0); break;
        }

        AddToMapGameObject(cell_type, go, cell_type == VirtualCell.CellType.Door, l.storey);

        // Move walls up a bit
        if (VirtualCell.IsFloor(cell_type))
        {
            // Already good
        }
        else
        {
            go.transform.localPosition += Vector3.up * 0.01f;
        }
    }
    // Control if we can open a door in the given direction. Open it if possible
    private void CreateDoor(VirtualMap map, VirtualRoom r, RoomGenerator roomGenerator, CellLocation start_floor_loc, CellLocation end_floor_loc, VirtualMap.DirectionType direction)
    {
        CellLocation passage = map.GetNeighbourCellLocation(start_floor_loc, direction);

        // We check whether we are connecting to another room
        if (map.IsRoomFloor(end_floor_loc))
        {
            // Room-to-room door
            roomGenerator.OpenRoomDoor(map, r, start_floor_loc, end_floor_loc, passage, direction);
        }
        else
        {
            // Room-to-corridor door
            roomGenerator.OpenCorridorDoor(map, r, start_floor_loc, end_floor_loc, passage, direction);
        }
    }
    override public void CreateObject(VirtualMap map, MetricLocation l, VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation)
    {
        GameObject go = null;

        if (alreadyCreated && currentIndex < spawnedSpriteGos.Count)
        {
            go = spawnedSpriteGos[currentIndex];
            currentIndex++;
        }
        else
        {
            go = (GameObject)GameObject.Instantiate(behaviour.spritePrefab, new Vector3(l.x * behaviour.tileSize, 0, l.y * behaviour.tileSize), Quaternion.identity);
            spawnedSpriteGos.Add(go);
        }

        Sprite sprite = behaviour.GetPrefab(cell_type);

        go.GetComponent <SpriteRenderer>().sprite = sprite;

        go.name = cell_type.ToString();
        go.GetComponent <BoxCollider2D>().size = new Vector2(behaviour.tileSize, behaviour.tileSize);
        AddToMapGameObject(cell_type, go);

//		Debug.Log ("Cell at " + l.x+"-"+l.y + " has orientation " + orientation);

        go.transform.localEulerAngles = new Vector3(90, 0, 0);
        switch (orientation)
        {
        case VirtualMap.DirectionType.West:     go.transform.localEulerAngles = new Vector3(90, 0, 0);  break;

        case VirtualMap.DirectionType.North:    go.transform.localEulerAngles = new Vector3(90, 90, 0); break;

        case VirtualMap.DirectionType.East:     go.transform.localEulerAngles = new Vector3(90, 180, 0); break;

        case VirtualMap.DirectionType.South:    go.transform.localEulerAngles = new Vector3(90, 270, 0); break;
        }


        // Move walls up a bit
        if (VirtualCell.IsFloor(cell_type))
        {
            // Already good
        }
        else
        {
            go.transform.localPosition += Vector3.up * 0.01f;
        }

        if (cell_type == VirtualCell.CellType.DoorHorizontalBottom)
        {
            go.transform.localPosition += Vector3.forward * behaviour.tileSize * 0.25f;
        }
    }
Beispiel #28
0
    override protected GameObjectChoice[] GetVariations(VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation = VirtualMap.DirectionType.None)
    {
        GameObjectChoice[] type_choices = null;
        //Debug.Log(cell_type);
        switch (cell_type)
        {
        case VirtualCell.CellType.CorridorCeiling:      type_choices = corridorCeilingVariations;               break;

        case VirtualCell.CellType.RoomCeiling:          type_choices = roomCeilingVariations;                   break;

        case VirtualCell.CellType.Ladder:                       type_choices = ladderVariations;                                break;

        case VirtualCell.CellType.Ladder2:                      type_choices = ladder2Variations;                               break;

        default: type_choices = base.GetVariations(cell_type, orientation); break;
        }
        return(type_choices);
    }
Beispiel #29
0
 public CellInstance(VirtualCell.CellType type, VirtualMap.DirectionType dir)
 {
     this.type = type;
     this.dir  = dir;
 }
 override protected GameObjectChoice[] GetVariations(VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation = VirtualMap.DirectionType.None)
 {
 
     // Treats floors as prefab sections
     GameObjectChoice[] type_choices = null;
     switch (cell_type)
     {
         case VirtualCell.CellType.CorridorFloorU: type_choices = sectionUVariations; break;
         case VirtualCell.CellType.CorridorFloorI: type_choices = sectionIVariations; break;
         case VirtualCell.CellType.CorridorFloorL: type_choices = sectionLVariations; break;
         case VirtualCell.CellType.CorridorFloorT: type_choices = sectionTVariations; break;
         case VirtualCell.CellType.CorridorFloorX: type_choices = sectionXVariations; break;
         //case VirtualCell.CellType.Ladder:         type_choices = sectionLadderVariations; break;
         default: type_choices = base.GetVariations(cell_type, orientation); break;
     }
     return type_choices;
 }