Пример #1
0
    // Deep copy Data
    public void DeepCopyData(BuildingLot _lot)
    {
        transform.position = _lot.transform.position;

        lotWidth = _lot.lotWidth;

        lotLength = _lot.lotLength;

        divided = _lot.divided;

        counter = _lot.counter;

        tileSize = _lot.tileSize;

        lotWidthUpdated = _lot.lotWidthUpdated;

        lotLengthUpdated = _lot.lotLengthUpdated;

        division = _lot.division;

        lotIndex = _lot.lotIndex;

        offsetX = _lot.offsetX;

        offsetZ = _lot.offsetZ;

        buildingWidth = _lot.buildingWidth;

        buildingLength = _lot.buildingLength;

        buildingHeight = _lot.buildingHeight;

        maxBuildingHeight = _lot.maxBuildingHeight;
    }
    private static void SetMutations(BuildingLot _lot)
    {
        // Find out how many mutations this building can have
        // (max 1 for each size)

        if (MutationNegX(_lot))
        {
            _lot.GetMutationList().Add(0); // NegX
        }
        if (MutationPosX(_lot))
        {
            _lot.GetMutationList().Add(1); // PosX
        }
        if (MutationNegZ(_lot))
        {
            _lot.GetMutationList().Add(2); // NegZ
        }
        if (MutationPosZ(_lot))
        {
            _lot.GetMutationList().Add(3); // PosZ
        }
        //pass through how many possible mutations,
        // Randomly set no of mutations for building
        // randomly choose face to mutate, check if possible? if so apply change
        if (_lot.GetMutationList().Count > 0) // Cant mutation a building with no room!
        {
            ApplyMutations(_lot);
        }
    }
Пример #3
0
 public RouteManager.Orientation get_station_orientation_with_room()
 {
     RouteManager.Orientation orientation = RouteManager.Orientation.East;
     foreach (KeyValuePair <string, GameObject> entry in building_map)
     {
         // do something with entry.Value or entry.Key
         BuildingLot bldg_lot    = entry.Value.GetComponent <BuildingLot>();
         int         train_count = bldg_lot.get_train_count();
         if (train_count < 2) // stations are not full
         {
             if (train_count < bldg_lot.building.get_occupancy_count())
             {
                 if (!bldg_lot.building.is_building_empty())
                 {
                     return(bldg_lot.orientation);
                 }
                 else
                 {
                     orientation = bldg_lot.orientation;
                 }
             }
             else
             {
                 orientation = bldg_lot.orientation;
             }
         }
     }
     return(orientation);
 }
    private static void GenerateMain(BuildingLot _lot)
    {
        // PosX
        Vector3 pos = _lot.transform.position + new Vector3(_lot.GetOffsetX() +
                                                            _lot.GetCurrentBuildingWidth(), 0.0f, _lot.GetOffsetZ() + (float)panelSize / 2);

        GeneratePosXPanels(_lot, (int)_lot.GetCurrentBuildingLength(), pos, _lot.GetBuildingPanels());

        // PosZ
        pos = _lot.transform.position + new Vector3(_lot.GetOffsetX() + (float)panelSize / 2, 0.0f,
                                                    _lot.GetOffsetZ() + _lot.GetCurrentBuildingLength());

        GeneratePosZPanels(_lot, (int)_lot.GetCurrentBuildingWidth(), pos, _lot.GetBuildingPanels());

        // NegX
        pos = _lot.transform.position + new Vector3(_lot.GetOffsetX(), 0.0f, _lot.GetOffsetZ() +
                                                    (float)panelSize / 2);

        GenerateNegXPanels(_lot, (int)_lot.GetCurrentBuildingLength(), pos, _lot.GetBuildingPanels());

        // NegZ
        pos = _lot.transform.position + new Vector3(_lot.GetOffsetX() + (float)panelSize / 2, 0.0f,
                                                    _lot.GetOffsetZ());

        GenerateNegZPanels(_lot, (int)_lot.GetCurrentBuildingWidth(), pos, _lot.GetBuildingPanels());

        // PosY
        pos = _lot.transform.position + new Vector3(_lot.GetOffsetX() + (float)panelSize / 2,
                                                    _lot.GetCurrentBuildingHeight() - (float)panelSize / 2, _lot.GetOffsetZ() + (float)panelSize / 2);

        GeneratePosYPanels(_lot, (int)_lot.GetCurrentBuildingWidth(), (int)_lot.GetCurrentBuildingLength(),
                           pos, _lot.GetBuildingPanels());
    }
    private static void ApplyMutations(BuildingLot _lot)
    {
        int maxMutations = 0;

        maxMutations = (int)Random.Range(0, _lot.GetMutationList().Count + 1);

        while (_lot.GetMutationList().Count > 0)
        {
            // Randomly choose face
            int face = (int)Random.Range(0, _lot.GetMutationList().Count);

            int direction = _lot.GetMutationList()[face];

            DirectMutation(_lot, direction);

            //Remove possible mutation from list
            for (int i = 0; i < _lot.GetMutationList().Count; i++)
            {
                if (_lot.GetMutationList()[i] == direction)
                {
                    _lot.GetMutationList().RemoveAt(i);
                    continue;
                }
            }
        }
    }
    private static void DirectMutation(BuildingLot _lot, int _direction)
    {
        // NegX = 0
        // PosX = 1
        // NegZ = 2
        // PosZ = 3

        switch (_direction)
        {
        case 0:
            GenerateNegXMutation(_lot);
            break;

        case 1:
            GeneratePosXMutation(_lot);
            break;

        case 2:
            GenerateNegZMutation(_lot);
            break;

        case 3:
            GeneratePosZMutation(_lot);
            break;
        }
    }
Пример #7
0
    public void Cancel()
    {
        Debug.Log("build cancel");

        active.closeGUI();
        buildMenu.SetActive(false);
        active = null;
    }
Пример #8
0
 public void CloseMenu(BuildingLot lot)
 {
     if (active == lot)
     {
         buildMenu.SetActive(false);
         active = null;
     }
 }
    private static bool MutationNegZ(BuildingLot _lot)
    {
        if (_lot.GetOffsetZ() != 0)
        {
            return(true);
        }

        return(false);
    }
    private static bool MutationPosX(BuildingLot _lot)
    {
        if (_lot.GetOffsetX() + _lot.GetCurrentBuildingWidth() < _lot.GetLotWidth())
        {
            return(true);
        }

        return(false);
    }
    private static bool MutationPosZ(BuildingLot _lot)
    {
        if (_lot.GetOffsetZ() + _lot.GetCurrentBuildingLength() < _lot.GetLotLength())
        {
            return(true);
        }

        return(false);
    }
Пример #12
0
 public void OpenMenu(BuildingLot lot)
 {
     if (active == null)
     {
         buildMenu.SetActive(true);
         active = lot;
         ButtonActivation();
         TextUpdate();
     }
 }
Пример #13
0
 public void initialize_city_tilemap()
 {
     foreach (string initial_building_lot in CityManager.initial_building_lot_list)
     {
         GameObject  first_building_lot_go = building_map[initial_building_lot];
         BuildingLot initial_bl            = first_building_lot_go.GetComponent <BuildingLot>();
         spawn_building(initial_bl);
         show_all_building_occupants(false); // hide all doors when city is first created
         building_id += 1;
     }
 }
Пример #14
0
    public void spawn_building(BuildingLot building_lot)
    {
        Building building = get_city_building();

        building_lot.set_building(building);
        building.building_id          = building_id;
        building.building_type        = city_type;
        building.building_orientation = building_lot.orientation;
        building.offset_position      = building_lot.origin_tile;
        building.max_capacity         = building_lot.length;
        building.person_grid          = new GameObject[building_lot.length];
        building.city         = this;
        building.building_lot = building_lot;
        city_building_list.Add(building);
    }
Пример #15
0
    //public Vector2 building_lot_to_thought_offset(BuildingLot bldg_lot)
    //{
    //    Vector2 thought_bubble_offset = new Vector2(0, 0);
    //    switch (bldg_lot.orientation)
    //    {
    //        case RouteManager.Orientation.North:
    //            thought_bubble_offset = new Vector2(3.6f, 0);
    //            break;
    //        case RouteManager.Orientation.East:
    //            thought_bubble_offset = new Vector2(2.6f, 2.6f);
    //            break;
    //        case RouteManager.Orientation.South:
    //            thought_bubble_offset = new Vector2(-3.6f, 2.6f);
    //            break;
    //        case RouteManager.Orientation.West:
    //            thought_bubble_offset = new Vector2(2.6f, 2.6f);
    //            break;
    //    }
    //    return thought_bubble_offset;
    //}

    public Sprite desired_activity_to_throught_sprite(string desired_activity, BuildingLot bldg_lot)
    {
        if (desired_activity == "work_thought_bubble")
        {
            if (bldg_lot.orientation == RouteManager.Orientation.West || bldg_lot.orientation == RouteManager.Orientation.East)
            {
                return(work_thought_bubble);
            }
            else
            {
                return(small_work_thought_bubble);
            }
        }
        if (desired_activity == "home_thought_bubble")
        {
            if (bldg_lot.orientation == RouteManager.Orientation.West || bldg_lot.orientation == RouteManager.Orientation.East)
            {
                return(home_thought_bubble);
            }
            else
            {
                return(small_home_thought_bubble);
            }
        }
        if (desired_activity == "restaurant_thought_bubble")
        {
            if (bldg_lot.orientation == RouteManager.Orientation.West || bldg_lot.orientation == RouteManager.Orientation.East)
            {
                return(restaurant_thought_bubble);
            }
            else
            {
                return(small_restaurant_thought_bubble);
            }
        }
        if (desired_activity == "vacation_thought_bubble")
        {
            if (bldg_lot.orientation == RouteManager.Orientation.West || bldg_lot.orientation == RouteManager.Orientation.East)
            {
                return(vacation_thought_bubble);
            }
            else
            {
                return(small_vacation_thought_bubble);
            }
        }
        throw new Exception("no sprite matches bubble");
    }
Пример #16
0
    public void Bisect()
    {
        if (_isFinal)
        {
            FindSidewalkNLotVerts();
            //CityMapManager.Instance.AddRoad(this);
            CityMapManager.Instance.AddSidewalk(this);
            initialLot = new BuildingLot(this);
            if (initialLot.isFinal())
            {
                initialLot.freeEdges.AddRange(new int[] { 0, 1, 2, 3 });
                finalLots.Add(initialLot);
            }
            else
            {
                CreateBuildingLots();
            }

            CityMapManager.Instance.Add(this);
            return;
        }

        var big_offset = Random.Range(0f, _divergence * edges[0].length) * edges[0].direction;

        if (Util.RollDice(new float[] { 0.5f, 0.5f }) == 1)
        {
            big_offset *= -1;
        }
        var opp_offset = Random.Range(0f, _divergence * edges[2].length) * edges[2].direction;

        if (Util.RollDice(new float[] { 0.5f, 0.5f }) == 1)
        {
            opp_offset *= -1;
        }

        Block b1 = new Block(edges[3].start, edges[3].end,
                             edges[0].middle + big_offset, edges[2].middle + opp_offset);

        b1.Bisect();
        Block b2 = new Block(edges[1].start, edges[1].end,
                             edges[2].middle + opp_offset, edges[0].middle + big_offset);

        b2.Bisect();
    }
    private static void GeneratePosZPanels(BuildingLot _lot, int _sectionWidth,
                                           Vector3 _startPos, List <Panel> _panels)
    {
        Vector3 pos = _startPos;

        Vector3 rot = new Vector3(90.0f, 0.0f, 0.0f);

        for (int h = 0; h < _lot.GetCurrentBuildingHeight(); h++)
        {
            for (int w = 0; w < _sectionWidth; w++)
            {
                var panel = new Panel(h, w, pos, rot);

                _panels.Add(panel);

                pos.x += panelSize;
            }

            pos.x -= _sectionWidth;
            pos.y += panelSize;
        }
    }
    private static void MergeList(BuildingLot _lot, List <Panel> _addedPanels)
    {
        for (int i = _addedPanels.Count - 1; i >= 0; i--)
        {
            for (int j = _lot.GetBuildingPanels().Count - 1; j >= 0; j--)
            {
                // If panel is overlapping, discard them as they must be inside the mesh
                if (_addedPanels[i].Position() == _lot.GetBuildingPanels()[j].Position())
                {
                    _lot.GetBuildingPanels().RemoveAt(j);
                    _addedPanels.RemoveAt(i);
                    break;
                }
            }
        }

        // Add remaining panels
        foreach (Panel panel in _addedPanels)
        {
            _lot.GetBuildingPanels().Add(panel);
        }
    }
    private static void GeneratePosYPanels(BuildingLot _lot, int _sectionWidth,
                                           int _sectionLength, Vector3 _startPos, List <Panel> _panels)
    {
        Vector3 pos = _startPos;

        Vector3 rot = Vector3.zero;

        for (int h = 0; h < _sectionLength; h++)
        {
            for (int w = 0; w < _sectionWidth; w++)
            {
                var panel = new Panel(h, w, pos, rot);

                _panels.Add(panel);

                pos.x += panelSize;
            }

            pos.x -= _sectionWidth;
            pos.z += panelSize;
        }
    }
Пример #20
0
    public List <int[]> get_parking_spot_with_room()
    {
        List <int[]> room_availability_list           = new List <int[]>();
        List <int[]> room_availability_and_train_list = new List <int[]>(); //takes priority because it has train

        foreach (KeyValuePair <string, GameObject> entry in building_map)
        {
            // do something with entry.Value or entry.Key
            BuildingLot bldg_lot = entry.Value.GetComponent <BuildingLot>();
            if (bldg_lot.building.current_capacity > 0)
            {
                if (bldg_lot.does_station_have_train())
                {
                    room_availability_and_train_list.Add(bldg_lot.parking_coord);
                }
                else
                {
                    room_availability_list.Add(bldg_lot.parking_coord);
                }
            }
        }
        room_availability_and_train_list.AddRange(room_availability_list);
        return(room_availability_and_train_list);
    }
    private static void GeneratePosZMutation(BuildingLot _lot)
    {
        List <Panel> addedPanels = new List <Panel>();

        // set new height, width and length
        // Calculate size of mutation

        int newHeight = (int)_lot.GetCurrentBuildingHeight() / 2;

        newHeight = (int)Random.Range(newHeight, _lot.GetCurrentBuildingHeight());

        if (newHeight <= 1)
        {
            return;
        }

        _lot.SetCurrentBuildingHeight(newHeight);

        int newWidth = (int)Random.Range(1, (_lot.GetPosZWidth() + 1));

        int newLength = (int)Random.Range(1, _lot.GetLotLength() - (_lot.GetNegXWidth() + _lot.GetOffsetZ()) + 1);

        if (newWidth == 1)
        {
            return;
        }

        // Generate panels!
        Vector3 pos = _lot.transform.position + new Vector3(_lot.GetOffsetX(), 0.0f,
                                                            _lot.GetOffsetZ() + _lot.GetNegXWidth() + (float)panelSize / 2);

        GenerateNegXPanels(_lot, newLength, pos, addedPanels);

        pos = _lot.transform.position + new Vector3(_lot.GetOffsetX() + newWidth, 0.0f,
                                                    _lot.GetOffsetZ() + _lot.GetNegXWidth() + (float)panelSize / 2);

        GeneratePosXPanels(_lot, newLength, pos, addedPanels);

        pos = _lot.transform.position + new Vector3(_lot.GetOffsetX() + (float)panelSize / 2, 0.0f,
                                                    _lot.GetOffsetZ() + _lot.GetNegXWidth());

        GenerateNegZPanels(_lot, newWidth, pos, addedPanels);

        pos = _lot.transform.position + new Vector3(_lot.GetOffsetX() + (float)panelSize / 2, 0.0f,
                                                    _lot.GetOffsetZ() + _lot.GetNegXWidth() + newLength);

        GeneratePosZPanels(_lot, newWidth, pos, addedPanels);

        pos = _lot.transform.position + new Vector3(_lot.GetOffsetX() + (float)panelSize / 2,
                                                    newHeight - (float)panelSize / 2, _lot.GetOffsetZ() + _lot.GetNegXWidth() + (float)panelSize / 2);

        GeneratePosYPanels(_lot, newWidth, newLength, pos, addedPanels);

        if (newWidth == _lot.GetPosZWidth())
        {
            _lot.SetNegXWidth(_lot.GetNegXWidth() + newLength);
            _lot.SetPosXWidth(_lot.GetPosXWidth() + newLength);
        }

        MergeList(_lot, addedPanels);
    }
Пример #22
0
    private void CreateBuildingLots()
    {
        var         es        = initialLot.edges;
        var         minLength = initialLot.edges.Min(e => e.length);
        BuildingLot lot;

        if (minLength <= 16f)
        {
            lot = new BuildingLot(es[0].start, es[0].middle, es[2].middle, es[2].end);
            lot.freeEdges.AddRange(new int[] { 0, 2, 3 });
            finalLots.Add(lot);

            lot = new BuildingLot(es[0].middle, es[0].end, es[2].start, es[2].middle);
            lot.freeEdges.AddRange(new int[] { 0, 1, 2 });
            finalLots.Add(lot);
            return;
        }

        if (minLength <= 27f && initialLot.edges[0].length <= 30f)
        {
            var r        = Util.RollDice(new float[] { 0.5f, 0.5f });
            var pointBig = es[0].start + r / 3f * es[0].length * es[0].direction;
            var pointOpp = es[2].start + (3 - r) / 3f * es[2].length * es[2].direction;
            var pointMid = (pointBig + pointOpp) / 2;

            lot = new BuildingLot(es[1].start, es[1].middle, pointMid, pointBig);
            lot.freeEdges.AddRange(new int[] { 0, 3 });
            finalLots.Add(lot);

            lot = new BuildingLot(es[1].middle, es[1].end, pointOpp, pointMid);
            lot.freeEdges.AddRange(new int[] { 0, 1 });
            finalLots.Add(lot);

            lot = new BuildingLot(es[0].start, pointBig, pointMid, es[3].middle);
            lot.freeEdges.AddRange(new int[] { 0, 3 });
            finalLots.Add(lot);

            lot = new BuildingLot(pointOpp, es[2].end, es[3].middle, pointMid);
            lot.freeEdges.AddRange(new int[] { 0, 1 });
            finalLots.Add(lot);
            return;
        }

        if (minLength <= 27f && es[0].length <= 40f)
        {
            var bisector = new Edge(es[3].middle, es[1].middle);
            var r        = Random.Range(11, 16);

            var p1big = es[0].start + r * es[0].direction;
            var p2big = p1big + Vector3.Distance(p1big, es[0].end) / 2 * es[0].direction;
            var p1mid = es[3].middle + r / es[0].length * bisector.length * bisector.direction;
            var p2mid = p1mid + Vector3.Distance(p1mid, bisector.end) / 2 * bisector.direction;

            lot = new BuildingLot(es[0].start, p1big, p1mid, bisector.start);
            lot.freeEdges.AddRange(new int[] { 0, 3 });
            finalLots.Add(lot);

            lot = new BuildingLot(p1big, p2big, p2mid, p1mid);
            lot.freeEdges.Add(0);
            finalLots.Add(lot);

            lot = new BuildingLot(p2big, es[0].end, bisector.end, p2mid);
            lot.freeEdges.AddRange(new int[] { 0, 1 });
            finalLots.Add(lot);

            var p1opp = es[2].start + r * es[2].direction;
            var p2opp = p1opp + Vector3.Distance(p1opp, es[2].end) / 2 * es[2].direction;
            var p3mid = es[1].middle - r / es[2].length * bisector.length * bisector.direction;
            var p4mid = p3mid - Vector3.Distance(p3mid, bisector.start) / 2 * bisector.direction;

            lot = new BuildingLot(es[2].start, p1opp, p3mid, es[1].middle);
            lot.freeEdges.AddRange(new int[] { 0, 3 });
            finalLots.Add(lot);

            lot = new BuildingLot(p1opp, p2opp, p4mid, p3mid);
            lot.freeEdges.Add(0);
            finalLots.Add(lot);

            lot = new BuildingLot(p2opp, es[2].end, es[3].middle, p4mid);
            lot.freeEdges.AddRange(new int[] { 0, 1 });
            finalLots.Add(lot);

            return;
        }

        // for initialLots larger than 40x27

        //CityMapManager.Instance.AddDrawableLot(initialLot);

        // big face range -> 11 - 20
        // small face range -> 6 - 9
        // therefore small = (3big + 21) / 9
        float   r1, r2;
        Vector3 p1, p2, p3, p4;

        for (int i = 0; i < 3; i += 2)
        {
            while (es[i].length - initialLot.occupied[i] > 7f)
            {
                if (initialLot.pointsInEdge[i].Count == 0)
                {
                    r1 = Random.Range(11, 20);
                    r2 = (3 * r1 + 21) / 9f;
                    p1 = es[i].start;
                    p2 = p1 + r1 * es[i].direction;
                    p4 = es[i].start - r2 * es[(i + 3) % 4].direction;
                    p3 = Util.IntersectionPoint(p2, es[i].right, p4, es[i].direction);

                    initialLot.pointsInEdge[i].Add(p2);
                    initialLot.occupied[i] += r1;
                    initialLot.pointsInEdge[(i + 3) % 4].Add(p4);
                    initialLot.occupied[(i + 3) % 4] += r2;

                    lot = new BuildingLot(p1, p2, p3, p4);
                    lot.freeEdges.AddRange(new int[] { 0, 3 });
                    finalLots.Add(lot);
                }
                else
                {
                    r1 = es[i].length - initialLot.occupied[i];
                    if (r1 > 31f)
                    {
                        r1 = Random.Range(11, 20);
                        r2 = (3 * r1 + 21) / 9f;

                        p1 = initialLot.pointsInEdge[i].Last();
                        p2 = p1 + r1 * es[i].direction;
                        p3 = p2 + r2 * es[i].right;
                        p4 = p1 + r2 * es[i].right;

                        initialLot.pointsInEdge[i].Add(p2);
                        initialLot.occupied[i] += r1;

                        lot = new BuildingLot(p1, p2, p3, p4);
                        lot.freeEdges.Add(0);
                        finalLots.Add(lot);
                    }
                    else if (25f <= r1 && r1 <= 31f)
                    {
                        r1 = r1 / 2;
                        r2 = (3 * r1 + 21) / 9f;

                        p1 = initialLot.pointsInEdge[i].Last();
                        p2 = p1 + r1 * es[i].direction;
                        p3 = p2 + r2 * es[i].right;
                        p4 = p1 + r2 * es[i].right;

                        initialLot.pointsInEdge[i].Add(p2);
                        initialLot.occupied[i] += r1;

                        lot = new BuildingLot(p1, p2, p3, p4);
                        lot.freeEdges.Add(0);
                        finalLots.Add(lot);
                    }
                    else if (19f <= r1 && r1 <= 25f)
                    {
                        r1 -= 7f;
                        r2  = (3 * r1 + 21) / 9f;

                        p1 = initialLot.pointsInEdge[i].Last();
                        p2 = p1 + r1 * es[i].direction;
                        p3 = p2 + r2 * es[(i + 1) % 4].direction;
                        p4 = p1 + r2 * es[i].right;

                        initialLot.pointsInEdge[i].Add(p2);
                        initialLot.occupied[i] += r1;

                        lot = new BuildingLot(p1, p2, p3, p4);
                        lot.freeEdges.Add(0);
                        finalLots.Add(lot);
                    }
                    else if (11f <= r1 && r1 <= 19f)
                    {
                        r2 = (3 * r1 + 21) / 9f;

                        p1 = initialLot.pointsInEdge[i].Last();
                        p2 = es[i].end;
                        p3 = es[i].end + r2 * es[(i + 1) % 4].direction;
                        p4 = Util.IntersectionPoint(p1, es[i].right, p3, es[i].direction);

                        initialLot.pointsInEdge[(i + 1) % 4].Add(p3);
                        initialLot.occupied[(i + 1) % 4] += r2;
                        initialLot.occupied[i]           += r1;

                        lot = new BuildingLot(p1, p2, p3, p4);
                        lot.freeEdges.AddRange(new int[] { 0, 1 });
                        finalLots.Add(lot);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }

        for (int i = 1; i < 4; i += 2)
        {
            if (initialLot.pointsInEdge[i].Count == 2)
            {
                if (Vector3.Distance(es[i].start, initialLot.pointsInEdge[i][0]) >
                    Vector3.Distance(es[i].start, initialLot.pointsInEdge[i][1]))
                {
                    initialLot.pointsInEdge[i].Reverse();
                }

                r1 = Vector3.Distance(initialLot.pointsInEdge[i][0], initialLot.pointsInEdge[i][1]);
                if (r1 <= 12f)
                {
                    r2 = r1;
                }
                else
                {
                    r2 = (3 * r1 + 21) / 9f;
                }

                p1 = initialLot.pointsInEdge[i][0];
                p2 = initialLot.pointsInEdge[i][1];
                p3 = p2 + r2 * es[(i + 1) % 4].direction;
                p4 = p1 - r2 * es[(i + 3) % 4].direction;

                lot = new BuildingLot(p1, p2, p3, p4);
                lot.freeEdges.Add(0);
                finalLots.Add(lot);
                continue;
            }

            if (initialLot.pointsInEdge[i].Count == 1)
            {
                var dist = Vector3.Distance(es[i].start, initialLot.pointsInEdge[i][0]);

                if (dist < 22f)
                {
                    p1 = es[i].start;
                    p2 = initialLot.pointsInEdge[i][0];
                    p4 = initialLot.pointsInEdge[(i + 3) % 4].Last();
                    p3 = Util.IntersectionPoint(p4, es[i].direction,
                                                p2, es[(i + 1) % 4].direction);

                    lot = new BuildingLot(p1, p2, p3, p4);
                    lot.freeEdges.AddRange(new int[] { 0, 3 });
                    finalLots.Add(lot);
                }
                else
                {
                    r1 = dist / 2;

                    p1 = es[i].start;
                    p2 = p1 + r1 * es[i].direction;
                    p4 = initialLot.pointsInEdge[(i + 3) % 4].Last();
                    p3 = Util.IntersectionPoint(p4, es[(i + 0) % 4].direction,
                                                p2, es[i].right);

                    lot = new BuildingLot(p1, p2, p3, p4);
                    lot.freeEdges.AddRange(new int[] { 0, 3 });
                    finalLots.Add(lot);

                    r2 = (3 * r1 + 21) / 9f;
                    p1 = p2;
                    p2 = initialLot.pointsInEdge[i][0];
                    p3 = p2 + r2 * es[(i + 1) % 4].direction;
                    p4 = p1 + r2 * es[i].right;

                    lot = new BuildingLot(p1, p2, p3, p4);
                    lot.freeEdges.Add(0);
                    finalLots.Add(lot);
                }
            }
        }
    }
    public static void GenerateBuilding(BuildingLot _lot)
    {
        GenerateMain(_lot);

        SetMutations(_lot);
    }
Пример #24
0
 public void Add(BuildingLot lot)
 {
     _lots.Add(lot);
 }