TeamREPENTOGON / REPENTOGON

Script extender for The Binding of Isaac: Repentance
https://repentogon.com/
GNU General Public License v2.0
107 stars 11 forks source link

LevelGenerator bug? #461

Open Rollerblade96 opened 1 month ago

Rollerblade96 commented 1 month ago

static LinkDirection ComputeAdjustedLinkDirection(LevelGenerator_Room const& source, int index) in LuaLevelGenerator.cpp is not working as far as I know. I've tried placing several larger room shapes with the LevelGenerator:PlaceRoom lua function and they always fail with an invalid adjusted link direction. This of course does not occur with simple 1x1 room shapes.

The code has two if statements on lines 265 and 271 that do the exact same check (perhaps this a starting point as to where the error is coming from):

https://github.com/TeamREPENTOGON/REPENTOGON/blob/60b9e44f6637ba49b253634230a26b82517b1ec5/repentogon/LuaInterfaces/LuaLevelGenerator.cpp#L263-L280

Rollerblade96 commented 1 month ago

Also might be okay to pass just the source index here as theres no real need to recompute the grid index?

Sylmir commented 1 month ago

Level generation is still a work in progress, most of it is untested (and also subject to change). PlaceRoom works only with 1x1 rooms for now.

Line 271 is definitely buggy, though I can't remember how to fix it, mainly because I'm unsure of what the adjusted link direction is. I do remember it is tied to the way the generator determines how one room connects to the room that was used as its source.

A primer on generation : the game places a room at the center of the 13*13 grid, then it draws a random number of rooms to place around that one. Then, it selects a random room and draws a random number of rooms to place around that one. Rinse and repeat.

Placing a room therefore involves using another room as the "source" (the source parameter in this function). The LinkDirection determines how the two rooms relate (is the new room placed to the left / right / above / below the source). For 1x1 rooms this is trivial, for rooms that are not 1x1 it is more complex. The game computes the direction between the grid index of the new room and the grid index of the room used as source. Because the grid index always corresponds to the top left square of the room (even for LTL room that "do not" have a top left square), determining how the two rooms are linked is a bit tricky.

I would need to review most of the code surrounding the calls to ComputeAdjustedLinkDirection in order to be sure I fully understand how I wanted this function to work (and I would probably need to dump a few level layouts to be 100% sure). If you want to give it a try, feel free to do so :)

I don't think the game has a concept of LinkDirection during generation, IIRC it's a thing I created in order to make custom level generation less difficult to handle. IIRC, a LevelGenerator_Room has a linkIdx and an adjustedLinkIdx that represent the naive and accurate way to link with the source room, and LinkDirection is used to compute the adjustedLinkIdx.

Rollerblade96 commented 1 month ago

Hmm. Thanks for your reply. Yes, it would be tricky to handle how the rooms connect for sure given the unique room shapes. If I had to make an educated guess it might be that the adjustedLinkidx works as an offset to the naive link direction, but when I get a chance I can have a look on my own :D

Edit: If my guess is right then line 265 is where the bug is since you'd want the adj_left to be the door slot below the left door. line 265 should be + 12 in that case

Rollerblade96 commented 1 month ago

I have a new branch im working on from my end with a few small changes that could aid in handling the level generation. Namely, I've added in MC_PRE_LEVEL_LAYOUT_GENERATED which might be useful for mods that want more control in the vanilla generator such as the number of rooms it generates. Please let me know if you would like to see the branch :)

Rollerblade96 commented 1 month ago

Also I started working on the level generator class as well. Looks like ComputeSafeConnection will need some serious rehauling for it to work with the adjusted link direction.