Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public string BasePath = @"C:\Users\reiv3_000\AppData\Roaming\SpaceEngineers\Saves\76561197993733345\Dark Horizons";
- public string BaseFileName = "Sandbox_Base.sbs";
- void Main()
- {
- var sectorCount = 27;
- var sectorSize = 16000;
- var subSectorCount = 4;
- var maxMapSize = new Vector3(50000, 50000, 50000);
- var beacons = new List<Beacon>();
- XNamespace ns = "http://www.w3.org/2001/XMLSchema-instance";
- var doc = XDocument.Load(Path.Combine(BasePath, BaseFileName));
- var sectorObjects = doc
- .Root
- //.Element("MyObjectBuilder_Sector");
- .Element("SectorObjects");
- var beaconObject = sectorObjects
- .Elements("MyObjectBuilder_EntityBase")
- .Where(node => node.Attribute(ns + "type").Value.Equals("MyObjectBuilder_CubeGrid"))
- .First();
- //beaconObject.Dump();
- var max = new Vector3(maxMapSize.X / 2, maxMapSize.Y / 2, maxMapSize.Z / 2);
- var offset = new Vector3(maxMapSize.X % sectorSize / 2, maxMapSize.Y % sectorSize / 2, maxMapSize.Z % sectorSize / 2);
- var random = new Random();
- for(var x = maxMapSize.X / 2f * -1f + offset.X;x + sectorSize < max.X;x += sectorSize) {
- for(var y = maxMapSize.Y / 2f * -1f + offset.Y;y + sectorSize < max.Y;y += sectorSize) {
- for(var z = maxMapSize.Z / 2f * -1f + offset.Z;z + sectorSize < max.Z;z += sectorSize) {
- var subSectors = new List<Beacon>();
- var beaconsThisSector = random.Next(subSectorCount / 2, subSectorCount);
- var sectorName = "ShitBaskets";
- while(subSectors.Count < beaconsThisSector) {
- var beacon = new Vector3((float)Math.Round((random.NextDouble() * sectorSize + x), 0),
- (float)Math.Round((random.NextDouble() * sectorSize) + y, 0),
- (float)Math.Round((random.NextDouble() * sectorSize) + z, 0));
- if(subSectors.Count == 0
- || subSectors.Any(b => beacon.DistanceFrom(b.Position.X, b.Position.Y, b.Position.Z) < 10000
- && beacon.DistanceFrom(b.Position.X, b.Position.Y, b.Position.Z) > 5000)) {
- subSectors.Add(new Beacon(beacon, sectorName + " - " + subSectors.Count));
- }
- }
- beacons.AddRange(subSectors);
- }
- }
- }
- // Create the new save
- foreach(var beacon in beacons) {
- var position = beaconObject.Element("PositionAndOrientation").Element("Position");
- position.Attribute("x").Value = beacon.Position.X.ToString();
- position.Attribute("y").Value = beacon.Position.Y.ToString();
- position.Attribute("z").Value = beacon.Position.Z.ToString();
- beaconObject.Element("EntityId").Value = random.Next(int.MaxValue).ToString();
- foreach(var entityId in beaconObject.Element("CubeBlocks").Elements("MyObjectBuilder_CubeBlock").Select(element => element.Element("EntityId"))) {
- if(entityId != null)
- entityId.Value = random.Next(int.MaxValue).ToString();
- }
- beaconObject.Element("CubeBlocks")
- .Elements("MyObjectBuilder_CubeBlock")
- .Where(element => element.Attribute(ns + "type").Value.Equals("MyObjectBuilder_Beacon"))
- .First()
- .SetElementValue("CustomName", beacon.Name);
- sectorObjects.Add(beaconObject);
- string.Format("Beacon Created: ({0},{1},{2})", beacon.Position.X, beacon.Position.Y, beacon.Position.Z).Dump();
- }
- doc.Save(Path.Combine(BasePath, "Sandbox_0_0_0_New.sbs"));
- }
- // Define other methods and classes here
- public struct Vector3 {
- public float X;
- public float Y;
- public float Z;
- public Vector3(float x, float y, float z) {
- X = x;
- Y = y;
- Z = z;
- }
- public Vector3(int x, int y, int z) {
- X = (float)x;
- Y = (float)y;
- Z = (float)z;
- }
- public float DistanceFrom(float x, float y, float z) {
- return (float)Math.Sqrt(Math.Pow((x - X), 2f) + Math.Pow((y - Y), 2f) + Math.Pow((z - Z), 2f));
- }
- }
- public class Beacon {
- public string Name;
- public Vector3 Position;
- public string Sector;
- public Beacon(Vector3 position, string name) {
- Name = name;
- Position = position;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement