Fixed most errors in block package

This commit is contained in:
Anuken
2020-03-06 14:41:38 -05:00
parent 4744465986
commit 73c0ebb75f
32 changed files with 1269 additions and 1523 deletions

View File

@@ -10,7 +10,6 @@ uniform vec3 u_ambientColor;
varying vec4 v_col; varying vec4 v_col;
const vec3 ambientColor = vec3(1.0); const vec3 ambientColor = vec3(1.0);
const vec3 ambientDir = normalize(vec3(1.0, 1.0, 1.0));
const vec3 diffuse = vec3(0.2); const vec3 diffuse = vec3(0.2);
const vec3 v1 = vec3(1.0, 0.0, 1.0); const vec3 v1 = vec3(1.0, 0.0, 1.0);
const vec3 v2 = vec3(1.0, 0.5, 0.0); const vec3 v2 = vec3(1.0, 0.5, 0.0);

View File

@@ -409,6 +409,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc{
public void offloadNear(Item item){ public void offloadNear(Item item){
Array<Tilec> proximity = proximity(); Array<Tilec> proximity = proximity();
int dump = rotation(); int dump = rotation();
useContent(item);
for(int i = 0; i < proximity.size; i++){ for(int i = 0; i < proximity.size; i++){
incrementDump(proximity.size); incrementDump(proximity.size);
@@ -544,8 +545,8 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc{
return out; return out;
} }
public float getProgressIncrease(Tilec entity, float baseTime){ public float getProgressIncrease(float baseTime){
return 1f / baseTime * entity.delta() * entity.efficiency(); return 1f / baseTime * delta() * efficiency();
} }
/** @return whether this block should play its active sound.*/ /** @return whether this block should play its active sound.*/
@@ -654,16 +655,6 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc{
} }
} }
public float percentSolid(int x, int y){
Tile tile = world.tile(x, y);
if(tile == null) return 0;
float sum = 0;
for(Tile other : tile.getLinkedTilesAs(block, tempTiles)){
sum += !other.floor().isLiquid ? 1f : 0f;
}
return sum / block.size / block.size;
}
/** Called when arbitrary configuration is applied to a tile. */ /** Called when arbitrary configuration is applied to a tile. */
public void configured(@Nullable Playerc player, @Nullable Object value){ public void configured(@Nullable Playerc player, @Nullable Object value){
//null is of type Void.class; anonymous classes use their superclass. //null is of type Void.class; anonymous classes use their superclass.

View File

@@ -51,10 +51,10 @@ public class EventType{
public static class MapPublishEvent{} public static class MapPublishEvent{}
public static class CommandIssueEvent{ public static class CommandIssueEvent{
public final Tile tile; public final Tilec tile;
public final UnitCommand command; public final UnitCommand command;
public CommandIssueEvent(Tile tile, UnitCommand command){ public CommandIssueEvent(Tilec tile, UnitCommand command){
this.tile = tile; this.tile = tile;
this.command = command; this.command = command;
} }

View File

@@ -168,6 +168,7 @@ public class Block extends UnlockableContent{
//TODO move //TODO move
public static TextureRegion[][] cracks; public static TextureRegion[][] cracks;
protected static final Array<Tile> tempTiles = new Array<>(); protected static final Array<Tile> tempTiles = new Array<>();
protected static final Array<Tilec> tempTileEnts = new Array<>();
/** Dump timer ID.*/ /** Dump timer ID.*/
protected final int timerDump = timers++; protected final int timerDump = timers++;
@@ -189,6 +190,16 @@ public class Block extends UnlockableContent{
} }
} }
public float percentSolid(int x, int y){
Tile tile = world.tile(x, y);
if(tile == null) return 0;
float sum = 0;
for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){
sum += !other.floor().isLiquid ? 1f : 0f;
}
return sum / size / size;
}
public void drawLayer(Tile tile){ public void drawLayer(Tile tile){
if(tile.entity != null) tile.entity.drawLayer(); if(tile.entity != null) tile.entity.drawLayer();
} }

View File

@@ -37,7 +37,7 @@ public interface Autotiler{
return buildBlending(req.tile(), req.rotation, directionals, req.worldContext); return buildBlending(req.tile(), req.rotation, directionals, req.worldContext);
} }
default int[] buildBlending(int rotation, BuildRequest[] directional, boolean world){ default int[] buildBlending(Tile tile, int rotation, BuildRequest[] directional, boolean world){
int[] blendresult = AutotilerHolder.blendresult; int[] blendresult = AutotilerHolder.blendresult;
blendresult[0] = 0; blendresult[0] = 0;
blendresult[1] = blendresult[2] = 1; blendresult[1] = blendresult[2] = 1;
@@ -71,7 +71,7 @@ public interface Autotiler{
} }
} }
default boolean blends(int rotation, @Nullable BuildRequest[] directional, int direction, boolean checkWorld){ default boolean blends(Tile tile, int rotation, @Nullable BuildRequest[] directional, int direction, boolean checkWorld){
int realDir = Mathf.mod(rotation - direction, 4); int realDir = Mathf.mod(rotation - direction, 4);
if(directional != null && directional[realDir] != null){ if(directional != null && directional[realDir] != null){
BuildRequest req = directional[realDir]; BuildRequest req = directional[realDir];
@@ -82,21 +82,21 @@ public interface Autotiler{
return checkWorld && blends(tile, rotation, direction); return checkWorld && blends(tile, rotation, direction);
} }
default boolean blends(int rotation, int direction){ default boolean blends(Tile tile, int rotation, int direction){
Tilec other = tile.getNearbyEntity(Mathf.mod(rotation - direction, 4)); Tilec other = tile.getNearbyEntity(Mathf.mod(rotation - direction, 4));
return other != null && other.team() == team && blends(tile, rotation, other.tileX(), other.tileY(), other.rotation(), other.block()); return other != null && other.team() == tile.team() && blends(tile, rotation, other.tileX(), other.tileY(), other.rotation(), other.block());
} }
default boolean blendsArmored(int rotation, int otherx, int othery, int otherrot, Block otherblock){ default boolean blendsArmored(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
return (Point2.equals(tile.x + Geometry.d4(rotation).x, tile.y + Geometry.d4(rotation).y, otherx, othery) return (Point2.equals(tile.x + Geometry.d4(rotation).x, tile.y + Geometry.d4(rotation).y, otherx, othery)
|| ((!otherblock.rotate && Edges.getFacingEdge(otherblock, otherx, othery, tile) != null && || ((!otherblock.rotate && Edges.getFacingEdge(otherblock, otherx, othery, tile) != null &&
Edges.getFacingEdge(otherblock, otherx, othery, tile).relativeTo(tile) == rotation) || (otherblock.rotate && Point2.equals(otherx + Geometry.d4(otherrot).x, othery + Geometry.d4(otherrot).y, tile.x, tile.y)))); Edges.getFacingEdge(otherblock, otherx, othery, tile).relativeTo(tile) == rotation) || (otherblock.rotate && Point2.equals(otherx + Geometry.d4(otherrot).x, othery + Geometry.d4(otherrot).y, tile.x, tile.y))));
} }
default boolean lookingAt(int rotation, int otherx, int othery, int otherrot, Block otherblock){ default boolean lookingAt(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
return (Point2.equals(tile.x + Geometry.d4(rotation).x, tile.y + Geometry.d4(rotation).y, otherx, othery) return (Point2.equals(tile.x + Geometry.d4(rotation).x, tile.y + Geometry.d4(rotation).y, otherx, othery)
|| (!otherblock.rotate || Point2.equals(otherx + Geometry.d4(otherrot).x, othery + Geometry.d4(otherrot).y, tile.x, tile.y))); || (!otherblock.rotate || Point2.equals(otherx + Geometry.d4(otherrot).x, othery + Geometry.d4(otherrot).y, tile.x, tile.y)));
} }
boolean blends(int rotation, int otherx, int othery, int otherrot, Block otherblock); boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock);
} }

View File

@@ -49,27 +49,27 @@ public class BuildBlock extends Block{
} }
@Remote(called = Loc.server) @Remote(called = Loc.server)
public static void onDeconstructFinish(Block block, int builderID){ public static void onDeconstructFinish(Tile tile, Block block, int builderID){
Team team = team; Team team = tile.team();
Fx.breakBlock.at(x, y, block.size); Fx.breakBlock.at(tile.drawx(), tile.drawy(), block.size);
Events.fire(new BlockBuildEndEvent(tile, Groups.unit.getByID(builderID), team, true)); Events.fire(new BlockBuildEndEvent(tile, Groups.unit.getByID(builderID), team, true));
tile.remove(); tile.remove();
if(shouldPlay()) Sounds.breaks.at(tile, calcPitch(false)); if(shouldPlay()) Sounds.breaks.at(tile, calcPitch(false));
} }
@Remote(called = Loc.server) @Remote(called = Loc.server)
public static void onConstructFinish(Block block, int builderID, byte rotation, Team team, boolean skipConfig){ public static void onConstructFinish(Tile tile, Block block, int builderID, byte rotation, Team team, boolean skipConfig){
if(tile == null) return; if(tile == null) return;
float healthf = tile.healthf(); float healthf = tile.entity.healthf();
tile.setBlock(block, team, (int)rotation); tile.setBlock(block, team, (int)rotation);
tile.health(block.health * healthf); tile.entity.health(block.health * healthf);
//last builder was this local client player, call placed() //last builder was this local client player, call placed()
if(!headless && builderID == player.unit().id()){ if(!headless && builderID == player.unit().id()){
if(!skipConfig){ if(!skipConfig){
tile.playerPlaced(); tile.entity.playerPlaced();
} }
} }
Fx.placeBlock.at(x, y, block.size); Fx.placeBlock.at(tile.drawx(), tile.drawy(), block.size);
} }
static boolean shouldPlay(){ static boolean shouldPlay(){
@@ -96,9 +96,9 @@ public class BuildBlock extends Block{
} }
} }
public static void constructed(Block block, int builderID, byte rotation, Team team, boolean skipConfig){ public static void constructed(Tile tile, Block block, int builderID, byte rotation, Team team, boolean skipConfig){
Call.onConstructFinish(tile, block, builderID, rotation, team, skipConfig); Call.onConstructFinish(tile, block, builderID, rotation, team, skipConfig);
tile.placed(); tile.entity.placed();
Events.fire(new BlockBuildEndEvent(tile, Groups.unit.getByID(builderID), team, false)); Events.fire(new BlockBuildEndEvent(tile, Groups.unit.getByID(builderID), team, false));
if(shouldPlay()) Sounds.place.at(tile, calcPitch(true)); if(shouldPlay()) Sounds.place.at(tile, calcPitch(true));

View File

@@ -11,8 +11,8 @@ public class ArmoredConveyor extends Conveyor{
} }
@Override @Override
public boolean blends(int rotation, int otherx, int othery, int otherrot, Block otherblock) { public boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock) {
return otherblock.outputsItems() && blendsArmored(rotation, otherx, othery, otherrot, otherblock); return otherblock.outputsItems() && blendsArmored(tile, rotation, otherx, othery, otherrot, otherblock);
} }
public class ArmoredConveyorEntity extends ConveyorEntity{ public class ArmoredConveyorEntity extends ConveyorEntity{

View File

@@ -76,8 +76,8 @@ public class Conveyor extends Block implements Autotiler{
} }
@Override @Override
public boolean blends(int rotation, int otherx, int othery, int otherrot, Block otherblock){ public boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
return otherblock.outputsItems() && lookingAt(rotation, otherx, othery, otherrot, otherblock); return otherblock.outputsItems() && lookingAt(tile, rotation, otherx, othery, otherrot, otherblock);
} }
@Override @Override
@@ -138,7 +138,7 @@ public class Conveyor extends Block implements Autotiler{
public void onProximityUpdate(){ public void onProximityUpdate(){
super.onProximityUpdate(); super.onProximityUpdate();
int[] bits = buildBlending(rotation(), null, true); int[] bits = buildBlending(tile, rotation(), null, true);
blendbits = bits[0]; blendbits = bits[0];
blendsclx = bits[1]; blendsclx = bits[1];
blendscly = bits[2]; blendscly = bits[2];

View File

@@ -41,8 +41,8 @@ public class MassDriver extends Block{
hasPower = true; hasPower = true;
outlineIcon = true; outlineIcon = true;
//point2 is relative //point2 is relative
config(Point2.class, (tile, point) -> tile.<MassDriverEntity>ent().link = Point2.pack(point.x + tile.x, point.y + tile.y)); config(Point2.class, (tile, point) -> ((MassDriverEntity)tile).link = Point2.pack(point.x + tile.tileX(), point.y + tile.tileY()));
config(Integer.class, (tile, point) -> tile.<MassDriverEntity>ent().link = point); config(Integer.class, (tile, point) -> ((MassDriverEntity)tile).link = point);
} }
@Override @Override
@@ -57,10 +57,55 @@ public class MassDriver extends Block{
baseRegion = Core.atlas.find(name + "-base"); baseRegion = Core.atlas.find(name + "-base");
} }
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.dashCircle(x * tilesize, y*tilesize, range, Pal.accent);
//check if a mass driver is selected while placing this driver
if(!control.input.frag.config.isShown()) return;
Tilec selected = control.input.frag.config.getSelectedTile();
if(selected == null || !(selected.block() instanceof MassDriver) || !(selected.dst(x * tilesize, y * tilesize) <= range)) return;
//if so, draw a dotted line towards it while it is in range
float sin = Mathf.absin(Time.time(), 6f, 1f);
Tmp.v1.set(x * tilesize + offset(), y * tilesize + offset()).sub(selected.x(), selected.y()).limit((size / 2f + 1) * tilesize + sin + 0.5f);
float x2 = x * tilesize - Tmp.v1.x, y2 = y * tilesize - Tmp.v1.y,
x1 = selected.x() + Tmp.v1.x, y1 = selected.y() + Tmp.v1.y;
int segs = (int)(selected.dst(x * tilesize, y * tilesize) / tilesize);
Lines.stroke(4f, Pal.gray);
Lines.dashLine(x1, y1, x2, y2, segs);
Lines.stroke(2f, Pal.placing);
Lines.dashLine(x1, y1, x2, y2, segs);
Draw.reset();
}
public class DriverBulletData implements Poolable{
public MassDriverEntity from, to;
public int[] items = new int[content.items().size];
@Override
public void reset(){
from = null;
to = null;
}
}
public class MassDriverEntity extends TileEntity{
int link = -1;
float rotation = 90;
float reload = 0f;
DriverState state = DriverState.idle;
OrderedSet<Tile> waitingShooters = new OrderedSet<>();
Tile currentShooter(){
return waitingShooters.isEmpty() ? null : waitingShooters.first();
}
@Override @Override
public void updateTile(){ public void updateTile(){
Tile link = world.tile(link); Tilec link = world.ent(this.link);
boolean hasLink = linkValid(tile); boolean hasLink = linkValid();
//reload regardless of state //reload regardless of state
if(reload > 0f){ if(reload > 0f){
@@ -68,7 +113,7 @@ public class MassDriver extends Block{
} }
//cleanup waiting shooters that are not valid //cleanup waiting shooters that are not valid
if(!shooterValid(tile, currentShooter())){ if(!shooterValid(currentShooter())){
waitingShooters.remove(currentShooter()); waitingShooters.remove(currentShooter());
} }
@@ -84,7 +129,7 @@ public class MassDriver extends Block{
//dump when idle or accepting //dump when idle or accepting
if(state == DriverState.idle || state == DriverState.accepting){ if(state == DriverState.idle || state == DriverState.accepting){
tryDump(tile); dump();
} }
//skip when there's no power //skip when there's no power
@@ -111,10 +156,10 @@ public class MassDriver extends Block{
float targetRotation = tile.angleTo(link); float targetRotation = tile.angleTo(link);
if( if(
tile.items.total() >= minDistribute && //must shoot minimum amount of items items.total() >= minDistribute && //must shoot minimum amount of items
link.block().itemCapacity - link.items.total() >= minDistribute //must have minimum amount of space link.block().itemCapacity - link.items().total() >= minDistribute //must have minimum amount of space
){ ){
MassDriverEntity other = link.ent(); MassDriverEntity other = (MassDriverEntity)link;
other.waitingShooters.add(tile); other.waitingShooters.add(tile);
if(reload <= 0.0001f){ if(reload <= 0.0001f){
@@ -127,7 +172,7 @@ public class MassDriver extends Block{
other.state == DriverState.accepting && other.state == DriverState.accepting &&
Angles.near(rotation, targetRotation, 2f) && Angles.near(other.rotation, targetRotation + 180f, 2f)){ Angles.near(rotation, targetRotation, 2f) && Angles.near(other.rotation, targetRotation + 180f, 2f)){
//actually fire //actually fire
fire(tile, link); fire(other);
//remove waiting shooters, it's done firing //remove waiting shooters, it's done firing
other.waitingShooters.remove(tile); other.waitingShooters.remove(tile);
//set both states to idle //set both states to idle
@@ -151,29 +196,6 @@ public class MassDriver extends Block{
y + Angles.trnsy(rotation + 180f, reload * knockback), rotation - 90); y + Angles.trnsy(rotation + 180f, reload * knockback), rotation - 90);
} }
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.dashCircle(x * tilesize, y*tilesize, range, Pal.accent);
//check if a mass driver is selected while placing this driver
if(!control.input.frag.config.isShown()) return;
Tile selected = control.input.frag.config.getSelectedTile();
if(selected == null || !(selected.block() instanceof MassDriver) || !(selected.dst(x * tilesize, y * tilesize) <= range)) return;
//if so, draw a dotted line towards it while it is in range
float sin = Mathf.absin(Time.time(), 6f, 1f);
Tmp.v1.set(x * tilesize + offset(), y * tilesize + offset()).sub(selected.drawx(), selected.drawy()).limit((size / 2f + 1) * tilesize + sin + 0.5f);
float x2 = x * tilesize - Tmp.v1.x, y2 = y * tilesize - Tmp.v1.y,
x1 = selected.drawx() + Tmp.v1.x, y1 = selected.drawy() + Tmp.v1.y;
int segs = (int)(selected.dst(x * tilesize, y * tilesize) / tilesize);
Lines.stroke(4f, Pal.gray);
Lines.dashLine(x1, y1, x2, y2, segs);
Lines.stroke(2f, Pal.placing);
Lines.dashLine(x1, y1, x2, y2, segs);
Draw.reset();
}
@Override @Override
public void drawConfigure(){ public void drawConfigure(){
float sin = Mathf.absin(Time.time(), 6f, 1f); float sin = Mathf.absin(Time.time(), 6f, 1f);
@@ -187,7 +209,7 @@ public class MassDriver extends Block{
Drawf.arrow(shooter.drawx(), shooter.drawy(), x, y, size * tilesize + sin, 4f + sin, Pal.place); Drawf.arrow(shooter.drawx(), shooter.drawy(), x, y, size * tilesize + sin, 4f + sin, Pal.place);
} }
if(linkValid(tile)){ if(linkValid()){
Tile target = world.tile(link); Tile target = world.tile(link);
Drawf.circles(target.drawx(), target.drawy(), (target.block().size / 2f + 1) * tilesize + sin - 2f, Pal.place); Drawf.circles(target.drawx(), target.drawy(), (target.block().size / 2f + 1) * tilesize + sin - 2f, Pal.place);
Drawf.arrow(x, y, target.drawx(), target.drawy(), size * tilesize + sin, 4f + sin); Drawf.arrow(x, y, target.drawx(), target.drawy(), size * tilesize + sin, 4f + sin);
@@ -197,8 +219,8 @@ public class MassDriver extends Block{
} }
@Override @Override
public boolean onConfigureTileTapped(Tile other){ public boolean onConfigureTileTapped(Tilec other){
if(tile == other) return false; if(this == other) return false;
if(link == other.pos()){ if(link == other.pos()){
tile.configure(-1); tile.configure(-1);
@@ -214,18 +236,16 @@ public class MassDriver extends Block{
@Override @Override
public boolean acceptItem(Tilec source, Item item){ public boolean acceptItem(Tilec source, Item item){
//mass drivers that ouput only cannot accept items //mass drivers that ouput only cannot accept items
return tile.items.total() < itemCapacity && linkValid(tile); return items.total() < itemCapacity && linkValid();
} }
protected void fire(Tile target){ protected void fire(MassDriverEntity target){
MassDriverEntity other = target.ent();
//reset reload, use power. //reset reload, use power.
reload = 1f; reload = 1f;
DriverBulletData data = Pools.obtain(DriverBulletData.class, DriverBulletData::new); DriverBulletData data = Pools.obtain(DriverBulletData.class, DriverBulletData::new);
data.from = entity; data.from = this;
data.to = other; data.to = target;
int totalUsed = 0; int totalUsed = 0;
for(int i = 0; i < content.items().size; i++){ for(int i = 0; i < content.items().size; i++){
int maxTransfer = Math.min(items.get(content.item(i)), ((MassDriver)tile.block()).itemCapacity - totalUsed); int maxTransfer = Math.min(items.get(content.item(i)), ((MassDriver)tile.block()).itemCapacity - totalUsed);
@@ -236,7 +256,7 @@ public class MassDriver extends Block{
float angle = tile.angleTo(target); float angle = tile.angleTo(target);
Bullets.driverBolt.create(entity, team(), Bullets.driverBolt.create(this, team(),
x + Angles.trnsx(angle, translation), y + Angles.trnsy(angle, translation), x + Angles.trnsx(angle, translation), y + Angles.trnsy(angle, translation),
angle, -1f, 1f, 1f, data); angle, -1f, 1f, 1f, data);
@@ -246,10 +266,10 @@ public class MassDriver extends Block{
smokeEffect.at(x + Angles.trnsx(angle, translation), smokeEffect.at(x + Angles.trnsx(angle, translation),
y + Angles.trnsy(angle, translation), angle); y + Angles.trnsy(angle, translation), angle);
Effects.shake(shake, shake, entity); Effects.shake(shake, shake, this);
} }
protected void handlePayload(MassDriverEntity entity, Bulletc bullet, DriverBulletData data){ public void handlePayload(Bulletc bullet, DriverBulletData data){
int totalItems = items.total(); int totalItems = items.total();
//add all the items possible //add all the items possible
@@ -264,7 +284,7 @@ public class MassDriver extends Block{
} }
} }
Effects.shake(shake, shake, entity); Effects.shake(shake, shake, this);
recieveEffect.at(bullet); recieveEffect.at(bullet);
reload = 1f; reload = 1f;
@@ -281,38 +301,12 @@ public class MassDriver extends Block{
protected boolean linkValid(){ protected boolean linkValid(){
if(tile == null) return false; if(tile == null) return false;
if(entity == null || link == -1) return false; if(link == -1) return false;
Tile link = world.tile(link); Tilec link = world.ent(this.link);
return link != null && link.block() instanceof MassDriver && link.team() == team && tile.dst(link) <= range; return link != null && link.block() instanceof MassDriver && link.team() == team && tile.dst(link) <= range;
} }
public class DriverBulletData implements Poolable{
public MassDriverEntity from, to;
public int[] items = new int[content.items().size];
@Override
public void reset(){
from = null;
to = null;
}
}
public class MassDriverEntity extends TileEntity{
int link = -1;
float rotation = 90;
float reload = 0f;
DriverState state = DriverState.idle;
OrderedSet<Tile> waitingShooters = new OrderedSet<>();
Tile currentShooter(){
return waitingShooters.isEmpty() ? null : waitingShooters.first();
}
public void handlePayload(Bulletc bullet, DriverBulletData data){
((MassDriver)block()).handlePayload(this, bullet, data);
}
@Override @Override
public Point2 config(){ public Point2 config(){
return Point2.unpack(link).sub(tile.x, tile.y); return Point2.unpack(link).sub(tile.x, tile.y);

View File

@@ -21,8 +21,8 @@ public class ArmoredConduit extends Conduit{
} }
@Override @Override
public boolean blends(int rotation, int otherx, int othery, int otherrot, Block otherblock){ public boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
return otherblock.outputsLiquid && blendsArmored(rotation, otherx, othery, otherrot, otherblock); return otherblock.outputsLiquid && blendsArmored(tile, rotation, otherx, othery, otherrot, otherblock);
} }
public class ArmoredConduitEntity extends TileEntity{ public class ArmoredConduitEntity extends TileEntity{

View File

@@ -74,8 +74,8 @@ public class Conduit extends LiquidBlock implements Autotiler{
} }
@Override @Override
public boolean blends(int rotation, int otherx, int othery, int otherrot, Block otherblock){ public boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
return otherblock.hasLiquids && otherblock.outputsLiquid && lookingAt(rotation, otherx, othery, otherrot, otherblock); return otherblock.hasLiquids && otherblock.outputsLiquid && lookingAt(tile, rotation, otherx, othery, otherrot, otherblock);
} }
@Override @Override
@@ -106,7 +106,7 @@ public class Conduit extends LiquidBlock implements Autotiler{
public void onProximityUpdate(){ public void onProximityUpdate(){
super.onProximityUpdate(); super.onProximityUpdate();
blendbits = buildBlending(rotation(), null, true)[0]; blendbits = buildBlending(tile, rotation(), null, true)[0];
} }
@Override @Override

View File

@@ -128,10 +128,10 @@ public class PowerNode extends PowerBlock{
Drawf.circles(x * tilesize + offset(), y * tilesize + offset(), laserRange * tilesize); Drawf.circles(x * tilesize + offset(), y * tilesize + offset(), laserRange * tilesize);
getPotentialLinks(tile, other -> { getPotentialLinks(tile, other -> {
Drawf.square(other.drawx(), other.drawy(), other.block().size * tilesize / 2f + 2f, Pal.place); Drawf.square(other.x(), other.y(), other.block().size * tilesize / 2f + 2f, Pal.place);
insulators(tile.x, tile.y, other.x, other.y, cause -> { insulators(tile.x, tile.y, other.tileX(), other.tileY(), cause -> {
Drawf.square(cause.drawx(), cause.drawy(), cause.block().size * tilesize / 2f + 2f, Pal.plastanium); Drawf.square(cause.x(), cause.y(), cause.block().size * tilesize / 2f + 2f, Pal.plastanium);
}); });
}); });
@@ -165,6 +165,10 @@ public class PowerNode extends PowerBlock{
return Intersector.overlaps(Tmp.cr1.set(srcx, srcy, range), other.getHitbox(Tmp.r1)); return Intersector.overlaps(Tmp.cr1.set(srcx, srcy, range), other.getHitbox(Tmp.r1));
} }
protected boolean overlaps(Tilec src, Tilec other, float range){
return overlaps(src.x(), src.y(), other.tile(), range);
}
protected boolean overlaps(Tile src, Tile other, float range){ protected boolean overlaps(Tile src, Tile other, float range){
return overlaps(src.drawx(), src.drawy(), other, range); return overlaps(src.drawx(), src.drawy(), other, range);
} }
@@ -177,26 +181,26 @@ public class PowerNode extends PowerBlock{
protected void getPotentialLinks(Tile tile, Cons<Tilec> others){ protected void getPotentialLinks(Tile tile, Cons<Tilec> others){
Boolf<Tilec> valid = other -> other != null && other.tile() != tile && other.power() != null && Boolf<Tilec> valid = other -> other != null && other.tile() != tile && other.power() != null &&
((!other.block().outputsPower && other.block().consumesPower) || (other.block().outputsPower && !other.block().consumesPower) || other.block() instanceof PowerNode) && ((!other.block().outputsPower && other.block().consumesPower) || (other.block().outputsPower && !other.block().consumesPower) || other.block() instanceof PowerNode) &&
overlaps(tile.x * tilesize + offset(), tile.y * tilesize + offset(), other, laserRange * tilesize) && other.team() == player.team() overlaps(tile.x * tilesize + offset(), tile.y * tilesize + offset(), other.tile(), laserRange * tilesize) && other.team() == player.team()
&& !other.proximity().contains(tile) && !graphs.contains(other.power().graph); && !other.proximity().contains(e -> e.tile() == tile) && !graphs.contains(other.power().graph);
tempTiles.clear(); tempTileEnts.clear();
graphs.clear(); graphs.clear();
Geometry.circle(tile.x, tile.y, (int)(laserRange + 2), (x, y) -> { Geometry.circle(tile.x, tile.y, (int)(laserRange + 2), (x, y) -> {
Tile other = world.ltile(x, y); Tilec other = world.ent(x, y);
if(valid.get(other) && !tempTiles.contains(other)){ if(valid.get(other) && !tempTileEnts.contains(other)){
tempTiles.add(other); tempTileEnts.add(other);
} }
}); });
tempTiles.sort((a, b) -> { tempTileEnts.sort((a, b) -> {
int type = -Boolean.compare(a.block() instanceof PowerNode, b.block() instanceof PowerNode); int type = -Boolean.compare(a.block() instanceof PowerNode, b.block() instanceof PowerNode);
if(type != 0) return type; if(type != 0) return type;
return Float.compare(a.dst2(tile), b.dst2(tile)); return Float.compare(a.dst2(tile), b.dst2(tile));
}); });
tempTiles.each(valid, t -> { tempTileEnts.each(valid, t -> {
graphs.add(t.power.graph); graphs.add(t.power().graph);
others.get(t); others.get(t);
}); });
} }
@@ -219,6 +223,26 @@ public class PowerNode extends PowerBlock{
} }
} }
public boolean linkValid(Tilec tile, Tilec link){
return linkValid(tile, link, true);
}
public boolean linkValid(Tilec tile, Tilec link, boolean checkMaxNodes){
if(tile == link || link == null || !link.block().hasPower || tile.team() != link.team()) return false;
if(overlaps(tile, link, laserRange * tilesize) || (link.block() instanceof PowerNode && overlaps(link, tile, ((PowerNode)link.block()).laserRange * tilesize))){
if(checkMaxNodes && link.block() instanceof PowerNode){
return link.power().links.size < ((PowerNode)link.block()).maxNodes || link.power().links.contains(tile.pos());
}
return true;
}
return false;
}
public static boolean insulated(Tile tile, Tile other){
return insulated(tile.x, tile.y, other.x, other.y);
}
public static boolean insulated(Tilec tile, Tilec other){ public static boolean insulated(Tilec tile, Tilec other){
return insulated(tile.tileX(), tile.tileY(), other.tileX(), other.tileY()); return insulated(tile.tileX(), tile.tileY(), other.tileX(), other.tileY());
} }
@@ -251,23 +275,23 @@ public class PowerNode extends PowerBlock{
(other.block().outputsPower && !other.block().consumesPower) || other.block() instanceof PowerNode) && linkValid(this, other) (other.block().outputsPower && !other.block().consumesPower) || other.block() instanceof PowerNode) && linkValid(this, other)
&& !other.proximity().contains(this) && other.power().graph != power.graph; && !other.proximity().contains(this) && other.power().graph != power.graph;
tempTiles.clear(); tempTileEnts.clear();
Geometry.circle(tile.x, tile.y, (int)(laserRange + 2), (x, y) -> { Geometry.circle(tile.x, tile.y, (int)(laserRange + 2), (x, y) -> {
Tile other = world.ltile(x, y); Tilec other = world.ent(x, y);
if(valid.get(other)){ if(valid.get(other)){
if(!insulated(tile, other)){ if(!insulated(this, other)){
tempTiles.add(other); tempTileEnts.add(other);
} }
} }
}); });
tempTiles.sort((a, b) -> { tempTileEnts.sort((a, b) -> {
int type = -Boolean.compare(a.block() instanceof PowerNode, b.block() instanceof PowerNode); int type = -Boolean.compare(a.block() instanceof PowerNode, b.block() instanceof PowerNode);
if(type != 0) return type; if(type != 0) return type;
return Float.compare(a.dst2(tile), b.dst2(tile)); return Float.compare(a.dst2(tile), b.dst2(tile));
}); });
tempTiles.each(valid, other -> { tempTileEnts.each(valid, other -> {
if(!tile.power.links.contains(other.pos())){ if(!power.links.contains(other.pos())){
tile.configureAny(other.pos()); tile.configureAny(other.pos());
} }
}); });
@@ -277,24 +301,21 @@ public class PowerNode extends PowerBlock{
@Override @Override
public void updateTile(){ public void updateTile(){
tile.power.graph.update(); power.graph.update();
} }
@Override @Override
public boolean onConfigureTileTapped(Tile other){ public boolean onConfigureTileTapped(Tilec other){
Tilec entity = tile.ent(); if(linkValid(this, other)){
other = other.link();
if(linkValid(tile, other)){
tile.configure(other.pos()); tile.configure(other.pos());
return false; return false;
} }
if(tile == other){ if(this == other){
if(other.power.links.size == 0){ if(other.power().links.size == 0){
int[] total = {0}; int[] total = {0};
getPotentialLinks(tile, link -> { getPotentialLinks(tile, link -> {
if(!insulated(tile, link) && total[0]++ < maxNodes){ if(!insulated(this, link) && total[0]++ < maxNodes){
tile.configure(link.pos()); tile.configure(link.pos());
} }
}); });
@@ -335,13 +356,13 @@ public class PowerNode extends PowerBlock{
for(int x = (int)(tile.x - laserRange - 2); x <= tile.x + laserRange + 2; x++){ for(int x = (int)(tile.x - laserRange - 2); x <= tile.x + laserRange + 2; x++){
for(int y = (int)(tile.y - laserRange - 2); y <= tile.y + laserRange + 2; y++){ for(int y = (int)(tile.y - laserRange - 2); y <= tile.y + laserRange + 2; y++){
Tile link = world.ltile(x, y); Tilec link = world.ent(x, y);
if(link != tile && linkValid(tile, link, false)){ if(link != this && linkValid(this, link, false)){
boolean linked = linked(tile, link); boolean linked = linked(link);
if(linked){ if(linked){
Drawf.square(link.drawx(), link.drawy(), link.block().size * tilesize / 2f + 1f, Pal.place); Drawf.square(link.x(), link.y(), link.block().size * tilesize / 2f + 1f, Pal.place);
} }
} }
} }
@@ -357,40 +378,24 @@ public class PowerNode extends PowerBlock{
Tilec entity = tile.ent(); Tilec entity = tile.ent();
for(int i = 0; i < power.links.size; i++){ for(int i = 0; i < power.links.size; i++){
Tile link = world.tile(power.links.get(i)); Tilec link = world.ent(power.links.get(i));
if(!linkValid(tile, link)) continue; if(!linkValid(this, link)) continue;
if(link.block() instanceof PowerNode && !(link.pos() < tile.pos())) continue; if(link.block() instanceof PowerNode && !(link.pos() < tile.pos())) continue;
drawLaser(tile, link); drawLaserTo(link);
} }
Draw.reset(); Draw.reset();
} }
protected boolean linked(Tile other){ protected boolean linked(Tilec other){
return tile.power.links.contains(other.pos()); return power.links.contains(other.pos());
} }
public boolean linkValid(Tilec tile, Tilec link){ protected void drawLaserTo(Tilec target){
return linkValid(tile, link, true); drawLaser(x, y, target.x(), target.y(), power.graph.getSatisfaction(), size, target.block().size);
}
public boolean linkValid(Tilec tile, Tilec link, boolean checkMaxNodes){
if(tile == link || link == null || !link.block().hasPower || team != link.team()) return false;
if(overlaps(tile, link, laserRange * tilesize) || (link.block() instanceof PowerNode && overlaps(link, tile, link.<PowerNode>cblock().laserRange * tilesize))){
if(checkMaxNodes && link.block() instanceof PowerNode){
return link.power.links.size < link.<PowerNode>cblock().maxNodes || link.power.links.contains(tile.pos());
}
return true;
}
return false;
}
protected void drawLaser(Tile target){
drawLaser(x, y, target.drawx(), target.drawy(), power.graph.getSatisfaction(), size, target.block().size);
} }
@Override @Override

View File

@@ -7,14 +7,10 @@ import arc.math.*;
import arc.util.*; import arc.util.*;
import arc.util.io.*; import arc.util.io.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.ui.*; import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.meta.*; import mindustry.world.meta.*;
import java.io.*;
public class Cultivator extends GenericCrafter{ public class Cultivator extends GenericCrafter{
public Color plantColor = Color.valueOf("5541b1"); public Color plantColor = Color.valueOf("5541b1");
public Color plantColorLight = Color.valueOf("7457ce"); public Color plantColorLight = Color.valueOf("7457ce");
@@ -38,13 +34,6 @@ public class Cultivator extends GenericCrafter{
topRegion = Core.atlas.find(name + "-top"); topRegion = Core.atlas.find(name + "-top");
} }
@Override
public void updateTile(){
super.updateTile();
warmup = Mathf.lerpDelta(warmup, consValid() ? 1f : 0f, 0.015f);
}
@Override @Override
public void setBars(){ public void setBars(){
super.setBars(); super.setBars();
@@ -67,6 +56,22 @@ public class Cultivator extends GenericCrafter{
drawPlaceText(Core.bundle.formatFloat("bar.efficiency", (1 + sumAttribute(attribute, x, y)) * 100, 1), x, y, valid); drawPlaceText(Core.bundle.formatFloat("bar.efficiency", (1 + sumAttribute(attribute, x, y)) * 100, 1), x, y, valid);
} }
@Override
public TextureRegion[] generateIcons(){
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-top"),};
}
public class CultivatorEntity extends GenericCrafterEntity{
public float warmup;
public float boost;
@Override
public void updateTile(){
super.updateTile();
warmup = Mathf.lerpDelta(warmup, consValid() ? 1f : 0f, 0.015f);
}
@Override @Override
public void draw(){ public void draw(){
Draw.rect(region, x, y); Draw.rect(region, x, y);
@@ -94,27 +99,17 @@ public class Cultivator extends GenericCrafter{
} }
@Override @Override
public TextureRegion[] generateIcons(){ public void onProximityUpdate(){
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-top"),};
}
@Override
public void onProximityAdded(){
super.onProximityAdded(); super.onProximityAdded();
boost = sumAttribute(attribute, tile.x, tile.y); boost = sumAttribute(attribute, tile.x, tile.y);
} }
@Override @Override
protected float getProgressIncrease(Tilec entity, float baseTime){ public float getProgressIncrease(float baseTime){
CultivatorEntity c = (CultivatorEntity)entity; return super.getProgressIncrease(baseTime) * (1f + boost);
return super.getProgressIncrease(entity, baseTime) * (1f + c.boost);
} }
public class CultivatorEntity extends GenericCrafterEntity{
public float warmup;
public float boost;
@Override @Override
public void write(Writes write){ public void write(Writes write){
super.write(write); super.write(write);

View File

@@ -1,10 +1,10 @@
package mindustry.world.blocks.production; package mindustry.world.blocks.production;
import arc.*; import arc.*;
import arc.struct.*;
import arc.graphics.*; import arc.graphics.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*; import arc.math.*;
import arc.struct.*;
import arc.util.*; import arc.util.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.entities.*; import mindustry.entities.*;
@@ -73,7 +73,7 @@ public class Drill extends Block{
bars.add("drillspeed", e -> { bars.add("drillspeed", e -> {
DrillEntity entity = (DrillEntity)e; DrillEntity entity = (DrillEntity)e;
return new Bar(() -> Core.bundle.format("bar.drillspeed", Strings.fixed(lastDrillSpeed * 60 * timeScale(), 2)), () -> Pal.ammo, () -> warmup); return new Bar(() -> Core.bundle.format("bar.drillspeed", Strings.fixed(entity.lastDrillSpeed * 60 * entity.timeScale(), 2)), () -> Pal.ammo, () -> entity.warmup);
}); });
} }
@@ -85,50 +85,22 @@ public class Drill extends Block{
topRegion = Core.atlas.find(name + "-top"); topRegion = Core.atlas.find(name + "-top");
} }
@Override public Item getDrop(Tile tile){
public void drawCracks(){} return tile.drop();
@Override
public void draw(){
float s = 0.3f;
float ts = 0.6f;
Draw.rect(region, x, y);
super.drawCracks();
if(drawRim){
Draw.color(heatColor);
Draw.alpha(warmup * ts * (1f - s + Mathf.absin(Time.time(), 3f, s)));
Draw.blend(Blending.additive);
Draw.rect(rimRegion, x, y);
Draw.blend();
Draw.color();
}
Draw.rect(rotatorRegion, x, y, drillTime * rotateSpeed);
Draw.rect(topRegion, x, y);
if(dominantItem != null && drawMineItem){
Draw.color(dominantItem.color);
Draw.rect("drill-top", x, y, 1f);
Draw.color();
}
} }
@Override @Override
public TextureRegion[] generateIcons(){ public boolean canPlaceOn(Tile tile){
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-rotator"), Core.atlas.find(name + "-top")}; if(isMultiblock()){
for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){
if(canMine(other)){
return true;
} }
@Override
public boolean shouldConsume(){
return tile.items.total() < itemCapacity;
} }
return false;
@Override }else{
public boolean shouldIdleSound(){ return canMine(tile);
return tile.efficiency() > 0.01f; }
} }
@Override @Override
@@ -154,17 +126,6 @@ public class Drill extends Block{
} }
} }
@Override
public void drawSelect(){
if(dominantItem != null){
float dx = x - size * tilesize/2f, dy = y + size * tilesize/2f;
Draw.mixcol(Color.darkGray, 1f);
Draw.rect(dominantItem.icon(Cicon.small), dx, dy - 1);
Draw.reset();
Draw.rect(dominantItem.icon(Cicon.small), dx, dy);
}
}
@Override @Override
public void setStats(){ public void setStats(){
super.setStats(); super.setStats();
@@ -195,7 +156,12 @@ public class Drill extends Block{
} }
} }
void countOre(){ @Override
public TextureRegion[] generateIcons(){
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-rotator"), Core.atlas.find(name + "-top")};
}
void countOre(Tile tile){
returnItem = null; returnItem = null;
returnCount = 0; returnCount = 0;
@@ -203,7 +169,7 @@ public class Drill extends Block{
itemArray.clear(); itemArray.clear();
for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){ for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){
if(isValid(other)){ if(canMine(other)){
oreCount.getAndIncrement(getDrop(other), 0, 1); oreCount.getAndIncrement(getDrop(other), 0, 1);
} }
} }
@@ -228,6 +194,44 @@ public class Drill extends Block{
returnCount = oreCount.get(itemArray.peek(), 0); returnCount = oreCount.get(itemArray.peek(), 0);
} }
public boolean canMine(Tile tile){
if(tile == null) return false;
Item drops = tile.drop();
return drops != null && drops.hardness <= tier;
}
public class DrillEntity extends TileEntity{
float progress;
int index;
float warmup;
float drillTime;
float lastDrillSpeed;
int dominantItems;
Item dominantItem;
@Override
public boolean shouldConsume(){
return items.total() < itemCapacity;
}
@Override
public boolean shouldIdleSound(){
return efficiency() > 0.01f;
}
@Override
public void drawSelect(){
if(dominantItem != null){
float dx = x - size * tilesize/2f, dy = y + size * tilesize/2f;
Draw.mixcol(Color.darkGray, 1f);
Draw.rect(dominantItem.icon(Cicon.small), dx, dy - 1);
Draw.reset();
Draw.rect(dominantItem.icon(Cicon.small), dx, dy);
}
}
@Override @Override
public void onProximityUpdate(){ public void onProximityUpdate(){
countOre(tile); countOre(tile);
@@ -242,7 +246,7 @@ public class Drill extends Block{
} }
if(timer(timerDump, dumpTime)){ if(timer(timerDump, dumpTime)){
tryDump(tile, dominantItem); dump(dominantItem);
} }
drillTime += warmup * delta(); drillTime += warmup * delta();
@@ -270,11 +274,9 @@ public class Drill extends Block{
return; return;
} }
if(dominantItems > 0 && progress >= drillTime + hardnessDrillMultiplier * dominantItem.hardness && tile.items.total() < itemCapacity){ if(dominantItems > 0 && progress >= drillTime + hardnessDrillMultiplier * dominantItem.hardness && items.total() < itemCapacity){
offloadNear(dominantItem);
offloadNear(tile, dominantItem); useContent(dominantItem);
useContent(tile, dominantItem);
index++; index++;
progress = 0f; progress = 0f;
@@ -284,42 +286,35 @@ public class Drill extends Block{
} }
@Override @Override
public boolean canPlaceOn(){ public void drawCracks(){}
if(isMultiblock()){
for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){ @Override
if(isValid(other)){ public void draw(){
return true; float s = 0.3f;
float ts = 0.6f;
Draw.rect(region, x, y);
super.drawCracks();
if(drawRim){
Draw.color(heatColor);
Draw.alpha(warmup * ts * (1f - s + Mathf.absin(Time.time(), 3f, s)));
Draw.blend(Blending.additive);
Draw.rect(rimRegion, x, y);
Draw.blend();
Draw.color();
} }
Draw.rect(rotatorRegion, x, y, drillTime * rotateSpeed);
Draw.rect(topRegion, x, y);
if(dominantItem != null && drawMineItem){
Draw.color(dominantItem.color);
Draw.rect("drill-top", x, y, 1f);
Draw.color();
} }
return false;
}else{
return isValid(tile);
} }
} }
public int tier(){
return tier;
}
public Item getDrop(){
return tile.drop();
}
public boolean isValid(){
if(tile == null) return false;
Item drops = tile.drop();
return drops != null && drops.hardness <= tier;
}
public class DrillEntity extends TileEntity{
float progress;
int index;
float warmup;
float drillTime;
float lastDrillSpeed;
int dominantItems;
Item dominantItem;
}
} }

View File

@@ -2,7 +2,6 @@ package mindustry.world.blocks.production;
import arc.*; import arc.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import mindustry.world.*;
import mindustry.world.meta.*; import mindustry.world.meta.*;
public class Fracker extends SolidPump{ public class Fracker extends SolidPump{
@@ -38,12 +37,20 @@ public class Fracker extends SolidPump{
return false; return false;
} }
@Override
public TextureRegion[] generateIcons(){
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-rotator"), Core.atlas.find(name + "-top")};
}
public class FrackerEntity extends SolidPumpEntity{
public float accumulator;
@Override @Override
public void drawCracks(){} public void drawCracks(){}
@Override @Override
public boolean shouldConsume(){ public boolean shouldConsume(){
return tile.liquids.get(result) < liquidCapacity - 0.01f; return liquids.get(result) < liquidCapacity - 0.01f;
} }
@Override @Override
@@ -52,7 +59,7 @@ public class Fracker extends SolidPump{
super.drawCracks(); super.drawCracks();
Draw.color(result.color); Draw.color(result.color);
Draw.alpha(tile.liquids.get(result) / liquidCapacity); Draw.alpha(liquids.get(result) / liquidCapacity);
Draw.rect(liquidRegion, x, y); Draw.rect(liquidRegion, x, y);
Draw.color(); Draw.color();
@@ -60,11 +67,6 @@ public class Fracker extends SolidPump{
Draw.rect(topRegion, x, y); Draw.rect(topRegion, x, y);
} }
@Override
public TextureRegion[] generateIcons(){
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-rotator"), Core.atlas.find(name + "-top")};
}
@Override @Override
public void updateTile(){ public void updateTile(){
if(consValid()){ if(consValid()){
@@ -76,16 +78,13 @@ public class Fracker extends SolidPump{
super.updateTile(); super.updateTile();
accumulator += delta() * efficiency(); accumulator += delta() * efficiency();
}else{ }else{
tryDumpLiquid(tile, result); dumpLiquid(result);
} }
} }
@Override @Override
public float typeLiquid(){ public float typeLiquid(){
return tile.liquids.get(result); return liquids.get(result);
} }
public class FrackerEntity extends SolidPumpEntity{
public float accumulator;
} }
} }

View File

@@ -55,36 +55,49 @@ public class GenericCrafter extends Block{
} }
} }
@Override
public boolean shouldIdleSound(Tilec tile){
return tile.cons().valid();
}
@Override @Override
public void init(){ public void init(){
outputsLiquid = outputLiquid != null; outputsLiquid = outputLiquid != null;
super.init(); super.init();
} }
@Override
public void draw(){
if(drawer == null){
super.draw();
}else{
drawer.get(tile);
}
}
@Override @Override
public TextureRegion[] generateIcons(){ public TextureRegion[] generateIcons(){
return drawIcons == null ? super.generateIcons() : drawIcons.get(); return drawIcons == null ? super.generateIcons() : drawIcons.get();
} }
@Override
public boolean outputsItems(){
return outputItem != null;
}
public class GenericCrafterEntity extends TileEntity{
public float progress;
public float totalProgress;
public float warmup;
@Override
public void draw(){
if(drawer == null){
super.draw();
}else{
drawer.get(this);
}
}
@Override
public boolean shouldConsume(){
if(outputItem != null && items.get(outputItem.item) >= itemCapacity){
return false;
}
return outputLiquid == null || !(liquids.get(outputLiquid.liquid) >= liquidCapacity - 0.001f);
}
@Override @Override
public void updateTile(){ public void updateTile(){
if(consValid()){ if(consValid()){
progress += getProgressIncrease(entity, craftTime); progress += getProgressIncrease(craftTime);
totalProgress += delta(); totalProgress += delta();
warmup = Mathf.lerpDelta(warmup, 1f, 0.02f); warmup = Mathf.lerpDelta(warmup, 1f, 0.02f);
@@ -99,15 +112,15 @@ public class GenericCrafter extends Block{
consume(); consume();
if(outputItem != null){ if(outputItem != null){
useContent(tile, outputItem.item); useContent(outputItem.item);
for(int i = 0; i < outputItem.amount; i++){ for(int i = 0; i < outputItem.amount; i++){
offloadNear(tile, outputItem.item); offloadNear(outputItem.item);
} }
} }
if(outputLiquid != null){ if(outputLiquid != null){
useContent(tile, outputLiquid.liquid); useContent(outputLiquid.liquid);
handleLiquid(tile, tile, outputLiquid.liquid, outputLiquid.amount); handleLiquid(this, outputLiquid.liquid, outputLiquid.amount);
} }
craftEffect.at(x, y); craftEffect.at(x, y);
@@ -115,36 +128,23 @@ public class GenericCrafter extends Block{
} }
if(outputItem != null && timer(timerDump, dumpTime)){ if(outputItem != null && timer(timerDump, dumpTime)){
tryDump(tile, outputItem.item); dump(outputItem.item);
} }
if(outputLiquid != null){ if(outputLiquid != null){
tryDumpLiquid(tile, outputLiquid.liquid); dumpLiquid(outputLiquid.liquid);
} }
} }
@Override
public boolean outputsItems(){
return outputItem != null;
}
@Override
public boolean shouldConsume(){
if(outputItem != null && tile.items.get(outputItem.item) >= itemCapacity){
return false;
}
return outputLiquid == null || !(tile.liquids.get(outputLiquid.liquid) >= liquidCapacity - 0.001f);
}
@Override @Override
public int getMaximumAccepted(Item item){ public int getMaximumAccepted(Item item){
return itemCapacity; return itemCapacity;
} }
public class GenericCrafterEntity extends TileEntity{ @Override
public float progress; public boolean shouldIdleSound(){
public float totalProgress; return cons.valid();
public float warmup; }
@Override @Override
public void write(Writes write){ public void write(Writes write){

View File

@@ -5,7 +5,6 @@ import arc.graphics.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*; import arc.math.*;
import arc.util.*; import arc.util.*;
import mindustry.world.*;
import static mindustry.Vars.renderer; import static mindustry.Vars.renderer;
@@ -24,6 +23,7 @@ public class GenericSmelter extends GenericCrafter{
topRegion = Core.atlas.find(name + "-top"); topRegion = Core.atlas.find(name + "-top");
} }
public class SmelterEntity extends GenericCrafterEntity{
@Override @Override
public void draw(){ public void draw(){
super.draw(); super.draw();
@@ -51,3 +51,4 @@ public class GenericSmelter extends GenericCrafter{
renderer.lights.add(x, y, (60f + Mathf.absin(10f, 5f)) * warmup * size, flameColor, 0.65f); renderer.lights.add(x, y, (60f + Mathf.absin(10f, 5f)) * warmup * size, flameColor, 0.65f);
} }
} }
}

View File

@@ -1,17 +1,14 @@
package mindustry.world.blocks.production; package mindustry.world.blocks.production;
import arc.graphics.Color; import arc.graphics.*;
import arc.graphics.g2d.Draw; import arc.graphics.g2d.*;
import arc.graphics.g2d.Fill; import arc.math.*;
import arc.math.Mathf; import arc.util.*;
import arc.util.Time; import mindustry.content.*;
import mindustry.content.Fx;
import mindustry.entities.*; import mindustry.entities.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.type.Item; import mindustry.type.*;
import mindustry.type.Liquid; import mindustry.world.*;
import mindustry.world.Block;
import mindustry.world.Tile;
public class Incinerator extends Block{ public class Incinerator extends Block{
public Effect effect = Fx.fuelburn; public Effect effect = Fx.fuelburn;
@@ -25,6 +22,9 @@ public class Incinerator extends Block{
solid = true; solid = true;
} }
public class IncineratorEntity extends TileEntity{
public float heat;
@Override @Override
public void updateTile(){ public void updateTile(){
if(consValid()){ if(consValid()){
@@ -66,18 +66,15 @@ public class Incinerator extends Block{
} }
@Override @Override
public void handleLiquid(Tile source, Liquid liquid, float amount){ public void handleLiquid(Tilec source, Liquid liquid, float amount){
if(Mathf.chance(0.02)){ if(Mathf.chance(0.02)){
effect.at(x, y); effect.at(x, y);
} }
} }
@Override @Override
public boolean acceptLiquid(Tile source, Liquid liquid, float amount){ public boolean acceptLiquid(Tilec source, Liquid liquid, float amount){
return heat > 0.5f; return heat > 0.5f;
} }
public class IncineratorEntity extends TileEntity{
public float heat;
} }
} }

View File

@@ -1,9 +1,7 @@
package mindustry.world.blocks.production; package mindustry.world.blocks.production;
import mindustry.world.Tile; import mindustry.world.consumers.*;
import mindustry.world.consumers.ConsumeLiquidBase; import mindustry.world.meta.*;
import mindustry.world.consumers.ConsumeType;
import mindustry.world.meta.BlockStat;
public class LiquidConverter extends GenericCrafter{ public class LiquidConverter extends GenericCrafter{
@@ -32,10 +30,11 @@ public class LiquidConverter extends GenericCrafter{
stats.add(BlockStat.output, outputLiquid.liquid, outputLiquid.amount * craftTime, false); stats.add(BlockStat.output, outputLiquid.liquid, outputLiquid.amount * craftTime, false);
} }
public class LiquidConverterEntity extends GenericCrafterEntity{
@Override @Override
public void drawLight(){ public void drawLight(){
if(hasLiquids && drawLiquidLight && outputLiquid.liquid.lightColor.a > 0.001f){ if(hasLiquids && drawLiquidLight && outputLiquid.liquid.lightColor.a > 0.001f){
drawLiquidLight(tile, outputLiquid.liquid, tile.liquids.get(outputLiquid.liquid)); drawLiquidLight(outputLiquid.liquid, liquids.get(outputLiquid.liquid));
} }
} }
@@ -43,10 +42,10 @@ public class LiquidConverter extends GenericCrafter{
public void updateTile(){ public void updateTile(){
ConsumeLiquidBase cl = consumes.get(ConsumeType.liquid); ConsumeLiquidBase cl = consumes.get(ConsumeType.liquid);
if(tile.cons().valid()){ if(cons.valid()){
float use = Math.min(cl.amount * delta(), liquidCapacity - liquids.get(outputLiquid.liquid)) * efficiency(); float use = Math.min(cl.amount * delta(), liquidCapacity - liquids.get(outputLiquid.liquid)) * efficiency();
useContent(tile, outputLiquid.liquid); useContent(outputLiquid.liquid);
progress += use / cl.amount / craftTime; progress += use / cl.amount / craftTime;
liquids.add(outputLiquid.liquid, use); liquids.add(outputLiquid.liquid, use);
if(progress >= 1f){ if(progress >= 1f){
@@ -55,6 +54,7 @@ public class LiquidConverter extends GenericCrafter{
} }
} }
tryDumpLiquid(tile, outputLiquid.liquid); dumpLiquid(outputLiquid.liquid);
}
} }
} }

View File

@@ -1,24 +1,18 @@
package mindustry.world.blocks.production; package mindustry.world.blocks.production;
import arc.Core; import arc.*;
import arc.struct.Array; import arc.graphics.*;
import arc.graphics.Color; import arc.graphics.g2d.*;
import arc.graphics.g2d.Draw; import mindustry.graphics.*;
import arc.graphics.g2d.TextureRegion; import mindustry.type.*;
import mindustry.graphics.Layer; import mindustry.ui.*;
import mindustry.type.Liquid; import mindustry.world.*;
import mindustry.ui.Cicon; import mindustry.world.blocks.liquid.*;
import mindustry.world.Tile;
import mindustry.world.blocks.liquid.LiquidBlock;
import mindustry.world.meta.*; import mindustry.world.meta.*;
import static mindustry.Vars.tilesize; import static mindustry.Vars.*;
import static mindustry.Vars.world;
public class Pump extends LiquidBlock{ public class Pump extends LiquidBlock{
protected final Array<Tile> drawTiles = new Array<>();
protected final Array<Tile> updateTiles = new Array<>();
public final int timerContentCheck = timers++; public final int timerContentCheck = timers++;
/** Pump amount, total. */ /** Pump amount, total. */
@@ -44,16 +38,6 @@ public class Pump extends LiquidBlock{
stats.add(BlockStat.output, 60f * pumpAmount, StatUnit.liquidSecond); stats.add(BlockStat.output, 60f * pumpAmount, StatUnit.liquidSecond);
} }
@Override
public void draw(){
Draw.rect(name, x, y);
Draw.color(tile.liquids.current().color);
Draw.alpha(tile.liquids.total() / liquidCapacity);
Draw.rect(liquidRegion, x, y);
Draw.color();
}
@Override @Override
public void drawPlace(int x, int y, int rotation, boolean valid) { public void drawPlace(int x, int y, int rotation, boolean valid) {
Tile tile = world.tile(x, y); Tile tile = world.tile(x, y);
@@ -63,7 +47,7 @@ public class Pump extends LiquidBlock{
Liquid liquidDrop = null; Liquid liquidDrop = null;
for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){ for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){
if(isValid(other)){ if(canPump(other)){
liquidDrop = other.floor().liquidDrop; liquidDrop = other.floor().liquidDrop;
tiles++; tiles++;
} }
@@ -85,10 +69,10 @@ public class Pump extends LiquidBlock{
} }
@Override @Override
public boolean canPlaceOn(){ public boolean canPlaceOn(Tile tile){
if(isMultiblock()){ if(isMultiblock()){
Liquid last = null; Liquid last = null;
for(Tile other : tile.getLinkedTilesAs(this, drawTiles)){ for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){
if(other.floor().liquidDrop == null) if(other.floor().liquidDrop == null)
continue; continue;
if(other.floor().liquidDrop != last && last != null) if(other.floor().liquidDrop != last && last != null)
@@ -97,18 +81,34 @@ public class Pump extends LiquidBlock{
} }
return last != null; return last != null;
}else{ }else{
return isValid(tile); return canPump(tile);
} }
} }
protected boolean canPump(Tile tile){
return tile != null && tile.floor().liquidDrop != null;
}
public class PumpEntity extends LiquidBlockEntity{
@Override
public void draw(){
Draw.rect(name, x, y);
Draw.color(liquids.current().color);
Draw.alpha(liquids.total() / liquidCapacity);
Draw.rect(liquidRegion, x, y);
Draw.color();
}
@Override @Override
public void updateTile(){ public void updateTile(){
float tiles = 0f; float tiles = 0f;
Liquid liquidDrop = null; Liquid liquidDrop = null;
if(isMultiblock()){ if(isMultiblock()){
for(Tile other : tile.getLinkedTiles(updateTiles)){ for(Tile other : tile.getLinkedTiles(tempTiles)){
if(isValid(other)){ if(canPump(other)){
liquidDrop = other.floor().liquidDrop; liquidDrop = other.floor().liquidDrop;
tiles++; tiles++;
} }
@@ -118,20 +118,17 @@ public class Pump extends LiquidBlock{
liquidDrop = tile.floor().liquidDrop; liquidDrop = tile.floor().liquidDrop;
} }
if(tile.cons().valid() && liquidDrop != null){ if(cons.valid() && liquidDrop != null){
float maxPump = Math.min(liquidCapacity - tile.liquids.total(), tiles * pumpAmount * tile.delta() / size / size) * tile.efficiency(); float maxPump = Math.min(liquidCapacity - liquids.total(), tiles * pumpAmount * delta() / size / size) * efficiency();
tile.liquids.add(liquidDrop, maxPump); liquids.add(liquidDrop, maxPump);
} }
if(tile.liquids.currentAmount() > 0f && timer(timerContentCheck, 10)){ if(liquids.currentAmount() > 0f && timer(timerContentCheck, 10)){
useContent(tile, tile.liquids.current()); useContent(liquids.current());
} }
tryDumpLiquid(tile, tile.liquids.current()); dumpLiquid(liquids.current());
} }
protected boolean isValid(){
return tile != null && tile.floor().liquidDrop != null;
} }
} }

View File

@@ -4,9 +4,10 @@ import arc.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*; import arc.math.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.io.*;
import mindustry.gen.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*; import mindustry.world.*;
import mindustry.world.blocks.production.GenericCrafter.*;
import mindustry.world.consumers.*; import mindustry.world.consumers.*;
import mindustry.world.meta.*; import mindustry.world.meta.*;
import mindustry.world.meta.values.*; import mindustry.world.meta.values.*;
@@ -51,17 +52,27 @@ public class Separator extends Block{
stats.add(BlockStat.productionTime, craftTime / 60f, StatUnit.seconds); stats.add(BlockStat.productionTime, craftTime / 60f, StatUnit.seconds);
} }
public class SeparatorEntity extends TileEntity{
public float progress;
public float totalProgress;
public float warmup;
@Override
public boolean shouldIdleSound(){
return cons.valid();
}
@Override @Override
public boolean shouldConsume(){ public boolean shouldConsume(){
return tile.items.total() < itemCapacity; return items.total() < itemCapacity;
} }
@Override @Override
public void draw(){ public void draw(){
super.draw(); super.draw();
Draw.color(tile.liquids.current().color); Draw.color(liquids.current().color);
Draw.alpha(tile.liquids.total() / liquidCapacity); Draw.alpha(liquids.total() / liquidCapacity);
Draw.rect(reg(liquidRegion), x, y); Draw.rect(reg(liquidRegion), x, y);
Draw.reset(); Draw.reset();
@@ -75,7 +86,7 @@ public class Separator extends Block{
totalProgress += warmup * delta(); totalProgress += warmup * delta();
if(consValid()){ if(consValid()){
progress += getProgressIncrease(entity, craftTime); progress += getProgressIncrease(craftTime);
warmup = Mathf.lerpDelta(warmup, 1f, 0.02f); warmup = Mathf.lerpDelta(warmup, 1f, 0.02f);
}else{ }else{
warmup = Mathf.lerpDelta(warmup, 0f, 0.02f); warmup = Mathf.lerpDelta(warmup, 0f, 0.02f);
@@ -102,13 +113,27 @@ public class Separator extends Block{
consume(); consume();
if(item != null && items.get(item) < itemCapacity){ if(item != null && items.get(item) < itemCapacity){
useContent(tile, item); offloadNear(item);
offloadNear(tile, item);
} }
} }
if(timer(timerDump, dumpTime)){ if(timer(timerDump, dumpTime)){
tryDump(tile); dump();
}
}
@Override
public void write(Writes write){
super.write(write);
write.f(progress);
write.f(warmup);
}
@Override
public void read(Reads read, byte revision){
super.read(read, revision);
progress = read.f();
warmup = read.f();
} }
} }
} }

View File

@@ -1,21 +1,17 @@
package mindustry.world.blocks.production; package mindustry.world.blocks.production;
import arc.Core; import arc.*;
import arc.graphics.g2d.Draw; import arc.graphics.g2d.*;
import arc.graphics.g2d.TextureRegion; import arc.math.*;
import arc.math.Mathf;
import arc.util.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import mindustry.content.Fx; import arc.util.*;
import mindustry.content.Liquids; import mindustry.content.*;
import mindustry.entities.*; import mindustry.entities.*;
import mindustry.gen.*; import mindustry.graphics.*;
import mindustry.graphics.Pal; import mindustry.type.*;
import mindustry.type.Liquid; import mindustry.ui.*;
import mindustry.ui.Bar; import mindustry.world.*;
import mindustry.world.Tile; import mindustry.world.meta.*;
import mindustry.world.meta.Attribute;
import mindustry.world.meta.BlockStat;
/** /**
* Pump that makes liquid from solids and takes in power. Only works on solid floor blocks. * Pump that makes liquid from solids and takes in power. Only works on solid floor blocks.
@@ -69,14 +65,22 @@ public class SolidPump extends Pump{
} }
@Override @Override
public void draw(){ public boolean canPlaceOn(Tile tile){
Draw.rect(region, x, y); if(isMultiblock()){
Draw.color(tile.liquids.current().color); for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){
Draw.alpha(tile.liquids.total() / liquidCapacity); if(canPump(other)){
Draw.rect(liquidRegion, x, y); return true;
Draw.color(); }
Draw.rect(name + "-rotator", x, y, pumpTime * rotateSpeed); }
Draw.rect(name + "-top", x, y); return false;
}else{
return canPump(tile);
}
}
@Override
protected boolean canPump(Tile tile){
return tile != null && !tile.floor().isLiquid;
} }
@Override @Override
@@ -84,28 +88,45 @@ public class SolidPump extends Pump{
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-rotator"), Core.atlas.find(name + "-top")}; return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-rotator"), Core.atlas.find(name + "-top")};
} }
public class SolidPumpEntity extends PumpEntity{
public float warmup;
public float pumpTime;
public float boost;
public float lastPump;
@Override
public void draw(){
Draw.rect(region, x, y);
Draw.color(liquids.current().color);
Draw.alpha(liquids.total() / liquidCapacity);
Draw.rect(liquidRegion, x, y);
Draw.color();
Draw.rect(name + "-rotator", x, y, pumpTime * rotateSpeed);
Draw.rect(name + "-top", x, y);
}
@Override @Override
public void updateTile(){ public void updateTile(){
float fraction = 0f; float fraction = 0f;
if(isMultiblock()){ if(isMultiblock()){
for(Tile other : tile.getLinkedTiles(tempTiles)){ for(Tile other : tile.getLinkedTiles(tempTiles)){
if(isValid(other)){ if(canPump(other)){
fraction += 1f / (size * size); fraction += 1f / (size * size);
} }
} }
}else{ }else{
if(isValid(tile)) fraction = 1f; if(canPump(tile)) fraction = 1f;
} }
fraction += boost; fraction += boost;
if(tile.cons().valid() && typeLiquid(tile) < liquidCapacity - 0.001f){ if(cons.valid() && typeLiquid() < liquidCapacity - 0.001f){
float maxPump = Math.min(liquidCapacity - typeLiquid(tile), pumpAmount * delta() * fraction * efficiency()); float maxPump = Math.min(liquidCapacity - typeLiquid(), pumpAmount * delta() * fraction * efficiency());
tile.liquids.add(result, maxPump); liquids.add(result, maxPump);
lastPump = maxPump; lastPump = maxPump;
warmup = Mathf.lerpDelta(warmup, 1f, 0.02f); warmup = Mathf.lerpDelta(warmup, 1f, 0.02f);
if(timer(timerContentCheck, 10)) useContent(tile, result); if(timer(timerContentCheck, 10)) useContent(result);
if(Mathf.chance(delta() * updateEffectChance)) if(Mathf.chance(delta() * updateEffectChance))
updateEffect.at(getX() + Mathf.range(size * 2f), getY() + Mathf.range(size * 2f)); updateEffect.at(getX() + Mathf.range(size * 2f), getY() + Mathf.range(size * 2f));
}else{ }else{
@@ -115,30 +136,11 @@ public class SolidPump extends Pump{
pumpTime += warmup * delta(); pumpTime += warmup * delta();
tryDumpLiquid(tile, result); dumpLiquid(result);
} }
@Override @Override
public boolean canPlaceOn(){ public void onProximityUpdate(){
if(isMultiblock()){
for(Tile other : tile.getLinkedTilesAs(this, drawTiles)){
if(isValid(other)){
return true;
}
}
return false;
}else{
return isValid(tile);
}
}
@Override
protected boolean isValid(){
return tile != null && !tile.floor().isLiquid;
}
@Override
public void onProximityAdded(){
super.onProximityAdded(); super.onProximityAdded();
if(attribute != null){ if(attribute != null){
@@ -147,13 +149,7 @@ public class SolidPump extends Pump{
} }
public float typeLiquid(){ public float typeLiquid(){
return tile.liquids.total(); return liquids.total();
} }
public class SolidPumpEntity extends TileEntity{
public float warmup;
public float pumpTime;
public float boost;
public float lastPump;
} }
} }

View File

@@ -99,7 +99,7 @@ public class CoreBlock extends StorageBlock{
storageCapacity = itemCapacity + proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0); storageCapacity = itemCapacity + proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0);
proximity.each(this::isContainer, t -> { proximity.each(this::isContainer, t -> {
t.items(items); t.items(items);
((StorageBlockEntity)t).linkedCore = tile; ((StorageBlockEntity)t).linkedCore = this;
}); });
for(Tilec other : state.teams.cores(team)){ for(Tilec other : state.teams.cores(team)){

View File

@@ -1,20 +1,16 @@
package mindustry.world.blocks.storage; package mindustry.world.blocks.storage;
import arc.*; import arc.*;
import arc.graphics.g2d.Draw; import arc.graphics.g2d.*;
import arc.graphics.g2d.Lines; import arc.math.*;
import arc.math.Mathf; import arc.util.*;
import arc.util.Time; import mindustry.*;
import mindustry.Vars; import mindustry.content.*;
import mindustry.content.Fx;
import mindustry.gen.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.graphics.Pal; import mindustry.gen.*;
import mindustry.type.Item; import mindustry.graphics.*;
import mindustry.type.ItemType; import mindustry.type.*;
import mindustry.world.Tile; import mindustry.world.meta.*;
import mindustry.world.meta.BlockStat;
import mindustry.world.meta.StatUnit;
import static mindustry.Vars.*; import static mindustry.Vars.*;
@@ -37,17 +33,13 @@ public class LaunchPad extends StorageBlock{
stats.add(BlockStat.launchTime, launchTime / 60f, StatUnit.seconds); stats.add(BlockStat.launchTime, launchTime / 60f, StatUnit.seconds);
} }
@Override public class LaunchPadEntity extends StorageBlockEntity{
public boolean acceptItem(Tilec source, Item item){
return item.type == ItemType.material && tile.items.total() < itemCapacity;
}
@Override @Override
public void draw(){ public void draw(){
super.draw(); super.draw();
//TODO broken //TODO broken
float progress = Mathf.clamp(Mathf.clamp((tile.items.total() / (float)itemCapacity)) * ((timer().getTime(timerLaunch) / (launchTime / tile.timeScale())))); float progress = Mathf.clamp(Mathf.clamp((items.total() / (float)itemCapacity)) * ((timer().getTime(timerLaunch) / (launchTime / timeScale()))));
float scale = size / 3f; float scale = size / 3f;
Lines.stroke(2f); Lines.stroke(2f);
@@ -56,7 +48,7 @@ public class LaunchPad extends StorageBlock{
Draw.color(Pal.accent); Draw.color(Pal.accent);
if(tile.cons().valid()){ if(cons.valid()){
for(int i = 0; i < 3; i++){ for(int i = 0; i < 3; i++){
float f = (Time.time() / 200f + i * 0.5f) % 1f; float f = (Time.time() / 200f + i * 0.5f) % 1f;
@@ -68,9 +60,13 @@ public class LaunchPad extends StorageBlock{
Draw.reset(); Draw.reset();
} }
@Override
public boolean acceptItem(Tilec source, Item item){
return item.type == ItemType.material && items.total() < itemCapacity;
}
@Override @Override
public void updateTile(){ public void updateTile(){
Tilec entity = tile.entity;
if(state.isCampaign() && consValid() && items.total() >= itemCapacity && timer(timerLaunch, launchTime / timeScale())){ if(state.isCampaign() && consValid() && items.total() >= itemCapacity && timer(timerLaunch, launchTime / timeScale())){
for(Item item : Vars.content.items()){ for(Item item : Vars.content.items()){
@@ -84,3 +80,4 @@ public class LaunchPad extends StorageBlock{
} }
} }
} }
}

View File

@@ -2,32 +2,17 @@ package mindustry.world.blocks.storage;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.type.Item; import mindustry.type.*;
import mindustry.world.Block; import mindustry.world.*;
import mindustry.world.Tile;
public abstract class StorageBlock extends Block{ public abstract class StorageBlock extends Block{
public StorageBlock(String name){ public StorageBlock(String name){
super(name); super(name);
hasItems = true; hasItems = true;
} solid = true;
update = false;
@Override destructible = true;
public boolean acceptItem(Tilec source, Item item){
return linkedCore != null ? linkedCore.acceptItem(linkedCore, source, item) : tile.items.get(item) < getMaximumAccepted(tile, item);
}
@Override
public int getMaximumAccepted(Item item){
return itemCapacity;
}
@Override
public void drawSelect(){
if(linkedCore != null){
linkedCore.block().drawSelect(linkedCore);
}
} }
@Override @Override
@@ -35,13 +20,15 @@ public abstract class StorageBlock extends Block{
return false; return false;
} }
public class StorageBlockEntity extends TileEntity{
protected @Nullable Tilec linkedCore;
/** /**
* Removes an item and returns it. If item is not null, it should return the item. * Removes an item and returns it. If item is not null, it should return the item.
* Returns null if no items are there. * Returns null if no items are there.
*/ */
public Item removeItem(Item item){ @Nullable
Tilec entity = tile.entity; public Item removeItem(@Nullable Item item){
if(item == null){ if(item == null){
return items.take(); return items.take();
}else{ }else{
@@ -58,8 +45,7 @@ public abstract class StorageBlock extends Block{
* Returns whether this storage block has the specified item. * Returns whether this storage block has the specified item.
* If the item is null, it should return whether it has ANY items. * If the item is null, it should return whether it has ANY items.
*/ */
public boolean hasItem(Item item){ public boolean hasItem(@Nullable Item item){
Tilec entity = tile.entity;
if(item == null){ if(item == null){
return items.total() > 0; return items.total() > 0;
}else{ }else{
@@ -67,8 +53,21 @@ public abstract class StorageBlock extends Block{
} }
} }
public class StorageBlockEntity extends TileEntity{ @Override
protected @Nullable public boolean acceptItem(Tilec source, Item item){
Tile linkedCore; return linkedCore != null ? linkedCore.acceptItem(source, item) : items.get(item) < getMaximumAccepted(item);
}
@Override
public int getMaximumAccepted(Item item){
return itemCapacity;
}
@Override
public void drawSelect(){
if(linkedCore != null){
linkedCore.drawSelect();
}
}
} }
} }

View File

@@ -27,11 +27,11 @@ public class Unloader extends Block{
hasItems = true; hasItems = true;
configurable = true; configurable = true;
config(Item.class, (tile, item) -> { config(Item.class, (tile, item) -> {
tile.items.clear(); tile.items().clear();
tile.<UnloaderEntity>ent().sortItem = item; ((UnloaderEntity)tile).sortItem = item;
}); });
configClear(tile -> tile.<UnloaderEntity>ent().sortItem = null); configClear(tile -> ((UnloaderEntity)tile).sortItem = null);
} }
@Override @Override
@@ -39,17 +39,36 @@ public class Unloader extends Block{
drawRequestConfigCenter(req, (Item)req.config, "unloader-center"); drawRequestConfigCenter(req, (Item)req.config, "unloader-center");
} }
@Override
public boolean canDump(Tile to, Item item){
return !(to.block() instanceof StorageBlock);
}
@Override @Override
public void setBars(){ public void setBars(){
super.setBars(); super.setBars();
bars.remove("items"); bars.remove("items");
} }
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);
}
}
@Override @Override
public void playerPlaced(){ public void playerPlaced(){
if(lastItem != null){ if(lastItem != null){
@@ -59,50 +78,16 @@ public class Unloader extends Block{
@Override @Override
public void updateTile(){ public void updateTile(){
if(timer(timerUnload, speed / timeScale()) && tile.items.total() == 0){ if(timer(timerUnload, speed / timeScale()) && items.total() == 0){
for(Tile other : tile.proximity()){ for(Tilec other : proximity){
if(other.interactable(team) && other.block().unloadable && other.block().hasItems && items.total() == 0 && if(other.interactable(team) && other.block().unloadable && other.block().hasItems && items.total() == 0 &&
((sortItem == null && other.items.total() > 0) || hasItem(other, sortItem))){ ((sortItem == null && items.total() > 0) || hasItem(other, sortItem))){
offloadNear(tile, removeItem(other, sortItem)); offloadNear(removeItem(other, sortItem));
} }
} }
} }
if(items.total() > 0){ dump();
tryDump(tile);
}
}
/**
* Removes an item and returns it. If item is not null, it should return the item.
* Returns null if no items are there.
*/
private Item removeItem(Item item){
Tilec entity = tile.entity;
if(item == null){
return items.take();
}else{
if(items.has(item)){
items.remove(item, 1);
return item;
}
return null;
}
}
/**
* Returns whether this storage block has the specified item.
* If the item is null, it should return whether it has ANY items.
*/
private boolean hasItem(Item item){
Tilec entity = tile.entity;
if(item == null){
return items.total() > 0;
}else{
return items.has(item);
}
} }
@Override @Override
@@ -119,8 +104,10 @@ public class Unloader extends Block{
ItemSelection.buildTable(table, content.items(), () -> tile.<UnloaderEntity>ent().sortItem, item -> tile.configure(lastItem = item)); ItemSelection.buildTable(table, content.items(), () -> tile.<UnloaderEntity>ent().sortItem, item -> tile.configure(lastItem = item));
} }
public class UnloaderEntity extends TileEntity{ @Override
public Item sortItem = null; public boolean canDump(Tilec to, Item item){
return !(to.block() instanceof StorageBlock);
}
@Override @Override
public Item config(){ public Item config(){

View File

@@ -1,12 +0,0 @@
package mindustry.world.blocks.storage;
public class Vault extends StorageBlock{
public Vault(String name){
super(name);
solid = true;
update = false;
destructible = true;
}
}

View File

@@ -38,40 +38,18 @@ public class CommandCenter extends Block{
UnitCommand command = UnitCommand.all[value]; UnitCommand command = UnitCommand.all[value];
((CommandCenter)tile.block()).effect.at(tile); ((CommandCenter)tile.block()).effect.at(tile);
for(Tile center : indexer.getAllied(team, BlockFlag.comandCenter)){ for(Tile center : indexer.getAllied(tile.team(), BlockFlag.comandCenter)){
if(center.block() instanceof CommandCenter){ if(center.block() instanceof CommandCenter){
CommandCenterEntity entity = center.ent(); CommandCenterEntity entity = center.ent();
command = command; entity.command = command;
} }
} }
Groups.unit.each(t -> t.team() == team, u -> u.controller().command(command)); Groups.unit.each(t -> t.team() == tile.team(), u -> u.controller().command(command));
Events.fire(new CommandIssueEvent(tile, command)); Events.fire(new CommandIssueEvent(tile, command));
}); });
} }
@Override
public void placed(){
super.placed();
ObjectSet<Tile> set = indexer.getAllied(team, BlockFlag.comandCenter);
if(set.size > 0){
CommandCenterEntity oe = set.first().ent();
command = oe.command;
}
}
@Override
public void removed(){
super.removed();
ObjectSet<Tile> set = indexer.getAllied(team, BlockFlag.comandCenter);
if(set.size == 1){
Groups.unit.each(t -> t.team() == team, u -> u.controller().command(UnitCommand.all[0]));
}
}
@Override @Override
public void load(){ public void load(){
super.load(); super.load();
@@ -83,6 +61,9 @@ public class CommandCenter extends Block{
} }
} }
public class CommandCenterEntity extends TileEntity{
public UnitCommand command = UnitCommand.attack;
@Override @Override
public void draw(){ public void draw(){
super.draw(); super.draw();
@@ -110,8 +91,27 @@ public class CommandCenter extends Block{
table.label(() -> command.localized()).style(Styles.outlineLabel).center().growX().get().setAlignment(Align.center); table.label(() -> command.localized()).style(Styles.outlineLabel).center().growX().get().setAlignment(Align.center);
} }
public class CommandCenterEntity extends TileEntity{ @Override
public UnitCommand command = UnitCommand.attack; public void placed(){
super.placed();
ObjectSet<Tile> set = indexer.getAllied(team, BlockFlag.comandCenter);
if(set.size > 0){
CommandCenterEntity oe = set.first().ent();
command = oe.command;
}
}
@Override
public void onRemoved(){
super.onRemoved();
ObjectSet<Tile> set = indexer.getAllied(team, BlockFlag.comandCenter);
if(set.size == 1){
Groups.unit.each(t -> t.team() == team, u -> u.controller().command(UnitCommand.all[0]));
}
}
@Override @Override
public Integer config(){ public Integer config(){

View File

@@ -1,147 +0,0 @@
package mindustry.world.blocks.units;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import java.io.*;
import static mindustry.Vars.*;
//TODO remove
public class MechPad extends Block{
public @NonNull UnitType mech;
public float buildTime = 60 * 5;
public MechPad(String name){
super(name);
update = true;
solid = false;
hasPower = true;
layer = Layer.overlay;
flags = EnumSet.of(BlockFlag.mechPad);
}
@Override
public void setStats(){
super.setStats();
stats.add(BlockStat.productionTime, buildTime / 60f, StatUnit.seconds);
}
@Remote(targets = Loc.both, called = Loc.server)
public static void onMechFactoryTap(Playerc player, Tile tile){
if(player == null || tile == null || !(tile.block() instanceof MechPad) || !checkValidTap(tile, player)) return;
if(!consValid()) return;
//player.beginRespawning(entity);
sameMech = false;
}
@Remote(called = Loc.server)
public static void onMechFactoryDone(){
if(!(tile.entity instanceof MechFactoryEntity)) return;
Fx.spawn.at(entity);
if(player == null) return;
//Mech mech = ((MechPad)tile.block()).mech;
//boolean resetSpawner = !sameMech && player.mech == mech;
//player.mech = !sameMech && player.mech == mech ? UnitTypes.starter : mech;
Playerc player = player;
//progress = 0;
//player.onRespawn(tile);
//if(resetSpawner) player.lastSpawner = null;
//player = null;
//Events.fire(new MechChangeEvent(player, player.mech));
}
protected static boolean checkValidTap(Playerc player){
return false;//!player.dead() && tile.interactable(player.team()) && Math.abs(player.x - x) <= tile.block().size * tilesize &&
//Math.abs(player.y - y) <= tile.block().size * tilesize && consValid() && player == null;
}
@Override
public void drawSelect(){
Draw.color(Pal.accent);
for(int i = 0; i < 4; i++){
float length = tilesize * size / 2f + 3 + Mathf.absin(Time.time(), 5f, 2f);
Draw.rect("transfer-arrow", x + Geometry.d4[i].x * length, y + Geometry.d4[i].y * length, (i + 2) * 90);
}
Draw.color();
}
@Override
public void tapped(Playerc player){
if(checkValidTap(tile, player)){
Call.onMechFactoryTap(player, tile);
}else if(player.isLocal() && mobile && !player.dead() && consValid() && player == null){
//deselect on double taps
//TODO remove
//player.moveTarget = player.moveTarget == tile.entity ? null : tile.entity;
}
}
@Override
public void drawLayer(){
if(player != null){
//TODO remove
//RespawnBlock.drawRespawn(tile, heat, progress, time, player, (!sameMech && player.mech == mech ? UnitTypes.starter : mech));
}
}
@Override
public void updateTile(){
if(player != null){
player.set(x, y);
heat = Mathf.lerpDelta(heat, 1f, 0.1f);
progress += 1f / buildTime * delta();
time += 0.5f * delta();
if(progress >= 1f){
Call.onMechFactoryDone(tile);
}
}else{
heat = Mathf.lerpDelta(heat, 0f, 0.1f);
}
}
public class MechFactoryEntity extends TileEntity{
Playerc player;
boolean sameMech;
float progress;
float time;
float heat;
@Override
public void write(Writes write){
super.write(write);
write.f(progress);
write.f(time);
write.f(heat);
}
@Override
public void read(Reads read, byte revision){
super.read(read, revision);
progress = read.f();
time = read.f();
heat = read.f();
}
}
}

View File

@@ -1,18 +1,16 @@
package mindustry.world.blocks.units; package mindustry.world.blocks.units;
import arc.Core; import arc.*;
import arc.struct.EnumSet; import arc.graphics.*;
import arc.graphics.Color;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.Angles; import arc.math.*;
import arc.math.Mathf; import arc.math.geom.*;
import arc.math.geom.Rect; import arc.struct.*;
import arc.util.Time; import arc.util.*;
import mindustry.entities.Units; import mindustry.entities.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.world.Block; import mindustry.world.*;
import mindustry.world.Tile;
import mindustry.world.meta.*; import mindustry.world.meta.*;
import static mindustry.Vars.tilesize; import static mindustry.Vars.tilesize;
@@ -60,16 +58,20 @@ public class RepairPoint extends Block{
super.init(); super.init();
} }
@Override
public void drawSelect(){
Drawf.dashCircle(x, y, repairRadius, Pal.accent);
}
@Override @Override
public void drawPlace(int x, int y, int rotation, boolean valid){ public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.dashCircle(x * tilesize + offset(), y * tilesize + offset(), repairRadius, Pal.accent); Drawf.dashCircle(x * tilesize + offset(), y * tilesize + offset(), repairRadius, Pal.accent);
} }
@Override
public TextureRegion[] generateIcons(){
return new TextureRegion[]{Core.atlas.find(name + "-base"), Core.atlas.find(name)};
}
public class RepairPointEntity extends TileEntity{
public Unitc target;
public float strength, rotation = 90;
@Override @Override
public void draw(){ public void draw(){
Draw.rect(baseRegion, x, y); Draw.rect(baseRegion, x, y);
@@ -96,8 +98,8 @@ public class RepairPoint extends Block{
} }
@Override @Override
public TextureRegion[] generateIcons(){ public void drawSelect(){
return new TextureRegion[]{Core.atlas.find(name + "-base"), Core.atlas.find(name)}; Drawf.dashCircle(x, y, repairRadius, Pal.accent);
} }
@Override @Override
@@ -127,9 +129,5 @@ public class RepairPoint extends Block{
public boolean shouldConsume(){ public boolean shouldConsume(){
return target != null; return target != null;
} }
public class RepairPointEntity extends TileEntity{
public Unitc target;
public float strength, rotation = 90;
} }
} }

View File

@@ -1,74 +0,0 @@
package mindustry.world.blocks.units;
import arc.graphics.g2d.*;
import arc.math.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.*;
import static mindustry.Vars.net;
//TODO remove ?
public class RespawnBlock{
public static void drawRespawn(float heat, float progress, float time, Playerc player, UnitType to){
progress = Mathf.clamp(progress);
Draw.color(Pal.darkMetal);
Lines.stroke(2f * heat);
Fill.poly(x, y, 4, 10f * heat);
Draw.reset();
if(player != null){
TextureRegion region = to.icon(Cicon.full);
Draw.color(0f, 0f, 0f, 0.4f * progress);
Draw.rect("circle-shadow", x, y, region.getWidth() / 3f, region.getWidth() / 3f);
Draw.color();
Shaders.build.region = region;
Shaders.build.progress = progress;
Shaders.build.color.set(Pal.accent);
Shaders.build.time = -time / 10f;
Draw.shader(Shaders.build, true);
Draw.rect(region, x, y);
Draw.shader();
Draw.color(Pal.accentBack);
float pos = Mathf.sin(time, 6f, 8f);
Lines.lineAngleCenter(x + pos, y, 90, 16f - Math.abs(pos) * 2f);
Draw.reset();
}
Lines.stroke(2f * heat);
Draw.color(Pal.accentBack);
Lines.poly(x, y, 4, 8f * heat);
float oy = -7f, len = 6f * heat;
Lines.stroke(5f);
Draw.color(Pal.darkMetal);
Lines.line(x - len, y + oy, x + len, y + oy, CapStyle.none);
for(int i : Mathf.signs){
Fill.tri(x + len * i, y + oy - Lines.getStroke()/2f, x + len * i, y + oy + Lines.getStroke()/2f, x + (len + Lines.getStroke() * heat) * i, y + oy);
}
Lines.stroke(3f);
Draw.color(Pal.accent);
Lines.line(x - len, y + oy, x - len + len*2 * progress, y + oy, CapStyle.none);
for(int i : Mathf.signs){
Fill.tri(x + len * i, y + oy - Lines.getStroke()/2f, x + len * i, y + oy + Lines.getStroke()/2f, x + (len + Lines.getStroke() * heat) * i, y + oy);
}
Draw.reset();
if(net.active() && player != null){
tile.drawPlaceText(player.name(), tile.x, tile.y - (Math.max((tile.block().size-1)/2, 0)), true);
}
}
}

View File

@@ -18,8 +18,6 @@ import mindustry.world.*;
import mindustry.world.consumers.*; import mindustry.world.consumers.*;
import mindustry.world.meta.*; import mindustry.world.meta.*;
import java.io.*;
import static mindustry.Vars.net; import static mindustry.Vars.net;
public class UnitFactory extends Block{ public class UnitFactory extends Block{
@@ -40,20 +38,21 @@ public class UnitFactory extends Block{
} }
@Remote(called = Loc.server) @Remote(called = Loc.server)
public static void onUnitFactorySpawn(int spawns){ public static void onUnitFactorySpawn(Tile tile, int spawns){
if(!(tile.entity instanceof UnitFactoryEntity) || !(tile.block() instanceof UnitFactory)) return; if(!(tile.entity instanceof UnitFactoryEntity) || !(tile.block() instanceof UnitFactory)) return;
UnitFactory factory = (UnitFactory)tile.block(); UnitFactory factory = (UnitFactory)tile.block();
UnitFactoryEntity entity = tile.ent();
buildTime = 0f; entity.buildTime = 0f;
spawned = spawns; entity.spawned = spawns;
Effects.shake(2f, 3f, entity); Effects.shake(2f, 3f, entity);
Fx.producesmoke.at(x, y); Fx.producesmoke.at(entity);
if(!net.client()){ if(!net.client()){
Unitc unit = factory.unitType.create(team); Unitc unit = factory.unitType.create(entity.team());
unit.set(x + Mathf.range(4), y + Mathf.range(4)); unit.set(entity.x() + Mathf.range(4), entity.y() + Mathf.range(4));
unit.add(); unit.add();
unit.vel().y = factory.launchVelocity; unit.vel().y = factory.launchVelocity;
Events.fire(new UnitCreateEvent(unit)); Events.fire(new UnitCreateEvent(unit));
@@ -101,17 +100,18 @@ public class UnitFactory extends Block{
stats.add(BlockStat.maxUnits, maxSpawn, StatUnit.none); stats.add(BlockStat.maxUnits, maxSpawn, StatUnit.none);
} }
@Override
public void unitRemoved(Unitc unit){
spawned--;
spawned = Math.max(spawned, 0);
}
@Override @Override
public TextureRegion[] generateIcons(){ public TextureRegion[] generateIcons(){
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-top")}; return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-top")};
} }
public class UnitFactoryEntity extends TileEntity{
float buildTime;
float time;
float speedScl;
int spawned;
@Override @Override
public void draw(){ public void draw(){
TextureRegion region = unitType.icon(Cicon.full); TextureRegion region = unitType.icon(Cicon.full);
@@ -160,8 +160,7 @@ public class UnitFactory extends Block{
buildTime = 0f; buildTime = 0f;
Call.onUnitFactorySpawn(tile, spawned + 1); Call.onUnitFactorySpawn(tile, spawned + 1);
useContent(tile, unitType); useContent(unitType);
consume(); consume();
} }
} }
@@ -176,12 +175,6 @@ public class UnitFactory extends Block{
return spawned < maxSpawn; return spawned < maxSpawn;
} }
public class UnitFactoryEntity extends TileEntity{
float buildTime;
float time;
float speedScl;
int spawned;
@Override @Override
public void write(Writes write){ public void write(Writes write){
super.write(write); super.write(write);