예제 #1
0
        /// <summary>
        /// Initializes the context object.
        /// </summary>
        /// <returns>THe context object.</returns>
        public static Context InitContext()
        {
            int worldSeed = 915434125;

            ConditionCompiler <BaseGlobalVariables> processor =
                new ConditionCompiler <BaseGlobalVariables>(new BaseGlobalVariables()
            {
                World = new World(),
            });
            Definitions  definitions = DefinitionSerializer.DeserializeFromDirectory(processor, "Definitions");
            ThingFactory factory     = new ThingFactory(definitions);

            HistoryGenerator history = new HistoryGenerator(factory, definitions);

            WorldGen.WorldGenerator worldGen = new WorldGen.WorldGenerator(worldSeed, factory);
            int   width  = 200;
            int   height = 200;
            World world  = worldGen.GenerateWorld(width, height);

            processor.UpdateGlobalVariables(g => g.World = world);

            Random rdm = new Random(worldSeed);

            for (int i = 0; i < 100; i++)
            {
                int  x        = rdm.Next(0, width - 1);
                int  y        = rdm.Next(0, height - 1);
                Site cityInst = factory.CreateSite(rdm, x, y, "City");
                world.Grid.AddThing(cityInst);
            }

            foreach (var thing in world.Grid.AllGridEntries.SelectMany(x => x.Square.GetThings()))
            {
                thing.FinalizeConstruction(new Random());
            }

            Context.Instance.Attach(history, world, processor);

            return(Context.Instance);
        }