예제 #1
0
        public override string ToString()
        {
            TextCanvas canvas = new TextCanvas(this.Width, this.Height, TextCanvas.NumOfColorsEnum.XTERM256);

            canvas.DrawRawData(0, 0, buffer);
            return(canvas.ToString());
        }
예제 #2
0
        private void Init()
        {
            string baseDir = "./Messages/Stars";

            //get the star ansi image;
            string filename = Path.Combine(baseDir, string.Format("{0}.MII", this.StarSystem.SpectralClass));
            var    starFile = Messages.Message.ReadMII2File(filename);

            TextCanvas canvas = new TextCanvas(screenWidth, 25, TextCanvas.NumOfColorsEnum.XTERM256);

            starFile.Write(0, 0, canvas);

            canvas.FillRectangle(41, 4, 79 - 41, 10, 0);
            canvas.DrawString(41, 4, string.Format("{0} System", StarSystem.Name), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(41, 5, string.Format("Stable system with {0} major bodies", StarSystem.NumberOfBodies + 1), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(41, 7, string.Format("Main Star: {0}", StarSystem.Name), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(41, 8, string.Format("{1} : {2}", StarSystem.Name, StarSystem.StarType, StarSystem.Desc), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(41, 9, string.Format("Spectral Class: {0}", StarSystem.SpectralClass), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(41, 10, string.Format("Luminosity: {0}", StarSystem.LuminosityClass), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(41, 11, string.Format("Magnitude: {0}", StarSystem.Magnitude), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(41, 12, string.Format("Size: ~{0:0.00}", StarSystem.Size), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(41, 13, string.Format("Mass: ~{0:0.00}", StarSystem.Mass), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(41, 14, string.Format("Habitable Zone ~{0:0.00}Au", StarSystem.HZone), (byte)ANSI.ANSIColor_16.Cyan, 0);

            //int boxX = 40, boxY = 0;

            //canvas.FillRectangle(boxX, boxY, 79 - boxX, 30 - boxY, 0);
            //canvas.DrawRectangle(boxX, boxY, 79 - boxX, 30 - boxY, 250);

            this.Canvas = canvas;
        }
예제 #3
0
 public void WriteTile(TextCanvas canvas)
 {
     for (int y = 0; y < canvas.Height; y += this.buffer.GetLength(1))
     {
         for (int x = 0; x < canvas.Width; x += this.buffer.GetLength(0))
         {
             canvas.DrawRawData(x, y, buffer);
         }
     }
 }
예제 #4
0
        private void Init()
        {
            string baseDir = "./Messages/Ships";

            //get the star ansi image;
            string filename = Path.Combine(baseDir, string.Format("{0}.png.MII", this.SpaceShip.MKIIFile));
            var    shipFile = Messages.Message.ReadMII2File(filename);

            TextCanvas canvas = new TextCanvas(screenWidth, 18, TextCanvas.NumOfColorsEnum.XTERM256);

            shipFile.Write(3, 1, canvas);

            Sector     sector     = SpaceShip.Coords.GetSector();
            StarSystem starSystem = null;

            foreach (var sys in sector.Systems)
            {
                if (sys.SystemId == SpaceShip.SystemId)
                {
                    starSystem = sys;
                    break;
                }
            }

            canvas.DrawString(20, 1, string.Format("Model: {0} - Reg Code: {1}",
                                                   (SpaceShip.Name == null || SpaceShip.Name.Trim() == string.Empty) ? "Unknown" : SpaceShip.Name,
                                                   SpaceShip.Code), 250, 0);

            canvas.DrawString(20, 2, string.Format("Sector: {0} - System {1} - Target: {2}",
                                                   SpaceShip.Coords.GetSector(),
                                                   (starSystem != null) ? starSystem.Name : "None",
                                                   (SpaceShip.Target != null) ? SpaceShip.Target.ToString() : "No target"
                                                   ), 250, 0);
            canvas.DrawString(20, 5, string.Format("Speed Capability: {0}", SpaceShip.Speed), 250, 0);
            canvas.DrawString(20, 6, string.Format("Mass: {0} - Hull {1}", SpaceShip.Mass, SpaceShip.Hull), 250, 0);
            canvas.DrawString(20, 7, string.Format("Main Thruster: {0} - Retro Thruster: {1}", SpaceShip.MainThrusterAccel, SpaceShip.RetroThrusterAccel), 250, 0);
            canvas.DrawString(20, 8, string.Format("Cargo Bay Cap: {0} ", SpaceShip.CargoBay.Capacity), 250, 0);
            canvas.DrawString(20, 9, string.Format("Energy: {0} - Generator {1}", SpaceShip.Energy, SpaceShip.Generator.Energy), 250, 0);
            canvas.DrawString(20, 10, string.Format("Gun Moutings: {0} - Guns {1}", SpaceShip.GunMoutings, SpaceShip.Lasers.Length), 250, 0);
            canvas.DrawString(20, 11, string.Format("Missile Pylons: {0} - Launchers {1}", SpaceShip.MissilePylons, SpaceShip.MissileLaunchers.Length), 250, 0);

            this.Canvas = canvas;
        }
예제 #5
0
        public string GetInfo()
        {
            string        baseDir  = "./Messages/Citys/";
            string        spfile   = "p1.png.MII";
            TextCanvas    canvas   = new TextCanvas(screenWidth, 18, TextCanvas.NumOfColorsEnum.XTERM256);
            StringBuilder sBuilder = new StringBuilder();

            canvas.FillRectangle(0, 0, 44, 18, 234);

            string tileFilename = Path.Combine(baseDir, spfile);
            var    img          = Messages.Message.ReadMII2File(tileFilename);

            img.Write(2, 2, canvas);

            canvas.DrawString(45, 1, string.Format("Port: {0}", SpacePort.Name), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(45, 2, string.Format("Planet: {0}", SpacePort.Body.PlanetName), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(45, 3, string.Format("Planet Sector: {0}", SpacePort.PlanetSector), (byte)ANSI.ANSIColor_16.Cyan, 0);

            sBuilder.AppendLine(canvas.ToString());
            return(sBuilder.ToString());
        }
예제 #6
0
        public string GetInfo()
        {
            string baseDir  = "./Messages/Planets";
            string filename = string.Empty;

            switch (Planet.BodyType)
            {
            case SystemBodyType.Asteroid: filename = "AS.MII"; break;

            case SystemBodyType.RockyWorld: filename = "R.MII"; break;

            case SystemBodyType.RockyPlanetoid: filename = "R2.MII"; break;

            case SystemBodyType.Inferno: filename = "I.MII"; break;

            case SystemBodyType.Venuzian: filename = "V.MII"; break;

            case SystemBodyType.Terrestrial: filename = "T.MII"; break;

            case SystemBodyType.WaterWorld: filename = "W.MII"; break;

            case SystemBodyType.IceWorld: filename = "W2.MII"; break;

            case SystemBodyType.GasGiant: filename = "GS.MII"; break;

            case SystemBodyType.RingedGasGiant: filename = "GS2.MII"; break;

            case SystemBodyType.SubGasGiant: filename = "GS3.MII"; break;

            default: filename = "R.MII"; break;
            }


            //get the star ansi image;
            filename = Path.Combine(baseDir, filename);
            var starFile = Messages.Message.ReadMII2File(filename);

            TextCanvas canvas = new TextCanvas(screenWidth, starFile.Height, TextCanvas.NumOfColorsEnum.XTERM256);

            starFile.Write(0, 0, canvas);

            canvas.DrawString(40, canvas.Height - 5, string.Format("Planet: {0}", Planet.Name), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(40, canvas.Height - 4, string.Format("Planet class: {0}", Planet.GetClass_Ext()), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(40, canvas.Height - 3, string.Format("Orbital period: {0} Earth years", Planet.OrbitalPeriod), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(40, canvas.Height - 2, string.Format("Orbital radius: {0:0.000} AU", Planet.OrbitalRadius), (byte)ANSI.ANSIColor_16.Cyan, 0);
            canvas.DrawString(40, canvas.Height - 1, string.Format("Surface Temperature: {0:0.0}°", Planet.Temperature), (byte)ANSI.ANSIColor_16.Cyan, 0);


            StringBuilder sBuilder = new StringBuilder();

            sBuilder.AppendLine(canvas.ToString());
            //sBuilder.AppendLine(WrapString(Planet.Description));

            sBuilder.AppendFormat("\r\n");
            sBuilder.AppendFormat(ANSI.SetColorANSI16("Surface sectors:\r\n", ANSI.ANSIColor_16.BrightCyan));

            char lineChar = 'A';

            for (int y = 0; y < Planet.PlanetSector.GetLength(1); y++)
            {
                if (y == 0)
                {
                    sBuilder.Append("  ");
                    sBuilder.Append(ANSI.ColorANSI16(ANSI.ANSIColor_16.BrightCyan));
                    for (int x = 0; x < Planet.PlanetSector.GetLength(0); x++)
                    {
                        sBuilder.AppendFormat("  {0,-2} ", x + 1);
                    }
                    sBuilder.Append(ANSI.ClearFormat());
                    sBuilder.AppendFormat("\r\n");
                }

                sBuilder.Append(ANSI.SetColorANSI16(string.Format("{0,-2}", lineChar), ANSI.ANSIColor_16.BrightCyan)); lineChar++;
                for (int x = 0; x < Planet.PlanetSector.GetLength(0); x++)
                {
                    GetPlanetSectorString(Planet.PlanetSector[x, y], sBuilder);
                }

                sBuilder.AppendFormat("\r\n");
            }

            sBuilder.AppendFormat(ANSI.SetColorANSI16("\r\nSpace Ports / Stations: ", ANSI.ANSIColor_16.BrightCyan));
            sBuilder.AppendFormat("{0}\r\n", (Planet.SpacePort.Count > 0) ? "" : ANSI.SetColorANSI16("None", ANSI.ANSIColor_16.Cyan));
            foreach (var s in Planet.SpacePort)
            {
                sBuilder.AppendFormat("{3}[{4}{0}{3}] {4}{1,-30}{3} Sector: {4}{2}{5}\r\n",
                                      s.Id, s.Name, s.PlanetSector,
                                      ANSI.ColorANSI16(ANSI.ANSIColor_16.Cyan),
                                      ANSI.ColorANSI16(ANSI.ANSIColor_16.BrightCyan),
                                      ANSI.ClearFormat()
                                      );
            }

            return(sBuilder.ToString());
        }
예제 #7
0
 public void Write(int x, int y, TextCanvas canvas)
 {
     canvas.DrawRawData(x, y, buffer);
 }
예제 #8
0
        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());
        }