public PlaceRoomResourcesAct(CreatureAI agent, BuildRoomOrder buildRoom, List <ResourceAmount> resources) : base(agent) { Name = "Place BuildRoom resources"; BuildRoom = buildRoom; Resources = resources; }
public IEnumerable <Status> SetTargetVoxelFromRoom(BuildRoomOrder buildRoom, string target) { if (buildRoom.VoxelOrders.Count == 0) { yield return(Status.Fail); } else { Voxel closestVoxel = null; float closestDist = float.MaxValue; foreach (BuildVoxelOrder voxDes in buildRoom.VoxelOrders) { float dist = (voxDes.Voxel.Position - Agent.Position).LengthSquared(); if (dist < closestDist) { closestDist = dist; closestVoxel = voxDes.Voxel; } } Agent.Blackboard.SetData(target, closestVoxel); yield return(Status.Success); } }
public override Act CreateScript(Creature creature) { Room room = Zone as Room; if (room == null) { return(null); } if (!creature.Faction.RoomBuilder.IsBuildDesignation(room)) { return(null); } BuildVoxelOrder voxVoxelOrder = creature.Faction.RoomBuilder.GetBuildDesignation(room); if (voxVoxelOrder == null) { return(null); } BuildRoomOrder designation = voxVoxelOrder.Order; if (designation == null) { return(null); } return(new BuildRoomAct(creature.AI, designation)); }
public PlaceRoomResourcesAct(CreatureAI agent, BuildRoomOrder buildRoom, List<ResourceAmount> resources) : base(agent) { Name = "Place BuildRoom resources"; BuildRoom = buildRoom; Resources = resources; }
public BuildRoomAct(CreatureAI agent, BuildRoomOrder buildRoom) : base(agent) { Name = "Build BuildRoom " + buildRoom.ToString(); Resources = buildRoom.ListRequiredResources(); BuildRoom = buildRoom; if (BuildRoom.ResourcesReservedFor != null && BuildRoom.ResourcesReservedFor.IsDead) { BuildRoom.ResourcesReservedFor = null; } Tree = new Sequence(new Select(new Domain(buildRoom.HasResources || buildRoom.ResourcesReservedFor != null, true), new Domain(!buildRoom.HasResources && (buildRoom.ResourcesReservedFor == null || buildRoom.ResourcesReservedFor == Agent), new Sequence(new Wrap(Reserve), new GetResourcesAct(Agent, Resources))), new Domain(buildRoom.HasResources || buildRoom.ResourcesReservedFor != null, true)), new Domain(() => IsRoomBuildOrder(buildRoom) && !buildRoom.IsBuilt && !buildRoom.IsDestroyed && ValidResourceState(), new Sequence( SetTargetVoxelFromRoomAct(buildRoom, "ActionVoxel"), new GoToNamedVoxelAct("ActionVoxel", PlanAct.PlanType.Adjacent, Agent), new Wrap(PutResources), new Wrap(WaitForResources) { Name = "Wait for resources..." }, new Wrap(() => Creature.HitAndWait(true, () => 1.0f, () => buildRoom.BuildProgress, () => buildRoom.BuildProgress += agent.Stats.BuildSpeed / buildRoom.VoxelOrders.Count * 0.5f, () => MathFunctions.RandVector3Box(buildRoom.GetBoundingBox()), ContentPaths.Audio.Oscar.sfx_ic_dwarf_craft, () => !buildRoom.IsBuilt && !buildRoom.IsDestroyed)) { Name = "Build room.." }, new CreateRoomAct(Agent, buildRoom) , new Wrap(OnFailOrCancel))) | new Wrap(OnFailOrCancel) ); }
public PlaceRoomResourcesAct(CreatureAI agent, BuildRoomOrder buildRoom, List <Quantitiy <Resource.ResourceTags> > resources) : base(agent) { Name = "Place BuildRoom resources"; BuildRoom = buildRoom; Resources = resources; }
public IEnumerable <Status> SetTargetVoxelFromRoom(BuildRoomOrder buildRoom, string target) { if (buildRoom.VoxelOrders.Count == 0) { yield return(Status.Fail); } else { var closestVoxel = VoxelHandle.InvalidHandle; float closestDist = float.MaxValue; foreach (var order in buildRoom.VoxelOrders) { float dist = (order.Voxel.WorldPosition - Agent.Position).LengthSquared(); if (dist < closestDist) { closestDist = dist; closestVoxel = order.Voxel; } } Agent.Blackboard.SetData(target, closestVoxel); yield return(Status.Success); } }
public BuildRoomTask(BuildRoomOrder zone) { Category = TaskCategory.BuildZone; MaxAssignable = 3; Name = "Build Room " + zone.ToBuild.RoomData.Name + zone.ToBuild.ID; Zone = zone; Priority = PriorityType.High; }
private void BuildNewVoxels(IEnumerable <Voxel> refs) { BuildRoomOrder order = null; IEnumerable <Voxel> designations = refs as IList <Voxel> ?? refs.ToList(); IEnumerable <Voxel> nonEmpty = designations.Select(r => r).Where(v => !v.IsEmpty); foreach (Voxel v in nonEmpty) { if (IsBuildDesignation(v) || IsInRoom(v)) { continue; } if (!v.GetVoxelAbove().IsEmpty) { continue; } if (order == null) { order = GetMostLikelyDesignation(v); } if (order != null) { order.VoxelOrders.Add(new BuildVoxelOrder(order, order.ToBuild, v)); } else { if (CurrentRoomData != RoomLibrary.GetData("Stockpile")) { Room toBuild = RoomLibrary.CreateRoom(Faction, CurrentRoomData.Name, designations.ToList(), true, World); DesignatedRooms.Add(toBuild); order = new BuildRoomOrder(toBuild, Faction, Faction.World); order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v)); BuildDesignations.Add(order); } else { Stockpile toBuild = new Stockpile(Faction, World); DesignatedRooms.Add(toBuild); order = new BuildStockpileOrder(toBuild, this.Faction); order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v)); BuildDesignations.Add(order); } } } if (order != null) { order.CreateFences(World.ComponentManager); TaskManager.AssignTasks(new List <Task>() { new BuildRoomTask(order) }, Faction.FilterMinionsWithCapability(World.Master.SelectedMinions, GameMaster.ToolMode.Build)); } }
public BuildRoomTask(BuildRoomOrder zone) { Category = TaskCategory.BuildZone; MaxAssignable = 3; Name = "Build Room " + zone.ToBuild.RoomData.Name + zone.ToBuild.ID; Zone = zone; Priority = PriorityType.Medium; BoredomIncrease = GameSettings.Default.Boredom_NormalTask; }
void destroyDialog_OnClosed(NewGui.Confirm.Result status, Room room) { if (status == NewGui.Confirm.Result.OKAY) { DesignatedRooms.Remove(room); List <BuildVoxelOrder> existingDesignations = GetDesignationsAssociatedWithRoom(room); BuildRoomOrder buildRoomDes = null; foreach (BuildVoxelOrder des in existingDesignations) { des.Order.VoxelOrders.Remove(des); buildRoomDes = des.Order; } BuildDesignations.Remove(buildRoomDes); room.Destroy(); } }
void destroyDialog_OnClosed(Dialog.ReturnStatus status, Room room) { if (status == Dialog.ReturnStatus.Ok) { DesignatedRooms.Remove(room); List <BuildVoxelOrder> existingDesignations = GetDesignationsAssociatedWithRoom(room); BuildRoomOrder buildRoomDes = null; foreach (BuildVoxelOrder des in existingDesignations) { des.Order.VoxelOrders.Remove(des); buildRoomDes = des.Order; } BuildDesignations.Remove(buildRoomDes); room.Destroy(); } }
public BuildRoomAct(CreatureAI agent, BuildRoomOrder buildRoom) : base(agent) { Name = "Build BuildRoom " + buildRoom.ToString(); Resources = buildRoom.ListRequiredResources(); Tree = new Sequence(new GetResourcesAct(Agent, Resources), new Sequence( new Wrap(() => IsRoomBuildOrder(buildRoom)), SetTargetVoxelFromRoomAct(buildRoom, "TargetVoxel"), new Wrap(() => IsRoomBuildOrder(buildRoom)), new GoToVoxelAct("TargetVoxel", PlanAct.PlanType.Adjacent, Agent), new Wrap(() => IsRoomBuildOrder(buildRoom)), new Wrap(() => Creature.HitAndWait(buildRoom.VoxelOrders.Count * 0.5f / agent.Stats.BuildSpeed, true)), new Wrap(() => IsRoomBuildOrder(buildRoom)), new PlaceRoomResourcesAct(Agent, buildRoom, Resources) , new Wrap(Creature.RestockAll)) | new Wrap(Creature.RestockAll) ); }
void destroyDialog_OnClosed(Gui.Widgets.Confirm.Result status, Room room) { if (status == Gui.Widgets.Confirm.Result.OKAY) { Player.Faction.RoomBuilder.DesignatedRooms.Remove(room); List <BuildVoxelOrder> existingDesignations = Player.Faction.RoomBuilder.GetDesignationsAssociatedWithRoom(room); BuildRoomOrder buildRoomDes = null; foreach (BuildVoxelOrder des in existingDesignations) { des.Order.VoxelOrders.Remove(des); buildRoomDes = des.Order; } if (buildRoomDes != null && buildRoomDes.DisplayWidget != null) { Player.World.Gui.DestroyWidget(buildRoomDes.DisplayWidget); } Player.Faction.RoomBuilder.BuildDesignations.Remove(buildRoomDes); room.Destroy(); } }
public static void DestroyRoom(Gui.Widgets.Confirm.Result status, Room room, Faction Faction, WorldManager World) { if (status == Gui.Widgets.Confirm.Result.OKAY) { Faction.RoomBuilder.DesignatedRooms.Remove(room); List <BuildVoxelOrder> existingDesignations = Faction.RoomBuilder.GetDesignationsAssociatedWithRoom(room); BuildRoomOrder buildRoomDes = null; foreach (BuildVoxelOrder des in existingDesignations) { des.Order.VoxelOrders.Remove(des); buildRoomDes = des.Order; } if (buildRoomDes != null && buildRoomDes.DisplayWidget != null) { World.Gui.DestroyWidget(buildRoomDes.DisplayWidget); } Faction.RoomBuilder.BuildDesignations.Remove(buildRoomDes); room.Destroy(); } }
private void BuildNewVoxels(IEnumerable <VoxelHandle> designations) { Room toBuild = RoomLibrary.CreateRoom(Faction, CurrentRoomData.Name, World); var order = new BuildRoomOrder(toBuild, Faction, Faction.World); BuildDesignations.Add(order); DesignatedRooms.Add(toBuild); foreach (var v in designations.Where(v => v.IsValid && !v.IsEmpty)) { order.VoxelOrders.Add(new BuildVoxelOrder(order, order.ToBuild, v)); } order.WorkObjects.AddRange(Fence.CreateFences(World.ComponentManager, ContentPaths.Entities.DwarfObjects.constructiontape, order.VoxelOrders.Select(o => o.Voxel), true)); foreach (var obj in order.WorkObjects) { obj.Manager.RootComponent.AddChild(obj); } World.Master.TaskManager.AddTask(new BuildRoomTask(order)); }
public override void OnVoxelsSelected(List <VoxelHandle> refs, InputManager.MouseButton button) { if (Command.Contains("Build/")) { string type = Command.Substring(6); BuildRoomOrder des = new BuildRoomOrder(RoomLibrary.CreateRoom(Player.Faction, type, refs, false, Player.World), Player.Faction, Player.World); des.ToBuild.Designations = refs; Player.Faction.RoomBuilder.BuildDesignations.Add(des); Player.Faction.RoomBuilder.DesignatedRooms.Add(des.ToBuild); des.Build(); } if (Command.Contains("Spawn/")) { string type = Command.Substring(6); foreach (var vox in refs.Where(vox => vox.IsValid)) { if (vox.IsEmpty) { var craftItem = CraftLibrary.GetCraftable(type); var offset = Vector3.Zero; if (craftItem != null) { offset = craftItem.SpawnOffset; } var body = EntityFactory.CreateEntity <Body>(type, vox.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + offset); if (body != null) { body.PropogateTransforms(); if (craftItem != null) { if (craftItem.AddToOwnedPool) { Player.Faction.OwnedObjects.Add(body); } if (craftItem.Moveable) { body.Tags.Add("Moveable"); } if (craftItem.Deconstructable) { body.Tags.Add("Deconstructable"); } } } } } } else if (Command.Contains("Rail/")) { string type = Command.Substring("Rail/".Length); var junction = new Rail.JunctionPiece { RailPiece = type, Orientation = Rail.PieceOrientation.North, Offset = Point.Zero }; foreach (var vox in refs.Where(vox => vox.IsValid)) { if (vox.IsEmpty) { var entity = new Rail.RailEntity(Player.World.ComponentManager, vox, junction); Player.World.ComponentManager.RootComponent.AddChild(entity); } } } else if (Command.Contains("Grass/")) { var type = GrassLibrary.GetGrassType(Command.Substring(6)); foreach (var vox in refs.Where(v => v.IsValid)) { var v = vox; if (!vox.IsEmpty) { v.GrassType = type.ID; } } } else if (Command.Contains("Decal/")) { var type = DecalLibrary.GetGrassType(Command.Substring(6)); foreach (var vox in refs.Where(v => v.IsValid)) { var v = vox; if (!vox.IsEmpty) { v.Decal = DecalType.EncodeDecal(DecalOrientation, type.ID); } } } else { foreach (var vox in refs.Where(vox => vox.IsValid)) { if (Command.Contains("Place/")) { string type = Command.Substring(6); var v = vox; v.Type = VoxelLibrary.GetVoxelType(type); v.QuickSetLiquid(LiquidType.None, 0); if (type == "Magic") { Player.World.ComponentManager.RootComponent.AddChild( new DestroyOnTimer(Player.World.ComponentManager, Player.World.ChunkManager, vox) { DestroyTimer = new Timer(5.0f + MathFunctions.Rand(-0.5f, 0.5f), true) }); } } else { switch (Command) { case "Delete Block": { var v = vox; Player.World.Master.Faction.OnVoxelDestroyed(vox); v.Type = VoxelLibrary.emptyType; v.QuickSetLiquid(LiquidType.None, 0); } break; case "Kill Block": foreach (var selected in refs) { if (!selected.IsEmpty) { Player.World.ChunkManager.KillVoxel(selected); } } break; case "Fill Water": { if (vox.IsEmpty) { var v = vox; v.QuickSetLiquid(LiquidType.Water, WaterManager.maxWaterLevel); } } break; case "Fill Lava": { if (vox.IsEmpty) { var v = vox; v.QuickSetLiquid(LiquidType.Lava, WaterManager.maxWaterLevel); } } break; case "Fire": { foreach (var flam2 in Player.World.EnumerateIntersectingObjects(vox.GetBoundingBox(), CollisionType.Both).OfType <Flammable>()) { flam2.Heat = flam2.Flashpoint + 1; } } break; case "Kill Things": { foreach (var comp in Player.World.EnumerateIntersectingObjects(vox.GetBoundingBox(), CollisionType.Both)) { comp.Die(); } } break; case "Disease": { foreach (var creature in Player.World.EnumerateIntersectingObjects(vox.GetBoundingBox(), CollisionType.Both).OfType <Creature>()) { var disease = Datastructures.SelectRandom(DiseaseLibrary.Diseases); creature.AcquireDisease(disease.Name); } break; } default: break; } } } } }
public BuildRoomTask(BuildRoomOrder zone) { Name = "Build BuildRoom " + zone.ToBuild.RoomData.Name + zone.ToBuild.ID; Zone = zone; Priority = PriorityType.Low; }
public override void OnVoxelsSelected(List <Voxel> refs, InputManager.MouseButton button) { if (!IsActive) { return; } string command = SelectorBox.CurrentValue; if (command == "") { return; } HashSet <Point3> chunksToRebuild = new HashSet <Point3>(); if (command.Contains("Build ")) { string type = command.Substring(6); BuildRoomOrder des = new BuildRoomOrder(RoomLibrary.CreateRoom(type, refs, false), Player.Faction); Player.Faction.RoomBuilder.BuildDesignations.Add(des); Player.Faction.RoomBuilder.DesignatedRooms.Add(des.ToBuild); des.Build(); if (type == Stockpile.StockpileName) { Player.Faction.Stockpiles.Add((Stockpile)des.ToBuild); } } else { foreach (Voxel vox in refs.Where(vox => vox != null)) { if (command.Contains("Place ")) { string type = command.Substring(6); vox.Type = VoxelLibrary.GetVoxelType(type); vox.IsVisible = true; vox.Water = new WaterCell(); vox.Health = vox.Type.StartingHealth; if (type == "Magic") { new VoxelListener(PlayState.ComponentManager, PlayState.ComponentManager.RootComponent, PlayState.ChunkManager, vox) { DestroyOnTimer = true, DestroyTimer = new Timer(5.0f + MathFunctions.Rand(-0.5f, 0.5f), true) }; } chunksToRebuild.Add(vox.ChunkID); } else { switch (command) { case "Delete Block": { PlayState.Master.Faction.OnVoxelDestroyed(vox); vox.Chunk.NotifyDestroyed(new Point3(vox.GridPosition)); vox.Type = VoxelType.TypeList[0]; vox.Water = new WaterCell(); if (!chunksToRebuild.Contains(vox.ChunkID)) { Chunks.ChunkData.ChunkMap[vox.ChunkID].NotifyTotalRebuild(vox.IsEmpty && !vox.IsInterior); } chunksToRebuild.Add(vox.ChunkID); } break; case "Kill Block": foreach (Voxel selected in refs) { if (!selected.IsEmpty) { selected.Kill(); } } break; case "Fill Water": { if (vox.IsEmpty) { vox.WaterLevel = 255; vox.Chunk.Data.Water[vox.Index].Type = LiquidType.Water; chunksToRebuild.Add(vox.ChunkID); } } break; case "Fill Lava": { Vector3 gridPos = vox.GridPosition; if (vox.IsEmpty) { vox.WaterLevel = 255; vox.Chunk.Data.Water[vox.Index].Type = LiquidType.Lava; chunksToRebuild.Add(vox.ChunkID); } } break; case "Fire": { List <Body> components = new List <Body>(); Player.Faction.Components.GetBodiesIntersecting(vox.GetBoundingBox(), components, CollisionManager.CollisionType.Dynamic | CollisionManager.CollisionType.Static); foreach (Flammable flam2 in components.Select(comp => comp.GetChildrenOfTypeRecursive <Flammable>()).Where(flam => flam.Count > 0).SelectMany(flam => flam)) { flam2.Heat = flam2.Flashpoint + 1; } } break; case "Kill Things": { List <Body> components = new List <Body>(); Player.Faction.Components.GetBodiesIntersecting(vox.GetBoundingBox(), components, CollisionManager.CollisionType.Dynamic | CollisionManager.CollisionType.Static); foreach (Body comp in components) { comp.Die(); } } break; default: if (vox.IsEmpty) { EntityFactory.CreateEntity <Body>(SelectorBox.CurrentValue, vox.Position + new Vector3(0.5f, 0.5f, 0.5f)); } break; } } } } foreach (Point3 chunk in chunksToRebuild) { Chunks.ChunkData.ChunkMap[chunk].NotifyTotalRebuild(false); } }
public BuildVoxelOrder(BuildRoomOrder Order, Room ToBuild, VoxelHandle Voxel) { this.Order = Order; this.ToBuild = ToBuild; this.Voxel = Voxel; }
private void BuildNewVoxels(IEnumerable<Voxel> refs) { BuildRoomOrder order = null; IEnumerable<Voxel> designations = refs as IList<Voxel> ?? refs.ToList(); IEnumerable<Voxel> nonEmpty = designations.Select(r => r).Where(v => !v.IsEmpty); foreach(Voxel v in nonEmpty) { if(IsBuildDesignation(v) || IsInRoom(v)) { continue; } if(order == null) { order = GetMostLikelyDesignation(v); } if (order != null) { order.VoxelOrders.Add(new BuildVoxelOrder(order, order.ToBuild, v)); } else { if(CurrentRoomData != RoomLibrary.GetData("Stockpile")) { Room toBuild = RoomLibrary.CreateRoom(CurrentRoomData.Name, designations.ToList(), true); DesignatedRooms.Add(toBuild); order = new BuildRoomOrder(toBuild, this.Faction); order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v)); BuildDesignations.Add(order); } else { Stockpile toBuild = new Stockpile("Stockpile " + Stockpile.NextID(), PlayState.ChunkManager); DesignatedRooms.Add(toBuild); order = new BuildStockpileOrder(toBuild, this.Faction); order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v)); BuildDesignations.Add(order); } } } if(order != null) { TaskManager.AssignTasks(new List<Task>() { new BuildRoomTask(order) }, Faction.FilterMinionsWithCapability(PlayState.Master.SelectedMinions, GameMaster.ToolMode.Build)); } }
public BuildVoxelOrder(BuildRoomOrder order, Room toBuild, Voxel voxel) { Order = order; ToBuild = toBuild; Voxel = voxel; }
public Act SetTargetVoxelFromRoomAct(BuildRoomOrder buildRoom, string target) { return new Wrap(() => SetTargetVoxelFromRoom(buildRoom, target)); }
private void BuildNewVoxels(IEnumerable <VoxelHandle> designations) { BuildRoomOrder order = null; foreach (var v in designations.Where(v => v.IsValid && !v.IsEmpty)) { if (IsBuildDesignation(v) || IsInRoom(v)) { continue; } // This check should be rendered pointless by the call to Verify made just // before calling this function. var above = VoxelHelpers.GetVoxelAbove(v); if (above.IsValid && !above.IsEmpty) { continue; } if (order == null) { order = GetMostLikelyDesignation(v); } if (order != null && order.ToBuild.RoomData == CurrentRoomData && !order.IsBuilt) { order.VoxelOrders.Add(new BuildVoxelOrder(order, order.ToBuild, v)); } else if (order == null) { if (CurrentRoomData == RoomLibrary.GetData("Stockpile")) { Stockpile toBuild = new Stockpile(Faction, World); DesignatedRooms.Add(toBuild); order = new BuildStockpileOrder(toBuild, this.Faction); order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v)); BuildDesignations.Add(order); } else if (CurrentRoomData == RoomLibrary.GetData("Treasury")) { Treasury toBuild = new Treasury(Faction, World); DesignatedRooms.Add(toBuild); order = new BuildRoomOrder(toBuild, this.Faction, Faction.World); order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v)); BuildDesignations.Add(order); } else { Room toBuild = RoomLibrary.CreateRoom(Faction, CurrentRoomData.Name, designations.ToList(), true, World); DesignatedRooms.Add(toBuild); order = new BuildRoomOrder(toBuild, Faction, Faction.World); order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v)); BuildDesignations.Add(order); } } else if (order.ToBuild.RoomData != CurrentRoomData || order.IsBuilt) { order = null; } } if (order != null) { order.WorkObjects.AddRange(Fence.CreateFences(World.ComponentManager, ContentPaths.Entities.DwarfObjects.constructiontape, order.VoxelOrders.Select(o => o.Voxel), true)); foreach (var obj in order.WorkObjects) { obj.Manager.RootComponent.AddChild(obj); } World.Master.TaskManager.AddTask(new BuildRoomTask(order)); /* * TaskManager.AssignTasks(new List<Task>() * { * new BuildRoomTask(order) * }, Faction.FilterMinionsWithCapability(World.Master.SelectedMinions, GameMaster.ToolMode.BuildZone)); */ } }
public override void OnVoxelsSelected(List<Voxel> refs, InputManager.MouseButton button) { if(!IsActive) { return; } string command = SelectorBox.CurrentValue; if(command == "") { return; } HashSet<Point3> chunksToRebuild = new HashSet<Point3>(); if(command.Contains("Build ")) { string type = command.Substring(6); BuildRoomOrder des = new BuildRoomOrder(RoomLibrary.CreateRoom(Player.Faction, type, refs, false), Player.Faction); Player.Faction.RoomBuilder.BuildDesignations.Add(des); Player.Faction.RoomBuilder.DesignatedRooms.Add(des.ToBuild); des.Build(); } else { foreach(Voxel vox in refs.Where(vox => vox != null)) { if(command.Contains("Place ")) { string type = command.Substring(6); vox.Type = VoxelLibrary.GetVoxelType(type); vox.Water = new WaterCell(); vox.Health = vox.Type.StartingHealth; if (type == "Magic") { new VoxelListener(PlayState.ComponentManager, PlayState.ComponentManager.RootComponent, PlayState.ChunkManager, vox) { DestroyOnTimer = true, DestroyTimer = new Timer(5.0f + MathFunctions.Rand(-0.5f, 0.5f), true) }; } chunksToRebuild.Add(vox.ChunkID); } else switch(command) { case "Delete Block": { PlayState.Master.Faction.OnVoxelDestroyed(vox); vox.Chunk.NotifyDestroyed(new Point3(vox.GridPosition)); vox.Type = VoxelType.TypeList[0]; vox.Water = new WaterCell(); if(!chunksToRebuild.Contains(vox.ChunkID)) { Chunks.ChunkData.ChunkMap[vox.ChunkID].NotifyTotalRebuild(vox.IsEmpty && !vox.IsInterior); } chunksToRebuild.Add(vox.ChunkID); } break; case "Kill Block": foreach(Voxel selected in refs) { if (!selected.IsEmpty) { selected.Kill(); } } break; case "Fill Water": { if (vox.IsEmpty) { vox.WaterLevel = 255; vox.Chunk.Data.Water[vox.Index].Type = LiquidType.Water; chunksToRebuild.Add(vox.ChunkID); } } break; case "Fill Lava": { Vector3 gridPos = vox.GridPosition; if (vox.IsEmpty) { vox.WaterLevel = 255; vox.Chunk.Data.Water[vox.Index].Type = LiquidType.Lava; chunksToRebuild.Add(vox.ChunkID); } } break; case "Fire": { List<Body> components = new List<Body>(); Player.Faction.Components.GetBodiesIntersecting(vox.GetBoundingBox(), components, CollisionManager.CollisionType.Dynamic | CollisionManager.CollisionType.Static); foreach(Flammable flam2 in components.Select(comp => comp.GetChildrenOfTypeRecursive<Flammable>()).Where(flam => flam.Count > 0).SelectMany(flam => flam)) { flam2.Heat = flam2.Flashpoint + 1; } } break; case "Kill Things": { List<Body> components = new List<Body>(); Player.Faction.Components.GetBodiesIntersecting(vox.GetBoundingBox(), components, CollisionManager.CollisionType.Dynamic | CollisionManager.CollisionType.Static); foreach(Body comp in components) { comp.Die(); } } break; default: if(vox.IsEmpty) { EntityFactory.CreateEntity<Body>(SelectorBox.CurrentValue, vox.Position + new Vector3(0.5f, 0.5f, 0.5f)); } break; } } } foreach(Point3 chunk in chunksToRebuild) { Chunks.ChunkData.ChunkMap[chunk].NotifyTotalRebuild(false); } }
/// <summary> /// Creates a flat, wooden balloon port for the balloon to land on, and Dwarves to sit on. /// </summary> /// <param name="roomDes">The player's BuildRoom designator (so that we can create a balloon port)</param> /// <param name="chunkManager">The terrain handler</param> /// <param name="x">The position of the center of the balloon port</param> /// <param name="z">The position of the center of the balloon port</param> /// <param name="size">The size of the (square) balloon port in voxels on a side</param> public BalloonPort GenerateInitialBalloonPort(RoomBuilder roomDes, ChunkManager chunkManager, float x, float z, int size) { var centerCoordinate = GlobalVoxelCoordinate.FromVector3(new Vector3(x, VoxelConstants.ChunkSizeY - 1, z)); var accumulator = 0; var count = 0; for (var offsetX = -size; offsetX <= size; ++offsetX) { for (var offsetY = -size; offsetY <= size; ++offsetY) { var topVoxel = VoxelHelpers.FindFirstVoxelBelowIncludeWater( new VoxelHandle(chunkManager.ChunkData, centerCoordinate + new GlobalVoxelOffset(offsetX, 0, offsetY))); if (topVoxel.Coordinate.Y > 0) { accumulator += topVoxel.Coordinate.Y + 1; count += 1; } } } var averageHeight = (int)Math.Round(((float)accumulator / (float)count)); // Next, create the balloon port by deciding which voxels to fill. var balloonPortDesignations = new List <VoxelHandle>(); var treasuryDesignations = new List <VoxelHandle>(); for (int dx = -size; dx <= size; dx++) { for (int dz = -size; dz <= size; dz++) { Vector3 worldPos = new Vector3(centerCoordinate.X + dx, centerCoordinate.Y, centerCoordinate.Z + dz); var baseVoxel = VoxelHelpers.FindFirstVoxelBelow(new VoxelHandle( chunkManager.ChunkData, GlobalVoxelCoordinate.FromVector3(worldPos))); if (!baseVoxel.IsValid) { continue; } var h = baseVoxel.Coordinate.Y + 1; var localCoord = baseVoxel.Coordinate.GetLocalVoxelCoordinate(); for (int y = averageHeight; y < h; y++) { var v = new VoxelHandle(baseVoxel.Chunk, new LocalVoxelCoordinate((int)localCoord.X, y, (int)localCoord.Z)); v.RawSetType(VoxelLibrary.GetVoxelType(0)); v.QuickSetLiquid(LiquidType.None, 0); } if (averageHeight < h) { h = averageHeight; } bool isPosX = (dx == size && dz == 0); bool isPosZ = (dz == size & dx == 0); bool isNegX = (dx == -size && dz == 0); bool isNegZ = (dz == -size && dz == 0); bool isSide = (isPosX || isNegX || isPosZ || isNegZ); Vector3 offset = Vector3.Zero; if (isSide) { if (isPosX) { offset = Vector3.UnitX; } else if (isPosZ) { offset = Vector3.UnitZ; } else if (isNegX) { offset = -Vector3.UnitX; } else if (isNegZ) { offset = -Vector3.UnitZ; } } // Fill from the top height down to the bottom. for (int y = h - 1; y < averageHeight; y++) { var v = new VoxelHandle(baseVoxel.Chunk, new LocalVoxelCoordinate((int)localCoord.X, y, (int)localCoord.Z)); v.RawSetType(VoxelLibrary.GetVoxelType("Scaffold")); v.QuickSetLiquid(LiquidType.None, 0); if (y == averageHeight - 1) { if (dz >= 0) { balloonPortDesignations.Add(v); } else { treasuryDesignations.Add(v); } } if (isSide) { var ladderPos = new Vector3(worldPos.X, y, worldPos.Z) + offset + Vector3.One * 0.5f; var ladderVox = new VoxelHandle(chunkManager.ChunkData, GlobalVoxelCoordinate.FromVector3(ladderPos)); if (ladderVox.IsValid && ladderVox.IsEmpty) { var ladder = EntityFactory.CreateEntity <Ladder>("Ladder", ladderPos); Master.Faction.OwnedObjects.Add(ladder); ladder.Tags.Add("Moveable"); ladder.Tags.Add("Deconstructable"); } } } } } // Actually create the BuildRoom. BalloonPort toBuild = new BalloonPort(PlayerFaction, balloonPortDesignations, this); BuildRoomOrder buildDes = new BuildRoomOrder(toBuild, roomDes.Faction, this); buildDes.Build(true); roomDes.DesignatedRooms.Add(toBuild); // Also add a treasury Treasury treasury = new Treasury(PlayerFaction, treasuryDesignations, this); treasury.OnBuilt(); roomDes.DesignatedRooms.Add(treasury); return(toBuild); }
public IEnumerable<Status> IsRoomBuildOrder(BuildRoomOrder buildRooom) { yield return Creature.Faction.RoomBuilder.BuildDesignations.Contains(buildRooom) ? Status.Success : Status.Fail; }
public IEnumerable <Status> IsRoomBuildOrder(BuildRoomOrder buildRooom) { yield return(Creature.Faction.RoomBuilder.BuildDesignations.Contains(buildRooom) ? Status.Success : Status.Fail); }
public CreateRoomAct(CreatureAI agent, BuildRoomOrder buildRoom) : base(agent) { Name = "Build room."; BuildRoom = buildRoom; }
public IEnumerable<Status> SetTargetVoxelFromRoom(BuildRoomOrder buildRoom, string target) { if (buildRoom.VoxelOrders.Count == 0) { yield return Status.Fail; } else { Voxel closestVoxel = null; float closestDist = float.MaxValue; foreach (BuildVoxelOrder voxDes in buildRoom.VoxelOrders) { float dist = (voxDes.Voxel.Position - Agent.Position).LengthSquared(); if (dist < closestDist) { closestDist = dist; closestVoxel = voxDes.Voxel; } } Agent.Blackboard.SetData(target, closestVoxel); yield return Status.Success; } }
public Act SetTargetVoxelFromRoomAct(BuildRoomOrder buildRoom, string target) { return(new Wrap(() => SetTargetVoxelFromRoom(buildRoom, target))); }
public bool IsRoomBuildOrder(BuildRoomOrder buildRooom) { return(Creature.Faction.RoomBuilder.BuildDesignations.Contains(buildRooom)); }
private bool IsRoomBuildOrder(Faction faction, BuildRoomOrder buildRooom) { return(faction.RoomBuilder.BuildDesignations.Contains(buildRooom)); }