public GeoGrid deepCopy(int numsubs) { GeoGrid dup = new GeoGrid(numsubs); for (int i = 0; i < NUMPARA; i++) { for (int j = 0; j < frequency - 1; j++) { for (int k = 0; k < 2 * frequency - 1; k++) { dup.getTile(i, j, k).Value = grid[i][j][k].Value; dup.getTile(i, j, k).Rank = grid[i][j][k].Rank; } } } return(dup); }
public void LoadGrid(GeoGrid g) { int edgeLen = (int)Math.Pow(2, numSubs); //Number of hexagons on an even face int even = Triangular(edgeLen) - 1; //Number of hexagons on an odd face int odd = Triangular(edgeLen - 1); int hexDex = 0; //This loop assigns the display hexagons to an index in the data representation //While there's five parallelograms, I end up doing the same thing twice in each one, so I did some simple integer division trickery. //Hopefully it doesn't f**k me in the butt down the road. //I'm down the road and pretty sure I'm being f****d in the butt System.Console.WriteLine("HexLen: " + hexList.Length); System.Console.WriteLine("Even: " + even); System.Console.WriteLine("Odd: " + odd); for (int par = 0; par < 10; par++) { int start = (par % 2) * edgeLen; for (int col = 1; col < edgeLen; col++) { for (int row = 0; row <= edgeLen - col; row++) { hexList[hexDex++].tile = g.getTile(par / 2, row, col + start); //hexDex++; } } for (int row = edgeLen - 1; row > 0; row--) { int iter = 0; for (int col = edgeLen; col > row; col--) { hexList[hexDex++].tile = g.getTile(par / 2, row + iter, col + start); iter++; } } } }
public static GeoGrid seaLevel(GeoGrid input, Project proj) { float sea = proj.SeaLevel; int freq = input.getFrequency(); GeoGrid landForms = new GeoGrid(proj.Frequency); for (int par = 0; par < GeoGrid.NUMPARA; par++) { for (int r = 0; r < freq - 1; r++) { for (int c = 0; c < 2 * freq - 1; c++) { if (input.getTile(par, r, c).Value <= sea) { landForms.getTile(par, r, c).Value = 0f; } else { landForms.getTile(par, r, c).Value = 1f; } if (r == 0 && c == 0) { landForms.getTile(par, r, c).Value = 1f; } else if (r == 0 && c == freq - 1) { landForms.getTile(par, r, c).Value = 1f; } else if (r == 0 && c == 2 * freq - 2) { landForms.getTile(par, r, c).Value = 1f; } else if (r == freq - 1 && c == 0) { landForms.getTile(par, r, c).Value = 1f; } else if (r == freq - 1 && c == freq - 1) { landForms.getTile(par, r, c).Value = 1f; } else if (r == freq - 1 && c == 2 * freq - 2) { landForms.getTile(par, r, c).Value = 1f; } } } } return(landForms); }
//cutoff determines the amount of steps before moisture reaches its lowest point public static RectGrid moisture(RectGrid input, Project proj, int cutoff) { GeoGrid geo = new GeoGrid(proj.Frequency); GeoGrid output = new GeoGrid(proj.Frequency); RectGrid coastDist = new RectGrid(input.Height, input.Width); GridDisplayEquiRect temp = new GridDisplayEquiRect(proj.Frequency); temp.RectToGeo(input, geo); GeoGrid landForms = seaLevel(geo, proj); int freq = landForms.getFrequency(); int rank = 1; Tile[] mates; bool clear = false; while (!clear) { clear = true; GeoGrid next = landForms.deepCopy(proj.Frequency); //Wheeeeeeee~ for (int par = 0; par < GeoGrid.NUMPARA; par++) { for (int r = 0; r < freq - 1; r++) { for (int c = 0; c < 2 * freq - 1; c++) { //If it's a land tile that hasn't been visited... if (landForms.getTile(par, r, c).Value > .5f) { mates = landForms.neighbors(r, c, par); for (int m = 0; m < mates.Length; m++) { //if it's a sea tile if (mates[m].Value < .5f) { //Remove from next step next.getTile(par, r, c).Value = 0f; //set distance away from coast output.getTile(par, r, c).Rank = Math.Min(rank, cutoff); clear = false; } } } } } } landForms = next; rank++; } //Determine moisture weight by dividing by cutoff (yes, I coulda put this in the loop above) for (int par = 0; par < GeoGrid.NUMPARA; par++) { for (int r = 0; r < freq - 1; r++) { for (int c = 0; c < 2 * freq - 1; c++) { output.getTile(par, r, c).Value = 1 - ((float)output.getTile(par, r, c).Rank / cutoff); output.getTile(par, r, c).Rank = 0; } } } temp.LoadGrid(output); temp.GeoToRect(coastDist); return(coastDist); }