From 336d59a9fd65eff4d94995e70c2d8089c8ea5c7c Mon Sep 17 00:00:00 2001 From: Enderdraak Date: Mon, 17 Oct 2022 19:48:33 +0200 Subject: [PATCH 1/2] Fix so hivemind popcap works This is a fix that makes sure that the hivemind popcap actually caps at the desired number. The fix can be used by other mods as well. Added info on how to use in readme.md --- locale/en/unit-control.cfg | 6 ++++++ readme.md | 5 +++++ script/unit_control.lua | 2 +- script/unit_deployment.lua | 8 +++++--- settings.lua | 9 +++++++++ 5 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 settings.lua diff --git a/locale/en/unit-control.cfg b/locale/en/unit-control.cfg index 2350e5a..eacea0b 100644 --- a/locale/en/unit-control.cfg +++ b/locale/en/unit-control.cfg @@ -20,3 +20,9 @@ queue-hold-position=Queue hold position suicide-all=Suicide all select-all-units=Select all units (within 200 tiles of click position) select-all-deployers=Select all deployers + +[mod-setting-name] +unit-control-spawn-units=Spawn units from deployers + +[mod-setting-description] +unit-control-spawn-units=Should Unit Control spawn units in the deployers. \ No newline at end of file diff --git a/readme.md b/readme.md index 62df756..9f93c8c 100644 --- a/readme.md +++ b/readme.md @@ -3,3 +3,8 @@ -------------------------------------- Allows controlling units with special 'Unit selection tool' and other tools available through the GUI. + +-------------------------------------- + +If you do not want unit control to spawn any units from all deployers, use this line in settings-updates: +data.raw["bool-setting"]["unit-control-spawn-units"].forced_value = false diff --git a/script/unit_control.lua b/script/unit_control.lua index 7fffb47..e048786 100644 --- a/script/unit_control.lua +++ b/script/unit_control.lua @@ -1943,7 +1943,7 @@ local on_entity_spawned = function(event) entity = unit, command_queue = util.copy(queue), idle = false, - is_unit = entity.type == "unit" + is_unit = unit.type == "unit" } script_data.units[unit.unit_number] = unit_data diff --git a/script/unit_deployment.lua b/script/unit_deployment.lua index 61ea933..b0465e5 100644 --- a/script/unit_deployment.lua +++ b/script/unit_deployment.lua @@ -12,9 +12,11 @@ local get_deployer_map = function() return deployer_map end deployer_map = {} - for name, prototype in pairs (game.item_prototypes["select-units"].entity_filters) do - if prototype.crafting_speed then - deployer_map[name] = true + if settings.startup["unit-control-spawn-units"].value then + for name, prototype in pairs (game.item_prototypes["select-units"].entity_filters) do + if prototype.crafting_speed then + deployer_map[name] = true + end end end return deployer_map diff --git a/settings.lua b/settings.lua new file mode 100644 index 0000000..664fcbb --- /dev/null +++ b/settings.lua @@ -0,0 +1,9 @@ +data:extend({ + { + type = "bool-setting", + name = "unit-control-spawn-units", + setting_type = "startup", + default_value = true, + hidden = true + } +}) \ No newline at end of file From e7cbc0e9c0cd3dafe364de69323cf23788b69750 Mon Sep 17 00:00:00 2001 From: Enderdraak Date: Wed, 8 Feb 2023 00:34:28 +0100 Subject: [PATCH 2/2] Retry on the fix Trying to make a fix with a remote call --- locale/en/unit-control.cfg | 6 ------ readme.md | 6 ++++-- script/unit_deployment.lua | 13 +++++++++---- settings.lua | 9 --------- 4 files changed, 13 insertions(+), 21 deletions(-) delete mode 100644 settings.lua diff --git a/locale/en/unit-control.cfg b/locale/en/unit-control.cfg index eacea0b..2350e5a 100644 --- a/locale/en/unit-control.cfg +++ b/locale/en/unit-control.cfg @@ -20,9 +20,3 @@ queue-hold-position=Queue hold position suicide-all=Suicide all select-all-units=Select all units (within 200 tiles of click position) select-all-deployers=Select all deployers - -[mod-setting-name] -unit-control-spawn-units=Spawn units from deployers - -[mod-setting-description] -unit-control-spawn-units=Should Unit Control spawn units in the deployers. \ No newline at end of file diff --git a/readme.md b/readme.md index 9f93c8c..545532a 100644 --- a/readme.md +++ b/readme.md @@ -6,5 +6,7 @@ Allows controlling units with special 'Unit selection tool' and other tools avai -------------------------------------- -If you do not want unit control to spawn any units from all deployers, use this line in settings-updates: -data.raw["bool-setting"]["unit-control-spawn-units"].forced_value = false +If you do not want unit control to spawn any units from your deployers, add this remote interface: +remote.add_interface("unit-control-no-spawning",{["mod-name"] = function.returns_list_of_deployers_to_be_ignored}) +You will need to input your own mod name so no conflicts will happen. +And for the funtion you need a funtion that returns an array of all the deployers you do not want unit control to spawn from. \ No newline at end of file diff --git a/script/unit_deployment.lua b/script/unit_deployment.lua index b0465e5..93ee90f 100644 --- a/script/unit_deployment.lua +++ b/script/unit_deployment.lua @@ -12,10 +12,15 @@ local get_deployer_map = function() return deployer_map end deployer_map = {} - if settings.startup["unit-control-spawn-units"].value then - for name, prototype in pairs (game.item_prototypes["select-units"].entity_filters) do - if prototype.crafting_speed then - deployer_map[name] = true + for name, prototype in pairs (game.item_prototypes["select-units"].entity_filters) do + if prototype.crafting_speed then + deployer_map[name] = true + end + end + if remote.interfaces["unit-control-no-spawning"] then + for name, _ in pairs(remote.interfaces["unit-control-no-spawning"]) do + for index, name in pairs(remote.call("unit-control-no-spawning", name)) do + deployer_map[name] = nil end end end diff --git a/settings.lua b/settings.lua deleted file mode 100644 index 664fcbb..0000000 --- a/settings.lua +++ /dev/null @@ -1,9 +0,0 @@ -data:extend({ - { - type = "bool-setting", - name = "unit-control-spawn-units", - setting_type = "startup", - default_value = true, - hidden = true - } -}) \ No newline at end of file