Search in sources :

Example 1 with Tile

use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.

the class Sorter method handleItem.

@Override
public void handleItem(Item item, Tile tile, Tile source) {
    Tile to = getTileTarget(item, tile, source, true);
    to.block().handleItem(item, to, tile);
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 2 with Tile

use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.

the class Sorter method getTileTarget.

Tile getTileTarget(Item item, Tile dest, Tile source, boolean flip) {
    SorterEntity entity = dest.entity();
    int dir = source.relativeTo(dest.x, dest.y);
    if (dir == -1)
        return null;
    Tile to;
    if (item == entity.sortItem) {
        to = dest.getNearby(dir);
    } else {
        Tile a = dest.getNearby(Mathf.mod(dir - 1, 4));
        Tile b = dest.getNearby(Mathf.mod(dir + 1, 4));
        boolean ac = a != null && !(a.block().instantTransfer && source.block().instantTransfer) && a.block().acceptItem(item, a, dest);
        boolean bc = b != null && !(b.block().instantTransfer && source.block().instantTransfer) && b.block().acceptItem(item, b, dest);
        if (ac && !bc) {
            to = a;
        } else if (bc && !ac) {
            to = b;
        } else if (!bc) {
            return null;
        } else {
            if (dest.getDump() == 0) {
                to = a;
                if (flip)
                    dest.setDump((byte) 1);
            } else {
                to = b;
                if (flip)
                    dest.setDump((byte) 0);
            }
        }
    }
    return to;
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 3 with Tile

use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.

the class TunnelConveyor method handleItem.

@Override
public void handleItem(Item item, Tile tile, Tile source) {
    TunnelEntity entity = tile.entity();
    if (entity.index >= entity.buffer.length)
        return;
    Tile tunnel = getDestTunnel(tile, item);
    if (tunnel == null)
        return;
    Tile to = tunnel.getNearby(tunnel.getRotation());
    if (to == null)
        return;
    entity.buffer[entity.index++] = Bits.packLong(NumberUtils.floatToIntBits(Timers.time()), item.id);
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 4 with Tile

use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.

the class TunnelConveyor method update.

@Override
public void update(Tile tile) {
    TunnelEntity entity = tile.entity();
    if (entity.index > 0) {
        long l = entity.buffer[0];
        float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
        if (Timers.time() >= time + speed || Timers.time() < time) {
            Item item = Item.getByID(Bits.getRightInt(l));
            Tile tunnel = getDestTunnel(tile, item);
            if (tunnel == null)
                return;
            Tile target = tunnel.getNearby(tunnel.getRotation());
            if (target == null)
                return;
            if (!target.block().acceptItem(item, target, tunnel))
                return;
            target.block().handleItem(item, target, tunnel);
            System.arraycopy(entity.buffer, 1, entity.buffer, 0, entity.index - 1);
            entity.index--;
        }
    }
}
Also used : Item(io.anuke.mindustry.resource.Item) Tile(io.anuke.mindustry.world.Tile)

Example 5 with Tile

use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.

the class Generator method distributeLaserPower.

protected void distributeLaserPower(Tile tile) {
    PowerEntity entity = tile.entity();
    for (int i = 0; i < laserDirections; i++) {
        int rot = (tile.getRotation() + i) - laserDirections / 2;
        Tile target = laserTarget(tile, rot);
        if (target == null || isInterfering(target, rot))
            continue;
        PowerAcceptor p = (PowerAcceptor) target.block();
        float transmit = Math.min(powerSpeed * Timers.delta(), entity.power);
        if (p.acceptsPower(target)) {
            float accepted = p.addPower(target, transmit);
            entity.power -= accepted;
        }
    }
}
Also used : PowerAcceptor(io.anuke.mindustry.world.blocks.types.PowerAcceptor) Tile(io.anuke.mindustry.world.Tile)

Aggregations

Tile (io.anuke.mindustry.world.Tile)45 Enemy (io.anuke.mindustry.entities.enemies.Enemy)10 Item (io.anuke.mindustry.resource.Item)7 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)6 Block (io.anuke.mindustry.world.Block)6 Vector2 (com.badlogic.gdx.math.Vector2)5 IOException (java.io.IOException)5 Array (com.badlogic.gdx.utils.Array)4 Player (io.anuke.mindustry.entities.Player)3 BlockPart (io.anuke.mindustry.world.blocks.types.BlockPart)3 PowerAcceptor (io.anuke.mindustry.world.blocks.types.PowerAcceptor)3 Rock (io.anuke.mindustry.world.blocks.types.Rock)3 IntMap (com.badlogic.gdx.utils.IntMap)2 LiquidBlock (io.anuke.mindustry.world.blocks.types.LiquidBlock)2 StaticBlock (io.anuke.mindustry.world.blocks.types.StaticBlock)2 GridPoint2 (com.badlogic.gdx.math.GridPoint2)1 Rectangle (com.badlogic.gdx.math.Rectangle)1 Vars (io.anuke.mindustry.Vars)1 TileEntity (io.anuke.mindustry.entities.TileEntity)1 Difficulty (io.anuke.mindustry.game.Difficulty)1