/// <summary> /// Called every frame /// </summary> /// <param name="gameTime">The current time</param> public void Update(DwarfTime gameTime) { foreach (var func in LazyActions) { if (func != null) { func.Invoke(); } } LazyActions.Clear(); if (FastForwardToDay) { if (Time.IsDay()) { FastForwardToDay = false; foreach (CreatureAI minion in Master.Faction.Minions) { minion.Status.Energy.CurrentValue = minion.Status.Energy.MaxValue; } //Master.ToolBar.SpeedButton.SetSpeed(1); Time.Speed = 100; } else { //Master.ToolBar.SpeedButton.SetSpecialSpeed(3); Time.Speed = 1000; } } //ParticleManager.Trigger("dice", CursorLightPos + Vector3.Up, Color.White, 1); FillClosestLights(gameTime); IndicatorManager.Update(gameTime); AspectRatio = GraphicsDevice.Viewport.AspectRatio; Camera.AspectRatio = AspectRatio; Camera.Update(gameTime, ChunkManager); HandleAmbientSound(); Master.Update(Game, gameTime); GoalManager.Update(this); Time.Update(gameTime); if (LastWorldPopup != null) { List <uint> removals = new List <uint>(); foreach (var popup in LastWorldPopup) { popup.Value.Update(gameTime, Camera, GraphicsDevice.Viewport); if (popup.Value.Widget == null || !Gui.RootItem.Children.Contains(popup.Value.Widget) || popup.Value.BodyToTrack == null || popup.Value.BodyToTrack.IsDead) { removals.Add(popup.Key); } } foreach (var removal in removals) { if (LastWorldPopup[removal].Widget != null && Gui.RootItem.Children.Contains(LastWorldPopup[removal].Widget)) { Gui.DestroyWidget(LastWorldPopup[removal].Widget); } LastWorldPopup.Remove(removal); } } if (Paused) { ComponentManager.UpdatePaused(gameTime, ChunkManager, Camera); TutorialManager.Update(Gui); } // If not paused, we want to just update the rest of the game. else { ParticleManager.Update(gameTime, this); TutorialManager.Update(Gui); Diplomacy.Update(gameTime, Time.CurrentDate, this); Factions.Update(gameTime); ComponentManager.Update(gameTime, ChunkManager, Camera); Sky.TimeOfDay = Time.GetSkyLightness(); Sky.CosTime = (float)(Time.GetTotalHours() * 2 * Math.PI / 24.0f); DefaultShader.TimeOfDay = Sky.TimeOfDay; MonsterSpawner.Update(gameTime); bool allAsleep = Master.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() && Master.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, Camera, GraphicsDevice); ChunkRenderer.Update(gameTime, Camera, GraphicsDevice); SoundManager.Update(gameTime, Camera, Time); Weather.Update(this.Time.CurrentDate, this); if (gameFile != null) { // Cleanup game file. gameFile = null; } #if DEBUG KeyboardState k = Keyboard.GetState(); if (k.IsKeyDown(Keys.Home)) { try { GameState.Game.GraphicsDevice.Reset(); } catch (Exception exception) { } } #endif }
/// <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; }
/// <summary> /// Called every frame /// </summary> /// <param name="gameTime">The current time</param> public void Update(DwarfTime gameTime) { EntityFactory.DoLazyActions(); if (FastForwardToDay) { if (Time.IsDay()) { FastForwardToDay = false; foreach (CreatureAI minion in Master.Faction.Minions) { minion.Status.Energy.CurrentValue = minion.Status.Energy.MaxValue; } //Master.ToolBar.SpeedButton.SetSpeed(1); Time.Speed = 100; } else { //Master.ToolBar.SpeedButton.SetSpecialSpeed(3); Time.Speed = 1000; } } //Drawer3D.DrawPlane(0, Camera.Position.X - 1500, Camera.Position.Z - 1500, Camera.Position.X + 1500, Camera.Position.Z + 1500, Color.Black); FillClosestLights(gameTime); IndicatorManager.Update(gameTime); AspectRatio = GraphicsDevice.Viewport.AspectRatio; Camera.AspectRatio = AspectRatio; Camera.Update(gameTime, ChunkManager); HandleAmbientSound(); Master.Update(Game, gameTime); GoalManager.Update(this); Time.Update(gameTime); if (Paused) { ComponentManager.UpdatePaused(); } // If not paused, we want to just update the rest of the game. else { TutorialManager.Update(Gui); GamePerformance.Instance.StartTrackPerformance("Diplomacy"); Diplomacy.Update(gameTime, Time.CurrentDate, this); GamePerformance.Instance.StopTrackPerformance("Diplomacy"); GamePerformance.Instance.StartTrackPerformance("Factions"); Factions.Update(gameTime); GamePerformance.Instance.StopTrackPerformance("Factions"); GamePerformance.Instance.StartTrackPerformance("Components"); ComponentManager.Update(gameTime, ChunkManager, Camera); GamePerformance.Instance.StopTrackPerformance("Components"); Sky.TimeOfDay = Time.GetSkyLightness(); Sky.CosTime = (float)(Time.GetTotalHours() * 2 * Math.PI / 24.0f); DefaultShader.TimeOfDay = Sky.TimeOfDay; GamePerformance.Instance.StartTrackPerformance("Monster Spawner"); MonsterSpawner.Update(gameTime); GamePerformance.Instance.StopTrackPerformance("Monster Spawner"); GamePerformance.Instance.StartTrackPerformance("All Asleep"); bool allAsleep = Master.AreAllEmployeesAsleep(); #if !UPTIME_TEST if (SleepPrompt == null && allAsleep && !FastForwardToDay && Time.IsNight()) { SleepPrompt = Gui.ConstructWidget(new Gui.Widgets.Confirm { Text = "All of your employees are asleep. Skip to daytime?", OkayText = "Skip to Daytime", CancelText = "Don't Skip", OnClose = (sender) => { if ((sender as Confirm).DialogResult == Confirm.Result.OKAY) { FastForwardToDay = true; } } }); Gui.ShowModalPopup(SleepPrompt); } else if (!allAsleep) { if (SleepPrompt != null) { SleepPrompt.Close(); } Time.Speed = 100; FastForwardToDay = false; SleepPrompt = null; } #endif GamePerformance.Instance.StopTrackPerformance("All Asleep"); } // These things are updated even when the game is paused GamePerformance.Instance.StartTrackPerformance("Chunk Manager"); ChunkManager.Update(gameTime, Camera, GraphicsDevice); ChunkRenderer.Update(gameTime, Camera, GraphicsDevice); GamePerformance.Instance.StopTrackPerformance("Chunk Manager"); GamePerformance.Instance.StartTrackPerformance("Sound Manager"); SoundManager.Update(gameTime, Camera, Time); GamePerformance.Instance.StopTrackPerformance("Sound Manager"); GamePerformance.Instance.StartTrackPerformance("Weather"); Weather.Update(this.Time.CurrentDate, this); GamePerformance.Instance.StopTrackPerformance("Weather"); if (gameFile != null) { // Cleanup game file. gameFile = null; } }