Example #1
0
        /// <summary>Initializes a new instance of the <see cref="Statistics"/> class.</summary>
        /// <param name="timeInfo">An object that provides the game's time information.</param>
        /// <param name="localizationProvider">The object to get the current locale from.</param>
        /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
        public Statistics(ITimeInfo timeInfo, ILocalizationProvider localizationProvider)
        {
            this.timeInfo             = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo));
            this.localizationProvider = localizationProvider ?? throw new ArgumentNullException(nameof(localizationProvider));

            customLocale = new Locale();
        }
Example #2
0
 /// <summary>Initializes a new instance of the <see cref="CitizenProcessor{TAI, TCitizen}"/> class.</summary>
 /// <param name="residentAI">The custom resident AI implementation.</param>
 /// <param name="spareTimeBehavior">A behavior that provides simulation info for the citizens spare time.</param>
 /// <param name="timeInfo">An object that provides the game time information.</param>
 /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
 public CitizenProcessor(RealTimeResidentAI <TAI, TCitizen> residentAI, SpareTimeBehavior spareTimeBehavior, ITimeInfo timeInfo)
 {
     this.residentAI        = residentAI ?? throw new ArgumentNullException(nameof(residentAI));
     this.spareTimeBehavior = spareTimeBehavior ?? throw new ArgumentNullException(nameof(spareTimeBehavior));
     this.timeInfo          = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo));
     cycleStartFrame        = int.MinValue;
 }
Example #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()];
            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="CitizenScheduleStorage"/> class.</summary>
 /// <param name="residentSchedules">The resident schedules to store or load.</param>
 /// <param name="citizens">The game's citizens array.</param>
 /// <param name="timeInfo">An object that provides the game time information.</param>
 /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
 /// <exception cref="ArgumentException">Thrown when <paramref name="residentSchedules"/> and <paramref name="citizens"/>
 /// have different length.</exception>
 public CitizenScheduleStorage(CitizenSchedule[] residentSchedules, Citizen[] citizens, ITimeInfo timeInfo)
 {
     this.residentSchedules = residentSchedules ?? throw new System.ArgumentNullException(nameof(residentSchedules));
     this.citizens          = citizens ?? throw new ArgumentNullException(nameof(citizens));
     this.timeInfo          = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo));
     if (residentSchedules.Length != citizens.Length)
     {
         throw new ArgumentException($"{nameof(residentSchedules)} and {nameof(citizens)} arrays must have equal length");
     }
 }
 /// <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="SpareTimeBehavior"/> class.</summary>
        /// <param name="config">The configuration to run with.</param>
        /// <param name="timeInfo">The object providing the game time information.</param>
        /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
        public SpareTimeBehavior(RealTimeConfig config, ITimeInfo timeInfo)
        {
            this.config   = config ?? throw new ArgumentNullException(nameof(config));
            this.timeInfo = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo));

            int agesCount = Enum.GetValues(typeof(Citizen.AgeGroup)).Length;

            defaultChances     = new uint[agesCount];
            secondShiftChances = new uint[agesCount];
            nightShiftChances  = new uint[agesCount];
            shoppingChances    = new uint[agesCount];
        }
Example #7
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="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));
 }
Example #8
0
 public static void Initialize(RenderWindow window, ITimeInfo timeInfo, IInput input, IWindowUtil windowUtil, Func <ILogger> getLogger, ITextInfo text)
 {
     Window = window;
     if (_initialized)
     {
         return;
     }
     _initialized = true;
     TimeInfo     = timeInfo;
     Input        = input;
     WindowUtil   = windowUtil;
     _getLogger   = getLogger;
     Text         = text;
 }
Example #9
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()];
        }
Example #10
0
 /// <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));
 }
Example #11
0
 /// <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>();
 }
Example #12
0
        /// <summary>Initializes a new instance of the <see cref="CitizenScheduleStorage"/> class.</summary>
        /// <param name="residentSchedules">The resident schedules to store or load.</param>
        /// <param name="citizensProvider">A method that returns the game's citizens array.</param>
        /// <param name="timeInfo">An object that provides the game time information.</param>
        /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="residentSchedules"/> and the array returned by
        /// <paramref name="citizensProvider"/> have different lengths.</exception>
        public CitizenScheduleStorage(CitizenSchedule[] residentSchedules, Func <Citizen[]> citizensProvider, ITimeInfo timeInfo)
        {
            this.residentSchedules = residentSchedules ?? throw new ArgumentNullException(nameof(residentSchedules));
            if (citizensProvider == null)
            {
                throw new ArgumentNullException(nameof(citizensProvider));
            }

            this.timeInfo = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo));

            citizens = citizensProvider();
            if (citizens == null || residentSchedules.Length != citizens.Length)
            {
                throw new ArgumentException($"{nameof(residentSchedules)} and citizens arrays must have equal length");
            }
        }
Example #13
0
 /// <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));
 }
Example #14
0
        /// <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);
        }
Example #15
0
 /// <summary>Initializes a new instance of the <see cref="SpareTimeBehavior"/> class.</summary>
 /// <param name="config">The configuration to run with.</param>
 /// <param name="timeInfo">The object providing the game time information.</param>
 /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
 public SpareTimeBehavior(RealTimeConfig config, ITimeInfo timeInfo)
 {
     this.config   = config ?? throw new ArgumentNullException(nameof(config));
     this.timeInfo = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo));
     chances       = new uint[Enum.GetValues(typeof(Citizen.AgeGroup)).Length];
 }
Example #16
0
 public CommercialAI(ITimeInfo timeInfo, IBuildingManagerConnection buildingManager)
 {
     this.timeInfo = timeInfo ?? throw new System.ArgumentNullException(nameof(timeInfo));
     BuildingMgr   = buildingManager ?? throw new System.ArgumentNullException(nameof(buildingManager));
 }