Search in sources :

Example 1 with PowerAcceptor

use of io.anuke.mindustry.world.blocks.types.PowerAcceptor 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)

Example 2 with PowerAcceptor

use of io.anuke.mindustry.world.blocks.types.PowerAcceptor 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;
}
Also used : PowerAcceptor(io.anuke.mindustry.world.blocks.types.PowerAcceptor) Tile(io.anuke.mindustry.world.Tile) GridPoint2(com.badlogic.gdx.math.GridPoint2)

Example 3 with PowerAcceptor

use of io.anuke.mindustry.world.blocks.types.PowerAcceptor 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());
        }
    }
}
Also used : PowerAcceptor(io.anuke.mindustry.world.blocks.types.PowerAcceptor) Tile(io.anuke.mindustry.world.Tile)

Aggregations

Tile (io.anuke.mindustry.world.Tile)3 PowerAcceptor (io.anuke.mindustry.world.blocks.types.PowerAcceptor)3 GridPoint2 (com.badlogic.gdx.math.GridPoint2)1