private static bool ProcessInBuilding(ref ResidentAI residentAI, uint citizenId, ref Citizen citizen)
        {
            if (citizen.ValidBuilding())
            {
                var buildingInstance = citizen.GetBuildingInstance();
                if (buildingInstance?.m_flags.IsFlagSet(Building.Flags.Evacuating) ?? false)
                {
                    return(false);
                }

                if (citizen.AtHome())
                {
                    ProcessAtHome(ref residentAI, citizenId, ref citizen);
                }
                else if (citizen.AtWork())
                {
                    ProcessAtWork(ref residentAI, citizenId, ref citizen);
                }
                else if (citizen.IsVisiting())
                {
                    ProcessVisiting(ref residentAI, citizenId, ref citizen);
                }
            }

            return(true);
        }
        public static bool ValidBuilding(this Citizen citizen)
        {
            var validHome  = citizen.AtHome() && citizen.ValidHomeBuilding();
            var validWork  = citizen.AtWork() && citizen.ValidWorkBuilding();
            var validVisit = citizen.IsVisiting() && citizen.ValidVisitBuilding();

            return(validHome || validWork || validVisit);
        }
        public static ushort GetBuilding(this Citizen citizen)
        {
            if (citizen.AtHome() && citizen.ValidHomeBuilding())
            {
                return(citizen.HomeBuilding());
            }
            else if (citizen.AtWork() && citizen.ValidWorkBuilding())
            {
                return(citizen.WorkBuilding());
            }
            else if (citizen.IsVisiting() && citizen.ValidVisitBuilding())
            {
                return(citizen.VisitBuilding());
            }

            return(0);
        }
        public static bool Process(ref TouristAI touristAI, uint citizenId, ref Citizen citizen)
        {
            if (!citizen.Arrested && !citizen.Sick && !citizen.Collapsed && !citizen.Dead && !citizen.AtHome() && !citizen.AtWork() && citizen.Exists())
            {
                CitizenActivityMonitor.LogActivity(citizenId, CitizenActivityMonitor.Activity.Unknown);

                if (citizen.IsAtABuilding())
                {
                    return(ProcessInBuilding(ref touristAI, citizenId, ref citizen));
                }
                else if (citizen.IsMoving())
                {
                    return(ProcessMoving(ref touristAI, citizenId, ref citizen));
                }

                return(true);
            }

            return(false);
        }
        public static bool ShouldBeAtWork(this Citizen citizen, uint citizenId, DateTime time)
        {
            var weekend = time.DayOfWeek == DayOfWeek.Saturday || time.DayOfWeek == DayOfWeek.Sunday;

            if (citizen.ValidWorkBuilding())
            {
                var ageGroup = Citizen.GetAgeGroup(citizen.m_age);
                if (ageGroup <= Citizen.AgeGroup.Teen)
                {
                    return(!weekend && UserModSettings.TimeIsBetween(time, UserModSettings.Settings.StartTime_Schools, UserModSettings.Settings.Duration_Schools) || (citizen.AtWork() && UserModSettings.TimeIsBefore(time, UserModSettings.Settings.StartTime_Schools)));
                }
                else if (ageGroup <= Citizen.AgeGroup.Young && citizen.Education3)
                {
                    return(!weekend && UserModSettings.TimeIsBetween(time, UserModSettings.Settings.StartTime_University, UserModSettings.Settings.Duration_University) || (citizen.AtWork() && UserModSettings.TimeIsBefore(time, UserModSettings.Settings.StartTime_University)));
                }
                else if (ageGroup <= Citizen.AgeGroup.Senior)
                {
                    var workInstance = citizen.WorkBuildingInstance();
                    return(workInstance.HasValue ? citizen.WorkBuildingInstance().Value.ShouldBeAtWork(citizenId, time) : false);
                }
            }

            return(false);
        }
        public static bool ShouldBeAtWork(this Citizen citizen, DateTime time)
        {
            if (citizen.ValidWorkBuilding() && time.DayOfWeek != DayOfWeek.Saturday && time.DayOfWeek != DayOfWeek.Sunday)
            {
                var ageGroup = Citizen.GetAgeGroup(citizen.m_age);
                if (ageGroup <= Citizen.AgeGroup.Teen)
                {
                    return(UserModSettings.TimeIsBetween(time, UserModSettings.Settings.StartTime_Schools, UserModSettings.Settings.Duration_Schools) || (citizen.AtWork() && UserModSettings.TimeIsBefore(time, UserModSettings.Settings.StartTime_Schools)));
                }
                else if (ageGroup <= Citizen.AgeGroup.Young && citizen.Education3)
                {
                    return(UserModSettings.TimeIsBetween(time, UserModSettings.Settings.StartTime_University, UserModSettings.Settings.Duration_University) || (citizen.AtWork() && UserModSettings.TimeIsBefore(time, UserModSettings.Settings.StartTime_University)));
                }
                else if (ageGroup <= Citizen.AgeGroup.Senior)
                {
                    return(UserModSettings.TimeIsBetween(time, UserModSettings.Settings.StartTime_Work, UserModSettings.Settings.Duration_Work) || (citizen.AtWork() && UserModSettings.TimeIsBefore(time, UserModSettings.Settings.StartTime_Work)));
                }
            }

            return(false);
        }