示例#1
0
        private bool ShouldMoveToSchoolOrWork(ushort currentBuilding, ushort workBuilding, float workBeginHour, float workEndHour, float overtime)
        {
            float gotoHour = workBeginHour - overtime - MaxHoursOnTheWay;

            if (gotoHour < 0)
            {
                gotoHour += 24f;
            }

            float leaveHour = workEndHour + overtime;

            if (leaveHour >= 24f)
            {
                leaveHour -= 24f;
            }

            float currentHour = TimeInfo.CurrentHour;

            if (!IsWorkHour(currentHour, gotoHour, leaveHour))
            {
                return(false);
            }

            float distance = BuildingMgr.GetDistanceBetweenBuildings(currentBuilding, workBuilding);
            float onTheWay = Mathf.Clamp(distance / OnTheWayDistancePerHour, MinHoursOnTheWay, MaxHoursOnTheWay);

            gotoHour = workBeginHour - overtime - onTheWay;
            if (gotoHour < 0)
            {
                gotoHour += 24f;
            }

            return(IsWorkHour(currentHour, gotoHour, leaveHour));
        }
示例#2
0
        private bool ShouldMoveToSchoolOrWork(ushort workBuilding, ushort currentBuilding, Citizen.AgeGroup citizenAge)
        {
            if (workBuilding == 0 || IsWeekend)
            {
                return(false);
            }

            float currentHour = TimeInfo.CurrentHour;
            float gotoWorkHour;
            float leaveWorkHour;
            bool  overtime;

            switch (citizenAge)
            {
            case Citizen.AgeGroup.Child:
            case Citizen.AgeGroup.Teen:
                gotoWorkHour  = Config.SchoolBegin;
                leaveWorkHour = Config.SchoolEnd;
                overtime      = false;
                break;

            case Citizen.AgeGroup.Young:
            case Citizen.AgeGroup.Adult:
                gotoWorkHour  = Config.WorkBegin;
                leaveWorkHour = Config.WorkEnd;
                overtime      = IsChance(Config.OnTimeQuota);
                break;

            default:
                return(false);
            }

            // Performance optimization:
            // If the current hour is far away from the working hours, don't even calculate the overtime and on the way time
            if (overtime &&
                (currentHour < gotoWorkHour - MaxHoursOnTheWay - Config.MaxOvertime || currentHour > leaveWorkHour + Config.MaxOvertime))
            {
                return(false);
            }
            else if (currentHour < gotoWorkHour - MaxHoursOnTheWay || currentHour > leaveWorkHour)
            {
                return(false);
            }

            if (overtime)
            {
                gotoWorkHour  -= Config.MaxOvertime * Randomizer.Int32(100) / 200f;
                leaveWorkHour += Config.MaxOvertime;
            }

            float distance = BuildingMgr.GetDistanceBetweenBuildings(currentBuilding, workBuilding);
            float onTheWay = Mathf.Clamp(distance / OnTheWayDistancePerHour, MinHoursOnTheWay, MaxHoursOnTheWay);

            gotoWorkHour -= onTheWay;

            return(currentHour >= gotoWorkHour && currentHour < leaveWorkHour);
        }
示例#3
0
        /// <summary>Gets an estimated travel time (in hours) between two specified buildings.</summary>
        /// <param name="building1">The ID of the first building.</param>
        /// <param name="building2">The ID of the second building.</param>
        /// <returns>An estimated travel time in hours.</returns>
        protected float GetEstimatedTravelTime(ushort building1, ushort building2)
        {
            if (building1 == 0 || building2 == 0 || building1 == building2)
            {
                return(0);
            }

            float distance = BuildingMgr.GetDistanceBetweenBuildings(building1, building2);

            return(RealTimeMath.Clamp(distance / OnTheWayDistancePerHour, MinTravelTime, MaxTravelTime));
        }