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); } }
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 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 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); } }
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; } } }