Ejemplo n.º 1
0
        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;
                }
            }
        }