Turret-based radar
This commit is contained in:
@@ -44,10 +44,5 @@ public class PowerTurret extends Turret{
|
||||
public BulletType peekAmmo(){
|
||||
return shootType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float baseReloadSpeed(){
|
||||
return cheating() ? 1f : power.status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public abstract class Turret extends Block{
|
||||
public abstract BulletType type();
|
||||
}
|
||||
|
||||
public class TurretEntity extends Building implements ControlBlock{
|
||||
public class TurretEntity extends Building implements ControlBlock, Ranged{
|
||||
public Seq<AmmoEntry> ammo = new Seq<>();
|
||||
public int totalAmmo;
|
||||
public float reload, rotation = 90, recoil, heat, logicControlTime = -1;
|
||||
@@ -151,6 +151,11 @@ public abstract class Turret extends Block{
|
||||
public Vec2 targetPos = new Vec2();
|
||||
public @NonNull BlockUnitc unit = Nulls.blockUnit;
|
||||
|
||||
@Override
|
||||
public float range(){
|
||||
return range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void created(){
|
||||
unit = (BlockUnitc)UnitTypes.block.create(team);
|
||||
@@ -168,6 +173,15 @@ public abstract class Turret extends Block{
|
||||
super.control(type, p1, p2, p3, p4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sense(LAccess sensor){
|
||||
if(sensor == LAccess.shootX) return targetPos.x;
|
||||
if(sensor == LAccess.shootY) return targetPos.y;
|
||||
if(sensor == LAccess.shooting) return (isControlled() ? unit.isShooting() : logicControlled() ? logicShooting : validateTarget()) ? 1 : 0;
|
||||
|
||||
return super.sense(sensor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Unit unit(){
|
||||
return (Unit)unit;
|
||||
@@ -407,7 +421,7 @@ public abstract class Turret extends Block{
|
||||
}
|
||||
|
||||
protected float baseReloadSpeed(){
|
||||
return 1f;
|
||||
return efficiency();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -67,6 +67,7 @@ public class LogicBlock extends Block{
|
||||
public LExecutor executor = new LExecutor();
|
||||
public float accumulator = 0;
|
||||
public IntSeq connections = new IntSeq();
|
||||
public IntSeq invalidConnections = new IntSeq();
|
||||
public boolean loaded = false;
|
||||
|
||||
public LogicEntity(){
|
||||
@@ -130,6 +131,22 @@ public class LogicBlock extends Block{
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
//check for previously invalid links to add after configuration
|
||||
removal.clear();
|
||||
|
||||
for(int i = 0; i < invalidConnections.size; i++){
|
||||
int val = invalidConnections.get(i);
|
||||
if(validLink(val) && !connections.contains(val)){
|
||||
removal.add(val);
|
||||
}
|
||||
}
|
||||
|
||||
if(!removal.isEmpty()){
|
||||
connections.addAll(removal);
|
||||
invalidConnections.removeAll(removal);
|
||||
updateCode(code);
|
||||
}
|
||||
|
||||
//remove invalid links
|
||||
removal.clear();
|
||||
|
||||
@@ -141,11 +158,11 @@ public class LogicBlock extends Block{
|
||||
}
|
||||
|
||||
if(!removal.isEmpty()){
|
||||
invalidConnections.addAll(removal);
|
||||
connections.removeAll(removal);
|
||||
updateCode(code);
|
||||
}
|
||||
|
||||
connections.removeAll(removal);
|
||||
|
||||
accumulator += edelta() * instructionsPerTick;
|
||||
|
||||
if(accumulator > maxInstructionScale * instructionsPerTick) accumulator = maxInstructionScale * instructionsPerTick;
|
||||
@@ -258,6 +275,7 @@ public class LogicBlock extends Block{
|
||||
write.str(v.name);
|
||||
|
||||
Object value = v.isobj ? v.objval : v.numval;
|
||||
if(value instanceof Unit) value = null; //do not save units.
|
||||
TypeIO.writeObject(write, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package mindustry.world.blocks.logic;
|
||||
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
public class MemoryBlock extends Block{
|
||||
public int memoryCapacity = 32;
|
||||
|
||||
public MemoryBlock(String name){
|
||||
super(name);
|
||||
destructible = true;
|
||||
}
|
||||
|
||||
public class MemoryEntity extends Building{
|
||||
public double[] memory = new double[memoryCapacity];
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
|
||||
write.i(memory.length);
|
||||
for(double v : memory){
|
||||
write.d(v);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
|
||||
int amount = read.i();
|
||||
memory = memory.length != amount ? new double[amount] : memory;
|
||||
for(int i = 0; i < amount; i++){
|
||||
memory[i] = read.d();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user