예제 #1
0
    void SetUpNewIntersection(Road road, Road otherRoad, Vector3 intersection, Junction j, RoadMap map)
    {
        // split road that is being intersected
        Road newRoad = segFactory.CreateRoad(intersection, otherRoad.end, otherRoad.t, otherRoad.type);

        otherRoad.MoveEnd(intersection);

        // set up links between roads
        newRoad.next.AddRange(otherRoad.next);
        newRoad.Parent = otherRoad;
        newRoad.prev.Add(new Road.Neighbour(road, true));
        road.next.Add(new Road.Neighbour(newRoad, true));
        road.next.Add(new Road.Neighbour(otherRoad, false));
        foreach (Road.Neighbour n in otherRoad.next)
        {
            n.r.ReplaceNeighbour(otherRoad, newRoad);
            //n.r.RemoveNeighbour(otherRoad);
            //n.r.prev.Add(new Road.Neighbour(newRoad, true));
        }

        otherRoad.next.Clear();
        otherRoad.next.Add(new Road.Neighbour(newRoad, true));
        otherRoad.next.Add(new Road.Neighbour(road, false));
        j.AddIncoming(road);
        j.AddOutgoing(newRoad);
        j.AddIncoming(otherRoad);
        map.AddRoad(newRoad);
    }
예제 #2
0
    public void Generate(int seed)
    {
        Random.InitState(seed);
        Heatmap.Seed(seed);
        if (CityConfig.SHOW_HEATMAP)
        {
            heatmapVis.Generate();
        }
        PriorityQueue <Road> priorityQ = new PriorityQueue <Road>();

        // set up first two segments in centre of map
        Road root1 = segFactory.CreateRoad(
            new Vector3(0, 0, 0),
            new Vector3(CityConfig.HIGHWAY_SEGMENT_LENGTH, 0, 0),
            0,
            RoadType.Highway);
        Road root2 = segFactory.CreateRoad(
            new Vector3(0, 0, 0),
            new Vector3(-CityConfig.HIGHWAY_SEGMENT_LENGTH, 0, 0),
            0,
            RoadType.Highway);

        root1.Parent = root2;
        root2.Parent = root1;
        priorityQ.Enqueue(root1);
        priorityQ.Enqueue(root2);

        int roadCount = 0;

        while (priorityQ.Count() > 0)
        {
            Road nextRoad = priorityQ.Dequeue();
            if (roadCount < CityConfig.MAX_ROADS)
            {
                // check local constraints
                bool accepted = localConstraints.Check(nextRoad, map);
                if (accepted)
                {
                    // set up branch links
                    // activate road
                    map.AddRoad(nextRoad);
                    foreach (Junction j in nextRoad.attachedSegments)
                    {
                        map.AddJunction(j);
                    }
                    roadCount++;

                    // generate new possible branches according to global goals
                    List <Road> goals = globalGoals.Generate(nextRoad, map);
                    foreach (Road r in goals)
                    {
                        priorityQ.Enqueue(r);
                    }
                }
                else
                {
                    DestroyImmediate(nextRoad.gameObject);
                }
            }
            else
            {
                // delete leftover roads after maximum has been exceeded
                DestroyImmediate(nextRoad.gameObject);
            }
        }
        print("Created " + roadCount + " roads!");

        lotsGenerator.Generate(map.allRoads);
    }