Пример #1
0
        public override void MapComponentTick()
        {
            if (Active)
            {
                if (Find.TickManager.TicksGame % 1009 == 0)
                {
                    // Check if there are any things needing to be hauled to carriers or trash
                    CheckForHaulables(false);

                    // Check for a new day
                    var day = GenDate.DaysPassed;
                    if (day > daysPassed)
                    {
                        daysPassed = day;
                        alreadyEntertainedToday = false;
                    }
                }
                else if (Find.TickManager.TicksGame % 799 == 0)
                {
                    if (currentLord.CurLordToil is LordToil_EntertainColony &&
                        Rand.Chance(0.21f) &&
                        !alreadyHadShowToday && !showingNow &&
                        GenLocalDate.HourFloat(map) > MinShowHour &&
                        GenLocalDate.HourFloat(map) < MaxShowHour)
                    {
                        TryStartShow();
                    }
                }
                else if (Find.TickManager.TicksGame % 757 == 0)
                {
                    // Check for colonists in area. They are kept in the list for roughly an hour.
                    CheckForColonists(checkRemoveColonists);
                    checkRemoveColonists = !checkRemoveColonists;
                }
                else if (Find.TickManager.TicksGame % 499 == 0)
                {
                    // Check carny rest levels
                    this.anyCarnyNeedsRest = currentLord.ownedPawns
                                             .Where(p => p.IsAny(CarnivalRole.Entertainer, CarnivalRole.Vendor))
                                             .Any(c => c.needs.rest.CurCategory > RestCategory.Rested);
                }
            }
        }
        public override void MapComponentTick()
        {
            base.MapComponentTick();
            if (!WorkManager.Enabled)
            {
                return;
            }
            var day       = GenLocalDate.DayOfYear(map);
            var hourFloat = GenLocalDate.HourFloat(map);

            if ((Find.TickManager.TicksGame + GetHashCode()) % 60 != 0 || Math.Abs(day - _currentDay) * 24 +
                Math.Abs(hourFloat - _currentTime) < 24f / Settings.UpdateFrequency)
            {
                return;
            }
            #if DEBUG
            Log.Message($"----- Work Manager: Updating work priorities... (day = {day}, hour = {hourFloat}) -----",
                        true);
            #endif
            if (!Current.Game.playSettings.useWorkPriorities)
            {
                Current.Game.playSettings.useWorkPriorities = true;
                foreach (var pawn in PawnsFinder.AllMapsWorldAndTemporary_Alive.Where(pawn =>
                                                                                      pawn.Faction == Faction.OfPlayer))
                {
                    pawn.workSettings?.Notify_UseWorkPrioritiesChanged();
                }
            }
            UpdateCache();
            if (_allPawns.Any())
            {
                AssignWorkPriorities();
            }
            _currentDay  = day;
            _currentTime = hourFloat;
            #if DEBUG
            Log.Message("----------------------------------------------------", true);
            #endif
        }
        public override void MapComponentTick()
        {
            base.MapComponentTick();
            if (!WorkManager.Enabled)
            {
                return;
            }
            if (Find.TickManager.CurTimeSpeed == TimeSpeed.Paused || Find.TickManager.TicksGame % 60 != 0)
            {
                return;
            }
            var year        = GenLocalDate.Year(map);
            var day         = GenLocalDate.DayOfYear(map);
            var hourFloat   = GenLocalDate.HourFloat(map);
            var hoursPassed = (year - _workUpdateTime.Year) * 60 * 24 + (day - _workUpdateTime.Day) * 24 + hourFloat -
                              _workUpdateTime.Hour;

            if (Settings.UpdateFrequency == 0)
            {
                Settings.UpdateFrequency = 24;
            }
            if (hoursPassed < 24f / Settings.UpdateFrequency)
            {
                return;
            }
            if (!Current.Game.playSettings.useWorkPriorities)
            {
                Current.Game.playSettings.useWorkPriorities = true;
                foreach (var pawn in PawnsFinder.AllMapsWorldAndTemporary_Alive.Where(pawn =>
                                                                                      pawn.Faction == Faction.OfPlayer))
                {
                    pawn.workSettings?.Notify_UseWorkPrioritiesChanged();
                }
            }
            if (Settings.AssignEveryoneWorkTypes == null)
            {
                Settings.AssignEveryoneWorkTypes =
                    new List <AssignEveryoneWorkType>(Settings.DefaultAssignEveryoneWorkTypes);
            }
            if (Prefs.DevMode && Settings.VerboseLogging)
            {
                Log.Message(
                    $"----- Work Manager: Updating work priorities... (day = {day}, hour = {hourFloat}, passed = {hoursPassed:N1}) -----");
            }
            _workUpdateTime.Year = year;
            _workUpdateTime.Day  = day;
            _workUpdateTime.Hour = hourFloat;
            UpdateCache();
            UpdateWorkPriorities();
            ApplyWorkPriorities();
            if (Settings.ManageWorkSchedule && (year - _scheduleUpdateTime.Year) * 60 * 24 +
                (day - _scheduleUpdateTime.Day) * 24 + hourFloat - _scheduleUpdateTime.Hour >= 24)
            {
                _scheduleUpdateTime.Year = year;
                _scheduleUpdateTime.Day  = day;
                _scheduleUpdateTime.Hour = hourFloat;
                UpdateSchedule();
            }
            if (Prefs.DevMode && Settings.VerboseLogging)
            {
                Log.Message("----------------------------------------------------");
            }
        }
Пример #4
0
        IEnumerator TickTasks()
        {
            var sw = new Stopwatch();

            sw.Start();
            RepositionColonists();
            yield return(null);

            HandleIncidents();
            yield return(null);

            FetchAvoidGrid();
            yield return(null);

            RecalculateVisibleMap();
            yield return(null);

            IncreaseZombiePopulation();
            yield return(null);

            UpdateZombieAvoider();
            yield return(null);

            ExecuteExplosions();
            yield return(null);

            var volume = 0f;

            if (allZombiesCached.Any())
            {
                var hour = GenLocalDate.HourFloat(Find.CurrentMap);
                if (hour < 12f)
                {
                    hour += 24f;
                }
                if (hour > Constants.HOUR_START_OF_NIGHT && hour < Constants.HOUR_END_OF_NIGHT)
                {
                    volume = 1f;
                }
                else if (hour >= Constants.HOUR_START_OF_DUSK && hour <= Constants.HOUR_START_OF_NIGHT)
                {
                    volume = GenMath.LerpDouble(Constants.HOUR_START_OF_DUSK, Constants.HOUR_START_OF_NIGHT, 0f, 1f, hour);
                }
                else if (hour >= Constants.HOUR_END_OF_NIGHT && hour <= Constants.HOUR_START_OF_DAWN)
                {
                    volume = GenMath.LerpDouble(Constants.HOUR_END_OF_NIGHT, Constants.HOUR_START_OF_DAWN, 1f, 0f, hour);
                }
            }
            yield return(null);

            if (Constants.USE_SOUND && ZombieSettings.Values.playCreepyAmbientSound)
            {
                if (zombiesAmbientSound == null)
                {
                    zombiesAmbientSound = CustomDefs.ZombiesClosingIn.TrySpawnSustainer(SoundInfo.OnCamera(MaintenanceType.None));
                }

                if (volume < zombiesAmbientSoundVolume)
                {
                    zombiesAmbientSoundVolume -= 0.0001f;
                }
                else if (volume > zombiesAmbientSoundVolume)
                {
                    zombiesAmbientSoundVolume += 0.0001f;
                }
                zombiesAmbientSound.info.volumeFactor = zombiesAmbientSoundVolume;
            }
            else
            {
                if (zombiesAmbientSound != null)
                {
                    zombiesAmbientSound.End();
                    zombiesAmbientSound = null;
                }
            }
            yield return(null);

            if (colonistsConverter.Count > 0)
            {
                var pawn = colonistsConverter.Dequeue();
                Tools.ConvertToZombie(pawn);
            }
            yield return(null);
        }
 public static float DayPercentNotRestingAt(int tile)
 {
     return(Mathf.InverseLerp(6f, 22f, GenLocalDate.HourFloat(tile)));
 }