public void UpdateRooms() { bool hasAnyMinions = SelectedMinions.Count > 0; foreach (Room room in Faction.GetRooms()) { if (room.wasDeserialized) { room.CreateGUIObjects(); room.wasDeserialized = false; } if (room.GUIObject != null && hasAnyMinions) { room.GUIObject.IsVisible = true; room.GUIObject.Enabled = true; } else if (!hasAnyMinions && room.GUIObject != null) { room.GUIObject.IsVisible = false; room.GUIObject.GUIObject.IsVisible = false; room.GUIObject.Enabled = false; } } }
public virtual Task ActOnIdle() { if (GatherManager.VoxelOrders.Count == 0 && (GatherManager.StockOrders.Count == 0 || !Faction.HasFreeStockpile())) { // This is what to do when the unit has not been given any explicit orders. List <Room> rooms = Faction.GetRooms(); // Find a room to train in if (Stats.CurrentClass.HasAction(GameMaster.ToolMode.Attack) && MathFunctions.RandEvent(0.01f)) { Body closestTraining = Faction.FindNearestItemWithTags("Train", Position, true); if (closestTraining != null) { return(new ActWrapperTask(new GoTrainAct(this))); } } // Otherwise, try to find a chair to sit in if (IdleTimer.HasTriggered && MathFunctions.RandEvent(0.25f)) { return(new ActWrapperTask(new GoToChairAndSitAct(this)) { Priority = Task.PriorityType.Eventually, AutoRetry = false }); } return(new ActWrapperTask(new WanderAct(this, 2, 1.0f + MathFunctions.Rand(-0.5f, 0.5f), 1.0f)) { Priority = Task.PriorityType.Eventually }); } // If we have no more build orders, look for gather orders else if (GatherManager.VoxelOrders.Count == 0) { GatherManager.StockOrder order = GatherManager.StockOrders[0]; GatherManager.StockOrders.RemoveAt(0); return(new ActWrapperTask(new StockResourceAct(this, order.Resource)) { Priority = Task.PriorityType.Low }); } // Otherwise handle build orders. else { List <Voxel> voxels = new List <Voxel>(); List <VoxelType> types = new List <VoxelType>(); foreach (GatherManager.BuildVoxelOrder order in GatherManager.VoxelOrders) { voxels.Add(order.Voxel); types.Add(order.Type); } GatherManager.VoxelOrders.Clear(); return(new ActWrapperTask(new BuildVoxelsAct(this, voxels, types)) { Priority = Task.PriorityType.Low, AutoRetry = true }); } }
void HireButton_OnClicked() { List <Room> rooms = Faction.GetRooms(); bool hasBalloonPort = rooms.Any(room => room.RoomData.Name == "BalloonPort"); if (CurrentApplicant.Level.Pay * 4 > Faction.Economy.CurrentMoney) { Dialog.Popup(GUI, "Can't hire!", "We can't afford the signing bonus. Our treasury: " + Faction.Economy.CurrentMoney.ToString("C"), ButtonType.OK, 500, 300, this, LocalBounds.Width / 2 - 250, LocalBounds.Height / 2 - 150); } else if (!hasBalloonPort) { Dialog.Popup(GUI, "Can't hire!", "We can't hire anyone when there are no balloon ports.", ButtonType.OK, 500, 300, this, LocalBounds.Width / 2 - 250, LocalBounds.Height / 2 - 150); } else { Applicants.Remove(CurrentApplicant); Faction.Hire(CurrentApplicant); SoundManager.PlaySound(ContentPaths.Audio.cash); OnOnHired(CurrentApplicant); CurrentApplicant = Applicants.FirstOrDefault(); ApplicantSelector.ClearChildren(); ApplicantSelector.Items.Clear(); foreach (Applicant applicant in Applicants) { ApplicantSelector.AddItem(applicant.Level.Name + " - " + applicant.Name); } ApplicantPanel.SetApplicant(Applicants.FirstOrDefault()); WasSomeoneHired = true; } }
public void VoxelsSelected(List <VoxelHandle> refs, InputManager.MouseButton button) { foreach (BuildRoomOrder order in BuildDesignations) { order.SetTint(Color.White); } foreach (Room room in Faction.GetRooms()) { room.SetTint(Color.White); } if (CurrentRoomData == null) { return; } if (button == InputManager.MouseButton.Left) { if (CurrentRoomData.Verify(refs, Faction, World)) { BuildNewVoxels(refs); } } }
public void OnVoxelsDragged(List <VoxelHandle> refs, InputManager.MouseButton button) { World.Master.VoxSelector.SelectionColor = Color.White; if (Faction == null) { Faction = World.PlayerFaction; } foreach (BuildRoomOrder order in BuildDesignations) { order.SetTint(Color.White); } foreach (Room room in Faction.GetRooms()) { room.SetTint(Color.White); } if (CurrentRoomData == null) { return; } if (button == InputManager.MouseButton.Left) { World.Tutorial("build " + CurrentRoomData.Name); if (CurrentRoomData.Verify(refs, Faction, World)) { List <Quantitiy <Resource.ResourceTags> > requirements = CurrentRoomData.GetRequiredResources(refs.Count, Faction); string tip = "Needs "; if (requirements.Count == 0) { tip = ""; } int i = 0; foreach (var requirement in requirements) { i++; tip += requirement.NumResources.ToString(); tip += " "; tip += requirement.ResourceType; tip += "\n"; } World.ShowTooltip("Release to build here."); } else { World.Master.VoxSelector.SelectionColor = GameSettings.Default.Colors.GetColor("Negative", Color.Red); } } }
public bool Verify( List <VoxelHandle> Voxels, Faction Faction, WorldManager World) { if (Voxels.Count == 0) { return(false); } if (Faction.GetRooms().Where(room => room.RoomData.Name == this.Name).Count() + 1 > MaxNumRooms) { World.ShowToolPopup(String.Format("We can only build {0} {1}. Destroy the existing to build a new one.", MaxNumRooms, Name)); return(false); } // Todo: Lift into helper function that uses better algorithm. List <BoundingBox> boxes = Voxels.Select(voxel => voxel.GetBoundingBox()).ToList(); BoundingBox box = MathFunctions.GetBoundingBox(boxes); Vector3 extents = box.Max - box.Min; float maxExtents = Math.Max(extents.X, extents.Z); float minExtents = Math.Min(extents.X, extents.Z); if (maxExtents < MinimumSideLength || minExtents < MinimumSideWidth) { World.ShowToolPopup("Room is too small (minimum is " + MinimumSideLength + " x " + MinimumSideWidth + ")!"); return(false); } int height = Voxels[0].Coordinate.Y; bool allEmpty = true; foreach (var voxel in Voxels) { if (voxel.IsEmpty) { continue; } var above = VoxelHelpers.GetVoxelAbove(voxel); allEmpty &= (above.IsValid && above.IsEmpty); if (voxel.Type.IsInvincible) { continue; } if (height != (int)voxel.Coordinate.Y && !CanBuildOnMultipleLevels) { World.ShowToolPopup("Room must be on flat ground!"); return(false); } if (MustBeBuiltOnSoil && !voxel.Type.IsSoil) { World.ShowToolPopup("Room must be built on soil!"); return(false); } if (!CanBuildAboveGround && voxel.Sunlight) { World.ShowToolPopup("Room can't be built aboveground!"); return(false); } if (!CanBuildBelowGround && !voxel.Sunlight) { World.ShowToolPopup("Room can't be built belowground!"); return(false); } } if (!allEmpty) { World.ShowToolPopup("Room must be built in free space."); return(false); } return(true); }
public void OnVoxelsDragged(List <VoxelHandle> refs, InputManager.MouseButton button) { if (Faction == null) { Faction = World.PlayerFaction; } if (displayObjects != null) { foreach (var thing in displayObjects) { thing.Delete(); } } foreach (BuildRoomOrder order in BuildDesignations) { order.SetTint(Color.White); } foreach (Room room in Faction.GetRooms()) { room.SetTint(Color.White); } if (CurrentRoomData == null) { return; } if (button == InputManager.MouseButton.Left) { World.Tutorial("build " + CurrentRoomData.Name); if (CurrentRoomData.Verify(refs, Faction, World)) { List <Quantitiy <Resource.ResourceTags> > requirements = CurrentRoomData.GetRequiredResources(refs.Count, Faction); string tip = "Needs "; if (requirements.Count == 0) { tip = ""; } int i = 0; foreach (var requirement in requirements) { i++; tip += requirement.NumResources.ToString(); tip += " "; tip += requirement.ResourceType; tip += "\n"; } World.ShowToolPopup("Release to build here."); displayObjects = RoomLibrary.GenerateRoomComponentsTemplate(CurrentRoomData, refs, World.ComponentManager, World.ChunkManager.Content, World.ChunkManager.Graphics); foreach (Body thing in displayObjects) { thing.SetFlagRecursive(GameComponent.Flag.Active, false); SetDisplayColor(thing, Color.Green); } } } else { foreach (var v in refs.Where(v => v.IsValid && !v.IsEmpty)) { if (IsBuildDesignation(v)) { var order = GetBuildDesignation(v); if (order == null || order.Order == null) { // TODO(mklingen): Don't know how this could happen, but we got a crash here... continue; } if (!order.Order.IsBuilt) { order.Order.SetTint(Color.Red); } else { order.ToBuild.SetTint(Color.Red); } break; } else if (IsInRoom(v)) { Room existingRoom = GetMostLikelyRoom(v); if (existingRoom == null) { continue; } existingRoom.SetTint(Color.Red); break; } } } }
public bool Verify( List <VoxelHandle> Voxels, Faction Faction, WorldManager World) { if (Voxels.Count == 0) { return(false); } if (Faction.GetRooms().Where(room => room.RoomData.Name == this.Name).Count() + 1 > MaxNumRooms) { World.ShowTooltip(String.Format("We can only build {0} {1}. Destroy the existing to build a new one.", MaxNumRooms, Name)); return(false); } List <BoundingBox> boxes = Voxels.Select(voxel => voxel.GetBoundingBox()).ToList(); BoundingBox box = MathFunctions.GetBoundingBox(boxes); Vector3 extents = box.Max - box.Min; float maxExtents = Math.Max(extents.X, extents.Z); float minExtents = Math.Min(extents.X, extents.Z); if (maxExtents < MinimumSideLength || minExtents < MinimumSideWidth) { World.ShowTooltip("Room is too small (minimum is " + MinimumSideLength + " x " + MinimumSideWidth + ")!"); return(false); } int height = Voxels[0].Coordinate.Y; foreach (var voxel in Voxels) { if (voxel.IsEmpty) { World.ShowTooltip("Room must be built on solid ground."); return(false); } var above = VoxelHelpers.GetVoxelAbove(voxel); if (above.IsValid && !above.IsEmpty) { World.ShowTooltip("Room must be built in free space."); return(false); } if (voxel.Type.IsInvincible) { continue; } if (height != (int)voxel.Coordinate.Y) { World.ShowTooltip("Room must be on flat ground!"); return(false); } if (!CanBuildAboveGround && voxel.Sunlight) { World.ShowTooltip("Room can't be built aboveground!"); return(false); } if (!CanBuildBelowGround && !voxel.Sunlight) { World.ShowTooltip("Room can't be built belowground!"); return(false); } if (Faction.RoomBuilder.IsInRoom(voxel) || Faction.RoomBuilder.IsBuildDesignation(voxel)) { World.ShowTooltip("Room's can't overlap!"); return(false); } } return(true); }