function Combineitems(building, tabl, food, bool) local rootItems if building then rootItems = dfhack.buildings.getStockpileContents(building) else rootItems = dfhack.items.getContainedItems(item) end if #rootItems == 0 and not f.args.all then qerror("Select a non-empty container") return else local foodCount = getItems(rootItems, food, 0, bool) local removedFood = { } --as:bool[] food.max=max if f.args.max then max = tonumber(f.args.max) if tonumber(f.args.max)== 0 then max = 500 end end for i=0,(foodCount-2) do local currentFood = food[i] --as:df.item_foodst local itemsNeeded = max - currentFood.stack_size if removedFood[currentFood.id] == nil and itemsNeeded > 0 then local j = i+1 local last = foodCount repeat local sourceFood = food[j] if bool>=10 and removedFood[sourceFood.id] == nil and FishitemsCompatible(currentFood, sourceFood) then local amountToMove = math.min(itemsNeeded, sourceFood.stack_size) itemsNeeded = itemsNeeded - amountToMove currentFood.stack_size = currentFood.stack_size + amountToMove if sourceFood.stack_size == amountToMove then removedFood[sourceFood.id] = true sourceFood.stack_size = 1 else sourceFood.stack_size = sourceFood.stack_size - amountToMove end -- else print("failed") elseif bool <10 and removedFood[sourceFood.id] == nil and itemsCompatible(currentFood, sourceFood) then local amountToMove = math.min(itemsNeeded, sourceFood.stack_size) itemsNeeded = itemsNeeded - amountToMove currentFood.stack_size = currentFood.stack_size + amountToMove if sourceFood.stack_size == amountToMove then removedFood[sourceFood.id] = true if bool>1 then sourceFood.stack_size = 1 end else sourceFood.stack_size = sourceFood.stack_size - amountToMove end -- else print("failed") end j = j + 1 until j == foodCount or itemsNeeded == 0 end end local removedCount = 0 for id,removed in pairs(removedFood) do if removed then removedCount = removedCount + 1 local removedFood = df.item.find(id) dfhack.items.remove(removedFood) end end if food.Tot == nil then food.Tot = 0 end if food.xTot == nil then food.xTot = 0 end food.Tot = food.Tot + foodCount food.xTot = food.xTot + removedCount end end if f.args.help then print(f.help) return end if not f.args.all then local building = stockpile or dfhack.gui.getSelectedBuilding(true) if building ~= nil and building:getType() ~= 29 then building = nil end if building ~= nil then if f.args.drinks or f.args.food then Combineitems(building, f, drinks, 1) print("found " .. drinks.Tot .. " drinks") print("merged " .. drinks.xTot .. " drinks") end if f.args.plants or f.args.food then Combineitems(building, f, plants, 2) print("found " .. plants.Tot .. " plants") print("merged " .. plants.xTot .. " plants") end if f.args.meat or f.args.food then Combineitems(building, f, meats, 3) print("found " .. meats.Tot .. " meat") print("merged " .. meats.xTot .. " meat") end if f.args.fat or f.args.food then Combineitems(building, f, fat, 4) print("found " .. fat.Tot .. " fat") print("merged " .. fat.xTot .. " fat") end if f.args.roasts or f.args.food then Combineitems(building, f, roasts, 5) print("found " .. roasts.Tot .. " prepared food") print("merged " .. roasts.xTot .. " prepared food") end if f.args.fish or f.args.food then Combineitems(building, f, fish, 10) print("found " .. fish.Tot .. " fish") print("merged " .. fish.xTot .. " fish") end else print('select a stockpile') end else if f.args.all then print('Combining all food...') for _, building in pairs(df.global.world.buildings.all) do if building:getType() == 29 and building ~= nil then if building ~= nil then if f.args.drinks or f.args.food then Combineitems(building, f, drinks, 1) end if f.args.plants or f.args.food then Combineitems(building, f, plants, 2) end if f.args.meat or f.args.food then Combineitems(building, f, meats, 3) end if f.args.fat or f.args.food then Combineitems(building, f, fat, 4) end if f.args.roasts or f.args.food then Combineitems(building, f, roasts, 5) end if f.args.fish or f.args.food then Combineitems(building, f, fish, 10) end else print('invalid') end end end if f.args.drinks or f.args.food then print("found " .. drinks.Tot .. " drinks") print("merged " .. drinks.xTot .. " drinks") end if f.args.plants or f.args.food then print("found " .. plants.Tot .. " plants") print("merged " .. plants.xTot .. " plants") end if f.args.meat or f.args.food then print("found " .. meats.Tot .. " meat") print("merged " .. meats.xTot .. " meat") end if f.args.fat or f.args.food then print("found " .. fat.Tot .. " fat or tallow") print("merged " .. fat.xTot .. " fat or tallow") end if f.args.roasts or f.args.food then print("found " .. roasts.Tot .. " prepared food") print("merged " .. roasts.xTot .. " prepared food") end if f.args.fish or f.args.food then print("found " .. fish.Tot .. " fish") print("merged " .. fish.xTot .. " fish") end end return end
没发完,脚本剩下部分: function Combineitems(building, tabl, food, bool) local rootItems if building then rootItems = dfhack.buildings.getStockpileContents(building) else rootItems = dfhack.items.getContainedItems(item) end if #rootItems == 0 and not f.args.all then qerror("Select a non-empty container") return else local foodCount = getItems(rootItems, food, 0, bool) local removedFood = { } --as:bool[] food.max=max if f.args.max then max = tonumber(f.args.max) if tonumber(f.args.max)== 0 then max = 500 end end for i=0,(foodCount-2) do local currentFood = food[i] --as:df.item_foodst local itemsNeeded = max - currentFood.stack_size if removedFood[currentFood.id] == nil and itemsNeeded > 0 then local j = i+1 local last = foodCount repeat local sourceFood = food[j] if bool>=10 and removedFood[sourceFood.id] == nil and FishitemsCompatible(currentFood, sourceFood) then local amountToMove = math.min(itemsNeeded, sourceFood.stack_size) itemsNeeded = itemsNeeded - amountToMove currentFood.stack_size = currentFood.stack_size + amountToMove if sourceFood.stack_size == amountToMove then removedFood[sourceFood.id] = true sourceFood.stack_size = 1 else sourceFood.stack_size = sourceFood.stack_size - amountToMove end -- else print("failed") elseif bool <10 and removedFood[sourceFood.id] == nil and itemsCompatible(currentFood, sourceFood) then local amountToMove = math.min(itemsNeeded, sourceFood.stack_size) itemsNeeded = itemsNeeded - amountToMove currentFood.stack_size = currentFood.stack_size + amountToMove if sourceFood.stack_size == amountToMove then removedFood[sourceFood.id] = true if bool>1 then sourceFood.stack_size = 1 end else sourceFood.stack_size = sourceFood.stack_size - amountToMove end -- else print("failed") end j = j + 1 until j == foodCount or itemsNeeded == 0 end end local removedCount = 0 for id,removed in pairs(removedFood) do if removed then removedCount = removedCount + 1 local removedFood = df.item.find(id) dfhack.items.remove(removedFood) end end if food.Tot == nil then food.Tot = 0 end if food.xTot == nil then food.xTot = 0 end food.Tot = food.Tot + foodCount food.xTot = food.xTot + removedCount end end if f.args.help then print(f.help) return end if not f.args.all then local building = stockpile or dfhack.gui.getSelectedBuilding(true) if building ~= nil and building:getType() ~= 29 then building = nil end if building ~= nil then if f.args.drinks or f.args.food then Combineitems(building, f, drinks, 1) print("found " .. drinks.Tot .. " drinks") print("merged " .. drinks.xTot .. " drinks") end if f.args.plants or f.args.food then Combineitems(building, f, plants, 2) print("found " .. plants.Tot .. " plants") print("merged " .. plants.xTot .. " plants") end if f.args.meat or f.args.food then Combineitems(building, f, meats, 3) print("found " .. meats.Tot .. " meat") print("merged " .. meats.xTot .. " meat") end if f.args.fat or f.args.food then Combineitems(building, f, fat, 4) print("found " .. fat.Tot .. " fat") print("merged " .. fat.xTot .. " fat") end if f.args.roasts or f.args.food then Combineitems(building, f, roasts, 5) print("found " .. roasts.Tot .. " prepared food") print("merged " .. roasts.xTot .. " prepared food") end if f.args.fish or f.args.food then Combineitems(building, f, fish, 10) print("found " .. fish.Tot .. " fish") print("merged " .. fish.xTot .. " fish") end else print('select a stockpile') end else if f.args.all then print('Combining all food...') for _, building in pairs(df.global.world.buildings.all) do if building:getType() == 29 and building ~= nil then if building ~= nil then if f.args.drinks or f.args.food then Combineitems(building, f, drinks, 1) end if f.args.plants or f.args.food then Combineitems(building, f, plants, 2) end if f.args.meat or f.args.food then Combineitems(building, f, meats, 3) end if f.args.fat or f.args.food then Combineitems(building, f, fat, 4) end if f.args.roasts or f.args.food then Combineitems(building, f, roasts, 5) end if f.args.fish or f.args.food then Combineitems(building, f, fish, 10) end else print('invalid') end end end if f.args.drinks or f.args.food then print("found " .. drinks.Tot .. " drinks") print("merged " .. drinks.xTot .. " drinks") end if f.args.plants or f.args.food then print("found " .. plants.Tot .. " plants") print("merged " .. plants.xTot .. " plants") end if f.args.meat or f.args.food then print("found " .. meats.Tot .. " meat") print("merged " .. meats.xTot .. " meat") end if f.args.fat or f.args.food then print("found " .. fat.Tot .. " fat or tallow") print("merged " .. fat.xTot .. " fat or tallow") end if f.args.roasts or f.args.food then print("found " .. roasts.Tot .. " prepared food") print("merged " .. roasts.xTot .. " prepared food") end if f.args.fish or f.args.food then print("found " .. fish.Tot .. " fish") print("merged " .. fish.xTot .. " fish") end end return end