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); } }
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 }
protected override void ScatterAt(IntVec3 pos, Map map, GenStepParams parms, int count) { var height = heightRange.RandomInRange; var spacing = spacingRange.RandomInRange; var s = new Stencil(map).MoveTo(pos); s = s.Bound(s.MinX, 0, s.MaxX, height) // .Border(ThingDefOf.Wall, GenCity.RandomWallStuff(map)) .FillRoof(RoofDefOf.RoofConstructed); // s.Expand(1) // .FillTerrain(GenCity.RandomFloor(map), IsValidTile); for (var i = s.MinX + spacingRange.RandomInRange; i <= s.MaxX; i += spacing) { for (var j = s.MinZ + spacingRange.RandomInRange; j <= s.MaxZ; j += spacing) { var point = s.pos + new IntVec3(i, 0, j); if (IsValidTile(map, point)) { s.MoveTo(point) .Spawn(ThingDefOf.Column, GenCity.RandomStuff(ThingDefOf.Column, map)); } } } }
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)); } }
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); } } }
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); } } }
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; } } }