Exemplo n.º 1
0
    public ProvinceSprite GetSprite(Terrain flag)
    {
        if (!MapSprites.Any())
        {
            return(null);
        }

        List <ProvinceSprite> valid = new List <ProvinceSprite>();

        foreach (var x in MapSprites)
        {
            if (flag.IsFlagSet(x.ValidTerrain) && !x.IsCenterpiece)
            {
                valid.Add(x);
            }
        }

        if (!valid.Any())
        {
            return(null);
        }

        ProvinceSprite spr  = valid.GetRandom();
        float          rand = UnityEngine.Random.Range(0f, 1f);
        int            ct   = 0;
        int            max  = MapSprites.Count;

        while ((spr.SpawnChance < rand || !flag.IsFlagSet(spr.ValidTerrain)) && ct < max)
        {
            ct++;

            rand = UnityEngine.Random.Range(0f, 1f);
            spr  = valid.GetRandom();
        }

        if (ct == max)
        {
            return(null);
        }

        return(spr);
    }
Exemplo n.º 2
0
    public List <SpriteMarker> PlaceSprites()
    {
        MapSpriteSet set = ArtManager.s_art_manager.GetMapSpriteSet(m_node.ProvinceData.Terrain);

        if (!set.MapSprites.Any())
        {
            return(m_sprites);
        }

        int valid_ct = set.MapSprites.Where(x => m_node.ProvinceData.Terrain.IsFlagSet(x.ValidTerrain)).Count();

        if (valid_ct == 0)
        {
            return(m_sprites);
        }

        while (m_sprite_points.Any())
        {
            Vector3        pos = m_sprite_points[0];
            ProvinceSprite ps  = ArtManager.s_art_manager.GetProvinceSprite(m_node.ProvinceData.Terrain);

            if (ps == null)
            {
                m_sprite_points.Remove(pos);
                continue;
            }

            while (UnityEngine.Random.Range(0f, 1f) > ps.SpawnChance)
            {
                ps = ArtManager.s_art_manager.GetProvinceSprite(m_node.ProvinceData.Terrain);

                if (ps == null)
                {
                    break;
                }
            }

            if (ps == null)
            {
                m_sprite_points.Remove(pos);
                continue;
            }

            List <Vector3> remove = m_sprite_points.Where(x => Vector3.Distance(x, pos) < ps.Size).ToList();

            foreach (Vector3 p in remove)
            {
                m_sprite_points.Remove(p);
            }

            //m_sprite_points.Remove(pos);
            pos.z = -3f;

            GameObject   g  = GameObject.Instantiate(MapSpritePrefab);
            SpriteMarker sm = g.GetComponent <SpriteMarker>();
            sm.SetSprite(ps);
            sm.transform.position = pos;

            m_sprites.Add(sm);
            m_sprites.AddRange(sm.CreateMirrorSprites(Vector3.zero, Vector3.zero));
        }

        return(m_sprites);
    }