private TaskState FindPath(Dwarf d, float dt) { if (State == TaskState.NotActive) { List<Building> craftingBuildings = WorldMap.Instance.GetCraftingBuildings(d.GetActionMapElementType()); if (d.GetActionMapElementType() == MapElementType.Arrow) { } foreach (Building b in craftingBuildings) { if (_cot.AssignedWorkshop != null && b != _cot.AssignedWorkshop) continue; if (b.IsCraftingItem() == false || //b.IsTakenByDwarf(d, d.GetActionMapElementType()) == true || (b.IsCraftingItem() == true && b.HasADwarfWorkingOnItem() == false && b.TypeThatIsBeingCrafted() == d.GetActionMapElementType())) { AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), b.GetActivationPoint(), b); _numerOfPaths++; } else continue; } // If no crafting building that can be used if (_numerOfPaths == 0) { return TaskState.Fail; } } _paths.AddRange(AsyncPathfinding.GetFinishedPathsWithData(d)); if (_numerOfPaths != _paths.Count) return TaskState.Running; PathfindingResult shortestPath = Path.ShortestPath(_paths); Building bb = (Building)shortestPath.Data; // If the crafting building was taken by another dwarf while we where calculating paths. if (bb.HasADwarfWorkingOnItem() == true) return TaskState.SmallFail; d.SetActionBuilding(bb); d.SetMovePath(shortestPath.Path); d.GetActionbuilding().TakeForCrafting(d, d.GetActionMapElementType()); _cot.AssignedWorkshop = d.GetActionbuilding(); return TaskState.Success; }
private TaskState FindDepot(Dwarf d, float dt) { if (State == TaskState.NotActive) { List<BuildingRequest> depoesCandidates = new List<BuildingRequest>(); List<Building> depos = WorldMap.Instance.GetDepos(d.GetActionMapElementType(), d.GetActionLevel()); foreach (Building b in depos) { depoesCandidates.Add(new BuildingRequest() { Building = b, TypeToGet = d.GetActionMapElementType(), Level = d.GetActionLevel() }); } // If no depot exist that has the required materials, the behavier fails if (depoesCandidates.Count == 0) { if (_buildBuilding.HasRequestedNeededResourcesForCrafting== true) return TaskState.Fail; if (CraftRules.IsMapElementTypeCraftable(d.GetActionMapElementType()) == true) { TaskManager.AddTask(new CraftingOfResourceTask(d.GetActionMapElementType(), d.GetActionLevel())); _buildBuilding.HasRequestedNeededResourcesForCrafting = true; } return TaskState.Fail; } foreach (BuildingRequest b in depoesCandidates) { AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), b.Building.GetActivationPoint(), b); _numerOfPaths++; } } _paths.AddRange(AsyncPathfinding.GetFinishedPathsWithData(d)); if (_paths.Count > _numerOfPaths) { } if (_numerOfPaths != _paths.Count) return TaskState.Running; PathfindingResult shortestPath = Path.ShortestPath(_paths); BuildingRequest br = (BuildingRequest)shortestPath.Data; d.SetActionBuilding(br.Building); d.SetActionMapElementType(br.TypeToGet); d.SetActionLevel(br.Level); d.SetMovePath(shortestPath.Path); return TaskState.Success; }
private TaskState Check(Dwarf d, float dt) { if (DoesBuildingHaveNecessaryMaterialsForCrafting(d.GetActionbuilding(), WorldObject.CreateWorldObject(d.GetActionMapElementType(), d.GetActionLevel())) == false) { d.GetActionbuilding().ReleaseForCrafting(); return TaskState.Fail; } return TaskState.Success; }
private TaskState Pickup(Dwarf d, float dt) { WorldObject m = d.GetActionbuilding().WithdrawWorldObject(d.GetActionMapElementType(), d.GetActionLevel()); if (m == null) return TaskState.Fail; d.CarryWorldObject(m); d.SetActionBuilding(d.GetPrevActionBuilding()); return TaskState.Success; }
private TaskState CraftItem(Dwarf d, float dt) { if (State == TaskState.NotActive) { if (d.GetActionbuilding().GetCraftSlot() != null && d.GetActionbuilding().GetCraftSlot().ElementType != d.GetActionMapElementType()) throw new Exception("Can't craft, workshop allready in use"); // If an item is already being crafted of the same kind if (d.GetActionbuilding().GetCraftSlot() != null && d.GetActionbuilding().GetCraftSlot().ElementType != d.GetActionMapElementType()) { DwarfConsole.WriteLine("Continues crafting, after it was aborted", ConsoleColor.Green); // Do thothing } else d.GetActionbuilding().SetCraftSlot((WorldObject)WorldObject.CreateWorldObject(d.GetActionMapElementType(), d.GetActionLevel())); } if (DoesBuildingHaveNecessaryMaterialsForCrafting(d.GetActionbuilding(), d.GetActionbuilding().GetCraftSlot()) == false) { d.GetActionbuilding().ReleaseDwarfFromCrafting(); return TaskState.Fail; } d.GetActionbuilding().CraftOnItemInCraftSlot(CraftRules.CraftOnItem(d.GetActionbuilding().BuildingType, d), dt); // The item was crafted :) if (d.GetActionbuilding().GetCraftSlot().IsCrafted() == true) { RemoveUsedResources(d.GetActionbuilding(), d.GetActionbuilding().GetCraftSlot()); DwarfConsole.WriteLine("Crafted: " + d.GetActionbuilding().GetCraftSlot().ElementType + " " + d.GetActionbuilding().GetCraftSlot().Level, ConsoleColor.Yellow); //d.CarryWorldObject(d.GetActionbuilding().TakeCraftSlot()); d.GetActionbuilding().ReleaseForCrafting(); return TaskState.Success; } else return TaskState.Running; }