[project1dev] working on road generation

  • From: Kent Petersen <kentkmp@xxxxxxxxx>
  • To: project1dev@xxxxxxxxxxxxx
  • Date: Sat, 12 Jun 2010 12:21:51 -0700

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

Other related posts: