public LogicPoint3 HexToLogicPos(LogicHex hex) { int tile = map.Get(hex.q, hex.r); int height = LogicTile.GetAltitude(tile); ///int tile = LogicTile.SetTerrain(0, TerrainType.Grass); return(HexToLogicPos(hex, height)); }
//static int min = int.MaxValue; //static int max = int.MinValue; public void UpdateMap() { int initTile = LogicTile.SetTerrain(0, TerrainType.Grass); initTile = LogicTile.SetAltitude(initTile, LogicTile.MAX_ALTITUDE / 2); map.Clear(initTile); GenerateMap(); //AltitudeAbsNoise(map, 5, seed, 100); //AltitudeNoise(map, 5, seed, 40); //AltitudeNoise(map, 6, seed, 20); //Noise(map, seed); /* * int gridSize = 8; * int gridRowCount = 5; * LogicHex center = new LogicHex(map.width/2,map.height/2); * LogicHex start = center.Sub(new LogicHex(gridSize * gridRowCount / 2, gridSize * gridRowCount / 2)); * * List<LogicHex> nodes = CreateGrid(gridSize, gridRowCount); * OffsetNodes(nodes, start); * RandomOffsetNodes(nodes, 7, seed); * * PlotNodes(map, nodes, 3, TerrainType.Sand); */ //int min, max; //GetAltitudeRange(map, out min, out max); /* * if (min < LogicWorld.min) * LogicWorld.min = min; * * if (max > LogicWorld.max) * LogicWorld.max = max; * * Debugger.Log("Altitude range 1 [" + LogicWorld.min + " - " + LogicWorld.max + "]"); * Debugger.Log("Altitude range 2 [" + LogicPerlinNoise.minNoise + " - " + LogicPerlinNoise.maxNoise + "]"); */ /*for(int i = -LogicPerlinNoise.SCALE; i < LogicPerlinNoise.SCALE; ++i) * { * int altitude = LogicPerlinNoise.ScaleNoise(i,LogicTile.MAX_ALTITUDE); * * if (altitude < min) * min = altitude; * * if (altitude > max) * max = altitude; * * }*/ //Debugger.Log("Altitude range 3 [" + min + " - " + max + "]"); }
public static void PlotNodes(LogicHexMap map, List <LogicHex> nodes, int radius, TerrainType terrain) { for (int i = 0; i < nodes.Count; ++i) { LogicHex node = nodes[i]; int tile = map.Get(node); tile = LogicTile.SetTerrain(tile, terrain); map.Set(node, tile); } }
public static void AltitudeAbsNoise(LogicHexMap map, int octave, int seed, int percent) { for (int r = 0; r < map.height; ++r) { for (int q = 0; q < map.width; ++q) { int tile = map.Get(q, r); int altitude = LogicTile.GetAltitude(tile); LogicPoint3 pos = HexToLogicPos(new LogicHex(q, r), altitude * ALTITUDE_SCALE); int noise = LogicPerlinNoise.Noise((pos.x << octave) + seed, (pos.z << octave) + seed, seed << 2, LogicTween.SCALE); int distanceToMiddle = (noise - LogicTween.SCALE_HALF); bool flip = false; if (distanceToMiddle < 0) { distanceToMiddle = -distanceToMiddle; flip = true; } distanceToMiddle = LogicTween.QuadIn(distanceToMiddle * 2) / 2; if (flip) { distanceToMiddle = -distanceToMiddle; } noise = LogicTween.SCALE_HALF + distanceToMiddle; noise = noise / (LogicTween.SCALE / LogicTile.MAX_ALTITUDE); /*int noise = LogicPerlinNoise.Noise((pos.x << octave) + seed, (pos.z << octave) + seed, seed << 2, LogicTile.MAX_ALTITUDE*2); * noise -= LogicTile.MAX_ALTITUDE; * if (noise < 0) * noise = -noise; * * * LogicTween.QuadIn(); */ //noise = LogicPerlinNoise.ScaleNoise(noise, LogicTile.MAX_ALTITUDE); altitude = Lerp(altitude, noise, percent); tile = LogicTile.SetAltitude(tile, altitude); map.Set(q, r, tile); } } }
public void Touch2Hex(LogicHex hex) { //tiles.Clear(); int tile = LogicTile.SetTerrain(0, TerrainType.Rock); //LogicHex origo = new LogicHex(9, 9); //tiles.Set(origo, tile); touch2 = hex; UpdateMap(); //map.Set(hex, tile); }
public static void AltitudeFlip(LogicHexMap map, int cutoff) { for (int r = 0; r < map.height; ++r) { for (int q = 0; q < map.width; ++q) { int tile = map.Get(q, r); int altitude = LogicTile.GetAltitude(tile); tile = LogicTile.SetAltitude(tile, altitude); map.Set(q, r, tile); } } }
public static int GetAverageHeight(LogicIntArray2 tiles, int x0, int y0, int width, int height) { int sum = 0; int count = 0; for (int y = y0; y < tiles.height && y < y0 + height; ++y) { for (int x = x0; x < tiles.width && x < x0 + width; ++x) { ++count; sum += LogicTile.GetAltitude(tiles.Get(x, y)); } } if (count == 0) { return(0); } return(sum / count); }
public static void AltitudeNoise(LogicHexMap map, int octave, int seed, int percent) { for (int r = 0; r < map.height; ++r) { for (int q = 0; q < map.width; ++q) { int tile = map.Get(q, r); int altitude = LogicTile.GetAltitude(tile); LogicPoint3 pos = HexToLogicPos(new LogicHex(q, r), altitude * ALTITUDE_SCALE); int noise = LogicPerlinNoise.Noise((pos.x << octave) + seed, (pos.z << octave) + seed, seed << 2, LogicTile.MAX_ALTITUDE); altitude = Lerp(altitude, noise, percent); tile = LogicTile.SetAltitude(tile, altitude); map.Set(q, r, tile); } } }
public LogicIntArray2 CreateRoom(int width, int height, int tileHeight) { int tile = 0; tile = LogicTile.SetTerrain(tile, TerrainType.Dirt); tile = LogicTile.SetRoom(tile, 1); tile = LogicTile.SetAltitude(tile, tileHeight); LogicIntArray2 room = new LogicIntArray2(width, height, tile); /* * for (int y = 0; y < width; ++y) * { * for (int x = 0; x < width; ++x) * { * room.Set(x,y,tile); * } * }*/ return(room); }
public static void GetAltitudeRange(LogicHexMap map, out int min, out int max) { max = int.MinValue; min = int.MaxValue; for (int r = 0; r < map.height; ++r) { for (int q = 0; q < map.width; ++q) { int tile = map.Get(q, r); int altitude = LogicTile.GetAltitude(tile); if (altitude < min) { min = altitude; } if (altitude > max) { max = altitude; } } } }
public int GetLogicTile() { int tile = LogicTile.SetAltitude(0, altitude / TILE_ALTITUDE_SCALE); return(LogicTile.SetTerrain(tile, terrain)); }