Example #1
0
        private void SetupThirdPass(CellRect rect)
        {
            foreach (IntVec3 c in rect)
            {
                if (c == Position + Static.LadderOffset1.RotatedBy(Rotation) || c == Position + Static.LadderOffset2.RotatedBy(Rotation) || c == Position + Static.LadderOffset3.RotatedBy(Rotation) || c == Position + Static.LadderOffset4.RotatedBy(Rotation))
                {
                    Map.terrainGrid.SetTerrain(c, QuarryDefOf.QRY_QuarriedGround);
                }

                List <Thing> thingsInCell = new List <Thing>();
                bool         usableCell   = true;
                // 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)
                    {
                        usableCell = false;
                        break;
                    }
                }

                if (usableCell)
                {
                    int filthAmount = Rand.RangeInclusive(1, 100);
                    // Check for dirt filth
                    if (filthAmount > 20 && filthAmount <= 40)
                    {
                        GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.FilthDirt), c, Map);
                    }
                    // Check for rock rubble
                    else if (filthAmount > 40)
                    {
                        GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.RockRubble), c, Map);
                        // Check for chunks
                        if (filthAmount > 80)
                        {
                            string   chunkType = RockTypesUnder.RandomElement();
                            ThingDef chunk     = QuarryMod.Database.Find(t => t.defName == "Chunk" + chunkType);
                            GenSpawn.Spawn(ThingMaker.MakeThing(chunk), c, Map);
                        }
                    }
                }
            }
        }
Example #2
0
        public Thing GiveResources(ResourceRequest req, out MoteType mote)
        {
            mote = MoteType.None;

            // Decrease the amount this quarry can be mined, eventually depleting it
            if (QuarryMod.QuarryMaxHealth != int.MaxValue)
            {
                quarryHealth--;
            }

            // Cache values since this process is convoluted and the values need to remain the same
            bool cachedJunkChance = Rand.Chance(QuarryMod.JunkChance);

            // Check for blocks first to prevent spawning chunks (these would just be cut into blocks)
            if (req == ResourceRequest.Blocks)
            {
                if (!cachedJunkChance)
                {
                    string blockType = RockTypesUnder.RandomElement();
                    return(new QuarryResource(QuarryMod.Database.Find(t => t.defName == "Blocks" + blockType), Rand.RangeInclusive(5, 10)).ToThing());
                }
                // The rock didn't break into a usable size, spawn rubble
                mote = MoteType.Failure;
                return(new QuarryResource(ThingDefOf.RockRubble, 1).ToThing());
            }

            // Try to give junk before resources. This simulates only mining chunks or useless rubble
            if (cachedJunkChance)
            {
                if (Rand.Chance(QuarryMod.ChunkChance))
                {
                    return(new QuarryResource(QuarryMod.Database.Find(t => t.defName == "Chunk" + RockTypesUnder.RandomElement()), 1).ToThing());
                }
                else
                {
                    mote = MoteType.Failure;
                    return(new QuarryResource(ThingDefOf.RockRubble, 1).ToThing());
                }
            }

            System.Random rand = new System.Random();

            // Try to give resources
            if (req == ResourceRequest.Resources)
            {
                int maxProb = QuarryMod.Resources.Sum(c => c.probability);
                int choice  = rand.Next(maxProb);
                int sum     = 0;

                foreach (QuarryResource resource in QuarryMod.Resources)
                {
                    for (int i = sum; i < resource.probability + sum; i++)
                    {
                        if (i >= choice)
                        {
                            if (resource.largeVein)
                            {
                                mote = MoteType.LargeVein;
                            }
                            return(resource.ToThing());
                        }
                    }
                    sum += resource.probability;
                }
                QuarryResource qr = QuarryMod.Resources.First();
                if (qr.largeVein)
                {
                    mote = MoteType.LargeVein;
                }
                return(qr.ToThing());
            }
            // The quarry was most likely toggled off while a pawn was still working. Give junk
            else
            {
                return(new QuarryResource(ThingDefOf.RockRubble, 1).ToThing());
            }
        }
Example #3
0
        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)
            {
                quarryHealth--;
            }

            // Determine if the mining job resulted in a sinkhole event, based on game difficulty
            if (jobsCompleted % 100 == 0 && Rand.Chance(Find.Storyteller.difficulty.difficulty / 50f))
            {
                eventTriggered = true;
            }

            // Cache values since this process is convoluted and the values need to remain the same
            bool cachedJunkChance = 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 (!cachedJunkChance)
                {
                    singleSpawn = false;
                    string blockType = RockTypesUnder.RandomElement();
                    return(QuarrySettings.database.Find(t => t.defName == "Blocks" + blockType));
                }
                // 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 (cachedJunkChance)
            {
                if (Rand.Chance(QuarrySettings.chunkChance / 100f))
                {
                    return(QuarrySettings.database.Find(t => t.defName == "Chunk" + RockTypesUnder.RandomElement()));
                }
                else
                {
                    mote = MoteType.Failure;
                    return(ThingDefOf.RockRubble);
                }
            }

            System.Random rand = new System.Random();

            // Try to give resources
            if (req == ResourceRequest.Resources)
            {
                singleSpawn = false;
                return(OreDictionary.From(QuarryMod.oreDictionary).TakeOne());
            }
            // The quarry was most likely toggled off while a pawn was still working. Give junk
            else
            {
                return(ThingDefOf.RockRubble);
            }
        }