Beispiel #1
0
        /// <summary>
        ///     生産中建物を構文解析する
        /// </summary>
        /// <param name="lexer">字句解析器</param>
        /// <returns>生産中建物</returns>
        private static BuildingDevelopment ParseBuildingDevelopment(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;
            }

            BuildingDevelopment building = new BuildingDevelopment();
            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の組
                    building.Id = id;
                    continue;
                }

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

                    // 名前
                    building.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)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        continue;
                    }

                    string s = token.Value as string;
                    if (string.IsNullOrEmpty(s))
                    {
                        return null;
                    }
                    s = s.ToLower();

                    if (!Scenarios.BuildingStrings.Contains(s))
                    {
                        // 無効なトークン
                        Log.InvalidToken(LogCategory, token, lexer);
                        continue;
                    }

                    // 建物の種類
                    building.Type = (BuildingType) Array.IndexOf(Scenarios.BuildingStrings, s);
                    continue;
                }

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

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

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

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

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

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

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

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

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

                    // 進捗率増分
                    building.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;
                    }

                    // 総進捗率
                    building.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;
                    }

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

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

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

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

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

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

                    // 完了日数
                    building.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単位の完了日数
                    building.DaysForFirst = (int) n;
                    continue;
                }

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

                    // 停止中
                    building.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;
                    }

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

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

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

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

            return building;
        }
Beispiel #2
0
 /// <summary>
 ///     生産中建物を書き出す
 /// </summary>
 /// <param name="building">生産中建物</param>
 /// <param name="writer">ファイル書き込み用</param>
 private static void WriteBuildingDevelopment(BuildingDevelopment building, TextWriter writer)
 {
     writer.WriteLine("  province_development = {");
     if (building.Id != null)
     {
         writer.Write("    id             = ");
         WriteTypeId(building.Id, writer);
         writer.WriteLine();
     }
     if (building.Name != null)
     {
         writer.WriteLine("    name           = \"{0}\"", building.Name);
     }
     if (building.Progress > 0)
     {
         writer.WriteLine("    progress       = {0}", DoubleHelper.ToString4(building.Progress));
     }
     if (building.Location > 0)
     {
         writer.WriteLine("    location       = {0}", building.Location);
     }
     if (building.Cost > 0)
     {
         writer.WriteLine("    cost           = {0}", DoubleHelper.ToString4(building.Cost));
     }
     if (building.Date != null)
     {
         writer.Write("    date           = ");
         WriteDate(building.Date, writer);
         writer.WriteLine();
     }
     if (building.Manpower > 0)
     {
         writer.WriteLine("    manpower       = {0}", DoubleHelper.ToString4(building.Manpower));
     }
     if (Game.Type == GameType.ArsenalOfDemocracy)
     {
         if (building.Halted)
         {
             writer.WriteLine("    halted         = yes");
         }
         writer.WriteLine("    close_when_finished = {0}", BoolHelper.ToString(building.CloseWhenFinished));
         writer.WriteLine("    waitingforclosure = {0}", BoolHelper.ToString(building.WaitingForClosure));
     }
     if (building.TotalProgress > 0)
     {
         writer.WriteLine("    total_progress = {0}", DoubleHelper.ToString4(building.Progress));
     }
     if (building.Size > 0)
     {
         writer.WriteLine("    size           = {0}", building.Size);
     }
     if (building.Done > 0)
     {
         writer.WriteLine("    done           = {0}", building.Done);
     }
     if (building.Days > 0)
     {
         writer.WriteLine("    days           = {0}", building.Days);
     }
     if (building.DaysForFirst > 0)
     {
         writer.WriteLine("    days_for_first = {0}", building.DaysForFirst);
     }
     if (building.GearingBonus > 0)
     {
         writer.WriteLine("    gearing_bonus  = {0}", DoubleHelper.ToString4(building.GearingBonus));
     }
     writer.WriteLine("    type           = {0}", Scenarios.BuildingStrings[(int) building.Type]);
     writer.WriteLine("  }");
 }