Anyway to predict if a room can be successfully placed/ know if it is actually placed when Choose Next Room?
EiZi233 opened this issue · 3 comments
Greeting! I am using this amazing plugin and trying to write a cool logic for spawning the room. I am wondering when I choose a room in the Choose Next Room function, are the room guaranteed to be placed? What will happen if, like the room is too big and cannot be placed?
Let's say in the example in the plugin description, I want to spawn a secret room once and only once in my dungeon, what is going on in the plugin if that secret room did not successfully spawned? In that case there will be no secret room at all or the generate is aborted?
And well some times the generator only spawn a single start room and no other rooms at all. Could this be caused by a similar issue?
Thanks!
Hi @EiZi233
when I choose a room in the Choose Next Room function, are the room guaranteed to be placed? What will happen if, like the room is too big and cannot be placed?
No, the room you return in the ChooseNextRoomData
function is not guaranteed to spawn.
If the room cannot be placed (overlapping other rooms) the function is re-called so you can try another room.
After 10 times of retry, no room will be placed and the generator will continue with another door.
what is going on in the plugin if that secret room did not successfully spawned? In that case there will be no secret room at all or the generate is aborted?
When the dungeon generator has finished to generate (either by door exhaustion or by ContinueToAddRoom
returning false) the function IsValidDungeon
will be called.
In that function you should check if you have one and only one secret room in the generated dungeon.
If you return false because of any of your not met requirements, the dungeon generator will clear the generated dungeon and will try to generate one.
If after 500 retries the IsValidDungeon
returns always false, then the dungeon abandons the generation and returns what he currently has.
You can see the flowchart in the wiki to visualize the path taken by the dungeon generator.
So you should keep in mind that randomizing the room choice is very important. If you only have one room data of your secret room, then you should not have the same code path to return the secret room each time the ChooseNextRoomData
is called. You have to randomize a little so you could return another random room instead, in case the secret room can't be spawned.
some times the generator only spawn a single start room and no other rooms at all. Could this be caused by a similar issue?
I don't know what your code is, but you are right, it could be caused by:
ContinueToAddRoom
returning false just after the first room,ChooseNextRoomData
exhausting all its retries for the room to choose just after the first room,IsValidDungeon
always returning false and so exhausting all the retries.
Make sure your rooms have enough door. A room with only one room will stop naturally the generation for this dungeon "branch", since the only door will be used to connect to previous room.
I think I will add some warning or error messages for those cases.
Hope I answered your questions.
Bests.