Ejemplo n.º 1
0
        public static void Init()
        {
            try
            {
                Reset();

                foreach (string str in System.IO.Directory.GetDirectories(Application.StartupPath + "\\data\\trains\\resources"))
                {
                    string[] l = System.IO.File.ReadAllLines(str + @"\data.xml", System.Text.Encoding.Default);
                    if (l[0] == @"<locomotive>")
                    {
                        Locomotive loc = new Locomotive();
                        loc.Load(str.Substring(str.LastIndexOf('\\') + 1, str.Length - str.LastIndexOf('\\') - 1));

                        Locomotives.Add(loc);
                        continue;
                    }
                    else if (l[0] == @"<coach>")
                    {
                        Coach car = new Coach();
                        car.Load(str.Substring(str.LastIndexOf('\\') + 1, str.Length - str.LastIndexOf('\\') - 1));

                        Coachs.Add(car);
                        continue;
                    }
                    else if (l[0] == @"<enginecoach>")
                    {
                        EngineCoach lc = new EngineCoach();
                        lc.Load(str.Substring(str.LastIndexOf('\\') + 1, str.Length - str.LastIndexOf('\\') - 1));

                        EngineCoachs.Add(lc);
                        continue;
                    }
                }

                foreach (string str in System.IO.Directory.GetDirectories(".\\data\\trains\\datas"))
                {
                    TrainData train = new TrainData();
                    train.Load(str.Substring(str.LastIndexOf('\\') + 1, str.Length - str.LastIndexOf('\\') - 1));

                    TrainDatas.Add(train);
                }
            }
            catch (Exception e)
            {
                Environment.ReportError(e, AccessManager.AccessKey);
            }
        }
Ejemplo n.º 2
0
        private decimal CalcDefIncome()
        {
            try
            {
                decimal res = 0;

                #region 열차 유지비
                foreach (var r in GameManager.RouteMgr.Routes)
                {
                    if (r.Owner != this)
                    {
                        continue;
                    }
                    foreach (var it in r.Trains)
                    {
                        res -= it.Data.Maintenance;
                    }
                }
                #endregion
                #region 세금
                res -= GameManager.GameRule.CalcTax(this);
                #endregion
                #region 노선 수익
                foreach (var it in GameManager.RouteMgr.Routes)
                {
                    if (it.Owner != this)
                    {
                        continue;
                    }

                    long pass_carry    = 0;
                    long freight_carry = 0;

                    foreach (var t in it.Trains)
                    {
                        foreach (TrainParant a in t.Data.Args)
                        {
                            if (a is Locomotive)
                            {
                                continue;
                            }

                            if (a is Coach)
                            {
                                Coach c = (Coach)a;

                                if (c.Rank == Coach.CarriageRank.FREIGHT)
                                {
                                    freight_carry += c.Carrying;
                                }
                                else
                                {
                                    pass_carry += c.Carrying;
                                }
                            }
                            else if (a is EngineCoach)
                            {
                                EngineCoach lc = (EngineCoach)a;

                                if (lc.Coach.Rank == EngineCoach.CoachData.CoachRank.FREIGHT)
                                {
                                    freight_carry += lc.Coach.Carrying;
                                }
                                else
                                {
                                    pass_carry += lc.Coach.Carrying;
                                }
                            }
                        }
                    }

                    int use = it.UseMoney;
                    if (it.Type == Route.RouteType.HIGH)
                    {
                        use = use + Convert.ToInt32(use * 0.3);
                    }

                    long pass_visit    = 0;
                    long freight_visit = 0;
                    long double_visit  = 0;

                    foreach (var s in it.Stations)
                    {
                        if (s.Type == Station.StationType.DOUBLE)
                        {
                            double_visit += s.Visitor;
                        }
                        else if (s.Type == Station.StationType.PASSENGER)
                        {
                            pass_visit += s.Visitor;
                        }
                        else if (s.Type == Station.StationType.FREIGHT)
                        {
                            freight_visit += s.Visitor;
                        }
                    }

                    res += GameManager.GameRule.CalcRouteIncome(pass_visit + (double_visit / 2), pass_carry, use);
                    res += GameManager.GameRule.CalcRouteIncome(freight_visit + (double_visit / 2), freight_carry, use);
                }
                #endregion

                return(res);
            }
            catch (Exception ex)
            {
                Environment.ReportError(ex, AccessManager.AccessKey);
                return(0);
            }
        }
Ejemplo n.º 3
0
        public void Load(string name)
        {
            try
            {
                string path = ".\\data\\trains\\datas\\" + name;

                XmlDocument xml = new XmlDocument();
                xml.Load(path + "\\data.xml");

                XmlNode root = xml.SelectNodes("traindata")[0];
                string  args = root.SelectNodes("args")[0].InnerText;
                Name  = root.SelectNodes("name")[0].InnerText;
                Image = Image.FromFile(path + @"\" + root.SelectNodes("image")[0].InnerText);

                XmlDocument arg = new XmlDocument();
                arg.Load(path + "\\" + args);

                XmlNode _args = arg.SelectNodes("args")[0];
                foreach (XmlNode it in _args.SelectNodes("arg"))
                {
                    if (it.Attributes["type"].Value == "locomotive")
                    {
                        if (TrainManager.GetLocomotiveByName(it.Attributes["name"].Value) == null)
                        {
                            throw new WrongTrainDataException("해당 이름을 가진 기관차가 없습니다.");
                        }

                        Locomotive t = TrainManager.Locomotives.First(x => x.Name == it.Attributes["name"].Value);

                        Args.Add(t);
                    }
                    else if (it.Attributes["type"].Value == "coach")
                    {
                        if (TrainManager.GetCoachByName(it.Attributes["name"].Value) == null)
                        {
                            throw new WrongTrainDataException("해당 이름을 가진 객차가 없습니다.");
                        }

                        Coach t = TrainManager.Coachs.First(x => x.Name == it.Attributes["name"].Value);

                        Args.Add(t);
                    }
                    else if (it.Attributes["type"].Value == "enginecoach")
                    {
                        if (TrainManager.GetEngineCoachByName(it.Attributes["name"].Value) == null)
                        {
                            throw new WrongTrainDataException("해당 이름을 가진 객차가 없습니다.");
                        }

                        EngineCoach ec = TrainManager.GetEngineCoachByName(it.Attributes["name"].Value);

                        Args.Add(ec);
                    }
                    else
                    {
                        throw new WrongTrainDataException("'" + it.Attributes["type"].Value + "' 라는 type 은 없습니다.");
                    }
                }

                // 검사
                if (Args.Count <= 1)
                {
                    throw new WrongTrainDataException("기관차와 객차의 수를 합친 수가 1 이하 입니다. 최소한 2 이상이여야 합니다.");
                }

                List <Locomotive>  loc   = new List <Locomotive>();
                List <EngineCoach> lc    = new List <EngineCoach>();
                List <TrainParant> loclc = new List <TrainParant>();

                foreach (var it in Args)
                {
                    if (it is Locomotive)
                    {
                        loc.Add((Locomotive)it);
                        loclc.Add(it);
                    }
                    else if (it is EngineCoach)
                    {
                        lc.Add((EngineCoach)it);
                        loclc.Add(it);
                    }
                }

                if (loc.Count + lc.Count == 0)                 // 0일 경우
                {
                    throw new WrongTrainDataException("기관차의 수가 0 입니다.");
                }

                long carry = 0;
                foreach (var it in loc)
                {
                    carry += it.Carrying;
                }
                foreach (var it in lc)
                {
                    carry += it.Locomotive.Carrying;
                }

                List <Coach> car = new List <Coach>();
                foreach (var it in Args)
                {
                    if (it is Coach)
                    {
                        car.Add((Coach)it);
                    }
                }

                if (car.Count > carry)                 //최대 연결 허용량보다 연결된게 더 높으면
                {
                    throw new WrongTrainDataException("기관차가 최대한 연결할 수 있는 객차 수보다 더 많은 객차가 연결 되었습니다.");
                }

                if (loc.Count + lc.Count > 1)                 // 1보다 크면
                {
                    int k = 0;
                    if (loclc[0] is Locomotive)
                    {
                        k = (int)((loclc[0] as Locomotive).Rank);
                    }
                    else if (loclc[1] is EngineCoach)
                    {
                        k = (int)((loclc[0] as EngineCoach).Locomotive.Rank);
                    }

                    foreach (var it in loclc)
                    {
                        if (it is Locomotive)
                        {
                            if ((int)((it as Locomotive).Rank) != k)
                            {
                                throw new WrongTrainDataException("기관차의 수가 1 보다 클 경우 기관차들의 등급이 같아야 합니다.");
                            }
                        }
                        else if (it is EngineCoach)
                        {
                            if ((int)((it as EngineCoach).Locomotive.Rank) != k)
                            {
                                throw new WrongTrainDataException("기관차의 수가 1 보다 클 경우 기관차들의 등급이 같아야 합니다.");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Environment.ReportError(e, AccessManager.AccessKey);
            }
        }