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; }