From 57ad1d5366a2acd9dc300a4c68b31b664025f407 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 9 Dec 2020 20:19:54 -0500 Subject: [PATCH] Fixed #3899 --- core/src/mindustry/content/Items.java | 1 + core/src/mindustry/core/Control.java | 2 +- .../maps/planet/SerpuloPlanetGenerator.java | 11 ++++++----- core/src/mindustry/type/Item.java | 2 ++ .../world/blocks/production/Drill.java | 2 +- .../world/blocks/storage/Unloader.java | 19 ++++++++++++++----- .../mindustry/world/modules/ItemModule.java | 16 ++++------------ gradle.properties | 2 +- 8 files changed, 30 insertions(+), 25 deletions(-) diff --git a/core/src/mindustry/content/Items.java b/core/src/mindustry/content/Items.java index 2c2e5eb60b..65c464a249 100644 --- a/core/src/mindustry/content/Items.java +++ b/core/src/mindustry/content/Items.java @@ -32,6 +32,7 @@ public class Items implements ContentList{ sand = new Item("sand", Color.valueOf("f7cba4")){{ alwaysUnlocked = true; + lowPriority = true; }}; coal = new Item("coal", Color.valueOf("272727")){{ diff --git a/core/src/mindustry/core/Control.java b/core/src/mindustry/core/Control.java index 906acdd4b5..00d4096e78 100644 --- a/core/src/mindustry/core/Control.java +++ b/core/src/mindustry/core/Control.java @@ -341,7 +341,7 @@ public class Control implements ApplicationListener, Loadable{ state.rules.waves = true; //reset win wave?? - state.rules.winWave = state.rules.attackMode ? -1 : sector.preset != null && sector.preset.captureWave > 0 ? sector.preset.captureWave : state.rules.winWave > state.wave ? state.rules.winWave : 40; + state.rules.winWave = state.rules.attackMode ? -1 : sector.preset != null && sector.preset.captureWave > 0 ? sector.preset.captureWave : state.rules.winWave > state.wave ? state.rules.winWave : 30; //if there's still an enemy base left, fix it if(state.rules.attackMode){ diff --git a/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java b/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java index b19e3229f0..356640f89a 100644 --- a/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java @@ -340,11 +340,12 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{ } }else if(floor != Blocks.basalt && floor != Blocks.ice && floor.asFloor().hasSurface()){ float noise = noise(x + 782, y, 5, 0.75f, 260f, 1f); - if(noise > 0.72f){ - floor = noise > 0.78f ? Blocks.taintedWater : (floor == Blocks.sand ? Blocks.sandWater : Blocks.darksandTaintedWater); - ore = Blocks.air; - }else if(noise > 0.67f){ - floor = (floor == Blocks.sand ? floor : Blocks.darksand); + if(noise > 0.67f && !enemies.contains(e -> Mathf.within(x, y, e.x, e.y, 8))){ + if(noise > 0.72f){ + floor = noise > 0.78f ? Blocks.taintedWater : (floor == Blocks.sand ? Blocks.sandWater : Blocks.darksandTaintedWater); + }else{ + floor = (floor == Blocks.sand ? floor : Blocks.darksand); + } ore = Blocks.air; } } diff --git a/core/src/mindustry/type/Item.java b/core/src/mindustry/type/Item.java index f52323d655..18cbdff886 100644 --- a/core/src/mindustry/type/Item.java +++ b/core/src/mindustry/type/Item.java @@ -24,6 +24,8 @@ public class Item extends UnlockableContent{ * 1 cost = 1 tick added to build time */ public float cost = 1f; + /** if true, this item is of lowest priority to drills. */ + public boolean lowPriority; public Item(String name, Color color){ super(name); diff --git a/core/src/mindustry/world/blocks/production/Drill.java b/core/src/mindustry/world/blocks/production/Drill.java index d2ffceb033..a124d9ceed 100644 --- a/core/src/mindustry/world/blocks/production/Drill.java +++ b/core/src/mindustry/world/blocks/production/Drill.java @@ -168,7 +168,7 @@ public class Drill extends Block{ } itemArray.sort((item1, item2) -> { - int type = Boolean.compare(item1 != Items.sand, item2 != Items.sand); + int type = Boolean.compare(!item1.lowPriority, !item2.lowPriority); if(type != 0) return type; int amounts = Integer.compare(oreCount.get(item1, 0), oreCount.get(item2, 0)); if(amounts != 0) return amounts; diff --git a/core/src/mindustry/world/blocks/storage/Unloader.java b/core/src/mindustry/world/blocks/storage/Unloader.java index 267d9925d7..d20f1c3620 100644 --- a/core/src/mindustry/world/blocks/storage/Unloader.java +++ b/core/src/mindustry/world/blocks/storage/Unloader.java @@ -27,6 +27,7 @@ public class Unloader extends Block{ saveConfig = true; itemCapacity = 0; noUpdateDisabled = true; + unloadable = false; config(Item.class, (UnloaderBuild tile, Item item) -> tile.sortItem = item); configClear((UnloaderBuild tile) -> tile.sortItem = null); @@ -47,10 +48,17 @@ public class Unloader extends Block{ public Item sortItem = null; public Building dumpingTo; public int offset = 0; + public int[] rotations; @Override public void updateTile(){ if(timer(timerUnload, speed / timeScale())){ + if(rotations == null || rotations.length != proximity.size){ + rotations = new int[proximity.size]; + } + + Log.info("unloader @", id); + for(int i = 0; i < proximity.size; i++){ int pos = (offset + i) % proximity.size; var other = proximity.get(pos); @@ -61,18 +69,19 @@ public class Unloader extends Block{ dumpingTo = other; //get item to be taken - Item item = sortItem == null ? other.items.beginTake() : sortItem; + Item item = sortItem == null ? other.items.takeIndex(rotations[pos]) : sortItem; //remove item if it's dumped correctly if(put(item)){ + other.items.remove(item, 1); + if(sortItem == null){ - other.items.endTake(item); - }else{ - other.items.remove(item, 1); + rotations[pos] = item.id + 1; } + other.itemTaken(item); }else if(sortItem == null){ - other.items.failTake(); + rotations[pos] = other.items.nextIndex(rotations[pos]); } } } diff --git a/core/src/mindustry/world/modules/ItemModule.java b/core/src/mindustry/world/modules/ItemModule.java index 0e4a3f96a1..835ae45fb4 100644 --- a/core/src/mindustry/world/modules/ItemModule.java +++ b/core/src/mindustry/world/modules/ItemModule.java @@ -206,7 +206,7 @@ public class ItemModule extends BlockModule{ /** Begins a speculative take operation. This returns the item that would be returned by #take(), but does not change state. */ @Nullable - public Item beginTake(){ + public Item takeIndex(int takeRotation){ for(int i = 0; i < items.length; i++){ int index = (i + takeRotation); if(index >= items.length) index -= items.length; @@ -217,23 +217,15 @@ public class ItemModule extends BlockModule{ return null; } - /** Finishes a take operation. Updates take state, removes the item. */ - public void endTake(Item item){ - items[item.id] --; - total --; - takeRotation = item.id + 1; - } - - public void failTake(){ + public int nextIndex(int takeRotation){ for(int i = 1; i < items.length; i++){ int index = (i + takeRotation); if(index >= items.length) index -= items.length; if(items[index] > 0){ - takeRotation += i; - takeRotation %= items.length; - return; + return (takeRotation + i) % items.length; } } + return takeRotation; } public int get(int id){ diff --git a/gradle.properties b/gradle.properties index 10c9faa4ee..9e82b5721f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=08d81cd26f74ea2e490c5ddc6e5a509f30f48368 +archash=f0400adb14a72ca567ea3b48ea8c3a22c55e1b9e