Ejemplo n.º 1
0
        public override void Decorate(Stencil s)
        {
            s.Bound(s.RandInclusive(s.MinX, s.MinX / 2) - 1, s.RandInclusive(s.MinZ, s.MinZ / 2) - 1, s.RandInclusive(s.MaxX / 2, s.MaxX) + 1, s.RandInclusive(s.MaxZ / 2, s.MaxZ) + 1)
            .FillTerrain(GenCity.RandomFloor(s.map, true));

            var def   = options.RandomElement();
            var thing = s.Spawn(def, GenCity.RandomStuff(def, s.map));

            if (chairDensity > 0)
            {
                var chairDef   = chairOptions.RandomElement();
                var chairStuff = GenCity.RandomStuff(chairDef, s.map);
                var sThing     = s.BoundTo(thing.OccupiedRect());
                for (var dir = 0; dir < 4; dir++)
                {
                    var sDir = sThing.Rotate(dir);
                    for (var x = sDir.MinX; x <= sDir.MaxX; x++)
                    {
                        if (s.Chance(chairDensity))
                        {
                            SpawnChair(sDir.Move(x, sDir.MinZ - 1), chairDef, chairStuff);
                        }
                    }
                }
            }
            else if (thing.def.hasInteractionCell && chairOptions.Count > 0)
            {
                var chairDef   = chairOptions.RandomElement();
                var chairStuff = GenCity.RandomStuff(chairDef, s.map);
                SpawnChair(s.MoveTo(thing.InteractionCell), chairDef, chairStuff);
            }
        }
Ejemplo 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());
                }
            }
Ejemplo n.º 3
0
        public override void Decorate(Stencil s)
        {
            var stuff    = GenCity.RandomStuff(ThingDefOf.Bed, s.map);
            var sDresser = s.Rotate(s.RandInclusive(0, 1) * 2);

            sDresser.Spawn(s.RandInclusive(sDresser.MinX + 1, sDresser.MaxX - 1), sDresser.MinZ + 1, DefDatabase <ThingDef> .GetNamed("Dresser"), stuff);
            var bedX = s.RandX;

            s.Spawn(bedX, s.MinZ, DefDatabase <ThingDef> .GetNamed("EndTable"), stuff);
            var bed = (Building_Bed)s.Spawn(bedX, s.MinZ + 1, ThingDefOf.Bed, stuff);

            bed.SetFactionDirect(s.map.ParentFaction);
            var pawn = GenCity.SpawnInhabitant(s.Chance(pawnInBedroomChance) ? s.pos : s.MapBounds.RandomCell, s.map, null, randomWorkSpot: true);

            bed.CompAssignableToPawn.TryAssignPawn(pawn);
        }
Ejemplo n.º 4
0
        protected override void ScatterAt(IntVec3 pos, Map map, GenStepParams parms, int count)
        {
            var width  = size.RandomInRange;
            var height = size.RandomInRange;
            var s      = new Stencil(map);
            var x      = s.RandInclusive(s.MinX, s.MaxX - width);
            var z      = s.RandInclusive(s.MinZ, s.MaxZ - height);
            var sX     = s.Bound(x, s.MinZ, x + width, s.MaxZ);
            var sZ     = s.Bound(s.MinX, z, s.MaxX, z + height);

            foreach (var cell in sX.bounds.Cells.Concat(sZ.bounds.Cells))
            {
                if (cell.GetTerrain(s.map).affordances.Contains(TerrainUtility.Bridgeable))
                {
                    s.map.terrainGrid.SetTerrain(cell, TerrainUtility.Bridge);
                }
            }
        }
        public override void Decorate(Stencil s)
        {
            var generators = stockGenerators.Count > 0
                ? stockGenerators
                : (traderKinds.RandomElementWithFallback()
                   ?? DefDatabase <TraderKindDef> .AllDefs.Where(t => t.stockGenerators.Count > 0).RandomElement()).stockGenerators;

            // var friendly = !s.map.ParentFaction.HostileTo(Faction.OfPlayer);
            foreach (var pos in s.bounds.Cells)
            {
                if (s.Chance(density * Config_Cities.Instance.lootScale))
                {
                    var thing = generators.RandomElement().GenerateThings(s.map.Tile).FirstOrDefault();
                    if (thing != null)
                    {
                        if (thing.stackCount > thing.def.stackLimit)
                        {
                            thing.stackCount = s.RandInclusive(1, thing.def.stackLimit);
                        }
                        thing = thing.TryMakeMinified();
                        GenSpawn.Spawn(thing, pos, s.map);
                        if (thing is Pawn pawn && pawn.Faction != null)
                        {
                            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.guest.SetGuestStatus(s.map.ParentFaction, GuestStatus.Prisoner);
                            }
                        }
                        else
                        {
                            thing.SetOwnedByCity(true, s.map);
                        }
                    }
                }
            }
Ejemplo n.º 6
0
        public override void Decorate(Stencil s)
        {
            var generators = stockGenerators.Count > 0 ? stockGenerators :
                             (traderKinds.RandomElementWithFallback()
                              ?? DefDatabase <TraderKindDef> .AllDefs.Where(t => t.stockGenerators.Count > 0).RandomElement()).stockGenerators;

            var friendly = !s.map.ParentFaction.HostileTo(Faction.OfPlayer);

            foreach (IntVec3 pos in s.bounds.Cells)
            {
                if (s.Chance(density))
                {
                    var thing = generators.RandomElement().GenerateThings(s.map.Tile).FirstOrDefault();
                    if (thing != null)
                    {
                        if (thing.stackCount > thing.def.stackLimit)
                        {
                            thing.stackCount = s.RandInclusive(1, thing.def.stackLimit);
                        }
                        GenSpawn.Spawn(thing, pos, s.map);
                        if (thing is Pawn pawn)
                        {
                            if (pawn.guest == null)
                            {
                                pawn.guest = new Pawn_GuestTracker(pawn);
                            }
                            pawn.guest.SetGuestStatus(s.map.ParentFaction, true);
                        }
                        else
                        {
                            thing.SetOwnedByCity(true);
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
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;
                }
            }
        }
Ejemplo n.º 8
0
        public override void GenerateRect(Stencil s)
        {
            s.FillTerrain(GenCity.RandomFloor(s.map));
            var pawn = (Pawn)null;

            if (!s.map.ParentFaction.HostileTo(Faction.OfPlayer))
            {
                pawn = GenCity.SpawnInhabitant(s.Coords(s.RandX / 2, s.RandZ / 2), s.map);
                var traderKind = DefDatabase <TraderKindDef> .AllDefs.RandomElement();

                pawn.mindState.wantsToTradeWithColony = true;
                PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
                pawn.trader.traderKind = traderKind;
                pawn.inventory.DestroyAll();
                var parms = new ThingSetMakerParams {
                    traderDef     = traderKind,
                    tile          = s.map.Tile,
                    makingFaction = s.map.ParentFaction,
                };
                foreach (var item in ThingSetMakerDefOf.TraderStock.root.Generate(parms))
                {
                    if (!(item is Pawn) && !pawn.inventory.innerContainer.TryAdd(item))
                    {
                        item.Destroy();
                    }
                }

                PawnInventoryGenerator.GiveRandomFood(pawn);
            }

            for (var dir = 0; dir < 4; dir++)
            {
                if (s.Chance(standChance))
                {
                    var sStand = s.Rotate(dir).Move(Mathf.RoundToInt(s.RandX / 2F), s.MaxZ - s.RandInclusive(0, 2)).Bound(-1, 0, 1, 0);
                    sStand.FillTerrain(GenCity.RandomFloor(s.map, true));
                    var wallStuff = GenCity.RandomWallStuff(s.map);
                    sStand.Spawn(sStand.MinX - 1, 0, ThingDefOf.Wall, wallStuff);
                    sStand.Spawn(sStand.MaxX + 1, 0, ThingDefOf.Wall, wallStuff);
                    sStand.Expand(1).FillRoof(RoofDefOf.RoofConstructed);
                    // if (pawn != null) {
                    //     var itemPos = sStand.Coords(sStand.RandX, sStand.RandZ);
                    //     var item = pawn.inventory.innerContainer.FirstOrDefault();
                    //     if (item != null) {
                    //         pawn.inventory.innerContainer.TryDrop(item, itemPos, s.map, ThingPlaceMode.Direct, out var result);
                    //         item.SetOwnedByCity(true, s.map);
                    //     }
                    // }
                }
            }
        }