private void SpawnFilth(IntVec3 c) { List <Thing> thingsInCell = new List <Thing>(); // Skip this cell if it is occupied by a placed object // This is to avoid save compression errors thingsInCell = Map.thingGrid.ThingsListAtFast(c); for (int t = 0; t < thingsInCell.Count; t++) { if (thingsInCell[t].def.saveCompressible) { return; } } Rand.PushState(); int filthAmount = Rand.RangeInclusive(1, 100); Rand.PopState(); // If this cell isn't filthy enough, skip it if (filthAmount <= 20) { return; } // Check for dirt filth if (filthAmount <= 40) { GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Filth_Dirt), c, Map); } else { GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Filth_RubbleRock), c, Map); // Check for chunks if (filthAmount > 80) { Rand.PushState(); GenSpawn.Spawn(ThingMaker.MakeThing(ChunksUnder.RandomElement()), c, Map); Rand.PopState(); } } }
public ThingDef GiveResources(ResourceRequest req, out MoteType mote, out bool singleSpawn, out bool eventTriggered) { // Increment the jobs completed jobsCompleted++; eventTriggered = false; mote = MoteType.None; singleSpawn = true; // Decrease the amount this quarry can be mined, eventually depleting it if (QuarrySettings.QuarryMaxHealth != int.MaxValue) { QuarryMined(); } // Determine if the mining job resulted in a sinkhole event, based on game difficulty if (jobsCompleted % SinkholeFrequency == 0 && Rand.Chance(Find.Storyteller.difficulty.difficulty / 50f)) { eventTriggered = true; // The sinkhole damages the quarry a little QuarryMined(Rand.RangeInclusive(1, 3)); } // Cache values since this process is convoluted and the values need to remain the same bool junkMined = Rand.Chance(QuarrySettings.junkChance / 100f); // Check for blocks first to prevent spawning chunks (these would just be cut into blocks) if (req == ResourceRequest.Blocks) { if (!junkMined) { singleSpawn = false; return(BlocksUnder.RandomElement()); } // The rock didn't break into a usable size, spawn rubble mote = MoteType.Failure; return(ThingDefOf.RockRubble); } // Try to give junk before resources. This simulates only mining chunks or useless rubble if (junkMined) { if (Rand.Chance(QuarrySettings.chunkChance / 100f)) { return(ChunksUnder.RandomElement()); } else { mote = MoteType.Failure; return(ThingDefOf.RockRubble); } } // Try to give resources if (req == ResourceRequest.Resources) { singleSpawn = false; return(OreDictionary.TakeOne()); } // The quarry was most likely toggled off while a pawn was still working. Give junk else { return(ThingDefOf.RockRubble); } }