/// <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(); } }
/// <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)); }
/// <summary>Initializes a new instance of the <see cref="TravelBehavior"/> class.</summary> /// <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="travelDistancePerCycle">The average distance a citizen can travel during a single simulation cycle.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="buildingManager"/> is null.</exception> /// <exception cref="ArgumentException">Thrown when <paramref name="travelDistancePerCycle"/> is negative or zero.</exception> public TravelBehavior(IBuildingManagerConnection buildingManager, float travelDistancePerCycle) { if (travelDistancePerCycle <= 0) { throw new ArgumentException("The travel distance per cycle cannot be negative or zero."); } this.buildingManager = buildingManager ?? throw new ArgumentNullException(nameof(buildingManager)); this.travelDistancePerCycle = travelDistancePerCycle; averageTravelSpeedPerHour = travelDistancePerCycle; }
/// <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="travelTimeCalculator">A method accepting two building IDs and returning the estimated travel time /// between those buildings (in hours).</param> /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception> public WorkBehavior( RealTimeConfig config, IRandomizer randomizer, IBuildingManagerConnection buildingManager, ITimeInfo timeInfo, Func <ushort, ushort, float> travelTimeCalculator) { 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.travelTimeCalculator = travelTimeCalculator ?? throw new ArgumentNullException(nameof(travelTimeCalculator)); }
/// <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()]; }
/// <summary> /// Initializes a new instance of the <see cref="GameConnections{TCitizen}"/> class. /// </summary> /// <param name="timeInfo">An object that provides the game time information.</param> /// <param name="citizenConnection">A proxy object that provides a way to call the game-specific methods of the <see cref="Citizen"/> struct.</param> /// <param name="citizenManager">A proxy object that provides a way to call the game-specific methods of the <see cref="global::CitizenManager"/> class.</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="simulationManager">A proxy object that provides a way to call the game-specific methods of the <see cref="global::SimulationManager"/> class.</param> /// <param name="transferManager">A proxy object that provides a way to call the game-specific methods of the <see cref="global::TransferManager"/> class.</param> public GameConnections( ITimeInfo timeInfo, ICitizenConnection <TCitizen> citizenConnection, ICitizenManagerConnection citizenManager, IBuildingManagerConnection buildingManager, ISimulationManagerConnection simulationManager, ITransferManagerConnection transferManager) { TimeInfo = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo)); CitizenConnection = citizenConnection ?? throw new ArgumentNullException(nameof(citizenConnection)); CitizenManager = citizenManager ?? throw new ArgumentNullException(nameof(citizenManager)); BuildingManager = buildingManager ?? throw new ArgumentNullException(nameof(buildingManager)); SimulationManager = simulationManager ?? throw new ArgumentNullException(nameof(simulationManager)); TransferManager = transferManager ?? throw new ArgumentNullException(nameof(transferManager)); }
/// <summary>Initializes a new instance of the <see cref="RealTimeEventManager"/> class.</summary> /// <param name="config">The configuration to run with.</param> /// <param name="eventProvider">The city event provider implementation.</param> /// <param name="eventManager"> /// A proxy object that provides a way to call the game-specific methods of the <see cref="global::EventManager"/> class. /// </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="randomizer"> /// An object that implements of the <see cref="IRandomizer"/> interface. /// </param> /// <param name="timeInfo">The time information source.</param> /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception> public RealTimeEventManager( RealTimeConfig config, ICityEventsProvider eventProvider, IEventManagerConnection eventManager, IBuildingManagerConnection buildingManager, IRandomizer randomizer, ITimeInfo timeInfo) { this.config = config ?? throw new ArgumentNullException(nameof(config)); this.eventProvider = eventProvider ?? throw new ArgumentNullException(nameof(eventProvider)); this.eventManager = eventManager ?? throw new ArgumentNullException(nameof(eventManager)); this.buildingManager = buildingManager ?? throw new ArgumentNullException(nameof(buildingManager)); this.randomizer = randomizer ?? throw new ArgumentNullException(nameof(randomizer)); this.timeInfo = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo)); upcomingEvents = new LinkedList <ICityEvent>(); }
/// <summary>Initializes a new instance of the <see cref="GameConnections{TCitizen}"/> class.</summary> /// <param name="timeInfo">An object that provides the game time information.</param> /// <param name="citizenConnection"> /// A proxy object that provides a way to call the game-specific methods of the <see cref="Citizen"/> struct. /// </param> /// <param name="citizenManager"> /// A proxy object that provides a way to call the game-specific methods of the <see cref="global::CitizenManager"/> class. /// </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="randomizer"> /// An object that implements of the <see cref="IRandomizer"/> interface. /// </param> /// <param name="transferManager"> /// A proxy object that provides a way to call the game-specific methods of the <see cref="global::TransferManager"/> class. /// </param> /// <param name="weatherInfo">An object that provides the game weather information.</param> public GameConnections( ITimeInfo timeInfo, ICitizenConnection <TCitizen> citizenConnection, ICitizenManagerConnection citizenManager, IBuildingManagerConnection buildingManager, IRandomizer randomizer, ITransferManagerConnection transferManager, IWeatherInfo weatherInfo) { TimeInfo = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo)); CitizenConnection = citizenConnection ?? throw new ArgumentNullException(nameof(citizenConnection)); CitizenManager = citizenManager ?? throw new ArgumentNullException(nameof(citizenManager)); BuildingManager = buildingManager ?? throw new ArgumentNullException(nameof(buildingManager)); Random = randomizer ?? throw new ArgumentNullException(nameof(randomizer)); TransferManager = transferManager ?? throw new ArgumentNullException(nameof(transferManager)); WeatherInfo = weatherInfo ?? throw new ArgumentNullException(nameof(weatherInfo)); }
/// <summary>Initializes a new instance of the <see cref="RealTimeEventManager"/> class.</summary> /// <param name="config">The configuration to run with.</param> /// <param name="eventProvider">The city event provider implementation.</param> /// <param name="eventManager"> /// A proxy object that provides a way to call the game-specific methods of the <see cref="EventManager"/> class. /// </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="randomizer"> /// An object that implements of the <see cref="IRandomizer"/> interface. /// </param> /// <param name="timeInfo">The time information source.</param> /// <param name="attendingTimeMargin">The time margin in hours specifying the maximum time before an event /// can be attended by the citizen.</param> /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception> public RealTimeEventManager( RealTimeConfig config, ICityEventsProvider eventProvider, IEventManagerConnection eventManager, IBuildingManagerConnection buildingManager, IRandomizer randomizer, ITimeInfo timeInfo, float attendingTimeMargin) { this.config = config ?? throw new ArgumentNullException(nameof(config)); this.eventProvider = eventProvider ?? throw new ArgumentNullException(nameof(eventProvider)); this.eventManager = eventManager ?? throw new ArgumentNullException(nameof(eventManager)); this.buildingManager = buildingManager ?? throw new ArgumentNullException(nameof(buildingManager)); this.randomizer = randomizer ?? throw new ArgumentNullException(nameof(randomizer)); this.timeInfo = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo)); this.attendingTimeMargin = attendingTimeMargin; upcomingEvents = new LinkedList <ICityEvent>(); eventsCache = new List <ICityEvent>(); readonlyEventsCache = new ReadOnlyList <ICityEvent>(eventsCache); eventsToAttend = new List <ICityEvent>(); EventsToAttend = new ReadOnlyList <ICityEvent>(eventsToAttend); }
/// <summary>Initializes a new instance of the <see cref="TravelBehavior"/> class.</summary> /// <param name="buildingManager"> /// A proxy object that provides a way to call the game-specific methods of the <see cref="BuildingManager"/> class. /// </param> /// <exception cref="System.ArgumentNullException">Thrown when the argument is null.</exception> public TravelBehavior(IBuildingManagerConnection buildingManager) { this.buildingManager = buildingManager ?? throw new System.ArgumentNullException(nameof(buildingManager)); }
/// <summary>Initializes a new instance of the <see cref="TravelBehavior"/> class.</summary> /// <param name="buildingManager"> /// A proxy object that provides a way to call the game-specific methods of the <see cref="BuildingManager"/> class. /// </param> /// <exception cref="System.ArgumentNullException">Thrown when the argument is null.</exception> public TravelBehavior(IBuildingManagerConnection buildingManager) { this.buildingManager = buildingManager ?? throw new System.ArgumentNullException(nameof(buildingManager)); averageCitizenSpeed = AverageDistancePerSimulationCycle; }
public CommercialAI(ITimeInfo timeInfo, IBuildingManagerConnection buildingManager) { this.timeInfo = timeInfo ?? throw new System.ArgumentNullException(nameof(timeInfo)); BuildingMgr = buildingManager ?? throw new System.ArgumentNullException(nameof(buildingManager)); }