Heya guys,
I'm having some problems randomly generating sprites.
The goal of the event system is to populate the layout with randomly generated square sprites which represent rooms with doors on either side.
The array "RoomFormation" represents the population of possible room combinations. Green sides represent doors where the object is named after the orientation of the doors (t=top, r=right, b=bottom, l=left).
The size of "RoomFormation" is 16x5 where there are 16 different sprite objects (x-axis), the name of the sprite object (y-axis=0), and the possible relative locations where the sprite can be placed (x.1, x.2, x.3, x.4 where the 1 refers to placement in the north, 2 is east, 3 is south, and 4 is west; i.e a "1.3 means a 't' tile placed in the south.)
Theory:
The function "TileRoll" goes through a process of scanning the "Grid" array for previously placed tiles and eliminates (zeroes the value) incompatible tile objects from "TilePool" (a copy of "RoomFormation"), then it draws a random value from "TileLottery" (a contracted "TilePool" array containing no zero values), from the randomly chosen value a tile is placed in the appropriate location.
[
[The "TileRoll" function is made in such a way to prevent 3-way intersections from occuring randomly]]
Problem:
Randomly, the process halts before MaxRoom tiles are placed.
In the time being I've added the highlighted condition in Event2-3 to restart if the process fails, however this is not something I want to keep in.
Screenshot examples of successful and failure layout generation:
http://imgur.com/a/5Wyv3
Cap file itself:
https://www.dropbox.com/s/u1zjtvg31mbp2 ... .capx?dl=0