From 64ab8328b8f95ace50c4ceaf793615ecbc6d2d91 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 7 Jul 2021 16:28:33 -0400 Subject: [PATCH] WallCrafter progress --- core/src/mindustry/content/Blocks.java | 19 ++- core/src/mindustry/world/Block.java | 2 +- core/src/mindustry/world/Build.java | 2 +- .../world/blocks/power/ThermalGenerator.java | 2 +- .../world/blocks/production/Drill.java | 2 +- .../world/blocks/production/Pump.java | 2 +- .../world/blocks/production/SolidPump.java | 2 +- .../world/blocks/production/WallCrafter.java | 110 +++++++++++------- .../world/blocks/storage/CoreBlock.java | 4 +- core/src/mindustry/world/meta/Attribute.java | 4 +- core/src/mindustry/world/meta/StatValues.java | 12 +- core/src/mindustry/world/meta/Stats.java | 2 +- 12 files changed, 101 insertions(+), 62 deletions(-) diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 19f5e2bccb..dcf55e93d5 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -81,7 +81,7 @@ public class Blocks implements ContentList{ //production mechanicalDrill, pneumaticDrill, laserDrill, blastDrill, waterExtractor, oilExtractor, cultivator, - beamDrill, + cliffCrusher, beamDrill, //storage coreShard, coreFoundation, coreNucleus, vault, container, unloader, @@ -377,7 +377,9 @@ public class Blocks implements ContentList{ wall = sporeWall; }}; - stoneWall = new StaticWall("stone-wall"); + stoneWall = new StaticWall("stone-wall"){{ + attributes.set(Attribute.silicate, 1f); + }}; sporeWall = new StaticWall("spore-wall"); @@ -413,10 +415,12 @@ public class Blocks implements ContentList{ ferricStoneWall = new StaticWall("ferric-stone-wall"){{ ferricStone.asFloor().wall = this; + attributes.set(Attribute.silicate, 0.5f); }}; beryllicStoneWall = new StaticWall("beryllic-stone-wall"){{ beryllicStone.asFloor().wall = this; + attributes.set(Attribute.silicate, 1.2f); }}; redIceWall = new StaticWall("red-ice-wall"){{ @@ -1509,8 +1513,17 @@ public class Blocks implements ContentList{ consumes.liquid(Liquids.water, 0.15f); }}; + cliffCrusher = new WallCrafter("cliff-crusher"){{ + requirements(Category.production, with(Items.copper, 10)); + consumes.power(0.2f); + + size = 2; + attribute = Attribute.silicate; + output = Items.sand; + }}; + beamDrill = new BeamDrill("beam-drill"){{ - requirements(Category.production, with(Items.copper, 150)); + requirements(Category.production, with(Items.copper, 10)); consumes.power(0.2f); tier = 4; size = 2; diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 154b41f9ab..a4a17257a7 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -367,7 +367,7 @@ public class Block extends UnlockableContent{ } /** Returns whether or not this block can be place on the specified */ - public boolean canPlaceOn(Tile tile, Team team){ + public boolean canPlaceOn(Tile tile, Team team, int rotation){ return true; } diff --git a/core/src/mindustry/world/Build.java b/core/src/mindustry/world/Build.java index d5bb888f7a..ab4fbcd53a 100644 --- a/core/src/mindustry/world/Build.java +++ b/core/src/mindustry/world/Build.java @@ -169,7 +169,7 @@ public class Build{ return false; } - if(!type.canPlaceOn(tile, team)){ + if(!type.canPlaceOn(tile, team, rotation)){ return false; } diff --git a/core/src/mindustry/world/blocks/power/ThermalGenerator.java b/core/src/mindustry/world/blocks/power/ThermalGenerator.java index 1c6d7837eb..a1a6659903 100644 --- a/core/src/mindustry/world/blocks/power/ThermalGenerator.java +++ b/core/src/mindustry/world/blocks/power/ThermalGenerator.java @@ -40,7 +40,7 @@ public class ThermalGenerator extends PowerGenerator{ } @Override - public boolean canPlaceOn(Tile tile, Team team){ + public boolean canPlaceOn(Tile tile, Team team, int rotation){ //make sure there's heat at this location return tile.getLinkedTilesAs(this, tempTiles).sumf(other -> other.floor().attributes.get(attribute)) > 0.01f; } diff --git a/core/src/mindustry/world/blocks/production/Drill.java b/core/src/mindustry/world/blocks/production/Drill.java index 8c627ea493..b833d9be9d 100644 --- a/core/src/mindustry/world/blocks/production/Drill.java +++ b/core/src/mindustry/world/blocks/production/Drill.java @@ -99,7 +99,7 @@ public class Drill extends Block{ } @Override - public boolean canPlaceOn(Tile tile, Team team){ + public boolean canPlaceOn(Tile tile, Team team, int rotation){ if(isMultiblock()){ for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){ if(canMine(other)){ diff --git a/core/src/mindustry/world/blocks/production/Pump.java b/core/src/mindustry/world/blocks/production/Pump.java index 98c87553a3..49d700342f 100644 --- a/core/src/mindustry/world/blocks/production/Pump.java +++ b/core/src/mindustry/world/blocks/production/Pump.java @@ -62,7 +62,7 @@ public class Pump extends LiquidBlock{ } @Override - public boolean canPlaceOn(Tile tile, Team team){ + public boolean canPlaceOn(Tile tile, Team team, int rotation){ if(isMultiblock()){ Liquid last = null; for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){ diff --git a/core/src/mindustry/world/blocks/production/SolidPump.java b/core/src/mindustry/world/blocks/production/SolidPump.java index 109ac57658..149cca79e2 100644 --- a/core/src/mindustry/world/blocks/production/SolidPump.java +++ b/core/src/mindustry/world/blocks/production/SolidPump.java @@ -65,7 +65,7 @@ public class SolidPump extends Pump{ } @Override - public boolean canPlaceOn(Tile tile, Team team){ + public boolean canPlaceOn(Tile tile, Team team, int rotation){ float sum = tile.getLinkedTilesAs(this, tempTiles).sumf(t -> canPump(t) ? baseEfficiency + (attribute != null ? t.floor().attributes.get(attribute) : 0f) : 0f); return sum > 0.00001f; } diff --git a/core/src/mindustry/world/blocks/production/WallCrafter.java b/core/src/mindustry/world/blocks/production/WallCrafter.java index 9c718a46b3..11943a010e 100644 --- a/core/src/mindustry/world/blocks/production/WallCrafter.java +++ b/core/src/mindustry/world/blocks/production/WallCrafter.java @@ -1,6 +1,7 @@ package mindustry.world.blocks.production; import arc.*; +import arc.func.*; import arc.graphics.g2d.*; import arc.math.*; import arc.math.geom.*; @@ -9,6 +10,7 @@ import mindustry.annotations.Annotations.*; import mindustry.content.*; import mindustry.entities.*; import mindustry.entities.units.*; +import mindustry.game.*; import mindustry.gen.*; import mindustry.type.*; import mindustry.world.*; @@ -24,7 +26,7 @@ public class WallCrafter extends Block{ /** Effect randomly played while drilling. */ public Effect updateEffect = Fx.mineSmall; /** Attribute to check for wall output. */ - public Attribute attribute = Attribute.oil; //TODO silicates + public Attribute attribute = Attribute.silicate; public Item output = Items.sand; @@ -35,11 +37,23 @@ public class WallCrafter extends Block{ rotate = true; update = true; solid = true; - drawArrow = false; envEnabled |= Env.space; } + @Override + public void setBars(){ + super.setBars(); + } + + @Override + public void setStats(){ + super.setStats(); + + stats.add(Stat.output, output); + stats.add(Stat.tiles, StatValues.blocks(attribute, floating, 1f, true, false)); + } + @Override public boolean outputsItems(){ return true; @@ -63,42 +77,57 @@ public class WallCrafter extends Block{ @Override public void drawPlace(int x, int y, int rotation, boolean valid){ + float eff = getEfficiency(x, y, rotation, null); + + drawPlaceText(Core.bundle.formatFloat("bar.drillspeed", 60f / drillTime * eff, 2), x, y, valid); + } + @Override + public boolean canPlaceOn(Tile tile, Team team, int rotation){ + return getEfficiency(tile.x, tile.y, rotation, null) > 0; + } + + float getEfficiency(int tx, int ty, int rotation, @Nullable Cons ctile){ float eff = 0f; + int cornerX = tx - (size-1)/2, cornerY = ty - (size-1)/2, s = size; for(int i = 0; i < size; i++){ - getLaserPos(x, y, rotation, Tmp.p1); - int rx = Tmp.p1.x, ry = Tmp.p1.y; + int rx = 0, ry = 0; + + switch(rotation){ + case 0 -> { + rx = cornerX + s; + ry = cornerY + i; + } + case 1 -> { + rx = cornerX + i; + ry = cornerY + s; + } + case 2 -> { + rx = cornerX - 1; + ry = cornerY + i; + } + case 3 -> { + rx = cornerX + i; + ry = cornerY - 1; + } + } Tile other = world.tile(rx, ry); if(other != null && other.solid()){ - eff += other.block().attributes.get(attribute); + float at = other.block().attributes.get(attribute); + eff += at; + if(at > 0 && ctile != null){ + ctile.get(other); + } } } - - drawPlaceText(Core.bundle.formatFloat("bar.drillspeed", 60f / drillTime * eff, 2), x, y, valid); - - } - - void getLaserPos(int tx, int ty, int rotation, Point2 out){ - int cornerX = tx - (size-1)/2, cornerY = ty - (size-1)/2, s = size; - switch(rotation){ - case 0 -> out.set(cornerX + s, cornerY + 1); - case 1 -> out.set(cornerX + 1, cornerY + s); - case 2 -> out.set(cornerX - 1, cornerY + 1); - case 3 -> out.set(cornerX + 1, cornerY - 1); - } + return eff; } public class WallCrafterBuild extends Building{ public float time; public float warmup; - @Override - public void drawSelect(){ - - //TODO efficiency - } - @Override public void updateTile(){ super.updateTile(); @@ -106,30 +135,21 @@ public class WallCrafter extends Block{ boolean cons = shouldConsume(); warmup = Mathf.lerpDelta(warmup, Mathf.num(consValid()), 0.1f); - float eff = 0f; + float dx = Geometry.d4x(rotation) * 0.5f, dy = Geometry.d4y(rotation) * 0.5f; - //update facing tiles - for(int p = 0; p < size; p++){ - getLaserPos(tile.x, tile.y, rotation, Tmp.p1); - - int rx = Tmp.p1.x, ry = Tmp.p1.y; - Tile dest = world.tile(rx, ry); - if(dest != null && dest.solid()){ - eff += dest.block().attributes.get(attribute); - - //TODO make not chance based? - if(cons && dest.block().attributes.get(attribute) > 0f && Mathf.chanceDelta(0.05 * warmup)){ - updateEffect.at(dest.worldx() + Mathf.range(3f), dest.worldy() + Mathf.range(3f)); - } + float eff = getEfficiency(tile.x, tile.y, rotation, dest -> { + //TODO make not chance based? + if(cons && Mathf.chanceDelta(0.05 * warmup)){ + updateEffect.at( + dest.worldx() + Mathf.range(3f) - dx, + dest.worldy() + Mathf.range(3f) - dy, + output.color + ); } + }); - - } - - time += edelta(); - - if(time >= drillTime){ - + if(cons && (time += edelta() * eff) >= drillTime){ + items.add(output, 1); time %= drillTime; } diff --git a/core/src/mindustry/world/blocks/storage/CoreBlock.java b/core/src/mindustry/world/blocks/storage/CoreBlock.java index 52844719d7..ae49d49f70 100644 --- a/core/src/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/mindustry/world/blocks/storage/CoreBlock.java @@ -123,7 +123,7 @@ public class CoreBlock extends StorageBlock{ } @Override - public boolean canPlaceOn(Tile tile, Team team){ + public boolean canPlaceOn(Tile tile, Team team, int rotation){ if(tile == null) return false; CoreBuild core = team.core(); //must have all requirements @@ -168,7 +168,7 @@ public class CoreBlock extends StorageBlock{ public void drawPlace(int x, int y, int rotation, boolean valid){ if(world.tile(x, y) == null) return; - if(!canPlaceOn(world.tile(x, y), player.team())){ + if(!canPlaceOn(world.tile(x, y), player.team(), rotation)){ drawPlaceText(Core.bundle.get( (player.team().core() != null && player.team().core().items.has(requirements, state.rules.buildCostMultiplier)) || state.rules.infiniteResources ? diff --git a/core/src/mindustry/world/meta/Attribute.java b/core/src/mindustry/world/meta/Attribute.java index 4ade4aa68f..15437879b0 100644 --- a/core/src/mindustry/world/meta/Attribute.java +++ b/core/src/mindustry/world/meta/Attribute.java @@ -17,7 +17,9 @@ public class Attribute{ /** Oil content. Used for oil extractor yield. */ oil = add("oil"), /** Light coverage. Negative values decrease solar panel efficiency. */ - light = add("light"); + light = add("light"), + /** Silicate content. Used for sand extraction. */ + silicate = add("silicate"); public final int id; public final String name; diff --git a/core/src/mindustry/world/meta/StatValues.java b/core/src/mindustry/world/meta/StatValues.java index 4a7704e36f..83f65ebc22 100644 --- a/core/src/mindustry/world/meta/StatValues.java +++ b/core/src/mindustry/world/meta/StatValues.java @@ -112,14 +112,18 @@ public class StatValues{ }; } - public static StatValue floorEfficiency(Floor floor, float multiplier, boolean startZero){ + public static StatValue blockEfficiency(Block floor, float multiplier, boolean startZero){ return table -> table.stack( new Image(floor.uiIcon).setScaling(Scaling.fit), new Table(t -> t.top().right().add((multiplier < 0 ? "[scarlet]" : startZero ? "[accent]" : "[accent]+") + (int)((multiplier) * 100) + "%").style(Styles.outlineLabel)) ); } - public static StatValue floors(Attribute attr, boolean floating, float scale, boolean startZero){ + public static StatValue blocks(Attribute attr, boolean floating, float scale, boolean startZero){ + return blocks(attr, floating, scale, startZero, true); + } + + public static StatValue blocks(Attribute attr, boolean floating, float scale, boolean startZero, boolean checkFloors){ return table -> table.table(c -> { Runnable[] rebuild = {null}; Map[] lastMap = {null}; @@ -130,14 +134,14 @@ public class StatValues{ if(state.isGame()){ var blocks = Vars.content.blocks() - .select(block -> block instanceof Floor f && indexer.isBlockPresent(block) && f.attributes.get(attr) != 0 && !(f.isLiquid && !floating)) + .select(block -> (!checkFloors || block instanceof Floor) && indexer.isBlockPresent(block) && block.attributes.get(attr) != 0 && !((block instanceof Floor f && f.isLiquid) && !floating)) .as().with(s -> s.sort(f -> f.attributes.get(attr))); if(blocks.any()){ int i = 0; for(var block : blocks){ - floorEfficiency(block, block.attributes.get(attr) * scale, startZero).display(c); + blockEfficiency(block, block.attributes.get(attr) * scale, startZero).display(c); if(++i % 5 == 0){ c.row(); } diff --git a/core/src/mindustry/world/meta/Stats.java b/core/src/mindustry/world/meta/Stats.java index d11b56f395..742400989f 100644 --- a/core/src/mindustry/world/meta/Stats.java +++ b/core/src/mindustry/world/meta/Stats.java @@ -66,7 +66,7 @@ public class Stats{ } public void add(Stat stat, Attribute attr, boolean floating, float scale, boolean startZero){ - add(stat, StatValues.floors(attr, floating, scale, startZero)); + add(stat, StatValues.blocks(attr, floating, scale, startZero)); } /** Adds a single string value with this stat. */