Beispiel #1
0
        } // end getavailiblesavegames

        public List <Dictionary <string, string> > GetAvailibleHubNames()
        {
            List <Dictionary <string, string> > airports = new List <Dictionary <string, string> >();

            this.SetPaths();
            StreamReader  stream             = new StreamReader(ConfigPath + "\\airports.dat");
            DataCsvLoader csv                = new DataCsvLoader(stream, false, true);
            Dictionary <string, string> line = csv.GetNextLineHeaders();

            while (line != null)
            {
                if (line["IsHub"] == "1")
                {
                    airports.Add(line);
                }
                line = csv.GetNextLineHeaders();
            }

            return(airports);
        }
Beispiel #2
0
        } // end constructor

        /* This copies all the files to a new savegamefolder and then loads the savegame */
        public SaveGame(String hub, String code, String name)
        {
            SaveGamePublic.SaveGame = this;
            this.SetPaths();
            // Get Config Path
            // Check Code
            // check if name already exists

            if (code.Length < 2 || code.Length > 3)
            {
                throw new SaveGameException("Code " + code + " must be 2 or 3 digits long");
            }
            code = code.ToUpper();


            // Check letters
            string pattern = @"^[a-zA-Z]+$";
            Regex  regex   = new Regex(pattern);

            if (!regex.IsMatch(code))
            {
                throw new SaveGameException("Code " + code + " is not valid.");
            }


            // Check Savegamefolder

            if (code == "CON" || Directory.Exists(SaveGameFolder + "\\" + code))
            {
                throw new SaveGameException("Savegame" + code + " already exists.");
            }

            // Create Directory
            //Debug.Write("Creating Directory: " + SaveGameFolder + "\\" + code, 2);
            ConcreteSaveGameFolder = SaveGameFolder + "\\" + code;
            Directory.CreateDirectory(ConcreteSaveGameFolder);

            // Load Continents
            Debug.Write("Loading Continents", 3);
            StreamReader     stream     = new StreamReader(ConfigPath + "\\Continents.dat");
            DataCsvLoader    csv        = new DataCsvLoader(stream, true);
            List <Continent> continents = new List <Continent>();

            string[] line = csv.GetNextLine();
            do
            {
                String contcode = line[0];
                String contname = line[1];
                int[]  weather  = new int[12];
                for (int i = 2; i < 14; i++)
                {
                    weather[i - 2] = Int32.Parse(line[i]);
                }
                Continent c = new Continent(contcode, contname, weather);
                line = csv.GetNextLine();
            } while (line != null);
            stream = null;


            // Initialize Countries
            Debug.Write("Loading Countries", 3);
            stream = new StreamReader(ConfigPath + "\\Countries.dat");
            csv    = new DataCsvLoader(stream, true);
            line   = csv.GetNextLine();
            while (line != null)
            {
                if (!this.Continents.ContainsKey(line[2]))
                {
                    throw new Exception("Continent not found: " + line[3]);
                }
                Continent cont    = this.Continents[line[2]];
                Country   country = new Country(line[0], line[1], cont);
                line = csv.GetNextLine();
            }

            // Initialize Regions
            Debug.Write("Loading Regions", 3);
            stream = new StreamReader(ConfigPath + "\\regions.dat");
            csv    = new DataCsvLoader(stream, true);
            line   = csv.GetNextLine();
            while (line != null)
            {
                if (!this.Countries.ContainsKey(line[1]))
                {
                    throw new Exception("Country not found: " + line[1]);
                }
                Country c = this.Countries[line[1]];
                Region  r = new Region(line[0], line[2], c);
                line = csv.GetNextLine();
            }

            // Initalize Airports
            Debug.Write("Loading Airports", 3);

            stream = new StreamReader(ConfigPath + "\\airports.dat");
            csv    = new DataCsvLoader(stream, true);
            line   = csv.GetNextLine();
            while (line != null)
            {
                if (!this.Regions.ContainsKey(line[2]))
                {
                    throw new Exception("Region not found: " + line[2]);
                }
                Region r = this.Regions[line[2]];
                bool   Ishub;
                if (line[5] == "1")
                {
                    Ishub = true;
                }
                else
                {
                    Ishub = false;
                }

                GeoCoordinate g;
                short         RunwayLength;
                short         RunwayCount;
                short         slots;
                int           passengers;

                try
                {
                    g            = new GeoCoordinate(Decimal.Parse(line[6]), Decimal.Parse(line[7]), Int32.Parse(line[8]));
                    RunwayLength = Int16.Parse(line[10]);
                    RunwayCount  = Int16.Parse(line[11]);
                    slots        = Int16.Parse(line[12]);
                    passengers   = Int32.Parse(line[13]);
                } catch (FormatException e)
                {
                    Debug.Write(e.Message);
                    throw new SaveGameException("Airport data corrupted. Airport: " + line[0] + "Not a number:"
                                                + line[6] + ", " + line[8] + ", " + line[8] + ", " + line[10] + ", " + line[11] + ", " + line[12] + ", " + line[13]
                                                );
                }

                Airport a = new Airport(line[0], line[1], line[4], r, Ishub, g, line[9], line[3], RunwayLength, RunwayCount, slots, passengers);
                foreach (KeyValuePair <String, Airport> b in this.Airports)
                {
                    if (a.Continent.Code == b.Value.Continent.Code)
                    {
                        Connection c = new Connection(a, b.Value);
                        if (c.Distance < 200 && a.Iata != b.Key)
                        {
                            c = c.Register();
                            Models.Routing.Path p = new GroundPath(c);
                        }
                    }
                } // end Floreach

                line = csv.GetNextLine();
            } // End Load Airports



            // Loading Manufacturers
            Debug.Write("Loading Manufacturers", 3);
            stream = new StreamReader(ConfigPath + "\\manufacturers.dat");
            csv    = new DataCsvLoader(stream, false, true);
            Dictionary <string, string> dic = csv.GetNextLineHeaders();

            while (dic != null)
            {
                Manufacturer M = new Manufacturer(dic["Manufacturer"],
                                                  Int32.Parse(dic["Parallel"]),
                                                  Int32.Parse(dic["PointsPerDay"])
                                                  );
                dic = csv.GetNextLineHeaders();
            }

            // Loading Manufacturers
            Debug.Write("Loading Aircrafts", 3);
            stream = new StreamReader(ConfigPath + "\\aircraft.dat");
            csv    = new DataCsvLoader(stream, false, true);
            dic    = csv.GetNextLineHeaders();
            while (dic != null)
            {
                Aircraft A = new Aircraft(dic);
                dic = csv.GetNextLineHeaders();
            }

            Debug.Write("Creating Player Airline");
            this.AirlinePlayer = new PlayerAirline(code, name, this.Airports[hub]);



            Debug.Write("Load complete", 1);
            this.Save();
        } // End constructor