Пример #1
0
        /// <summary>
        ///     生産中輸送船団を構文解析する
        /// </summary>
        /// <param name="lexer">字句解析器</param>
        /// <returns>生産中輸送船団</returns>
        private static ConvoyDevelopment ParseConvoyDevelopment(TextLexer lexer)
        {
            // =
            Token token = lexer.GetToken();
            if (token.Type != TokenType.Equal)
            {
                Log.InvalidToken(LogCategory, token, lexer);
                return null;
            }

            // {
            token = lexer.GetToken();
            if (token.Type != TokenType.OpenBrace)
            {
                Log.InvalidToken(LogCategory, token, lexer);
                return null;
            }

            ConvoyDevelopment convoy = new ConvoyDevelopment();
            while (true)
            {
                token = lexer.GetToken();

                // ファイルの終端
                if (token == null)
                {
                    break;
                }

                // } (セクション終端)
                if (token.Type == TokenType.CloseBrace)
                {
                    break;
                }

                // 無効なトークン
                if (token.Type != TokenType.Identifier)
                {
                    Log.InvalidToken(LogCategory, token, lexer);
                    lexer.SkipLine();
                    continue;
                }

                string keyword = token.Value as string;
                if (string.IsNullOrEmpty(keyword))
                {
                    continue;
                }
                keyword = keyword.ToLower();

                // id
                if (keyword.Equals("id"))
                {
                    TypeId id = ParseTypeId(lexer);
                    if (id == null)
                    {
                        Log.InvalidSection(LogCategory, "id", lexer);
                        continue;
                    }

                    // typeとidの組
                    convoy.Id = id;
                    continue;
                }

                // name
                if (keyword.Equals("name"))
                {
                    string s = ParseString(lexer);
                    if (s == null)
                    {
                        Log.InvalidClause(LogCategory, "name", lexer);
                        continue;
                    }

                    // 名前
                    convoy.Name = s;
                    continue;
                }

                // type
                if (keyword.Equals("type"))
                {
                    // =
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Equal)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    token = lexer.GetToken();
                    if (token.Type == TokenType.Identifier)
                    {
                        // 無効なトークン
                        string s = token.Value as string;
                        if (string.IsNullOrEmpty(s))
                        {
                            continue;
                        }
                        s = s.ToLower();

                        // transports
                        if (s.Equals("transports"))
                        {
                            // 輸送船
                            convoy.Type = ConvoyType.Transports;
                            continue;
                        }

                        if (s.Equals("escorts"))
                        {
                            // 護衛艦
                            convoy.Type = ConvoyType.Escorts;
                            continue;
                        }
                    }

                    // 無効なトークン
                    Log.InvalidToken(LogCategory, token, lexer);
                    continue;
                }

                // location
                if (keyword.Equals("location"))
                {
                    int? n = ParseInt(lexer);
                    if (!n.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "location", lexer);
                        continue;
                    }

                    // 位置
                    convoy.Location = (int) n;
                    continue;
                }

                // cost
                if (keyword.Equals("cost"))
                {
                    double? d = ParseDouble(lexer);
                    if (!d.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "cost", lexer);
                        continue;
                    }

                    // 必要IC
                    convoy.Cost = (double) d;
                    continue;
                }

                // manpower
                if (keyword.Equals("manpower"))
                {
                    double? d = ParseDouble(lexer);
                    if (!d.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "manpower", lexer);
                        continue;
                    }

                    // 必要人的資源
                    convoy.Manpower = (double) d;
                    continue;
                }

                // date
                if (keyword.Equals("date"))
                {
                    GameDate date = ParseDate(lexer);
                    if (date == null)
                    {
                        Log.InvalidSection(LogCategory, "date", lexer);
                        continue;
                    }

                    // 完了予定日
                    convoy.Date = date;
                    continue;
                }

                // progress
                if (keyword.Equals("progress"))
                {
                    double? d = ParseDouble(lexer);
                    if (!d.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "progress", lexer);
                        continue;
                    }

                    // 進捗率増分
                    convoy.Progress = (double) d;
                    continue;
                }

                // total_progress
                if (keyword.Equals("total_progress"))
                {
                    double? d = ParseDouble(lexer);
                    if (!d.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "total_progress", lexer);
                        continue;
                    }

                    // 総進捗率
                    convoy.TotalProgress = (double) d;
                    continue;
                }

                // gearing_bonus
                if (keyword.Equals("gearing_bonus"))
                {
                    double? d = ParseDouble(lexer);
                    if (!d.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "gearing_bonus", lexer);
                        continue;
                    }

                    // 連続生産ボーナス
                    convoy.GearingBonus = (double) d;
                    continue;
                }

                // size
                if (keyword.Equals("size"))
                {
                    int? n = ParseInt(lexer);
                    if (!n.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "size", lexer);
                        continue;
                    }

                    // 総生産数
                    convoy.Size = (int) n;
                    continue;
                }

                // done
                if (keyword.Equals("done"))
                {
                    int? n = ParseInt(lexer);
                    if (!n.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "done", lexer);
                        continue;
                    }

                    // 生産完了数
                    convoy.Done = (int) n;
                    continue;
                }

                // days
                if (keyword.Equals("days"))
                {
                    int? n = ParseInt(lexer);
                    if (!n.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "days", lexer);
                        continue;
                    }

                    // 完了日数
                    convoy.Days = (int) n;
                    continue;
                }

                // days_for_first
                if (keyword.Equals("days_for_first"))
                {
                    int? n = ParseInt(lexer);
                    if (!n.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "days_for_first", lexer);
                        continue;
                    }

                    // 1単位の完了日数
                    convoy.DaysForFirst = (int) n;
                    continue;
                }

                // halted
                if (keyword.Equals("halted"))
                {
                    bool? b = ParseBool(lexer);
                    if (!b.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "halted", lexer);
                        continue;
                    }

                    // 停止中
                    convoy.Halted = (bool) b;
                    continue;
                }

                // close_when_finished
                if (keyword.Equals("close_when_finished"))
                {
                    bool? b = ParseBool(lexer);
                    if (!b.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "close_when_finished", lexer);
                        continue;
                    }

                    // 完了時にキューを削除するかどうか
                    convoy.CloseWhenFinished = (bool) b;
                    continue;
                }

                // waitingforclosure
                if (keyword.Equals("waitingforclosure"))
                {
                    bool? b = ParseBool(lexer);
                    if (!b.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "waitingforclosure", lexer);
                        continue;
                    }

                    // waitingforclosure (詳細不明)
                    convoy.WaitingForClosure = (bool) b;
                    continue;
                }

                // retooling_time
                if (keyword.Equals("retooling_time"))
                {
                    double? d = ParseDouble(lexer);
                    if (!d.HasValue)
                    {
                        Log.InvalidClause(LogCategory, "retooling_time", lexer);
                        continue;
                    }

                    // 生産ライン準備時間
                    convoy.RetoolingTime = (double) d;
                    continue;
                }

                // 無効なトークン
                Log.InvalidToken(LogCategory, token, lexer);
                lexer.SkipLine();
            }

            return convoy;
        }
Пример #2
0
 /// <summary>
 ///     生産中輸送船団を書き出す
 /// </summary>
 /// <param name="convoy">生産中輸送船団</param>
 /// <param name="writer">ファイル書き込み用</param>
 private static void WriteConvoyDevelopment(ConvoyDevelopment convoy, TextWriter writer)
 {
     writer.WriteLine("  convoy_development = {");
     if (convoy.Id != null)
     {
         writer.Write("    id             = ");
         WriteTypeId(convoy.Id, writer);
         writer.WriteLine();
     }
     if (convoy.Name != null)
     {
         writer.WriteLine("    name           = \"{0}\"", convoy.Name);
     }
     if (convoy.Progress > 0)
     {
         writer.WriteLine("    progress       = {0}", DoubleHelper.ToString4(convoy.Progress));
     }
     if (convoy.Location > 0)
     {
         writer.WriteLine("    location       = {0}", convoy.Location);
     }
     if (convoy.Cost > 0)
     {
         writer.WriteLine("    cost           = {0}", DoubleHelper.ToString4(convoy.Cost));
     }
     if (convoy.Date != null)
     {
         writer.Write("    date           = ");
         WriteDate(convoy.Date, writer);
         writer.WriteLine();
     }
     if (convoy.Manpower > 0)
     {
         writer.WriteLine("    manpower       = {0}", DoubleHelper.ToString4(convoy.Manpower));
     }
     if (Game.Type == GameType.ArsenalOfDemocracy)
     {
         if (convoy.Halted)
         {
             writer.WriteLine("    halted         = yes");
         }
         writer.WriteLine("    close_when_finished = {0}", BoolHelper.ToString(convoy.CloseWhenFinished));
         writer.WriteLine("    waitingforclosure = {0}", BoolHelper.ToString(convoy.WaitingForClosure));
         if (convoy.RetoolingTime > 0)
         {
             writer.WriteLine("    retooling_time = {0}", DoubleHelper.ToString4(convoy.RetoolingTime));
         }
     }
     if (convoy.TotalProgress > 0)
     {
         writer.WriteLine("    total_progress = {0}", DoubleHelper.ToString4(convoy.Progress));
     }
     if (convoy.Size > 0)
     {
         writer.WriteLine("    size           = {0}", convoy.Size);
     }
     if (convoy.Done > 0)
     {
         writer.WriteLine("    done           = {0}", convoy.Done);
     }
     if (convoy.Days > 0)
     {
         writer.WriteLine("    days           = {0}", convoy.Days);
     }
     if (convoy.DaysForFirst > 0)
     {
         writer.WriteLine("    days_for_first = {0}", convoy.DaysForFirst);
     }
     if (convoy.GearingBonus > 0)
     {
         writer.WriteLine("    gearing_bonus  = {0}", DoubleHelper.ToString4(convoy.GearingBonus));
     }
     writer.WriteLine("    type           = {0}", Scenarios.ConvoyStrings[(int) convoy.Type]);
     writer.WriteLine("  }");
 }