예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RealTimeBuildingAI"/> class.
        /// </summary>
        ///
        /// <param name="config">The configuration to run with.</param>
        /// <param name="timeInfo">The time information source.</param>
        /// <param name="buildingManager">A proxy object that provides a way to call the game-specific methods of the <see cref="BuildingManager"/> class.</param>
        /// <param name="toolManager">A proxy object that provides a way to call the game-specific methods of the <see cref="ToolManager"/> class.</param>
        /// <param name="workBehavior">A behavior that provides simulation info for the citizens' work time.</param>
        /// <param name="travelBehavior">A behavior that provides simulation info for the citizens' traveling.</param>
        /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
        public RealTimeBuildingAI(
            RealTimeConfig config,
            ITimeInfo timeInfo,
            IBuildingManagerConnection buildingManager,
            IToolManagerConnection toolManager,
            IWorkBehavior workBehavior,
            ITravelBehavior travelBehavior)
        {
            this.config          = config ?? throw new ArgumentNullException(nameof(config));
            this.timeInfo        = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo));
            this.buildingManager = buildingManager ?? throw new ArgumentNullException(nameof(buildingManager));
            this.toolManager     = toolManager ?? throw new ArgumentNullException(nameof(toolManager));
            this.workBehavior    = workBehavior ?? throw new ArgumentNullException(nameof(workBehavior));
            this.travelBehavior  = travelBehavior ?? throw new ArgumentNullException(nameof(travelBehavior));

            lightStates      = new bool[buildingManager.GetMaxBuildingsCount()];
            reachingTroubles = new byte[lightStates.Length];

            // This is to preallocate the hash sets to a large capacity, .NET 3.5 doesn't provide a proper way.
            var preallocated = Enumerable.Range(0, MaximumBuildingsInConstruction * 2).Select(v => (ushort)v).ToList();

            buildingsInConstruction = new[]
            {
                new HashSet <ushort>(preallocated),
                new HashSet <ushort>(preallocated),
                new HashSet <ushort>(preallocated),
                new HashSet <ushort>(preallocated),
            };

            for (int i = 0; i < buildingsInConstruction.Length; ++i)
            {
                // Calling Clear() doesn't trim the capacity, we're using this trick for preallocating the hash sets
                buildingsInConstruction[i].Clear();
            }
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RealTimePrivateBuildingAI"/> class.
 /// </summary>
 ///
 /// <param name="config">The configuration to run with.</param>
 /// <param name="timeInfo">The time information source.</param>
 /// <param name="buildingManager">A proxy object that provides a way to call the game-specific methods of the <see cref="global::BuildingManager"/> class.</param>
 /// <param name="toolManager">A proxy object that provides a way to call the game-specific methods of the <see cref="global::ToolManager"/> class.</param>
 ///
 /// <exception cref="System.ArgumentNullException">Thrown when any argument is null.</exception>
 public RealTimePrivateBuildingAI(
     RealTimeConfig config,
     ITimeInfo timeInfo,
     IBuildingManagerConnection buildingManager,
     IToolManagerConnection toolManager)
 {
     this.config          = config ?? throw new System.ArgumentNullException(nameof(config));
     this.timeInfo        = timeInfo ?? throw new System.ArgumentNullException(nameof(timeInfo));
     this.buildingManager = buildingManager ?? throw new System.ArgumentNullException(nameof(buildingManager));
     this.toolManager     = toolManager ?? throw new System.ArgumentNullException(nameof(toolManager));
 }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RealTimeBuildingAI"/> class.
        /// </summary>
        ///
        /// <param name="config">The configuration to run with.</param>
        /// <param name="timeInfo">The time information source.</param>
        /// <param name="buildingManager">A proxy object that provides a way to call the game-specific methods of the <see cref="BuildingManager"/> class.</param>
        /// <param name="toolManager">A proxy object that provides a way to call the game-specific methods of the <see cref="ToolManager"/> class.</param>
        /// <param name="workBehavior">A behavior that provides simulation info for the citizens work time.</param>
        /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
        public RealTimeBuildingAI(
            RealTimeConfig config,
            ITimeInfo timeInfo,
            IBuildingManagerConnection buildingManager,
            IToolManagerConnection toolManager,
            WorkBehavior workBehavior)
        {
            this.config          = config ?? throw new ArgumentNullException(nameof(config));
            this.timeInfo        = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo));
            this.buildingManager = buildingManager ?? throw new ArgumentNullException(nameof(buildingManager));
            this.toolManager     = toolManager ?? throw new ArgumentNullException(nameof(toolManager));
            this.workBehavior    = workBehavior ?? throw new ArgumentNullException(nameof(workBehavior));

            lightStates = new bool[buildingManager.GetMaxBuildingsCount()];
        }