public virtual void Generate(Stencil s)
            {
                var spacingX = this.spacingX > 0 ? this.spacingX : spacing;
                var spacingZ = this.spacingZ > 0 ? this.spacingZ : spacing;

                s.ClearThingsInBounds();
                if (!naturalFloor)
                {
                    s.FillTerrain(GenCity.RandomFloor(s.map));
                }
                if (roofed)
                {
                    var wallStuff = GenCity.RandomWallStuff(s.map);
                    s.Spawn(s.MinX, s.MinZ, ThingDefOf.Wall, wallStuff);
                    s.Spawn(s.MaxX, s.MinZ, ThingDefOf.Wall, wallStuff);
                    s.Spawn(s.MinX, s.MaxZ, ThingDefOf.Wall, wallStuff);
                    s.Spawn(s.MaxX, s.MaxZ, ThingDefOf.Wall, wallStuff);
                    s.FillRoof(RoofDefOf.RoofConstructed);
                }

                var stuff = thingStuff ?? GenCity.RandomStuff(thingDef, s.map);

                var paddingX = spacingX / 2 + 1;
                var paddingZ = spacingZ / 2 + 1;

                for (var x = s.MinX + paddingX; x <= s.MaxX - paddingX; x += spacingX)
                {
                    for (var z = s.MinZ + paddingZ; z <= s.MaxZ - paddingZ; z += spacingZ)
                    {
                        s.Spawn(x, z, thingDef, stuff);
                    }
                }
            }
Esempio n. 2
0
            public virtual void Generate(Stencil s)
            {
                var weapon = s.Spawn(weaponDef, weaponDef.MadeFromStuff ? ThingDefOf.Steel : null);

                weapon.SetFactionDirect(s.map.ParentFaction);
                if (ammoDef != null)
                {
                    var ammo = s.RotateRand().Spawn(s.RandInclusive(-1, 1), s.RandInclusive(2, 3), ammoDef);
                    ammo.stackCount = ammoCount.RandomInRange;
                    ammo.SetOwnedByCity(true, s.map);
                }

                if (roofed)
                {
                    var stuff = GenCity.RandomWallStuff(s.map);
                    s.Spawn(s.MinX, s.MinZ, ThingDefOf.Wall, stuff);
                    s.Spawn(s.MaxX, s.MinZ, ThingDefOf.Wall, stuff);
                    s.Spawn(s.MinX, s.MaxZ, ThingDefOf.Wall, stuff);
                    s.Spawn(s.MaxX, s.MaxZ, ThingDefOf.Wall, stuff);
                    s.FillRoof(RoofDefOf.RoofConstructed);
                }

                if (manned)
                {
                    GenCity.SpawnInhabitant(s.pos, s.map, new LordJob_ManTurrets());
                }
            }
        void GenRooms(Stencil s, bool parentWall)
        {
            s = s.Center();
            var room = roomDecorators.RandomElementByWeight(r => r.weight / r.maxArea);

            if (s.Area > room.maxArea)
            {
                if (s.Width < s.Height)
                {
                    s = s.Rotate(1 + s.RandInclusive(0, 1) * 2);
                }

                var wallX   = Mathf.RoundToInt(s.RandX * .3F);
                var hasWall = s.Chance(wallChance);

                var doorZ = 0; // default unused
                if (hasWall)
                {
                    var wallStuff = RandomWallStuff(s.map);
                    if (parentWall)
                    {
                        var offset = s.RandInclusive(0, 2) + 1;
                        doorZ = s.Chance(.5F) ? s.MinZ + offset : s.MaxZ - offset;

                        var minZ = s.MinZ + 1;
                        var maxZ = s.MaxZ - 1;
                        for (var z = minZ; z <= maxZ; z++)
                        {
                            if (z != doorZ)
                            {
                                s.Spawn(wallX, z, ThingDefOf.Wall, wallStuff);
                            }
                        }
                        // TODO dry
                    }
                    else
                    {
                        s.Fill(wallX, s.MinZ + 1, wallX, s.MaxZ - 1, ThingDefOf.Wall, RandomWallStuff(s.map));
                    }
                }

                var left  = s.Bound(s.MinX, s.MinZ, wallX, s.MaxZ);
                var right = s.Bound(wallX, s.MinZ, s.MaxX, s.MaxZ);
                GenRooms(left, hasWall);
                GenRooms(right, hasWall);

                if (hasWall && parentWall)
                {
                    s.Spawn(wallX, doorZ, ThingDefOf.Door, RandomWallStuff(s.map));
                }
            }
            else
            {
                var sInterior = s.Expand(-1);
                sInterior.ClearThingsInBounds();
                s.FillTerrain(RandomFloor(s.map));

                if (room.roofed)
                {
                    s.FillRoof(RoofDefOf.RoofConstructed);
                }

                if (s.Chance(room.lightChance))
                {
                    var sLamp = s.Expand(-1).MoveRand();
                    sLamp.Spawn(ThingDefOf.StandingLamp);
                }

                try {
                    room.Decorate(sInterior);
                }
                catch {
                    Log.Error("Error occurred in room decorator type: " + room.GetType().Name);
                    throw;
                }
            }
        }