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;
}
}
}
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;
}
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());
}
}
}
Aggregations