private void CreateRandomEvent(ushort buildingId)
        {
            string buildingClass = buildingManager.GetBuildingClassName(buildingId);

            if (string.IsNullOrEmpty(buildingClass))
            {
                return;
            }

            ICityEvent newEvent = eventProvider.GetRandomEvent(buildingClass);

            if (newEvent == null)
            {
                return;
            }

            DateTime startTime = upcomingEvents.Count == 0
                ? timeInfo.Now
                : upcomingEvents.Last.Value.EndTime.Add(MinimumIntervalBetweenEvents);

            startTime = AdjustEventStartTime(startTime, randomize: true);
            if (startTime < earliestEvent)
            {
                return;
            }

            earliestEvent = startTime.AddHours(randomizer.GetRandomValue(EventIntervalVariance));

            newEvent.Configure(buildingId, buildingManager.GetBuildingName(buildingId), startTime);
            upcomingEvents.AddLast(newEvent);
            OnEventsChanged();
            Log.Debug(LogCategory.Events, timeInfo.Now, $"New event created for building {newEvent.BuildingId}, starts on {newEvent.StartTime}, ends on {newEvent.EndTime}");
        }
Beispiel #2
0
        private WorkShift GetWorkShift(int workShiftCount)
        {
            switch (workShiftCount)
            {
            case 1:
                return(WorkShift.First);

            case 2:
                return(randomizer.ShouldOccur(config.SecondShiftQuota)
                        ? WorkShift.Second
                        : WorkShift.First);

            case 3:
                int random = randomizer.GetRandomValue(100u);
                if (random < config.NightShiftQuota)
                {
                    return(WorkShift.Night);
                }
                else if (random < config.SecondShiftQuota + config.NightShiftQuota)
                {
                    return(WorkShift.Second);
                }

                return(WorkShift.First);

            default:
                return(WorkShift.Unemployed);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Calculates the citizen's maximum budget for visiting a city event. It depends on the
        /// citizen's wealth.
        /// </summary>
        /// ///
        /// <param name="wealth">The citizen's wealth.</param>
        /// <param name="randomizer">A reference to the game's randomizer.</param>
        /// <returns>The citizen's budget for attending an event.</returns>
        protected static float GetCitizenBudgetForEvent(Citizen.Wealth wealth, IRandomizer randomizer)
        {
            switch (wealth)
            {
            case Citizen.Wealth.Low:
                return(30f + randomizer.GetRandomValue(60));

            case Citizen.Wealth.Medium:
                return(80f + randomizer.GetRandomValue(80));

            case Citizen.Wealth.High:
                return(120f + randomizer.GetRandomValue(320));

            default:
                return(0);
            }
        }
Beispiel #4
0
        /// <summary>Accepts an event attendee with specified properties.</summary>
        /// <param name="age">The attendee age.</param>
        /// <param name="gender">The attendee gender.</param>
        /// <param name="education">The attendee education.</param>
        /// <param name="wealth">The attendee wealth.</param>
        /// <param name="wellbeing">The attendee wellbeing.</param>
        /// <param name="happiness">The attendee happiness.</param>
        /// <param name="randomizer">A reference to the game's randomizer.</param>
        /// <returns>
        /// <c>true</c> if the event attendee with specified properties is accepted and can attend this city event;
        /// otherwise, <c>false</c>.
        /// </returns>
        public override bool TryAcceptAttendee(
            Citizen.AgeGroup age,
            Citizen.Gender gender,
            Citizen.Education education,
            Citizen.Wealth wealth,
            Citizen.Wellbeing wellbeing,
            Citizen.Happiness happiness,
            IRandomizer randomizer)
        {
            if (attendeesCount > eventTemplate.Capacity)
            {
                return(false);
            }

            if (eventTemplate.Costs != null && eventTemplate.Costs.Entry > GetCitizenBudgetForEvent(wealth, randomizer))
            {
                return(false);
            }

            CityEventAttendees attendees = eventTemplate.Attendees;
            float randomPercentage       = randomizer.GetRandomValue(100u);

            if (!CheckAge(age, attendees, randomPercentage))
            {
                return(false);
            }

            randomPercentage = randomizer.GetRandomValue(100u);
            if (!CheckGender(gender, attendees, randomPercentage))
            {
                return(false);
            }

            randomPercentage = randomizer.GetRandomValue(100u);
            if (!CheckEducation(education, attendees, randomPercentage))
            {
                return(false);
            }

            randomPercentage = randomizer.GetRandomValue(100u);
            if (!CheckWealth(wealth, attendees, randomPercentage))
            {
                return(false);
            }

            randomPercentage = randomizer.GetRandomValue(100u);
            if (!CheckWellbeing(wellbeing, attendees, randomPercentage))
            {
                return(false);
            }

            randomPercentage = randomizer.GetRandomValue(100u);
            if (!CheckHappiness(happiness, attendees, randomPercentage))
            {
                return(false);
            }

            attendeesCount++;
            return(true);
        }
        /// <summary>
        /// Gets the education level of the new citizen based on their <paramref name="age" />.
        /// </summary>
        /// <param name="age">The citizen's age as raw value (0-255).</param>
        /// <param name="currentEducation">The current value of the citizen's education.</param>
        /// <returns>The education level of the new citizen with the specified age.</returns>
        public Citizen.Education GetEducation(int age, Citizen.Education currentEducation)
        {
            if (!config.UseSlowAging)
            {
                return(currentEducation);
            }

            var randomValue = randomizer.GetRandomValue(100u);

            // Age:
            // 0-14    -> child
            // 15-44   -> teen
            // 45-89   -> young
            // 90-179  -> adult
            // 180-255 -> senior
            if (age < 10)
            {
                // little children
                return(Citizen.Education.Uneducated);
            }
            else if (age < 40)
            {
                // children and most of the teens
                return(randomValue <= 25 ? Citizen.Education.Uneducated : Citizen.Education.OneSchool);
            }
            else if (age < 80)
            {
                // few teens and most of the young adults
                if (randomValue < 50)
                {
                    return(Citizen.Education.Uneducated);
                }
                else if (randomValue < 90)
                {
                    return(Citizen.Education.OneSchool);
                }
                else
                {
                    return(Citizen.Education.TwoSchools);
                }
            }
            else
            {
                // few young adults, adults and seniors
                if (randomValue < 50)
                {
                    return(Citizen.Education.Uneducated);
                }
                else if (randomValue < 80)
                {
                    return(Citizen.Education.OneSchool);
                }
                else if (randomValue < 90)
                {
                    return(Citizen.Education.TwoSchools);
                }
                else
                {
                    return(Citizen.Education.ThreeSchools);
                }
            }
        }