private void ExtendRiver(float[] flow, List <int>[] riverPaths, int index, RiverDef incomingRiver) { if (riverPaths[index] != null) { int bestOutput = riverPaths[index].MaxBy((int ni) => flow[ni]); RiverDef riverDef = incomingRiver; while (riverDef != null && (float)riverDef.degradeThreshold > flow[bestOutput]) { riverDef = riverDef.degradeChild; } if (riverDef != null) { Find.WorldGrid.OverlayRiver(index, bestOutput, riverDef); ExtendRiver(flow, riverPaths, bestOutput, riverDef); } if (incomingRiver.branches != null) { foreach (int alternateRiver in from ni in riverPaths[index] where ni != bestOutput select ni) { RiverDef.Branch branch2 = incomingRiver.branches.Where((RiverDef.Branch branch) => (float)branch.minFlow <= flow[alternateRiver]).MaxByWithFallback((RiverDef.Branch branch) => branch.minFlow); if (branch2 != null && Rand.Value < branch2.chance) { Find.WorldGrid.OverlayRiver(index, alternateRiver, branch2.child); ExtendRiver(flow, riverPaths, alternateRiver, branch2.child); } } } } }
/// <summary> /// Determine if <paramref name="river"/> is large enough for all ships in <paramref name="pawns"/> /// </summary> /// <param name="river"></param> /// <param name="pawns"></param> public static bool ShipsFitOnRiver(RiverDef river, List <Pawn> pawns) { foreach (VehiclePawn vehicle in pawns.Where(p => p.IsBoat())) { if ((vehicle.VehicleDef.properties.riverTraversability?.widthOnMap ?? int.MaxValue) > river.widthOnMap) { return(false); } } return(true); }
public static bool ShipsFitOnRiver(RiverDef river, List <Pawn> pawns) { foreach (Pawn p in pawns.Where(x => IsShip(x))) { if ((p.def.GetCompProperties <CompProperties_Ships>()?.riverTraversability?.GetRiverSize() ?? 5) > river.GetRiverSize()) { return(false); } } return(true); }
public void OverlayRiver(int fromTile, int toTile, RiverDef riverDef) { if (riverDef == null) { Log.ErrorOnce("Attempted to remove river with overlayRiver; not supported", 90292250); return; } RiverDef riverDef2 = GetRiverDef(fromTile, toTile, visibleOnly: false); if (riverDef2 == riverDef) { return; } Tile tile = this[fromTile]; Tile tile2 = this[toTile]; if (riverDef2 != null) { if (riverDef2.degradeThreshold >= riverDef.degradeThreshold) { return; } tile.potentialRivers.RemoveAll((Tile.RiverLink rl) => rl.neighbor == toTile); tile2.potentialRivers.RemoveAll((Tile.RiverLink rl) => rl.neighbor == fromTile); } if (tile.potentialRivers == null) { tile.potentialRivers = new List <Tile.RiverLink>(); } if (tile2.potentialRivers == null) { tile2.potentialRivers = new List <Tile.RiverLink>(); } List <Tile.RiverLink> potentialRivers = tile.potentialRivers; Tile.RiverLink item = new Tile.RiverLink { neighbor = toTile, river = riverDef }; potentialRivers.Add(item); List <Tile.RiverLink> potentialRivers2 = tile2.potentialRivers; item = new Tile.RiverLink { neighbor = fromTile, river = riverDef }; potentialRivers2.Add(item); }
public static SimpleCurve GetTemperatureToPowerOutputFactorCurveFor(Thing thing) { RiverDef river = thing.Map.GetRiver(); float halfPowerProductionLowTemp = LowPowerProductionDict[river]; return(new SimpleCurve() { new CurvePoint(Mathf.RoundToInt(halfPowerProductionLowTemp * 1.5f), 0f), new CurvePoint(halfPowerProductionLowTemp, 0.5f), new CurvePoint(FullPowerProductionLowTemp, 1f), new CurvePoint(FullPowerProductionHighTemp, 1f), new CurvePoint(HalfPowerProductionHighTemp, 0.5f), new CurvePoint(ZeroPowerProductionHighTemp, 0f) }); }
private void CreateRivers(float[] flow, List <int>[] riverPaths, int index) { List <int> list = new List <int>(); Find.WorldGrid.GetTileNeighbors(index, list); for (int i = 0; i < list.Count; i++) { float targetFlow = flow[list[i]]; RiverDef riverDef = DefDatabase <RiverDef> .AllDefs.Where((RiverDef rd) => rd.spawnFlowThreshold > 0 && (float)rd.spawnFlowThreshold <= targetFlow).MaxByWithFallback((RiverDef rd) => rd.spawnFlowThreshold); if (riverDef != null && Rand.Value < riverDef.spawnChance) { Find.WorldGrid.OverlayRiver(index, list[i], riverDef); ExtendRiver(flow, riverPaths, list[i], riverDef); } } }
public void OverlayRiver(int fromTile, int toTile, RiverDef riverDef) { if (riverDef == null) { Log.ErrorOnce("Attempted to remove river with overlayRiver; not supported", 90292250, false); } else { RiverDef riverDef2 = this.GetRiverDef(fromTile, toTile, false); if (riverDef2 != riverDef) { Tile tile = this[fromTile]; Tile tile2 = this[toTile]; if (riverDef2 != null) { if (riverDef2.degradeThreshold >= riverDef.degradeThreshold) { return; } tile.potentialRivers.RemoveAll((Tile.RiverLink rl) => rl.neighbor == toTile); tile2.potentialRivers.RemoveAll((Tile.RiverLink rl) => rl.neighbor == fromTile); } if (tile.potentialRivers == null) { tile.potentialRivers = new List <Tile.RiverLink>(); } if (tile2.potentialRivers == null) { tile2.potentialRivers = new List <Tile.RiverLink>(); } tile.potentialRivers.Add(new Tile.RiverLink { neighbor = toTile, river = riverDef }); tile2.potentialRivers.Add(new Tile.RiverLink { neighbor = fromTile, river = riverDef }); } } }
private void ExtendRiver(float[] flow, List <int>[] riverPaths, int index, RiverDef incomingRiver) { if (riverPaths[index] == null) { return; } int bestOutput = riverPaths[index].MaxBy((int ni) => flow[ni]); RiverDef riverDef = incomingRiver; while (riverDef != null && (float)riverDef.degradeThreshold > flow[bestOutput]) { riverDef = riverDef.degradeChild; } if (riverDef != null) { Find.WorldGrid.OverlayRiver(index, bestOutput, riverDef); this.ExtendRiver(flow, riverPaths, bestOutput, riverDef); } if (incomingRiver.branches != null) { using (IEnumerator <int> enumerator = (from ni in riverPaths[index] where ni != bestOutput select ni).GetEnumerator()) { while (enumerator.MoveNext()) { int alternateRiver = enumerator.Current; RiverDef.Branch branch2 = (from branch in incomingRiver.branches where (float)branch.minFlow <= flow[alternateRiver] select branch).MaxByWithFallback((RiverDef.Branch branch) => branch.minFlow, null); if (branch2 != null && Rand.Value < branch2.chance) { Find.WorldGrid.OverlayRiver(index, alternateRiver, branch2.child); this.ExtendRiver(flow, riverPaths, alternateRiver, branch2.child); } } } } }
public static int GetRiverSize(this RiverDef river) { if (river is null) { return(0); } if (river == RiverDefOf.Creek) { return(1); } if (river == RiverDefOf.River) { return(2); } if (river == RiverDefOf.LargeRiver) { return(3); } if (river == RiverDefOf.HugeRiver) { return(4); } throw new NotImplementedException("RiverDefSize"); }
private void RawDataToTiles() { if (this.tiles.Count != this.TilesCount) { this.tiles.Clear(); for (int m = 0; m < this.TilesCount; m++) { this.tiles.Add(new Tile()); } } else { for (int j = 0; j < this.TilesCount; j++) { this.tiles[j].potentialRoads = null; this.tiles[j].potentialRivers = null; } } DataSerializeUtility.LoadUshort(this.tileBiome, this.TilesCount, delegate(int i, ushort data) { this.tiles[i].biome = (DefDatabase <BiomeDef> .GetByShortHash(data) ?? BiomeDefOf.TemperateForest); }); DataSerializeUtility.LoadUshort(this.tileElevation, this.TilesCount, delegate(int i, ushort data) { this.tiles[i].elevation = (float)(data - 8192); }); DataSerializeUtility.LoadByte(this.tileHilliness, this.TilesCount, delegate(int i, byte data) { this.tiles[i].hilliness = (Hilliness)data; }); DataSerializeUtility.LoadUshort(this.tileTemperature, this.TilesCount, delegate(int i, ushort data) { this.tiles[i].temperature = (float)data / 10f - 300f; }); DataSerializeUtility.LoadUshort(this.tileRainfall, this.TilesCount, delegate(int i, ushort data) { this.tiles[i].rainfall = (float)data; }); DataSerializeUtility.LoadByte(this.tileSwampiness, this.TilesCount, delegate(int i, byte data) { this.tiles[i].swampiness = (float)data / 255f; }); int[] array = DataSerializeUtility.DeserializeInt(this.tileRoadOrigins); byte[] array2 = DataSerializeUtility.DeserializeByte(this.tileRoadAdjacency); ushort[] array3 = DataSerializeUtility.DeserializeUshort(this.tileRoadDef); for (int k = 0; k < array.Length; k++) { int num = array[k]; int tileNeighbor = this.GetTileNeighbor(num, (int)array2[k]); RoadDef byShortHash = DefDatabase <RoadDef> .GetByShortHash(array3[k]); if (byShortHash != null) { if (this.tiles[num].potentialRoads == null) { this.tiles[num].potentialRoads = new List <Tile.RoadLink>(); } if (this.tiles[tileNeighbor].potentialRoads == null) { this.tiles[tileNeighbor].potentialRoads = new List <Tile.RoadLink>(); } this.tiles[num].potentialRoads.Add(new Tile.RoadLink { neighbor = tileNeighbor, road = byShortHash }); this.tiles[tileNeighbor].potentialRoads.Add(new Tile.RoadLink { neighbor = num, road = byShortHash }); } } int[] array4 = DataSerializeUtility.DeserializeInt(this.tileRiverOrigins); byte[] array5 = DataSerializeUtility.DeserializeByte(this.tileRiverAdjacency); ushort[] array6 = DataSerializeUtility.DeserializeUshort(this.tileRiverDef); for (int l = 0; l < array4.Length; l++) { int num2 = array4[l]; int tileNeighbor2 = this.GetTileNeighbor(num2, (int)array5[l]); RiverDef byShortHash2 = DefDatabase <RiverDef> .GetByShortHash(array6[l]); if (byShortHash2 != null) { if (this.tiles[num2].potentialRivers == null) { this.tiles[num2].potentialRivers = new List <Tile.RiverLink>(); } if (this.tiles[tileNeighbor2].potentialRivers == null) { this.tiles[tileNeighbor2].potentialRivers = new List <Tile.RiverLink>(); } this.tiles[num2].potentialRivers.Add(new Tile.RiverLink { neighbor = tileNeighbor2, river = byShortHash2 }); this.tiles[tileNeighbor2].potentialRivers.Add(new Tile.RiverLink { neighbor = num2, river = byShortHash2 }); } } }
private static int <CreateRivers> m__1(RiverDef rd) { return(rd.spawnFlowThreshold); }
public override void DoWindowContents(Rect inRect) { Text.Font = GameFont.Small; Rect mainScrollRect = new Rect(0, 20, inRect.width, inRect.height); Rect mainScrollVertRect = new Rect(0, 0, mainScrollRect.x, inRect.width); Widgets.BeginScrollView(mainScrollRect, ref mainScrollPosition, mainScrollVertRect); Rect group1 = new Rect(0, 0, inRect.width, inRect.height); if (Widgets.ButtonText(new Rect(0, 0, 200, 20), Translator.Translate("DeleteSingleRoad"))) { DeleteRoad(); } if (Widgets.ButtonText(new Rect(0, 25, 200, 20), Translator.Translate("DeleteRangeRoads"))) { DeleteRangeRoad(); } if (Widgets.ButtonText(new Rect(210, 0, 200, 20), Translator.Translate("DeleteSingleRiver"))) { DeleteRiver(); } if (Widgets.ButtonText(new Rect(210, 25, 200, 20), Translator.Translate("DeleteRangeRivers"))) { DeleteRangeRivers(); } if (Widgets.ButtonText(new Rect(0, 50, 200, 20), Translator.Translate("DeleteAllRoads"))) { DeleteAllRoads(); } if (Widgets.ButtonText(new Rect(210, 50, 200, 20), Translator.Translate("DeleteAllRivers"))) { DeleteAllRivers(); } if (Widgets.ButtonText(new Rect(0, 80, 200, 20), Translator.Translate("NoText"))) { selectedRoad = null; Messages.Message($"Selected road: None", MessageTypeDefOf.NeutralEvent, false); } int roadListLength = avaliableRoads.Count * 25; Rect roadScrollRect = new Rect(0, 110, 200, 170); Rect roadScrollVertRect = new Rect(0, 0, roadScrollRect.x, roadListLength); int yButtonPos = 0; Widgets.BeginScrollView(roadScrollRect, ref scrollPosition, roadScrollVertRect); foreach (var road in avaliableRoads) { if (Widgets.ButtonText(new Rect(0, yButtonPos, 200, 20), road.label)) { selectedRoad = road; Messages.Message($"Selected road: {selectedRoad.LabelCap}", MessageTypeDefOf.NeutralEvent, false); if (selectedRiver != null) { PaintMode = false; } } yButtonPos += 22; } Widgets.EndScrollView(); yButtonPos = 295; Widgets.Label(new Rect(0, yButtonPos, 50, 20), Translator.Translate("StartTileLabel")); roadId1 = Widgets.TextField(new Rect(65, yButtonPos, 130, 20), roadId1); yButtonPos += 30; Widgets.Label(new Rect(0, yButtonPos, 50, 20), Translator.Translate("EndTileLabel")); roadId2 = Widgets.TextField(new Rect(65, yButtonPos, 130, 20), roadId2); yButtonPos += 30; if (Widgets.ButtonText(new Rect(0, yButtonPos, 200, 20), Translator.Translate("CreateRoadLabel"))) { CreateRoad(); } if (Widgets.ButtonText(new Rect(210, 80, 200, 20), Translator.Translate("NoText"))) { selectedRiver = null; Messages.Message($"Selected river: None", MessageTypeDefOf.NeutralEvent, false); } yButtonPos = 110; int riverListLength = avaliableRivers.Count * 25; Rect riverScrollRect = new Rect(210, 110, 200, 170); Rect riverScrollVertRect = new Rect(0, 0, riverScrollRect.x, riverListLength); Widgets.BeginScrollView(riverScrollRect, ref riverScrollPosition, riverScrollRect); foreach (var river in avaliableRivers) { if (Widgets.ButtonText(new Rect(210, yButtonPos, 200, 20), river.label)) { selectedRiver = river; Messages.Message($"Selected river: {selectedRiver.LabelCap}", MessageTypeDefOf.NeutralEvent, false); if (selectedRoad != null) { PaintMode = false; } } yButtonPos += 22; } Widgets.EndScrollView(); yButtonPos = 295; Widgets.Label(new Rect(210, yButtonPos, 50, 20), Translator.Translate("StartTileLabel")); riverId1 = Widgets.TextField(new Rect(265, yButtonPos, 130, 20), riverId1); yButtonPos += 30; Widgets.Label(new Rect(210, yButtonPos, 50, 20), Translator.Translate("EndTileLabel")); riverId2 = Widgets.TextField(new Rect(265, yButtonPos, 130, 20), riverId2); yButtonPos += 30; if (Widgets.ButtonText(new Rect(210, yButtonPos, 200, 20), Translator.Translate("CreateRiverLael"))) { CreateRiver(); } yButtonPos += 30; if (Widgets.ButtonText(new Rect(210, yButtonPos, 200, 20), Translator.Translate("CreateEdgeRiver"))) { CreateEdgeRiver(); } yButtonPos += 30; Widgets.Label(new Rect(0, yButtonPos, 200, 20), $"Selected tile ID: {Find.WorldSelector.selectedTile}"); if (Widgets.RadioButtonLabeled(new Rect(210, yButtonPos, 200, 20), Translator.Translate("PaintMode"), PaintMode)) { TurnPaintMode(); } Widgets.EndScrollView(); }