public static MarbleMove Load(string line) { int from = 0; int passing = 0; int to = 0; CelestialBodyType type = 0; line = line.Substring(line.IndexOf(':') + 1); while (line.Length > 0) { if (line.StartsWith(" From ")) { int.TryParse(Utils.ReadSaveFileLineSegment(line), out from); } else if (line.StartsWith(" Passing ")) { int.TryParse(Utils.ReadSaveFileLineSegment(line), out passing); } else if (line.StartsWith(" To ")) { int.TryParse(Utils.ReadSaveFileLineSegment(line), out to); } else if (line.StartsWith(" Marble ")) { Enum.TryParse(Utils.ReadSaveFileLineSegment(line), out type); } //else if (line.StartsWith(" Light ")) // int.TryParse(ReadSaveFileLineSegment(line), out move.PassOverMarbleStarIndex); line = line.Substring(line.IndexOf(';') + 1); } return(new MarbleMove(from, passing, to, type)); }
private void LoadMap() { byte[] bytes = System.IO.File.ReadAllBytes("MapInfo.dat"); CelestialBodyType type = (CelestialBodyType)System.BitConverter.ToInt32(bytes, 4); if (type == CelestialBodyType.Universe) { Map = new CelestialBodies.Universe(bytes, 0); } else if (type == CelestialBodyType.Expanse) { Map = new CelestialBodies.Expanse(bytes, 0); } else if (type == CelestialBodyType.Galaxy) { Map = new CelestialBodies.Galaxy(bytes, 0); } else if (type == CelestialBodyType.Sector) { Map = new CelestialBodies.Sector(bytes, 0); } else { Map = new CelestialBodies.SolarSystem(bytes, 0); } int offset = System.BitConverter.ToInt32(bytes, 0); Network = new Network(bytes, offset, Map); }
private string NameOfType(CelestialBodyType type) { switch (type) { case (CelestialBodyType.Universe): return("Universe"); case (CelestialBodyType.Expanse): return("Expanse"); case (CelestialBodyType.Galaxy): return("Galaxy"); case (CelestialBodyType.Sector): return("Sector"); case (CelestialBodyType.SolarSystem): return("SolarSystem"); case (CelestialBodyType.Star): return("Star"); case (CelestialBodyType.Planet): return("Planet"); default: return("Unknown"); } }
public static void SetDrawProperties(int shaderID, CelestialBodyType celestialBody, float defaultSpecularPower = -1f) { CelestialBody body = CelestialBodies[celestialBody]; if (body.TextureMap != null) { body.TextureMap.Bind(); } if (body.SpecularMap != null) { Game.SetSpecularMapEnabled(shaderID, true); body.SpecularMap.Bind(); } else { Game.SetSpecularMapEnabled(shaderID, false); } if (body.SpecularPower >= 0f) { //MaterialProperties.SetSpecular(shaderID, new Vector3(body.SpecularReflectivity)); MaterialProperties.SetShininess(shaderID, body.SpecularPower); } else { MaterialProperties.SetShininess(shaderID, defaultSpecularPower); } }
private CelestialBody GetCelestialBody(TableRow tableRow) { var name = tableRow["name"]; double radius = double.Parse(tableRow["radius"]); double orbitDistance = double.Parse(tableRow["orbitDistance"]); double orbitalAngularVelocity = double.Parse(tableRow["orbitalAngularVelocity"]); double rotatationalAngularVelocity = double.Parse(tableRow["rotatationalAngularVelocity"]); double initialOrbitalAngularPositionOffset = double.Parse(tableRow["initialOrbitalAngularPositionOffset"]); double currentAngularPosition = double.Parse(tableRow["currentAngularPosition"]); var material = _state.Materials[tableRow["material"]]; CelestialBodyType bodyType = (CelestialBodyType)Enum.Parse(typeof(CelestialBodyType), tableRow["bodyType"]); var moonString = tableRow["satellites"]; var strings = ExtractStringsFromCsv(moonString); CelestialBody[] satellites = null; if (!(strings.Length == 1 && string.IsNullOrWhiteSpace(strings[0]))) { foreach (var s in strings) { Assert.Contains(s, _state.CelestialBodies.Keys); } satellites = strings.Select(i => _state.CelestialBodies[i]).ToArray(); } var celestialBody = new CelestialBody(name, radius, orbitDistance, orbitalAngularVelocity, rotatationalAngularVelocity, initialOrbitalAngularPositionOffset, currentAngularPosition, material, bodyType, satellites); return(celestialBody); }
/// <summary> /// Deserialization Constructor /// </summary> /// <param name="bytes"></param> /// <param name="startIndex"></param> protected CelestialBody(byte[] bytes, int startIndex) { int offset = 4; Type = (CelestialBodyType)BitConverter.ToInt32(bytes, startIndex + offset); offset += 4; ID = new CelestialBodyIdentifier(bytes, startIndex + offset); offset += BitConverter.ToInt32(bytes, startIndex + offset); float x = BitConverter.ToSingle(bytes, startIndex + offset); offset += 4; float y = BitConverter.ToSingle(bytes, startIndex + offset); offset += 4; Position = new Vector2(x, y); Radius = BitConverter.ToSingle(bytes, startIndex + offset); offset += 4; Expanses = DeserializeExpanses(bytes, startIndex + offset); offset += BitConverter.ToInt32(bytes, startIndex + offset); Galaxies = DeserializeGalaxies(bytes, startIndex + offset); offset += BitConverter.ToInt32(bytes, startIndex + offset); Sectors = DeserializeSectors(bytes, startIndex + offset); offset += BitConverter.ToInt32(bytes, startIndex + offset); SolarSystems = DeserializeSolarSystems(bytes, startIndex + offset); offset += BitConverter.ToInt32(bytes, startIndex + offset); Stars = DeserializeStars(bytes, startIndex + offset); offset += BitConverter.ToInt32(bytes, startIndex + offset); Planets = DeserializePlanets(bytes, startIndex + offset); }
public MarbleMove(int fromSlot, int passOverSlot, int toSlot, CelestialBodyType passOverMarble) { FromSlot = fromSlot; PassOverSlot = passOverSlot; ToSlot = toSlot; PassOverMarble = passOverMarble; }
/// <summary> /// /// </summary> /// <param name="mapSize"></param> /// <param name="seed"></param> /// <param name="maxThreads">Minimum of 2 threads required</param> /// <param name="callback"></param> public GenerateMap(CelestialBodyType mapSize, int seed, int maxThreads, Callback callback) { MapSize = mapSize; MapSeed = seed; FinishedCallback = callback; maxThreads = Mathf.Max(2, maxThreads); ThreadManager.Initialize(maxThreads - 1); ProgressTracker.Initialize(); }
public Container(CelestialBodyType type, CelestialBodyIdentifier id, float radius, int randomSeed, float quadtreeRadius, bool root, bool immovable = false) : base(radius, immovable) { AccessToInitialized = new object(); Type = type; ID = id; RNG = new System.Random(randomSeed); Quadtree = new Quadtree(this, quadtreeRadius, -quadtreeRadius, -quadtreeRadius, quadtreeRadius); Initialized = false; Root = root; }
public CelestialBodyIdentifier(CelestialBodyIdentifier parentID, CelestialBodyType childType, int childIndex) { Type = childType; Address = new Dictionary <CelestialBodyType, int>(); foreach (CelestialBodyType type in Enum.GetValues(typeof(CelestialBodyType))) { Address.Add(type, parentID.Address[type]); } Address[childType] = childIndex; }
/// <summary> /// Creates a new instance /// </summary> /// <param name="name"></param> /// <param name="radius"></param> /// <param name="orbitDistance"></param> /// <param name="orbitalAngularVelocity"></param> /// <param name="rotatationalAngularVelocity"></param> /// <param name="initialOrbitalAngularPositionOffset"></param> /// <param name="currentAngularPosition">set to <paramref name="initialOrbitalAngularPositionOffset"/>if creating, or not if reloading</param> /// <param name="material">The material the celestial body is made from</param> /// <param name="bodyType">The celestial body type</param> /// <param name="satellites">The satellites of this body.</param> public CelestialBody(string name, double radius, double orbitDistance, double orbitalAngularVelocity, double rotatationalAngularVelocity, double initialOrbitalAngularPositionOffset, double currentAngularPosition, IMaterial material, CelestialBodyType bodyType, CelestialBody[] satellites = null) { Name = name; Radius = radius; OrbitDistance = orbitDistance; OrbitalAngularVelocity = orbitalAngularVelocity; RotatationalAngularVelocity = rotatationalAngularVelocity; InitialOrbitalAngularPositionOffset = initialOrbitalAngularPositionOffset; CurrentAngularPosition = currentAngularPosition; Material = material; BodyType = bodyType; Satellites = satellites ?? new CelestialBody[0]; }
public CelestialBodyIdentifier(byte[] bytes, int startIndex) { Address = new Dictionary <CelestialBodyType, int>(); int offset = 4; Type = (CelestialBodyType)BitConverter.ToInt32(bytes, startIndex + offset); offset += 4; foreach (CelestialBodyType type in Enum.GetValues(typeof(CelestialBodyType))) { Address.Add(type, BitConverter.ToInt32(bytes, startIndex + offset)); offset += 4; } }
public CelestialBodyIdentifier(CelestialBodyType typeParam) { Type = typeParam; Address = new Dictionary <CelestialBodyType, int>(); foreach (CelestialBodyType type in Enum.GetValues(typeof(CelestialBodyType))) { if (type == typeParam) { Address.Add(type, 0); } else { Address.Add(type, -1); } } }
public virtual Entity Init (string defID, CelestialBodyType Type, float Mass, float Diameter, PlanetarySystem System, CelestialBody parent=null) { type = Type; if (parent == null) { orbit = new OrbitEntity (this, Mass, Diameter, Vector3.zero); } else { orbit = new OrbitEntity (this, Mass, Diameter, parent.orbit, parent.orbit.Barycenter); } Entity entity = base.Init (defID); ChangeSystem (System); ResourceManager.RandomizeStockpile (this); Name = system.name + " " + type.ToString () + " " + UnityEngine.Random.Range (0, 999); //colony = new Colony (this); return entity; }
public CelestialBody GetCelestialBody(CelestialBodyIdentifier id) { for (int i = CelestialBodyIdentifier.LargestCelestialBodyType(); i >= (int)Type; i--) { if (ID.Address[(CelestialBodyType)i] != id.Address[(CelestialBodyType)i]) { Debug.Log("bad address: " + id.ToString() + " in " + ID.ToString()); return(null); } } if (ID.Type == id.Type) { return(this); } for (int i = (int)Type - 1; i >= (int)id.Type; i--) { CelestialBodyType type = (CelestialBodyType)i; if (id.Address[type] != -1) { switch (type) { case CelestialBodyType.Expanse: return(Expanses[id.Address[type]].GetCelestialBody(id)); case CelestialBodyType.Galaxy: return(Galaxies[id.Address[type]].GetCelestialBody(id)); case CelestialBodyType.Sector: return(Sectors[id.Address[type]].GetCelestialBody(id)); case CelestialBodyType.SolarSystem: return(SolarSystems[id.Address[type]].GetCelestialBody(id)); case CelestialBodyType.Star: return(Stars[id.Address[type]].GetCelestialBody(id)); case CelestialBodyType.Planet: return(Planets[id.Address[type]].GetCelestialBody(id)); } } } return(null); }
private void PreInitializeMap(CelestialBodyType size, int seed) { if (size == CelestialBodyType.Universe) { Map = new Containers.Universe(new CelestialBodyIdentifier(size), seed, true); } else if (size == CelestialBodyType.Expanse) { Map = new Containers.Expanse(new CelestialBodyIdentifier(size), seed, true); } else if (size == CelestialBodyType.Galaxy) { Map = new Containers.Galaxy(new CelestialBodyIdentifier(size), seed, true); } else if (size == CelestialBodyType.Sector) { Map = new Containers.Sector(new CelestialBodyIdentifier(size), seed, true); } else { Map = new Containers.SolarSystem(new CelestialBodyIdentifier(size), seed, true); } }
public void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } if (Input.GetKeyDown(KeyCode.Alpha1) && Menu) { Menu = false; MenuScreen.SetActive(false); RenderEdges = true; MapSize = CelestialBodyType.Galaxy; InitializeGame(); } if (Input.GetKeyDown(KeyCode.Alpha2) && Menu) { Menu = false; MenuScreen.SetActive(false); RenderEdges = false; MapSize = CelestialBodyType.Universe; InitializeGame(); } //Debug.Log(1f/Time.deltaTime); }
public LifeStage CalculateStageOfLife(CelestialBodyType celestialType) { LifeStage stageOfLife; int roll = Die.Roll(2, 20); if (roll <= 3) stageOfLife = LifeStage.None; else if (roll <= 6) stageOfLife = LifeStage.OrganicCompounds; else if (roll <= 10) stageOfLife = LifeStage.SingleCellular; else if (roll <= 15) stageOfLife = LifeStage.MultiCellular; else if (roll <= 22) stageOfLife = LifeStage.SimpleLife; else if (roll <= 37) stageOfLife = LifeStage.ComplexLife; else if (roll <= 40) stageOfLife = LifeStage.SentientLife; else stageOfLife = LifeStage.None; if (celestialType == CelestialBodyType.Blackhole || celestialType == CelestialBodyType.Star || celestialType == CelestialBodyType.Wormhole) { stageOfLife = LifeStage.None; } else if (celestialType == CelestialBodyType.AsteroidBelt || celestialType == CelestialBodyType.Comet || celestialType == CelestialBodyType.GasPlanet || celestialType == CelestialBodyType.Rings) { int detrimentalRoll = Die.Roll(1, 4) - 1; int stageOfLifeInt = (int)stageOfLife - detrimentalRoll; if (stageOfLifeInt <= 0) stageOfLifeInt = 0; stageOfLife = (LifeStage)stageOfLifeInt; } return stageOfLife; }
public CelestialBody(string name, CelestialBodyType type) { this.name = name; this.type = type; }
public void Initialize(string type, string orbit, string size) { for (int i = 0; i < _resourceZones.Length; i++) { _resourceZones[i] = new Zone(i); _resourceZones[i].HostCelestialBody = this; } switch (type) { case "Photosphere": _type = CelestialBodyType.Star; break; case "Photon Sphere": _type = CelestialBodyType.BlackHole; break; case "Neutron Sphere": _type = CelestialBodyType.NeutronStar; break; case "Planet": _type = CelestialBodyType.Planet; break; case "Moon": _type = CelestialBodyType.Moon; break; case "Gas Giant": _type = CelestialBodyType.GasGiant; break; case "Large Moon": case "Titan": _type = CelestialBodyType.Titan; break; case "Ring": _type = CelestialBodyType.Ring; break; case "Asteroid": // Minor backward compatibility. case "Planetoid": _type = CelestialBodyType.Planetoid; break; case "Ringworld Arc 1": case "Ringworld Arc 2": case "Ringworld Arc 3": case "Ringworld Arc 4": case "Ringworld Arc 5": case "Ringworld Arc 6": case "Ringworld Arc 7": case "Ringworld Arc 8": case "Ringworld Arc 9": case "Ringworld Arc 10": case "Ringworld Arc 11": case "Ringworld Arc 12": case "Ringworld Arc 13": case "Ringworld Arc 14": case "Ringworld Arc 15": case "Ringworld Arc 16": case "Ringworld Arc 17": case "Ringworld Arc 18": case "Ringworld Arc 19": case "Ringworld Arc 20": case "Ringworld Arc 21": _type = CelestialBodyType.RingworldArc; break; default: throw new Exception($"Unknown type: '{type}'"); } switch (orbit) { case "n/a": _orbit = CelestialBodyOrbit.Star; break; case "Inferno Zone": _orbit = CelestialBodyOrbit.Inferno; break; case "Inner Zone": _orbit = CelestialBodyOrbit.Inner; break; case "Habitable Zone": _orbit = CelestialBodyOrbit.Habitable; break; case "Outer Zone": _orbit = CelestialBodyOrbit.Outer; break; case "Frigid Zone": _orbit = CelestialBodyOrbit.Frigid; break; default: throw new Exception($"Unknown orbit: '{orbit}'"); } // Planet size. if (_type == CelestialBodyType.RingworldArc) { _diameter = 36135; // 229,814 x 17,850m in spherical diameter. } else { int pos = size.IndexOf("m "); if (pos >= 0) { size = size.Remove(pos); } size = size.Replace(".", "").Replace(",", ""); int.TryParse(size, out _diameter); } }
protected CelestialBody(MapGenerator.Containers.Container container) { ID = container.ID; Type = container.Type; Position = container.GlobalPosition; Radius = container.Radius; if (container.Expanses != null) { Expanses = new Expanse[container.Expanses.Length]; for (int i = 0; i < Expanses.Length; i++) { Expanses[i] = new Expanse(container.Expanses[i]); } } else { Expanses = new Expanse[0]; } if (container.Galaxies != null) { Galaxies = new Galaxy[container.Galaxies.Length]; for (int i = 0; i < Galaxies.Length; i++) { Galaxies[i] = new Galaxy(container.Galaxies[i]); } } else { Galaxies = new Galaxy[0]; } if (container.Sectors != null) { Sectors = new Sector[container.Sectors.Length]; for (int i = 0; i < Sectors.Length; i++) { Sectors[i] = new Sector(container.Sectors[i]); } } else { Sectors = new Sector[0]; } if (container.SolarSystems != null) { SolarSystems = new SolarSystem[container.SolarSystems.Length]; for (int i = 0; i < SolarSystems.Length; i++) { SolarSystems[i] = new SolarSystem(container.SolarSystems[i]); } } else { SolarSystems = new SolarSystem[0]; } if (container.Stars != null) { Stars = new Star[container.Stars.Length]; for (int i = 0; i < Stars.Length; i++) { Stars[i] = new Star(container.Stars[i]); } } else { Stars = new Star[0]; } if (container.Planets != null) { Planets = new Planet[container.Planets.Length]; for (int i = 0; i < Planets.Length; i++) { Planets[i] = new Planet(container.Planets[i]); } } else { Planets = new Planet[0]; } }