Beispiel #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();
            }
        }
Beispiel #2
0
 /// <summary>Initializes a new instance of the <see cref="WorkBehavior"/> class.</summary>
 /// <param name="config">The configuration to run with.</param>
 /// <param name="randomizer">The randomizer implementation.</param>
 /// <param name="buildingManager">The building manager implementation.</param>
 /// <param name="timeInfo">The time information source.</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 WorkBehavior(
     RealTimeConfig config,
     IRandomizer randomizer,
     IBuildingManagerConnection buildingManager,
     ITimeInfo timeInfo,
     ITravelBehavior travelBehavior)
 {
     this.config          = config ?? throw new ArgumentNullException(nameof(config));
     this.randomizer      = randomizer ?? throw new ArgumentNullException(nameof(randomizer));
     this.buildingManager = buildingManager ?? throw new ArgumentNullException(nameof(buildingManager));
     this.timeInfo        = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo));
     this.travelBehavior  = travelBehavior ?? throw new ArgumentNullException(nameof(travelBehavior));
 }
Beispiel #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>
        /// <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()];
        }
Beispiel #4
0
        /// <summary>Initializes a new instance of the <see cref="RealTimeResidentAI{TAI, TCitizen}"/> class.</summary>
        /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
        /// <param name="config">A <see cref="RealTimeConfig"/> instance containing the mod's configuration.</param>
        /// <param name="connections">A <see cref="GameConnections{T}"/> instance that provides the game connection implementation.</param>
        /// <param name="residentAI">A connection to the game's resident AI.</param>
        /// <param name="eventManager">An <see cref="IRealTimeEventManager"/> instance.</param>
        /// <param name="buildingAI">The custom building AI.</param>
        /// <param name="workBehavior">A behavior that provides simulation info for the citizens work time.</param>
        /// <param name="spareTimeBehavior">A behavior that provides simulation info for the citizens spare time.</param>
        /// <param name="travelBehavior">A behavior that provides simulation info for the citizens traveling.</param>
        public RealTimeResidentAI(
            RealTimeConfig config,
            GameConnections <TCitizen> connections,
            ResidentAIConnection <TAI, TCitizen> residentAI,
            IRealTimeEventManager eventManager,
            IRealTimeBuildingAI buildingAI,
            IWorkBehavior workBehavior,
            ISpareTimeBehavior spareTimeBehavior,
            ITravelBehavior travelBehavior)
            : base(config, connections, eventManager)
        {
            this.residentAI        = residentAI ?? throw new ArgumentNullException(nameof(residentAI));
            this.buildingAI        = buildingAI ?? throw new ArgumentNullException(nameof(buildingAI));
            this.workBehavior      = workBehavior ?? throw new ArgumentNullException(nameof(workBehavior));
            this.spareTimeBehavior = spareTimeBehavior ?? throw new ArgumentNullException(nameof(spareTimeBehavior));
            this.travelBehavior    = travelBehavior ?? throw new ArgumentNullException(nameof(travelBehavior));

            residentSchedules = new CitizenSchedule[CitizenMgr.GetMaxCitizensCount()];
        }