Esempio n. 1
0
        private static bool addNextRoomToPath(SimplifiedLayoutDataPacket simpleDataPacket, byte[] previousRoomCoords, byte[] previousRoomInfo, byte moreRoomsToPlace, bool isKeyPath, System.Random random_thread)
        {
            // If there are no more rooms to place, send 'true' all the way up:
            if (moreRoomsToPlace == 0)
            {
                return(true);
            }

            // I need to set the previous space to 'tried' right away:
            simpleDataPacket.getPathRoom_usingBuildingCoords(previousRoomCoords[0], previousRoomCoords[1]).setHasntBeenTried(false);

            // We need some info to be defined upfront. The last room of a keyPath needs to have a key:
            byte keyToPlace = 0;

            if (moreRoomsToPlace == 1 && isKeyPath)
            {
                keyToPlace = (byte)(simpleDataPacket.getCurrentClearanceLevel() + 1);
            }

            // We assume the first room has been done already, so any later room could get a random door:
            byte doorToPlace = simpleDataPacket.getRandomClearanceLevel(random_thread);

            // The clearance might update based on the door placed:
            byte[] nextRoomInfo = new byte[2];
            nextRoomInfo[1] = (byte)Mathf.Max(doorToPlace, previousRoomInfo[1]);

            byte[] nextRoomCoords = new byte[2];


            // Now, check each of the surrounding rooms, starting with a random one:
            // byte randomDirection = (byte)Random.Range(0, 4);
            byte randomDirection = (byte)random_thread.Next(0, 4);

            for (int index = 0; index < 4; index++)
            {
                switch (randomDirection)
                {
                case Constants.doorID_left:
                    nextRoomCoords[0] = (byte)(previousRoomCoords[0] - 1);
                    nextRoomCoords[1] = previousRoomCoords[1];
                    nextRoomInfo[0]   = Constants.doorID_right;
                    break;

                case Constants.doorID_right:
                    nextRoomCoords[0] = (byte)(previousRoomCoords[0] + 1);
                    nextRoomCoords[1] = previousRoomCoords[1];
                    nextRoomInfo[0]   = Constants.doorID_left;
                    break;

                case Constants.doorID_up:
                    nextRoomCoords[0] = previousRoomCoords[0];
                    nextRoomCoords[1] = (byte)(previousRoomCoords[1] - 1);
                    nextRoomInfo[0]   = Constants.doorID_down;
                    break;

                default: //case Constants.doorID_down:
                    nextRoomCoords[0] = previousRoomCoords[0];
                    nextRoomCoords[1] = (byte)(previousRoomCoords[1] + 1);
                    nextRoomInfo[0]   = Constants.doorID_up;
                    break;
                }



                if (simpleDataPacket.checkIfCoordIsAvailable(nextRoomCoords[0], nextRoomCoords[1]))
                {
                    if (addNextRoomToPath(simpleDataPacket, nextRoomCoords, nextRoomInfo, (byte)(moreRoomsToPlace - 1), isKeyPath, random_thread))
                    {
                        simpleDataPacket.getPathRoom_usingBuildingCoords(nextRoomCoords[0], nextRoomCoords[1]).setInformation(nextRoomInfo[1], nextRoomInfo[0], doorToPlace, keyToPlace);
                        return(true);
                    }
                }

                randomDirection = (byte)((randomDirection + 1) % 4);
            }

            // If we get here, then none of the adjacent spaces had room. We return false, so the room above can try another door:
            return(false);
        }