From 64b9d0db40dfb6f52c2d454a930c836fb8929c16 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Thu, 17 Apr 2025 04:29:35 +0900 Subject: [PATCH 1/4] Add asserts to auto research queue (#385) * Update research.lua * Use asserts rather than ignore errors --------- Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> --- exp_scenario/module/commands/research.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exp_scenario/module/commands/research.lua b/exp_scenario/module/commands/research.lua index 420a8741..63939033 100644 --- a/exp_scenario/module/commands/research.lua +++ b/exp_scenario/module/commands/research.lua @@ -71,7 +71,9 @@ local function on_research_finished(event) if not research.res_queue_enable then return end local force = event.research.force - if force.technologies[config.bonus_inventory.res[config.mod_set].name].level > config.bonus_inventory.res[config.mod_set].level then + local research = assert(config.bonus_inventory.res[config.mod_set], "Unknown mod set: " .. tostring(config.mod_set)) + local technology = assert(force.technologies[research.name], "Unknown technology: " .. tostring(research.name)) + if technology.level > research.level then module.res_queue(force, event.by_script) end end From 79ab6db28ac8b42985ff831f1e3cde3394b928b1 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Thu, 17 Apr 2025 04:59:12 +0900 Subject: [PATCH 2/4] Add character check to selection control (#386) --- exp_legacy/module/modules/control/selection.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exp_legacy/module/modules/control/selection.lua b/exp_legacy/module/modules/control/selection.lua index cb08e3a6..461f2cd4 100644 --- a/exp_legacy/module/modules/control/selection.lua +++ b/exp_legacy/module/modules/control/selection.lua @@ -76,7 +76,9 @@ function Selection.start(player, selection_name, single_use, ...) --player.cursor_stack_temporary = true -- Make a slot to place the selection tool even if inventory is full - player.character_inventory_slots_bonus = player.character_inventory_slots_bonus + 1 + if player.character then + player.character_inventory_slots_bonus = player.character_inventory_slots_bonus + 1 + end local inventory = player.get_main_inventory() if inventory then player.hand_location = { inventory = inventory.index, slot = #inventory } From aee15341bd0b133dbe0a6c62f909cae491d28cde Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sun, 27 Apr 2025 07:34:35 +0900 Subject: [PATCH 3/4] Update GUI Research Tracker (#390) * Update research.lua * Update research.lua * Update research.lua * Format config and move pollution ageing * Update research.lua * Update research.lua * Update research.lua --------- Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> --- exp_legacy/module/config/research.lua | 40 +++++++++++++--------- exp_legacy/module/modules/gui/research.lua | 33 +++++++----------- exp_scenario/module/commands/research.lua | 4 +-- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/exp_legacy/module/config/research.lua b/exp_legacy/module/config/research.lua index 41a102f0..e9e53f63 100644 --- a/exp_legacy/module/config/research.lua +++ b/exp_legacy/module/config/research.lua @@ -7,21 +7,27 @@ return { queue_amount = 3, mod_set = "base", mod_set_lookup = { - "space-age" + "space-age", }, -- this enable 20 more inventory for each mining productivity level up to 4 bonus_inventory = { enabled = true, - res = { - -- Mining Productivity + log = { ["base"] = { ["name"] = "mining-productivity-4", - ["level"] = 4, + ["level"] = 4 }, ["space-age"] = { ["name"] = "mining-productivity-3", - ["level"] = 3, - } + ["level"] = 3 + }, + }, + res = { + -- Mining Productivity + ["mining-productivity"] = true, + ["mining-productivity-2"] = true, + ["mining-productivity-3"] = true, + ["mining-productivity-4"] = true, }, name = "character_inventory_slots_bonus", rate = 5, @@ -73,20 +79,20 @@ return { ["productivity-module-3"] = 300, ["speed-module-3"] = 300, ["rocket-silo"] = 300, - ["space-science-pack"] = 300 + ["space-science-pack"] = 300, }, ["space-age"] = { ["logistic-science-pack"] = 3600, ["military-science-pack"] = 3600, - ["chemical-science-pack"] = 4500, - ["utility-science-pack"] = 5400, - ["production-science-pack"] = 5400, - ["space-science-pack"] = 5400, - ["metallurgic-science-pack"] = 6300, - ["electromagnetic-science-pack"] = 6300, - ["agricultural-science-pack"] = 6300, - ["cryogenic-science-pack"] = 6300, - ["promethium-science-pack"] = 7200 + ["chemical-science-pack"] = 5400, + ["utility-science-pack"] = 7200, + ["production-science-pack"] = 7200, + ["space-science-pack"] = 7200, + ["metallurgic-science-pack"] = 10800, + ["electromagnetic-science-pack"] = 10800, + ["agricultural-science-pack"] = 10800, + ["cryogenic-science-pack"] = 10800, + ["promethium-science-pack"] = 14400, } }, inf_res = { @@ -157,7 +163,7 @@ return { ["rocket-part-productivity"] = 1, -- Follower Robot Count ["follower-robot-count-5"] = 5, - } + }, }, -- prevent research up to a certain level limit_res = { diff --git a/exp_legacy/module/modules/gui/research.lua b/exp_legacy/module/modules/gui/research.lua index 4a8bed31..f58d5c6f 100644 --- a/exp_legacy/module/modules/gui/research.lua +++ b/exp_legacy/module/modules/gui/research.lua @@ -85,32 +85,25 @@ end local function research_notification(event) if config.inf_res[config.mod_set][event.research.name] then - if event.research.name == config.bonus_inventory.res[config.mod_set].name then - if event.research.level == config.bonus_inventory.res[config.mod_set].level + 1 then - -- Add run result to log - research_add_log() - end - - if config.bonus_inventory.enabled then - event.research.force[config.bonus_inventory.name] = math.max((event.research.level - 1) * config.bonus_inventory.rate, config.bonus_inventory.limit) - end - - if config.pollution_ageing_by_research then - game.map_settings.pollution.ageing = math.min(10, event.research.level / 5) - end + if event.research.name == config.bonus_inventory.log[config.mod_set].name + and event.research.level == config.bonus_inventory.log[config.mod_set].level + 1 then + -- Add run result to log + research_add_log() end if not (event.by_script) then game.print{ "research.inf", research_time_format(game.tick), event.research.name, event.research.level - 1 } end - else - if not (event.by_script) then - game.print{ "research.msg", research_time_format(game.tick), event.research.name } - end + elseif not (event.by_script) then + game.print{ "research.msg", research_time_format(game.tick), event.research.name } + end - if config.bonus_inventory.enabled and (event.research.name == "mining-productivity-1" or event.research.name == "mining-productivity-2" or event.research.name == "mining-productivity-3") then - event.research.force[config.bonus_inventory.name] = event.research.level * config.bonus_inventory.rate - end + if config.bonus_inventory.enabled and config.bonus_inventory.res[event.research.name] then + event.research.force[config.bonus_inventory.name] = math.min((event.research.level - 1) * config.bonus_inventory.rate, config.bonus_inventory.limit) + end + + if config.pollution_ageing_by_research and config.bonus_inventory.res[event.research.name] then + game.map_settings.pollution.ageing = math.min(10, event.research.level / 5) end end diff --git a/exp_scenario/module/commands/research.lua b/exp_scenario/module/commands/research.lua index 63939033..40b36ee4 100644 --- a/exp_scenario/module/commands/research.lua +++ b/exp_scenario/module/commands/research.lua @@ -23,7 +23,7 @@ end) --- @param silent boolean True when no message should be printed function module.res_queue(force, silent) local res_q = force.research_queue - local res = force.technologies[config.bonus_inventory.res[config.mod_set].name] + local res = force.technologies[config.bonus_inventory.log[config.mod_set].name] if #res_q < config.queue_amount then for i = #res_q, config.queue_amount - 1 do @@ -71,7 +71,7 @@ local function on_research_finished(event) if not research.res_queue_enable then return end local force = event.research.force - local research = assert(config.bonus_inventory.res[config.mod_set], "Unknown mod set: " .. tostring(config.mod_set)) + local research = assert(config.bonus_inventory.log[config.mod_set], "Unknown mod set: " .. tostring(config.mod_set)) local technology = assert(force.technologies[research.name], "Unknown technology: " .. tostring(research.name)) if technology.level > research.level then module.res_queue(force, event.by_script) From c984907aec32f17d21b17996ce543d076f88306b Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sun, 27 Apr 2025 07:35:25 +0900 Subject: [PATCH 4/4] Dual Mode for Waterfill Command (#391) * Update waterfill.lua * Update waterfill.lua * Update waterfill.lua * Clean up water fill logic * Update waterfill.lua --------- Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> --- exp_scenario/module/commands/waterfill.lua | 63 +++++++++++++++------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/exp_scenario/module/commands/waterfill.lua b/exp_scenario/module/commands/waterfill.lua index a3c9d602..bb6beb17 100644 --- a/exp_scenario/module/commands/waterfill.lua +++ b/exp_scenario/module/commands/waterfill.lua @@ -7,6 +7,14 @@ local Commands = require("modules/exp_commands") local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection local SelectionName = "ExpCommand_Waterfill" +local planet = { + ["nauvis"] = "water-mud", + ["gleba"] = "wetland-blue-slime", + ["vulcanus"] = "lava", + ["fulgora"] = "oil-ocean-shallow", + ["aquilo"] = "ammoniacal-ocean" +} + --- Toggle player selection mode for artillery Commands.new("waterfill", { "exp-commands_waterfill.description" }) :register(function(player) @@ -33,12 +41,15 @@ Selection.on_selection(SelectionName, function(event) local player = game.players[event.player_index] local surface = event.surface + --[[ if surface.planet and surface.planet ~= game.planets.nauvis then player.print({ "exp-commands_waterfill.nauvis-only" }, Commands.print_settings.error) return end + ]] local area_size = (area.right_bottom.x - area.left_top.x) * (area.right_bottom.y - area.left_top.y) + if area_size > 1000 then player.print({ "exp-commands_waterfill.area-too-large", 1000, area_size }, Commands.print_settings.error) return @@ -48,34 +59,50 @@ 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 failed_tiles = 0 local tiles_to_make = {} - for x = area.left_top.x, area.right_bottom.x do - for y = area.left_top.y, area.right_bottom.y do + 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 #chests > 0 then + for _, chest in pairs(chests) do tile_count = tile_count + 1 - tiles_to_make[tile_count] = { - name = "water-mud", - position = { x, y }, - } + 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 + tiles_to_make[tile_count] = { name = tile_to_apply, position = { x, y } } + end + end + + 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 remaining_tiles = surface.count_tiles_filtered{ area = area, name = "water-mud" } - local t_diff = tile_count - remaining_tiles + local tiles_made = tile_count - failed_tiles + assert(tiles_made >= 0) - if item_count_cliff >= t_diff 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 } @@ -83,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