From 0543616f1504cf7e27e0f5bee3e5451572547efc Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 7 Jul 2021 10:31:18 -0400 Subject: [PATCH] WIP "wall crafter" --- core/src/mindustry/world/Block.java | 3 + .../world/blocks/environment/Floor.java | 3 - .../world/blocks/production/WallCrafter.java | 153 ++++++++++++++++++ gradle.properties | 2 +- 4 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 core/src/mindustry/world/blocks/production/WallCrafter.java diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 2fccf0130b..154b41f9ab 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -25,6 +25,7 @@ import mindustry.graphics.*; import mindustry.graphics.MultiPacker.*; import mindustry.type.*; import mindustry.ui.*; +import mindustry.world.blocks.*; import mindustry.world.blocks.environment.*; import mindustry.world.blocks.power.*; import mindustry.world.consumers.*; @@ -112,6 +113,8 @@ public class Block extends UnlockableContent{ public boolean useColor = true; /** item that drops from this block, used for drills */ public @Nullable Item itemDrop = null; + /** Array of affinities to certain things. */ + public Attributes attributes = new Attributes(); /** tile entity health */ public int health = -1; /** base block explosiveness */ diff --git a/core/src/mindustry/world/blocks/environment/Floor.java b/core/src/mindustry/world/blocks/environment/Floor.java index 5ecd9872b4..14ec094818 100644 --- a/core/src/mindustry/world/blocks/environment/Floor.java +++ b/core/src/mindustry/world/blocks/environment/Floor.java @@ -15,7 +15,6 @@ import mindustry.graphics.*; import mindustry.graphics.MultiPacker.*; import mindustry.type.*; import mindustry.world.*; -import mindustry.world.blocks.*; import static mindustry.Vars.*; @@ -54,8 +53,6 @@ public class Floor extends Block{ public Block blendGroup = this; /** Effect displayed when randomly updated. */ public Effect updateEffect = Fx.none; - /** Array of affinities to certain things. */ - public Attributes attributes = new Attributes(); /** Whether this ore generates in maps by default. */ public boolean oreDefault = false; /** Ore generation params. */ diff --git a/core/src/mindustry/world/blocks/production/WallCrafter.java b/core/src/mindustry/world/blocks/production/WallCrafter.java new file mode 100644 index 0000000000..9c718a46b3 --- /dev/null +++ b/core/src/mindustry/world/blocks/production/WallCrafter.java @@ -0,0 +1,153 @@ +package mindustry.world.blocks.production; + +import arc.*; +import arc.graphics.g2d.*; +import arc.math.*; +import arc.math.geom.*; +import arc.util.*; +import mindustry.annotations.Annotations.*; +import mindustry.content.*; +import mindustry.entities.*; +import mindustry.entities.units.*; +import mindustry.gen.*; +import mindustry.type.*; +import mindustry.world.*; +import mindustry.world.meta.*; + +import static mindustry.Vars.*; + +public class WallCrafter extends Block{ + public @Load("@-top") TextureRegion topRegion; + + /** Time to produce one item at 100% efficiency. */ + public float drillTime = 200f; + /** Effect randomly played while drilling. */ + public Effect updateEffect = Fx.mineSmall; + /** Attribute to check for wall output. */ + public Attribute attribute = Attribute.oil; //TODO silicates + + public Item output = Items.sand; + + public WallCrafter(String name){ + super(name); + + hasItems = true; + rotate = true; + update = true; + solid = true; + drawArrow = false; + + envEnabled |= Env.space; + } + + @Override + public boolean outputsItems(){ + return true; + } + + @Override + public boolean rotatedOutput(int x, int y){ + return false; + } + + @Override + public TextureRegion[] icons(){ + return new TextureRegion[]{region, topRegion}; + } + + @Override + public void drawRequestRegion(BuildPlan req, Eachable list){ + Draw.rect(region, req.drawx(), req.drawy()); + Draw.rect(topRegion, req.drawx(), req.drawy(), req.rotation * 90); + } + + @Override + public void drawPlace(int x, int y, int rotation, boolean valid){ + float eff = 0f; + + for(int i = 0; i < size; i++){ + getLaserPos(x, y, rotation, Tmp.p1); + int rx = Tmp.p1.x, ry = Tmp.p1.y; + + Tile other = world.tile(rx, ry); + if(other != null && other.solid()){ + eff += other.block().attributes.get(attribute); + } + } + + 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); + } + } + + public class WallCrafterBuild extends Building{ + public float time; + public float warmup; + + @Override + public void drawSelect(){ + + //TODO efficiency + } + + @Override + public void updateTile(){ + super.updateTile(); + + boolean cons = shouldConsume(); + + warmup = Mathf.lerpDelta(warmup, Mathf.num(consValid()), 0.1f); + float eff = 0f; + + //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)); + } + } + + + } + + time += edelta(); + + if(time >= drillTime){ + + time %= drillTime; + } + + if(timer(timerDump, dumpTime)){ + dump(); + } + } + + @Override + public boolean shouldConsume(){ + return items.total() < itemCapacity; + } + + @Override + public void draw(){ + //TODO draw spinner drill thingies + Draw.rect(block.region, x, y); + Draw.rect(topRegion, x, y, rotdeg()); + } + } +} diff --git a/gradle.properties b/gradle.properties index 5aa6936a7b..95715623ae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,4 +10,4 @@ kapt.include.compile.classpath=false kotlin.stdlib.default.dependency=false #needed for android compilation android.useAndroidX=true -archash=ca296ad37aeca186fcef3290bb8a6e9143bdd245 +archash=33c4976f8084fbb6fc26cfdcca2dda3442711d17