Initial reconstructor impl
This commit is contained in:
@@ -165,7 +165,6 @@ public class Block extends UnlockableContent{
|
||||
public float buildCostMultiplier = 1f;
|
||||
/** Whether this block has instant transfer.*/
|
||||
public boolean instantTransfer = false;
|
||||
public boolean alwaysUnlocked = false;
|
||||
|
||||
protected Prov<Tilec> entityType = null; //initialized later
|
||||
//TODO move
|
||||
@@ -352,16 +351,16 @@ public class Block extends UnlockableContent{
|
||||
Draw.reset();
|
||||
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime(), 6f, 0.28f));
|
||||
Draw.alpha(1f);
|
||||
float prevScale = Draw.scl;
|
||||
Draw.scl *= req.animScale;
|
||||
drawRequestRegion(req, list);
|
||||
Draw.scl = prevScale;
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list){
|
||||
TextureRegion reg = getRequestRegion(req, list);
|
||||
Draw.rect(reg, req.drawx(), req.drawy(),
|
||||
reg.getWidth() * req.animScale * Draw.scl,
|
||||
reg.getHeight() * req.animScale * Draw.scl,
|
||||
!rotate ? 0 : req.rotation * 90);
|
||||
Draw.rect(reg, req.drawx(), req.drawy(), !rotate ? 0 : req.rotation * 90);
|
||||
|
||||
if(req.hasConfig){
|
||||
drawRequestConfig(req, list);
|
||||
@@ -380,12 +379,8 @@ public class Block extends UnlockableContent{
|
||||
Color color = content instanceof Item ? ((Item)content).color : content instanceof Liquid ? ((Liquid)content).color : null;
|
||||
if(color == null) return;
|
||||
|
||||
float prev = Draw.scl;
|
||||
|
||||
Draw.color(color);
|
||||
Draw.scl *= req.animScale;
|
||||
Draw.rect(region, req.drawx(), req.drawy());
|
||||
Draw.scl = prev;
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@@ -627,11 +622,6 @@ public class Block extends UnlockableContent{
|
||||
return !buildVisibility.visible();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alwaysUnlocked(){
|
||||
return alwaysUnlocked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createIcons(MultiPacker packer){
|
||||
super.createIcons(packer);
|
||||
|
||||
@@ -20,7 +20,7 @@ public class ItemBuffer{
|
||||
|
||||
public void accept(Item item, short data){
|
||||
//if(!accepts()) return;
|
||||
buffer[index++] = Pack.longInt(Float.floatToIntBits(Time.time()), Pack.shortInt((short)item.id, data));
|
||||
buffer[index++] = Pack.longInt(Float.floatToIntBits(Time.time()), Pack.shortInt(item.id, data));
|
||||
}
|
||||
|
||||
public void accept(Item item){
|
||||
|
||||
@@ -283,6 +283,10 @@ public class Tile implements Position, QuadTreeObject{
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public int rotdeg(){
|
||||
return rotation * 90;
|
||||
}
|
||||
|
||||
public void rotation(int rotation){
|
||||
this.rotation = (byte)rotation;
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public class BuildBlock extends Block{
|
||||
@Override
|
||||
public void draw(){
|
||||
if(!(previous == null || cblock == null || previous == cblock) && Core.atlas.isFound(previous.icon(Cicon.full))){
|
||||
Draw.rect(previous.icon(Cicon.full), x, y, previous.rotate ? tile.rotation() * 90 : 0);
|
||||
Draw.rect(previous.icon(Cicon.full), x, y, previous.rotate ? tile.rotdeg() : 0);
|
||||
}
|
||||
|
||||
Draw.draw(Layer.blockBuilding, () -> {
|
||||
@@ -183,7 +183,7 @@ public class BuildBlock extends Block{
|
||||
Shaders.blockbuild.region = region;
|
||||
Shaders.blockbuild.progress = progress;
|
||||
|
||||
Draw.rect(region, x, y, target.rotate ? tile.rotation() * 90 : 0);
|
||||
Draw.rect(region, x, y, target.rotate ? tile.rotdeg() : 0);
|
||||
Draw.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class Conveyor extends Block implements Autotiler{
|
||||
if(bits == null) return;
|
||||
|
||||
TextureRegion region = regions[bits[0]][0];
|
||||
Draw.rect(region, req.drawx(), req.drawy(), region.getWidth() * bits[1] * Draw.scl * req.animScale, region.getHeight() * bits[2] * Draw.scl * req.animScale, req.rotation * 90);
|
||||
Draw.rect(region, req.drawx(), req.drawy(), region.getWidth() * bits[1] * Draw.scl, region.getHeight() * bits[2] * Draw.scl, req.rotation * 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -249,7 +249,7 @@ public class Conveyor extends Block implements Autotiler{
|
||||
|
||||
@Override
|
||||
public void getStackOffset(Item item, Vec2 trns){
|
||||
trns.trns(tile.rotation() * 90 + 180f, tilesize / 2f);
|
||||
trns.trns(tile.rotdeg() + 180f, tilesize / 2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,7 @@ import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.payloads.*;
|
||||
import mindustry.world.blocks.production.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@@ -81,7 +82,7 @@ public class PayloadConveyor extends Block{
|
||||
//TODO DEBUG
|
||||
if(Core.input.keyTap(KeyCode.g) && world.entWorld(Core.input.mouseWorld().x, Core.input.mouseWorld().y) == this){
|
||||
item = new UnitPayload((Mathf.chance(0.5) ? UnitTypes.wraith : UnitTypes.dagger).create(Team.sharded));
|
||||
itemRotation = rotation() * 90;
|
||||
itemRotation = rotdeg();
|
||||
animation = 0f;
|
||||
}
|
||||
|
||||
@@ -106,7 +107,7 @@ public class PayloadConveyor extends Block{
|
||||
//dump item forward
|
||||
float trnext = size * tilesize / 2f, cx = Geometry.d4(rotation()).x, cy = Geometry.d4(rotation()).y;
|
||||
|
||||
if(item.dump(x + cx * trnext, y + cy * trnext, rotation() * 90)){
|
||||
if(item.dump(x + cx * trnext, y + cy * trnext, rotdeg())){
|
||||
item = null;
|
||||
}
|
||||
}
|
||||
@@ -123,7 +124,7 @@ public class PayloadConveyor extends Block{
|
||||
float glow = Math.max((dst - (Math.abs(fract() - 0.5f) * 2)) / dst, 0);
|
||||
Draw.mixcol(Pal.accent, glow);
|
||||
|
||||
float trnext = fract() * size * tilesize, trprev = size * tilesize * (fract() - 1), rot = rotation() * 90;
|
||||
float trnext = fract() * size * tilesize, trprev = size * tilesize * (fract() - 1), rot = rotdeg();
|
||||
|
||||
TextureRegion clipped = clipRegion(tile.getHitbox(Tmp.r1), tile.getHitbox(Tmp.r2).move(trnext, 0), topRegion);
|
||||
float s = tilesize * size;
|
||||
@@ -164,12 +165,12 @@ public class PayloadConveyor extends Block{
|
||||
animation = Math.max(animation, fract());
|
||||
|
||||
float fract = animation;
|
||||
rot = Mathf.slerp(itemRotation, rotation() * 90, fract);
|
||||
rot = Mathf.slerp(itemRotation, rotdeg(), fract);
|
||||
|
||||
if(fract < 0.5f){
|
||||
Tmp.v1.trns(itemRotation + 180, (0.5f - fract) * tilesize * size);
|
||||
}else{
|
||||
Tmp.v1.trns(rotation() * 90, (fract - 0.5f) * tilesize * size);
|
||||
Tmp.v1.trns(rotdeg(), (fract - 0.5f) * tilesize * size);
|
||||
}
|
||||
|
||||
float vx = Tmp.v1.x, vy = Tmp.v1.y;
|
||||
@@ -196,10 +197,7 @@ public class PayloadConveyor extends Block{
|
||||
if(direction == rotation()){
|
||||
return !blocked || next != null;
|
||||
}else{
|
||||
Tilec accept = nearby(Geometry.d4(direction).x * size, Geometry.d4(direction).y * size);
|
||||
return accept != null && accept.block().size == size && accept.block().outputsPayload &&
|
||||
//block must either be facing this one, or not be rotating
|
||||
((accept.tileX() + Geometry.d4(accept.rotation()).x * size == tileX() && accept.tileY() + Geometry.d4(accept.rotation()).y * size == tileY()) || !accept.block().rotate);
|
||||
return PayloadAcceptor.blends(this, direction);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Sorter extends Block{
|
||||
|
||||
@Override
|
||||
public void drawRequestConfig(BuildRequest req, Eachable<BuildRequest> list){
|
||||
drawRequestConfigCenter(req, (Item)req.config, "center");
|
||||
drawRequestConfigCenter(req, req.config, "center");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -74,11 +74,11 @@ public class StackConveyor extends Block implements Autotiler{
|
||||
if(bits == null) return;
|
||||
|
||||
TextureRegion region = regions[0];
|
||||
Draw.rect(region, req.drawx(), req.drawy(), region.getWidth() * Draw.scl * req.animScale, region.getHeight() * Draw.scl * req.animScale, req.rotation * 90);
|
||||
Draw.rect(region, req.drawx(), req.drawy(), req.rotation * 90);
|
||||
|
||||
for(int i = 0; i < 4; i++){
|
||||
if((bits[3] & (1 << i)) == 0){
|
||||
Draw.rect(edgeRegion, req.drawx(), req.drawy(), region.getWidth() * Draw.scl * req.animScale, region.getHeight() * Draw.scl * req.animScale, (req.rotation - i) * 90);
|
||||
Draw.rect(edgeRegion, req.drawx(), req.drawy(), (req.rotation - i) * 90);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class StackConveyor extends Block implements Autotiler{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.rect(regions[state], x, y, rotation() * 90);
|
||||
Draw.rect(regions[state], x, y, rotdeg());
|
||||
|
||||
for(int i = 0; i < 4; i++){
|
||||
if((blendprox & (1 << i)) == 0){
|
||||
|
||||
@@ -26,7 +26,7 @@ public class BlockLauncher extends PayloadAcceptor{
|
||||
size = 3;
|
||||
}
|
||||
|
||||
public class BlockLauncherEntity extends PayloadAcceptorEntity{
|
||||
public class BlockLauncherEntity extends PayloadAcceptorEntity<BlockPayload>{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
@@ -42,15 +42,14 @@ public class BlockLauncher extends PayloadAcceptor{
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
if(updatePayload() && efficiency() >= 0.99f){
|
||||
if(moveInPayload() && efficiency() >= 0.99f){
|
||||
Effects.shake(4f, 4f, this);
|
||||
Fx.producesmoke.at(this);
|
||||
|
||||
positions.clear();
|
||||
BlockPayload pay = (BlockPayload)payload;
|
||||
|
||||
Geometry.circle(tileX(), tileY(), world.width(), world.height(), (int)(range / tilesize), (cx, cy) -> {
|
||||
if(Build.validPlace(team, cx, cy, pay.block, 0)){
|
||||
if(Build.validPlace(team, cx, cy, payload.block, 0)){
|
||||
positions.add(Point2.pack(cx, cy));
|
||||
}
|
||||
});
|
||||
@@ -58,7 +57,7 @@ public class BlockLauncher extends PayloadAcceptor{
|
||||
if(positions.isEmpty()) return;
|
||||
|
||||
int pick = positions.random();
|
||||
LaunchedBlock launch = new LaunchedBlock(Point2.x(pick), Point2.y(pick), pay.block, team);
|
||||
LaunchedBlock launch = new LaunchedBlock(Point2.x(pick), Point2.y(pick), payload.block, team);
|
||||
Fx.blockTransfer.at(x, y, 0, launch);
|
||||
Time.run(Fx.blockTransfer.lifetime, () -> {
|
||||
float ex = launch.x * tilesize + launch.block.offset(), ey = launch.y * tilesize + launch.block.offset();
|
||||
@@ -75,7 +74,7 @@ public class BlockLauncher extends PayloadAcceptor{
|
||||
}
|
||||
}
|
||||
|
||||
public class LaunchedBlock{
|
||||
public static class LaunchedBlock{
|
||||
public final int x, y;
|
||||
public final Block block;
|
||||
public final Team team;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ArmoredConduit extends Conduit{
|
||||
Tilec next = tile.front();
|
||||
if(next != null && next.team() == team && next.block().hasLiquids) return;
|
||||
|
||||
Draw.rect(capRegion, x, y, tile.rotation() * 90);
|
||||
Draw.rect(capRegion, x, y, tile.rotdeg());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,13 +42,11 @@ public class Conduit extends LiquidBlock implements Autotiler{
|
||||
|
||||
Draw.color(botColor);
|
||||
Draw.alpha(0.5f);
|
||||
Draw.rect(botRegions[bits[0]], req.drawx(), req.drawy(),
|
||||
botRegions[bits[0]].getWidth() * Draw.scl * req.animScale, botRegions[bits[0]].getHeight() * Draw.scl * req.animScale,
|
||||
req.rotation * 90);
|
||||
Draw.rect(botRegions[bits[0]], req.drawx(), req.drawy(), req.rotation * 90);
|
||||
Draw.color();
|
||||
|
||||
|
||||
Draw.rect(topRegions[bits[0]], req.drawx(), req.drawy(), topRegions[bits[0]].getWidth() * Draw.scl * req.animScale, topRegions[bits[0]].getHeight() * Draw.scl * req.animScale, req.rotation * 90);
|
||||
Draw.rect(topRegions[bits[0]], req.drawx(), req.drawy(), req.rotation * 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,7 +80,7 @@ public class Conduit extends LiquidBlock implements Autotiler{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
int rotation = rotation() * 90;
|
||||
float rotation = rotdeg();
|
||||
|
||||
Draw.color(botColor);
|
||||
Draw.rect(botRegions[blendbits], x, y, rotation);
|
||||
|
||||
@@ -29,7 +29,7 @@ public class LiquidBlock extends Block{
|
||||
public class LiquidBlockEntity extends TileEntity{
|
||||
@Override
|
||||
public void draw(){
|
||||
int rotation = rotate ? rotation() * 90 : 0;
|
||||
float rotation = rotate ? rotdeg() : 0;
|
||||
Draw.rect(bottomRegion, x, y, rotation);
|
||||
|
||||
if(liquids.total() > 0.001f){
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.world.blocks.payloads;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import mindustry.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
@@ -14,6 +15,9 @@ public class UnitPayload implements Payload{
|
||||
|
||||
@Override
|
||||
public boolean dump(float x, float y, float rotation){
|
||||
//no client dumping
|
||||
if(Vars.net.client()) return true;
|
||||
|
||||
unit.set(x, y);
|
||||
unit.rotation(rotation);
|
||||
unit.add();
|
||||
@@ -23,8 +27,8 @@ public class UnitPayload implements Payload{
|
||||
|
||||
@Override
|
||||
public void draw(float x, float y, float rotation){
|
||||
Drawf.shadow(x, y, 24);
|
||||
Draw.rect("pneumatic-drill", x, y, rotation);
|
||||
// Drawf.shadow(x, y, 24);
|
||||
//Draw.rect("pneumatic-drill", x, y, rotation);
|
||||
Drawf.shadow(x, y, 20);
|
||||
Draw.rect(unit.type().icon(Cicon.full), x, y, rotation - 90);
|
||||
}
|
||||
|
||||
@@ -32,16 +32,9 @@ public class PowerDiode extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list) {
|
||||
TextureRegion reg = icon(Cicon.full);
|
||||
Draw.rect(icon(Cicon.full), req.drawx(), req.drawy(),
|
||||
reg.getWidth() * req.animScale * Draw.scl,
|
||||
reg.getHeight() * req.animScale * Draw.scl,
|
||||
0);
|
||||
Draw.rect(arrow, req.drawx(), req.drawy(),
|
||||
arrow.getWidth() * req.animScale * Draw.scl,
|
||||
arrow.getHeight() * req.animScale * Draw.scl,
|
||||
!rotate ? 0 : req.rotation * 90);
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list){
|
||||
Draw.rect(icon(Cicon.full), req.drawx(), req.drawy());
|
||||
Draw.rect(arrow, req.drawx(), req.drawy(), !rotate ? 0 : req.rotation * 90);
|
||||
}
|
||||
|
||||
// battery % of the graph on either side, defaults to zero
|
||||
@@ -53,7 +46,7 @@ public class PowerDiode extends Block{
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.rect(region, x, y, 0);
|
||||
Draw.rect(arrow, x, y, rotate ? tile.rotation() * 90 : 0);
|
||||
Draw.rect(arrow, x, y, rotate ? tile.rotdeg() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -266,7 +266,7 @@ public class PowerNode extends PowerBlock{
|
||||
public void placed(){
|
||||
if(net.client()) return;
|
||||
|
||||
Boolf<Tilec> valid = other -> other != null && other != tile && ((!other.block().outputsPower && other.block().consumesPower) ||
|
||||
Boolf<Tilec> valid = other -> other != null && other != this && ((!other.block().outputsPower && other.block().consumesPower) ||
|
||||
(other.block().outputsPower && !other.block().consumesPower) || other.block() instanceof PowerNode) && linkValid(this, other)
|
||||
&& !other.proximity().contains(this) && other.power().graph != power.graph;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package mindustry.world.blocks.production;
|
||||
import arc.func.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
|
||||
@@ -12,6 +12,7 @@ import mindustry.world.blocks.payloads.*;
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
public class PayloadAcceptor extends Block{
|
||||
public float payloadSpeed = 0.5f;
|
||||
|
||||
public PayloadAcceptor(String name){
|
||||
super(name);
|
||||
@@ -19,10 +20,20 @@ public class PayloadAcceptor extends Block{
|
||||
update = true;
|
||||
}
|
||||
|
||||
public class PayloadAcceptorEntity extends TileEntity{
|
||||
public @Nullable Payload payload;
|
||||
public Vec2 inputVector = new Vec2();
|
||||
public float inputRotation;
|
||||
public static boolean blends(Tilec tile, int direction){
|
||||
int size = tile.block().size;
|
||||
Tilec accept = tile.nearby(Geometry.d4(direction).x * size, Geometry.d4(direction).y * size);
|
||||
return accept != null &&
|
||||
accept.block().size == size &&
|
||||
accept.block().outputsPayload &&
|
||||
//block must either be facing this one, or not be rotating
|
||||
((accept.tileX() + Geometry.d4(accept.rotation()).x * size == tile.tileX() && accept.tileY() + Geometry.d4(accept.rotation()).y * size == tile.tileY()) || !accept.block().rotate);
|
||||
}
|
||||
|
||||
public class PayloadAcceptorEntity<T extends Payload> extends TileEntity{
|
||||
public @Nullable T payload;
|
||||
public Vec2 payVector = new Vec2();
|
||||
public float payRotation;
|
||||
|
||||
@Override
|
||||
public boolean acceptPayload(Tilec source, Payload payload){
|
||||
@@ -31,25 +42,29 @@ public class PayloadAcceptor extends Block{
|
||||
|
||||
@Override
|
||||
public void handlePayload(Tilec source, Payload payload){
|
||||
this.payload = payload;
|
||||
this.inputVector.set(source).sub(this).clamp(-size * tilesize / 2f, size * tilesize / 2f, -size * tilesize / 2f, size * tilesize / 2f);
|
||||
this.inputRotation = source.angleTo(this);
|
||||
this.payload = (T)payload;
|
||||
this.payVector.set(source).sub(this).clamp(-size * tilesize / 2f, size * tilesize / 2f, -size * tilesize / 2f, size * tilesize / 2f);
|
||||
this.payRotation = source.angleTo(this);
|
||||
}
|
||||
|
||||
/** @return true if the payload is in position. */
|
||||
public boolean updatePayload(){
|
||||
public boolean moveInPayload(){
|
||||
if(payload == null) return false;
|
||||
|
||||
inputRotation = Mathf.slerpDelta(inputRotation, 90f, 0.3f);
|
||||
inputVector.lerpDelta(Vec2.ZERO, 0.2f);
|
||||
payRotation = Mathf.slerpDelta(payRotation, rotate ? rotdeg() : 90f, 0.3f);
|
||||
payVector.approachDelta(Vec2.ZERO, payloadSpeed);
|
||||
|
||||
return inputVector.isZero(0.5f);
|
||||
return hasArrived();
|
||||
}
|
||||
|
||||
public boolean hasArrived(){
|
||||
return payVector.isZero(0.01f);
|
||||
}
|
||||
|
||||
public void drawPayload(){
|
||||
if(payload != null){
|
||||
Draw.z(Layer.blockOver);
|
||||
payload.draw(x + inputVector.x, y + inputVector.y, inputRotation);
|
||||
payload.draw(x + payVector.x, y + payVector.y, payRotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,13 @@ import arc.scene.ui.layout.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public class LiquidSource extends Block{
|
||||
|
||||
@@ -39,7 +38,7 @@ public class LiquidSource extends Block{
|
||||
|
||||
@Override
|
||||
public void drawRequestConfig(BuildRequest req, Eachable<BuildRequest> list){
|
||||
drawRequestConfigCenter(req, (Content)req.config, "center");
|
||||
drawRequestConfigCenter(req, req.config, "center");
|
||||
}
|
||||
|
||||
public class LiquidSourceEntity extends TileEntity{
|
||||
|
||||
@@ -216,7 +216,7 @@ public class CoreBlock extends StorageBlock{
|
||||
|
||||
if(heat > 0.001f){
|
||||
Draw.draw(Layer.blockOver, () -> {
|
||||
Drawf.drawRespawn(this, heat, progress, time, unitType, lastRequested);
|
||||
Drawf.respawn(this, heat, progress, time, unitType, lastRequested);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class Unloader extends Block{
|
||||
|
||||
@Override
|
||||
public void drawRequestConfig(BuildRequest req, Eachable<BuildRequest> list){
|
||||
drawRequestConfigCenter(req, (Item)req.config, "unloader-center");
|
||||
drawRequestConfigCenter(req, req.config, "unloader-center");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,21 +1,122 @@
|
||||
package mindustry.world.blocks.units;
|
||||
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.blocks.payloads.*;
|
||||
import mindustry.world.consumers.*;
|
||||
|
||||
public class Reconstructor extends Block{
|
||||
import static mindustry.Vars.state;
|
||||
|
||||
public class Reconstructor extends UnitBlock{
|
||||
public @Load(value = "@-top", fallback = "factory-top") TextureRegion topRegion;
|
||||
public @Load(value = "@-out", fallback = "factory-out") TextureRegion outRegion;
|
||||
public @Load(value = "@-in", fallback = "factory-in") TextureRegion inRegion;
|
||||
public int tier = 1;
|
||||
public float constructTime = 60 * 2;
|
||||
|
||||
public Reconstructor(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
public class ReassemblerEntity extends TileEntity{
|
||||
public @Nullable Unitc unit;
|
||||
@Override
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list){
|
||||
Draw.rect(region, req.drawx(), req.drawy());
|
||||
Draw.rect(outRegion, req.drawx(), req.drawy(), req.rotation * 90);
|
||||
Draw.rect(topRegion, req.drawx(), req.drawy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
bars.add("progress", entity -> new Bar("bar.progress", Pal.ammo, ((ReconstructorEntity)entity)::fraction));
|
||||
}
|
||||
|
||||
public class ReconstructorEntity extends UnitBlockEntity{
|
||||
|
||||
public float fraction(){
|
||||
return progress / constructTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptPayload(Tilec source, Payload payload){
|
||||
return this.payload == null
|
||||
&& relativeTo(source) != rotation()
|
||||
&& payload instanceof UnitPayload
|
||||
&& ((UnitPayload)payload).unit.type().upgrade != null
|
||||
&& ((UnitPayload)payload).unit.type().tier == tier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.rect(region, x, y);
|
||||
|
||||
//draw input
|
||||
for(int i = 0; i < 4; i++){
|
||||
if(blends(this, i) && i != rotation()){
|
||||
Draw.rect(inRegion, x, y, i * 90);
|
||||
}
|
||||
}
|
||||
|
||||
Draw.rect(outRegion, x, y, rotdeg());
|
||||
|
||||
if(constructing() && hasArrived()){
|
||||
Draw.draw(Layer.blockOver, () -> {
|
||||
Draw.alpha(1f - progress/ constructTime);
|
||||
Draw.rect(payload.unit.type().icon(Cicon.full), x, y, rotdeg() - 90);
|
||||
Draw.reset();
|
||||
Drawf.construct(this, payload.unit.type().upgrade, rotdeg() - 90f, progress / constructTime, speedScl, time);
|
||||
});
|
||||
}else{
|
||||
Draw.z(Layer.blockOver);
|
||||
payRotation = rotdeg();
|
||||
|
||||
drawPayload();
|
||||
}
|
||||
|
||||
Draw.z(Layer.blockOver + 0.1f);
|
||||
Draw.rect(topRegion, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
boolean valid = false;
|
||||
|
||||
if(payload != null){
|
||||
//check if offloading
|
||||
if(payload.unit.type().upgrade == null || payload.unit.type().tier != tier){
|
||||
outputPayload();
|
||||
}else{ //update progress
|
||||
if(moveInPayload()){
|
||||
if(consValid()){
|
||||
valid = true;
|
||||
progress += edelta();
|
||||
}
|
||||
|
||||
//upgrade the unit
|
||||
if(progress >= constructTime){
|
||||
payload.unit = payload.unit.type().upgrade.create(payload.unit.team());
|
||||
progress = 0;
|
||||
Fx.unitSpawn.at(this);
|
||||
consume();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
speedScl = Mathf.lerpDelta(speedScl, Mathf.num(valid), 0.05f);
|
||||
time += edelta() * speedScl * state.rules.unitBuildSpeedMultiplier;
|
||||
}
|
||||
|
||||
public boolean constructing(){
|
||||
return payload != null && payload.unit.type().upgrade != null && payload.unit.type().tier == tier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
75
core/src/mindustry/world/blocks/units/UnitBlock.java
Normal file
75
core/src/mindustry/world/blocks/units/UnitBlock.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package mindustry.world.blocks.units;
|
||||
|
||||
import arc.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.payloads.*;
|
||||
import mindustry.world.blocks.production.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class UnitBlock extends PayloadAcceptor{
|
||||
|
||||
public UnitBlock(String name){
|
||||
super(name);
|
||||
|
||||
outputsPayload = true;
|
||||
rotate = true;
|
||||
update = true;
|
||||
solid = true;
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void onUnitBlockSpawn(Tile tile){
|
||||
if(!(tile.entity instanceof UnitBlockEntity)) return;
|
||||
tile.<UnitBlockEntity>ent().spawned();
|
||||
}
|
||||
|
||||
|
||||
public class UnitBlockEntity extends PayloadAcceptorEntity<UnitPayload>{
|
||||
public float progress, payloadPos, time, speedScl;
|
||||
|
||||
public void spawned(){
|
||||
progress = 0f;
|
||||
|
||||
if(!net.client() && payload != null){
|
||||
Unitc unit = payload.unit;
|
||||
unit.set(x, y);
|
||||
unit.rotation(rotdeg());
|
||||
unit.vel().trns(rotdeg(), payloadSpeed * 2f).add(Mathf.range(0.1f), Mathf.range(0.1f));
|
||||
unit.trns(Tmp.v1.trns(rotdeg(), size * tilesize/2f));
|
||||
unit.trns(unit.vel());
|
||||
unit.add();
|
||||
Events.fire(new UnitCreateEvent(unit));
|
||||
}
|
||||
|
||||
payload = null;
|
||||
}
|
||||
|
||||
public void outputPayload(){
|
||||
if(payload == null) return;
|
||||
|
||||
payloadPos += edelta() * payloadSpeed;
|
||||
payVector.trns(rotdeg(), payloadPos);
|
||||
payRotation = rotdeg();
|
||||
|
||||
if(payloadPos >= size * tilesize/2f){
|
||||
payloadPos = size * tilesize/2f;
|
||||
|
||||
Tile front = frontLarge();
|
||||
if(front != null && front.entity != null && front.block().outputsPayload){
|
||||
if(movePayload(payload)){
|
||||
payload = null;
|
||||
}
|
||||
}else if(front != null && !front.solid()){
|
||||
//create unit if there's space
|
||||
Call.onUnitBlockSpawn(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,28 +7,22 @@ import arc.math.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.blocks.payloads.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class UnitFactory extends Block{
|
||||
public float payloadSpeed = 0.5f;
|
||||
public class UnitFactory extends UnitBlock{
|
||||
public @Load(value = "@-top", fallback = "factory-top") TextureRegion topRegion;
|
||||
public @Load(value = "@-out", fallback = "factory-out") TextureRegion outRegion;
|
||||
public int[] capacities;
|
||||
@@ -63,12 +57,6 @@ public class UnitFactory extends Block{
|
||||
}));
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void onUnitFactorySpawn(Tile tile){
|
||||
if(!(tile.entity instanceof UnitFactoryEntity)) return;
|
||||
tile.<UnitFactoryEntity>ent().spawned();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
@@ -106,9 +94,9 @@ public class UnitFactory extends Block{
|
||||
|
||||
@Override
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list){
|
||||
Draw.rect(region, req.drawx(), req.drawy(), region.getWidth() * req.animScale * Draw.scl, region.getHeight() * req.animScale * Draw.scl);
|
||||
Draw.rect(outRegion, req.drawx(), req.drawy(), outRegion.getWidth() * req.animScale * Draw.scl, outRegion.getHeight() * req.animScale * Draw.scl, req.rotation * 90);
|
||||
Draw.rect(topRegion, req.drawx(), req.drawy(), outRegion.getWidth() * req.animScale * Draw.scl, outRegion.getHeight() * req.animScale * Draw.scl);
|
||||
Draw.rect(region, req.drawx(), req.drawy());
|
||||
Draw.rect(outRegion, req.drawx(), req.drawy(), req.rotation * 90);
|
||||
Draw.rect(topRegion, req.drawx(), req.drawy());
|
||||
}
|
||||
|
||||
public static class UnitPlan{
|
||||
@@ -125,10 +113,8 @@ public class UnitFactory extends Block{
|
||||
UnitPlan(){}
|
||||
}
|
||||
|
||||
public class UnitFactoryEntity extends TileEntity{
|
||||
public class UnitFactoryEntity extends UnitBlockEntity{
|
||||
public int currentPlan = -1;
|
||||
public float progress, time, speedScl, payloadPos;
|
||||
public @Nullable UnitPayload payload;
|
||||
|
||||
public float fraction(){
|
||||
return currentPlan == -1 ? 0 : progress / plans[currentPlan].time;
|
||||
@@ -141,6 +127,11 @@ public class UnitFactory extends Block{
|
||||
ItemSelection.buildTable(table, units, () -> currentPlan == -1 ? null : plans[currentPlan].unit, unit -> configure(units.indexOf(unit)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptPayload(Tilec source, Payload payload){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
super.display(table);
|
||||
@@ -166,96 +157,38 @@ public class UnitFactory extends Block{
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.rect(region, x, y);
|
||||
Draw.rect(outRegion, x, y, rotation() * 90);
|
||||
Draw.rect(outRegion, x, y, rotdeg());
|
||||
|
||||
if(currentPlan != -1){
|
||||
UnitPlan plan = plans[currentPlan];
|
||||
|
||||
Draw.draw(Layer.blockOver, () -> {
|
||||
TextureRegion region = plan.unit.icon(Cicon.full);
|
||||
|
||||
Shaders.build.region = region;
|
||||
Shaders.build.progress = progress / plan.time;
|
||||
Shaders.build.color.set(Pal.accent);
|
||||
Shaders.build.color.a = speedScl;
|
||||
Shaders.build.time = -time / 20f;
|
||||
|
||||
Draw.shader(Shaders.build);
|
||||
Draw.rect(region, x, y, rotation() * 90 - 90);
|
||||
Draw.shader();
|
||||
|
||||
Draw.color(Pal.accent);
|
||||
Draw.alpha(speedScl);
|
||||
|
||||
Lines.lineAngleCenter(x + Mathf.sin(time, 20f, Vars.tilesize / 2f * size - 2f), y, 90, size * Vars.tilesize - 4f);
|
||||
|
||||
Draw.reset();
|
||||
});
|
||||
Draw.draw(Layer.blockOver, () -> Drawf.construct(this, plan.unit, rotdeg() - 90f, progress / plan.time, speedScl, time));
|
||||
}
|
||||
|
||||
Draw.z(Layer.blockOver);
|
||||
|
||||
if(payload != null){
|
||||
payload.draw(
|
||||
x + Angles.trnsx(rotation() * 90, payloadPos),
|
||||
y + Angles.trnsy(rotation() * 90, payloadPos),
|
||||
rotation() * 90
|
||||
);
|
||||
}
|
||||
payRotation = rotdeg();
|
||||
drawPayload();
|
||||
|
||||
Draw.z(Layer.blockOver + 0.1f);
|
||||
|
||||
Draw.rect(topRegion, x, y);
|
||||
}
|
||||
|
||||
public void spawned(){
|
||||
progress = 0f;
|
||||
|
||||
if(!net.client() && payload != null){
|
||||
Unitc unit = payload.unit;
|
||||
unit.set(x, y);
|
||||
|
||||
unit.rotation(rotation() * 90);
|
||||
unit.vel().trns(rotation() * 90, payloadSpeed * 2f).add(Mathf.range(0.1f), Mathf.range(0.1f));
|
||||
unit.trns(Tmp.v1.trns(rotation() * 90, size * tilesize/2f));
|
||||
unit.trns(unit.vel());
|
||||
unit.add();
|
||||
Events.fire(new UnitCreateEvent(unit));
|
||||
}
|
||||
|
||||
payload = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
if(currentPlan < 0 || currentPlan >= plans.length){
|
||||
currentPlan = -1;
|
||||
}
|
||||
|
||||
if((consValid() || tile.isEnemyCheat()) && currentPlan != -1){
|
||||
time += delta() * efficiency() * speedScl * Vars.state.rules.unitBuildSpeedMultiplier;
|
||||
progress += delta() * efficiency() * Vars.state.rules.unitBuildSpeedMultiplier;
|
||||
if(consValid() && currentPlan != -1){
|
||||
time += edelta() * speedScl * Vars.state.rules.unitBuildSpeedMultiplier;
|
||||
progress += edelta() * Vars.state.rules.unitBuildSpeedMultiplier;
|
||||
speedScl = Mathf.lerpDelta(speedScl, 1f, 0.05f);
|
||||
}else{
|
||||
speedScl = Mathf.lerpDelta(speedScl, 0f, 0.05f);
|
||||
}
|
||||
|
||||
if(payload != null){
|
||||
payloadPos += edelta() * payloadSpeed;
|
||||
if(payloadPos >= size * tilesize/2f){
|
||||
payloadPos = size * tilesize/2f;
|
||||
|
||||
Tile front = frontLarge();
|
||||
if(front != null && front.entity != null && front.block().outputsPayload){
|
||||
if(movePayload(payload)){
|
||||
payload = null;
|
||||
}
|
||||
}else if(front != null && !front.solid()){
|
||||
//create unit
|
||||
Call.onUnitFactorySpawn(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
outputPayload();
|
||||
|
||||
if(currentPlan != -1 && payload == null){
|
||||
UnitPlan plan = plans[currentPlan];
|
||||
|
||||
@@ -7,7 +7,6 @@ import arc.util.ArcAnnotate.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.Cicon;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.world.meta.values.*;
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import arc.util.ArcAnnotate.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.Cicon;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.world.meta.values.*;
|
||||
|
||||
@@ -19,7 +18,7 @@ public class ConsumeItems extends Consume{
|
||||
|
||||
/** Mods.*/
|
||||
protected ConsumeItems(){
|
||||
this(new ItemStack[]{});
|
||||
this(ItemStack.empty);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,6 @@ import arc.util.ArcAnnotate.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.Cicon;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
public class ConsumeLiquid extends ConsumeLiquidBase{
|
||||
|
||||
@@ -57,9 +57,7 @@ public class LiquidModule extends BlockModule{
|
||||
}
|
||||
|
||||
public void reset(Liquid liquid, float amount){
|
||||
for(int i = 0; i < liquids.length; i++){
|
||||
liquids[i] = 0f;
|
||||
}
|
||||
Arrays.fill(liquids, 0f);
|
||||
liquids[liquid.id] = amount;
|
||||
total = amount;
|
||||
current = liquid;
|
||||
|
||||
Reference in New Issue
Block a user