Exemplo n.º 1
0
        static void Load(string Path, ParseBlock Block)
        {
            Cence.Module.AddParsers(Block);

            Block.AddParser <Color>("color", i => ClassLibrary.Instance.ParseColor(i.String), false);
            Block.AddParser <List <Color> >("color[]", i => ClassLibrary.Instance.ParseColors(i.String), false);
            Block.AddParser <Dictionary <string, Color> >("color<>", i => i.BreakToDictionary <Color>(), false);

            Block.AddParser <Polygon>("zone", i => new Polygon(i));
            Block.AddParser <Coordinate>();
            Block.AddParser <TileBase>();
            Block.AddParser <TileEdge>();
            Block.AddParser <TilePathOverlay>();
            Block.AddParser <WeaponClass>();
            Block.AddParser <UnitClass>();
            Block.AddParser <UnitWeight>();
            Block.AddParser <UnitStatus>();
            Block.AddParser <BlockType>();
            Block.AddParser <Front>();
            Block.AddParser <Weapon>();

            Block.AddParser <MovementRule>();
            Block.AddParser <UnitMovementRules>();
            Block.AddParser <Faction>();
            Block.AddParser <UnitConfiguration>();
            Block.AddParser <UnitConstraints>();
            Block.AddParser <UnitConfigurationLink>();
            Block.AddParser <UnitConfigurationLock>();
            Block.AddParser <FormationFeature>();
            Block.AddParser <FormationTemplate>("formation-template", i => null);
            Block.AddParser <CompositeFormationTemplate>();
            Block.AddParser <AtomicFormationTemplate>();
            Block.AddParser <BindingFormationTemplate>();
            Block.AddParser <FilteringFormationTemplate>();
            Block.AddParser <ParameterizingFormationTemplate>();
            Block.AddParser <ReplicatingFormationTemplate>();
            Block.AddParser <SelectingFormationTemplate>();
            Block.AddParser <SwitchingFormationTemplate>();
            Block.AddParser <Direction>();
            Block.AddParser <TerrainAttribute>();
            Block.AddParser <TileComponentRules>();
            Block.AddParser <TileRuleSet>();
            Block.AddParser <Environment>();

            Block.AddParsers <object>(MatcherSerializer.Instance.GetParsers());

            Block.AddParser <UnitGroup>();
            Block.AddParser <UnitCount>();
            Block.AddParser <ConvoyMovementAutomator>();
            Block.AddParser <PositionalDeploymentConfiguration>();
            Block.AddParser <ConvoyDeploymentConfiguration>();

            Block.AddParser <ObjectiveSuccessLevel>();
            Block.AddParser <VictoryCondition>();
            Block.AddParser <ObjectiveSuccessTrigger>();

            Block.AddParsers <Objective>(ObjectiveSerializer.Instance.GetParsers());

            Block.AddParser <ArmyConfiguration>();
            Block.AddParser <BoardConfiguration>();
            Block.AddParser <BoardCompositeMapConfiguration>(
                "map-configuration", i => new BoardCompositeMapConfiguration(i));
            Block.AddParser <RandomMapConfiguration>();
            Block.AddParsers <Sequence>(SequenceSerializer.Instance.GetParsers());
            Block.AddParser <TurnConfiguration>();
            Block.AddParser <ScenarioRules>();
            Block.AddParser <Scenario>();

            Block.AddParser <FactionRenderDetails>(
                "faction-render-details", i => new FactionRenderDetails(i, Path + "/FactionSymbols/"));
            Block.AddParser <UnitRenderDetails>(
                "unit-render-details", i => new UnitRenderDetails(i, Path + "/UnitSprites/"));
            Block.AddParser <TileRenderer>();
            Block.AddParser <MapGeneratorConfiguration>();
            Block.AddParser <TerrainGeneratorConfiguration>();
            Block.AddParser <MatchSetting>();
            Block.AddParser <MarkovGenerator <char> >(
                "name-generator", i => FileUtils.LoadLanguage(Path + "/NameGenerators/" + i.String));
            Block.AddParser <FeatureGenerator>();

            var attributes = Block.BreakToAttributes <object>(typeof(Attribute), true);

            UnitMovementRules  = (Dictionary <string, UnitMovementRules>)attributes[(int)Attribute.UNIT_MOVEMENT_RULES];
            TileComponentRules =
                (Dictionary <string, TileComponentRules>)attributes[(int)Attribute.TILE_COMPONENT_RULES];
            Environments         = (Dictionary <string, Environment>)attributes[(int)Attribute.ENVIRONMENTS];
            Factions             = (Dictionary <string, Faction>)attributes[(int)Attribute.FACTIONS];
            FactionRenderDetails =
                (Dictionary <string, FactionRenderDetails>)attributes[(int)Attribute.FACTION_RENDER_DETAILS];
            UnitConfigurations     = (Dictionary <string, UnitConfiguration>)attributes[(int)Attribute.UNIT_CONFIGURATIONS];
            UnitConfigurationLinks =
                (Dictionary <string, UnitConfigurationLink>)attributes[(int)Attribute.UNIT_CONFIGURATION_LINKS];
            UnitConfigurationLocks =
                (Dictionary <string, UnitConfigurationLock>)attributes[(int)Attribute.UNIT_CONFIGURATION_LOCKS];
            FormationTemplates = (Dictionary <string, FormationTemplate>)attributes[(int)Attribute.FORMATION_TEMPLATES];
            UnitRenderDetails  = (Dictionary <string, UnitRenderDetails>)attributes[(int)Attribute.UNIT_RENDER_DETAILS];
            Scenarios          = (List <Scenario>)attributes[(int)Attribute.SCENARIOS];
            TileRenderers      = (Dictionary <string, TileRenderer>)attributes[(int)Attribute.TILE_RENDERERS];
            NameGenerators     = (Dictionary <string, MarkovGenerator <char> >)attributes[(int)Attribute.NAME_GENERATORS];
            MatchSettings      = (Dictionary <string, MatchSetting>)attributes[(int)Attribute.MATCH_SETTINGS];

            // Emit warnings for units without configured render details.
            foreach (UnitConfiguration unit in UnitConfigurations.Values)
            {
                if (!UnitRenderDetails.ContainsKey(unit.UniqueKey))
                {
                    Console.WriteLine(
                        "[WARNING]: No render details configured for UnitConfiguration {0}", unit.UniqueKey);
                }
                else if (!File.Exists(UnitRenderDetails[unit.UniqueKey].ImagePath))
                {
                    Console.WriteLine(
                        "[WARNING]: Image {0} missing for UnitConfiguration {1}",
                        UnitRenderDetails[unit.UniqueKey].ImagePath,
                        unit.UniqueKey);
                }
            }

            // Emit warnings for factions without configured render details.
            foreach (Faction faction in Factions.Values)
            {
                if (!FactionRenderDetails.ContainsKey(faction.UniqueKey))
                {
                    Console.WriteLine(
                        "[WARNING]: No render details configured for Faction {0}", faction.UniqueKey);
                }
                else if (!File.Exists(FactionRenderDetails[faction.UniqueKey].ImagePath))
                {
                    Console.WriteLine(
                        "[WARNING]: Image {0} missing for Faction {1}",
                        FactionRenderDetails[faction.UniqueKey].ImagePath,
                        faction.UniqueKey);
                }
            }

            // Debug scenario configurations.
            foreach (Scenario s in Scenarios)
            {
                using (MemoryStream m = new MemoryStream())
                {
                    try
                    {
                        var stream = new SerializationOutputStream(m);
                        stream.Write(s);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("There was an error writing scenario {0}\n\n{1}", s.Name, e.Message);
                    }
                    m.Seek(0, SeekOrigin.Begin);
                    try
                    {
                        var stream = new SerializationInputStream(m);
                        var copy   = new Scenario(stream);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("There was an error reading scenario {0}\n\n{1}", s.Name, e);
                        Console.WriteLine(new HexDumpWriter(16).Write(m.GetBuffer()));
                    }
                }
            }

            var random     = new Random();
            var parameters =
                new ArmyParameters(
                    Factions["german"],
                    0,
                    0,
                    new ScenarioParameters(1940, MatchSettings["russia-winter"], 0, new Coordinate(0, 0), false));

            foreach (var template in FormationTemplates.Values)
            {
                Console.WriteLine(
                    string.Join(
                        "\n",
                        template.Generate(random, new FormationParameters(parameters)).Select(i => i.ToString())));
            }
        }