Ejemplo n.º 1
0
 /// <summary>
 /// Creates a scenario.
 /// </summary>
 public OrbScenario()
 {
     System = "Sol";
     Ships = new List<OrbVessel>();
     Camera = new OrbCamera();
     HUDmode = OrbHUD.Surface;
     MJD = -1d;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a scenario.
 /// </summary>
 public OrbScenario()
 {
     System  = "Sol";
     Ships   = new List <OrbVessel>();
     Camera  = new OrbCamera();
     HUDmode = OrbHUD.Surface;
     MJD     = -1d;
 }
Ejemplo n.º 3
0
        private void Parse(string[] lines)
        {
            int i;

            for (i = 0; i <= lines.Count() - 1; i++)
            {
                switch (lines[i].ToUpperInvariant())
                {
                case "BEGIN_DESC":
                {
                    i++;
                    Description = lines[i];
                    i++;
                    while (!(lines[i] == "END_DESC"))
                    {
                        Description += '\n' + lines[i];
                        i++;
                    }
                    break;
                }

                case "BEGIN_ENVIRONMENT":
                {
                    i++;
                    while (!(lines[i] == "END_ENVIRONMENT"))
                    {
                        string[] content = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                        switch (content[0].ToUpperInvariant())
                        {
                        case "SYSTEM":
                            System = content[1];
                            break;

                        case "DATE":
                            switch (content[1])
                            {
                            case "MJD":
                                MJD = double.Parse(content[2]);
                                break;

                            case "JD":
                                MJD = double.Parse(content[2]) + 2400000.5;
                                break;

                            default:
                                //MJD = Misc.GetMJD(DateTime.Now); // Wrong: we should only indicate there's no MJD data
                                MJD = -1d;                 // Will trigger 'HasMJD = false'
                                break;
                            }
                            break;

                        case "HELP":
                            Help = content[1];
                            break;

                        case "SCRIPT":
                            Script = content[1];
                            break;
                        }

                        i++;
                    }
                    break;
                }

                case "BEGIN_CAMERA":
                {
                    OrbCamera cam = new OrbCamera();

                    while (lines[i] != "END_CAMERA")
                    {
                        string[] line = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                        switch (line[0].ToUpperInvariant())
                        {
                        case "MODE":
                            if (line[1] == "Extern")
                            {
                                cam.Mode = OrbCamera.CameraMode.Extern;
                            }
                            else
                            {
                                cam.Mode = OrbCamera.CameraMode.GlassCockpit;
                            }

                            break;

                        case "TARGET":
                            cam.Target = line[1];

                            break;

                        case "POS":
                            try { cam.Pos = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])); }
                            catch { }

                            break;

                        case "TRACKMODE":
                            OrbCamera.CameraTrackMode tmode;
                            if (Enum.TryParse <OrbCamera.CameraTrackMode>(line[1], out tmode))
                            {
                                cam.TrackMode = tmode;
                            }

                            try { cam.RefBody = line[2]; }
                            catch { }

                            break;

                        case "GROUNDLOCATION":
                            if (line.Length < 4)
                            {
                                break;
                            }
                            cam.GroundLocation = new double[] { double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3]) };

                            break;

                        case "GROUNDDIRECTION":
                            if (line.Length < 3)
                            {
                                break;
                            }
                            cam.GroundDirection = new double[] { double.Parse(line[1]), double.Parse(line[2]) };

                            break;

                        case "FOV":
                            cam.FieldOfView = double.Parse(line[1]);

                            break;
                        }
                        i++;
                    }
                    Camera = cam;

                    break;
                }

                case "BEGIN_PANEL":
                    Camera.Mode = OrbCamera.CameraMode.PanelCockpit;
                    while (lines[i] != "END_PANEL")
                    {
                        i++;
                    }

                    break;

                case "BEGIN_VC":
                    Camera.Mode = OrbCamera.CameraMode.VirtualCockpit;
                    while (lines[i] != "END_VC")
                    {
                        i++;
                    }

                    break;

                case "BEGIN_HUD":
                    i++;
                    while (lines[i] != "END_HUD")
                    {
                        string[] line2 = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        switch (line2[0].ToUpperInvariant())
                        {
                        case "TYPE":
                            OrbHUD hud = OrbHUD.None;
                            Enum.TryParse <OrbHUD>(line2[1], out hud);
                            HUDmode = hud;

                            break;
                        }

                        i++;
                    }

                    break;

                case "BEGIN_SHIPS":
                {
                    OrbVessel ship = new OrbVessel();

                    i++;
                    string[] content = lines[i].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

                    if (content.Count() == 2)
                    {
                        ship.Name        = content[0];
                        ship.VesselClass = content[1];

                        i++;
                        while (!(lines[i] == "END"))
                        {
                            string[] line = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                            switch (line[0].ToUpperInvariant())
                            {
                            case "STATUS":
                                ship.Status  = line[1];
                                ship.RefBody = line[2];
                                break;

                            case "POS":
                                ship.SetPOS(Double.Parse(line[2]), double.Parse(line[1]));
                                break;

                            case "HEADING":
                                ship.Heading = double.Parse(line[1]);
                                break;

                            case "RPOS":
                                ship.RPos = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3]));
                                break;

                            case "RVEL":
                                ship.RVel = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3]));
                                break;

                            case "AROT":
                                ship.ARot = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3]));
                                break;

                            case "VROT":
                                ship.VRot = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3]));
                                break;

                            case "FUEL":
                            {
                                ship.Fuel = float.Parse(line[1]);
                                break;
                            }

                            case "PRPLEVEL":
                            {
                                List <OrbLevels> level = new List <OrbLevels>();
                                for (int j = 1; j < line.Count() - 1; j++)
                                {
                                    string[] split = line[j].Split(':');
                                    level.Add(new OrbLevels(int.Parse(split[0]), float.Parse(split[1])));
                                }
                                ship.PrpLevel = level;
                                break;
                            }

                            case "THLEVEL":
                            {
                                List <OrbLevels> throttles = new List <OrbLevels>();
                                for (int j = 1; j < line.Count() - 1; j++)
                                {
                                    string[] split = line[j].Split(':');
                                    throttles.Add(new OrbLevels(int.Parse(split[0]), float.Parse(split[1])));
                                }
                                ship.ThLevel = throttles;
                                break;
                            }

                            case "DOCKINFO":
                            {
                                List <OrbDockInfo> dockinfo = new List <OrbDockInfo>();
                                for (int j = 1; j < line.Count() - 1; j++)
                                {
                                    string[] split = line[j].Split(':');
                                    dockinfo.Add(new OrbDockInfo {
                                                DockID = int.Parse(split[0]), TargetDockID = int.Parse(split[1]), TargetVessel = split[2]
                                            });
                                }
                                ship.DockInfo = dockinfo;
                                break;
                            }

                            default:
                            {
                                string key   = line[0];
                                string value = "";
                                for (int j = 1; j < line.Count(); j++)
                                {
                                    value += line[j] + " ";
                                }
                                ship.Extra.Add(key, value.Trim());

                                break;
                            }
                            }

                            i++;
                        }
                    }
                }

                break;
                }
            }
            if (MJD == 0)
            {
                MJD = Misc.GetMJD(DateTime.Now);
            }
        }
Ejemplo n.º 4
0
        private void Parse(string[] lines)
        {
            int i;
            for (i = 0; i <= lines.Count()-1; i++)
            {
                switch (lines[i].ToUpperInvariant())
                {
                    case "BEGIN_DESC":
                        {
                            i++;
                            Description = lines[i];
                            i++;
                            while (!(lines[i] == "END_DESC"))
                            {
                                Description += '\n' + lines[i];
                                i++;
                            }
                            break;
                        }
                    case "BEGIN_ENVIRONMENT":
                        {
                            i++;
                            while (!(lines[i] == "END_ENVIRONMENT"))
                            {
                                string[] content = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                                switch (content[0].ToUpperInvariant())
                                {
                                    case "SYSTEM":
                                        System = content[1];
                                        break;
                                    case "DATE":
                                        switch (content[1])
                                        {
                                            case "MJD":
                                                MJD = double.Parse(content[2]);
                                                break;
                                            case "JD":
                                                MJD = double.Parse(content[2]) + 2400000.5;
                                                break;
                                            default:
                                                //MJD = Misc.GetMJD(DateTime.Now); // Wrong: we should only indicate there's no MJD data
                                                MJD = -1d; // Will trigger 'HasMJD = false'
                                                break;
                                        }
                                        break;
                                    case "HELP":
                                        Help = content[1];
                                        break;
                                    case "SCRIPT":
                                        Script = content[1];
                                        break;
                                }

                                i++;
                            }
                            break;
                        }
                    case "BEGIN_CAMERA":
                        {
                            OrbCamera cam = new OrbCamera();

                            while (lines[i] != "END_CAMERA")
                            {
                                string[] line = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                                switch (line[0].ToUpperInvariant())
                                {
                                    case "MODE":
                                        if (line[1] == "Extern") cam.Mode = OrbCamera.CameraMode.Extern;
                                        else cam.Mode = OrbCamera.CameraMode.GlassCockpit;

                                        break;
                                    case "TARGET":
                                        cam.Target = line[1];

                                        break;
                                    case "POS":
                                        try { cam.Pos = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])); }
                                        catch { }

                                        break;
                                    case "TRACKMODE":
                                        OrbCamera.CameraTrackMode tmode;
                                        if(Enum.TryParse<OrbCamera.CameraTrackMode>(line[1], out tmode)) cam.TrackMode = tmode;

                                        try { cam.RefBody = line[2]; }
                                        catch { }

                                        break;
                                    case "GROUNDLOCATION":
                                        if (line.Length < 4) break;
                                        cam.GroundLocation = new double[] { double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3]) };

                                        break;
                                    case "GROUNDDIRECTION":
                                        if (line.Length < 3) break;
                                        cam.GroundDirection = new double[] { double.Parse(line[1]), double.Parse(line[2]) };

                                        break;
                                    case "FOV":
                                        cam.FieldOfView = double.Parse(line[1]);

                                        break;
                                }
                                i++;
                            }
                            Camera = cam;

                            break;
                        }
                    case "BEGIN_PANEL":
                        Camera.Mode = OrbCamera.CameraMode.PanelCockpit;
                        while (lines[i] != "END_PANEL")
                        {
                            i++;
                        }

                        break;
                    case "BEGIN_VC":
                        Camera.Mode = OrbCamera.CameraMode.VirtualCockpit;
                        while (lines[i]!="END_VC")
                        {
                            i++;
                        }

                        break;
                    case "BEGIN_HUD":
                        i++;
                        while (lines[i]!="END_HUD")
                        {
                            string[] line2 = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            switch (line2[0].ToUpperInvariant())
                            {
                                case "TYPE":
                                    OrbHUD hud = OrbHUD.None;
                                    Enum.TryParse<OrbHUD>(line2[1], out hud);
                                    HUDmode = hud;

                                    break;
                            }

                            i++;
                        }

                        break;
                    case "BEGIN_SHIPS":
                        {
                            OrbVessel ship = new OrbVessel();

                            i++;
                            string[] content = lines[i].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

                            if (content.Count() == 2)
                            {
                                ship.Name = content[0];
                                ship.VesselClass = content[1];

                                i++;
                                while (!(lines[i] == "END"))
                                {
                                    string[] line = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                                    switch (line[0].ToUpperInvariant())
                                    {
                                        case "STATUS":
                                                ship.Status = line[1];
                                                ship.RefBody = line[2];
                                                break;
                                        case "POS":
                                                ship.SetPOS(Double.Parse(line[2]), double.Parse(line[1]));
                                                break;
                                        case "HEADING":
                                                ship.Heading = double.Parse(line[1]);
                                                break;
                                        case "RPOS":
                                                ship.RPos = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3]));
                                                break;
                                        case "RVEL":
                                                ship.RVel = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3]));
                                                break;
                                        case "AROT":
                                                ship.ARot = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3]));
                                                break;
                                        case "VROT":
                                                ship.VRot = new Vector3(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3]));
                                                break;
                                        case "FUEL":
                                            {
                                                ship.Fuel = float.Parse(line[1]);
                                                break;
                                            }
                                        case "PRPLEVEL":
                                            {
                                                List<OrbLevels> level = new List<OrbLevels>();
                                                for (int j = 1; j < line.Count()-1; j++)
                                                {
                                                    string[] split = line[j].Split(':');
                                                    level.Add(new OrbLevels(int.Parse(split[0]), float.Parse(split[1])));
                                                }
                                                ship.PrpLevel = level;
                                                break;
                                            }
                                        case "THLEVEL":
                                            {
                                                List<OrbLevels> throttles = new List<OrbLevels>();
                                                for (int j = 1; j < line.Count()-1; j++)
                                                {
                                                    string[] split = line[j].Split(':');
                                                    throttles.Add(new OrbLevels(int.Parse(split[0]), float.Parse(split[1])));
                                                }
                                                ship.ThLevel = throttles;
                                                break;
                                            }
                                        case "DOCKINFO":
                                            {
                                                List<OrbDockInfo> dockinfo = new List<OrbDockInfo>();
                                                for (int j = 1; j<line.Count() - 1; j++)
                                                {
                                                    string[] split = line[j].Split(':');
                                                    dockinfo.Add(new OrbDockInfo { DockID = int.Parse(split[0]), TargetDockID = int.Parse(split[1]), TargetVessel = split[2] });
                                                }
                                                ship.DockInfo = dockinfo;
                                                break;
                                            }
                                        default:
                                            {
                                                string key = line[0];
                                                string value = "";
                                                for (int j = 1; j < line.Count(); j++)
                                                {
                                                    value += line[j] + " ";
                                                }
                                                ship.Extra.Add(key, value.Trim());

                                                break;
                                            }
                                    }

                                    i++;
                                }
                            }
                        }

                        break;
                }
            }
            if (MJD == 0) MJD = Misc.GetMJD(DateTime.Now);
        }