Week 6-7 Placing the rooms in the labyrinth.

Week 6-7 Placing the rooms in the labyrinth.

This update was written 17/11/17. Week 8.
Unfortunately this part of the PLG took 3 weeks to complete due to a problem encountered.

The first draft of the algorithm was this
Place the rooms
1.    Select randomly a open exit in open_exits List. This will be the exit way we attach the next component.
2.    Select randomly between room or corridor.
3.    Select randomly a open exit from the selected room/corridor.
4.    Rotate the the parent room/corridor so it aligns with the selected open exit.
5.    Move the Room so both exits are in the same location.
6.    Check if the placed room collides with an existing room and if it placed outside the layout area.
7.    If any of the above two statements is true then delete the room/corridor.
8.    If not, remove the selected exit from the open_exits list
9.    Check if any of the remaining exits of the room/corridor are outside the level area, if they are add them to the PossibleExitPoint list, if not then add the room/corridors remaining exits to the list open_exits.
10.  Repeat steps 10-18 until the room density is reached or step 18 has failed 4 times in a row.
Snap Rooms Together and Closing open doorways
11. Check if at least one of the exits from each preset piece is not listed in the open_exits list. Indicating that are preset room is conneceted.
12. If  a preset room is not connected find the nearest open exit and create a corridor attaching it. Repeat for all unattached presets rooms.
13. While the open exits list is in size larger than Y (another number to be determined) find a open exit and connect it to the closest open exit available.
14.  While the open exits list is in size larger than Z (another number to be determined) add a cap room (cap rooms are rooms with only one exit point) to a random exit in openexits list and remove it from the list.
For each of the remaining open exits randomly assign a and place a blocking point prefab. This might be a sealed door a pile of rubble blocking the door.

Bellow I will mention changes to the current algorithm: 

Initially I worked to just create a complex of attached rooms ignoring the layout. 

      1. I choose a random exit point from the available exit points, later on I decided to just take the first exit from the list ExitPoints[0].Transform. There is a List (FailedAttemps  <int>, same size as openExits) this list indicates how many times we have tried to attach a room to that point. Every time it fails we increase the value for that point by 1, starting from 0. if the value is greater than 2 then we remove that point from the list and try again at position index=0.

2. I still select and instantiate randomly between rooms, open areas and corridors, no restriction yet, but there will be a Legendary container where rooms can only be placed once.

3.    Select randomly a open exit from the selected room/corridor.

4.    Rotate the the parent room/corridor so it aligns with the selected open exit.

5.    Move the Room so both exits are in the same location.

6.    Check if the placed room collides with another room. 

7.    If collision is detected  the room/corridor , increase the value of failed attempts list, which is the same size of the OpenExits.

8.    If coliition is detected delete the piece* (to be stored in the future to increase performance) and increase failedattempts[0] by 1. go to step 1.

9.If no colition was detected.

9a. Examine if any of the remaining exit points are outside the max area, if yes store them in OutsidePoints List. 

9b. Examine if any of the  remaining exit points are close to any of our preset pieces exits.
       if yes attach the preset piece to that exit. Remove that preset piece from the preset folder. check if the preset folder is empty if yes then delete it.

10. Add the remaining exits of the open piece to the OpenExits[]

11.  Repeat steps 1-10 until the room density is reached or step the NumberOfRooms set is equal to the room counter.

12. Scan the density of the labyrinth, in steps of 10. if the density is smaller then target density then NumberOfRooms=NumberOfRooms+10 and set the boolean indicator for good density as false.

13. If the density is good then scan the line for the pre-exit room (same code used when looking for the exit plane.

14. Add to 50% of the points in OutsidePoints list a random One exit room.

Comments

Popular posts from this blog

Player stats and brightness.

Testing the PLG

More work done on the interface, saving data.