ID:151848
 
I'm trying to figure out a way to calculate all the turfs inside a room of any size. The room has entrances and exits which can be opened or closed (doors). I was thinking somehow picking a single spot in the room and "growing" out until it can't grow anymore (where it would stop growing when it got to an entrance or exit), but I just can't think of a way to implement it. Any help? Thanks.
Koil wrote:
I'm trying to figure out a way to calculate all the turfs inside a room of any size. The room has entrances and exits which can be opened or closed (doors). I was thinking somehow picking a single spot in the room and "growing" out until it can't grow anymore (where it would stop growing when it got to an entrance or exit), but I just can't think of a way to implement it. Any help? Thanks.

Well, something like this is something you want to make as efficient as possible, so tell me: how are your rooms laid-out? Are they all rectangular? Will there ever be a non-rect room that you will need to know the size of? Are you looking for the size of the room or are you trying to contain the turfs of the room in a list? It might be easier to hard-code each room an area subtype of its own and use that. Details man, details!
In response to CaptFalcon33035
If they are rectangular/square, you can use the block() function :)
I highly recommend the Dijkstra proc which you'll find as part of Theodis' Pathfinder library: hub://Theodis.Pathfinder

Theodis' libraries, Pathfinder in particular, are godsends to BYOND developers.
I'm trying to figure out a way to calculate all the turfs inside a room of any size. The room has entrances and exits which can be opened or closed (doors). I was thinking somehow picking a single spot in the room and "growing" out until it can't grow anymore (where it would stop growing when it got to an entrance or exit), but I just can't think of a way to implement it. Any help? Thanks.

Yeah you have the basic idea right. What you need a is a flood fill. Wikipedia has some info on it http://en.wikipedia.org/wiki/Flood_fill . Basic algorithm is as follows.

Make a list
Pick any tile in the room and stick it in the list
While(list isn't empty)
Take a tile from the list
Mark the tiles as part of the room
For each adjacent tile that isn't blocked by anything that would cause a room change and isn't already marked
Add tile to the list


That should flag all tiles that are part of the room.
In response to Theodis
I wonder where you find all these interesting algorithms. All your demos and libraries have them.
In response to Kaiochao
He's majoring/majored(?) in game design or software design or something; he's paying/payed to learn them!
In response to Kaiochao
I wonder where you find all these interesting algorithms. All your demos and libraries have them.

If you have a community college around I suggest seeing if they offer a data structures and algorithms course. It's a great way to get a taste for the basics and make it easier to pick up more stuff. Once you have a decent foundation wikipedia actually has a decent amount of reference on a lot of data structures and algorithms and links out to other sites covering them.