public void Extend(SystemBody body) { Coords sectorCoords = new Coords(body.StarSystem.Coords.SectorIndexX, body.StarSystem.Coords.SectorIndexY); if (sectors.Contains(sectorCoords)) { string baseDir = GetExtentionDir(body); Dictionary <string, string> properties = new Dictionary <string, string>(); if (Directory.Exists(baseDir)) { string filename = Path.Combine(baseDir, "properties.txt"); properties = ReadProperties(filename); IExtendableObject obj = body as IExtendableObject; if (obj != null) { foreach (var key in properties.Keys) { obj.ExtendedProperties.SetValue(key.ToLower(), properties[key]); } } } } }
public PlanetElement(GLEffect a_oDefaultEffect, Vector3 a_oPosition, SystemBody a_oPlanet, System.Drawing.Color a_oColor, SceenElement PElement) : base(a_oPlanet) { m_oOrbitCircle = new CircleElement(a_oDefaultEffect, a_oPosition, a_oPlanet, a_oColor); #warning Cannot add m_oOrbitCircle to children for Planet Element _ParentElement = PElement; }
public string GetExtentionDir(SystemBody body) { string baseDir = GetExtentionDir(body.StarSystem); string bodyDirPart = string.Format("b.{0}", body.SystemBodyId); string bodyDir = Path.Combine(baseDir, bodyDirPart); return(bodyDir); }
public SpacePort(SystemBody body, string Id, string name, string sector, string Modifiers, SpacePortType type) { this.Body = body; this.Id = Id; this.Name = name; this.PlanetSector = sector; this.Modifiers = Modifiers; this.Type = type; }
public SystemObjectSector(SystemBody body, string bSectorId) { string extentionFilename = string.Format("{0}.txt", bSectorId); if (ObjectExtender.Instance.HasExtention(this, extentionFilename)) { string data = ObjectExtender.Instance.GetExtentionData(this, extentionFilename); this.Definition = data; ParseData(data, body); } }
public string MakeExtentionDirs(SystemBody body) { string baseDir = MakeExtentionDirs(body.StarSystem); string bodyDirPart = string.Format("b.{0}", body.SystemBodyId); string bodyDir = Path.Combine(baseDir, bodyDirPart); if (!Directory.Exists(bodyDir)) { Directory.CreateDirectory(bodyDir); } return(bodyDir); }
private static async Task WriteBody(StreamWriter writer, SystemBody body) { if (body.Type.Equals("star", StringComparison.OrdinalIgnoreCase)) { await writer.WriteLineAsync($" {body.Name}: {body.Type}/{body.SubType} distance:{body.DistanceToArrival}ls {(body.IsScoopable.GetValueOrDefault() ? "scoopable" : "non-scoopable")} age:{body.Age} luminosity:{body.Luminosity} spectralClass:{body.SpectralClass} mass:{body.SolarMasses} radius:{body.SolarRadius} temperature:{body.SurfaceTemperature}K reserve:{body.ReserveLevel} belts:{string.Join(",", body.Belts.Select(b => b.Type))} rings:{string.Join(",", body.Rings.Select(b => b.Type))}"); } else if (body.Type.Equals("planet", StringComparison.OrdinalIgnoreCase)) { await writer.WriteLineAsync($" {body.Name}: {body.Type}/{body.SubType} distance:{body.DistanceToArrival}ls {(body.IsLandable.GetValueOrDefault() ? "landable" : "not-landable")} gravity:{body.Gravity}G earthMasses:{body.EarthMasses} temperature:{body.SurfaceTemperature}K pressure:{body.SurfacePressure} atmosphere:{body.AtmosphereType} volcanism:{body.VolcanismType} terraforming:{body.TerraformingState} reserve:{body.ReserveLevel} rings:{string.Join(",", body.Rings.Select(b => b.Type))}"); } else { await writer.WriteLineAsync($" {body.Name}: {body.Type}/{body.SubType} distance:{body.DistanceToArrival}ls"); } }
public override bool Update() { if (Target != null && !this.InSpace) //Follow Target { SystemLocation dLocation = null; SystemBody body = this.Target as SystemBody; if (body != null) { dLocation = SystemLocation.GetUpdatedLocation(body); } else { dLocation = this.Target.SystemLocation; } if (dLocation.GetInSystemDistance(this.SystemLocation) > (1000)) { SetDestSystemLocation(dLocation); } } this.IsDirty |= base.Update(); if (this.IsDirty) { if (Player != null) { Player.Location = new GameLocation(this.Coords); Player.Location.UpdateSystemBody(this.SystemLocation, this.InSpace); Player.Persist(); } return(true); } else { return(false); } }
public ioPlanetInfo(SystemBody planet) : this(planet, 79) { }
public static IStarSystem ParseStarSystem(string data) { dynamic sysJson = JObject.Parse(data); (float, float, float)coords = ((float)sysJson.coords.x, (float)sysJson.coords.y, (float)sysJson.coords.z); var system = new StarSystem() { Coordinates = coords, SystemName = sysJson.name, Id = (ulong)sysJson.id64, }; // typeof Array var bodies = sysJson.bodies; List <ISystemBody> systemBodies = new List <ISystemBody>(bodies.Count); Dictionary <string, List <ISystemBody> > bodyIdentifiersAndChildren = new Dictionary <string, List <ISystemBody> >(); foreach (var b in bodies) { var body = new SystemBody() { Id = (ulong)b.id64, BodyId = (uint)b.bodyId, Name = b.name ?? string.Empty, Type = b.type ?? string.Empty, SubType = b.subType ?? string.Empty, DistanceToArrival = (float?)b.distanceToArrival ?? -1f, VolcanismType = b.volcanismType ?? "No volcanism", AtmosphereType = b.atmosphereType ?? "No atmosphere", SurfaceTemp = (float?)b.surfaceTemperature, Gravity = (float?)b.gravity ?? -1, Landable = (bool?)b.isLandable ?? false, }; foreach (var entry in GetParentIdentifiers(GetOwnIdentier(system.SystemName, body.Name))) { if (!bodyIdentifiersAndChildren.ContainsKey(entry)) { bodyIdentifiersAndChildren[entry] = new List <ISystemBody>(); } bodyIdentifiersAndChildren[entry].Add(body); } systemBodies.Add(body); } // Link parents / children foreach (var keys in bodyIdentifiersAndChildren.Keys) { foreach (var body in bodyIdentifiersAndChildren[keys]) { var identifier = GetOwnIdentier(system.SystemName, body.Name); if (!bodyIdentifiersAndChildren.ContainsKey(identifier)) { // No children continue; } foreach (var child in bodyIdentifiersAndChildren[identifier]) { child.Parents.Add(body); body.Children.Add(child); } } } system.BodyList = systemBodies; return(system); }
private void ParseData(string spec, SystemBody body) { Random rand = new Random((int)body.SystemId.Id); List <char[]> def = new List <char[]>(); StringReader sr = new StringReader(spec); string line; while ((line = sr.ReadLine()) != null) { def.Add(line.ToCharArray()); } //equalise int maxLength = 0; for (int y = 0; y < def.Count; y++) { if (def[y].Length > maxLength) { maxLength = def[y].Length; } } for (int y = 0; y < def.Count; y++) { for (int x = 0; x < def[y].Length; x++) { char c = def[y][x]; if (c == 'B') { #region void //string filename = Path.Combine(baseDir, buildings[rand.Next(0, buildings.Length - 1)]); //var buildind = Messages.Message.ReadMII2File(filename); //buildind.Write(x * 21, y * 8, mainCanvas); #endregion } else if (c == 'P') { //Give space for the port [2x2] if (x + 1 < def[y].Length) { def[y][x + 1] = '+'; } if (y + 1 < def.Count) { if (x < def[y + 1].Length) { def[y + 1][x] = '_'; } if (x + 1 < def[y + 1].Length) { def[y + 1][x + 1] = '_'; } } #region void //string filename = Path.Combine(baseDir, sPorts[0]); //var buildind = Messages.Message.ReadMII2File(filename); //buildind.Write(x * 21, y * 8, mainCanvas); #endregion } else if (c == 'F') { //Give space for the factory [2x2] if (x + 1 < def[y].Length) { def[y][x + 1] = '+'; } if (y + 1 < def.Count) { if (x < def[y + 1].Length) { def[y + 1][x] = '_'; } if (x + 1 < def[y + 1].Length) { def[y + 1][x + 1] = '_'; } } #region void //string filename = Path.Combine(baseDir, factoriesB[rand.Next(0, factoriesB.Length - 1)]); //var buildind = Messages.Message.ReadMII2File(filename); //buildind.Write(x * 21, y * 8, mainCanvas); #endregion } else if (c == 'f') { //Give space for the factory [1x2] if (x + 1 < def[y].Length) { def[y][x + 1] = '+'; } #region void //string filename = Path.Combine(baseDir, factoriesA[rand.Next(0, factoriesB.Length - 1)]); //var buildind = Messages.Message.ReadMII2File(filename); //buildind.Write(x * 21, y * 8, mainCanvas); #endregion } } } }
/// <summary> /// Constructor for planetary targets. /// </summary> /// <param name="BodyTarget">Body which is the target</param> public TargetTN(SystemBody BodyTarget) : base() { TargetType = BodyTarget.SSEntity; Body = BodyTarget; }
public bool HasExtention(SystemBody body, string extention) { string filename = Path.Combine(GetExtentionDir(body), extention); return(File.Exists(filename)); }
public string GetExtentionData(SystemBody body, string extention) { string filename = Path.Combine(GetExtentionDir(body), extention); return(FlatFileDB.Instance.ReadFile(filename)); }
public ioPlanetInfo(SystemBody planet, int screenWidth) { this.Planet = planet; this.screenWidth = screenWidth; }
public static List <SpacePort> GeneratePorts(SystemBody body) { List <SpacePort> ports = new List <SpacePort>(); var distance = body.StarSystem.Coords.CalculateDistance((new Sector()).Coords); var prob = 2 - (distance * 2 / 150); if (prob < 0) { prob = 0; } int minP = 0, maxP = 0; switch (body.BodyType) { case SystemBodyType.Asteroid: minP = 0; maxP = 1; break; case SystemBodyType.GasGiant: minP = 0; maxP = 0; break; case SystemBodyType.IceWorld: minP = 1; maxP = 3; break; case SystemBodyType.Inferno: minP = 0; maxP = 2; break; case SystemBodyType.RingedGasGiant: minP = 0; maxP = 0; break; case SystemBodyType.RockyPlanetoid: minP = 0; maxP = 1; break; case SystemBodyType.RockyWorld: minP = 1; maxP = 2; break; case SystemBodyType.SubGasGiant: minP = 0; maxP = 0; break; case SystemBodyType.Terrestrial: minP = 1; maxP = 3; break; case SystemBodyType.Venuzian: minP = 0; maxP = 0; break; case SystemBodyType.WaterWorld: minP = 1; maxP = 3; break; } minP = (int)(minP * prob); maxP = (int)(maxP * prob); Random rand = new Random( (int)(body.SystemBodyId ^ body.SystemId.SectorIndexX ^ body.SystemId.SectorIndexY)); int numOfPorts = rand.Next(minP, maxP); for (int i = 0; i < numOfPorts; i++) { int a = body.PlanetSector.GetLength(0); int b = body.PlanetSector.GetLength(1); int s1 = rand.Next(0, a); int s2 = rand.Next(0, b); string Id = string.Format("P{0}", i); string sector = string.Format("{0}{1}", (char)((int)'A' + s1), s2); string name = string.Format("{0} P{1}", body.Name, i); SpacePort p = new SpacePort(body, Id, name, sector, "", SpacePortType.SpacePort); ports.Add(p); } return(ports); }
public BBS(SystemBody body) : this() { this.BBSName = body.Name; this.BBSCode = string.Format("{0}/{1}", body.Coords.ToString(), body.Name); this.Parent = null; }
/// <summary> /// Constructor for planetary targets. /// </summary> /// <param name="BodyTarget">Body which is the target</param> public TargetTN(SystemBody BodyTarget) : base() { TargetType = BodyTarget.SSEntity; Body = BodyTarget; }
/// <summary> /// Target assignment of planets. /// </summary> /// <param name="PlanetTarget">planet</param> public void assignTarget(SystemBody PlanetTarget) { m_oTarget = new TargetTN(PlanetTarget); }
public string GetHud() { List <SectorObject> secObjects = new List <SectorObject>(); List <ObjInfo> objects = new List <ObjInfo>(); GameManager manager = GameManager.Instance; //int smallHudWidth = 30, smallHudHeight = 15; int smallHudWidth = 20, smallHudHeight = 12; TextCanvas closeDistHUDCanvas = new TextCanvas(smallHudWidth, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); closeDistHUDCanvas.DrawGrid(0, 0, smallHudWidth, smallHudHeight, (byte)234); closeDistHUDCanvas.DrawRectangle(0, 0, smallHudWidth, smallHudHeight, (byte)ANSI.ANSIColor_8.Cyan); TextCanvas nearbyShipsHUDCanvas = new TextCanvas(smallHudWidth, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); nearbyShipsHUDCanvas.DrawGrid(0, 0, smallHudWidth, smallHudHeight, (byte)234); nearbyShipsHUDCanvas.DrawRectangle(0, 0, smallHudWidth, smallHudHeight, (byte)ANSI.ANSIColor_8.Cyan); TextCanvas closeDistHUDCanvas_Target = new TextCanvas(smallHudWidth, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); closeDistHUDCanvas_Target.DrawGrid(0, 0, smallHudWidth, smallHudHeight, (byte)234); closeDistHUDCanvas_Target.DrawRectangle(0, 0, smallHudWidth, smallHudHeight, (byte)ANSI.ANSIColor_8.Cyan); TextCanvas nearbyEShipsHUDCanvas = new TextCanvas(smallHudWidth, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); nearbyEShipsHUDCanvas.DrawGrid(0, 0, smallHudWidth, smallHudHeight, (byte)234); nearbyEShipsHUDCanvas.DrawRectangle(0, 0, smallHudWidth, smallHudHeight, (byte)ANSI.ANSIColor_8.Cyan); TextCanvas canvas = new TextCanvas(Width - 5, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); //canvas.DrawRectangle(0, 0, Width -5, Height -5, (byte)ANSI.ANSIColor_8.Cyan); //canvas.DrawString(Width / 2, Height / 2, "▲", (byte)ANSI.ANSIColor_16.Green, (byte)ANSI.ANSIColor_16.Black); StarSystem system = this.Player.Player.Location.StarSystem; SpaceShip ship = this.Player.Player.SpaceShip; if (system == null) { return(string.Empty); } var sysM = manager.StarSystemManager.GetStarSystemArea(system.Coords); secObjects.AddRange(system.SystemBodies); secObjects.AddRange(sysM.GetShipsInSystem().Cast <SectorObject>()); secObjects.Add(system); if (ship.Target != null) { secObjects.Add(ship.Target); } secObjects.Add(ship); double minDist = Double.MaxValue; double minDistShips = Double.MaxValue; double minDist_Target = Double.MaxValue; double minDistEShips = Double.MaxValue; foreach (SectorObject secObject in secObjects) { double dist = secObject.SystemLocation.GetInSystemDistance(ship.SystemLocation); double dist_Target = (ship.Target != null) ? secObject.SystemLocation.GetInSystemDistance(ship.Target.SystemLocation) : 0; if (dist < minDist && dist > 0) { minDist = dist; } if (dist_Target < minDist_Target && dist_Target > 0) { minDist_Target = dist_Target; } SpaceShip shipObj = secObject as SpaceShip; SystemBody bodyObj = secObject as SystemBody; StarSystem sysObj = secObject as StarSystem; ObjInfo info = new ObjInfo(); info.X = secObject.SystemLocation.X; info.Y = secObject.SystemLocation.Y; info.Distance = dist; if (secObject == ship) { info.IsPlayer = true; } if (secObject == ship.Target) { info.IsTarget = true; } if (shipObj != null) { info.Display = "▪"; if (dist < minDistShips && dist > 0) { minDistShips = dist; } if (info.IsEnemy) { if (dist < minDistEShips && dist > 0) { minDistEShips = dist; } } } else if (bodyObj != null) { info.Display = "●"; } else if (sysObj != null) { info.Display = "☼"; } objects.Add(info); } if (minDist_Target == Double.MaxValue) { minDist_Target = 0; } if (minDistShips == Double.MaxValue) { minDistShips = 0; } if (minDistEShips == Double.MaxValue) { minDistEShips = 0; } //write close distance HUD double hudRange = minDist * (smallHudHeight / 2); // 149598000 / 2; double zX = ship.SystemLocation.X; double zY = ship.SystemLocation.Y; #region Close Distance HUD foreach (var obj in objects) { if (obj.Distance < (hudRange)) { double x = obj.X - zX, y = obj.Y - zY; int cX = (int)(x * smallHudWidth / hudRange + (smallHudWidth / 2)); int cY = (int)(y * smallHudHeight / hudRange + (smallHudHeight / 2)); byte foreColor = (byte)ANSI.ANSIColor_16.Cyan; if (obj.IsPlayer) { foreColor = (byte)ANSI.ANSIColor_16.Green; } if (obj.IsEnemy) { foreColor = (byte)ANSI.ANSIColor_16.Red; } if (obj.IsTarget) { foreColor = (byte)ANSI.ANSIColor_16.DarkYellow; } closeDistHUDCanvas.DrawString(cX, cY, obj.Display, foreColor, (byte)ANSI.ANSIColor_16.Black); } } closeDistHUDCanvas.DrawString(1, 1, string.Format("{0}", SystemLocation.GetDistanceDesc(hudRange)), 6, 0); #endregion #region Nearby Ships HUD hudRange = minDistShips * (smallHudHeight / 2); foreach (var obj in objects) { if (obj.Distance < (hudRange)) { double x = obj.X - zX, y = obj.Y - zY; int cX = (int)(x * smallHudWidth / hudRange + (smallHudWidth / 2)); int cY = (int)(y * smallHudHeight / hudRange + (smallHudHeight / 2)); byte foreColor = (byte)ANSI.ANSIColor_16.Cyan; if (obj.IsPlayer) { foreColor = (byte)ANSI.ANSIColor_16.Green; } if (obj.IsEnemy) { foreColor = (byte)ANSI.ANSIColor_16.Red; } if (obj.IsTarget) { foreColor = (byte)ANSI.ANSIColor_16.DarkYellow; } nearbyShipsHUDCanvas.DrawString(cX, cY, obj.Display, foreColor, (byte)ANSI.ANSIColor_16.Black); } } nearbyShipsHUDCanvas.DrawString(1, 1, string.Format("{0}", SystemLocation.GetDistanceDesc(hudRange)), 6, 0); #endregion #region Nearby Enemy Ships HUD hudRange = minDistEShips * (smallHudHeight / 2); foreach (var obj in objects) { if (obj.Distance < (hudRange) && obj.IsEnemy) { double x = obj.X - zX, y = obj.Y - zY; int cX = (int)(x * smallHudWidth / hudRange + (smallHudWidth / 2)); int cY = (int)(y * smallHudHeight / hudRange + (smallHudHeight / 2)); byte foreColor = (byte)ANSI.ANSIColor_16.Cyan; if (obj.IsPlayer) { foreColor = (byte)ANSI.ANSIColor_16.Green; } if (obj.IsEnemy) { foreColor = (byte)ANSI.ANSIColor_16.Red; } if (obj.IsTarget) { foreColor = (byte)ANSI.ANSIColor_16.DarkYellow; } nearbyEShipsHUDCanvas.DrawString(cX, cY, obj.Display, foreColor, (byte)ANSI.ANSIColor_16.Black); } } nearbyEShipsHUDCanvas.DrawString(1, 1, string.Format("{0}", SystemLocation.GetDistanceDesc(hudRange)), 6, 0); #endregion #region Target Close Distance HUD hudRange = minDist_Target * (smallHudHeight / 2); // 149598000 / 2; if (ship.Target != null) { zX = ship.Target.SystemLocation.X; zY = ship.Target.SystemLocation.Y; } foreach (var obj in objects) { if (obj.Distance < (hudRange)) { double x = obj.X - zX, y = obj.Y - zY; int cX = (int)(x * smallHudWidth / hudRange + (smallHudWidth / 2)); int cY = (int)(y * smallHudHeight / hudRange + (smallHudHeight / 2)); byte foreColor = (byte)ANSI.ANSIColor_16.Cyan; if (obj.IsPlayer) { foreColor = (byte)ANSI.ANSIColor_16.Green; } if (obj.IsEnemy) { foreColor = (byte)ANSI.ANSIColor_16.Red; } if (obj.IsTarget) { foreColor = (byte)ANSI.ANSIColor_16.DarkYellow; } closeDistHUDCanvas_Target.DrawString(cX, cY, obj.Display, foreColor, (byte)ANSI.ANSIColor_16.Black); } } closeDistHUDCanvas_Target.DrawString(1, 1, string.Format("{0}", SystemLocation.GetDistanceDesc(hudRange)), 6, 0); #endregion canvas.DrawRawData(0, 0, closeDistHUDCanvas.GetRawData()); canvas.DrawRawData(smallHudWidth, 0, nearbyShipsHUDCanvas.GetRawData()); canvas.DrawRawData(smallHudWidth * 2, 0, closeDistHUDCanvas_Target.GetRawData()); canvas.DrawRawData(smallHudWidth * 3, 0, nearbyEShipsHUDCanvas.GetRawData()); long baseX, baseY; baseX = (long)(ship.SystemLocation.X / minDist); baseY = (long)(ship.SystemLocation.Y / minDist); return(canvas.ToString()); }