Ejemplo n.º 1
0
        public FlagData(ParseBlock Block)
        {
            Block.AddParser <FlagTemplate>("flag-template", i => new FlagTemplate(i));
            Block.AddParser <GraphNode <Vector2f[]> >("node",
                                                      i => new GraphNode <Vector2f[]>(Cardamom.Interface.ClassLibrary.Instance.ParseVector2fs(i.String)));

            foreach (FlagTemplate template in Block.BreakToArray <FlagTemplate>())
            {
                _Templates.Add(template.Frequency, template);
            }
        }
Ejemplo n.º 2
0
        public LanguageGenerator(ParseBlock Block)
        {
            Block.AddParser <OrthographyBank>("orthogrphy", i => new OrthographyBank(i));
            Block.AddParser <Sound>("sound", i => new Sound(i));
            Block.AddParser <SoundPicker>("soundlocks", i => new SoundPicker(i));
            Block.AddParser <Matched>("symbol", i => new Matched(new Sound(i)));

            object[] attributes = Block.BreakToAttributes <object>(typeof(Attribute));
            _OrthographyBank = (OrthographyBank)attributes[(int)Attribute.ORTHOGRAPHY];
            _SoundPicker     = (SoundPicker)attributes[(int)Attribute.SOUNDLOCKS];
            _Sounds          = (List <Sound>)attributes[(int)Attribute.SOUNDS];
        }
Ejemplo n.º 3
0
        public void ReadBlock(ParseBlock 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 <Vector2f>("vector2f", i => ClassLibrary.Instance.ParseVector2f(i.String), false);
            Block.AddParser <Vector2f[]>("vector2f[]", i => ClassLibrary.Instance.ParseVector2fs(i.String), false);
            Block.AddParser <Font>("font", i => ClassLibrary.Instance.ParseFont(i.String));
            Block.AddParser <Sound>("sound", i => ClassLibrary.Instance.ParseSound(i.String));
            Block.AddParser <Texture>("texture", i => ClassLibrary.Instance.ParseTexture(i.String));
            Block.AddParser <Class>("class", i => new Class(i));
            Block.AddParser <SubClass>("mode", i => new SubClass(i));

            _Classes = (Dictionary <string, Class>)Block.BreakToDictionary <object>(true)["classes"];
        }
Ejemplo n.º 4
0
        public Economy(
            ParseBlock Block,
            Func <ParseBlock, Good> GoodParser         = null,
            Func <ParseBlock, Service> ServiceParser   = null,
            Func <ParseBlock, Resource> ResourceParser = null,
            Func <ParseBlock, Process> ProcessParser   = null)
        {
            Block.AddParser <Tangible>("tangible", i => new Tangible(i));
            Block.AddParser <Good>("good", GoodParser != null ? GoodParser : i => new Good(i));
            Block.AddParser <Service>("service", ServiceParser != null ? ServiceParser : i => new Service(i));
            Block.AddParser <Resource>("resource", ResourceParser != null ? ResourceParser : i => new Resource(i));
            Block.AddParser <Process>("process", ProcessParser != null ? ProcessParser : i => new Process(i));

            object[] attributes = Block.BreakToAttributes <object>(typeof(Attribute), true);
            _Processes = ((Dictionary <string, Process>)attributes[(int)Attribute.PROCESSES]);
            _Tangibles = ((Dictionary <string, Tangible>)attributes[(int)Attribute.TANGIBLES]);
            _Resources = ((Dictionary <string, Resource>)attributes[(int)Attribute.RESOURCES]);
            _Labor     = (Service)_Tangibles["labor"];
        }
Ejemplo n.º 5
0
        public Language(ParseBlock Block)
        {
            Block.AddParser <Sound>("sound",
                                    i =>
            {
                var s = new Sound(i);
                AddSound(s);
                return(s);
            });
            Block.AddParser <Generator <Sound> >("generator",
                                                 i =>
            {
                var g = new SingleGenerator <Sound>(i, OPERATORS, _Generators);
                _Generators.Add(i.Name, g);
                return(g);
            });
            Block.AddParser <ReplaceRule <Sound> >("replacer", i => new ReplaceRule <Sound>(i, OPERATORS, _Generators));
            Block.AddParser <PrintRule <Sound> >("orthography", i => new PrintRule <Sound>(i, OPERATORS, _Generators));

            object[] attributes = Block.BreakToAttributes <object>(typeof(Attribute));
            _Replacers = (List <ReplaceRule <Sound> >)attributes[(int)Attribute.REPLACERS];
            _Printers  = (List <PrintRule <Sound> >)attributes[(int)Attribute.ORTHOGRAPHY];
        }
Ejemplo n.º 6
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())));
            }
        }