public static void DoLeavingsFor(TerrainDef terrain, IntVec3 cell, Map map)
 {
     if (Current.ProgramState == ProgramState.Playing)
     {
         ThingOwner <Thing>     thingOwner = new ThingOwner <Thing>();
         List <ThingCountClass> list       = terrain.CostListAdjusted(null, true);
         for (int i = 0; i < list.Count; i++)
         {
             ThingCountClass thingCountClass = list[i];
             int             num             = GenMath.RoundRandom((float)thingCountClass.count * terrain.resourcesFractionWhenDeconstructed);
             if (num > 0)
             {
                 Thing thing = ThingMaker.MakeThing(thingCountClass.thingDef, null);
                 thing.stackCount = num;
                 thingOwner.TryAdd(thing, true);
             }
         }
         while (true)
         {
             if (thingOwner.Count > 0)
             {
                 Thing thing2 = default(Thing);
                 if (!thingOwner.TryDrop(thingOwner[0], cell, map, ThingPlaceMode.Near, out thing2, (Action <Thing, int>)null))
                 {
                     break;
                 }
                 continue;
             }
             return;
         }
         Log.Warning("Failed to place all leavings for removed terrain " + terrain + " at " + cell);
     }
 }
        public static void DoLeavingsFor(TerrainDef terrain, IntVec3 cell, Map map)
        {
            if (Current.ProgramState != ProgramState.Playing)
            {
                return;
            }
            ThingOwner <Thing>        thingOwner = new ThingOwner <Thing>();
            List <ThingDefCountClass> list       = terrain.CostListAdjusted(null);

            for (int i = 0; i < list.Count; i++)
            {
                ThingDefCountClass thingDefCountClass = list[i];
                int num = GenMath.RoundRandom((float)thingDefCountClass.count * terrain.resourcesFractionWhenDeconstructed);
                if (num > 0)
                {
                    Thing thing = ThingMaker.MakeThing(thingDefCountClass.thingDef);
                    thing.stackCount = num;
                    thingOwner.TryAdd(thing);
                }
            }
            while (thingOwner.Count > 0)
            {
                if (!thingOwner.TryDrop(thingOwner[0], cell, map, ThingPlaceMode.Near, out var _))
                {
                    Log.Warning(string.Concat("Failed to place all leavings for removed terrain ", terrain, " at ", cell));
                    break;
                }
            }
        }
Exemple #3
0
 public static bool IsFloorAllowed_NewTmp(TerrainDef floor, bool allowWoodenFloor, bool allowConcrete, Map useOnlyStonesAvailableOnMap, bool onlyBuildableByPlayer, bool onlyStoneFloor)
 {
     if (!allowWoodenFloor && floor == TerrainDefOf.WoodPlankFloor)
     {
         return(false);
     }
     if (!allowConcrete && floor == TerrainDefOf.Concrete)
     {
         return(false);
     }
     if (onlyStoneFloor)
     {
         List <ThingDefCountClass> list = floor.CostListAdjusted(null);
         for (int i = 0; i < list.Count; i++)
         {
             if (list[i].thingDef.stuffProps != null && !list[i].thingDef.stuffProps.categories.Contains(StuffCategoryDefOf.Stony))
             {
                 return(false);
             }
         }
     }
     if (useOnlyStonesAvailableOnMap != null)
     {
         bool flag  = false;
         bool flag2 = true;
         List <ThingDefCountClass> list2 = floor.CostListAdjusted(null);
         for (int j = 0; j < list2.Count; j++)
         {
             if (list2[j].thingDef.stuffProps != null && list2[j].thingDef.stuffProps.SourceNaturalRock != null && list2[j].thingDef.stuffProps.SourceNaturalRock.IsNonResourceNaturalRock)
             {
                 flag  = true;
                 flag2 = (flag2 && Find.World.NaturalRockTypesIn(useOnlyStonesAvailableOnMap.Tile).Contains(list2[j].thingDef.stuffProps.SourceNaturalRock));
             }
         }
         if (flag && !flag2)
         {
             return(false);
         }
     }
     if (onlyBuildableByPlayer && !PlayerCanBuildNow(floor))
     {
         return(false);
     }
     return(true);
 }