From 692718d4eaeeff91a9dfb8b09af9e5e53f495e93 Mon Sep 17 00:00:00 2001 From: buthed010203 Date: Tue, 28 Dec 2021 23:22:01 -0500 Subject: [PATCH] Fix strange behavior of MinerAI (#6454) * Fix strange behavior of MinerAI See: https://discord.com/channels/391020510269669376/396416151032299521/925110542216073216 > Anuke, is the current behavior of miner ai where it wont mine anything if the item that the core has the fewest of has all of its ores covered? The only place the hasOre code is used is miner ai so i assume thats a bug? * Update BlockIndexer.java --- core/src/mindustry/ai/BlockIndexer.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/mindustry/ai/BlockIndexer.java b/core/src/mindustry/ai/BlockIndexer.java index b5a0ef202c..535462e200 100644 --- a/core/src/mindustry/ai/BlockIndexer.java +++ b/core/src/mindustry/ai/BlockIndexer.java @@ -33,7 +33,7 @@ public class BlockIndexer{ /** Stores all damaged tile entities by team. */ private Seq[] damagedTiles = new Seq[Team.all.length]; /** All ores available on this map. */ - private ObjectSet allOres = new ObjectSet<>(); + private ObjectIntMap allOres = new ObjectIntMap<>(); /** Stores teams that are present here as tiles. */ private Seq activeTeams = new Seq<>(Team.class); /** Maps teams to a map of flagged tiles by flag. */ @@ -78,8 +78,6 @@ public class BlockIndexer{ var drop = tile.drop(); if(drop != null){ - allOres.add(drop); - int qx = (tile.x / quadrantSize); int qy = (tile.y / quadrantSize); @@ -92,6 +90,7 @@ public class BlockIndexer{ ores[drop.id][qx][qy] = new IntSeq(false, 16); } ores[drop.id][qx][qy].add(tile.pos()); + allOres.increment(drop); } } } @@ -150,9 +149,11 @@ public class BlockIndexer{ //when the drop can be mined, record the ore position if(tile.block() == Blocks.air && !seq.contains(pos)){ seq.add(pos); + allOres.increment(drop); }else{ //otherwise, it likely became blocked, remove it (even if it wasn't there) seq.removeValue(pos); + allOres.increment(drop, -1); } } @@ -177,7 +178,7 @@ public class BlockIndexer{ /** @return whether this item is present on this map. */ public boolean hasOre(Item item){ - return allOres.contains(item); + return allOres.get(item) > 0; } /** Returns all damaged tiles by team. */