コード例 #1
0
        protected override void ResolveInt(ResolveParams parms)
        {
            CellRect outerRect = parms.rect ?? parms.sketch.OccupiedRect;
            bool     allowWood = parms.allowWood ?? true;
            bool     flag      = parms.requireFloor ?? false;

            rects.Clear();
            processed.Clear();
            foreach (IntVec3 item2 in outerRect.Cells.InRandomOrder())
            {
                CellRect item = SketchGenUtility.FindBiggestRectAt(item2, outerRect, parms.sketch, processed, (IntVec3 x) => !AnyColumnBlockerAt(x, parms.sketch));
                if (!item.IsEmpty)
                {
                    rects.Add(item);
                }
            }
            ThingDef stuff = GenStuff.RandomStuffInexpensiveFor(ThingDefOf.Column, null, (ThingDef x) => SketchGenUtility.IsStuffAllowed(x, allowWood, parms.useOnlyStonesAvailableOnMap, allowFlammableWalls: true, ThingDefOf.Column));

            for (int i = 0; i < rects.Count; i++)
            {
                if (rects[i].Width < 3 || rects[i].Height < 3 || !Rand.Chance(0.8f))
                {
                    continue;
                }
                CellRect cellRect = rects[i].ContractedBy(1);
                Sketch   sketch   = new Sketch();
                if (Rand.Bool)
                {
                    int newZ = Rand.RangeInclusive(cellRect.minZ, cellRect.CenterCell.z);
                    int num  = ((cellRect.Width >= 4) ? Rand.Element(2, 3) : 2);
                    for (int j = cellRect.minX; j <= cellRect.maxX; j += num)
                    {
                        if (!flag || parms.sketch.AnyTerrainAt(new IntVec3(j, 0, newZ)))
                        {
                            sketch.AddThing(ThingDefOf.Column, new IntVec3(j, 0, newZ), Rot4.North, stuff);
                        }
                    }
                    ResolveParams parms2 = parms;
                    parms2.sketch                 = sketch;
                    parms2.symmetryOrigin         = rects[i].minZ + rects[i].Height / 2;
                    parms2.symmetryOriginIncluded = rects[i].Height % 2 == 1;
                    SketchResolverDefOf.Symmetry.Resolve(parms2);
                }
                else
                {
                    int newX = Rand.RangeInclusive(cellRect.minX, cellRect.CenterCell.x);
                    int num2 = ((cellRect.Height >= 4) ? Rand.Element(2, 3) : 2);
                    for (int k = cellRect.minZ; k <= cellRect.maxZ; k += num2)
                    {
                        if (!flag || parms.sketch.AnyTerrainAt(new IntVec3(newX, 0, k)))
                        {
                            sketch.AddThing(ThingDefOf.Column, new IntVec3(newX, 0, k), Rot4.North, stuff);
                        }
                    }
                    ResolveParams parms3 = parms;
                    parms3.sketch                 = sketch;
                    parms3.symmetryOrigin         = rects[i].minX + rects[i].Width / 2;
                    parms3.symmetryOriginIncluded = rects[i].Width % 2 == 1;
                    SketchResolverDefOf.Symmetry.Resolve(parms3);
                }
                parms.sketch.Merge(sketch, wipeIfCollides: false);
            }
            rects.Clear();
            processed.Clear();
        }
        protected override void ResolveInt(ResolveParams parms)
        {
            CellRect outerRect    = parms.rect ?? parms.sketch.OccupiedRect;
            bool     allowWood    = parms.allowWood ?? true;
            ThingDef stuff        = GenStuff.RandomStuffInexpensiveFor(parms.wallEdgeThing, null, (ThingDef x) => SketchGenUtility.IsStuffAllowed(x, allowWood, parms.useOnlyStonesAvailableOnMap, allowFlammableWalls: true, parms.wallEdgeThing));
            Rot4     rot          = ((parms.wallEdgeThing.size.z > parms.wallEdgeThing.size.x) ? Rot4.North : Rot4.East);
            Rot4     rot2         = ((parms.wallEdgeThing.size.z > parms.wallEdgeThing.size.x) ? Rot4.East : Rot4.North);
            CellRect cellRect     = GenAdj.OccupiedRect(default(IntVec3), rot, parms.wallEdgeThing.size);
            CellRect cellRect2    = GenAdj.OccupiedRect(default(IntVec3), rot2, parms.wallEdgeThing.size);
            bool     requireFloor = parms.requireFloor ?? false;

            processed.Clear();
            try
            {
                foreach (IntVec3 item in outerRect.Cells.InRandomOrder())
                {
                    CellRect cellRect3 = SketchGenUtility.FindBiggestRectAt(item, outerRect, parms.sketch, processed, (IntVec3 x) => !parms.sketch.ThingsAt(x).Any() && (!requireFloor || (parms.sketch.TerrainAt(x) != null && parms.sketch.TerrainAt(x).layerable)));
                    if (cellRect3.Width < cellRect.Width || cellRect3.Height < cellRect.Height || cellRect3.Width < cellRect2.Width || cellRect3.Height < cellRect2.Height || !Rand.Chance(0.2f))
                    {
                        continue;
                    }
                    CellRect rect  = new CellRect(cellRect3.minX, cellRect3.CenterCell.z - cellRect.Height / 2, cellRect.Width, cellRect.Height);
                    CellRect rect2 = new CellRect(cellRect3.maxX - (cellRect.Width - 1), cellRect3.CenterCell.z - cellRect.Height / 2, cellRect.Width, cellRect.Height);
                    CellRect rect3 = new CellRect(cellRect3.CenterCell.x - cellRect2.Width / 2, cellRect3.maxZ - (cellRect2.Height - 1), cellRect2.Width, cellRect2.Height);
                    CellRect rect4 = new CellRect(cellRect3.CenterCell.x - cellRect2.Width / 2, cellRect3.minZ, cellRect2.Width, cellRect2.Height);
                    if ((Rand.Bool && CanPlaceAt(rect, Rot4.West, parms.sketch)) || CanPlaceAt(rect2, Rot4.East, parms.sketch))
                    {
                        if (Rand.Bool && CanPlaceAt(rect, Rot4.West, parms.sketch))
                        {
                            parms.sketch.AddThing(parms.wallEdgeThing, new IntVec3(rect.minX - cellRect.minX, 0, rect.minZ - cellRect.minZ), rot, stuff, 1, null, null, wipeIfCollides: false);
                        }
                        else if (CanPlaceAt(rect2, Rot4.East, parms.sketch))
                        {
                            parms.sketch.AddThing(parms.wallEdgeThing, new IntVec3(rect2.minX - cellRect.minX, 0, rect2.minZ - cellRect.minZ), rot, stuff, 1, null, null, wipeIfCollides: false);
                        }
                    }
                    else if (Rand.Bool && CanPlaceAt(rect3, Rot4.North, parms.sketch))
                    {
                        parms.sketch.AddThing(parms.wallEdgeThing, new IntVec3(rect3.minX - cellRect2.minX, 0, rect3.minZ - cellRect2.minZ), rot2, stuff, 1, null, null, wipeIfCollides: false);
                    }
                    else if (CanPlaceAt(rect4, Rot4.South, parms.sketch))
                    {
                        parms.sketch.AddThing(parms.wallEdgeThing, new IntVec3(rect4.minX - cellRect2.minX, 0, rect4.minZ - cellRect2.minZ), rot2, stuff, 1, null, null, wipeIfCollides: false);
                    }
                }
            }
            finally
            {
                processed.Clear();
            }
        }
コード例 #3
0
        protected override void ResolveInt(ResolveParams parms)
        {
            CellRect outerRect    = parms.rect ?? parms.sketch.OccupiedRect;
            bool     allowWood    = parms.allowWood ?? true;
            ThingDef stuff        = GenStuff.RandomStuffInexpensiveFor(parms.thingCentral, null, (ThingDef x) => SketchGenUtility.IsStuffAllowed(x, allowWood, parms.useOnlyStonesAvailableOnMap, allowFlammableWalls: true, parms.thingCentral));
            bool     requireFloor = parms.requireFloor ?? false;

            processed.Clear();
            try
            {
                foreach (IntVec3 item in outerRect.Cells.InRandomOrder())
                {
                    CellRect cellRect = SketchGenUtility.FindBiggestRectAt(item, outerRect, parms.sketch, processed, (IntVec3 x) => !parms.sketch.ThingsAt(x).Any() && (!requireFloor || (parms.sketch.TerrainAt(x) != null && parms.sketch.TerrainAt(x).layerable)));
                    if (cellRect.Width >= parms.thingCentral.size.x + 2 && cellRect.Height >= parms.thingCentral.size.z + 2 && Rand.Chance(0.4f))
                    {
                        parms.sketch.AddThing(parms.thingCentral, new IntVec3(cellRect.CenterCell.x - parms.thingCentral.size.x / 2, 0, cellRect.CenterCell.z - parms.thingCentral.size.z / 2), Rot4.North, stuff, 1, null, null, wipeIfCollides: false);
                    }
                }
            }
            finally
            {
                processed.Clear();
            }
        }
        protected override void ResolveInt(ResolveParams parms)
        {
            ThingDef assignRandomStuffTo = parms.assignRandomStuffTo;
            bool     flag                = parms.connectedGroupsSameStuff ?? false;
            bool     allowWood           = parms.allowWood ?? true;
            bool     allowFlammableWalls = parms.allowFlammableWalls ?? true;

            thingsAt.Clear();
            foreach (SketchThing thing2 in parms.sketch.Things)
            {
                if (assignRandomStuffTo != null && thing2.def != assignRandomStuffTo)
                {
                    continue;
                }
                foreach (IntVec3 item in thing2.OccupiedRect)
                {
                    if (!thingsAt.TryGetValue(item, out var value))
                    {
                        value = new List <SketchThing>();
                        thingsAt.Add(item, value);
                    }
                    value.Add(thing2);
                }
            }
            visited.Clear();
            foreach (SketchThing thing in parms.sketch.Things)
            {
                if ((assignRandomStuffTo != null && thing.def != assignRandomStuffTo) || visited.Contains(thing))
                {
                    continue;
                }
                ThingDef stuff = GenStuff.RandomStuffInexpensiveFor(thing.def, null, (ThingDef x) => SketchGenUtility.IsStuffAllowed(x, allowWood, parms.useOnlyStonesAvailableOnMap, allowFlammableWalls, thing.def));
                thing.stuff = stuff;
                visited.Add(thing);
                if (!flag)
                {
                    continue;
                }
                stack.Clear();
                stack.Push(thing);
                while (stack.Count != 0)
                {
                    SketchThing sketchThing = stack.Pop();
                    sketchThing.stuff = stuff;
                    foreach (IntVec3 item2 in sketchThing.OccupiedRect.ExpandedBy(1))
                    {
                        if (!thingsAt.TryGetValue(item2, out var value2))
                        {
                            continue;
                        }
                        for (int i = 0; i < value2.Count; i++)
                        {
                            if (value2[i].def == thing.def && !visited.Contains(value2[i]))
                            {
                                visited.Add(value2[i]);
                                stack.Push(value2[i]);
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
        protected override void ResolveInt(ResolveParams parms)
        {
            wallPositions.Clear();
            for (int i = 0; i < parms.sketch.Things.Count; i++)
            {
                if (parms.sketch.Things[i].def == ThingDefOf.Wall)
                {
                    wallPositions.Add(parms.sketch.Things[i].pos);
                }
            }
            bool     allowWood = parms.allowWood ?? true;
            ThingDef stuff     = GenStuff.RandomStuffInexpensiveFor(parms.cornerThing, null, (ThingDef x) => SketchGenUtility.IsStuffAllowed(x, allowWood, parms.useOnlyStonesAvailableOnMap, allowFlammableWalls: true, parms.cornerThing));
            bool     flag      = parms.requireFloor ?? false;

            try
            {
                foreach (IntVec3 wallPosition in wallPositions)
                {
                    if (Rand.Chance(0.09f))
                    {
                        if (wallPositions.Contains(new IntVec3(wallPosition.x + 1, 0, wallPosition.z - 1)) && !wallPositions.Contains(new IntVec3(wallPosition.x + 1, 0, wallPosition.z)) && (!flag || (parms.sketch.TerrainAt(new IntVec3(wallPosition.x + 1, 0, wallPosition.z)) != null && parms.sketch.TerrainAt(new IntVec3(wallPosition.x + 1, 0, wallPosition.z)).layerable)))
                        {
                            parms.sketch.AddThing(parms.cornerThing, new IntVec3(wallPosition.x + 1, 0, wallPosition.z), Rot4.North, stuff, 1, null, null, wipeIfCollides: false);
                        }
                        if (wallPositions.Contains(new IntVec3(wallPosition.x + 1, 0, wallPosition.z - 1)) && !wallPositions.Contains(new IntVec3(wallPosition.x, 0, wallPosition.z - 1)) && (!flag || (parms.sketch.TerrainAt(new IntVec3(wallPosition.x, 0, wallPosition.z - 1)) != null && parms.sketch.TerrainAt(new IntVec3(wallPosition.x, 0, wallPosition.z - 1)).layerable)))
                        {
                            parms.sketch.AddThing(parms.cornerThing, new IntVec3(wallPosition.x, 0, wallPosition.z - 1), Rot4.North, stuff, 1, null, null, wipeIfCollides: false);
                        }
                        if (wallPositions.Contains(new IntVec3(wallPosition.x + 1, 0, wallPosition.z + 1)) && !wallPositions.Contains(new IntVec3(wallPosition.x, 0, wallPosition.z + 1)) && (!flag || (parms.sketch.TerrainAt(new IntVec3(wallPosition.x, 0, wallPosition.z + 1)) != null && parms.sketch.TerrainAt(new IntVec3(wallPosition.x, 0, wallPosition.z + 1)).layerable)))
                        {
                            parms.sketch.AddThing(parms.cornerThing, new IntVec3(wallPosition.x, 0, wallPosition.z + 1), Rot4.North, stuff, 1, null, null, wipeIfCollides: false);
                        }
                        if (wallPositions.Contains(new IntVec3(wallPosition.x + 1, 0, wallPosition.z + 1)) && !wallPositions.Contains(new IntVec3(wallPosition.x + 1, 0, wallPosition.z)) && (!flag || (parms.sketch.TerrainAt(new IntVec3(wallPosition.x + 1, 0, wallPosition.z)) != null && parms.sketch.TerrainAt(new IntVec3(wallPosition.x + 1, 0, wallPosition.z)).layerable)))
                        {
                            parms.sketch.AddThing(parms.cornerThing, new IntVec3(wallPosition.x + 1, 0, wallPosition.z), Rot4.North, stuff, 1, null, null, wipeIfCollides: false);
                        }
                    }
                }
            }
            finally
            {
                wallPositions.Clear();
            }
        }