コード例 #1
0
ファイル: RealTimeBuildingAI.cs プロジェクト: sjon85/RealTime
        /// <summary>
        /// Determines whether the building with the specified <paramref name="buildingId"/> is noise restricted
        /// (has NIMBY policy that is active on current time).
        /// </summary>
        /// <param name="buildingId">The building ID to check.</param>
        /// <param name="currentBuildingId">The ID of a building where the citizen starts their journey.
        /// Specify 0 if there is no journey in schedule.</param>
        /// <returns>
        ///   <c>true</c> if the building with the specified <paramref name="buildingId"/> has NIMBY policy
        ///   that is active on current time; otherwise, <c>false</c>.
        /// </returns>
        public bool IsNoiseRestricted(ushort buildingId, ushort currentBuildingId = 0)
        {
            if (buildingManager.GetBuildingSubService(buildingId) != ItemClass.SubService.CommercialLeisure)
            {
                return(false);
            }

            float currentHour = timeInfo.CurrentHour;

            if (currentHour >= config.GoToSleepHour || currentHour <= config.WakeUpHour)
            {
                return(buildingManager.IsBuildingNoiseRestricted(buildingId));
            }

            if (currentBuildingId == 0)
            {
                return(false);
            }

            float travelTime = travelBehavior.GetEstimatedTravelTime(currentBuildingId, buildingId);

            if (travelTime == 0)
            {
                return(false);
            }

            float arriveHour = (float)timeInfo.Now.AddHours(travelTime).TimeOfDay.TotalHours;

            if (arriveHour >= config.GoToSleepHour || arriveHour <= config.WakeUpHour)
            {
                return(buildingManager.IsBuildingNoiseRestricted(buildingId));
            }

            return(false);
        }
コード例 #2
0
        /// <summary>Updates the citizen's work shift parameters in the specified citizen's <paramref name="schedule"/>.</summary>
        /// <param name="schedule">The citizen's schedule to update the work shift in.</param>
        /// <param name="citizenAge">The age of the citizen.</param>
        public void UpdateWorkShift(ref CitizenSchedule schedule, Citizen.AgeGroup citizenAge)
        {
            if (schedule.WorkBuilding == 0 || citizenAge == Citizen.AgeGroup.Senior)
            {
                schedule.UpdateWorkShift(WorkShift.Unemployed, 0, 0, false);
                return;
            }

            ItemClass.Service    buildingSevice     = buildingManager.GetBuildingService(schedule.WorkBuilding);
            ItemClass.SubService buildingSubService = buildingManager.GetBuildingSubService(schedule.WorkBuilding);

            float     workBegin, workEnd;
            WorkShift workShift = schedule.WorkShift;

            switch (citizenAge)
            {
            case Citizen.AgeGroup.Child:
            case Citizen.AgeGroup.Teen:
                workShift = WorkShift.First;
                workBegin = config.SchoolBegin;
                workEnd   = config.SchoolEnd;
                break;

            case Citizen.AgeGroup.Young:
            case Citizen.AgeGroup.Adult:
                if (workShift == WorkShift.Unemployed)
                {
                    workShift = GetWorkShift(GetBuildingWorkShiftCount(buildingSevice, buildingSubService));
                }

                workBegin = config.WorkBegin;
                workEnd   = config.WorkEnd;
                break;

            default:
                return;
            }

            switch (workShift)
            {
            case WorkShift.First when HasExtendedFirstWorkShift(buildingSevice, buildingSubService):
                workBegin = Math.Min(config.WakeupHour, EarliestWakeUp);

                break;

            case WorkShift.Second:
                workBegin = workEnd;
                workEnd   = 0;
                break;

            case WorkShift.Night:
                workEnd   = workBegin;
                workBegin = 0;
                break;
            }

            schedule.UpdateWorkShift(workShift, workBegin, workEnd, IsBuildingActiveOnWeekend(buildingSevice, buildingSubService));
        }