From 12509e6225e3945b5ea11b043c6fa6cade9e1717 Mon Sep 17 00:00:00 2001 From: EggleEgg <125359838+EggleEgg@users.noreply.github.com> Date: Thu, 2 Jul 2026 16:08:45 +0200 Subject: [PATCH] Make all research prioritize resources outside of the currently active sector (#12153) * Make all research prioritize resources outside of the currently active sector * YOU DONT EVEN NEED THIS STOP IMPORTING RANDOM CLASSES * hopefully I m not stupid enough to mess this up * STOP IMPORTING * did I screw up somewhere? who knows --- .../mindustry/ui/dialogs/ResearchDialog.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/core/src/mindustry/ui/dialogs/ResearchDialog.java b/core/src/mindustry/ui/dialogs/ResearchDialog.java index d3ffe9546d..46bc62f21b 100644 --- a/core/src/mindustry/ui/dialogs/ResearchDialog.java +++ b/core/src/mindustry/ui/dialogs/ResearchDialog.java @@ -248,19 +248,24 @@ public class ResearchDialog extends BaseDialog{ public void add(Item item, int amount){ //only have custom removal logic for when the sequence gets items taken out of it (e.g. research) if(amount < 0){ + Sector curSector = state.isCampaign() ? state.rules.sector : null; //remove items from each sector's storage, one by one //negate amount since it's being *removed* - this makes it positive amount = -amount; - //% that gets removed from each sector - double percentage = (double)amount / get(item); + //% that gets removed from each sector except the current one + double percentage = (double)amount / Math.max(get(item) - (curSector != null && cache.get(curSector) != null ? cache.get(curSector).get(item) : 0), 1); int[] counter = {amount}; + cache.each((sector, seq) -> { - if(counter[0] == 0) return; + if(counter[0] == 0 || sector == curSector) return; + + int available = seq.get(item); + if(available <= 0) return; //amount that will be removed - int toRemove = Math.min((int)Math.ceil(percentage * seq.get(item)), counter[0]); + int toRemove = Math.min(counter[0], Math.min((int)Math.ceil(percentage * available), available)); //actually remove it from the sector sector.removeItem(item, toRemove); @@ -269,6 +274,19 @@ public class ResearchDialog extends BaseDialog{ counter[0] -= toRemove; }); + //only consume from the active sector last + if(counter[0] > 0 && curSector != null){ + var seq = cache.get(curSector); + if(seq != null){ + int toRemove = Math.min(seq.get(item), counter[0]); + + curSector.removeItem(item, toRemove); + seq.remove(item, toRemove); + + counter[0] -= toRemove; + } + } + //negate again to display correct number amount = -amount; }