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); } }
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)); } }
public override void Decorate(Stencil s) { var floorStuff = GenCity.RandomFloor(s.map); var columnStuff = GenCity.RandomStuff(ThingDefOf.Column, s.map); var distance = distanceRange.RandomInRange; for (var dir = 0; dir < 4; dir++) { var sDir = s.Rotate(dir); sDir = sDir.Bound(sDir.MinX, sDir.MaxZ + 1, sDir.MaxX, sDir.MaxZ + distance); if (dir % 2 == 0) { sDir = sDir.Expand(distance, 0, distance, 0); } var spacing = columnSpacingRange.RandomInRange; for (var x = sDir.MinX + Rand.Range(0, spacing); x <= sDir.MaxX; x += spacing) { var sCol = sDir.Move(x, sDir.MaxZ); if (sCol.IsInMap() && IsValidTile(s.map, sCol.pos)) { sCol.Spawn(ThingDefOf.Column, columnStuff); } } sDir.FillRoof(RoofDefOf.RoofConstructed) .FillTerrain(floorStuff, IsValidTile); } }
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); } } }
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); } }
protected override void ScatterAt(IntVec3 pos, Map map, GenStepParams parms, int count) { var terrain = sidewalkTerrains.RandomElement(); var s = new Stencil(map).MoveTo(pos).RotateRand(); if (IsValidTile(map, s.pos)) { s.SetTerrain(terrain); } var s1 = s.Move(0, 1); while (s1.Check(s1.pos, IsValidTile)) { s1.SetTerrain(terrain); s1 = s1.Move(0, 1); } var s2 = s.Move(0, -1); while (s2.Check(s2.pos, IsValidTile)) { s2.SetTerrain(terrain); s2 = s2.Move(0, -1); } }
private void SpawnChair(Stencil s, ThingDef thing, ThingDef stuff) { s.Spawn(thing, stuff); if (s.Chance(chairPawnChance)) { GenCity.SpawnInhabitant(s.pos, s.map); } }
void GenSideRoad(Stencil s, TerrainDef roadTerrain, TerrainDef sidewalkTerrain) { s.Bound(-2, 0, 2, s.MaxZ) .BorderTerrain(sidewalkTerrain, (m, p) => IsValidSidewalkTerrain(p.GetTerrain(m))); s.Bound(-1, 0, 1, s.MaxZ) .ClearThingsInBounds() .FillTerrain(roadTerrain); s.Bound(-3, 0, 3, s.MaxZ) .BorderTerrain(TerrainUtility.Bridge, (m, p) => p.GetTerrain(m).IsWater); }
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 }
void SpawnChair(Stencil s, ThingDef thing, ThingDef stuff) { if (s.Check(IsValidChairTile)) { s.Spawn(thing, stuff); } if (s.Chance(chairPawnChance) && s.IsInMap()) { GenCity.SpawnInhabitant(s.pos, s.map); } }
public override void Decorate(Stencil s) { base.Decorate(s); var sVent = s.RotateRand().Move(0, s.MaxZ - 1).Bound(-1, -1, 1, 1); sVent.Border(ThingDefOf.Wall, GenCity.RandomWallStuff(s.map)); sVent.Bound(0, 0, 0, 0).ClearRoof(); var tempControl = sVent.Spawn(0, -1, ThingDefOf.Cooler).TryGetComp <CompTempControl>(); tempControl.targetTemperature = -1; }
public override void Decorate(Stencil s) { Stencil.Mask mask = p => TerrainUtility.IsNatural(p.GetTerrain(s.map)); for (var dir = 0; dir < 4; dir++) { var sDir = s.Rotate(dir); sDir.Bound(sDir.MinX - distance, sDir.MaxZ + distance, sDir.MinX / 2, sDir.MaxZ + distance) .Fill(ThingDefOf.Sandbags, mask: mask); sDir.Bound(sDir.MaxX / 2, sDir.MaxZ + distance, sDir.MaxX + distance, sDir.MaxZ + distance) .Fill(ThingDefOf.Sandbags, mask: mask); } }
protected override void ScatterAt(IntVec3 pos, Map map, GenStepParams parms, int count) { var s = new Stencil(map); s = s.BoundTo(CellRect.FromLimits(pos, s.bounds.RandomCell)); var stuff = GenCity.RandomWallStuff(map); for (var dir = 0; dir < 4; dir++) { var sDir = s.Rotate(dir); sDir.Fill(sDir.MinX, sDir.MaxZ, sDir.MaxX, sDir.MaxZ, ThingDefOf.Wall, stuff, IsValidTile); } }
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; }
public override void Decorate(Stencil s) { var charge = this.charge.RandomInRange; for (int x = s.MinX + 1; x <= s.MaxX - 1; x++) { var batteryComp = s.Spawn(x, 0, ThingDefOf.Battery).TryGetComp <CompPowerBattery>(); if (batteryComp != null) { batteryComp.SetStoredEnergyPct(charge); } } }
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); // } // } } } }
public override void GenerateRect(Stencil s) { var plant = DefDatabase <ThingDef> .AllDefs .Where(t => t.category == ThingCategory.Plant && t.altitudeLayer == altitudeLayer && !t.plant.cavePlant && t != ThingDefOf.Plant_TreeAnima) .RandomElement(); foreach (var pos in s.bounds.Cells) { if (s.Chance(density) && pos.GetFirstThing <Thing>(s.map) == null) { GenSpawn.Spawn(plant, pos, s.map); } } }
public override void Decorate(Stencil s) { var thing = Rand.Chance(barricadeChance) ? ThingDefOf.Barricade : ThingDefOf.Sandbags; var stuff = GenCity.RandomStuff(thing, s.map); for (var dir = 0; dir < 4; dir++) { var sDir = s.Rotate(dir); sDir.Bound(sDir.MinX - distance, sDir.MaxZ + distance, sDir.MinX / 2, sDir.MaxZ + distance) .Fill(thing, stuff, mask: IsValidTile); sDir.Bound(sDir.MaxX / 2, sDir.MaxZ + distance, sDir.MaxX + distance, sDir.MaxZ + distance) .Fill(thing, stuff, mask: IsValidTile); } }
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 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); }
public static IntVec3 FindDropSpot(Map map, int dropArea = 10) { var attempts = 20; Stencil s; do { s = new Stencil(map).MoveRand() .ExpandRegion(p => p.GetFirstThing <Thing>(map) == null, dropArea) .Center(); if (s.Area >= dropArea) { break; } }while(--attempts >= 0); return(s.pos); }
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); }
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 GenerateRect(Stencil s) { var stuff = GenCity.RandomStuff(ThingDefOf.Sandbags, s.map); for (var dir = 0; dir < 4; dir++) { var sDir = s.Rotate(dir); for (var x = sDir.MinX; x <= sDir.MaxX; x++) { if (x <= sDir.MinX / 2 || x >= sDir.MaxX / 2) { sDir.Spawn(x, sDir.MaxZ, ThingDefOf.Sandbags, stuff); } } } options.Where(opt => !opt.selfDestructive || s.map.ParentFaction.def.permanentEnemy || s.map.Parent is Citadel) .RandomElementByWeight(opt => opt.weight).Generate(s); }
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); } } } }
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); var spacing = spacingRange.RandomInRange; for (var i = s.MinX + spacingRange.RandomInRange; i <= s.MaxX; i += spacing) { var point = s.MoveRand().pos + IntVec3.North * 3; if (IsValidTile(map, point)) { var trap = s.MoveTo(point) .Spawn(jitterRange.RandomInRange * Rand.Sign, jitterRange.RandomInRange * Rand.Sign, DefDatabase <ThingDef> .GetNamed("TrapIED_HighExplosive")); trap.SetFactionDirect(map.ParentFaction); } } }
Stencil?GetStencil(Map map, IntVec3 pos) { if (cachedPos != null && pos == cachedPos) { return(cachedStencil); } cachedPos = pos; var s = new Stencil(map) .MoveTo(pos) .ExpandRegion(IsValidTile, areaConstraints.max); var ratio = (float)s.Width / s.Height; if (s.Area < areaConstraints.min || ratio > maxRatio || 1 / ratio > maxRatio) { return(cachedStencil = null); } return(cachedStencil = s); }
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); } }
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); } } } } }
public abstract void Decorate(Stencil s);