private TaskState CraftItem(Dwarf d, float dt, double dtd) { if (State == TaskState.NotActive) // DEADEDIT: Not sure about this || ... fixes a bug where line 50 will crash, because GetCraftSlot() is null.. but that should not happen (i think) { if ( d.GetActionbuilding().GetCraftSlot() != null && // If an item is being crafted d.GetActionbuilding().GetCraftSlot().ElementType != d.GetActionMapElementType() // and the item is different than the item the dwarf wants to craft ) 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() // DEADEDIT TODO: Mabey this should be == instead of != ) { DwarfConsole.WriteLine("Continues crafting, after it was aborted", ConsoleColor.Green); // Do thothing } else { // Creates a new item, that needs to be crafted // TODO: Mabey this should first be created when the building has enough materials to make it? WorldObject newWorldObject = (WorldObject)WorldObject.CreateWorldObject(d.GetActionMapElementType(), d.GetActionLevel()); d.GetActionbuilding().SetCraftSlot(newWorldObject); } } // DEADEDIT: Removed because of copy paste //if (DoesBuildingHaveNecessaryMaterialsForCrafting(d.GetActionbuilding(), d.GetActionbuilding().GetCraftSlot()) == false) //{ // d.GetActionbuilding().ReleaseDwarfFromCrafting(); // return TaskState.Fail; //} // Increases cooking stats if (d.GetActionMapElementType() == MapElementType.Meal) { d.DidSomeCooking(dt); } else { d.DidSomeCrafting(dt); } // Craft on the item d.GetActionbuilding().CraftOnItemInCraftSlot(CraftRules.CraftOnItem(d.GetActionbuilding().BuildingType, d), dt, dtd); // Check if the item is 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; }
private TaskState FindDepot(Dwarf d, float dt, double dtd) { if (d.GetActionMapElementType() == MapElementType.FoodSpecial) { } 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, double dtd) { 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, double dtd) { WorldObject m = d.GetActionbuilding().WithdrawWorldObject(d.GetActionMapElementType(), d.GetActionLevel()); if (m == null) return TaskState.Fail; if (m.RegisteredForConsumption == true) { //throw new Exception(""); } if (m.ElementType == MapElementType.Plank) DwarfDebugInfo.PlanksPickedUp++; d.CarryWorldObject(m); d.SetActionBuilding(d.GetPrevActionBuilding()); return TaskState.Success; }
private TaskState FindPath(Dwarf d, float dt, double dtd) { if (d.GetActionMapElementType() == MapElementType.Meal) { } 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; Building b = d.AssignedWorkBuilding; 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 { DwarfConsole.WriteLine("DWARF TRIED TO TAKE CRAFTING BUILD, BUT WAS ALREADY IN USE. THIS SHOULD HAPPEN RARELY", ConsoleColor.DarkRed); //Debugger.Break(); return TaskState.Fail; } // 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; }