public NetworkRunner(CvarcClient client)
        {
            this.client = client;

            factory = new SoloNetworkControllerFactory(client);

            var configProposal = client.Read<ConfigurationProposal>();
            var loadingData = configProposal.LoadingData;
            var competitions = Dispatcher.Loader.GetCompetitions(loadingData);
            var settings = competitions.Logic.CreateDefaultSettings();
            if (configProposal.SettingsProposal != null)
                configProposal.SettingsProposal.Push(settings, true);
            configuration = new Configuration
            {
                LoadingData = loadingData,
                Settings = settings
            };

            //configuration.Settings.EnableLog = true;
            //configuration.Settings.LogFile = UnityConstants.LogFolderRoot + "cvarclog1";

            var worldSettingsType = competitions.Logic.WorldStateType;
            worldState = (IWorldState)client.Read(worldSettingsType);

            Name = loadingData.AssemblyName + loadingData.Level;
            CanInterrupt = true;
            CanStart = true;
        }
		/// <summary>
		/// Creates a world. 
		/// </summary>
		/// <param name="configuration">Contains the cometition/level name and the settings</param>
		/// <param name="controllerFactory">Is used to create controllers, i.e. entities that control the robots</param>
		/// <param name="state">The initial state of the world</param>
		/// <returns></returns>
		public IWorld CreateWorld(Configuration configuration, ControllerFactory controllerFactory, IWorldState state)
		{
			var competitions = GetCompetitions(configuration.LoadingData);
			var world = competitions.Logic.CreateWorld();
			world.Initialize(competitions, configuration, controllerFactory, state);
			world.Exit += ()=>
				controllerFactory.Exit();
			return world;
		}
        readonly IWorldState worldState; // откуда?

        #endregion Fields

        #region Constructors

        public TutorialRunner(LoadingData loadingData, Configuration configuration = null, IWorldState worldState = null)
        {
            factory = new TutorialControllerFactory();

            var competitions = Dispatcher.Loader.GetCompetitions(loadingData);
            if (configuration == null)
            {
                this.configuration = new Configuration
                {
                    LoadingData = loadingData,
                    Settings = competitions.Logic.CreateDefaultSettings()
                };
            }
            else
                this.configuration = configuration;

            this.worldState = worldState ?? competitions.Logic.CreateWorldState(competitions.Logic.PredefinedWorldStates[0]);
            //this.worldState = worldState ?? competitions.Logic.CreateWorldState("0"); // lol

            Name = "Tutorial";
            CanStart = true;
            CanInterrupt = true;
        }
		/// <summary>
		/// Creates the world for non-networking case: BotDemo or Tutorial modes.
		/// </summary>
		/// <param name="loadingData"></param>
		/// <param name="proposal"></param>
		/// <param name="factory"></param>
		/// <returns></returns>
		public IWorld CreateSimpleMode(LoadingData loadingData, SettingsProposal proposal, ControllerFactory factory)
		{
			var configuration = new Configuration();
			configuration.LoadingData = loadingData;
			var competitions = GetCompetitions(configuration.LoadingData);
			configuration.Settings = competitions.Logic.CreateDefaultSettings();


			proposal.Push(configuration.Settings, true);
			var stateName = configuration.Settings.WorldState;
			if (stateName == null)
			{
				if (competitions.Logic.PredefinedWorldStates.Count == 0)
					throw new Exception("The count of predefined stated in the " + competitions.Logic.GetType() + " is zero");
				stateName = competitions.Logic.PredefinedWorldStates[0];
			}
			var state = competitions.Logic.CreateWorldState(stateName);
			return CreateWorld(configuration, factory, state);

		}
Beispiel #5
0
        public void Initialize(Competitions competitions, GameSettings configuration, ControllerFactory controllerFactory, WorldState worldState)
        {
            Debugger.Log("World initialization");
            Debugger.Log("Starting basic fields");

            Competitions  = competitions;
            Configuration = configuration;
            WorldState    = Compatibility.Check <TWorldState>(this, worldState);

            Clocks      = new WorldClocks();
            IdGenerator = new IdGenerator();
            Scores      = new Scores(this);
            Logger      = new LogWriter(this, Configuration.EnableLog, Configuration.LogFile, Configuration, WorldState);
            Keyboard    = competitions.KeyboardFactory();
            LoggingPositionObjectIds = new List <string>();

            // setting up the parameters

            Clocks.TimeLimit = Configuration.TimeLimit;


            Debugger.Log("About to init engines");
            //Initializing world
            this.Engines = competitions.EnginesFactory(configuration);

            Debugger.Log("Init engines OK");

            Debugger.Log("Complete: basic fields. Starting engine");
            foreach (var engine in Engines)
            {
                engine.LogWriter = Logger;
            }
            Debugger.Log("Complete: engine. Starting controller factory");
            controllerFactory.Initialize(this);
            Debugger.Log("Complete: controller factory. Creating world");
            CreateWorld();
            Debugger.Log("World created");


            //Initializing actors
            actors = new List <IActor>();
            foreach (var id in competitions.Logic.Actors.Keys)
            {
                InitializeActor(
                    competitions,
                    id,
                    competitions.Logic.Actors[id],
                    controllerFactory.Create
                    );
            }

            foreach (var l in competitions.Logic.NPC)
            {
                var f = l.Item3;
                InitializeActor(competitions, l.Item1, l.Item2, (cid, a) => f(a));
            }

            Debugger.Log("Additional world initialization");
            AdditionalInitialization();
        }