private void OnDelete() { // We first add selected road to the deleted roads because when we do Remove() on "Roads", the next selected road will be the one after previous selected one RoadsObs.Instance.DeletedRoads.Add(SelectedRoad); Roads.Remove(SelectedRoad); serializer.SerializeObject <ObservableCollection <Road> >(Roads, "roads.xml"); }
public void InitRoadArray(ref Roads[] roads) { for (int i = 0; i < roads.Length; i++) { roads[i] = new Roads(); } }
private Node GetObjectUnderMouse() { var currentLoc = SelectRect.Position; if (currentLoc != null) { var zoneUnder = Zones.FirstOrDefault(a => a.Position == currentLoc); var buildingUnder = Buildings.FirstOrDefault(a => a.Position == currentLoc); var roadUnder = Roads.FirstOrDefault(a => a.Position == currentLoc); if (zoneUnder != null) { return(zoneUnder as Node); } else if (buildingUnder != null) { return(buildingUnder as Node); } else if (roadUnder != null) { return(roadUnder as Node); } else { return(null); } } else { return(null); } }
public void AddCityCentre(List <Vector3> _intersections) { Point a = new Point(); Point b = new Point(); for (int i = 0; i < _intersections.Count; i++) { if (i % 2 == 0 || i == 0) { a.position.x = _intersections[i].x; //Draws new road for every point made a.position.y = _intersections[i].z; } else { b.position.x = _intersections[i].x; b.position.y = _intersections[i].z; Roads rb = new Roads(a, b); Roads.Add(rb); Intersection ab = new Intersection(new List <Point>() { rb.start }); Intersections.Add(ab); } } }
int InRoad(Point P, Roads S) { if (S.start.position.x != S.end.position.x) { if (S.start.position.x <= P.position.x && P.position.x <= S.end.position.x) { return(1); } if (S.start.position.x >= P.position.x && P.position.x >= S.end.position.x) { return(1); } } else // S is vertical, so test y coordinate { if (S.start.position.y <= P.position.y && P.position.y <= S.end.position.y) { return(1); } if (S.start.position.y >= P.position.y && P.position.y >= S.end.position.y) { return(1); } } return(0); }
void Awake() { //inits //Debug.Log("Runninng inits"); rowList = new List<GameObject> (); roadEnd = new RoadEnd (gameController); roads = new Roads (); }
private int IntersectionCount(Roads segment, out Vector2 intersection, out Roads other, Roads skip) { intersection = Vector2.zero; other = null; Vector2 tmp = Vector2.zero; Vector2 interTmp = Vector3.zero; int count = 0; for (int i = 0; i < this.Roads.Count; i++) { Roads seg = this.Roads[i]; if (seg.Equals(skip)) { continue; } else if (Vector2.Distance(seg.start.position, segment.start.position) < 0.01f || Vector2.Distance(seg.end.position, segment.end.position) < 0.01f) { continue; } else if (Vector2.Distance(seg.start.position, segment.end.position) < 0.01f || Vector2.Distance(seg.end.position, segment.start.position) < 0.01f) { continue; } else if (TwoDimentsionalIntersection(segment, seg, out interTmp, out tmp) != 0) { other = seg; intersection = new Vector2(interTmp.x, interTmp.y); count++; } } return(count); }
public void EvaluateRoad(Roads _road) { Vector2 start = _road.start.position; Vector2 end = _road.end.position; Vector2 dir = (end - start).normalized; float distance = Vector2.Distance(start, end); Vector2 current = start; bool side = true; for (float f = roadWidth; f < distance || side; f += 1.5f) { if (f > distance && side) { side = false; f = roadWidth; } Vector2 per = new Vector2(-dir.y, dir.x); if (side) { per *= -1; } BuildingGen(start, dir, distance, side, f, per); } }
public override bool Equals(object other) { Roads otherRoad = other as Roads; return(start.Equals(otherRoad.start) && end.Equals(otherRoad.end) || start.Equals(otherRoad.end) && end.Equals(otherRoad.start)); }
private bool CreateSingleLevel() { int tmp = 0; for (int i = 0; i < RoadCount; i++) { tmp = i; bool BuildSuccess = false; roads[i].type = (RoadType)Random.Range(0, 2); if (roads[i].type == RoadType.roadstraight) { BuildSuccess = BuildStraightRoad(i); } if (BuildSuccess) { continue; } BuildSuccess = BuildTurnRoad(i); if (!BuildSuccess) { CheckIfCompleted = FinishLevel(i); PositionOfCheckeredFlagInArray = i; Debug.Log("Broken " + i); return(false); } } PositionOfCheckeredFlagInArray = tmp; //Was not changing the postion of the flag so this appeard to be the case. Not true, I think. lastRoad = roads[RoadCount - 2]; //This happens because 'lastRoad' is set to 'RoadCount - 1' on last intereration of the for loop CheckIfCompleted = FinishLevel(RoadCount - 1); //When checking for the last collion. Could be rewritten to take of such exception, in theory. Debug.Log(roads[9].direction);Debug.Log(roads[8].direction);Debug.Log(lastRoad.direction); return(true); }
/// <summary> /// Добавляет новую дорогу в город, а также автоматически проверяет её пересечение /// с другими дорогами и границами города. Если пересечение найдется, то на это место будет /// добавлена новая постройка. Но если в городе уже существует постройка на найденных координатах пересечения, /// то новая добавлена не будет. /// Помимо этого, добавляет в список «соседей» уже существующих построек новую. /// </summary> /// <param name="newRoad">Новая дорогая для добавления.</param> public void AddRoad(Road newRoad) { foreach (Road existedRoad in Roads) { if (existedRoad.TryGetIntersectPoint(newRoad, out var intersectPoint)) { Institution newInstitution; if (Institutions.Contains(intersectPoint)) { newInstitution = Institutions[intersectPoint]; } else { newInstitution = _insitutionBuilder.Build(existedRoad, newRoad, intersectPoint); Institutions.Add(newInstitution); } UpdateNeighbours(existedRoad, newInstitution, intersectPoint); UpdateNeighbours(newRoad, newInstitution, intersectPoint); } } Roads.Add(newRoad); }
void TriangulateRoadSegment(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, Vector3 v5, Vector3 v6) { Roads.AddQuad(v1, v2, v4, v5); Roads.AddQuad(v2, v3, v5, v6); Roads.AddQuadUV(0f, 1f, 0f, 0f); Roads.AddQuadUV(1f, 0f, 0f, 0f); }
public void TriangulateAllCells() { // This method could be invoked at any time, even when cells have already been triangulated earlier. // So we should begin by clearing the old data. Terrain.Clear(); Rivers.Clear(); Roads.Clear(); Water.Clear(); WaterShore.Clear(); Estuaries.Clear(); Features.Clear(); for (int i = 0; i < _cells.Length; i++) { Precalculation(_cells[i]); } for (int i = 0; i < _cells.Length; i++) { TriangulateCell(_cells[i]); AddFeatures(_cells[i]); } Terrain.Apply(); Rivers.Apply(); Roads.Apply(); Water.Apply(); WaterShore.Apply(); Estuaries.Apply(); Features.Apply(); }
/// <summary> Adds road element to terrain. </summary> /// <param name="roadElement">Road element</param> public void AddRoad(RoadElement roadElement) { lock (Roads) { Roads.Add(roadElement); } }
//-------------------------------------------------------------------------------------------- void Start() { seed = UnityEngine.Random.Range(0, 1000); Roads road = new Roads(); road.width = width; road.height = height; road.mean = mean; road.std_dev = std_dev; road.generateRandomPoints(); road.returnEdges(); edges = road.edges; road.placeRoads(); roads = road.roads; Buildings buildings = new Buildings(); buildings.width = width; buildings.height = height; buildings.edges = edges; buildings.c = offsetFromRoad; //intercept offset buildings.placeBuildings(); buildings.putBuildingsWithPerlinNoise(); houses = buildings.houses; scatterHouses(); removeIntersections(); }
public Map Generate() { TriangleNet.Mesh mesh = createMesh(); Map map = new Map(); foreach (TriangleNet.Geometry.Vertex triVertex in mesh.Vertices) { Vertex v = map.AddVertex((float)triVertex.x, (float)triVertex.y); vertexIDMap.Add(triVertex.GetHashCode(), v.ID); } foreach (TriangleNet.Geometry.Edge Edge in mesh.Edges) { map.AddEdge(vertexIDMap[Edge.P0], vertexIDMap[Edge.P1]); } Prims prims = new Prims(map); prims.AssignMSTEdges(); Roads roads = new Roads(map, roadDensity); roads.AssignRoadEdges(); return(map); }
public void Read(Stream input, Endian endian = Endian.Little) { RoadGraphRoadToJunctionEdgeMappingCount = input.ReadValueU16(endian); RoadGraphEdgeCount = input.ReadValueU16(endian); for (int i = 0; i < RoadGraphEdgeCount; i++) { RoadGraphEdges.Add(new Tuple <ushort, ushort>(input.ReadValueU16(endian), input.ReadValueU16(endian))); } ushort roadCount = input.ReadValueU16(endian); for (int i = 0; i < roadCount; i++) { var road = new RoadDefinitionDe(); road.Read(input, endian); Roads.Add(road); } for (int i = 0; i < RoadGraphEdgeCount; i++) { var costMapping = new CostMapEntryDe(); costMapping.Read(input, endian); CostMap.Add(costMapping); } byte magic0 = input.ReadValueU8(); byte magic1 = input.ReadValueU8(); byte magic2 = input.ReadValueU8(); byte magic3 = input.ReadValueU8(); if (magic0 != 0x11 && magic1 != 0x11 && magic2 != 0x11 && magic3 != 0) { throw new IOException($"Unexpected magic values ({magic0}, {magic1}, {magic2}, {magic3})"); } ushort splineCount = input.ReadValueU16(endian); for (int i = 0; i < splineCount; i++) { var spline = new RoadSplineDe(); spline.Read(input, endian); Splines.Add(spline); } for (int i = 0; i < roadCount * 2; i++) { RoadToCrossroadMapping.Add(input.ReadValueU16(endian)); } ushort crossroadCount = input.ReadValueU16(endian); for (int i = 0; i < crossroadCount; i++) { var crossroad = new CrossroadDe(); crossroad.Read(input, endian); Crossroads.Add(crossroad); } }
public void Mapinit() { ElementsManager.Instance.SwitchCheckPoint(); roads = GetComponentInChildren <Roads>(); Lanes = roads.list_Lane; ElementsManager.Instance.RemoveAllElements(); SetMapElements(); }
public Settlement Copy() { var copy = new Settlement(Fields, MainRoad, false); Roads.Cast <ICopyable <Road> >().ToList().ForEach(g => copy.Roads.Add(g.Copy())); copy.Fitness = this.Fitness; return(copy); }
private void TriangulateRoadEdge(Vector3 centre, Vector3 ml, Vector3 mr, float index) { Roads.AddTriangle(centre, ml, mr); Roads.AddTriangleUV(new Vector3(1f, 0f), new Vector3(0f, 0f), new Vector3(0f, 0f)); var indices = new Vector3(index, index, index); Roads.AddTriangleCellData(indices, weights1); }
/// <summary> /// Creates the geometry for connecting different roads that converge on the cell center. /// </summary> void TriangulateRoadEdge(Vector3 center, Vector3 mL, Vector3 mR, float index) { Roads.AddTriangle(center, mL, mR); Roads.AddTriangleUV(new Vector2(1f, 0f), new Vector2(0f, 0f), new Vector2(0f, 0f)); Vector3 indices; indices.x = indices.y = indices.z = index; Roads.AddTriangleCellData(indices, weights1); }
public void Setup(Vertex position, Roads roads) { this.position = position; this.roads = roads; var target = new GameObject(name + " Waypoint Target").transform; this.GetComponent <WaypointProgressTracker>().target = target; this.GetComponent <CarAIControl>().m_Target = target; }
private void BuildRoads() { var topology = new Topology(this); var roads = new List <List <Vector2> > (); var streets = new List <List <Vector2> > (); foreach (var gate in Gates.ToList()) { var endPoint = Market.Shape.Vertices.OrderBy(v => (gate - v).magnitude).First(); var street = topology.BuildPath(gate, endPoint, topology.Outer); if (street != null) { //roads.Add(street); streets.Add(street); if (CityWall.Gates.Contains(gate)) { var direction = GeometryHelpers.Scale(gate - Center, 100000); var start = topology.Node2V.Values.OrderBy(v => (v - direction).magnitude).First(); var road = topology.BuildPath(start, gate, topology.Inner); if (road == null) { CityWall.Gates.Remove(gate); CityWall.Towers.Add(gate); Gates.Remove(gate); } else { roads.Add(road); } } } } if (!roads.Any()) { throw new InvalidOperationException("No roads into the town"); } Roads.AddRange(TidyUpRoads(roads)); Streets.AddRange(TidyUpRoads(streets)); foreach (var road in Roads) { var insideVertices = road.Where(rv => Patches.Where(p => p.Shape.ContainsPoint(rv)).All(p => p.WithinCity)).Except(Gates).ToList(); foreach (var insideVertex in insideVertices) { road.Remove(insideVertex); } } }
public void CountRoads(bool on) { if (on) { Roads.ForEach(r => Factors.Add(r)); } else { Roads.ForEach(r => Factors.Remove(r)); } }
private Roads[] Patch(Roads segment, Point splitPosition) { this.Roads.RemoveAll(p => p.Equals(segment)); Roads left = new Roads(segment.start, new Point(splitPosition.position)); Roads right = new Roads(segment.end, new Point(splitPosition.position)); this.Roads.Add(left); this.Roads.Add(right); return(new Roads[] { left, right }); }
private void TriangulateRoadSegment( Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, Vector3 v5, Vector3 v6, Color w1, Color w2, Vector3 indices) { Roads.AddQuad(v1, v2, v4, v5); Roads.AddQuad(v2, v3, v5, v6); Roads.AddQuadUV(0f, 1f, 0f, 0f); Roads.AddQuadUV(1f, 0f, 0f, 0f); Roads.AddQuadCellData(indices, w1, w2); Roads.AddQuadCellData(indices, w1, w2); }
IEnumerator UnfadeToNormal(GameObject road) { yield return(new WaitForSeconds(2f)); Glow glow = GetRoadFromAngle(transform.rotation.eulerAngles.y).GetComponent <Glow> (); if (glow.GetColor() == commandColor) { glow.SetColor(glow.originalColor); Roads.Remove(road); } }
private void RefreshRoads() { Roads.Clear(); foreach (var cell in CenteredCells) { RoadTriangulator.TriangulateRoads(cell, Roads); } Roads.Apply(); TerrainBaker.BakeIntoChunk(this); }
public void PlaceRoad(int x, int y) { Construct road = new Construct(ConstructType.Road); road.X = (byte)x; road.Y = (byte)y; road.Config = ConstructConfig.EndPieceBottom; Roads.Add(road); // TODO: Only check adjacent roads DetermineConstructConfigForAllConstructs(); }
/// <summary> /// Create the two quads of a road segment. /// </summary> void TriangulateRoadSegment(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, Vector3 v5, Vector3 v6, Color w1, Color w2, Vector3 indices) { Roads.AddQuad(v1, v2, v4, v5); Roads.AddQuad(v2, v3, v5, v6); // This results in U for the 2 road quads -> 0 ||||| 1 1 ||||| 0 // This way we can use U in the shader as a measure of how close we are to the center of the road Roads.AddQuadUV(0f, 1f, 0f, 0f); Roads.AddQuadUV(1f, 0f, 0f, 0f); Roads.AddQuadCellData(indices, w1, w2); Roads.AddQuadCellData(indices, w1, w2); }
private async Task <bool> AddZone <T> (T zone, Vector2 Location) { var existingZone = Zones.FirstOrDefault(a => a.Position == Location); var existingBuilding = Buildings.FirstOrDefault(a => a.Position == Location); var existingRoad = Roads.FirstOrDefault(a => a.Position == Location); if (existingZone != null || existingBuilding != null) { if (existingZone != null) { DeleteObject(existingZone); } else if (existingBuilding != null) { DeleteObject(existingBuilding); } else if (existingRoad != null) { DeleteObject(existingRoad); } } if (zone is ResidentialZone) { Node z1 = zone as Node; CallDeferred("add_child", zone as Node); var _z = z1 as ResidentialZone; _z.Position = Location; _z.ID = (Zones.Count() < 1) ? 1 : Zones.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1; Zones.Add(_z); } else if (zone is BusinessZone) { Node z1 = zone as Node; CallDeferred("add_child", zone as Node); var _z = z1 as BusinessZone; _z.Position = Location; _z.ID = (Zones.Count() < 1) ? 1 : Zones.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1; Zones.Add(_z); } else if (zone is IndustryZone) { Node z1 = zone as Node; CallDeferred("add_child", zone as Node); var _z = z1 as IndustryZone; _z.Position = Location; _z.ID = (Zones.Count() < 1) ? 1 : Zones.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1; Zones.Add(_z); } return(await Task.FromResult(true).ConfigureAwait(false)); }
private int buildSecRoads(ref Roads.Road road,MapHexa currentHexa, Roads.Road.RoadBlock currentBlock,int id,MapHexa.HexDir incDir) { Roads.Road.RoadBlock newBlock; List <MapHexa.HexDir> possibleDirections = initDirectionsExcNbours (incDir); // Randomize next direction for (int i = possibleDirections.Count-1; i >= 0; i--) { // Randomize direction MapHexa.HexDir dir = possibleDirections [Random.Range (0, i+1)]; possibleDirections.Remove (dir); //Debug.Log ("Checking direction "+dir); // Take hexa from that direction if (currentHexa.getNeighbour (dir) == null) continue; MapHexa hexa = currentHexa.getNeighbour (dir).GetComponent<MapHexa>(); // Check if we have reached end OR we are colliding other road here //Debug.Log("pörrr"); if (isHexaAtTheEdge (hexa.getCoords ())) { // Continue to next direction if we can't continue; } MapHexa nearbyHexa = isOtherRoadNearby (hexa, road.roadId); if (nearbyHexa != null) { newBlock = new Roads.Road.RoadBlock (hexa.getCoords (),id); currentBlock.nextRoadBlock.roadId = road.roadId; currentBlock.nextRoadBlock.roadBlockId = newBlock.blockId; road.addRoadBlock (newBlock); newBlock.finalRoad = true; newBlock.nextRoadBlock.roadId = nearbyHexa.roadBlock.roadId; newBlock.nextRoadBlock.roadBlockId = nearbyHexa.roadBlock.blockId; hexa.finalR = true; return 1; } if (isEndNear(hexa)) { newBlock = new Roads.Road.RoadBlock (hexa.getCoords (),id); currentBlock.nextRoadBlock.roadId = road.roadId; currentBlock.nextRoadBlock.roadBlockId = newBlock.blockId; road.addRoadBlock (newBlock); newBlock.finalRoad = true; newBlock.nextRoadBlock.roadId = Constants.RoadEndId; newBlock.nextRoadBlock.roadBlockId = Constants.RoadEndId; hexa.finalR = true; return 1; } // Check if we can go there if (isHexaNearThisRoad(hexa.getCoords(),road.roadId,getCounterDir(dir)) ){ // Continue to next direction if we can't continue; } // Add new roadBlock with given id newBlock = new Roads.Road.RoadBlock (hexa.getCoords (),id); road.addRoadBlock (newBlock); // Call next roadblock int ret = buildSecRoads(ref road, hexa,newBlock,id+1,getCounterDir(dir)); // Check if we have been successful reaching the end, set hexa to road if (ret == 1) { currentBlock.nextRoadBlock.roadId = road.roadId; currentBlock.nextRoadBlock.roadBlockId = newBlock.blockId; newBlock.finalRoad = true; hexa.finalR = true; // Finally, remove all the extra blocks if (id == 1) { for (int a = road.roadBlocks.Count-1; a >=0; a--) { if (!road.roadBlocks [a].finalRoad) { road.deleteRoadBlock (road.roadBlocks[a].coord); } } //Debug.Log ("Roadhexas block: "+ road.getRoadBlock(2).blockId +" and "+ mapData.getHexa(road.getRoadBlock(2).coord).GetComponent<MapHexa>().roadBlock.blockId); } return 1; } // Leave the block only if ret is 1 // Else we have to continue if we can reach the end from here } // If we fail at this point, clean made block and return to previous block //Debug.Break(); return 0; }
// Builds first road from start to end. private int buildMainRoad(ref Roads.Road road,MapHexa currentHexa, Roads.Road.RoadBlock currentBlock,int id,MapHexa.HexDir incDir) { //if (id == 83) // return 1; //MapHexa.Coordinate currentCoords = currentRoadBlock.getCoords (); //bool foundNext = false; //Debug.Log ("<color=red> Now at "+currentHexa.getCoords().rowId+" "+currentHexa.getCoords().hexaId+" </color> "); Roads.Road.RoadBlock newBlock; List <MapHexa.HexDir> possibleDirections = initDirectionsExcNbours (incDir); // Randomize next direction for (int i = possibleDirections.Count-1; i >= 0; i--) { // Randomize direction MapHexa.HexDir dir = possibleDirections [Random.Range (0, i+1)]; possibleDirections.Remove (dir); //Debug.Log ("Checking direction "+dir); // Take hexa from that direction if (currentHexa.getNeighbour (dir) == null) continue; MapHexa hexa = currentHexa.getNeighbour (dir).GetComponent<MapHexa>(); // Check if we have reached end if (isEndNear(hexa)) { //Debug.Log ("End found"); newBlock = new Roads.Road.RoadBlock (hexa.getCoords (),id); currentBlock.nextRoadBlock.roadId = road.roadId; currentBlock.nextRoadBlock.roadBlockId = newBlock.blockId; road.addRoadBlock (newBlock); newBlock.finalRoad = true; newBlock.nextRoadBlock.roadId = Constants.RoadEndId; newBlock.nextRoadBlock.roadBlockId = Constants.RoadEndId; hexa.finalR = true; return 1; } //Debug.Log ("<color=red>Going to </color> "+dir); // Check if we can go there if (isHexaAtTheEdge (hexa.getCoords ())) { // Continue to next direction if we can't continue; } if (isHexaNearThisRoad(hexa.getCoords(),road.roadId,getCounterDir(dir)) ){ // Continue to next direction if we can't continue; } // Add new roadBlock with given id newBlock = new Roads.Road.RoadBlock (hexa.getCoords (),id); road.addRoadBlock (newBlock); // Call next roadblock int ret = buildMainRoad(ref road, hexa,newBlock,id+1,getCounterDir(dir)); // Check if we have been successful reaching the end, set hexa to road if (ret == 1) { currentBlock.nextRoadBlock.roadId = road.roadId; currentBlock.nextRoadBlock.roadBlockId = newBlock.blockId; newBlock.finalRoad = true; hexa.finalR = true; // Finally, remove all the extra blocks if (id == 1) { for (int a = road.roadBlocks.Count-1; a >=0; a--) { if (!road.roadBlocks [a].finalRoad) { road.deleteRoadBlock (road.roadBlocks[a].coord); } } } return 1; } // Leave the block only if ret is 1 // Else we have to continue if we can reach the end from here } // If we fail at this point, clean made block and return to previous block //Debug.Break(); return 0; }
void Awake() { //inits rowList = new List<GameObject> (); roadEnd = new Roads.RoadEnd (this.gameObject); roads = new Roads (); }