Пример #1
0
        /// <summary>
        /// Called every frame
        /// </summary>
        /// <param name="gameTime">The current time</param>
        public void Update(DwarfTime gameTime)
        {
            #region Fast Forward To Day
            if (FastForwardToDay)
            {
                if (Time.IsDay())
                {
                    FastForwardToDay = false;
                    foreach (CreatureAI minion in PlayerFaction.Minions)
                    {
                        minion.Stats.Energy.CurrentValue = minion.Stats.Energy.MaxValue;
                    }
                    Time.Speed = 100;
                }
                else
                {
                    Time.Speed = 1000;
                }
            }
            #endregion

            IndicatorManager.Update(gameTime);
            HandleAmbientSound();
            UpdateOrphanedTasks();

            TaskManager.Update(PlayerFaction.Minions);

            if (Paused)
            {
                Renderer.Camera.LastWheel = Mouse.GetState().ScrollWheelValue;
            }

            // Should we display the out of food message?
            checkFoodTimer.Update(gameTime);
            if (checkFoodTimer.HasTriggered)
            {
                var food = CountResourcesWithTag(Resource.ResourceTags.Edible);
                if (food == 0)
                {
                    MakeAnnouncement("We're out of food!", null, () => { return(CountResourcesWithTag(Resource.ResourceTags.Edible) == 0); });
                }
            }

            GamblingState.Update(gameTime);
            EventScheduler.Update(this, Time.CurrentDate);

            Time.Update(gameTime);

            if (Paused)
            {
                ComponentManager.UpdatePaused(gameTime, ChunkManager, Renderer.Camera);
                TutorialManager.Update(UserInterface.Gui);
            }
            // If not paused, we want to just update the rest of the game.
            else
            {
                ParticleManager.Update(gameTime, this);
                TutorialManager.Update(UserInterface.Gui);

                foreach (var updateSystem in UpdateSystems)
                {
                    try
                    {
                        updateSystem.Update(gameTime);
                    }
                    catch (Exception) { }
                }

                UpdateZones(gameTime);

                #region Mourn dead minions
                if (PlayerFaction.Minions.Any(m => m.IsDead))
                {
                    foreach (var minion in PlayerFaction.Minions)
                    {
                        minion.Creature.AddThought("A friend died recently.", new TimeSpan(2, 0, 0, 0), -25.0f);

                        if (!minion.IsDead)
                        {
                            continue;
                        }

                        MakeAnnouncement(String.Format("{0} ({1}) died!", minion.Stats.FullName, minion.Stats.CurrentClass.Name));
                        SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic);
                        Tutorial("death");
                    }
                }
                #endregion

                #region Free stuck minions
                foreach (var minion in PlayerFaction.Minions)
                {
                    if (minion == null)
                    {
                        throw new InvalidProgramException("Null minion?");
                    }
                    if (minion.Stats == null)
                    {
                        throw new InvalidProgramException("Minion has null status?");
                    }

                    if (minion.Stats.IsAsleep)
                    {
                        continue;
                    }

                    if (minion.CurrentTask == null)
                    {
                        continue;
                    }

                    if (minion.Stats.IsTaskAllowed(TaskCategory.Dig))
                    {
                        minion.Movement.SetCan(MoveType.Dig, GameSettings.Default.AllowAutoDigging);
                    }

                    minion.ResetPositionConstraint();
                }
                #endregion

                foreach (var body in PlayerFaction.OwnedObjects)
                {
                    if (body.ReservedFor != null && body.ReservedFor.IsDead)
                    {
                        body.ReservedFor = null;
                    }
                }

                #region Manage selection circles
                PersistentData.SelectedMinions.RemoveAll(m => m.IsDead);

                foreach (var m in PlayerFaction.Minions)
                {
                    var selectionCircle = m.GetRoot().GetComponent <SelectionCircle>();
                    if (selectionCircle != null)
                    {
                        selectionCircle.SetFlagRecursive(GameComponent.Flag.Visible, false);
                    }
                    m.Creature.Sprite.DrawSilhouette = false;
                }
                ;

                foreach (var creature in PersistentData.SelectedMinions)
                {
                    var selectionCircle = creature.GetRoot().GetComponent <SelectionCircle>();
                    if (selectionCircle == null)
                    {
                        selectionCircle = creature.GetRoot().AddChild(new SelectionCircle(creature.Manager)) as SelectionCircle;
                    }
                    selectionCircle.SetFlag(GameComponent.Flag.ShouldSerialize, false);
                    selectionCircle.SetFlagRecursive(GameComponent.Flag.Visible, true);
                    creature.Creature.Sprite.DrawSilhouette = true;
                }
                #endregion

                PersistentData.Designations.CleanupDesignations();

                Factions.Update(gameTime);

                foreach (var applicant in PersistentData.NewArrivals)
                {
                    if (Time.CurrentDate >= applicant.ArrivalTime)
                    {
                        HireImmediately(applicant.Applicant);
                    }
                }

                PersistentData.NewArrivals.RemoveAll(a => Time.CurrentDate >= a.ArrivalTime);



                ComponentManager.Update(gameTime, ChunkManager, Renderer.Camera);
                MonsterSpawner.Update(gameTime);
                bool allAsleep = AreAllEmployeesAsleep();

#if !UPTIME_TEST
                if (SleepPrompt == null && allAsleep && !FastForwardToDay && Time.IsNight())
                {
                    SleepPrompt = new QueuedAnnouncement()
                    {
                        Text        = "All your employees are asleep. Click here to skip to day.",
                        ClickAction = (sender, args) =>
                        {
                            FastForwardToDay = true;
                            SleepPrompt      = null;
                        },
                        ShouldKeep = () =>
                        {
                            return(FastForwardToDay == false && Time.IsNight() && AreAllEmployeesAsleep());
                        }
                    };
                    MakeAnnouncement(SleepPrompt);
                }
                else if (!allAsleep)
                {
                    Time.Speed       = 100;
                    FastForwardToDay = false;
                    SleepPrompt      = null;
                }
#endif
            }

            // These things are updated even when the game is paused

            Splasher.Splash(gameTime, ChunkManager.Water.GetSplashQueue());

            ChunkManager.Update(gameTime, Renderer.Camera, GraphicsDevice);
            SoundManager.Update(gameTime, Renderer.Camera, Time);
            Weather.Update(this.Time.CurrentDate, this);

#if DEBUG
            KeyboardState k = Keyboard.GetState();
            if (k.IsKeyDown(Keys.Home))
            {
                try
                {
                    GameState.Game.GraphicsDevice.Reset();
                }
                catch (Exception exception)
                {
                }
            }
#endif

            if (Time.CurrentDate.Hour != _prevHour)
            {
                TrackStats();
            }
            _prevHour = Time.CurrentDate.Hour;
        }
Пример #2
0
        /// <summary>
        /// Called every frame
        /// </summary>
        /// <param name="gameTime">The current time</param>
        public void Update(DwarfTime gameTime)
        {
            IndicatorManager.Update(gameTime);
            HandleAmbientSound();

            TaskManager.Update(PlayerFaction.Minions);

            //if (Paused)
            //    Renderer.Camera.LastWheel = Mouse.GetState().ScrollWheelValue;

            // Should we display the out of food message?
            checkFoodTimer.Update(gameTime);
            if (checkFoodTimer.HasTriggered)
            {
                var food = CountResourcesWithTag("Edible");
                if (food == 0)
                {
                    MakeAnnouncement("We're out of food!", null, () => { return(CountResourcesWithTag("Edible") == 0); });
                }
            }

            GamblingState.Update(gameTime);
            EventScheduler.Update(this, Time.CurrentDate);

            Time.Update(gameTime);

            if (Paused)
            {
                ComponentManager.UpdatePaused(gameTime, ChunkManager, Renderer.Camera);
                TutorialManager.Update(UserInterface.Gui);
            }
            // If not paused, we want to just update the rest of the game.
            else
            {
                ParticleManager.Update(gameTime, this);
                TutorialManager.Update(UserInterface.Gui);

                foreach (var updateSystem in UpdateSystems)
                {
                    try
                    {
                        updateSystem.Update(gameTime);
                    }
                    catch (Exception) { }
                }

                UpdateZones(gameTime);

                #region Mourn dead minions
                foreach (var deadMinion in PlayerFaction.Minions.Where(m => m.IsDead && m.Stats.CurrentClass.TriggersMourning))
                {
                    MakeAnnouncement(String.Format("{0} ({1}) died!", deadMinion.Stats.FullName, deadMinion.Stats.CurrentClass.Name));
                    SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic);
                    Tutorial("death");

                    foreach (var minion in PlayerFaction.Minions)
                    {
                        minion.Creature.AddThought("A friend died recently.", new TimeSpan(2, 0, 0, 0), -25.0f);
                    }
                }
                #endregion

                #region Free stuck minions
                foreach (var minion in PlayerFaction.Minions)
                {
                    if (minion == null)
                    {
                        throw new InvalidProgramException("Null minion?");
                    }
                    if (minion.Stats == null)
                    {
                        throw new InvalidProgramException("Minion has null status?");
                    }

                    if (minion.Stats.IsAsleep)
                    {
                        continue;
                    }

                    if (!minion.CurrentTask.HasValue())
                    {
                        continue;
                    }

                    if (minion.Stats.IsTaskAllowed(TaskCategory.Dig))
                    {
                        minion.Movement.SetCan(MoveType.Dig, GameSettings.Current.AllowAutoDigging);
                    }

                    minion.ResetPositionConstraint();
                }
                #endregion

                foreach (var body in PlayerFaction.OwnedObjects)
                {
                    if (body.ReservedFor != null && body.ReservedFor.IsDead)
                    {
                        body.ReservedFor = null;
                    }
                }

                #region Manage selection circles
                PersistentData.SelectedMinions.RemoveAll(m => m.IsDead);

                foreach (var m in PlayerFaction.Minions)
                {
                    if (m.GetRoot().GetComponent <SelectionCircle>().HasValue(out var selectionCircle))
                    {
                        selectionCircle.SetFlagRecursive(GameComponent.Flag.Visible, false);
                    }

                    m.Creature.Sprite.DrawSilhouette = false;
                }
                ;

                foreach (var creature in PersistentData.SelectedMinions)
                {
                    if (creature.GetRoot().GetComponent <SelectionCircle>().HasValue(out var selectionCircle))
                    {
                        selectionCircle.SetFlag(GameComponent.Flag.ShouldSerialize, false);
                        selectionCircle.SetFlagRecursive(GameComponent.Flag.Visible, true);
                    }
                    else
                    {
                        selectionCircle = creature.GetRoot().AddChild(new SelectionCircle(creature.Manager, creature.Creature.Physics)) as SelectionCircle;
                        selectionCircle.SetFlag(GameComponent.Flag.ShouldSerialize, false);
                        selectionCircle.SetFlagRecursive(GameComponent.Flag.Visible, true);
                    }

                    creature.Creature.Sprite.DrawSilhouette = true;
                }
                #endregion

                PersistentData.Designations.CleanupDesignations();

                Factions.Update(gameTime);

                foreach (var applicant in PersistentData.NewArrivals)
                {
                    if (Time.CurrentDate >= applicant.ArrivalTime)
                    {
                        HireImmediately(applicant.Applicant);
                    }
                }

                PersistentData.NewArrivals.RemoveAll(a => Time.CurrentDate >= a.ArrivalTime);



                ComponentManager.Update(gameTime, ChunkManager, Renderer.Camera);
                MonsterSpawner.Update(gameTime);
            }

            // These things are updated even when the game is paused

            Splasher.Splash(gameTime, ChunkManager.Water.GetSplashQueue());

            ChunkManager.Update(gameTime, Renderer.Camera, GraphicsDevice);
            SoundManager.Update(gameTime, Renderer.Camera, Time);
            Weather.Update(this.Time.CurrentDate, this);

#if DEBUG
            KeyboardState k = Keyboard.GetState();
            if (k.IsKeyDown(Keys.Home))
            {
                try
                {
                    GameState.Game.GraphicsDevice.Reset();
                }
                catch (Exception exception)
                {
                }
            }
#endif

            if (Time.CurrentDate.Hour != _prevHour)
            {
                TrackStats();
            }
            _prevHour = Time.CurrentDate.Hour;
        }