Beispiel #1
0
        private static bool buildOnePath(SimplifiedLayoutDataPacket simpleDataPacket, byte lengthOfPath, bool isKeyPath, System.Random random_thread)
        {
            byte[] roomCoords = new byte[2]; // X, Y
            byte[] roomInfo   = new byte[2]; // direction, clearance

            // First, find a good spotm and gather information:
            do
            {
                roomCoords = simpleDataPacket.getRandomCoordInBoundingBox(random_thread);
                roomInfo   = gatherInfoAboutRandomAdjacentPlacedRoom(simpleDataPacket.getSimpleArray_building(), roomCoords, random_thread);
            } while (roomInfo[0] == Constants.doorID_null);

            // Reset the path array, update it's position relative to the builderArray, and keep track of the first room:
            SimpleRoom_Building firstRoomInPath = simpleDataPacket.resetArray_Path(roomCoords[0], roomCoords[1]);

            // define the first room, which will always have a door on a keyPath:
            if (isKeyPath)
            {
                roomInfo[1] = simpleDataPacket.getCurrentClearanceLevel();
                if (lengthOfPath > 1)
                {
                    firstRoomInPath.setInformation(roomInfo[1], roomInfo[0], roomInfo[1], 0);
                }
                else
                {
                    firstRoomInPath.setInformation(roomInfo[1], roomInfo[0], roomInfo[1], (byte)(roomInfo[1] + 1));
                }
            }
            else
            {
                byte doorClearance = simpleDataPacket.getRandomClearanceLevel(random_thread);
                roomInfo[1] = (byte)Mathf.Max(doorClearance, roomInfo[1]);
                firstRoomInPath.setInformation(roomInfo[1], roomInfo[0], doorClearance, 0);
            }

            // now, attempt to place the next room. If any room fails, this will return false. If they all succeed, this will return true:
            if (addNextRoomToPath(simpleDataPacket, roomCoords, roomInfo, (byte)(lengthOfPath - 1), isKeyPath, random_thread))
            {
                simpleDataPacket.joinPathArrayElementsIntoBuildingArray();
                return(true);
            }

            return(false);
        }