How to do 2d tile room assignments?
With games like Prison Architect, Rimworld, Terraria, and Starbound, I am surprised this hasn't been asked before. I would like the game to detect when a room is built and assign all tiles inside of it with a room id variable to help with a variety of troubleshooting and game mechanics planned down the road.
What I have is a class array for my tile world's properties. Each tile has a "walled" boolean that determines if that tile has a wall or a free space. I use this for path finding. I also have a "roomID" integer variable to hold the room ID.
What I want is to effectively, and cleanly assign rooms any time a wall is built, merge rooms if necessary, or remove a room if it is no longer completely enclosed by walls.
My ideas were to either follow a wall around until it reaches itself making a concave figure and assigning all inside tiles; Or starting with a door and checking all adjacent tiles to see if they have a different room ID and continue to the wall till there is nothing left or we have hit another room. I am not sure how effective this would be when building walls.
for visual here is a picture: