Example #1
0
        public override void Generate(Map map, GenStepParams parms)
        {
            var s = new Stencil(map);

            s = s.Bound(s.MinX, s.MaxZ - Mathf.RoundToInt(map.Size.x * HeightRatio), s.MaxX, s.MaxZ)
                .Center();

            // Clear area
            s.Expand(0, 3, 0, 0).ClearThingsInBounds();

            // Courtyard floor
            s.FillTerrain(BaseGenUtility.RandomHightechFloorDef());

            // Outer floor
            s.Bound(0, s.MinZ - 1, 0, s.MinZ - 8).SetTerrain(GenCity.RandomFloor(map));

            // Outer barricade
            s.Fill(s.MinX, s.MinZ - 7, s.MaxX, s.MinZ - 7, ThingDefOf.Barricade, GenCity.RandomStuff(ThingDefOf.Barricade, map), IsValidBarricadeTile);

            // Outer wall
            var wallStuff = BaseGenUtility.RandomHightechWallStuff();
            var doorX     = s.MinX + map.Size.x / 2;

            s.Fill(s.MinX, s.MinZ - 3, doorX - 1, s.MinZ, ThingDefOf.Wall, wallStuff);
            s.Fill(doorX + 1, s.MinZ - 3, s.MaxX, s.MinZ, ThingDefOf.Wall, wallStuff);
            s.Bound(doorX, s.MinZ - 3, doorX, s.MinZ)
            .Fill(ThingDefOf.Door, wallStuff);

            // Inner keep
            s = s.Expand(-marginRange.RandomInRange, -marginRange.RandomInRange, -marginRange.RandomInRange, -marginRange.RandomInRange);

            var genStep = (GenStep_Buildings)buildingGenStepDef.genStep;

            genStep.GenerateRect(s);

            // Mechanoids
            var mechs = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms {
                groupKind = PawnGroupKindDefOf.Combat,
                tile      = map.Tile,
                faction   = Faction.OfMechanoids,
                points    = 5000,
            }).ToList();

            foreach (var mech in mechs)
            {
                var pos = s.Expand(-10).MoveRand().pos;
                GenSpawn.Spawn(mech, GenCity.FindPawnSpot(pos, map), map);
                mech.SetFactionDirect(map.ParentFaction);
                mech.Name = new NameSingle(mechanoidNames[Rand.Range(0, mechanoidNames.Count)] + " #" + Rand.RangeInclusive(10, 40));
                var lord = LordMaker.MakeNewLord(map.ParentFaction, new LordJob_LiveInCitadel(pos), map);
                lord.AddPawn(mech);
            }

            //TODO throne room
        }
        public override void Decorate(Stencil s)
        {
            var sBed  = s.Expand(-1);
            var thing = bedOptions.RandomElement();
            var stuff = GenCity.RandomStuff(thing, s.map);
            var bed   = (Building_Bed)sBed.Spawn(sBed.RandX, sBed.RandZ, thing, stuff);

            bed.SetFactionDirect(s.map.ParentFaction);
            bed.ForPrisoners = true;
            if (s.Chance(prisonerChance))
            {
                var pawn = GenCity.SpawnInhabitant(s.pos, s.map, kind: PawnKindDefOf.Slave);
                if (pawn.guest == null)
                {
                    pawn.guest = new Pawn_GuestTracker(pawn);
                }
                if (pawn.skills == null)
                {
                    pawn.skills = new Pawn_SkillTracker(pawn);
                }
                if (pawn.Faction.HostileTo(s.map.ParentFaction))
                {
                    pawn.equipment.DestroyAllEquipment();
                    pawn.guest.SetGuestStatus(s.map.ParentFaction, GuestStatus.Prisoner);
                }
            }
        }
Example #3
0
        protected override void ScatterAt(IntVec3 pos, Map map, GenStepParams parms, int count)
        {
            var s = new Stencil(map).MoveTo(pos);

            s = s.Bound(s.MinX, 0, s.MaxX, 0)
                .ClearThingsInBounds();

            s.Expand(1)
            .FillTerrain(GenCity.RandomFloor(map), IsValidTile);

            var sandbagStuff = GenCity.RandomStuff(ThingDefOf.Sandbags, map);

            s.MoveWithBounds(0, -2)
            .Border(ThingDefOf.Sandbags, sandbagStuff, mask: IsValidTile);
            s.MoveWithBounds(0, 2)
            .Border(ThingDefOf.Sandbags, sandbagStuff, mask: IsValidTile);

            var sentries = sentryRange.RandomInRange;

            for (var i = 0; i < sentries; i++)
            {
                var point = s.MoveRand().pos + IntVec3.North * 3;
                GenCity.SpawnInhabitant(point, map, new LordJob_DefendBase(map.ParentFaction, point));
            }
        }
        void GenMainRoad(Stencil s, TerrainDef roadTerrain, TerrainDef divTerrain, TerrainDef sidewalkTerrain)
        {
            s.Bound(-3, 0, 3, s.MaxZ)
            .BorderTerrain(sidewalkTerrain, (m, p) => IsValidSidewalkTerrain(p.GetTerrain(m)));
            s.Bound(-2, 0, 2, s.MaxZ)
            .ClearThingsInBounds()
            .FillTerrain(roadTerrain);
            var s1 = s;

            s.Bound(-4, 0, 4, s.MaxZ)
            .BorderTerrain(TerrainUtility.Bridge, (m, p) => p.GetTerrain(m).IsWater);
            s.FillTerrain(0, 0, 0, s.MaxZ, divTerrain);
            s = s.Move(0, roadSpacing.RandomInRange);
            while (s.Expand(-2).IsInBounds())
            {
                if (s.Chance(roadChance))
                {
                    GenSideRoad(s.Left().Move(0, 3), roadTerrain, sidewalkTerrain);
                }

                if (s.Chance(roadChance))
                {
                    GenSideRoad(s.Right().Move(0, 3), roadTerrain, sidewalkTerrain);
                }

                s = s.Move(0, roadSpacing.RandomInRange);
            }
        }
Example #5
0
        public override void Decorate(Stencil s)
        {
            var sBed       = s.Expand(-1);
            var thing      = ThingDefOf.Bed;
            var stuff      = GenCity.RandomStuff(thing, s.map);
            var monitorDef = DefDatabase <ThingDef> .GetNamed("VitalsMonitor");

            var monitor = sBed.Spawn(sBed.RandX, sBed.MaxZ, monitorDef);
            var bed     = (Building_Bed)sBed.Spawn(sBed.RandX, sBed.RandZ, thing, stuff);

            bed.SetFactionDirect(s.map.ParentFaction);
            bed.Medical = true;
        }
Example #6
0
        public override void Decorate(Stencil s)
        {
            var sBed  = s.Expand(-1);
            var thing = bedOptions.RandomElement();
            var stuff = GenCity.RandomStuff(thing, s.map);
            var bed   = (Building_Bed)sBed.Spawn(sBed.RandX, sBed.RandZ, thing, stuff);

            bed.SetFactionDirect(s.map.ParentFaction);
            bed.ForPrisoners = true;
            if (s.Chance(prisonerChance))
            {
                var pawn = GenCity.SpawnInhabitant(s.pos, s.map);
                pawn.guest.SetGuestStatus(s.map.ParentFaction, true);
                bed.TryAssignPawn(pawn);
            }
        }
        public override void GenerateRect(Stencil s)
        {
            GenRooms(s, true);

            var wallStuff = RandomWallStuff(s.map);
            var doorStuff = RandomWallStuff(s.map);
            var hasDoor   = false;

            for (var dir = 0; dir < 4; dir++)
            {
                var sDir = s.Rotate(dir);

                var doorHere = !hasDoor || s.Chance(doorChance);
                if (doorHere)
                {
                    hasDoor = true;
                    var offset = sDir.RandInclusive(0, 2) + 2;
                    var doorZ  = sDir.Chance(.5F) ? sDir.MinZ + offset : sDir.MaxZ - offset;
                    for (var z = sDir.MinZ; z < sDir.MaxZ; z++)
                    {
                        if (z != doorZ)
                        {
                            sDir.Spawn(sDir.MaxX, z, ThingDefOf.Wall, doorStuff);
                        }
                        else
                        {
                            sDir.Move(sDir.MaxX + 1, z).ClearBuildingsAtPos();
                            sDir.Spawn(sDir.MaxX, z, ThingDefOf.Door, wallStuff);
                        }
                    }
                }
                else
                {
                    sDir.Fill(sDir.MaxX, sDir.MinZ, sDir.MaxX, sDir.MaxZ - 1, ThingDefOf.Wall, wallStuff);
                }
            }

            if (buildingDecorators.Count > 0)
            {
                buildingDecorators.RandomElement().Decorate(s);
            }

            // s.FillFog();
            s.Expand(1).BorderTerrain(GenCity.RandomFloor(s.map), IsValidTile);
        }
        public override void Generate(Map map, GenStepParams parms)
        {
            var roadTerrain     = roadTerrains.RandomElement();
            var divTerrain      = divTerrains.RandomElement();
            var sidewalkTerrain = sidewalkTerrains.RandomElement();

            var radius = centerRadius.RandomInRange;

            var s = new Stencil(map);

            s = s.MoveTo(s.Expand(-radius - 2).bounds.RandomCell);

            s.Bound(-radius, -radius, radius, radius)
            .ClearThingsInBounds()
            .FillTerrain(sidewalkTerrains.RandomElement());

            s.FillTerrain(-2, -2, 2, 2, roadTerrain);

            for (var dir = 0; dir < 4; dir++)
            {
                GenMainRoad(s.Rotate(dir).Move(0, 3), roadTerrain, divTerrain, sidewalkTerrain);
            }
        }
        protected override void ScatterAt(IntVec3 pos, Map map, GenStepParams parms, int count)
        {
            var tier = tierRange.RandomInRange;

            pos.z = (int)(map.Size.z * (1 - Rand.Value * mapDensity));  /////////

            var s = new Stencil(map).MoveTo(pos);

            // if (IsValidWallTile(map, s.pos)) {
            //     s.Spawn(ThingDefOf.Door, wallStuff);
            // }
            s = s.Bound(s.MinX, 0, s.MaxX, 0);

            // s.Fill(ThingDefOf.Wall, wallStuff, IsValidWallTile);

            s.Expand(0, -1, 0, -3)
            .ClearThingsInBounds();

            s.MoveWithBounds(0, -3)
            .Fill(ThingDefOf.Barricade, GenCity.RandomStuff(ThingDefOf.Barricade, map), IsValidTile);

            var sentries = sentryRange.RandomInRange;

            for (var i = 0; i < sentries; i++)
            {
                var point = s.MoveRand().pos + IntVec3.South;
                GenCity.SpawnInhabitant(point, map, new LordJob_DefendBase(map.ParentFaction, point));
            }

            if (Config_Cities.Instance.enableMortars)
            {
                var mortars = tierRange.RandomInRange * 1; /**/
                for (var i = 0; i < mortars; i++)
                {
                    var attempts = 10;
                    do
                    {
                        var point   = s.Expand(-2, 0, -2, 0).MoveRand().pos + IntVec3.North * (tier + 2);
                        var sMortar = s.MoveTo(point).ExpandRegion(IsValidEmplacementTile, 25).Center();
                        if (s.Area >= 9)
                        {
                            var mortar = sMortar.ClearThingsInBounds()
                                         .FillTerrain(TerrainDefOf.Concrete)
                                         .Back()
                                         .Spawn(ThingDefOf.Turret_Mortar, GenCity.RandomStuff(ThingDefOf.Turret_Mortar, map));
                            mortar.SetFactionDirect(map.ParentFaction);

                            var ammoPoint = point + IntVec3.North * 2;
                            var ammo      = s.MoveTo(ammoPoint).Spawn(0, 0, ThingDefOf.Shell_HighExplosive);
                            ammo.stackCount = ammoRange.RandomInRange;
                            ammo.SetOwnedByCity(true, s.map);
                            GenCity.SpawnInhabitant(ammoPoint, map, new LordJob_ManTurrets());

                            break;
                        }
                    } while (attempts-- > 0);
                }
            }

            s.Bound(s.MinX, 0, s.MaxX, 0)
            .Expand(3).FillTerrain(TerrainDefOf.Concrete, IsValidTile);

            // s.Bound(s.MinX, 0, s.MaxX, -3)
            //     .FillRoof(RoofDefOf.RoofConstructed, IsValidTile);
        }
        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;
                }
            }
        }