void MakeProvinceIdTexture(ProvinceMarker pm, Vector3 offset, Transform t) { Bounds cam_bounds = CaptureCam.Bounds(offset); var pn = pm.ProvinceNumber; Color c = new Color32(0, (byte)(pn / 256), (byte)(pn % 256), 255); Debug.Assert(pn != 0); { var province_mesh = Instantiate(province_id_mesh_prefab); province_mesh.GetComponent <MeshFilter>().mesh = pm.MeshFilter.sharedMesh; var new_mat = Instantiate(province_id_mesh_prefab.sharedMaterial); new_mat.color = c; province_mesh.GetComponent <MeshRenderer>().material = new_mat; province_mesh.transform.position = offset; var bounds = province_mesh.bounds; province_mesh.transform.SetParent(t); BorderOverlap.Duplicate(province_mesh.gameObject, province_mesh.bounds, cam_bounds); } }
public List <SpriteMarker> PlaceSprites() { ClearSprites(); if (m_wraps != null) { foreach (ProvinceWrapMarker m in m_wraps) { m.PlaceSprites(); } } MapSpriteSet set = ArtManager.s_art_manager.GetMapSpriteSet(m_node.ProvinceData.Terrain); if (!set.MapSprites.Any()) { return(new List <SpriteMarker>()); } List <ProvinceSprite> shuffled = set.MapSprites.Where(x => x.IsCenterpiece && m_node.ProvinceData.Terrain.IsFlagSet(x.ValidTerrain)); if (m_node.ProvinceData.Terrain.IsFlagSet(Terrain.LARGEPROV) && !m_node.ProvinceData.IsWater) { shuffled = set.MapSprites.Where(x => x.IsCenterpiece && x.ValidTerrain == Terrain.LARGEPROV); } shuffled.Shuffle(); List <ProvinceSprite> centers = shuffled.OrderBy(x => 9000f - x.Size).ToList(); if (centers.Any() && !IsDummy) // certain provinces have a centerpiece so place that first { foreach (ProvinceSprite ps in centers) { if (ps.Size < m_center_size) { Vector3 pos = m_poly_center; m_sprite_points = m_sprite_points.Where(x => !(Vector3.Distance(x, pos) < ps.Size * 0.5f || Mathf.Abs(pos.y - x.y) < 0.2f)); pos.z = -3; sprite_group.PlaceSprite(ps, pos); break; } } } set.MapSprites.Shuffle(); List <ProvinceSprite> sprites = new List <ProvinceSprite>(); foreach (ProvinceSprite ps in set.MapSprites) // guarantee that we have at least 1 of each valid sprite { if (!m_node.ProvinceData.Terrain.IsFlagSet(ps.ValidTerrain) || ps.IsCenterpiece || !m_sprite_points.Any()) { continue; } sprites.Add(ps); } if (sprites.Count == 0) { return(new List <SpriteMarker>()); } { List <NativeObjectPlacer.Item> sprite_items = new List <NativeObjectPlacer.Item>(); List <float> sprite_size = new List <float>(); foreach (var s in sprites) { sprite_items.Add(new NativeObjectPlacer.Item { size = s.Size, spawn_chance = s.SpawnChance, extra_border_dist = s.ValidTerrain == Terrain.LARGEPROV ? 1 : 0, }); } List <Vector3> already_placed = new List <Vector3>(); already_placed.AddRange(sprite_group.SpritePos()); List <int> objs = NativeObjectPlacer.Invoke(sprite_items, m_sprite_points, m_poly, already_placed); for (int i = 0; i < objs.Count; ++i) { sprite_group.PlaceSprite(sprites[objs[i]], m_sprite_points[i]); } m_sprite_points.Clear(); } List <SpriteMarker> all = new List <SpriteMarker>(); foreach (ProvinceWrapMarker m in m_wraps) { all.AddRange(m.PlaceSprites()); } sprite_group.Build(CaptureCam.Bounds()); return(all); }
public List <SpriteMarker> PlaceSprites() { ClearSprites(); if (m_wraps != null) { foreach (var m in m_wraps) { m.PlaceSprites(); } } var set = ArtManager.s_art_manager.GetMapSpriteSet(m_node.ProvinceData.Terrain); if (!set.MapSprites.Any()) { return(new List <SpriteMarker>()); } var shuffled = set.MapSprites.Where(x => x.IsCenterpiece && m_node.ProvinceData.Terrain.IsFlagSet(x.ValidTerrain)); if (m_node.ProvinceData.Terrain.IsFlagSet(Terrain.LARGEPROV) && !m_node.ProvinceData.IsWater) { shuffled = set.MapSprites.Where(x => x.IsCenterpiece && x.ValidTerrain == Terrain.LARGEPROV); } shuffled.Shuffle(); var centers = shuffled.OrderBy(x => 9000f - x.Size).ToList(); if (centers.Any() && !IsDummy) // certain provinces have a centerpiece so place that first { foreach (var ps in centers) { if (ps.Size < m_center_size) { var pos = m_poly_center; if (ps.CullSpritePositions) { pos.z = -10; // sprite points are at z = -10 so we need to match that m_sprite_points = m_sprite_points.Where(x => (Vector3.Distance(x, pos) > (ps.Size * 0.4f))); } pos.z = -3; // sprite placement is at z = -3 SpriteGroup.PlaceSprite(ps, pos); break; } } } set.MapSprites.Shuffle(); var sprites = new List <ProvinceSprite>(); foreach (var ps in set.MapSprites) // guarantee that we have at least 1 of each valid sprite { if (!m_node.ProvinceData.Terrain.IsFlagSet(ps.ValidTerrain) || ps.IsCenterpiece) { continue; } sprites.Add(ps); } if (sprites.Count == 0) { return(new List <SpriteMarker>()); } var sprite_items = new List <NativeObjectPlacer.Item>(); var sprite_size = new List <float>(); foreach (var s in sprites) { sprite_items.Add(new NativeObjectPlacer.Item { size = s.Size, spawn_chance = s.SpawnChance, place_at_least_1 = s.PlaceAtLeastOne == true ? 1 : 0, extra_border_dist = s.ValidTerrain == Terrain.LARGEPROV ? 1 : 0, cull_nearby_points = s.CullSpritePositions == true ? 1 : 0 }); } var already_placed = new List <Vector3>(); already_placed.AddRange(SpriteGroup.SpritePos()); var objs = NativeObjectPlacer.Invoke(sprite_items, m_sprite_points, m_poly, already_placed); for (var i = 0; i < objs.Count; ++i) { SpriteGroup.PlaceSprite(sprites[objs[i]], m_sprite_points[i]); } m_sprite_points.Clear(); var all = new List <SpriteMarker>(); foreach (var m in m_wraps) { all.AddRange(m.PlaceSprites()); } SpriteGroup.Build(CaptureCam.Bounds()); return(all); }