void ColorWindDirection(MapLoc l) { GameObject go = Tiles[l]; ResetTile(go); Color cb = Color.black; Color ct = Color.white; if (mapGen.Elevation[l.x, l.y] > mapGen.seaLevel) { cb = Color.white; ct = Color.black; } go.GetComponent <Renderer>().material.SetColor("_Color", cb); TextMesh tm = go.GetComponentInChildren <TextMesh>(); if (tm != null) { tm.text = '\u2192'.ToString(); tm.color = ct; Vec v = mapGen.WindVector[l.x, l.y]; float z = 0f; float z2 = 90f; float d = 0f; if (!v.Equals(null)) { d = MapUtil.VectorToRadians(v.x, v.y); d = MapUtil.RadiansToDegrees(d); z = 90f; z2 = 0f; } //Debug.Log("[" + l.x + "," + l.y + "] is ["+v.x+","+v.y+"]"); tm.GetComponentInParent <Transform>().eulerAngles = new Vector3(z, d, z2); } }
public static void ThermalWorkhorse(float[,] Elevation, MapLoc l, float talusAngle) { Dictionary <MapLoc, float> n = MapUtil.GetValidNeighbors(Elevation, l); // Thermal Erosion float di; float dtotal = 0f; float dmax = float.NegativeInfinity; foreach (KeyValuePair <MapLoc, float> kvp in n) { di = Elevation[l.x, l.y] - Elevation[kvp.Key.x, kvp.Key.y]; if (di > talusAngle) { dtotal += di; di = di > dmax ? dmax : di; } } float startingElev = Elevation[l.x, l.y]; foreach (KeyValuePair <MapLoc, float> kvp in n) { di = startingElev - Elevation[kvp.Key.x, kvp.Key.y]; float delta = 0.5f * (dmax - talusAngle) * di / dtotal; Elevation[kvp.Key.x, kvp.Key.y] += delta; Elevation[l.x, l.y] -= delta; } }
public void TurnWind(WindTurnType wt, float[,] Elevation, float seaLevel) { if (wt == WindTurnType.None) { // do nothing } else if (wt == WindTurnType.RandomWalk) { int r = UnityEngine.Random.Range(-1, 1); velocity = new Vec(velocity.x, r); } else if (wt == WindTurnType.TerrainBased) { if (Elevation[approxMapLoc.x, approxMapLoc.y] > seaLevel) { velocity.x -= deltaHeight; velocity.y -= deltaHeight; Vec lVec = velocity.GetRotatedVector(-90); Vec rVec = velocity.GetRotatedVector(90); MapLoc lMapLoc = new MapLoc((int)(Math.Max(1, actualMapLoc.x + lVec.x)), (int)Math.Max(1, actualMapLoc.y + lVec.y)); MapLoc rMapLoc = new MapLoc((int)(Math.Max(1, actualMapLoc.x + rVec.x)), (int)Math.Max(1, actualMapLoc.y + rVec.y)); try { float fDiff = Elevation[lMapLoc.x, lMapLoc.y] - Elevation[rMapLoc.x, rMapLoc.y]; velocity.x += lMapLoc.x * fDiff; velocity.y += lMapLoc.y * fDiff; } catch { // ¯\_(ツ)_/¯ } } } }
private void AStarWorkhorse(ref List <Node> prioQueue, ref bool PathFound, MapLoc originMapLoc, MapLoc destinationMapLoc) { prioQueue = prioQueue.OrderBy(x => x.distanceFrom[originMapLoc] + x.distanceTo[destinationMapLoc]).ToList(); Node n = prioQueue.First(); prioQueue.Remove(n); foreach (Node neighbor in n.neighbors) { if (!neighbor.Visited) { float newCost = n.distanceFrom[originMapLoc] + n.neighborWeights[neighbor]; if (!neighbor.distanceFrom.ContainsKey(originMapLoc) || newCost < neighbor.distanceFrom[originMapLoc]) // this will cause problems if there is ever no cost between nodes! { neighbor.distanceFrom[originMapLoc] = newCost; neighbor.NearestTo[originMapLoc] = n; if (!prioQueue.Contains(neighbor)) { prioQueue.Add(neighbor); } } } } n.Visited = true; if (n.loc.Equals(destinationMapLoc)) { PathFound = true; } }
public static Dictionary <MapLoc, float> GetValidNeighbors(float[,] Elevation, MapLoc l, bool excludeSelf = true, bool includeDiagonal = false, bool Wrap = true) { Dictionary <MapLoc, float> neighbors = new Dictionary <MapLoc, float>(); int x = 0; int y = 0; int xDim = Elevation.GetLength(0); int yDim = Elevation.GetLength(1); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (excludeSelf && i == 0 && j == 0) { } else { GetCoordinates(xDim, yDim, l.x + i, l.y + j, ref x, ref y, Wrap); if (x >= 0 && y >= 0 && x < xDim && y < yDim) { if (includeDiagonal || Math.Sqrt(i * i + j * j) <= 1) { neighbors[new MapLoc(x, y)] = Elevation[x, y]; } } } } } return(neighbors); }
public static Vec VectorBetween(MapLoc l1, MapLoc l2) { float x = l2.x - l1.x; float y = l1.y - l2.y; return(new Vec(x, y)); }
public void SetNodeList(float[,] _elevation, float _seaLevel, delCost fCost, float _seaTravelCost = 0f) { int xDim = _elevation.GetLength(0); int yDim = _elevation.GetLength(1); Node[,] nodes = new Node[xDim, yDim]; for (int x = 0; x < xDim; x++) { for (int y = 0; y < yDim; y++) { nodes[x, y] = new Node(x, y); nodeDict[new MapLoc(x, y)] = nodes[x, y]; } } for (int x = 0; x < xDim; x++) { for (int y = 0; y < yDim; y++) { Node n = nodes[x, y]; n.Visited = false; MapLoc l = new MapLoc(x, y); Dictionary <MapLoc, float> d = MapUtil.GetValidNeighbors(_elevation, l); foreach (KeyValuePair <MapLoc, float> kvp in d) { n.neighborWeights[nodes[kvp.Key.x, kvp.Key.y]] = fCost(l, kvp.Key, _elevation, _seaLevel, _seaTravelCost); n.neighbors.Add(nodes[kvp.Key.x, kvp.Key.y]); } nodelist.Add(n); } } }
public static List <MapLoc> GetMapLocsDescending(float[,] Elevation, Benchmark bench = null) { if (bench != null) { bench.StartBenchmark("GetMapLocsDescending"); } List <MapLoc> dMapLocs = new List <MapLoc>(); int xDim = Elevation.GetLength(0); int yDim = Elevation.GetLength(1); for (int x = 0; x < xDim; x++) { for (int y = 0; y < yDim; y++) { MapLoc l = new MapLoc(x, y); l.v = Elevation[x, y]; dMapLocs.Add(l); } } dMapLocs.OrderBy(l => l.v); dMapLocs.Reverse(); if (bench != null) { bench.EndBenchmark("GetMapLocsDescending"); } return(dMapLocs); }
public static List <MapLoc> GetListOfDepressedMapLocs(float[,] Elevation) { List <MapLoc> depressedMapLocs = new List <MapLoc>(); int xDim = Elevation.GetLength(0); int yDim = Elevation.GetLength(1); MapLoc l; float e; bool lIsDepressed; for (int x = 0; x < xDim; x++) { for (int y = 0; y < yDim; y++) { l = new MapLoc(x, y); e = Elevation[x, y]; lIsDepressed = true; Dictionary <MapLoc, float> lNeighbors = GetValidNeighbors(Elevation, l); // Get Depressed MapLocs foreach (KeyValuePair <MapLoc, float> n in lNeighbors) { if (n.Value <= e) { lIsDepressed = false; break; } } if (lIsDepressed) { depressedMapLocs.Add(l); } } } return(depressedMapLocs); }
public void FlowProportional(ref float[,] flowStep, MapLoc l) { Dictionary <MapLoc, float> neighbors = MapUtil.GetValidNeighbors(Elevation, l, false); // Flow Proportional float localHeight = Elevation[l.x, l.y]; Dictionary <MapLoc, float> lowerNeighbors = new Dictionary <MapLoc, float>(); float fDiff; float totalDiff = 0f; foreach (KeyValuePair <MapLoc, float> n in neighbors) { if (n.Value < localHeight) { fDiff = localHeight - n.Value; lowerNeighbors[n.Key] = fDiff; totalDiff += fDiff; } } if (lowerNeighbors.Count > 0) { foreach (KeyValuePair <MapLoc, float> n in lowerNeighbors) { flowStep[n.Key.x, n.Key.y] += Water[l.x, l.y] * n.Value / totalDiff; } } else { float newElev = MapUtil.GetNeighborAverage(Elevation, l); newElev = (newElev + Elevation[l.x, l.y]) / 2f; Elevation[l.x, l.y] = newElev; } }
public Path(MapLoc _origin, MapLoc _destination, List <Node> _path, float _distancePath, float _distanceEuclidean) { originMapLoc = _origin; destinationMapLoc = _destination; distancePath = _distancePath; distanceEuclidean = _distanceEuclidean; path = _path; }
public Wind(float _x, float _y, float _xv, float _yv, float _water, float[,] Elevation) { actualMapLoc = new Vec(_x, _y); approxMapLoc = new MapLoc((int)_x, (int)_y); velocity = new Vec(_xv, _yv); Water = _water; xDim = Elevation.GetLength(0); yDim = Elevation.GetLength(1); }
void ColorSpectrum(MapLoc l) { GameObject go = Tiles[l]; ResetTile(go); float e = mapGen.WaterFlux[l.x, l.y]; Color c = MapColor.GetColorContinuous(e, cdictSpectrum); go.GetComponent <Renderer>().material.SetColor("_Color", c); }
void ColorWaterFlux(MapLoc l) { GameObject go = Tiles[l]; ResetTile(go); float e = mapGen.WaterFlux[l.x, l.y]; Color c = mapGen.Elevation[l.x, l.y] < mapGen.seaLevel ? ColorBasic(e, 0f, Color.black, Color.blue) : ColorBasic(e, 0f, Color.white, Color.blue); go.GetComponent <Renderer>().material.SetColor("_Color", c); }
void ColorWindMagnitude(MapLoc l) { GameObject go = Tiles[l]; ResetTile(go); float e = mapGen.WindMagnitude[l.x, l.y]; Color c = ColorBasic(e, 0f, Color.white, Color.black); go.GetComponent <Renderer>().material.SetColor("_Color", c); }
void ColorTemperature(MapLoc l) { GameObject go = Tiles[l]; ResetTile(go); float e = mapGen.Temperature[l.x, l.y]; Color c = ColorBasic(e, 0f, Color.blue, Color.red); go.GetComponent <Renderer>().material.SetColor("_Color", c); }
private void BeforeScenario() { CurrentLocation = new MapLoc { Terrain = Terrain.Citadel, Flags = 0, Thing = ThingType.None, HasObject = false }; }
void ColorLandmass(MapLoc l) { GameObject go = Tiles[l]; ResetTile(go); float e = mapGen.Elevation[l.x, l.y]; Color c = ColorCutoff(e, mapGen.seaLevel, Color.blue, Color.green); go.GetComponent <Renderer>().material.SetColor("_Color", c); }
private void AStarInit(out List <Node> prioQueue, MapLoc originMapLoc, MapLoc destinationMapLoc) { foreach (Node n in nodelist) { n.distanceTo[destinationMapLoc] = MapUtil.Distance(n.loc, destinationMapLoc); } nodeDict[originMapLoc].distanceFrom[originMapLoc] = 0f; prioQueue = new List <Node>(); prioQueue.Add(nodeDict[originMapLoc]); }
public static float CostStandard(MapLoc l, MapLoc n, float[,] _elevation, float _seaLevel, float _seaTravelCost) { float nelev = _elevation[n.x, n.y]; float lelev = _elevation[l.x, l.y]; float diff = (nelev > _seaLevel && lelev > _seaLevel) ? Math.Abs(nelev - lelev) : _seaTravelCost; float dist = MapUtil.Distance(n, l); diff *= dist; diff += dist; return(diff); }
public static float GetNeighborAverage(float[,] Elevation, MapLoc l) { Dictionary <MapLoc, float> neighbors = GetValidNeighbors(Elevation, l); // GetNeighborAversge List <float> NeighborHeights = new List <float>(); foreach (KeyValuePair <MapLoc, float> kvp in neighbors) { NeighborHeights.Add(kvp.Value); } return(NeighborHeights.Average()); }
public static bool IsBorder(MapLoc l, float[,] Elevation) { int x = l.x; int y = l.y; int xDim = Elevation.GetLength(0); int yDim = Elevation.GetLength(1); bool isBorder = (x == 0 || y == 0 || x == xDim - 1 || y == yDim - 1) ? true : false; return(isBorder); }
public Path GetPath(MapLoc origin, MapLoc destination) { PathOD p = new PathOD(origin, destination); bool pathFound = false; if (!PathDict.ContainsKey(p)) { pathFound = AStarSearch(origin, destination); } return(PathDict[p]); }
public Node(int _x, int _y) { x = _x; y = _y; loc = new MapLoc(_x, _y); distanceTo = new Dictionary <MapLoc, float>(); distanceFrom = new Dictionary <MapLoc, float>(); distanceBetween = new Dictionary <PathOD, float>(); neighbors = new List <Node>(); NearestTo = new Dictionary <MapLoc, Node>(); neighborWeights = new Dictionary <Node, float>(); }
void ColorFlatness(MapLoc l) { Color c = MapColor.GetColorLerp(mapGen.Elevation[l.x, l.y], Color.white, Color.black); //float e = mapGen.WaterFlux[l.x, l.y]; c = mapGen.Elevation[l.x, l.y] < mapGen.seaLevel ? Color.blue : c; GameObject go = Tiles[l]; ResetTile(go); go.GetComponent <Renderer>().material.SetColor("_Color", c); }
void ColorBasic(MapLoc l) { float arableFrac = 2f; //2.5f GameObject go = Tiles[l]; ResetTile(go); float e = mapGen.Elevation[l.x, l.y]; Color c = ColorCutoff(e, mapGen.seaLevel, Color.black, Color.green); float f = mapGen.WaterFlux[l.x, l.y]; c = (f > mapGen.riverLevel / arableFrac && e > mapGen.seaLevel) ? Color.yellow : c; // a rough representation of arable land c = (f > mapGen.riverLevel && e > mapGen.seaLevel) ? Color.blue : c; go.GetComponent <Renderer>().material.SetColor("_Color", c); }
void ColorNatural(MapLoc l) { GameObject go = Tiles[l]; ResetTile(go); float e = mapGen.Elevation[l.x, l.y]; float r = mapGen.WaterFlux[l.x, l.y]; Color c = MapColor.GetColorContinuous(e, cdictNatural); c = (r > mapGen.riverLevel && e > mapGen.seaLevel) ? MapColor.GetColorLerp(0.5f, Color.cyan, Color.blue) : c; //c = (r > mapGen.riverLevel && e > mapGen.seaLevel) ? Color.cyan : c; c = (mapGen.Temperature[l.x, l.y] < mapGen.iceLevel) ? Color.white : c; go.GetComponent <Renderer>().material.SetColor("_Color", c); }
public static int RiverNeighbors(MapLoc l, float[,] WaterFlux, float riverLevel) { Dictionary <MapLoc, float> neighbors = GetValidNeighbors(WaterFlux, l); int numberRiverNeighbors = 0; foreach (KeyValuePair <MapLoc, float> kvp in neighbors) { if (kvp.Value > riverLevel) { numberRiverNeighbors++; } } return(numberRiverNeighbors); }
public static int OceanNeighbors(MapLoc l, float[,] Elevation, float seaLevel) { Dictionary <MapLoc, float> neighbors = GetValidNeighbors(Elevation, l); int numberOceanNeighbors = 0; foreach (KeyValuePair <MapLoc, float> kvp in neighbors) { if (kvp.Value < seaLevel) { numberOceanNeighbors++; } } return(numberOceanNeighbors); }
void ColorRegions(MapLoc l) { Color c = mapGen.Elevation[l.x, l.y] < mapGen.seaLevel ? Color.black : Color.white; GameObject go = Tiles[l]; ResetTile(go); go.GetComponent <Renderer>().material.SetColor("_Color", c); TextMesh tm = go.GetComponentInChildren <TextMesh>(); if (tm != null) { tm.text = mapGen.Regions[l.x, l.y].ToString(); tm.color = mapGen.Elevation[l.x, l.y] < mapGen.seaLevel ? Color.white : Color.black; } }