Beispiel #1
0
        private bool SelectRoomTemplates(Random rng, out string result)
        {
            List <RoomTemplate> filteredRoomTemplates = new List <RoomTemplate>();
            bool success = true;

            result = SuccessMessages.GENERAL_SUCCESS;

            for (RoomIndexIterator iterator = new RoomIndexIterator(m_roomGrid);
                 success && iterator.Valid;
                 iterator.Next())
            {
                RoomIndex  roomIndex = iterator.Current;
                RoomLayout room      = GetRoomByIndex(roomIndex);

                filteredRoomTemplates.Clear();
                m_roomTemplateSet.GetTemplatesWithPortalBitmask(room.portalRoomSideBitmask, filteredRoomTemplates);

                if (filteredRoomTemplates.Count > 0)
                {
                    RoomTemplate roomTemplate = filteredRoomTemplates[rng.Next(filteredRoomTemplates.Count)];

                    room.static_room_data.room_template_name = roomTemplate.TemplateName;
                }
                else
                {
                    result  = ErrorMessages.MISSING_ROOM_TEMPLATE;
                    success = false;
                }
            }

            return(success);
        }
Beispiel #2
0
        private bool CreateEnergyTanks(
            Random rng,
            out String result)
        {
            bool success = true;

            result = SuccessMessages.GENERAL_SUCCESS;

            for (RoomIndexIterator iterator = new RoomIndexIterator(m_roomGrid);
                 success && iterator.Valid;
                 iterator.Next())
            {
                RoomIndex    roomIndex    = iterator.Current;
                RoomLayout   room         = GetRoomByIndex(roomIndex);
                RoomTemplate roomTemplate = m_roomTemplateSet.GetTemplateByName(room.static_room_data.room_template_name);

                foreach (EnergyTankTemplate energyTankTemplate in roomTemplate.EnergyTankTemplates)
                {
                    //TODO: CreateEnergyTanks - Scale back energy tank distribution based on difficulty
                    EnergyTank energyTank = EnergyTank.CreateEnergyTank(room.room_key, energyTankTemplate);

                    room.energyTanks.Add(energyTank);
                }
            }

            return(success);
        }
Beispiel #3
0
    bool checkRoomSide(RoomData nextRoom, RoomIndex doorIndex, DoorDirection direction, Dictionary <RoomIndex, Door> doorDictionary, ref List <DoorHelperClass> doorsToClose)
    {
        Door doorAtIndex;

        bool hasCorrespondingDoor = true;

        if (doorDictionary.TryGetValue(doorIndex, out doorAtIndex))
        {
            bool found = false;
            foreach (Door door in nextRoom.doors)
            {
                if (door.Direction == direction && door.WorldIndex == doorIndex)
                {
                    doorsToClose.Add(new DoorHelperClass(doorAtIndex, doorIndex));
                    found = true;
                }
            }
            if (!found)
            {
                hasCorrespondingDoor = false;
            }
        }

        return(hasCorrespondingDoor);
    }
Beispiel #4
0
    RoomParam CreateRoom(RoomIndex coordonates)
    {
        (List <TileParam> groundTilesParam, List <TileParam> outerWallTilesParam) = CreateBoard();
        List <Vector3Int> gridPositions = new List <Vector3Int>();

        InitialiseList(gridPositions);
        List <TileParam> wallTilesParam = LayoutTileAtRandom(gridPositions, wallTiles, wallCount.minimum, wallCount.maximum);
        //List<ObjectParam> objectsParam = LayoutObjectAtRandom(gridPositions, enemyTiles, 0, 2);
        List <UnitParam> unitsParam = LayoutUnitAtRandom(gridPositions, zombie1, 0, 1, UnitNature.Zombie1);//entre 0 et 2 enemies, provisoirement

        unitsParam.AddRange(LayoutUnitAtRandom(gridPositions, zombie2, 0, 1, UnitNature.Zombie2));
        unitsParam.AddRange(LayoutUnitAtRandom(gridPositions, zombie3, 0, 1, UnitNature.Zombie3));

        RoomParam roomParam = new RoomParam
        {
            coordonates         = coordonates,
            wallTilesParam      = wallTilesParam,
            outerWallTilesParam = outerWallTilesParam,
            groundTilesParam    = groundTilesParam,
            //objectsParam = objectsParam,
            unitsParam = unitsParam
        };

        return(roomParam);
    }
Beispiel #5
0
    void InitGame()
    {
        surface = Instantiate(surfacePrefab);
        (levelRooms, connectedRooms) = levelGenerator.GenerateLevel();
        statManager.InitiateStats(levelRooms);
        gearManager.InitiateGears(levelRooms);
        currentRoomIndex = new RoomIndex {
            abs = 0, ord = 0
        };
        currentRoom = levelRooms[currentRoomIndex];
        map         = mapController.CreateMap(levelRooms, connectedRooms);
        map.SetActive(false);

        playerParam = new UnitParam
        {
            id         = 0,
            unitNature = UnitNature.Player,
            stat       = statManager.GenerateStat(UnitNature.Player),
            gear       = new Gear {
            }
        };

        roomGenerator.SetupRoom(currentRoom, playerSpawn);
        surface.BuildNavMesh();
    }
Beispiel #6
0
        private bool CreateMobSpawners(
            Random rng,
            out String result)
        {
            bool success = true;

            result = SuccessMessages.GENERAL_SUCCESS;

            for (RoomIndexIterator iterator = new RoomIndexIterator(m_roomGrid);
                 success && iterator.Valid;
                 iterator.Next())
            {
                RoomIndex    roomIndex    = iterator.Current;
                RoomLayout   room         = GetRoomByIndex(roomIndex);
                RoomTemplate roomTemplate = m_roomTemplateSet.GetTemplateByName(room.static_room_data.room_template_name);

                foreach (MobSpawnerTemplate mobSpawnerTemplate in roomTemplate.MobSpawnerTemplates)
                {
                    MobSpawner spawner =
                        MobSpawner.CreateMobSpawner(
                            room.room_key,
                            mobSpawnerTemplate,
                            m_mobSpawnTableSet,
                            rng);

                    // Don't bother adding mob spawners that don't have any spawns left
                    if (spawner.RemainingSpawnCount > 0)
                    {
                        room.mobSpawners.Add(spawner);
                    }
                }
            }

            return(success);
        }
Beispiel #7
0
 public RoomKey GetRoomKeyForRoomIndex(RoomIndex roomIndex)
 {
     return(new RoomKey(
                m_minRoomKey.game_id,
                m_minRoomKey.x + roomIndex.X,
                m_minRoomKey.y + roomIndex.Y,
                m_minRoomKey.z + roomIndex.Z));
 }
Beispiel #8
0
            public RoomIndexIterator(RoomLayout[, ,] roomGrid, eIterationType type)
            {
                m_roomIndex     = new RoomIndex(-1, 0, 0);
                m_roomGrid      = roomGrid;
                m_iterationType = type;

                Next();
            }
Beispiel #9
0
            public RoomIndexIterator(RoomLayout[, ,] roomGrid)
            {
                m_roomIndex     = new RoomIndex(-1, 0, 0);
                m_roomGrid      = roomGrid;
                m_iterationType = eIterationType.nonNullRooms;

                Next();
            }
Beispiel #10
0
    public RoomData()
    {
        doors = new List <Door>();
        Index = new RoomIndex();

        Dimensions  = new RoomIndex();
        UpperBounds = new RoomIndex();
        LowerBounds = new RoomIndex();
    }
Beispiel #11
0
    public bool containsDoor(RoomIndex index)
    {
        foreach (Door door in this.doors)
        {
            if (door.RelativeIndex == index)
            {
                return(true);
            }
        }

        return(false);
    }
Beispiel #12
0
    public int numberOfRooms = 5;//Dans un premier temps on impose le nombre de salle


    public (Dictionary <RoomIndex, RoomParam>, List <List <RoomIndex> >) GenerateLevel()
    {
        width          = GameManager.instance.width;
        height         = GameManager.instance.height;
        unitIdIterator = 0;

        Dictionary <RoomIndex, RoomParam> rooms = new Dictionary <RoomIndex, RoomParam>();
        List <RoomIndex>         openList       = new List <RoomIndex>();
        List <RoomIndex>         closedList     = new List <RoomIndex>();
        List <List <RoomIndex> > connectedRooms = new List <List <RoomIndex> >();//on garde en memoire les salles connectees entre elles par une porte
        RoomIndex startRoomCoord = new RoomIndex {
            abs = 0, ord = 0
        };

        openList.Add(startRoomCoord);

        for (int i = 0; i < numberOfRooms; i++)
        {
            int       randomIndex = Random.Range(0, openList.Count - 1);
            RoomIndex coordonates = openList[randomIndex];
            openList.Remove(coordonates);
            closedList.Add(coordonates);
            RoomParam roomParam = CreateRoom(coordonates);
            rooms.Add(coordonates, roomParam);

            foreach (RoomIndex coord in GetNeighbouringRooms(coordonates))
            {
                if (closedList.Contains(coord))
                {
                    if (Math.Abs((coordonates.abs - coord.abs) + (coordonates.ord - coord.ord)) == 1) //ie salles voisines
                    {
                        rooms = ConnectRooms(rooms, coord, coordonates);                              //on ouvre les portes entre les 2 salles
                        List <RoomIndex> list1 = new List <RoomIndex>();
                        list1.Add(coord);
                        list1.Add(coordonates);
                        List <RoomIndex> list2 = new List <RoomIndex>();
                        list2.Add(coord);
                        list2.Add(coordonates);
                        connectedRooms.Add(list1);
                        connectedRooms.Add(list2);
                    }
                    continue;
                }
                if (openList.Contains(coord) || closedList.Contains(coord))
                {
                    continue;
                }
                openList.Add(coord);
            }
        }
        return(rooms, connectedRooms);
    }
Beispiel #13
0
 public void init(float baseSize, string roomName, float relativeChance, int rotation, Vector3 dimensions, Vector3 lowerBound, Vector3 upperBound, RoomIndex Index)
 {
     this.baseSize           = baseSize;
     this.roomName           = roomName;
     this.relativeChance     = relativeChance;
     this.rotation           = rotation;
     this.dimensions         = dimensions;
     this.lowerBound         = lowerBound;
     this.upperBound         = upperBound;
     this.Index              = Index;
     this.transform.position = new Vector3(Index.x, Index.y, Index.z);
     rotateGameObject();
 }
Beispiel #14
0
        public RoomLayout TryGetRoomByIndex(RoomIndex roomIndex)
        {
            RoomLayout room       = null;
            int        roomXIndex = roomIndex.X;
            int        roomYIndex = roomIndex.Y;
            int        roomZIndex = roomIndex.Z;

            if (roomXIndex >= 0 && roomXIndex < m_roomGrid.GetLength(0) &&
                roomYIndex >= 0 && roomYIndex < m_roomGrid.GetLength(1) &&
                roomZIndex >= 0 && roomZIndex < m_roomGrid.GetLength(2))
            {
                room = m_roomGrid[roomXIndex, roomYIndex, roomZIndex];
            }

            return(room);
        }
Beispiel #15
0
    public void rotate90Deg(int rotations)
    {
        for (int i = 0; i < rotations; i++)
        {
            rotation = (rotation + 90) % 360;

            foreach (Door door in doors)
            {
                door.rotateDoorIndex(upperBound);
            }

            upperBound = new Vector3(upperBound.z, upperBound.y, upperBound.x);
            dimensions = new Vector3(dimensions.z, dimensions.y, dimensions.x);
        }
        rotateGameObject();
    }
        // GET: Room
        public ActionResult Index()
        {
            string cookie = Request.Cookies["cookie"].Value.ToString();


            ApplicationUser user = _context.ApplicationUsers.Include("Role").FirstOrDefault(u => u.token == cookie);

            ViewBag.User = user;
            //var list = _context.Rooms.Include("BedType").OrderByDescending(p => p.Id).ToList();

            RoomIndex roomvw = new RoomIndex
            {
                Rooms    = _context.Rooms.Include("BedType").OrderByDescending(p => p.Id).ToList(),
                bedTypes = _context.bedTypes.ToList(),
            };

            return(View(roomvw));
        }
Beispiel #17
0
        private void RemoveRoomFromGrid(RoomIndex roomIndex)
        {
            RoomLayout room = GetRoomByIndex(roomIndex);

            // Neighbor on the +x side
            if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.positive_x))
            {
                RoomLayout posXRoom = GetRoomByIndex(roomIndex.Offset(1, 0, 0));

                // No more room on the -x side
                posXRoom.RoomFlagPortalOnSide(MathConstants.eSignedDirection.negative_x, false);
            }

            // Neighbor on the -x side
            if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.negative_x))
            {
                RoomLayout negXRoom = GetRoomByIndex(roomIndex.Offset(-1, 0, 0));

                // No more room on the +x side
                negXRoom.RoomFlagPortalOnSide(MathConstants.eSignedDirection.positive_x, false);
            }

            // Neighbor on the +y side
            if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.positive_y))
            {
                RoomLayout posYRoom = GetRoomByIndex(roomIndex.Offset(0, 1, 0));

                // No more room on the -y side
                posYRoom.RoomFlagPortalOnSide(MathConstants.eSignedDirection.negative_y, false);
            }

            // Neighbor on the -y side
            if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.negative_y))
            {
                RoomLayout negYRoom = GetRoomByIndex(roomIndex.Offset(0, -1, 0));

                // No more room on the +y side
                negYRoom.RoomFlagPortalOnSide(MathConstants.eSignedDirection.positive_y, false);
            }

            // Stomp this room
            m_roomGrid[roomIndex.X, roomIndex.Y, roomIndex.Z] = null;
        }
Beispiel #18
0
    public RoomData(string name, RoomType type, float RelativeChance, Vector3 dimensions, Vector3 lowerBound, Vector3 upperBound, List <Door> doors)
    {
        this.Name           = name;
        this.Type           = type;
        this.RelativeChance = RelativeChance;
        this.Dimensions     = dimensions;
        this.LowerBounds    = lowerBound;
        this.UpperBounds    = upperBound;

        this.doors = new List <Door>(doors.Count);
        foreach (Door door in doors)
        {
            this.doors.Add(new Door(door));
        }
        foreach (Door door in this.doors)
        {
            door.Room = this;
        }
        Index = new RoomIndex();
    }
Beispiel #19
0
        private bool CanRemoveRoomFromGrid(RoomIndex roomIndex)
        {
            RoomLayout room          = GetRoomByIndex(roomIndex);
            bool       canRemoveRoom = true;

            // Can't remove this room if it contains stairs
            // Or we are neighboring a room that contains stairs
            if (!room.RoomHasStairs)
            {
                RoomKey roomKey = GetRoomKeyForRoomIndex(roomIndex);

                // Can't remove the origin room because that's where the player is spawned in a new game
                canRemoveRoom = !(roomKey.x == 0 && roomKey.y == 0 && roomKey.z == 0);

                if (canRemoveRoom && room.RoomHasPortalOnSide(MathConstants.eSignedDirection.positive_x))
                {
                    canRemoveRoom &= !GetRoomByIndex(roomIndex.Offset(1, 0, 0)).RoomHasStairs;
                }

                if (canRemoveRoom && room.RoomHasPortalOnSide(MathConstants.eSignedDirection.negative_x))
                {
                    canRemoveRoom &= !GetRoomByIndex(roomIndex.Offset(-1, 0, 0)).RoomHasStairs;
                }

                if (canRemoveRoom && room.RoomHasPortalOnSide(MathConstants.eSignedDirection.positive_y))
                {
                    canRemoveRoom &= !GetRoomByIndex(roomIndex.Offset(0, 1, 0)).RoomHasStairs;
                }

                if (canRemoveRoom && room.RoomHasPortalOnSide(MathConstants.eSignedDirection.negative_y))
                {
                    canRemoveRoom &= !GetRoomByIndex(roomIndex.Offset(0, -1, 0)).RoomHasStairs;
                }
            }
            else
            {
                canRemoveRoom = false;
            }

            return(canRemoveRoom);
        }
Beispiel #20
0
    public List <RoomIndex> GetNeighbouringRooms(RoomIndex coord)
    {
        List <RoomIndex> neighbourList = new List <RoomIndex>(); int abs; int ord;

        for (int i = -1; i <= 1; i++)
        {
            for (int j = -1; j <= 1; j++)
            {
                if (i * j != 0)//On veut pas de diagonale
                {
                    continue;
                }
                abs = coord.abs + i; ord = coord.ord + j;
                RoomIndex neighbour = new RoomIndex {
                    abs = abs, ord = ord
                };
                neighbourList.Add(neighbour);
            }
        }
        return(neighbourList);
    }
Beispiel #21
0
        private void FilterIsolatedRooms(
            Dictionary <int, List <RoomIndex> > connectivityIdToRoomIndexMap)
        {
            for (RoomIndexIterator iterator = new RoomIndexIterator(m_roomGrid);
                 iterator.Valid;
                 iterator.Next())
            {
                RoomIndex  roomIndex = iterator.Current;
                RoomLayout room      = GetRoomByIndex(roomIndex);

                if (room.RoomIsIsolated)
                {
                    List <RoomIndex> connectedSet = connectivityIdToRoomIndexMap[room.connectivity_id];

                    // Remove the room from the connectivity set
                    connectivityIdToRoomIndexMap.Remove(room.connectivity_id);

                    // Remove the room from the room grid
                    m_roomGrid[roomIndex.X, roomIndex.Y, roomIndex.Z] = null;
                }
            }
        }
Beispiel #22
0
        private Portal CreateTeleporterPortal(
            Random rng,
            RoomIndex roomIndex)
        {
            Portal                portal              = null;
            RoomLayout            room                = GetRoomByIndex(roomIndex);
            RoomTemplate          roomTemplate        = m_roomTemplateSet.GetTemplateByName(room.static_room_data.room_template_name);
            List <PortalTemplate> teleporterTemplates =
                roomTemplate.PortalTemplates.Where(t => t.PortalType == ePortalType.teleporter).ToList();

            if (teleporterTemplates.Count > 0)
            {
                RoomKey        roomKey        = GetRoomKeyForRoomIndex(roomIndex);
                PortalTemplate portalTemplate = teleporterTemplates[rng.Next(teleporterTemplates.Count)];

                portal = new Portal();
                portal.bounding_box = portalTemplate.BoundingBox;
                portal.room_side    = portalTemplate.PortalRoomSide;
                portal.portal_type  = portalTemplate.PortalType;
                portal.room_x       = roomKey.x;
                portal.room_y       = roomKey.y;
                portal.room_z       = roomKey.z;

                // This is a temp ID for the purpose of portal connection.
                // A new ID will get assigned when inserting this portal into the DB.
                portal.portal_id = m_nextPortalId;
                ++m_nextPortalId;

                // This get sets in the next pass
                portal.target_portal_id = -1;

                // Add the new portal to the room
                room.portals.Add(portal);
            }

            return(portal);
        }
Beispiel #23
0
    public static RoomIndex DirectionOffsetIndex(this DoorDirection direction)
    {
        RoomIndex retVec = new RoomIndex();

        switch (direction)
        {
        case DoorDirection.NORTH:
            retVec = new RoomIndex(0, 0, 1);
            break;

        case DoorDirection.EAST:
            retVec = new RoomIndex(1, 0, 0);
            break;

        case DoorDirection.SOUTH:
            retVec = new RoomIndex(0, 0, -1);
            break;

        case DoorDirection.WEST:
            retVec = new RoomIndex(-1, 0, 0);
            break;

        case DoorDirection.UP:
            retVec = new RoomIndex(0, 1, 0);
            break;

        case DoorDirection.DOWN:
            retVec = new RoomIndex(0, -1, 0);
            break;

        default:
            break;
        }

        return(retVec);
    }
Beispiel #24
0
 public Door(RoomData room, RoomIndex relativeIndex)
 {
     this.Room          = room;
     this.RelativeIndex = relativeIndex;
     ConnectedRoom      = null;
 }
Beispiel #25
0
 public Door(RoomIndex relativeIndex, DoorDirection direction)
 {
     this.RelativeIndex = relativeIndex;
     this.Direction     = direction;
     ConnectedRoom      = null;
 }
Beispiel #26
0
        private void JoinAdjacentDisjointRoomSets(
            Dictionary <int, List <RoomIndex> > connectivityIdToRoomIndexMap)
        {
            // Look for any null room that neighboring at least two disjoint sets of rooms
            for (RoomIndexIterator iterator = new RoomIndexIterator(m_roomGrid, RoomIndexIterator.eIterationType.nullRooms);
                 iterator.Valid;
                 iterator.Next())
            {
                RoomIndex   nullRoomIndex      = iterator.Current;
                RoomIndex[] neighboringIndices = new RoomIndex[4] {
                    nullRoomIndex.Offset(1, 0, 0),
                    nullRoomIndex.Offset(-1, 0, 0),
                    nullRoomIndex.Offset(0, 1, 0),
                    nullRoomIndex.Offset(0, -1, 0)
                };
                MathConstants.eSignedDirection[] neighborSideFlags = new MathConstants.eSignedDirection[4] {
                    MathConstants.eSignedDirection.positive_x,
                    MathConstants.eSignedDirection.negative_x,
                    MathConstants.eSignedDirection.positive_y,
                    MathConstants.eSignedDirection.negative_y
                };

                bool createNewRoom = false;
                TypedFlags <MathConstants.eSignedDirection> nullRoomNeighborFlags = new TypedFlags <MathConstants.eSignedDirection>();
                int lastConnectivityId = -1;

                for (int side_index = 0; side_index < 4; ++side_index)
                {
                    MathConstants.eSignedDirection neighborSide = neighborSideFlags[side_index];
                    RoomIndex neighborRoomIndex = neighboringIndices[side_index];

                    // See if an adjacent room exists on this side
                    RoomLayout neighborRoom = TryGetRoomByIndex(neighborRoomIndex);

                    if (neighborRoom != null)
                    {
                        // Record that a neighboring room was found in this side
                        nullRoomNeighborFlags.Set(neighborSide, true);

                        // See if the neighboring room is actually disjoint from a previous neighbor
                        // we have found on another side (different connectivity_id)
                        int roomConnectivityId = neighborRoom.connectivity_id;

                        if (lastConnectivityId != -1 &&
                            roomConnectivityId != lastConnectivityId)
                        {
                            List <RoomIndex> roomSet     = connectivityIdToRoomIndexMap[roomConnectivityId];
                            List <RoomIndex> lastRoomSet = connectivityIdToRoomIndexMap[lastConnectivityId];

                            // Make the connectivity ids match for rooms in both sets
                            roomSet.ForEach(rIndex => GetRoomByIndex(rIndex).connectivity_id = lastConnectivityId);

                            // Merge the rooms in the set into the previous set
                            lastRoomSet.AddRange(roomSet);

                            // Remove the set
                            connectivityIdToRoomIndexMap.Remove(roomConnectivityId);

                            // Since we have merged two adjacent sets we now need a new room
                            // to bridge the disjoin sets
                            createNewRoom = true;
                        }

                        // Keep track of the last valid connectivity we found for the next iteration
                        lastConnectivityId = neighborRoom.connectivity_id;
                    }
                }

                if (createNewRoom)
                {
                    // Create a new room at the null room index location
                    RoomLayout newRoom = new RoomLayout(GetRoomKeyForRoomIndex(nullRoomIndex));

                    // Record which neighbors the null room has
                    newRoom.portalRoomSideBitmask = nullRoomNeighborFlags;

                    // All neighbors should have the same connectivity id now
                    // so just get the connectivity id from the last valid neighbor
                    newRoom.connectivity_id = lastConnectivityId;

                    // Finally store the new room in the room grid
                    m_roomGrid[nullRoomIndex.X, nullRoomIndex.Y, nullRoomIndex.Z] = newRoom;

                    // Add the new room to the connectivity set it's helping to bridge
                    {
                        List <RoomIndex> lastRoomSet = connectivityIdToRoomIndexMap[lastConnectivityId];

                        lastRoomSet.Add(new RoomIndex(nullRoomIndex));
                    }

                    // Tell all neighboring rooms about the new room adjacent to it
                    for (int side_index = 0; side_index < 4; ++side_index)
                    {
                        MathConstants.eSignedDirection neighborSide = neighborSideFlags[side_index];
                        RoomIndex neighborRoomIndex = neighboringIndices[side_index];

                        // See if an adjacent room exists on this side
                        if (newRoom.portalRoomSideBitmask.Test(neighborSide))
                        {
                            RoomLayout neighborRoom = GetRoomByIndex(neighborRoomIndex);
                            MathConstants.eSignedDirection opposingNeighborSide = RoomKey.GetOpposingRoomSide(neighborSide);

                            neighborRoom.RoomFlagPortalOnSide(opposingNeighborSide, true);
                        }
                    }
                }
            }
        }
Beispiel #27
0
 public RoomIndex doorToWorldIndex(RoomIndex door)
 {
     return(this.Index + door);
 }
Beispiel #28
0
        private bool CreateNormalPortals(out string result)
        {
            bool success = true;

            result = SuccessMessages.GENERAL_SUCCESS;

            // Create portals in each room
            for (RoomIndexIterator iterator = new RoomIndexIterator(m_roomGrid);
                 iterator.Valid;
                 iterator.Next())
            {
                RoomIndex    roomIndex    = iterator.Current;
                RoomKey      roomKey      = GetRoomKeyForRoomIndex(roomIndex);
                RoomLayout   room         = GetRoomByIndex(roomIndex);
                RoomTemplate roomTemplate = m_roomTemplateSet.GetTemplateByName(room.static_room_data.room_template_name);

                foreach (PortalTemplate portalTemplate in roomTemplate.PortalTemplates)
                {
                    if (portalTemplate.PortalType != ePortalType.teleporter)
                    {
                        Portal portal = new Portal();

                        portal.bounding_box = portalTemplate.BoundingBox;
                        portal.room_side    = portalTemplate.PortalRoomSide;
                        portal.room_x       = roomKey.x;
                        portal.room_y       = roomKey.y;
                        portal.room_z       = roomKey.z;
                        portal.portal_type  = portalTemplate.PortalType;

                        // This is a temp ID for the purpose of portal connection.
                        // A new ID will get assigned when inserting this portal into the DB.
                        portal.portal_id = m_nextPortalId;
                        ++m_nextPortalId;

                        // This get sets in the next pass
                        portal.target_portal_id = -1;

                        room.portals.Add(portal);
                    }
                }
            }

            // Connect neighboring portals
            for (RoomIndexIterator iterator = new RoomIndexIterator(m_roomGrid);
                 success && iterator.Valid;
                 iterator.Next())
            {
                RoomIndex  roomIndex = iterator.Current;
                RoomLayout room      = GetRoomByIndex(roomIndex);

                foreach (Portal portal in room.portals)
                {
                    MathConstants.eSignedDirection opposingRoomSide = RoomKey.GetOpposingRoomSide(portal.room_side);
                    RoomIndex  opposingRoomIndex = roomIndex.GetOpposingRoomIndex(portal.room_side);
                    RoomLayout opposingRoom      = GetRoomByIndex(opposingRoomIndex);
                    Portal     opposingPortal    = opposingRoom.portals.Find(p => p.room_side == opposingRoomSide);

                    if (opposingPortal != null)
                    {
                        portal.target_portal_id         = opposingPortal.portal_id;
                        opposingPortal.target_portal_id = portal.portal_id;
                    }
                    else
                    {
                        result  = ErrorMessages.DUNGEON_LAYOUT_ERROR;
                        success = false;
                        break;
                    }
                }
            }

            return(success);
        }
Beispiel #29
0
        private bool CreateTeporterPortals(
            Random rng,
            Dictionary <int, List <RoomIndex> > connectivityIdToRoomIndexMap,
            out string result)
        {
            List <int> connectivityIDs = connectivityIdToRoomIndexMap.Keys.ToList <int>();
            bool       success         = true;

            result = SuccessMessages.GENERAL_SUCCESS;

            if (connectivityIDs.Count > 1)
            {
                for (int list_index = 1; list_index < connectivityIDs.Count; ++list_index)
                {
                    int connectivityId      = connectivityIDs[list_index - 1];
                    int otherConnectivityId = connectivityIDs[list_index];

                    // Only consider rooms in a set that don't already have teleporters in them.
                    // We do this because we only have the guarantee of one portal template per room.
                    // We could always have enough rooms to pick from if:
                    // 1) Each connectivity set has at least 2 rooms (enforced by FilterIsolatedRooms)
                    // 2) For N room sets we make N-1 portal pairs
                    List <RoomIndex> roomIndexSetA =
                        (from r in connectivityIdToRoomIndexMap[connectivityId]
                         where GetRoomByIndex(r).portals.Count(p => p.portal_type == ePortalType.teleporter) == 0
                         select r).ToList();
                    List <RoomIndex> roomIndexSetB =
                        (from r in connectivityIdToRoomIndexMap[otherConnectivityId]
                         where GetRoomByIndex(r).portals.Count(p => p.portal_type == ePortalType.teleporter) == 0
                         select r).ToList();

                    if (roomIndexSetA.Count > 0 && roomIndexSetB.Count > 0)
                    {
                        RoomIndex roomIndexA = roomIndexSetA[rng.Next(roomIndexSetA.Count)];
                        RoomIndex roomIndexB = roomIndexSetB[rng.Next(roomIndexSetB.Count)];

                        Portal teleporterA = CreateTeleporterPortal(rng, roomIndexA);
                        Portal teleporterB = CreateTeleporterPortal(rng, roomIndexB);

                        if (teleporterA != null && teleporterB != null)
                        {
                            teleporterA.target_portal_id = teleporterB.portal_id;
                            teleporterB.target_portal_id = teleporterA.portal_id;
                        }
                        else
                        {
                            result  = ErrorMessages.DUNGEON_LAYOUT_ERROR;
                            success = false;
                            break;
                        }
                    }
                    else
                    {
                        result  = ErrorMessages.DUNGEON_LAYOUT_ERROR;
                        success = false;
                        break;
                    }
                }
            }

            return(success);
        }
Beispiel #30
0
 public RoomLayout GetRoomByIndex(RoomIndex roomIndex)
 {
     return(m_roomGrid[roomIndex.X, roomIndex.Y, roomIndex.Z]);
 }