From 2b9d618bd270324a54112122d782623b2b348c44 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 7 May 2020 21:37:41 -0400 Subject: [PATCH] Implemented various suggestions - Pathfinding weighs walls more - C disables all HUD - Unloader doesn't store items - Some bugfixes --- core/assets/contributors | 1 + core/src/mindustry/ai/Pathfinder.java | 6 +-- core/src/mindustry/content/Bullets.java | 1 + core/src/mindustry/entities/def/TileComp.java | 22 ++++++++- core/src/mindustry/graphics/LoadRenderer.java | 3 +- .../maps/planet/TODOPlanetGenerator.java | 2 +- .../ui/dialogs/SettingsMenuDialog.java | 2 +- .../mindustry/ui/fragments/HudFragment.java | 4 +- core/src/mindustry/world/Block.java | 2 +- core/src/mindustry/world/Tile.java | 14 +----- .../world/blocks/production/Drill.java | 2 +- .../blocks/production/GenericCrafter.java | 2 +- .../world/blocks/production/Separator.java | 2 +- .../world/blocks/storage/Unloader.java | 48 ++++++++----------- .../mindustry/world/modules/ItemModule.java | 19 ++++++++ gradle.properties | 2 +- 16 files changed, 78 insertions(+), 54 deletions(-) diff --git a/core/assets/contributors b/core/assets/contributors index 1af018e7da..ba93d0b0ab 100644 --- a/core/assets/contributors +++ b/core/assets/contributors @@ -58,6 +58,7 @@ Clarence "Sparr" Risher bei2 AceEllysium Cedric L'homme +Michał “Neoqueto” indielm Ameb player20033 diff --git a/core/src/mindustry/ai/Pathfinder.java b/core/src/mindustry/ai/Pathfinder.java index d19e2c7157..f290e18c9d 100644 --- a/core/src/mindustry/ai/Pathfinder.java +++ b/core/src/mindustry/ai/Pathfinder.java @@ -62,7 +62,7 @@ public class Pathfinder implements Runnable{ /** Packs a tile into its internal representation. */ private int packTile(Tile tile){ - return PathTile.get(tile.cost, tile.getTeamID(), (byte)0, !tile.solid() && tile.floor().drownTime <= 0f); + return PathTile.get(tile.cost, tile.getTeamID(), !tile.solid() && tile.floor().drownTime <= 0f); } /** Starts or restarts the pathfinding thread. */ @@ -360,11 +360,11 @@ public class Pathfinder implements Runnable{ @Struct class PathTileStruct{ //traversal cost - byte cost; + short cost; //team of block, if applicable (0 by default) byte team; //type of target; TODO remove - byte type; + //byte type; //whether it's viable to pass this block boolean passable; } diff --git a/core/src/mindustry/content/Bullets.java b/core/src/mindustry/content/Bullets.java index 0c074131e1..a23cfa2975 100644 --- a/core/src/mindustry/content/Bullets.java +++ b/core/src/mindustry/content/Bullets.java @@ -489,6 +489,7 @@ public class Bullets implements ContentList{ despawnEffect = Fx.none; hitSize = 4; lifetime = 16f; + drawSize = 400f; }}; meltdownLaser = new BulletType(0.001f, 70){ diff --git a/core/src/mindustry/entities/def/TileComp.java b/core/src/mindustry/entities/def/TileComp.java index 70bce2d925..9ce4b5cd5f 100644 --- a/core/src/mindustry/entities/def/TileComp.java +++ b/core/src/mindustry/entities/def/TileComp.java @@ -477,7 +477,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree * Tries to put this item into a nearby container, if there are no available * containers, it gets added to the block's inventory. */ - public void offloadNear(Item item){ + public void offload(Item item){ Array proximity = proximity(); int dump = rotation() / block.dumpIncrement; useContent(item); @@ -494,6 +494,26 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree handleItem(this, item); } + /** + * Tries to put this item into a nearby container. Returns success. Unlike #offload(), this method does not change the block inventory. + */ + public boolean put(Item item){ + Array proximity = proximity(); + int dump = rotation() / block.dumpIncrement; + useContent(item); + + for(int i = 0; i < proximity.size; i++){ + incrementDump(proximity.size); + Tilec other = proximity.get((i + dump) % proximity.size); + if(other.team() == team() && other.acceptItem(this, item) && canDump(other, item)){ + other.handleItem(this, item); + return true; + } + } + + return false; + } + /** Try dumping any item near the */ public boolean dump(){ return dump(null); diff --git a/core/src/mindustry/graphics/LoadRenderer.java b/core/src/mindustry/graphics/LoadRenderer.java index 62fd27260f..ddea53bf4c 100644 --- a/core/src/mindustry/graphics/LoadRenderer.java +++ b/core/src/mindustry/graphics/LoadRenderer.java @@ -40,7 +40,8 @@ public class LoadRenderer implements Disposable{ private long lastFrameTime; { - fx.addEffect(new VignettingFilter(false)); + //vignetting is probably too much + //fx.addEffect(new VignettingFilter(false)); fx.addEffect(new BloomFilter()); bars = new Bar[]{ diff --git a/core/src/mindustry/maps/planet/TODOPlanetGenerator.java b/core/src/mindustry/maps/planet/TODOPlanetGenerator.java index 89a17c3fe1..d3f218e8d0 100644 --- a/core/src/mindustry/maps/planet/TODOPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/TODOPlanetGenerator.java @@ -43,7 +43,7 @@ public class TODOPlanetGenerator extends PlanetGenerator{ float rawHeight(Vec3 position){ position = Tmp.v33.set(position).scl(scl); - return Mathf.pow((float)noise.octaveNoise3D(7, 0.48f, 1f/3f, position.x, position.y, position.z), 2.3f); + return Mathf.pow((float)noise.octaveNoise3D(7, 0.48f, 1f/3f, position.x, position.y, position.z), 2.3f) + 0.05f; } @Override diff --git a/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java b/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java index eac5fc4d9b..f56abbaba8 100644 --- a/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java +++ b/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java @@ -344,7 +344,7 @@ public class SettingsMenuDialog extends SettingsDialog{ } }); - graphics.checkPref("linear", !mobile, b -> { + graphics.checkPref("linear", true, b -> { for(Texture tex : Core.atlas.getTextures()){ TextureFilter filter = b ? TextureFilter.Linear : TextureFilter.Nearest; tex.setFilter(filter, filter); diff --git a/core/src/mindustry/ui/fragments/HudFragment.java b/core/src/mindustry/ui/fragments/HudFragment.java index 38d9a69c19..a85b757897 100644 --- a/core/src/mindustry/ui/fragments/HudFragment.java +++ b/core/src/mindustry/ui/fragments/HudFragment.java @@ -181,7 +181,7 @@ public class HudFragment extends Fragment{ //fps display cont.table(info -> { - info.top().left().margin(4).visible(() -> Core.settings.getBool("fps")); + info.top().left().margin(4).visible(() -> Core.settings.getBool("fps") && shown); info.update(() -> info.setTranslation(state.rules.waves || state.isEditor() ? 0f : -Scl.scl(dsize * 4 + 3), 0)); IntFormat fps = new IntFormat("fps"); IntFormat ping = new IntFormat("ping"); @@ -193,7 +193,7 @@ public class HudFragment extends Fragment{ }); parent.fill(t -> { - t.visible(() -> Core.settings.getBool("minimap") && !state.rules.tutorial); + t.visible(() -> Core.settings.getBool("minimap") && !state.rules.tutorial && shown); //minimap t.add(new Minimap()); t.row(); diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 4e2c23972d..64432e779f 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -302,7 +302,7 @@ public class Block extends UnlockableContent{ // Note: Power stats are added by the consumers. if(hasLiquids) stats.add(BlockStat.liquidCapacity, liquidCapacity, StatUnit.liquidUnits); - if(hasItems) stats.add(BlockStat.itemCapacity, itemCapacity, StatUnit.items); + if(hasItems && itemCapacity > 0) stats.add(BlockStat.itemCapacity, itemCapacity, StatUnit.items); } public void setBars(){ diff --git a/core/src/mindustry/world/Tile.java b/core/src/mindustry/world/Tile.java index 12a6a51601..c19322cbb7 100644 --- a/core/src/mindustry/world/Tile.java +++ b/core/src/mindustry/world/Tile.java @@ -20,7 +20,7 @@ public class Tile implements Position, QuadTreeObject{ static final ObjectSet tileSet = new ObjectSet<>(); /** Tile traversal cost. */ - public byte cost = 1; + public short cost = 1; /** Tile entity, usually null. */ public @Nullable Tilec entity; public short x, y; @@ -452,32 +452,22 @@ public class Tile implements Position, QuadTreeObject{ } } - //+24 - if(occluded){ cost += 2; } - //+26 - if(block.synthetic() && solid()){ - cost += Mathf.clamp(block.health / 10f, 0, 20); + cost += Mathf.clamp(block.health / 6f, 0, 1000); } - //+46 - if(floor.isLiquid){ cost += 10; } - //+56 - if(floor.drownTime > 0){ cost += 70; } - //+126 - if(cost < 0){ cost = Byte.MAX_VALUE; } diff --git a/core/src/mindustry/world/blocks/production/Drill.java b/core/src/mindustry/world/blocks/production/Drill.java index 9effee6d16..e42d5ff8be 100644 --- a/core/src/mindustry/world/blocks/production/Drill.java +++ b/core/src/mindustry/world/blocks/production/Drill.java @@ -266,7 +266,7 @@ public class Drill extends Block{ } if(dominantItems > 0 && progress >= drillTime + hardnessDrillMultiplier * dominantItem.hardness && items.total() < itemCapacity){ - offloadNear(dominantItem); + offload(dominantItem); useContent(dominantItem); index++; diff --git a/core/src/mindustry/world/blocks/production/GenericCrafter.java b/core/src/mindustry/world/blocks/production/GenericCrafter.java index 7915a32792..2a82dec02e 100644 --- a/core/src/mindustry/world/blocks/production/GenericCrafter.java +++ b/core/src/mindustry/world/blocks/production/GenericCrafter.java @@ -114,7 +114,7 @@ public class GenericCrafter extends Block{ if(outputItem != null){ useContent(outputItem.item); for(int i = 0; i < outputItem.amount; i++){ - offloadNear(outputItem.item); + offload(outputItem.item); } } diff --git a/core/src/mindustry/world/blocks/production/Separator.java b/core/src/mindustry/world/blocks/production/Separator.java index bdfaf05b3c..9fa8efbdc3 100644 --- a/core/src/mindustry/world/blocks/production/Separator.java +++ b/core/src/mindustry/world/blocks/production/Separator.java @@ -112,7 +112,7 @@ public class Separator extends Block{ consume(); if(item != null && items.get(item) < itemCapacity){ - offloadNear(item); + offload(item); } } diff --git a/core/src/mindustry/world/blocks/storage/Unloader.java b/core/src/mindustry/world/blocks/storage/Unloader.java index b13fde20fa..66be1104fc 100644 --- a/core/src/mindustry/world/blocks/storage/Unloader.java +++ b/core/src/mindustry/world/blocks/storage/Unloader.java @@ -25,6 +25,7 @@ public class Unloader extends Block{ hasItems = true; configurable = true; saveConfig = true; + itemCapacity = 0; config(Item.class, (tile, item) -> { tile.items().clear(); @@ -47,40 +48,31 @@ public class Unloader extends Block{ public class UnloaderEntity extends TileEntity{ public Item sortItem = null; - - private Item removeItem(Tilec tile, Item item){ - if(item == null){ - return tile.items().take(); - }else{ - if(tile.items().has(item)){ - tile.items().remove(item, 1); - return item; - } - - return null; - } - } - - private boolean hasItem(Tilec tile, Item item){ - if(item == null){ - return tile.items().total() > 0; - }else{ - return tile.items().has(item); - } - } + public Tilec dumpingTo; @Override public void updateTile(){ - if(timer(timerUnload, speed / timeScale()) && items.total() == 0){ + if(timer(timerUnload, speed / timeScale())){ for(Tilec other : proximity){ - if(other.interactable(team) && other.block().unloadable && other.block().hasItems && items.total() == 0 && - ((sortItem == null && items.total() > 0) || hasItem(other, sortItem))){ - offloadNear(removeItem(other, sortItem)); + if(other.interactable(team) && other.block().unloadable && other.block().hasItems + && ((sortItem == null && other.items().total() > 0) || (sortItem != null && other.items().has(sortItem)))){ + //make sure the item can't be dumped back into this block + dumpingTo = other; + + //get item to be taken + Item item = sortItem == null ? other.items().beginTake() : sortItem; + + //remove item if it's dumped correctly + if(put(item)){ + if(sortItem == null){ + other.items().endTake(item); + }else{ + other.items().remove(item, 1); + } + } } } } - - dump(); } @Override @@ -110,7 +102,7 @@ public class Unloader extends Block{ @Override public boolean canDump(Tilec to, Item item){ - return !(to.block() instanceof StorageBlock); + return !(to.block() instanceof StorageBlock) && to != dumpingTo; } @Override diff --git a/core/src/mindustry/world/modules/ItemModule.java b/core/src/mindustry/world/modules/ItemModule.java index d3294f2acd..ba7a309fa5 100644 --- a/core/src/mindustry/world/modules/ItemModule.java +++ b/core/src/mindustry/world/modules/ItemModule.java @@ -160,6 +160,25 @@ public class ItemModule extends BlockModule{ return null; } + /** Begins a speculative take operation. This returns the item that would be returned by #take(), but does not change state. */ + public Item beginTake(){ + for(int i = 0; i < items.length; i++){ + int index = (i + takeRotation); + if(index >= items.length) index -= items.length; + if(items[index] > 0){ + return content.item(index); + } + } + 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 int get(int id){ return items[id]; } diff --git a/gradle.properties b/gradle.properties index 8a8ef7b2ab..243155bbca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=3bba9d6264dc329066068b1bd6fadd6632d2e7b9 +archash=7a43c29eca25a472f966f48fe9df213b61e9f18c