public void drawRailRoadsFromScratch(Nation player) { HashSet <int> allProvinces = PlayerCalculator.getAllProvinces(player); foreach (int provIndex in allProvinces) { assemblyCsharp.Province prov = State.getProvinces()[provIndex]; if (prov.railroad) { drawRailroadOnMap(prov, player); } } }
public void drawRailroadOnMap(assemblyCsharp.Province prov, Nation player) { WorldMapStrategyKit.Province mapProvince = map.provinces[prov.getIndex()]; Vector2 provCenter = mapProvince.center; for (int i = 0; i < prov.Neighbours.Count; i++) { if (PlayerCalculator.getAllProvinces(player).Contains(prov.Neighbours[i])) { // draw rail segment from prv to neighbourProv assemblyCsharp.Province neighbourProvince = State.getProvinces()[prov.Neighbours[i]]; if (neighbourProvince.railroad && !neighbourProvince.Linked.Contains(prov.getIndex()) && !prov.Linked.Contains(neighbourProvince.getIndex())) { WorldMapStrategyKit.Province mapNeighbourProvince = map.provinces[prov.Neighbours[i]]; Vector2 neighbourCenter = mapNeighbourProvince.center; Cell startCell = map.GetCell(provCenter); Cell endCell = map.GetCell(neighbourCenter); List <int> cellIndices = map.FindRoute(startCell, endCell, TERRAIN_CAPABILITY.OnlyGround); if (cellIndices == null) { return; } int positionsCount = cellIndices.Count; Debug.Log("Number of positions: " + positionsCount); Vector2[] positions = new Vector2[positionsCount]; for (int k = 0; k < positionsCount; k++) { positions[k] = map.cells[cellIndices[k]].center; } // Build a railroad along the map coordinates LineMarkerAnimator lma = map.AddLine(positions, Color.white, 0.0f, 0.15f); Texture2D railwayMatt = Resources.Load("Sprites/GUI/railRoad", typeof(Texture2D)) as Texture2D; lma.lineMaterial.mainTexture = railwayMatt; lma.lineMaterial.mainTextureScale = new Vector2(16f, 2f); neighbourProvince.Linked.Add(prov.getIndex()); prov.Linked.Add(neighbourProvince.getIndex()); } } } }