public List <SpriteMarker> PlaceSprites()
    {
        if (m_sprites != null)
        {
            foreach (var sm in m_sprites)
            {
                GameObject.Destroy(sm.gameObject);
            }
        }

        m_sprites = new List <SpriteMarker>();

        if (m_connection.ConnectionType == ConnectionType.MOUNTAIN)
        {
            if (PolyBorder == null)
            {
                return(m_sprites);
            }

            m_sprites = new List <SpriteMarker>();

            var last = new Vector3(-900, -900, 0);
            var cs   = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);

            if (cs == null)
            {
                return(m_sprites);
            }

            var ct = 0;

            make_sprite(PolyBorder.P1, cs, Vector3.zero);
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            make_sprite(PolyBorder.P2, cs, Vector3.zero);
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);

            foreach (var pt in PolyBorder.OrderedFinePoints)
            {
                if (Vector3.Distance(pt, PolyBorder.P2) < cs.Size) // if near to the endpoint, find the mid point between end point and current point and draw 1 sprite
                {
                    Vector3 midpoint = (last + PolyBorder.P2) / 2;
                    make_sprite(midpoint, cs, Vector3.zero);
                    break;
                }

                if (Vector3.Distance(pt, last) < cs.Size) // still too close to the last placed sprite, keep searching
                {
                    ct++;
                    continue;
                }

                ct++;
                last = pt;

                make_sprite(pt, cs, Vector3.zero);
                cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            }
        }
        else if (m_connection.ConnectionType == ConnectionType.MOUNTAINPASS)
        {
            if (PolyBorder == null)
            {
                return(m_sprites);
            }

            var last  = new Vector3(-900, -900, 0);
            var cs    = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            var other = PolyBorder.Reversed();

            make_sprite(PolyBorder.P1, cs, Vector3.zero); // draw a sprite at both endpoints
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            make_sprite(PolyBorder.P2, cs, Vector3.zero);
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);

            var first_quarter = Mathf.RoundToInt(PolyBorder.OrderedFinePoints.Count * 0.3f);
            var last_quarter  = Mathf.RoundToInt(PolyBorder.OrderedFinePoints.Count * 0.7f);
            var gap_distance  = Vector3.Distance(PolyBorder.OrderedFinePoints[first_quarter], PolyBorder.OrderedFinePoints[last_quarter]);

            if (gap_distance < ArtManager.s_art_manager.CurrentArtConfiguration.MinimumMountainPassGapSize)
            {
                first_quarter = Mathf.RoundToInt(PolyBorder.OrderedFinePoints.Count * 0.2f);
                last_quarter  = Mathf.RoundToInt(PolyBorder.OrderedFinePoints.Count * 0.8f);
            }

            for (int i = 0; i < PolyBorder.OrderedFinePoints.Count; i++)
            {
                var pt = PolyBorder.OrderedFinePoints[i];
                var is_mountain = i <first_quarter || i> last_quarter;

                if (Vector3.Distance(pt, PolyBorder.P2) < cs.Size) // if near to the endpoint, find the mid point between end point and current point and draw 1 sprite
                {
                    Vector3 midpoint = (last + PolyBorder.P2) / 2;
                    make_sprite(midpoint, cs, Vector3.zero);
                    break;
                }

                if (Vector3.Distance(pt, last) < cs.Size) // still too close to the last placed sprite, keep searching
                {
                    continue;
                }

                last = pt;
                make_sprite(pt, cs, Vector3.zero);

                if (is_mountain)
                {
                    cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
                }
                else
                {
                    cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAINPASS);
                }
            }
        }

        return(m_sprites);
    }
Esempio n. 2
0
    public List <SpriteMarker> PlaceSprites()
    {
        if (m_sprites != null)
        {
            foreach (SpriteMarker sm in m_sprites)
            {
                GameObject.Destroy(sm.gameObject);
            }
        }

        m_sprites = new List <SpriteMarker>();

        if (m_connection.ConnectionType == ConnectionType.MOUNTAIN)
        {
            if (PolyBorder == null)
            {
                return(m_sprites);
            }

            m_sprites = new List <SpriteMarker>();

            Vector3          last = new Vector3(-900, -900, 0);
            ConnectionSprite cs   = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);

            if (cs == null)
            {
                return(m_sprites);
            }

            int ct = 0;

            make_sprite(PolyBorder.P1, cs, Vector3.zero);
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            make_sprite(PolyBorder.P2, cs, Vector3.zero);
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);

            foreach (Vector3 pt in PolyBorder.OrderedFinePoints)
            {
                if (Vector3.Distance(last, pt) < cs.Size && ct < m_border.OrderedFinePoints.Count - 1)
                {
                    ct++;
                    continue;
                }

                ct++;
                last = pt;

                make_sprite(pt, cs, Vector3.zero);

                cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            }
        }
        else if (m_connection.ConnectionType == ConnectionType.MOUNTAINPASS)
        {
            if (PolyBorder == null)
            {
                return(m_sprites);
            }

            m_sprites = new List <SpriteMarker>();

            Vector3          last  = new Vector3(-900, -900, 0);
            ConnectionSprite cs    = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            PolyBorder       other = PolyBorder.Reversed();

            int right_ct  = 0;
            int right_pos = 0;

            foreach (Vector3 pt in other.OrderedFinePoints)
            {
                if (Vector3.Distance(last, pt) < cs.Size)
                {
                    right_pos++;
                    continue;
                }

                last = pt;

                make_sprite(pt, cs, Vector3.zero);

                if (right_ct > 1)
                {
                    break;
                }

                cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);

                right_ct++;
                right_pos++;
            }

            Vector3 endpt = other.OrderedFinePoints[right_pos];
            right_ct = -1;
            cs       = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            bool is_mountain = true;

            foreach (Vector3 pt in PolyBorder.OrderedFinePoints)
            {
                if (Vector3.Distance(pt, endpt) < 0.08f)
                {
                    break;
                }

                if (Vector3.Distance(last, pt) < cs.Size)
                {
                    continue;
                }

                last = pt;

                if (!is_mountain)
                {
                    make_sprite(pt, cs, new Vector3(0, 0.01f));
                }
                else
                {
                    make_sprite(pt, cs, Vector3.zero);
                }

                if (Vector3.Distance(pt, endpt) < 2.0f)
                {
                    cs          = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAINPASS);
                    is_mountain = false;
                }
                else
                {
                    cs          = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
                    is_mountain = true;
                }

                right_ct--;
            }
        }

        return(m_sprites);
    }
Esempio n. 3
0
    public void RecalculatePoly()
    {
        m_poly = new List <Vector3>();

        if (IsDummy)
        {
            return;
        }

        List <PolyBorder> borders = new List <PolyBorder>();

        List <ConnectionMarker> conns = new List <ConnectionMarker>();

        conns.AddRange(m_connections);

        if (m_linked != null)
        {
            foreach (ProvinceMarker pm in m_linked)
            {
                conns.AddRange(pm.Connections);
            }
        }

        if (Node.X == 0 && Node.Y == 0)                  // corner case
        {
            foreach (ConnectionMarker cm in Connections) // main connections
            {
                borders.Add(cm.PolyBorder);
            }

            foreach (ProvinceMarker pm in LinkedProvinces) // grab all children connections
            {
                foreach (ConnectionMarker cm in pm.Connections)
                {
                    borders.Add(cm.GetOffsetBorder(-cm.DummyOffset));
                }
            }
        }
        else // bot side or left side case
        {
            foreach (ConnectionMarker cm in conns)
            {
                if (cm.IsEdge && (Node.X == 0 || Node.Y == 0) && Vector3.Distance(cm.Midpoint, transform.position) > 3f)
                {
                    borders.Add(cm.GetOffsetBorder(-cm.DummyOffset));
                }
                else
                {
                    borders.Add(cm.PolyBorder);
                }
            }
        }

        m_needs_regen = false;
        Vector3           cur    = borders[0].P2;
        PolyBorder        b      = null;
        List <PolyBorder> result = new List <PolyBorder>();

        while (borders.Any())
        {
            b = borders.FirstOrDefault(x => Vector3.Distance(x.P1, cur) < 0.01f);

            if (b == null)
            {
                b = borders.FirstOrDefault(x => Vector3.Distance(x.P2, cur) < 0.01f);

                if (b == null) // this probably should never happen
                {
                    m_needs_regen = true;
                    Debug.LogError("Unable to find PolyBorder for province marker: " + ProvinceNumber);
                    break;
                }

                PolyBorder rev = b.Reversed();

                result.Add(rev);
                borders.Remove(b);
                cur = rev.P2;
                b   = null;
            }
            else
            {
                borders.Remove(b);
                cur = b.P2;
            }

            if (b != null)
            {
                result.Add(b);
            }
        }

        Vector3        avg        = Vector3.zero;
        List <Vector3> simplified = new List <Vector3>();

        foreach (PolyBorder pb in result)
        {
            int mid1 = Mathf.RoundToInt(pb.OrderedPoints.Count * 0.33f);
            int mid2 = Mathf.RoundToInt(pb.OrderedPoints.Count * 0.66f);

            m_poly.AddRange(pb.GetFullLengthBorderMinusEnd());
            avg += pb.P1;
            avg += pb.OrderedPoints[mid1];
            avg += pb.OrderedPoints[mid2];
            simplified.Add(pb.P1);
            simplified.Add(pb.OrderedPoints[mid1]);
            simplified.Add(pb.OrderedPoints[mid2]);
        }

        Vector3 closest = new Vector3(9000, 9000);

        avg       /= (result.Count * 3);
        avg       -= new Vector3(0f, 0.2f); // shift the center down slightly for aesthetics
        simplified = simplified.OrderBy(x => Mathf.Abs(avg.y - x.y)).ToList();

        foreach (Vector3 p in simplified) // calculate the distance to left
        {
            if (p.x < avg.x)
            {
                m_center_size = Vector3.Distance(p, avg);
                break;
            }
        }

        foreach (Vector3 p in simplified) // calculate the distance to right
        {
            if (p.x > avg.x)
            {
                m_center_size += Vector3.Distance(p, avg);
                m_center_size *= 0.75f;
                break;
            }
        }

        m_poly_center = avg;
    }
Esempio n. 4
0
    private List <Vector3> get_contour(PolyBorder pb, float min_lat, float max_lat)
    {
        var dist    = 0.08f;
        var pts     = new List <Vector3>();
        var norm    = (pb.P2 - pb.P1).normalized;
        var prev    = pb.P1;
        var lateral = Vector3.zero;

        for (var i = 0; i < pb.OrderedPoints.Count - 1; i++)
        {
            var pt = pb.OrderedPoints[i];

            if (Vector3.Distance(prev, pt) < dist)
            {
                continue;
            }

            var behind  = pb.OrderedPoints[Mathf.Max(i - 1, 0)];
            var forward = pb.OrderedPoints[Mathf.Min(i + 1, pb.OrderedPoints.Count - 1)];

            dist = UnityEngine.Random.Range(0.04f, 0.16f);

            var dir      = (pt - behind).normalized;
            var lateral1 = Vector3.Cross(dir, Vector3.forward);
            dir = (forward - pt).normalized;
            var lateral2 = Vector3.Cross(dir, Vector3.forward);
            var true_lat = (lateral1 + lateral2) * 0.5f;

            if (i == 0)
            {
                true_lat = lateral2;
            }
            else if (i == pb.OrderedPoints.Count - 1)
            {
                true_lat = lateral1;
            }

            var shift = pt + true_lat * UnityEngine.Random.Range(min_lat, max_lat);
            pts.Add(shift);

            lateral = true_lat;
            prev    = pt;
        }

        var endpt  = pb.P2 + norm * 0.04f + lateral * min_lat;
        var endpt2 = pb.P2 + norm * 0.04f - lateral * min_lat;

        pts.Add(endpt);
        pts.Add(endpt2);
        prev = endpt;
        dist = 0.08f;

        var ordered = pb.Reversed().OrderedPoints;

        for (var i = 0; i < ordered.Count - 1; i++)
        {
            var pt = ordered[i];

            if (Vector3.Distance(prev, pt) < dist)
            {
                continue;
            }

            var behind  = ordered[Mathf.Max(i - 1, 0)];
            var forward = ordered[Mathf.Min(i + 1, ordered.Count - 1)];

            dist = UnityEngine.Random.Range(0.04f, 0.16f);

            var dir      = (pt - behind).normalized;
            var lateral1 = Vector3.Cross(dir, Vector3.forward);
            dir = (forward - pt).normalized;
            var lateral2 = Vector3.Cross(dir, Vector3.forward);
            var true_lat = (lateral1 + lateral2) * 0.5f;

            if (i == 0)
            {
                true_lat = lateral2;
            }
            else if (i == ordered.Count - 1)
            {
                true_lat = lateral1;
            }

            var shift = pt + true_lat * UnityEngine.Random.Range(min_lat, max_lat);
            pts.Add(shift);

            lateral = true_lat;
            prev    = pt;
        }

        endpt  = pb.P1 - norm * 0.04f + lateral * min_lat;
        endpt2 = pb.P1 - norm * 0.04f - lateral * min_lat;

        pts.Add(endpt);
        pts.Add(endpt2);
        pts.Add(pts[0]);

        var path = new CubicBezierPath(pts.ToArray());

        var max     = (float)(pts.Count - 1) - 0.04f;
        var j       = 0.04f;
        var spacing = 0.04f;
        var last    = pb.P1;

        ordered = new List <Vector3>();

        while (j < max)
        {
            var pt = path.GetPoint(j);

            if (Vector3.Distance(pt, last) >= spacing)
            {
                ordered.Add(pt);
                last = pt;
            }

            j += 0.04f;
        }

        return(ordered);
    }
Esempio n. 5
0
    public List <SpriteMarker> PlaceSprites()
    {
        if (m_sprites != null)
        {
            foreach (var sm in m_sprites)
            {
                GameObject.Destroy(sm.gameObject);
            }
        }

        m_sprites = new List <SpriteMarker>();
        var all = new List <SpriteMarker>();

        /*foreach (var m in m_wraps)
         * {
         *  //all.AddRange(m.PlaceSprites());
         * }*/

        if (PolyBorder != null)
        {
            var max = MapBorder.s_map_border.Maxs;
            var min = MapBorder.s_map_border.Mins;
            var p1  = false;
            var p2  = false;

            if (PolyBorder.P1.x < min.x ||
                PolyBorder.P1.y < min.y ||
                PolyBorder.P1.x > max.x ||
                PolyBorder.P1.y > max.y)
            {
                m_force_mirror = true;
                m_forced_min   = PolyBorder.P1;
                m_forced_max   = PolyBorder.P1;
                p1             = true;
            }
            if (PolyBorder.P2.x < min.x ||
                PolyBorder.P2.y < min.y ||
                PolyBorder.P2.x > max.x ||
                PolyBorder.P2.y > max.y)
            {
                m_force_mirror = true;
                m_forced_min   = PolyBorder.P2;
                m_forced_max   = PolyBorder.P2;
                p2             = true;
            }

            if (p1 && p2)
            {
                m_forced_max = max + new Vector3(0.02f, 0.02f);
                m_forced_min = max - new Vector3(0.02f, 0.02f);
            }
        }

        if (m_connection.ConnectionType == ConnectionType.MOUNTAIN)
        {
            if (PolyBorder == null)
            {
                return(m_sprites);
            }

            var last   = new Vector3(-900, -900, 0);
            var cs     = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            var bottom = ArtManager.s_art_manager.GetMountainSpecSprite();

            if (cs == null)
            {
                return(m_sprites);
            }

            var ct = 0;

            make_sprite(PolyBorder.P1, cs, Vector3.zero);
            make_sprite(PolyBorder.P1, bottom, new Vector3(0, 0.01f));
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            make_sprite(PolyBorder.P2, cs, Vector3.zero);
            make_sprite(PolyBorder.P2, bottom, new Vector3(0, 0.01f));
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);

            foreach (var pt in PolyBorder.OrderedFinePoints)
            {
                if (Vector3.Distance(last, pt) < cs.Size && ct < PolyBorder.OrderedFinePoints.Count - 3)
                {
                    ct++;
                    continue;
                }

                ct++;
                last = pt;

                make_sprite(pt, cs, Vector3.zero);
                make_sprite(pt, bottom, new Vector3(0, 0.01f));

                cs     = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
                bottom = ArtManager.s_art_manager.GetMountainSpecSprite();
            }
        }
        else if (m_connection.ConnectionType == ConnectionType.MOUNTAINPASS)
        {
            if (PolyBorder == null)
            {
                return(m_sprites);
            }

            var last   = new Vector3(-900, -900, 0);
            var cs     = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            var bottom = ArtManager.s_art_manager.GetMountainSpecSprite();
            var other  = PolyBorder.Reversed();

            make_sprite(PolyBorder.P1, cs, Vector3.zero);
            make_sprite(PolyBorder.P1, bottom, new Vector3(0, 0.01f));
            cs     = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            bottom = ArtManager.s_art_manager.GetMountainSpecSprite();
            make_sprite(PolyBorder.P2, cs, Vector3.zero);
            make_sprite(PolyBorder.P2, bottom, new Vector3(0, 0.01f));
            cs     = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            bottom = ArtManager.s_art_manager.GetMountainSpecSprite();

            make_sprite(other.OrderedFinePoints[0], cs, Vector3.zero);
            make_sprite(other.OrderedFinePoints[0], bottom, new Vector3(0, 0.01f));
            cs     = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            bottom = ArtManager.s_art_manager.GetMountainSpecSprite();
            make_sprite(other.OrderedFinePoints[1], cs, Vector3.zero);
            make_sprite(other.OrderedFinePoints[1], bottom, new Vector3(0, 0.01f));
            cs     = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            bottom = ArtManager.s_art_manager.GetMountainSpecSprite();
            make_sprite(other.OrderedFinePoints[2], cs, Vector3.zero);
            make_sprite(other.OrderedFinePoints[2], bottom, new Vector3(0, 0.01f));
            cs     = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            bottom = ArtManager.s_art_manager.GetMountainSpecSprite();

            var endpt = other.OrderedFinePoints[2];
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            var is_mountain = true;

            foreach (var pt in PolyBorder.OrderedFinePoints)
            {
                if (Vector3.Distance(pt, endpt) < 0.05f)
                {
                    break;
                }

                if (Vector3.Distance(last, pt) < cs.Size)
                {
                    continue;
                }

                last = pt;

                if (!is_mountain)
                {
                    make_sprite(pt, cs, new Vector3(0, 0.01f));
                }
                else
                {
                    make_sprite(pt, cs, Vector3.zero);
                    make_sprite(pt, bottom, new Vector3(0, 0.01f));
                }

                if (Vector3.Distance(pt, endpt) < 0.6f)
                {
                    cs          = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAINPASS);
                    is_mountain = false;
                }
                else
                {
                    cs          = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
                    is_mountain = true;
                }

                bottom = ArtManager.s_art_manager.GetMountainSpecSprite();
            }
        }
        else if (m_connection.ConnectionType == ConnectionType.SHALLOWRIVER)
        {
            var mid = Mathf.RoundToInt(PolyBorder.OrderedPoints.Count * 0.25f);

            if (UnityEngine.Random.Range(0, 2) == 0)
            {
                mid = Mathf.RoundToInt(PolyBorder.OrderedPoints.Count * 0.75f);
            }

            var pos    = PolyBorder.OrderedPoints[mid];
            var pos2   = PolyBorder.OrderedPoints[mid + 1];
            var actual = (pos - pos2).normalized;//(PolyBorder.P2 - PolyBorder.P1).normalized;

            var dir = new Vector3(-0.05f, 1f);

            if (Mathf.Abs(actual.y) < 0.3f)
            {
                var cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.RIVER);
                make_sprite(pos, cs, Vector3.zero);
            }
            else
            {
                var cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.SHALLOWRIVER);

                if ((actual.y < 0 && actual.x > 0) || (actual.y > 0 && actual.x < 0))
                {
                    make_bridge_sprite(pos, cs, Vector3.zero, true, true);
                    dir = new Vector3(1f, 0.3f);
                }
                else
                {
                    make_bridge_sprite(pos, cs, Vector3.zero, true, false);
                    dir = new Vector3(1f, -0.3f);
                }
            }

            var cull      = 0.05f;
            var positions = new List <Vector3>();

            while (cull < 0.35f)
            {
                positions.Add(pos + (dir * cull));
                positions.Add(pos + (dir * -cull));

                cull += 0.05f;
            }

            m_culling_points = positions;
        }
        else if (m_connection.ConnectionType == ConnectionType.ROAD)
        {
            if (PolyBorder == null)
            {
                return(m_sprites);
            }

            var cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.ROAD);

            if (cs == null)
            {
                return(m_sprites);
            }

            foreach (var pt in m_poly)
            {
                make_sprite(pt, cs, new Vector3(UnityEngine.Random.Range(-0.01f, 0.01f), UnityEngine.Random.Range(-0.01f, 0.01f)));

                cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.ROAD);
            }
        }

        all.AddRange(m_sprites);
        return(all);
    }
Esempio n. 6
0
    public List <SpriteMarker> PlaceSprites()
    {
        if (m_sprites != null)
        {
            foreach (var sm in m_sprites)
            {
                GameObject.Destroy(sm.gameObject);
            }
        }

        m_sprites = new List <SpriteMarker>();
        var all = new List <SpriteMarker>();

        if (PolyBorder != null)
        {
            var max = MapBorder.s_map_border.Maxs;
            var min = MapBorder.s_map_border.Mins;
            var p1  = false;
            var p2  = false;

            if (PolyBorder.P1.x < min.x ||
                PolyBorder.P1.y < min.y ||
                PolyBorder.P1.x > max.x ||
                PolyBorder.P1.y > max.y)
            {
                m_force_mirror = true;
                m_forced_min   = PolyBorder.P1;
                m_forced_max   = PolyBorder.P1;
                p1             = true;
            }
            if (PolyBorder.P2.x < min.x ||
                PolyBorder.P2.y < min.y ||
                PolyBorder.P2.x > max.x ||
                PolyBorder.P2.y > max.y)
            {
                m_force_mirror = true;
                m_forced_min   = PolyBorder.P2;
                m_forced_max   = PolyBorder.P2;
                p2             = true;
            }

            if (p1 && p2)
            {
                m_forced_max = max + new Vector3(0.02f, 0.02f);
                m_forced_min = max - new Vector3(0.02f, 0.02f);
            }
        }

        if (m_connection.ConnectionType == ConnectionType.MOUNTAIN)
        {
            if (PolyBorder == null)
            {
                return(m_sprites);
            }

            var last = new Vector3(-900, -900, 0);
            var cs   = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);

            if (cs == null)
            {
                return(m_sprites);
            }

            var ct = 0;
            make_sprite(PolyBorder.P1, cs, Vector3.zero); // draw a sprite at both endpoints
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            make_sprite(PolyBorder.P2, cs, Vector3.zero);
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);

            foreach (var pt in PolyBorder.OrderedFinePoints)
            {
                if (Vector3.Distance(pt, PolyBorder.P2) < cs.Size) // if near to the endpoint, find the mid point between end point and current point and draw 1 sprite
                {
                    Vector3 midpoint = (last + PolyBorder.P2) / 2;
                    make_sprite(midpoint, cs, Vector3.zero);
                    break;
                }

                if (Vector3.Distance(pt, last) < cs.Size) // still too close to the last placed sprite, keep searching
                {
                    ct++;
                    continue;
                }

                ct++;
                last = pt;

                make_sprite(pt, cs, Vector3.zero);
                cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            }
        }
        else if (m_connection.ConnectionType == ConnectionType.MOUNTAINPASS)
        {
            if (PolyBorder == null)
            {
                return(m_sprites);
            }

            var last  = new Vector3(-900, -900, 0);
            var cs    = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            var other = PolyBorder.Reversed();

            make_sprite(PolyBorder.P1, cs, Vector3.zero); // draw a sprite at both endpoints
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
            make_sprite(PolyBorder.P2, cs, Vector3.zero);
            cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);

            var first_quarter = Mathf.RoundToInt(PolyBorder.OrderedFinePoints.Count * 0.3f);
            var last_quarter  = Mathf.RoundToInt(PolyBorder.OrderedFinePoints.Count * 0.7f);
            var gap_distance  = Vector3.Distance(PolyBorder.OrderedFinePoints[first_quarter], PolyBorder.OrderedFinePoints[last_quarter]);

            if (gap_distance < ArtManager.s_art_manager.CurrentArtConfiguration.MinimumMountainPassGapSize)
            {
                first_quarter = Mathf.RoundToInt(PolyBorder.OrderedFinePoints.Count * 0.2f);
                last_quarter  = Mathf.RoundToInt(PolyBorder.OrderedFinePoints.Count * 0.8f);
            }

            for (int i = 0; i < PolyBorder.OrderedFinePoints.Count; i++)
            {
                var pt = PolyBorder.OrderedFinePoints[i];
                var is_mountain = i <first_quarter || i> last_quarter;

                if (Vector3.Distance(pt, PolyBorder.P2) < cs.Size) // if near to the endpoint, find the mid point between end point and current point and draw 1 sprite
                {
                    Vector3 midpoint = (last + PolyBorder.P2) / 2;
                    make_sprite(midpoint, cs, Vector3.zero);
                    break;
                }

                if (Vector3.Distance(pt, last) < cs.Size) // still too close to the last placed sprite, keep searching
                {
                    continue;
                }

                last = pt;
                make_sprite(pt, cs, Vector3.zero);

                if (is_mountain)
                {
                    cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN);
                }
                else
                {
                    cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAINPASS);
                }
            }
        }
        else if (m_connection.ConnectionType == ConnectionType.SHALLOWRIVER)
        {
            var mid = Mathf.RoundToInt(PolyBorder.OrderedPoints.Count * 0.25f);

            if (UnityEngine.Random.Range(0, 2) == 0)
            {
                mid = Mathf.RoundToInt(PolyBorder.OrderedPoints.Count * 0.75f);
            }

            var pos    = PolyBorder.OrderedPoints[mid];
            var pos2   = PolyBorder.OrderedPoints[mid + 1];
            var actual = (pos - pos2).normalized;//(PolyBorder.P2 - PolyBorder.P1).normalized;

            var dir = new Vector3(-0.05f, 1f);

            if (Mathf.Abs(actual.y) < 0.3f)
            {
                var cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.RIVER);
                make_sprite(pos, cs, Vector3.zero);
            }
            else
            {
                var cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.SHALLOWRIVER);

                if ((actual.y < 0 && actual.x > 0) || (actual.y > 0 && actual.x < 0))
                {
                    make_bridge_sprite(pos, cs, Vector3.zero, true, true);
                    dir = new Vector3(1f, 0.3f);
                }
                else
                {
                    make_bridge_sprite(pos, cs, Vector3.zero, true, false);
                    dir = new Vector3(1f, -0.3f);
                }
            }

            var cull      = 0.05f;
            var positions = new List <Vector3>();

            while (cull < 0.35f)
            {
                positions.Add(pos + (dir * cull));
                positions.Add(pos + (dir * -cull));

                cull += 0.05f;
            }

            m_culling_points = positions;
        }
        else if (m_connection.ConnectionType == ConnectionType.ROAD)
        {
            if (PolyBorder == null)
            {
                return(m_sprites);
            }

            var cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.ROAD);

            if (cs == null)
            {
                return(m_sprites);
            }

            foreach (var pt in m_poly)
            {
                make_sprite(pt, cs, new Vector3(UnityEngine.Random.Range(-0.01f, 0.01f), UnityEngine.Random.Range(-0.01f, 0.01f)));

                cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.ROAD);
            }
        }

        all.AddRange(m_sprites);
        return(all);
    }