public WorldPointContinent ContinentPointToWorldPoint(ContinentPoint point, WorldCreationStatic Sim) { Vector2 mod = Vector2.zero; Vector2 newPos = point.Pos + WorldPointCenter.Pos; if (newPos.x > Sim.Width - 1) { mod = new Vector2(-Sim.Width, 0); } if (newPos.x > Sim.Width * 2 - 1) { mod = new Vector2(-Sim.Width * 2, 0); } if (newPos.x < 0) { mod = new Vector2(Sim.Width, 0); } if (newPos.x < -Sim.Width) { mod = new Vector2(Sim.Width * 2, 0); } if (newPos.y >= 100) { return(null); } if (newPos.y < 0) { return(null); } if (!Sim.WorldPointContinents.ContainsKey(newPos + mod)) { Debug.Log("Bad Vector: " + (point.Pos + WorldPointCenter.Pos + mod) + " points: " + point.Pos + WorldPointCenter.Pos + mod); } return(Sim.WorldPointContinents[point.Pos + WorldPointCenter.Pos + mod]); }
public void CreateContinents() { int Ocean = WorldPointContinents.Count; int Land = 0; //for (int i = 0; i < 7; i++) while (true) { Continent cont = new Continent(new WorldPointContinent(new Vector2(Random.Range(0, Width), Random.Range(0, Height)))); Continents.Add(cont); Dictionary <Vector2, bool> Map = new ZoomLandCreation(5, 5).Create(3); int width = (int)Map.Select(p => p.Key.x).Max() / (int)2; List <Vector2> LandPoints = new List <Vector2>(); foreach (var pair in Map) { if (pair.Value) { LandPoints.Add(pair.Key); } } foreach (var p in LandPoints) { ContinentPoint cp = new ContinentPoint(p - new Vector2(width, width), cont); if (cont.Points.ContainsKey(p - new Vector2(width, width))) { continue; } cont.Points.Add(p - new Vector2(width, width), cp); WorldPointContinent wp = cont.ContinentPointToWorldPoint(cp, this); if (wp != null && wp.contPoint == null) { wp.contPoint = cp; Land++; Ocean--; } } if ((float)Land / (float)(Ocean + Land) > 0.3f) { break; } } foreach (WorldPointContinent wp in WorldPointContinents.Values) { GameObject go = Instantiate(cubePrefab); go.transform.position = wp.Pos; go.GetComponent <MeshRenderer>().material = Resources.Load <Material>("green"); go.GetComponent <MeshRenderer>().material.color = wp.contPoint == null ? Color.blue : Color.green; wp.go = go; } }
public void CreateContinents() { List <Vector2> ContinentPoints = new List <Vector2>() { new Vector2(30, 30), new Vector2(51, 65), new Vector2(106, 53), new Vector2(106, 23), new Vector2(140, 34), new Vector2(138, 74) }; for (int i = 0; i < 6; i++) { Continent cont = new Continent(new WorldPointContinent(new Vector2(ContinentPoints[i].x, Height - ContinentPoints[i].y))); Continents.Add(cont); Dictionary <Vector2, bool> Map = new Dictionary <Vector2, bool>(); while (Map.Count < 2300) { Map = new ZoomLandCreation(5, 5).Create(4); } int width = (int)Map.Select(p => p.Key.x).Max() / (int)2; List <Vector2> LandPoints = new List <Vector2>(); foreach (var pair in Map) { if (pair.Value) { LandPoints.Add(pair.Key); } } foreach (var p in LandPoints) { ContinentPoint cp = new ContinentPoint(p - new Vector2(width, width), cont); if (cont.Points.ContainsKey(p - new Vector2(width, width))) { continue; } cont.Points.Add(p - new Vector2(width, width), cp); WorldPointContinent wp = cont.ContinentPointToWorldPoint(cp, this); if (wp != null && wp.contPoint == null) { wp.contPoint = cp; } } } foreach (WorldPointContinent wp in WorldPointContinents.Values) { GameObject go = Instantiate(cubePrefab); go.transform.position = wp.Pos; go.GetComponent <MeshRenderer>().material = Resources.Load <Material>("green"); go.GetComponent <MeshRenderer>().material.color = wp.contPoint == null ? Color.blue : Color.green; wp.go = go; gos.Add(go); } }
public void AdditionalSubduction(WorldPointContinent origSubductionPoint, Continent subductingContinent, Continent growingContinent) { //if (Random.Range(0, 2) == 0) { if (WorldPointContinents.ContainsKey(origSubductionPoint.Pos + subductingContinent.driftDirection)) { WorldPointContinent AddedHeightPoint = WorldPointContinents[origSubductionPoint.Pos + subductingContinent.driftDirection]; ContinentPoint cp = WorldPointContinentToContinentPoint(AddedHeightPoint, growingContinent); if (cp != null) { cp.height++; } } } }
public List <ContinentPoint> GetXNeighbors(ContinentPoint point, int width) { List <ContinentPoint> Neighbors = new List <ContinentPoint>(); for (int x = -width; x <= width; x++) { for (int y = -width; y <= width; y++) { if (x == 0 && y == 0) { continue; } if (Points.ContainsKey(new Vector2(x + point.Pos.x, y + point.Pos.y))) { Neighbors.Add(Points[new Vector2(x + point.Pos.x, y + point.Pos.y)]); } } } return(Neighbors); }
public void RecalculateWorldPointContinents(Continent Cont) { //foreach (Continent plate in Plates) { Dictionary <ContinentPoint, ContinentPoint> Collisions = new Dictionary <ContinentPoint, ContinentPoint>(); foreach (ContinentPoint point in Cont.Points.Values) { WorldPointContinent wp = Cont.ContinentPointToWorldPoint(point, this); if (wp != null) { if (wp.contPoint != null) { Collisions.Add(wp.contPoint, point); } else { wp.contPoint = point; } } } foreach (Continent collCont in Collisions.Select(p => p.Key.cont).Distinct()) { Dictionary <ContinentPoint, ContinentPoint> ContinentCollisionPoints = Collisions.Where(p => p.Key.cont == collCont).ToDictionary(p => p.Key, p => p.Value); if (ContinentCollisionPoints.Count < 10) //if ((float)ContinentCollisionPoints.Count / (float)collCont.Points.Count < 0.025f) { foreach (var pair in ContinentCollisionPoints) { //not big enough to be collision, smaller one subducts WorldPointContinent wp = collCont.ContinentPointToWorldPoint(pair.Key, this); ContinentPoint theirPoint = pair.Key; ContinentPoint ourPoint = pair.Value; if (Cont.GetNeighbors(ourPoint).Count < 3) { //island or something, we give it to them theirPoint.height += 2; Cont.Points.Remove(ourPoint.Pos); /*Vector2 worldPosition = collCont.WorldPointCenter.Pos + theirPoint.Pos; * ContinentPoint theirNewPoint = new ContinentPoint(worldPosition - Cont.WorldPointCenter.Pos, Cont); * theirNewPoint.height = theirPoint.height; * if (!collCont.Points.ContainsKey(theirNewPoint.Pos)) * { * collCont.Points.Add(theirNewPoint.Pos, theirNewPoint); * WorldPointContinent wp2 = collCont.ContinentPointToWorldPoint(theirNewPoint, this); * if (wp2 != null) * wp2.contPoint = theirNewPoint; * }*/ // if(Random.Range(0,2) == 0) AdditionalSubduction(wp, Cont, collCont); } else if (collCont.GetNeighbors(theirPoint).Count < 3) { //we are colliding with an island ourPoint.height += 2; wp.contPoint = ourPoint; collCont.Points.Remove(theirPoint.Pos); /* Vector2 worldPosition = collCont.WorldPointCenter.Pos + theirPoint.Pos; * ContinentPoint ourNewPoint = new ContinentPoint(worldPosition - Cont.WorldPointCenter.Pos, Cont); * ourNewPoint.height = theirPoint.height; * if (!Cont.Points.ContainsKey(ourNewPoint.Pos)) * { * Cont.Points.Add(ourNewPoint.Pos, ourNewPoint); * WorldPointContinent wp2 = Cont.ContinentPointToWorldPoint(ourNewPoint, this); * if (wp2 != null) * wp2.contPoint = ourNewPoint; * }*/ AdditionalSubduction(wp, collCont, Cont); } else if (ourPoint.height > theirPoint.height) //cont already there subducts { ourPoint.height += 2; wp.contPoint = ourPoint; collCont.Points.Remove(theirPoint.Pos); // if (Random.Range(0, 2) == 0) AdditionalSubduction(wp, collCont, Cont); } else //our cont subducts { theirPoint.height += 2; Cont.Points.Remove(ourPoint.Pos); //if (Random.Range(0, 2) == 0) AdditionalSubduction(wp, Cont, collCont); } } } else { //big enough, the continents become one //first fix collision points foreach (var pair in ContinentCollisionPoints) { WorldPointContinent wp = collCont.ContinentPointToWorldPoint(pair.Key, this); ContinentPoint theirPoint = pair.Key; ContinentPoint ourPoint = pair.Value; wp.contPoint = ourPoint; ourPoint.height++; collCont.Points.Remove(theirPoint.Pos); AdditionalSubduction(wp, collCont, Cont); } //then move their cont points to our continent foreach (ContinentPoint theirPoint in collCont.Points.Values) { Vector2 worldPosition = collCont.WorldPointCenter.Pos + theirPoint.Pos; ContinentPoint ourNewPoint = new ContinentPoint(worldPosition - Cont.WorldPointCenter.Pos, Cont); ourNewPoint.height = theirPoint.height; if (!Cont.Points.ContainsKey(ourNewPoint.Pos)) { Cont.Points.Add(ourNewPoint.Pos, ourNewPoint); WorldPointContinent wp = Cont.ContinentPointToWorldPoint(ourNewPoint, this); if (wp != null) { wp.contPoint = ourNewPoint; } } } DeletedContinents.Add(collCont); } } } }
public void SplitContinent(Continent c) { //first split Dictionary <Vector2, List <Vector2> > voronoiCenters = new Dictionary <Vector2, List <Vector2> >(); int worldXMin = (int)c.Points.Min(p => p.Key.x) + (int)c.WorldPointCenter.Pos.x; int worldXMax = (int)c.Points.Max(p => p.Key.x) + (int)c.WorldPointCenter.Pos.x; int worldYMin = (int)c.Points.Min(p => p.Key.y) + (int)c.WorldPointCenter.Pos.y; int worldYMax = (int)c.Points.Max(p => p.Key.y) + (int)c.WorldPointCenter.Pos.y; //now split the continent Vector2 cont1 = new Vector2(Random.Range(worldXMin, worldXMax), Random.Range(worldYMin, worldYMax)); Vector2 cont2 = new Vector2(Random.Range(worldXMin, worldXMax), Random.Range(worldYMin, worldYMax)); if (!WorldPointContinents.ContainsKey(cont1) || !WorldPointContinents.ContainsKey(cont2)) { return; } Continent newCont1 = new Continent(c.WorldPointCenter); Continent newCont2 = new Continent(c.WorldPointCenter); for (int i = 0; i < 20; i++) { Vector2 voronoi = new Vector2(Random.Range(worldXMin, worldXMax), Random.Range(worldYMin, worldYMax)); voronoiCenters.Add(voronoi, new List <Vector2>()); } foreach (ContinentPoint cp in c.Points.Values) { Vector2 cpWorldPos = cp.Pos + c.WorldPointCenter.Pos; float shortestDist = 9999; Vector2 voronoi = Vector2.zero; foreach (var pair in voronoiCenters) { float dist = Vector2.Distance(cpWorldPos, pair.Key); if (dist < shortestDist) { shortestDist = dist; voronoi = pair.Key; } } voronoiCenters[voronoi].Add(cp.Pos); } List <ContinentPoint> con1Points = new List <ContinentPoint>(); List <ContinentPoint> con2Points = new List <ContinentPoint>(); foreach (var pair in voronoiCenters) { float dist1 = Vector2.Distance(cont1, pair.Key); float dist2 = Vector2.Distance(cont2, pair.Key); if (dist1 < dist2) { foreach (Vector2 v in pair.Value) { ContinentPoint newCP = new ContinentPoint(v - cont1, newCont1); newCP.height = c.Points[v].height; con1Points.Add(newCP); } } else { foreach (Vector2 v in pair.Value) { ContinentPoint newCP = new ContinentPoint(v - cont2, newCont2); newCP.height = c.Points[v].height; con2Points.Add(newCP); } } } newCont1.driftDirection = (cont1 - cont2).normalized; newCont1.driftDirection = new Vector2((int)newCont1.driftDirection.x + 1, (int)newCont1.driftDirection.y + 1); newCont2.driftDirection = (cont2 - cont1).normalized; newCont2.driftDirection = new Vector2((int)newCont2.driftDirection.x + 1, (int)newCont2.driftDirection.y + 1); newCont1.driftDuration = 15; newCont2.driftDuration = 15; Continents.Add(newCont1); Continents.Add(newCont2); Continents.Remove(c); lastContBreak = age; }