Beispiel #1
0
    public void CreateRoom(Guid roomId, Enums.RoomTypes roomType, Enums.RoomSizes roomSize, Enums.RoomOverUnder roomOverUnder, GridIndex leftMostIndex)
    {
        RoomDefData RoomDefData = RoomFactory.Ref.GetRoomDefData(roomType, roomSize, roomOverUnder);

        RoomInstanceData RoomData = new RoomInstanceData();

        RoomData.RoomId              = roomId;
        RoomData.RoomName            = RoomDefData.RoomName;
        RoomData.RoomSize            = RoomDefData.RoomSize;
        RoomData.RoomCategory        = RoomDefData.RoomCategory;
        RoomData.RoomType            = RoomDefData.RoomType;
        RoomData.RoomOverUnder       = RoomDefData.RoomOverUnder;
        RoomData.ManSlotCount        = RoomDefData.ManSlotCount;
        RoomData.ManSlotsPositions   = new Vector3[RoomDefData.ManSlotCount];    // Data will be set by object script on Start()
        RoomData.ManSlotsRotations   = new Quaternion[RoomDefData.ManSlotCount]; // Data will be set by object script on Start()
        RoomData.ManSlotsAssignments = new Guid[RoomDefData.ManSlotCount];
        for (int i = 0; i < RoomData.ManSlotCount; i++)
        {
            RoomData.ManSlotsAssignments[i] = Guid.Empty;
        }
        RoomData.ManWorkingStates = RoomDefData.ManWorkingStates;
        RoomData.CoveredIndizes   = GridManager.Ref.GetOccupiedindizes(roomSize, leftMostIndex);

        CreateRoom(RoomData);
    }
Beispiel #2
0
 public void SetRoomInfoData(Enums.RoomSizes roomSize, Enums.RoomTypes roomType, Enums.RoomOverUnder roomOverUnder, GridIndex leftMostIndex)
 {
     RoomSize      = roomSize;
     RoomType      = roomType;
     RoomOverUnder = roomOverUnder;
     LeftmostIndex = leftMostIndex;
 }
Beispiel #3
0
    public GameObject CreateRoom(Enums.RoomTypes roomType, Enums.RoomSizes roomSize, Enums.RoomOverUnder roomOverUnder)
    {
        RoomDefData DefData    = GetRoomDefData(roomType, roomSize, roomOverUnder);
        GameObject  RoomObject = LoadRoom(DefData);

        RoomObject.SetActive(true);
        return(RoomObject);
    }
Beispiel #4
0
    // When a new room is created, set grid indizes and internal links accordingly
    public void RegisterAtGrid(Enums.RoomSizes roomSize, Guid roomId, GridIndex leftMostIndex)
    {
        GridIndex[] Occupiedindizes = GetOccupiedindizes(roomSize, leftMostIndex);

        for (int i = 0; i < Occupiedindizes.Length; i++)
        {
            _GridData[Occupiedindizes[i].X, Occupiedindizes[i].Y, Occupiedindizes[i].Z] = new TileData(true, roomId, roomSize);
        }

        LinkRoom(Occupiedindizes); // Calculate and store movements to other grid elements
    }
Beispiel #5
0
    // When a room is removed, set grid indizes accordingly
    public void DeregisterFromGrid(GridIndex leftMostIndex, Enums.RoomSizes roomSize)
    {
        GridIndex[] Occupiedindizes = GetOccupiedindizes(roomSize, leftMostIndex);

        for (int i = 0; i < Occupiedindizes.Length; i++)
        {
            _GridData[Occupiedindizes[i].X, Occupiedindizes[i].Y, Occupiedindizes[i].Z] = new TileData();
        }

        UnlinkRoom(Occupiedindizes); // Remove movements to other grid elements
    }
Beispiel #6
0
    public RoomDefData GetRoomDefData(Enums.RoomTypes roomType, Enums.RoomSizes roomSize, Enums.RoomOverUnder roomOverUnder)
    {
        foreach (RoomDefData DefData in Constants.RoomDefinitions)
        {
            if ((DefData.RoomType == roomType) && (DefData.RoomSize == roomSize) && (DefData.RoomOverUnder == roomOverUnder))
            {
                return(DefData);
            }
        }

        Debug.Assert(1 == 0);
        return(Constants.RoomDefinitions[0]);
    }
Beispiel #7
0
    public GridIndex[] GetPossibleBuildingindizes(Enums.RoomSizes roomSize)
    {
        // Note: Returning only the leftmost index per possible location, as this is reference for building

        // Building Rules:
        // We can build rooms of size 1/2/4/6 right and left of of existing rooms
        // We can build room size 1 below and above existing size 1 rooms

        List <GridIndex> indexList = new List <GridIndex>();

        CheckBuildingPositionsInRange(0, Constants.GridSizeY, roomSize, ref indexList);

        return(indexList.ToArray());  // Can also be empty
    }
Beispiel #8
0
 // NOTE: OverUnder is defaulted to NEUTRAL, meaning the room will be buildable above and below ground unless otherwise specified!!!
 public RoomDefData(string roomName, string roomModelFile,
                    Enums.RoomSizes roomSize, Enums.RoomTypes roomType, Enums.RoomCategories roomCategory,
                    int manSlotCount, Enums.ManStates[] manWorkingStates,
                    string roomDescription, Enums.RoomOverUnder overUnder = Enums.RoomOverUnder.Neutral)
 {
     _RoomName         = roomName;
     _RoomModelFile    = roomModelFile;
     _RoomSize         = roomSize;
     _RoomType         = roomType;
     _RoomCategory     = roomCategory;
     _ManSlotCount     = manSlotCount;
     _ManWorkingStates = manWorkingStates;
     _RoomDescription  = roomDescription;
     _RoomOverUnder    = overUnder;
 }
Beispiel #9
0
    public GridIndex[] GetOccupiedindizes(Enums.RoomSizes roomSize, GridIndex leftMostIndex)
    {
        if (leftMostIndex == null)
        {
            throw new ArgumentNullException("leftMostIndex");
        }

        GridIndex[] Occupiedindizes;

        if (roomSize == Enums.RoomSizes.Size1)
        {
            Occupiedindizes = new GridIndex[] { new GridIndex(leftMostIndex), leftMostIndex.GetBack() }
        }
        ;
        else
        {
            Occupiedindizes = leftMostIndex.GetLeft().GetRight((int)roomSize);
        }

        return(Occupiedindizes);
    }
Beispiel #10
0
    void CheckLeftRightBuildingPositions(GridIndex index, Enums.RoomSizes roomSize, ref List <GridIndex> indexList)
    {
        // Left check
        GridIndex[] indizes = index.GetLeft((int)roomSize);
        if (GridIndex.IsValid(indizes) && IsGridAreaFree(indizes))
        {
            if (indexList.Contains(indizes[0]) == false)
            {
                indexList.Add(indizes[0]);
            }
        }

        // Right check
        indizes = index.GetRight((int)roomSize);
        if (GridIndex.IsValid(indizes) && IsGridAreaFree(indizes))
        {
            if (indexList.Contains(indizes[0]) == false)
            {
                indexList.Add(indizes[0]);
            }
        }
    }
Beispiel #11
0
    void CheckBuildingPositionsInRange(int y0, int y1, Enums.RoomSizes roomSize, ref List <GridIndex> indexList)
    {
        // Only checking the front plane for this (Z = 0)
        for (int y = y0; y < y1; y++)
        {
            for (int x = 0; x < Constants.GridSizeX; x++)
            {
                GridIndex index = new GridIndex(x, y, 0); // Grid index we now look at
                if (_GridData[index.X, index.Y, 0].Occupied == false)
                {
                    continue;                                                   // Nothing there, so can not build next to it
                }
                // Special for size1 room: We can build above/below a size one
                if ((roomSize == _GridData[x, y, 0].RoomSize) && (roomSize == Enums.RoomSizes.Size1))
                {
                    CheckAboveBelowBuildingPositions(index, ref indexList);
                }

                CheckLeftRightBuildingPositions(index, roomSize, ref indexList);
            }
        }
    }
Beispiel #12
0
 public bool IsGridAreaFree(GridIndex leftMostIndex, Enums.RoomSizes roomSize)
 {
     GridIndex[] Occupiedindizes = GetOccupiedindizes(roomSize, leftMostIndex);
     return(IsGridAreaFree(Occupiedindizes));
 }
Beispiel #13
0
 private void InitiateBuilding(Enums.RoomSizes RoomSize, Enums.RoomTypes RoomType, Enums.RoomOverUnder RoomOverUnder = Enums.RoomOverUnder.Neutral)
 {
     StateManager.Ref.SetGameState(Enums.GameStates.BuildRoom);
     GridIndex[] BuildingIndexArray = GridManager.Ref.GetPossibleBuildingindizes(RoomSize);
     BuildManager.Ref.ShowRoomPositionSelectors(BuildingIndexArray, RoomType, RoomSize, RoomOverUnder);
 }
Beispiel #14
0
 public void Build_Finished(Enums.RoomSizes roomSize, Enums.RoomTypes roomType, Enums.RoomOverUnder roomOverUnder, GridIndex index)
 {
     HideRoomPositionSelectors();
     RoomManager.Ref.CreateRoom(Guid.NewGuid(), roomType, roomSize, roomOverUnder, index);
 }
Beispiel #15
0
    public void ShowRoomPositionSelectors(GridIndex[] indexArray, Enums.RoomTypes roomType, Enums.RoomSizes roomSize, Enums.RoomOverUnder overUnder)
    {
        if (indexArray == null)
        {
            return;
        }

        if (indexArray.Length == 0)
        {
            StateManager.Ref.SetGameState(Enums.GameStates.Normal);
            GuiManager.Ref.Initiate_UserInfoSmall("Sorry, can't build a room of this type now!");
            return;
        }

        for (int i = 0; i < indexArray.Length; i++)
        {
            Debug.Assert(roomSize != Enums.RoomSizes.None);

            //CHECK TO SEE IF BUILDING IS UNDER/OVERWORLD, SKIP TO NEXT ITERATION IF POSITION IS NOT COMPATIBLE WITH OVERUNDER TYPE
            int yPos = indexArray[i].Y;

            if ((yPos < Constants.GridSurfaceY && (int)overUnder == 1) ||
                (yPos >= Constants.GridSurfaceY && (int)overUnder == -1))
            {
                continue;
            }

            GameObject go = Instantiate(Resources.Load <GameObject>(Constants.RoomBuildSelectorModels[roomSize]));
            Debug.Assert(go != null);

            go.transform.position = GridManager.Ref.GetWorldPositionFromGridIndex(indexArray[i]);

            go.transform.GetComponent <BuildPositionScript>().SetRoomInfoData(roomSize, roomType, overUnder, indexArray[i]);
            go.SetActive(true);

            RoomPositionSelectors.Add(go);
        }
    }
Beispiel #16
0
 public TileData(bool occupied, Guid roomId, Enums.RoomSizes roomSize)
 {
     _Occupied = occupied; // A room has been built here already
     _RoomId   = roomId;
     _RoomSize = roomSize;
 }