use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class TunnelConveyor method getDestTunnel.
Tile getDestTunnel(Tile tile, Item item) {
Tile dest = tile;
int rel = (tile.getRotation() + 2) % 4;
for (int i = 0; i < maxdist; i++) {
if (dest == null)
return null;
dest = dest.getNearby(rel);
if (dest != null && dest.block() instanceof TunnelConveyor && dest.getRotation() == rel && dest.getNearby(rel) != null && dest.getNearby(rel).block().acceptItem(item, dest.getNearby(rel), dest)) {
return dest;
}
}
return null;
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class Generator method laserTarget.
protected Tile laserTarget(Tile tile, int rotation) {
rotation = Mathf.mod(rotation, 4);
GridPoint2 point = Geometry.d4[rotation];
for (int i = 1; i < laserRange; i++) {
Tile other = world.tile(tile.x + i * point.x, tile.y + i * point.y);
if (other != null && other.block() instanceof PowerAcceptor) {
Tile linked = other.getLinked();
if (linked == null || linked instanceof PowerAcceptor) {
return other;
}
}
}
return null;
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class Junction method update.
@Override
public void update(Tile tile) {
JunctionEntity entity = tile.entity();
for (int i = 0; i < 2; i++) {
Buffer buffer = (i == 0 ? entity.bx : entity.by);
if (buffer.index > 0) {
if (buffer.index > buffer.items.length)
buffer.index = buffer.items.length;
long l = buffer.items[0];
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
if (Timers.time() >= time + speed || Timers.time() < time) {
int val = Bits.getRightInt(l);
Item item = Item.getByID(Bits.getLeftShort(val));
int direction = Bits.getRightShort(val);
Tile dest = tile.getNearby(direction);
if (dest == null || !dest.block().acceptItem(item, dest, tile))
continue;
dest.block().handleItem(item, dest, tile);
System.arraycopy(buffer.items, 1, buffer.items, 0, buffer.index - 1);
buffer.index--;
}
}
}
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class PowerBooster method distributePower.
// TODO better distribution
protected void distributePower(Tile tile) {
PowerEntity p = tile.entity();
if (!p.timer.get(timerGenerate, powerTime)) {
return;
}
int acceptors = 0;
float flow = 0f;
for (int i = 0; i < 2; i++) {
for (int x = -powerRange; x <= powerRange; x++) {
for (int y = -powerRange; y <= powerRange; y++) {
if (x == 0 && y == 0) {
continue;
}
if (Vector2.dst(x, y, 0, 0) < powerRange) {
Tile dest = world.tile(tile.x + x, tile.y + y);
if (dest != null && dest.block() instanceof PowerAcceptor && ((PowerAcceptor) dest.block()).acceptsPower(dest)) {
if (i == 1) {
PowerAcceptor block = (PowerAcceptor) dest.block();
float transmission = Math.min(flow, p.power);
float amount = block.addPower(dest, transmission);
p.power -= amount;
} else {
acceptors++;
}
}
}
}
}
// TODO better distribution scheme
if (i == 0 && acceptors > 0) {
flow = Mathf.clamp(p.power / acceptors, 0f, powerSpeed / acceptors * Timers.delta());
}
}
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class RepairTurret method drawLayer2.
@Override
public void drawLayer2(Tile tile) {
PowerTurretEntity entity = tile.entity();
TileEntity target = entity.blockTarget;
if (entity.power >= powerUsed && target != null && Angles.angleDist(entity.angleTo(target), entity.rotation) < 10) {
Tile targetTile = target.tile;
float len = 4f;
float x = tile.drawx() + Angles.trnsx(entity.rotation, len), y = tile.drawy() + Angles.trnsy(entity.rotation, len);
float x2 = targetTile.drawx(), y2 = targetTile.drawy();
Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 14f));
Draw.alpha(0.3f);
Lines.stroke(4f);
Lines.line(x, y, x2, y2);
Lines.stroke(2f);
Draw.rect("circle", x2, y2, 7f, 7f);
Draw.alpha(1f);
Lines.stroke(2f);
Lines.line(x, y, x2, y2);
Lines.stroke(1f);
Draw.rect("circle", x2, y2, 5f, 5f);
Draw.reset();
}
}
Aggregations