예제 #1
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"];
        }
예제 #2
0
        public Environment(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            UniqueKey          = Block.Name;
            TileRuleSet        = (TileRuleSet)attributes[(int)Attribute.TILE_RULE_SET];
            MovementMultiplier = (float)(attributes[(int)Attribute.MOVEMENT_MULTIPLIER] ?? 1f);

            _RestrictRoadMovement = new bool[Enum.GetValues(typeof(UnitClass)).Length];
            foreach (UnitClass unitClass in
                     (IEnumerable <UnitClass>)(attributes[(int)Attribute.RESTRICT_ROAD_MOVEMENT]
                                               ?? Enumerable.Empty <UnitClass>()))
            {
                _RestrictRoadMovement[(int)unitClass] = true;
            }
        }
예제 #3
0
파일: Class.cs 프로젝트: jascou/ROTNS
        public Class(ParseBlock Block)
            : this()
        {
            _Name = Block.Name;

            Dictionary <string, object> D = Block.BreakToDictionary <object>();

            if (D.ContainsKey("parent"))
            {
                Inherit((Class)D["parent"]);
                D.Remove("parent");
            }
            if (D.ContainsKey("default"))
            {
                SubClass newDefault = ((SubClass)D["default"]).Combine(_SubClasses[(int)Mode.None]);
                for (int i = 0; i < _SubClasses.Length; ++i)
                {
                    _SubClasses[i] = ((SubClass)D["default"]).Combine(_SubClasses[i]);
                }
                D.Remove("default");
            }
            if (D.ContainsKey("fade"))
            {
                _IncrementedAttributes = (List <string>)D["fade"];
                D.Remove("fade");
            }
            foreach (var KV in D)
            {
                SubClass newClass = ((SubClass)KV.Value).Combine(_SubClasses[(int)Mode.None]);
                switch (KV.Key)
                {
                case "hover": _SubClasses[(int)Mode.Hover] = newClass; break;

                case "focus": _SubClasses[(int)Mode.Focus] = newClass; break;

                case "selected": _SubClasses[(int)Mode.Selected] = newClass; break;

                case "disabled": _SubClasses[(int)Mode.Disabled] = newClass; break;

                case "selected-hover": _SubClasses[(int)Mode.SelectedHover] = newClass; break;

                case "selected-disabled": _SubClasses[(int)Mode.SelectedDisabled] = newClass; break;
                }
            }
        }
예제 #4
0
 public PrintRule(ParseBlock Block, List <Operator <T> > Operators, Dictionary <string, Generator <T> > Generators)
 {
     string[] def = Block.String.Split(new string[] { "=>" }, StringSplitOptions.None);
     _Match = new MatchRule <T>(def[0], Operators, Generators);
     string[] ops = def[1].Split(':');
     for (int i = 0; i < ops.Length; ++i)
     {
         if (ops[i].Contains('*'))
         {
             string[] d = ops[i].Split('*');
             _Options.Add(Convert.ToDouble(d[0], System.Globalization.CultureInfo.InvariantCulture), d[1].Trim());
         }
         else
         {
             _Options.Add(1, ops[i].Trim());
         }
     }
 }
예제 #5
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"];
        }
예제 #6
0
        public MIPreFsh ParseOneOnly(String fshText,
            String relativePath)
        {
            fshText = fshText.Replace("\r", "");
            String[] inputLines = fshText.Split('\n');

            Parser.MFSHLexer lexer = new Parser.MFSHLexer(new AntlrInputStream(fshText));
            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(new MFSHErrorListenerLexer(this.Mfsh,
                "MFsh Lexer",
                relativePath,
                inputLines));

            Parser.MFSHParser parser = new Parser.MFSHParser(new CommonTokenStream(lexer));
            parser.Trace = false;
            parser.RemoveErrorListeners();
            parser.AddErrorListener(new MFSHErrorListenerParser(this.Mfsh,
                "MFsh Parser",
                relativePath,
                inputLines));
            //parser.ErrorHandler = new BailErrorStrategy();

            Parser.MFSHVisitor visitor = new Parser.MFSHVisitor(this.Mfsh, relativePath);
            visitor.DebugFlag = this.DebugFlag;
            visitor.Visit(parser.document());
            if (visitor.state.Count != 1)
            {
                String fullMsg = $"Error processing {relativePath}. Unterminated #{visitor.state.Peek().Name}";
                this.Mfsh.ConversionError("mfsh", "ProcessInclude", fullMsg);
            }

            ParseBlock block = visitor.Current;
            MIPreFsh retVal = new MIPreFsh(relativePath, 0)
            {
                Items = block.Items,
                RelativePath = relativePath,
                Usings = visitor.Usings
            };

            return retVal;
        }
        public ConvoyDeploymentConfiguration(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            UnitGroup         = (UnitGroup)attributes[(int)Attribute.UNIT_GROUP];
            IsStrictConvoy    = (bool)(attributes[(int)Attribute.IS_STRICT_CONVOY] ?? false);
            MovementAutomator = (ConvoyMovementAutomator)attributes[(int)Attribute.MOVEMENT_AUTOMATOR];
            EntryTurn         = (byte)(attributes[(int)Attribute.ENTRY_TURN] ?? (byte)0);

            var m    = (Matcher <Tile>)attributes[(int)Attribute.MATCHER];
            var edge = new TileOnEdge(Direction.ANY);

            if (m == null)
            {
                Matcher = edge;
            }
            else
            {
                Matcher = new CompositeMatcher <Tile>(new Matcher <Tile>[] { edge, m }, Aggregators.AND);
            }
        }
예제 #8
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];
        }
예제 #9
0
 public BindingFormationTemplate(ParseBlock Block)
     : this(Block.BreakToList <FormationTemplate>())
 {
 }
    static public TCP2_Config CreateFromFile(string text)
    {
        string[]    lines  = text.Split(new string[] { "\n", "\r\n" }, System.StringSplitOptions.RemoveEmptyEntries);
        TCP2_Config config = new TCP2_Config();

        //Flags
        ParseBlock currentBlock = ParseBlock.None;

        for (int i = 0; i < lines.Length; i++)
        {
            string line = lines[i];

            if (line.StartsWith("//"))
            {
                continue;
            }

            string[] data = line.Split(new string[] { "\t" }, System.StringSplitOptions.RemoveEmptyEntries);
            if (line.StartsWith("#"))
            {
                currentBlock = ParseBlock.None;

                switch (data[0])
                {
                case "#filename":       config.Filename = data[1]; break;

                case "#shadername":     config.ShaderName = data[1]; break;

                case "#features":       currentBlock = ParseBlock.Features; break;

                case "#flags":          currentBlock = ParseBlock.Flags; break;

                default: Debug.LogWarning("[TCP2 Shader Config] Unrecognized tag: " + data[0] + "\nline " + (i + 1)); break;
                }
            }
            else
            {
                if (data.Length > 1)
                {
                    bool enabled = false;
                    bool.TryParse(data[1], out enabled);

                    if (enabled)
                    {
                        if (currentBlock == ParseBlock.Features)
                        {
                            config.Features.Add(data[0]);
                        }
                        else if (currentBlock == ParseBlock.Flags)
                        {
                            config.Flags.Add(data[0]);
                        }
                        else
                        {
                            Debug.LogWarning("[TCP2 Shader Config] Unrecognized line while parsing : " + line + "\nline " + (i + 1));
                        }
                    }
                }
            }
        }

        return(config);
    }
        public FurthestAdvanceObjective(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            Direction = (Direction)attributes[(int)Attribute.DIRECTION];
        }
예제 #12
0
        public TileInRegion(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            NormalizedRegionName = (string)attributes[(int)Attribute.REGION_NAME];
        }
예제 #13
0
 public ReplaceRule(ParseBlock Block, List <Operator <T> > Operators, Dictionary <string, Generator <T> > Generators)
 {
     string[] def = Block.String.Split(new string[] { "=>" }, StringSplitOptions.None);
     _Match       = new MatchRule <T>(def[0], Operators, Generators);
     _Replacement = new SingleGenerator <T>(def[1], Operators, Generators);
 }
예제 #14
0
 public StaticSequence(ParseBlock Block)
 {
     _Sequence = Parse.Array(Block.String, Convert.ToByte);
     Count     = _Sequence.Length;
 }
예제 #15
0
 public Good(ParseBlock Block)
     : base(Block)
 {
 }
예제 #16
0
        public TileHasPath(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            Path = (TilePathOverlay)attributes[(int)Attribute.PATH];
        }
예제 #17
0
 public SingleGenerator(ParseBlock Block, List <Operator <T> > Operators, Dictionary <string, Generator <T> > Generators)
     : this(Block.String, Operators, Generators)
 {
 }
예제 #18
0
 public SumObjective(ParseBlock Block)
 {
     Objectives = Block.BreakToList <Objective>();
 }
예제 #19
0
        public TileWithin(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            Zone = (Polygon)attributes[(int)Attribute.ZONE];
        }
예제 #20
0
        public UnitHasPosition(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            Matcher = (Matcher <Tile>)attributes[(int)Attribute.MATCHER];
        }
        public UnitHasConfiguration(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            UnitConfiguration = (UnitConfiguration)attributes[(int)Attribute.UNIT_CONFIGURATION];
        }
예제 #22
0
        public TileHasEdge(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            Edge = (TileEdge)attributes[(int)Attribute.EDGE];
        }
예제 #23
0
        public UnitConfiguration(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            UniqueKey = Block.Name;
            Name      = (string)attributes[(int)Attribute.NAME];
            UnitClass = (UnitClass)attributes[(int)Attribute.UNIT_CLASS];

            var weaponClass    = (WeaponClass)(attributes[(int)Attribute.WEAPON_CLASS] ?? WeaponClass.NA);
            var attack         = (byte)(attributes[(int)Attribute.ATTACK] ?? (byte)0);
            var range          = (byte)(attributes[(int)Attribute.RANGE] ?? (byte)0);
            var canDoubleRange = (bool)(attributes[(int)Attribute.CAN_DOUBLE_RANGE] ?? false);

            PrimaryWeapon = (Weapon)(
                attributes[(int)Attribute.PRIMARY_WEAPON] ?? new Weapon(weaponClass, attack, range, canDoubleRange, 0));
            SecondaryWeapon = (Weapon)(attributes[(int)Attribute.SECONDARY_WEAPON] ?? default(Weapon));
            Defense         = (byte)attributes[(int)Attribute.DEFENSE];
            Movement        = (byte)(attributes[(int)Attribute.MOVEMENT] ?? (byte)(IsAircraft() ? byte.MaxValue : 0));
            IsVehicle       = (bool)(
                attributes[(int)Attribute.IS_VEHICLE] ??
                (IsAircraft() ||
                 UnitClass == UnitClass.AMPHIBIOUS_VEHICLE ||
                 UnitClass == UnitClass.ASSAULT_GUN ||
                 UnitClass == UnitClass.ENGINEER_VEHICLE ||
                 UnitClass == UnitClass.FLAME_TANK ||
                 UnitClass == UnitClass.RECONNAISSANCE_VEHICLE ||
                 UnitClass == UnitClass.SELF_PROPELLED_ARTILLERY ||
                 UnitClass == UnitClass.TANK ||
                 UnitClass == UnitClass.TANK_DESTROYER ||
                 UnitClass == UnitClass.TRANSPORT ||
                 UnitClass == UnitClass.WRECKAGE));
            IsArmored = (bool)(
                attributes[(int)Attribute.IS_ARMORED] ??
                ((IsVehicle && UnitClass != UnitClass.TRANSPORT && !IsAircraft()) || UnitClass == UnitClass.FORT));
            var wrecksAs = (string)(attributes[(int)Attribute.WRECKS_AS] ?? GetDefaultWreck());

            WrecksAs      = wrecksAs == string.Empty ? null : Block.Get <UnitConfiguration>(wrecksAs);
            UnitWeight    = (UnitWeight)(attributes[(int)Attribute.UNIT_WEIGHT] ?? GetDefaultUnitWeight());
            IsParatroop   = (bool)(attributes[(int)Attribute.IS_PARATROOP] ?? false);
            IsCommando    = (bool)(attributes[(int)Attribute.IS_COMMANDO] ?? false);
            HasLowProfile = (bool)(
                attributes[(int)Attribute.HAS_LOW_PROFILE] ??
                (UnitClass == UnitClass.INFANTRY ||
                 UnitClass == UnitClass.COMMAND_POST ||
                 UnitClass == UnitClass.FORT));

            MovementRules = (UnitMovementRules)(attributes[(int)Attribute.MOVEMENT_RULES]
                                                ?? Block.Get <UnitMovementRules>(GetDefaultMovementRules()));

            IsCarrier = (bool)(attributes[(int)Attribute.IS_CARRIER]
                               ?? ((IsVehicle && !IsAircraft()) || UnitClass == UnitClass.TRANSPORT));
            CanOnlyCarryInfantry = (bool)(attributes[(int)Attribute.CAN_ONLY_CARRY_INFANTRY]
                                          ?? IsCarrier && UnitClass != UnitClass.TRANSPORT);
            UnloadsWhenDisrupted = (bool)(attributes[(int)Attribute.UNLOADS_WHEN_DISRUPTED] ?? CanOnlyCarryInfantry);
            CanOnlyCarryLight    = (bool)(attributes[(int)Attribute.CAN_ONLY_CARRY_LIGHT] ?? false);
            CanCarryInWater      = (bool)(attributes[(int)Attribute.CAN_CARRY_IN_WATER] ?? false);
            IsPassenger          = (bool)(attributes[(int)Attribute.IS_PASSENGER]
                                          ?? (UnitClass == UnitClass.INFANTRY ||
                                              UnitClass == UnitClass.COMMAND_POST ||
                                              UnitClass == UnitClass.TOWED_GUN));
            IsOversizedPassenger = (bool)(attributes[(int)Attribute.IS_OVERSIZED_PASSENGER] ?? false);
            CannotUseRoadMovementWithOversizedPassenger = (bool)(
                attributes[(int)Attribute.CANNOT_USE_ROAD_MOVEMENT_WITH_OVERSIZED_PASSENGER] ?? CanOnlyCarryInfantry);
            OversizedPassengerMovementMultiplier = (float)(
                attributes[(int)Attribute.OVERSIZED_PASSENGER_MOVEMENT_MULTIPLIER] ?? 1f);
            WaterDieModifier = (int)(attributes[(int)Attribute.WATER_DIE_MODIFIER] ?? 0);

            IsEngineer    = (bool)(attributes[(int)Attribute.IS_ENGINEER] ?? false);
            CanDirectFire = (bool)(attributes[(int)Attribute.CAN_DIRECT_FIRE]
                                   ?? (PrimaryWeapon.Attack > 0 && UnitClass != UnitClass.MINEFIELD && !IsAircraft()));
            CanIndirectFire = (bool)(attributes[(int)Attribute.CAN_INDIRECT_FIRE]
                                     ?? (UnitClass == UnitClass.SELF_PROPELLED_ARTILLERY ||
                                         PrimaryWeapon.WeaponClass == WeaponClass.MORTAR));
            CanOverrun = (bool)(attributes[(int)Attribute.CAN_OVERRUN]
                                ?? (IsVehicle &&
                                    IsArmored &&
                                    UnitClass != UnitClass.SELF_PROPELLED_ARTILLERY && CanDirectFire));
            CanOnlyOverrunUnarmored = (bool)(attributes[(int)Attribute.CAN_ONLY_OVERRUN_UNARMORED]
                                             ?? (CanOverrun && PrimaryWeapon.WeaponClass == WeaponClass.INFANTRY));
            CanCloseAssault = (bool)(attributes[(int)Attribute.CAN_CLOSE_ASSAULT]
                                     ?? (UnitClass == UnitClass.INFANTRY || UnitClass == UnitClass.CAVALRY));
            CanOnlySupportCloseAssault = (bool)(attributes[(int)Attribute.CAN_ONLY_SUPPORT_CLOSE_ASSAULT] ?? false);
            CanAirAttack             = (bool)(attributes[(int)Attribute.CAN_AIR_ATTACK] ?? UnitClass == UnitClass.FIGHTER_BOMBER);
            CanAntiAircraft          = (bool)(attributes[(int)Attribute.CAN_ANTI_AIRCRAFT] ?? false);
            CanClearMines            = (bool)(attributes[(int)Attribute.CAN_CLEAR_MINES] ?? IsEngineer);
            CanPlaceMines            = (bool)(attributes[(int)Attribute.CAN_PLACE_MINES] ?? IsEngineer);
            CanPlaceBridges          = (bool)(attributes[(int)Attribute.CAN_PLACE_BRIDGES] ?? IsEngineer);
            InnatelyClearsMines      = (bool)(attributes[(int)Attribute.INNATELY_CLEARS_MINES] ?? false);
            ImmuneToMines            = (bool)(attributes[(int)Attribute.IMMUNE_TO_MINES] ?? (InnatelyClearsMines || IsAircraft()));
            MinimumIndirectFireRange =
                (byte)(attributes[(int)Attribute.MINIMUM_INDIRECT_FIRE_RANGE]
                       ?? (UnitClass == UnitClass.TOWED_GUN || PrimaryWeapon.WeaponClass == WeaponClass.MORTAR
                                                   ? (byte)1
                                                   : (byte)((PrimaryWeapon.Range + 1) / 2)));

            CanSpot    = (bool)(attributes[(int)Attribute.CAN_SPOT] ?? GetDefaultCanSpot());
            CanReveal  = (bool)(attributes[(int)Attribute.CAN_REVEAL] ?? CanSpot && !IsAircraft());
            SpotRange  = (byte)(attributes[(int)Attribute.SPOT_RANGE] ?? GetDefaultSpotRange());
            SightRange = IsEmplaceable() ? (byte)0 : Math.Max((byte)20, SpotRange);

            DismountAs = (UnitConfiguration)attributes[(int)Attribute.DISMOUNT_AS];
            CanRemount = (bool)(attributes[(int)Attribute.CAN_REMOUNT] ?? DismountAs != null);

            CanSupportArmored   = (bool)(attributes[(int)Attribute.CAN_SUPPORT_ARMORED] ?? false);
            CloseAssaultCapture = (bool)(attributes[(int)Attribute.CLOSE_ASSAULT_CAPTURE]
                                         ?? UnitClass == UnitClass.COMMAND_POST);
            AreaControlCapture = (bool)(attributes[(int)Attribute.AREA_CONTROL_CAPTURE] ?? UnitClass == UnitClass.FORT);
        }
예제 #24
0
 public BoardCompositeMapConfiguration(ParseBlock Block)
 {
     Boards = Block.BreakToList <List <BoardConfiguration> >();
 }
예제 #25
0
 public OrthographyBank(ParseBlock Block)
 {
     object[] attributes = Block.BreakToAttributes <object>(typeof(Attribute));
     _Orthography = (List <SymbolSet>)attributes[(int)Attribute.ORTHOGRAPHY];
     _Modifiers   = (List <Matched>)attributes[(int)Attribute.MODIFIERS];
 }
예제 #26
0
        public TileHasUnit(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            Matcher = (Matcher <Unit>)attributes[(int)Attribute.MATCHER];
        }
 public PreventEnemyObjective(ParseBlock Block)
 {
 }
예제 #28
0
 public SoundClass(ParseBlock Block)
 {
     object[] attributes = Block.BreakToAttributes <object>(typeof(Attribute));
     _Frequency   = (double)attributes[(int)Attribute.FREQUENCY];
     _Identifiers = (string[])attributes[(int)Attribute.IDENTIFIERS];
 }
예제 #29
0
파일: SymbolSet.cs 프로젝트: jascou/ROTNS
 public SymbolSet(ParseBlock Block)
 {
     object[] attributes = Block.BreakToAttributes <object>(typeof(Attribute));
     _Frequency = (double)attributes[(int)Attribute.FREQUENCY];
     _Symbols   = (List <Matched>)attributes[(int)Attribute.SYMBOLS];
 }
예제 #30
0
        public UnitHasStatus(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            Status = (UnitStatus)attributes[(int)Attribute.STATUS];
        }