and hey, the reason this works is because the game already sorts tiles from nearest to farthest away from tile 0 On Sat, Jun 12, 2010 at 3:40 PM, Alan Wolfe <alan.wolfe@xxxxxxxxx> wrote: > hey you know what an easier way might be? > > 1) Set a var CheckTileIndex to 0 > 2) See if the neighbors of Tile [CheckTileIndex] have roads built. If one > neighbor doesn't, then you know one needs to be built there and you are > done. > 3) else CheckTileIndex = CheckTileIndex + 1 > 4) Go to 1 > > > On Sat, Jun 12, 2010 at 3:35 PM, Kent Petersen <kentkmp@xxxxxxxxx> wrote: > >> Hmm, I see. >> >> >> On Sat, Jun 12, 2010 at 12:41 PM, Alan Wolfe <alan.wolfe@xxxxxxxxx>wrote: >> >>> Here's how i think i would do it... >>> >>> Our goal is to flood fill outwards from tile 0. >>> >>> I'd make an array to store the tiles we want to explore and i'd put "0" >>> in it to start (at index 0) meaning we want to start out by exploring tile >>> 0. Lets call this list TilesToExploreList. >>> >>> I'd also make a variable "TilesToExploreIndex" and set that to 0. >>> >>> 1) Get the current tile index which is >>> TilesToExploreList[TilesToExploreIndex]. If there is no tile there (ie the >>> index is greater than the size of the array) then we are done building all >>> the roads we can. >>> 2) If this current tile index doesn't have a road, we should build one >>> here and we have found a place to build our road. >>> 3) If this current tile index does have a road, add all the neighbor >>> tiles of this tile (that aren't -1 and aren't already in the list) to the >>> end of TilesToExploreList. >>> 4) Increment TilesToExploreIndex >>> 5) Go to 1 >>> >>> In english what we are doing is: >>> >>> Start with the first tile, build a road there if we can. >>> If a road is already there, check each neighbor. >>> If all the neighbors have roads check all the neighbor's neighbors >>> continue until you find a place to put a road, or you run out of tiles to >>> look at. >>> >>> If you run out of tiles that means that all the tiles have roads. >>> >>> I know it's a little bit complicated but does it make sense? >>> >>> It's kind of like recursion but instead of making a recursive call we are >>> just keeping a list of what tiles to check next >>> >>> >>> On Sat, Jun 12, 2010 at 12:21 PM, Kent Petersen <kentkmp@xxxxxxxxx>wrote: >>> >>>> So, I'm working on the road generation and I am having a problem getting >>>> the process started. I am trying to check for the initial tile to start >>>> building from but its not there yet. I feel like I'm in a chicken and the >>>> egg situation. I will copy my code in here. Any thoughts on the matter? >>>> >>>> >>>> >>>> function FindBestRoadBuildSpot() >>>> --check to see if there is an available spot to grow to >>>> --Debug_Print(string.format("Current houses = %i Max Houses = >>>> %i",CurrentHouses,NumHouses)); >>>> --Debug_Print(string.format("Neighbors of Tile %i = >>>> %i,%i,%i,%i",Tile,NavMesh_GetTileNeighbor(Tile,0),NavMesh_GetTileNeighbor(Tile,1),NavMesh_GetTileNeighbor(Tile,2),NavMesh_GetTileNeighbor(Tile,3))); >>>> >>>> --VarName = string.format("Level1/ow/Tile%i/RoadBuilt",Tile); >>>> while NextTile ~= -1 do >>>> RandomTile = math.random(0,NumTiles); >>>> --Note: initial tile isnt set yet >>>> VarName = string.format("Level1/ow/Tile%i/RoadBuilt",RandomTile); >>>> Debug_Print(string.format("Initial Tile Check = >>>> Tile#%i",RandomTile)); >>>> TileValue = Data_GetValue(VarName); >>>> Debug_Print(string.format("Selected TileValue = %i",TileValue)); >>>> if TileValue==1 then >>>> RandomNeighbor = math.random(0,4); >>>> Debug_Print(string.format("RandomNeighbor Check = >>>> Tile#%i",RandomNeighbor)); >>>> NextTile=NavMesh_GetTileNeighbor(RandomTile,RandomNeighbor); >>>> end >>>> --NOTE: how do we determine the starting tile?? >>>> --NextTile=NavMesh_GetTileNeighbor(TileIndex,Var); >>>> end >>>> >>>> --if CurrentTiles < NumTiles-1 then >>>> >>>> --if 70% of the houses are built >>>> if CurrentHouses >= NumHouses*.7 then >>>> --increment the number of tiles in use; city grow >>>> CurrentTiles = CurrentTiles+1; >>>> --incremement the amount of available house space there is >>>> NumHouses = CurrentTiles*6; --6 houses on a tile >>>> --return CurrentTiles; >>>> >>>> end >>>> return NextTile; >>>> >>>> --end >>>> --if we got here, nothing found, return invalid indices >>>> --return -1; >>>> end >>>> >>>> -------------------------------------- >>>> >>>> function BuildRoad(Tile,Index) >>>> >>>> if Tile < 0 then >>>> return; >>>> end >>>> >>>> --get where our tile is located >>>> BasePosX, BasePosY = NavMesh_GetTile(Tile); >>>> >>>> --build a road if we need to >>>> VarName = string.format("Level1/ow/Tile%i/RoadBuilt",Tile); >>>> if Data_GetValue(VarName) == 0 then >>>> Data_SetValue(VarName,1); >>>> >>>> --Vertical peice of road >>>> RoadDecal = Decal_Create("./Art/Models/Overworld/roadV.png",0,0); >>>> Decal_SetPos(RoadDecal,BasePosX+25,BasePosY,0); >>>> Decal_SetDims(RoadDecal,25,100,5000); >>>> Decal_SetShader(RoadDecal,RoadShader); >>>> Decal_AddRule(RoadDecal,"IsTerrain","is",1); >>>> Decal_MakeStatic(RoadDecal); >>>> >>>> --horizontal peice of road >>>> RoadDecal = Decal_Create("./Art/Models/Overworld/roadH.png",0,0); >>>> Decal_SetPos(RoadDecal,BasePosX,BasePosY+25,0); >>>> Decal_SetDims(RoadDecal,100,25,5000); >>>> Decal_SetShader(RoadDecal,RoadShader); >>>> Decal_AddRule(RoadDecal,"IsTerrain","is",1); >>>> Decal_MakeStatic(RoadDecal); >>>> >>>> >>>> Debug_Print(string.format("Neighbors of Tile %i = >>>> %i,%i,%i,%i",Tile,NavMesh_GetTileNeighbor(Tile,0),NavMesh_GetTileNeighbor(Tile,1),NavMesh_GetTileNeighbor(Tile,2),NavMesh_GetTileNeighbor(Tile,3))); >>>> end >>>> >>>> end >>>> >>>> >>> >> >