diff --git a/exp_scenario/module/commands/waterfill.lua b/exp_scenario/module/commands/waterfill.lua index 4ef722bd..bb6beb17 100644 --- a/exp_scenario/module/commands/waterfill.lua +++ b/exp_scenario/module/commands/waterfill.lua @@ -9,7 +9,7 @@ local SelectionName = "ExpCommand_Waterfill" local planet = { ["nauvis"] = "water-mud", - ["gleba"] = "water-mud", + ["gleba"] = "wetland-blue-slime", ["vulcanus"] = "lava", ["fulgora"] = "oil-ocean-shallow", ["aquilo"] = "ammoniacal-ocean" @@ -59,29 +59,29 @@ Selection.on_selection(SelectionName, function(event) local item_count_craft = math.min(math.floor(player.get_item_count("explosives") / 10), player.get_item_count("barrel"), player.get_item_count("grenade")) local item_count_total = item_count_cliff + item_count_craft - if item_count_total < area_size then - player.print({ "exp-commands_waterfill.too-few-explosives", area_size, item_count_total }, Commands.print_settings.error) - return - end - local tile_count = 0 - local remaining_tiles = 0 + local failed_tiles = 0 local tiles_to_make = {} - local chest = surface.find_entities_filtered{ area = area, name = "steel-chest", force = player.force } + local chests = surface.find_entities_filtered{ area = area, name = "steel-chest", force = player.force } local tile_to_apply = (surface.planet and planet[surface.planet]) or "water-mud" - if #chest > 0 then - for _, v in pairs(chest) do - if v.get_inventory(defines.inventory.chest).is_empty() and tile_count < item_count_total then - tile_count = tile_count + 1 - tiles_to_make[tile_count] = { name = tile_to_apply, position = { v.position.x, v.position.y } } - v.destroy() - elseif v.get_inventory(defines.inventory.chest).is_empty() then - remaining_tiles = remaining_tiles + 1 + if #chests > 0 then + for _, chest in pairs(chests) do + tile_count = tile_count + 1 + if chest.get_inventory(defines.inventory.chest).is_empty() and tile_count <= item_count_total then + tiles_to_make[tile_count] = { name = tile_to_apply, position = { chest.position.x, chest.position.y } } + chest.destroy() + else + failed_tiles = failed_tiles + 1 end end else + if item_count_total < area_size then + player.print({ "exp-commands_waterfill.too-few-explosives", area_size, item_count_total }, Commands.print_settings.error) + return + end + for x = area.left_top.x, area.right_bottom.x do for y = area.left_top.y, area.right_bottom.y do tile_count = tile_count + 1 @@ -89,19 +89,20 @@ Selection.on_selection(SelectionName, function(event) end end - remaining_tiles = surface.count_tiles_filtered{ area = area, name = tile_to_apply } + failed_tiles = surface.count_tiles_filtered{ area = area, name = tile_to_apply } end surface.set_tiles(tiles_to_make, true, "abort_on_collision", true, false, player, 0) - local t_diff = tile_count - remaining_tiles + local tiles_made = tile_count - failed_tiles + assert(tiles_made >= 0) - if item_count_cliff >= t_diff and t_diff > 0 then - player.remove_item{ name = "cliff-explosives", count = t_diff } + if item_count_cliff >= tiles_made then + player.remove_item{ name = "cliff-explosives", count = tiles_made } else if item_count_cliff > 0 then player.remove_item{ name = "cliff-explosives", count = item_count_cliff } end - local item_count_needed = t_diff - item_count_cliff + local item_count_needed = tiles_made - item_count_cliff if item_count_needed > 0 then player.remove_item{ name = "explosives", count = 10 * item_count_needed } player.remove_item{ name = "barrel", count = item_count_needed } @@ -109,8 +110,8 @@ Selection.on_selection(SelectionName, function(event) end end - if remaining_tiles > 0 then - player.print({ "exp-commands_waterfill.part-complete", tile_count, remaining_tiles }, Commands.print_settings.default) + if failed_tiles > 0 then + player.print({ "exp-commands_waterfill.part-complete", tile_count, failed_tiles }, Commands.print_settings.default) else player.print({ "exp-commands_waterfill.complete", tile_count }, Commands.print_settings.default) end