public static GetAdjacentZone ( int zoneAbs, int zoneOrd, Rot4 direction, int &adjacentZoneAbs, int &adjacentZoneOrd ) : void | ||
zoneAbs | int | |
zoneOrd | int | |
direction | Rot4 | |
adjacentZoneAbs | int | |
adjacentZoneOrd | int | |
Résultat | void |
public static bool GetRandomFreeCardinalZoneAdjacentTo(int zoneAbs, int zoneOrd, out Rot4 cardinal, ZoneProperties[,] zoneMap, int horizontalZonesNumber, int verticalZonesNumber) { // Get the free zones. List <Rot4> cardinalList = new List <Rot4>(); for (int cardinalAsInt = 0; cardinalAsInt < 4; cardinalAsInt++) { int testedZoneAbs = 0; int testedZoneOrd = 0; Rot4 testedCardinal = new Rot4(cardinalAsInt); Zone.GetAdjacentZone(zoneAbs, zoneOrd, testedCardinal, out testedZoneAbs, out testedZoneOrd); if (ZoneIsInArea(testedZoneAbs, testedZoneOrd, horizontalZonesNumber, verticalZonesNumber)) { if (zoneMap[testedZoneOrd, testedZoneAbs].zoneType == ZoneType.NotYetGenerated) { cardinalList.Add(testedCardinal); } } } if (cardinalList.Count == 0) { cardinal = Rot4.North; return(false); } else { cardinal = cardinalList.RandomElement <Rot4>(); return(true); } }
static void GenerateOutpostLayoutCommandRoom() { Rot4 commandRoomCardinal; bool freeZoneIsFound = Zone.GetRandomFreeCardinalZoneAdjacentTo(mainRoomZoneAbs, mainRoomZoneOrd, out commandRoomCardinal, zoneMap, horizontalZonesNumber, verticalZonesNumber); if (freeZoneIsFound == false) { Log.Warning("MiningCo. OutpostGenerator: failed to find a free zone for the command room."); return; } int commandRoomZoneAbs = 0; int commandRoomZoneOrd = 0; Zone.GetAdjacentZone(mainRoomZoneAbs, mainRoomZoneOrd, commandRoomCardinal, out commandRoomZoneAbs, out commandRoomZoneOrd); float dropZoneSideSelector = Rand.Value; Rot4 relativeRotation = Rot4.North; Rot4 absoluteRotation = Rot4.North; if (dropZoneSideSelector < 0.5f) { // Drop zone is "on the west" of command room. relativeRotation = Rot4.West; absoluteRotation = new Rot4((commandRoomCardinal.AsInt + relativeRotation.AsInt) % 4); } else { // Drop zone is "on the east" of command room. relativeRotation = Rot4.East; absoluteRotation = new Rot4((commandRoomCardinal.AsInt + relativeRotation.AsInt) % 4); } int dropZoneAbs = 0; int dropZoneOrd = 0; Zone.GetAdjacentZone(commandRoomZoneAbs, commandRoomZoneOrd, absoluteRotation, out dropZoneAbs, out dropZoneOrd); if ((Zone.ZoneIsInArea(dropZoneAbs, dropZoneOrd, horizontalZonesNumber, verticalZonesNumber) == false) || (zoneMap[dropZoneOrd, dropZoneAbs].zoneType != ZoneType.NotYetGenerated)) { // Get the opposite side. relativeRotation = new Rot4((relativeRotation.AsInt + 2) % 4); absoluteRotation = new Rot4((absoluteRotation.AsInt + 2) % 4); Zone.GetAdjacentZone(commandRoomZoneAbs, commandRoomZoneOrd, absoluteRotation, out dropZoneAbs, out dropZoneOrd); if ((Zone.ZoneIsInArea(dropZoneAbs, dropZoneOrd, horizontalZonesNumber, verticalZonesNumber) == false) || (zoneMap[dropZoneOrd, dropZoneAbs].zoneType != ZoneType.NotYetGenerated)) { Log.Warning("MiningCo. OutpostGenerator: failed to find a free zone for the drop zone."); return; } } zoneMap[commandRoomZoneOrd, commandRoomZoneAbs] = new ZoneProperties(ZoneType.SmallRoomCommandRoom, commandRoomCardinal, relativeRotation); relativeRotation.Rotate(RotationDirection.Clockwise); // Rotate 2 times to get the opposite direction. relativeRotation.Rotate(RotationDirection.Clockwise); zoneMap[dropZoneOrd, dropZoneAbs] = new ZoneProperties(ZoneType.DropZone, commandRoomCardinal, relativeRotation); }
static void GenerateOutpostLayoutPowerSupply() { Rot4 batteryRoomCardinal; bool freeZoneIsFound = Zone.GetRandomFreeCardinalZoneAdjacentTo(mainRoomZoneAbs, mainRoomZoneOrd, out batteryRoomCardinal, zoneMap, horizontalZonesNumber, verticalZonesNumber); if (freeZoneIsFound == false) { Log.Warning("MiningCo. OutpostGenerator: failed to find a free zone for the battery room."); return; } int batteryRoomZoneAbs = 0; int batteryRoomZoneOrd = 0; Zone.GetAdjacentZone(mainRoomZoneAbs, mainRoomZoneOrd, batteryRoomCardinal, out batteryRoomZoneAbs, out batteryRoomZoneOrd); float solarPanelZoneSideSelector = Rand.Value; Rot4 relativeRotation = Rot4.North; Rot4 absoluteRotation = Rot4.North; if (solarPanelZoneSideSelector < 0.5f) { // Solar zone is "on the west" of battery room. relativeRotation = Rot4.West; absoluteRotation = new Rot4((batteryRoomCardinal.AsInt + relativeRotation.AsInt) % 4); } else { // Solar zone is "on the east" of battery room. relativeRotation = Rot4.East; absoluteRotation = new Rot4((batteryRoomCardinal.AsInt + relativeRotation.AsInt) % 4); } int solarPanelZoneAbs = 0; int solarPanelZoneOrd = 0; Zone.GetAdjacentZone(batteryRoomZoneAbs, batteryRoomZoneOrd, absoluteRotation, out solarPanelZoneAbs, out solarPanelZoneOrd); if ((Zone.ZoneIsInArea(solarPanelZoneAbs, solarPanelZoneOrd, horizontalZonesNumber, verticalZonesNumber) == false) || (zoneMap[solarPanelZoneOrd, solarPanelZoneAbs].zoneType != ZoneType.NotYetGenerated)) { // Get the opposite side. relativeRotation = new Rot4((relativeRotation.AsInt + 2) % 4); absoluteRotation = new Rot4((absoluteRotation.AsInt + 2) % 4); Zone.GetAdjacentZone(batteryRoomZoneAbs, batteryRoomZoneOrd, absoluteRotation, out solarPanelZoneAbs, out solarPanelZoneOrd); if ((Zone.ZoneIsInArea(solarPanelZoneAbs, solarPanelZoneOrd, horizontalZonesNumber, verticalZonesNumber) == false) || (zoneMap[solarPanelZoneOrd, solarPanelZoneAbs].zoneType != ZoneType.NotYetGenerated)) { Log.Warning("MiningCo. OutpostGenerator: failed to find a free zone for the solar panels."); return; } } zoneMap[batteryRoomZoneOrd, batteryRoomZoneAbs] = new ZoneProperties(ZoneType.SmallRoomBatteryRoom, batteryRoomCardinal, relativeRotation); relativeRotation.Rotate(RotationDirection.Clockwise); // Rotate 2 times to get the opposite direction. relativeRotation.Rotate(RotationDirection.Clockwise); zoneMap[solarPanelZoneOrd, solarPanelZoneAbs] = new ZoneProperties(ZoneType.SolarPanelZone, batteryRoomCardinal, relativeRotation); }
static void GenerateOutpostLayoutSecondaryRooms() { for (int rotationAsInt = 0; rotationAsInt < 4; rotationAsInt++) { int zoneAbs = 0; int zoneOrd = 0; Rot4 rotation = new Rot4(rotationAsInt); Zone.GetAdjacentZone(mainRoomZoneAbs, mainRoomZoneOrd, rotation, out zoneAbs, out zoneOrd); if (zoneMap[zoneOrd, zoneAbs].zoneType == ZoneType.NotYetGenerated) { ZoneType secondaryRoomType = OG_Common.GetRandomZoneTypeSmallRoom(outpostData); zoneMap[zoneOrd, zoneAbs] = new ZoneProperties(secondaryRoomType, rotation, Rot4.North); } } }
public static void GenerateBigRoomBatteryRoom(IntVec3 areaSouthWestOrigin, int zoneAbs, int zoneOrd, Rot4 rotation, ZoneProperties[,] zoneMap, ref OG_OutpostData outpostData) { IntVec3 origin = Zone.GetZoneOrigin(areaSouthWestOrigin, zoneAbs, zoneOrd); IntVec3 rotatedOrigin = Zone.GetZoneRotatedOrigin(areaSouthWestOrigin, zoneAbs, zoneOrd, rotation); OG_Common.GenerateEmptyRoomAt(rotatedOrigin, Genstep_GenerateOutpost.zoneSideSize, Genstep_GenerateOutpost.zoneSideSize, rotation, TerrainDefOf.Concrete, TerrainDef.Named("MetalTile"), ref outpostData); // Spawn doors. OG_Common.SpawnDoorAt(rotatedOrigin + new IntVec3(5, 0, 10).RotatedBy(rotation), ref outpostData); OG_Common.SpawnDoorAt(rotatedOrigin + new IntVec3(10, 0, 5).RotatedBy(rotation), ref outpostData); OG_Common.SpawnDoorAt(rotatedOrigin + new IntVec3(5, 0, 0).RotatedBy(rotation), ref outpostData); OG_Common.SpawnDoorAt(rotatedOrigin + new IntVec3(0, 0, 5).RotatedBy(rotation), ref outpostData); // Spawn generators. OG_Common.TrySpawnThingAt(OG_Util.CompactAutonomousGeneratorDef, null, rotatedOrigin + new IntVec3(1, 0, 1).RotatedBy(rotation), true, new Rot4(Rot4.North.AsInt + rotation.AsInt), ref outpostData); OG_Common.TrySpawnThingAt(OG_Util.CompactAutonomousGeneratorDef, null, rotatedOrigin + new IntVec3(1, 0, 8).RotatedBy(rotation), true, new Rot4(Rot4.North.AsInt + rotation.AsInt), ref outpostData); OG_Common.TrySpawnThingAt(OG_Util.CompactAutonomousGeneratorDef, null, rotatedOrigin + new IntVec3(8, 0, 8).RotatedBy(rotation), true, new Rot4(Rot4.North.AsInt + rotation.AsInt), ref outpostData); // Spawn batteries. OG_Common.TrySpawnThingAt(ThingDefOf.Battery, null, rotatedOrigin + new IntVec3(1, 0, 3).RotatedBy(rotation), true, new Rot4(Rot4.North.AsInt + rotation.AsInt), ref outpostData); OG_Common.TrySpawnThingAt(ThingDefOf.Battery, null, rotatedOrigin + new IntVec3(3, 0, 1).RotatedBy(rotation), true, new Rot4(Rot4.East.AsInt + rotation.AsInt), ref outpostData); OG_Common.TrySpawnThingAt(ThingDefOf.Battery, null, rotatedOrigin + new IntVec3(1, 0, 7).RotatedBy(rotation), true, new Rot4(Rot4.South.AsInt + rotation.AsInt), ref outpostData); OG_Common.TrySpawnThingAt(ThingDefOf.Battery, null, rotatedOrigin + new IntVec3(3, 0, 9).RotatedBy(rotation), true, new Rot4(Rot4.East.AsInt + rotation.AsInt), ref outpostData); OG_Common.TrySpawnThingAt(ThingDefOf.Battery, null, rotatedOrigin + new IntVec3(9, 0, 7).RotatedBy(rotation), true, new Rot4(Rot4.South.AsInt + rotation.AsInt), ref outpostData); OG_Common.TrySpawnThingAt(ThingDefOf.Battery, null, rotatedOrigin + new IntVec3(7, 0, 9).RotatedBy(rotation), true, new Rot4(Rot4.West.AsInt + rotation.AsInt), ref outpostData); // Spawn power controller. OG_Common.TrySpawnThingAt(ThingDef.Named("MultiAnalyzer"), null, rotatedOrigin + new IntVec3(7, 0, 2).RotatedBy(rotation), true, new Rot4(Rot4.North.AsInt + rotation.AsInt), ref outpostData); // Spawn lamp and vents. OG_Common.TrySpawnLampAt(rotatedOrigin + new IntVec3(3, 0, 7).RotatedBy(rotation), Color.blue, ref outpostData); for (int cardinalAsInt = 0; cardinalAsInt < 4; cardinalAsInt++) { Rot4 cardinal = new Rot4(cardinalAsInt); int adjacentZoneAbs = 0; int adjacentZoneOrd = 0; Zone.GetAdjacentZone(zoneAbs, zoneOrd, cardinal, out adjacentZoneAbs, out adjacentZoneOrd); if (zoneMap[adjacentZoneOrd, adjacentZoneAbs].zoneType == ZoneType.SolarPanelZone) { if (cardinal == Rot4.North) { OG_Common.SpawnVentAt(origin + new IntVec3(4, 0, 10), Rot4.North, ref outpostData); OG_Common.SpawnVentAt(origin + new IntVec3(6, 0, 10), Rot4.North, ref outpostData); } else if (cardinal == Rot4.East) { OG_Common.SpawnVentAt(origin + new IntVec3(10, 0, 4), Rot4.East, ref outpostData); OG_Common.SpawnVentAt(origin + new IntVec3(10, 0, 6), Rot4.East, ref outpostData); } else if (cardinal == Rot4.South) { OG_Common.SpawnVentAt(origin + new IntVec3(4, 0, 0), Rot4.South, ref outpostData); OG_Common.SpawnVentAt(origin + new IntVec3(6, 0, 0), Rot4.West, ref outpostData); } else if (cardinal == Rot4.West) { OG_Common.SpawnVentAt(origin + new IntVec3(0, 0, 4), Rot4.West, ref outpostData); OG_Common.SpawnVentAt(origin + new IntVec3(0, 0, 6), Rot4.West, ref outpostData); } } } OG_Common.GenerateHorizontalAndVerticalPavedAlleys(origin); }