private CityGraph AddBuildingsToCity(CityGraph currentCity, int lotsToPlace) { //Sort Edges by distance from the center in travel time. List <CityGraph.Edge> allEdges = new List <CityGraph.Edge>(currentCity.GetEdges()); allEdges.Sort(CompareEdges); //place lots on edges (left or right) //Lots are made up of at least 4 points. float totalLotsToPlace = lotsToPlace; for (int i = 0; i < allEdges.Count && lotsToPlace > 0; i++) { if (Random.value < (1 - populationDensity)) { continue; } if (allEdges [i].NeighbouringLotsCount < 2) { GridPoint point1 = allEdges [i].pointA.position; GridPoint point2 = allEdges [i].pointB.position; Vector2 point1Vec = point1.ConvertToWorldPoint(m_PointSpacing); Vector2 point2Vec = point2.ConvertToWorldPoint(m_PointSpacing); Vector2 edgeVector = point2Vec - point1Vec; Vector2 rhNormal = new Vector2(edgeVector.y, -edgeVector.x); Vector2 lhNormal = new Vector2(-edgeVector.y, edgeVector.x); CityGraph.Lot rhLot = new CityGraph.Lot(point1, point2, ConvertToGridPoint(point1Vec + rhNormal), ConvertToGridPoint(point2Vec + rhNormal)); CityGraph.Lot lhLot = new CityGraph.Lot(point1, point2, ConvertToGridPoint(point1Vec + lhNormal), ConvertToGridPoint(point2Vec + lhNormal)); bool coinFlip = Random.value > 0.5f; CityGraph.Lot lotToAdd = rhLot; if (coinFlip == true) { lotToAdd = lhLot; } bool success = currentCity.AddLot(allEdges [i], lotToAdd); if (!success) { lotToAdd = coinFlip ? rhLot : lhLot; success = currentCity.AddLot(allEdges [i], lotToAdd); } if (success) { lotsToPlace--; } } } return(currentCity); }
private void TryRemoveHighValuePoint(GridPoint point) { Vector2 worldPoint = point.ConvertToWorldPoint(m_PointSpacing); for (int i = m_RemainingHighValuePoints.Count - 1; i >= 0; i--) { if (Vector2.Distance(m_RemainingHighValuePoints [i].ConvertToWorldPoint(m_PointSpacing), worldPoint) < 0.5f) { m_RemainingHighValuePoints.RemoveAt(i); } } }
private Vector2 GetRandomPoint() { if (m_RemainingHighValuePoints.Count > 0 && Random.value > 0.4f) { int randomHVIndex = Random.Range(0, m_RemainingHighValuePoints.Count); GridPoint highValuePoint = m_RemainingHighValuePoints [randomHVIndex]; return(highValuePoint.ConvertToWorldPoint(m_PointSpacing)); } else { int randPointIndex = Random.Range(0, m_FreePointsTable.Count); GridPoint newPoint = m_FreePointsTable.ElementAt(randPointIndex).Key; RemovePoint(newPoint); return(newPoint.ConvertToWorldPoint(m_PointSpacing)); } }
private CityGraph BuildRRT(CityGraph init, int numVerticesK, float incDist) { CityGraph outputGraph = init; RemoveObstructedPoints(); if (restrictToCircle) { } for (int k = 0; k < numVerticesK; k++) { Vector2 qRand = GetRandomPoint(); GridPoint qNear = GetNearestPoint(qRand, init); float curInc = incDist - ((outputGraph.GetVertexCount() / reduceIncEvery) * reduceBy); curInc = Mathf.Max(curInc, minIncrement); GridPoint qNew = NewConfig(qNear.ConvertToWorldPoint(m_PointSpacing), qRand, curInc); outputGraph.AddVertex(qNew); outputGraph.AddEdge(qNear, qNew); } return(outputGraph); }