Esempio n. 1
0
 public void Copy(ArmyParameters Copy)
 {
     Faction    = Copy.Faction;
     Points     = Copy.Points;
     Team       = Copy.Team;
     Parameters = Copy.Parameters;
 }
Esempio n. 2
0
        void HandleChange(object Sender, EventArgs E)
        {
            ArmyParameters parameters = null;

            try
            {
                var points = Convert.ToUInt32(_PointsInput.Value);
                parameters =
                    new ArmyParameters(
                        _FactionSelect.Value.Value, points, _TeamSelect.Value.Value, ArmyBuilder.Parameters.Parameters);
            }
            catch (Exception e) { }
            if (parameters != null && OnParametersChanged != null)
            {
                OnParametersChanged(this, new ValuedEventArgs <ArmyParameters>(parameters));
            }
        }
Esempio n. 3
0
        public ArmyBuilderScreen(
            Vector2f WindowSize,
            IEnumerable <UnitConfigurationLink> UnitConfigurations,
            ArmyParameters Parameters,
            UnitConfigurationRenderer Renderer)
            : base(WindowSize)
        {
            _Parameters = Parameters;
            _Links      = UnitConfigurations;

            _Pane.Position = .5f * (WindowSize - _Pane.Size);

            var header = new Button("army-builder-header")
            {
                DisplayedString =
                    string.Format(
                        "{0} - {1} - {2}",
                        ObjectDescriber.Describe(Parameters.Faction),
                        ObjectDescriber.Describe(Parameters.Parameters.Setting.Front),
                        Parameters.Parameters.Year)
            };

            _UnitClassSelect.Position = new Vector2f(0, header.Size.Y);

            _AvailableUnits = new UnitConfigurationTable(
                "army-builder-table",
                "army-builder-table-row",
                "army-builder-table-cell",
                _Parameters.Faction,
                Renderer,
                false);
            _AvailableUnits.Position            = new Vector2f(0, _UnitClassSelect.Position.Y + _UnitClassSelect.Size.Y + 16);
            _AvailableUnits.OnUnitClicked      += HandleAddUnit;
            _AvailableUnits.OnUnitRightClicked += HandleUnitInfoRequested;

            _PointTotalButton          = new Button("army-builder-point-total");
            _PointTotalButton.Position = new Vector2f(_AvailableUnits.Size.X + 16, header.Size.Y);
            SetPointTotal(0);

            _SelectedUnits = new UnitConfigurationTable(
                "army-builder-table",
                "army-builder-table-row",
                "army-builder-table-cell",
                _Parameters.Faction,
                Renderer,
                true);
            _SelectedUnits.Position =
                new Vector2f(_AvailableUnits.Size.X + 16, _PointTotalButton.Position.Y + _PointTotalButton.Size.Y + 16);
            _SelectedUnits.OnUnitRightClicked += HandleRemoveUnit;

            foreach (UnitClass c in Enum.GetValues(typeof(UnitClass)))
            {
                _UnitClassSelect.Add(
                    new SelectionOption <UnitClass>("army-builder-select-option")
                {
                    DisplayedString = ObjectDescriber.Describe(c),
                    Value           = c
                });
            }

            _UnitClassSelect.OnChange += FilterUnits;
            FilterUnits();

            var finishedButton = new Button("army-builder-large-button")
            {
                DisplayedString = "Finished"
            };

            finishedButton.Position = _Pane.Size - finishedButton.Size - new Vector2f(32, 32);
            finishedButton.OnClick += HandleFinished;

            _Pane.Add(header);
            _Pane.Add(_AvailableUnits);
            _Pane.Add(_SelectedUnits);
            _Pane.Add(_PointTotalButton);
            _Pane.Add(_UnitClassSelect);
            _Pane.Add(finishedButton);
            _Items.Add(_Pane);
        }
 public FormationParameters(ArmyParameters Parameters, IEnumerable <FormationFeature> Features)
 {
     this.Parameters = Parameters;
     this.Features   = Utils.ToArray(Features);
 }
 public FormationParameters(ArmyParameters Parameters)
     : this(Parameters, new List <FormationFeature>())
 {
 }
Esempio n. 6
0
 public bool SetParameters(ArmyParameters Parameters)
 {
     this.Parameters.Copy(Parameters);
     return(true);
 }
Esempio n. 7
0
 public ArmyBuilder(IdGenerator IdGenerator, ArmyParameters Parameters)
 {
     Id = IdGenerator.GenerateId();
     this.Parameters = Parameters;
 }
Esempio n. 8
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())));
            }
        }