Esempio n. 1
0
        internal Dictionary <TechAreas, ITechArea> Parse()
        {
            _areas   = new Dictionary <TechAreas, ITechArea>();
            _reqs    = new MultiMap <int, int>();
            _mapping = new Dictionary <int, Technology>();
            _state   = States.file;

            ClausewitzParser clausewitzParser = new ClausewitzParser(BeginBlock, EndBlock, Variable, Value);

            foreach (string filename in Directory.GetFiles(_root + Constants.TechPath))
            {
                if (filename.EndsWith(@"\old_nuclear_tech.txt"))
                {
                    continue;
                }

                clausewitzParser.Parse(filename);
            }

            foreach (int tech in _reqs.Keys)
            {
                foreach (int req in _reqs.ValueList(tech))
                {
                    _mapping[tech].Preds.Add(_mapping[req]);
                    _mapping[req].Succs.Add(_mapping[tech]);
                }
            }

            foreach (var item in _areas)
            {
                ((TechArea)item.Value).CheckConsistency(_areas);
            }

            return(_areas);
        }
Esempio n. 2
0
        private static void ExtractEffects(string path)
        {
            EffectStates state = EffectStates.Unknown;
            MultiMap <string, string> effects = new MultiMap <string, string>();
            ClausewitzParser          parser  = new ClausewitzParser(
                name =>
            {
                if (name == "effects")
                {
                    if (state != EffectStates.Unknown)
                    {
                        throw new ClauzewitzSyntaxException("effects block inside " + state.ToString());
                    }
                    state = EffectStates.Effects;
                }
                else if (name == "command")
                {
                    if (state != EffectStates.Effects)
                    {
                        throw new ClauzewitzSyntaxException("command block inside " + state.ToString());
                    }
                    state = EffectStates.Command;
                }
            },
                () =>
            {
                if (state == EffectStates.Command)
                {
                    state = EffectStates.Effects;
                }
                else if (state == EffectStates.Effects)
                {
                    state = EffectStates.Unknown;
                }
            },
                (name, val) =>
            {
                if (state != EffectStates.Command)
                {
                    return;
                }

                effects.Add(name, val);
            },
                val =>
            {
            });

            foreach (string filename in Directory.GetFiles(path))
            {
                if (filename.EndsWith(@"\old_nuclear_tech.txt"))
                {
                    continue;
                }

                parser.Parse(filename);
            }

            Console.WriteLine("Found the following effects:");
            foreach (string key in effects.Keys)
            {
                Console.WriteLine(key + ":");
                foreach (string val in effects.ValueList(key))
                {
                    Console.WriteLine("\t" + val);
                }
            }
        }