internal static bool DoProspectFind(Pawn worker, Map map, float radius, out IntVec3 prospect, out ThingDef thingDef) { thingDef = null; prospect = IntVec3.Zero; if (!CellFinderLoose.TryFindRandomNotEdgeCellWith(5, x => CanScatterAt(x, map) && x != worker.Position && (x - worker.Position).LengthHorizontalSquared <= radius * radius, map, out var result)) { return(false); } thingDef = ChooseLumpThingDef(); if (!thingDef.IsMetal) { return(false); } prospect = result; var numCells = Mathf.CeilToInt(thingDef.deepLumpSizeRange.RandomInRange); foreach (var item in GridShapeMaker.IrregularLump(result, map, numCells)) { if (CanScatterAt(item, map) && !item.InNoBuildEdgeArea(map)) { map.deepResourceGrid.SetAt(item, thingDef, thingDef.deepCountPerCell); } } return(true); }
public void GenerateUndergroundWaterGrid(Map map, MapComponent_WaterGrid waterGrid, int basePoolNum, int minWaterPoolNum, float baseRainFall, float basePlantDensity, float literPerCell, IntRange poolCellRange, FloatRange baseRegenRateRange, float rainRegenRatePerCell) { float rainRate = map.TileInfo.rainfall / baseRainFall; float areaRate = map.Area / BaseMapArea; float plantRate = map.Biome.plantDensity / basePlantDensity; int waterPoolNum = Mathf.RoundToInt(basePoolNum * rainRate * areaRate * plantRate); //Log.Message(string.Format("rain={0},area={1},plant={2},num={3}", rainRate.ToString("F3"), areaRate.ToString("F3"), plantRate.ToString("F3"), waterPoolNum)); if (plantRate > 0.0f) { waterPoolNum = Mathf.Max(waterPoolNum, minWaterPoolNum); } for (int i = 0; i < waterPoolNum; i++) { IntVec3 result; if (CellFinderLoose.TryFindRandomNotEdgeCellWith(5, (c) => !waterGrid.GetCellBool(map.cellIndices.CellToIndex(c)), map, out result)) { int numCells = poolCellRange.RandomInRange; float baseRegenRate = baseRegenRateRange.RandomInRange; UndergroundWaterPool pool = new UndergroundWaterPool(waterGrid, numCells * literPerCell, WaterType.RawWater, baseRegenRate, rainRegenRatePerCell); pool.ID = i + 1; waterGrid.AddWaterPool(pool, GridShapeMaker.IrregularLump(result, map, numCells)); } } waterGrid.ModifyPoolGrid(); }
protected override void ScatterAt(IntVec3 loc, Map map, GenStepParams parms, int stackCount = 1) { if (!TryGetRandomValidRotation(loc, map, out Rot4 rot)) { Log.Warning("Could not find any valid rotation for " + thingDef); return; } if (clearSpaceSize > 0) { foreach (IntVec3 item in GridShapeMaker.IrregularLump(loc, map, clearSpaceSize)) { item.GetEdifice(map)?.Destroy(); } } Thing thing = ThingMaker.MakeThing(thingDef, stuff); if (thingDef.Minifiable) { thing = thing.MakeMinified(); } if (thing.def.category == ThingCategory.Item) { thing.stackCount = stackCount; thing.SetForbidden(value: true, warnOnFail: false); GenPlace.TryPlaceThing(thing, loc, map, ThingPlaceMode.Near, out Thing lastResultingThing); if (nearPlayerStart && lastResultingThing != null && lastResultingThing.def.category == ThingCategory.Item && TutorSystem.TutorialMode) { Find.TutorialState.AddStartingItem(lastResultingThing); } } else { GenSpawn.Spawn(thing, loc, map, rot); } }
protected override void ScatterAt(IntVec3 c, Map map, int stackCount = 1) { ThingDef thingDef = this.ChooseThingDef(); int numCells = (this.forcedLumpSize <= 0) ? thingDef.building.mineableScatterLumpSizeRange.RandomInRange : this.forcedLumpSize; this.recentLumpCells.Clear(); foreach (IntVec3 current in GridShapeMaker.IrregularLump(c, map, numCells)) { GenSpawn.Spawn(thingDef, current, map); this.recentLumpCells.Add(current); } }
protected override void ScatterAt(IntVec3 c, Map map, int stackCount = 1) { ThingDef thingDef = this.ChooseThingDef(); int numCells = Mathf.CeilToInt((float)thingDef.deepLumpSizeRange.RandomInRange); foreach (IntVec3 current in GridShapeMaker.IrregularLump(c, map, numCells)) { if (!current.InNoBuildEdgeArea(map)) { map.deepResourceGrid.SetAt(current, thingDef, thingDef.deepCountPerCell); } } }
protected override void ScatterAt(IntVec3 c, Map map, GenStepParams parms, int stackCount = 1) { ThingDef thingDef = ChooseThingDef(); if (thingDef != null) { int numCells = (forcedLumpSize > 0) ? forcedLumpSize : thingDef.building.mineableScatterLumpSizeRange.RandomInRange; recentLumpCells.Clear(); foreach (IntVec3 item in GridShapeMaker.IrregularLump(c, map, numCells)) { GenSpawn.Spawn(thingDef, item, map); recentLumpCells.Add(item); } } }
protected override void ScatterAt(IntVec3 loc, Map map, GenStepParams parms, int stackCount = 1) { Rot4 rot; if (!this.TryGetRandomValidRotation(loc, map, out rot)) { Logger.Warning("Could not find any valid rotation for " + this.thingDef); return; } if (this.clearSpaceSize > 0) { using (IEnumerator <IntVec3> enumerator = GridShapeMaker.IrregularLump(loc, map, this.clearSpaceSize).GetEnumerator()) { while (enumerator.MoveNext()) { Building edifice = enumerator.Current.GetEdifice(map); if (edifice != null) { edifice.Destroy(DestroyMode.Vanish); } } } } Thing thing = ThingMaker.MakeThing(this.thingDef, this.stuff); if (this.thingDef.Minifiable) { thing = thing.MakeMinified(); } if (thing.def.category == ThingCategory.Item) { thing.stackCount = stackCount; thing.SetForbidden(true, false); Thing thing2; GenPlace.TryPlaceThing(thing, loc, map, ThingPlaceMode.Near, out thing2, null, null, default(Rot4)); if (this.nearPlayerStart && thing2 != null && thing2.def.category == ThingCategory.Item && TutorSystem.TutorialMode) { Find.TutorialState.AddStartingItem(thing2); return; } } else { GenSpawn.Spawn(thing, loc, map, rot, WipeMode.Vanish, false); } }
public static void GenerateUndergroundWaterGrid(Map map, MapComponent_WaterGrid waterGrid, int basePoolNum = 30, int minWaterPoolNum = 3, float baseRainFall = 1000f, float basePlantDensity = 0.25f, float literPerCell = 10.0f, IntRange poolCellRange = default, FloatRange baseRegenRateRange = default, float rainRegenRatePerCell = 5.0f) { if (poolCellRange == default) { poolCellRange = new IntRange(30, 100); } if (baseRegenRateRange == default) { baseRegenRateRange = new FloatRange(10.0f, 20.0f); } var BaseMapArea = 250f * 250f; var rainRate = map.TileInfo.rainfall / baseRainFall; var areaRate = map.Area / BaseMapArea; var plantRate = map.Biome.plantDensity / basePlantDensity; var waterPoolNum = Mathf.RoundToInt(basePoolNum * rainRate * areaRate * plantRate); // Log.Message(string.Format("rain={0},area={1},plant={2},num={3}", rainRate.ToString("F3"), areaRate.ToString("F3"), plantRate.ToString("F3"), waterPoolNum)); if (plantRate > 0.0f) { waterPoolNum = Mathf.Max(waterPoolNum, minWaterPoolNum); } for (var i = 0; i < waterPoolNum; i++) { if (!CellFinderLoose.TryFindRandomNotEdgeCellWith(5, c => !waterGrid.GetCellBool(map.cellIndices.CellToIndex(c)), map, out var result)) { continue; } var numCells = poolCellRange.RandomInRange; var baseRegenRate = baseRegenRateRange.RandomInRange; var pool = new UndergroundWaterPool(waterGrid, numCells * literPerCell, WaterType.RawWater, baseRegenRate, rainRegenRatePerCell) { ID = i + 1 }; waterGrid.AddWaterPool(pool, GridShapeMaker.IrregularLump(result, map, numCells)); } waterGrid.ModifyPoolGrid(); }
protected override void ScatterAt(IntVec3 loc, Map map, int stackCount = 1) { Rot4 rot; if (!this.TryGetRandomValidRotation(loc, map, out rot)) { Log.Warning("Could not find any valid rotation for " + this.thingDef); } else { if (this.clearSpaceSize > 0) { foreach (IntVec3 current in GridShapeMaker.IrregularLump(loc, map, this.clearSpaceSize)) { Building edifice = current.GetEdifice(map); if (edifice != null) { edifice.Destroy(DestroyMode.Vanish); } } } Thing thing = ThingMaker.MakeThing(this.thingDef, this.stuff); if (this.thingDef.Minifiable) { thing = thing.MakeMinified(); } if (thing.def.category == ThingCategory.Item) { thing.stackCount = stackCount; thing.SetForbidden(true, false); Thing thing2; GenPlace.TryPlaceThing(thing, loc, map, ThingPlaceMode.Near, out thing2, null); if (this.nearPlayerStart && thing2 != null && thing2.def.category == ThingCategory.Item && TutorSystem.TutorialMode) { Find.TutorialState.AddStartingItem(thing2); } } else { // TODO: Evaluate new WipeMode and 5th argument GenSpawn.Spawn(thing, loc, map, rot, WipeMode.Vanish, false); } } }
protected override void ScatterAt(IntVec3 loc, Map map, int stackCount = 1) { if (!TryGetRandomValidRotation(loc, map, out Rot4 rot)) { Log.Warning("Could not find any valid rotation for " + thingDef); return; } if (clearSpaceSize > 0) { using (IEnumerator <IntVec3> enumerator = GridShapeMaker.IrregularLump(loc, map, clearSpaceSize).GetEnumerator()) { while (enumerator.MoveNext()) { Building edifice = GridsUtility.GetEdifice(enumerator.Current, map); if (edifice != null) { edifice.Destroy(0); } } } } Thing thing = ThingMaker.MakeThing(thingDef, stuff); if (thingDef.Minifiable) { thing = MinifyUtility.MakeMinified(thing); } if (thing.def.category == ThingCategory.Item) { thing.stackCount = stackCount; ForbidUtility.SetForbidden(thing, true, false); GenPlace.TryPlaceThing(thing, loc, map, ThingPlaceMode.Near, out Thing thing2, null); if (nearPlayerStart && thing2 != null && thing2.def.category == ThingCategory.Item && TutorSystem.TutorialMode) { Find.TutorialState.AddStartingItem(thing2); return; } } else { GenSpawn.Spawn(thing, loc, map, rot, false); } }
static bool Prefix(GenStep_ScatterLumpsMineable __instance, IntVec3 c, Map map, List <IntVec3> ___recentLumpCells) { ThingDef chosen = null; if (__instance.forcedDefToScatter != null) { chosen = __instance.forcedDefToScatter; } else { chosen = DefDatabase <ThingDef> .AllDefs.RandomElementByWeightWithFallback(delegate(ThingDef d) { if (d.building == null) { return(0f); } if (d.building.mineableThing != null && d.building.mineableThing.BaseMarketValue > __instance.maxValue) { return(0f); } var preferred = d.GetCompProperties <CompProperties_OreBiomePreferred>(); if (preferred != null && !preferred.allowedBiomes.Contains(map.Biome)) { return(d.building.mineableScatterCommonality * 0.15f); } return(d.building.mineableScatterCommonality); }, null); } if (chosen != null) { int numCells = (__instance.forcedLumpSize <= 0) ? chosen.building.mineableScatterLumpSizeRange.RandomInRange : __instance.forcedLumpSize; ___recentLumpCells.Clear(); foreach (IntVec3 intVec in GridShapeMaker.IrregularLump(c, map, numCells)) { GenSpawn.Spawn(chosen, intVec, map, WipeMode.Vanish); ___recentLumpCells.Add(intVec); } } return(false); }
public static bool ScatterAt_PreFix(IntVec3 c, Map map, GenStep_ScatterLumpsMineable __instance) { ThingDef thingDef = null; if (__instance.forcedDefToScatter != null) { thingDef = __instance.forcedDefToScatter; } else { thingDef = DefDatabase <ThingDef> .AllDefs.RandomElementByWeight(delegate(ThingDef d) { if (d.building == null) { return(0f); } if (d.GetCompProperties <CompProperties_BiomeSpecific>() != null && !d.GetCompProperties <CompProperties_BiomeSpecific>().allowedBiomes.Contains(map.Biome.defName)) { return(0f); } return(d.building.mineableScatterCommonality); }); } List <IntVec3> recentLumpCells = (List <IntVec3>)AccessTools.Field(typeof(GenStep_ScatterLumpsMineable), "recentLumpCells").GetValue(__instance); int numCells = (__instance.forcedLumpSize <= 0) ? thingDef.building.mineableScatterLumpSizeRange.RandomInRange : __instance.forcedLumpSize; recentLumpCells.Clear(); foreach (IntVec3 current in GridShapeMaker.IrregularLump(c, map, numCells)) { GenSpawn.Spawn(thingDef, current, map); recentLumpCells.Add(current); } AccessTools.Field(typeof(GenStep_ScatterLumpsMineable), "recentLumpCells").SetValue(__instance, recentLumpCells); return(false); }