Set IPT instruction

This commit is contained in:
Anuken
2022-02-14 11:39:27 -05:00
parent ea639dfee0
commit bea112a63c
4 changed files with 79 additions and 9 deletions

View File

@@ -3543,7 +3543,7 @@ public class Blocks{
requirements(Category.units, with(Items.graphite, 600, Items.beryllium, 600, Items.oxide, 250, Items.tungsten, 400, Items.silicon, 500));
size = 5;
//TODO remove ducts and crushers, replace with 2-3 high cost special blocks with silicon requirements
plans.add(new AssemblerUnitPlan(UnitTypes.vanquish, 60f * 50f, BlockStack.list(Blocks.tungstenWallLarge, 12, Blocks.duct, 14, Blocks.cliffCrusher, 12)));
plans.add(new AssemblerUnitPlan(UnitTypes.vanquish, 60f * 50f, BlockStack.list(Blocks.tungstenWallLarge, 12, Blocks.cliffCrusher, 12)));
consumes.power(3f);
areaSize = 13;
researchCostMultiplier = 0.4f;
@@ -3555,7 +3555,7 @@ public class Blocks{
shipAssembler = new UnitAssembler("ship-assembler"){{
requirements(Category.units, with(Items.beryllium, 700, Items.oxide, 300, Items.tungsten, 500, Items.silicon, 800));
size = 5;
plans.add(new AssemblerUnitPlan(UnitTypes.quell, 60f * 60f, BlockStack.list(Blocks.berylliumWallLarge, 12, Blocks.duct, 20, Blocks.plasmaBore, 8)));
plans.add(new AssemblerUnitPlan(UnitTypes.quell, 60f * 60f, BlockStack.list(Blocks.berylliumWallLarge, 12, Blocks.plasmaBore, 8)));
consumes.power(3f);
areaSize = 13;
@@ -3566,7 +3566,7 @@ public class Blocks{
mechAssembler = new UnitAssembler("mech-assembler"){{
requirements(Category.units, with(Items.graphite, 500, Items.carbide, 600, Items.oxide, 200, Items.tungsten, 500, Items.silicon, 900));
size = 5;
plans.add(new AssemblerUnitPlan(UnitTypes.bulwark, 60f * 60f, BlockStack.list(Blocks.tungstenWallLarge, 5, Blocks.duct, 2)));
plans.add(new AssemblerUnitPlan(UnitTypes.bulwark, 60f * 60f, BlockStack.list(Blocks.tungstenWallLarge, 5)));
consumes.power(3f);
areaSize = 13;
@@ -3860,12 +3860,12 @@ public class Blocks{
worldProcessor = new LogicBlock("world-processor"){{
requirements(Category.logic, BuildVisibility.editorOnly, with());
//TODO customizable IPT
targetable = false;
instructionsPerTick = 8;
forceDark = true;
privileged = true;
size = 1;
maxInstructionsPerTick = 30;
}};
worldCell = new MemoryBlock("world-cell"){{

View File

@@ -19,6 +19,7 @@ import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.environment.*;
import mindustry.world.blocks.logic.*;
import mindustry.world.blocks.logic.LogicBlock.*;
import mindustry.world.blocks.logic.LogicDisplay.*;
import mindustry.world.blocks.logic.MemoryBlock.*;
import mindustry.world.blocks.logic.MessageBlock.*;
@@ -46,9 +47,11 @@ public class LExecutor{
public Var counter;
public int[] binds;
public int iptIndex = -1;
public LongSeq graphicsBuffer = new LongSeq();
public StringBuilder textBuffer = new StringBuilder();
public Building[] links = {};
public @Nullable LogicBuild build;
public IntSet linkIds = new IntSet();
public Team team = Team.derelict;
public boolean privileged = false;
@@ -73,10 +76,14 @@ public class LExecutor{
public void load(LAssembler builder){
vars = new Var[builder.vars.size];
instructions = builder.instructions;
iptIndex = -1;
builder.vars.each((name, var) -> {
Var dest = new Var(name);
vars[var.id] = dest;
if(dest.name.equals("@ipt")){
iptIndex = var.id;
}
dest.constant = var.constant;
@@ -1364,5 +1371,26 @@ public class LExecutor{
}
}
public static class SetRateI implements LInstruction{
public int amount;
public SetRateI(int amount){
this.amount = amount;
}
public SetRateI(){
}
@Override
public void run(LExecutor exec){
if(exec.build != null && exec.build.block.privileged){
exec.build.ipt = Mathf.clamp(exec.numi(amount), 1, ((LogicBlock)exec.build.block).maxInstructionsPerTick);
if(exec.iptIndex >= 0 && exec.vars.length > exec.iptIndex){
exec.vars[exec.iptIndex].numval = exec.build.ipt;
}
}
}
}
//endregion
}

View File

@@ -1403,4 +1403,29 @@ public class LStatements{
return new ExplosionI(b.var(team), b.var(x), b.var(y), b.var(radius), b.var(damage), b.var(air), b.var(ground), b.var(pierce));
}
}
@RegisterStatement("setrate")
public static class SetRateStatement extends LStatement{
public String amount = "10";
@Override
public void build(Table table){
fields(table, "ipt = ", amount, str -> amount = str);
}
@Override
public boolean privileged(){
return true;
}
@Override
public Color color(){
return Pal.logicWorld;
}
@Override
public LInstruction build(LAssembler builder){
return new SetRateI(builder.var(amount));
}
}
}

View File

@@ -33,6 +33,8 @@ public class LogicBlock extends Block{
public int maxInstructionScale = 5;
public int instructionsPerTick = 1;
//privileged only
public int maxInstructionsPerTick = 40;
public float range = 8 * 10;
public LogicBlock(String name){
@@ -220,12 +222,15 @@ public class LogicBlock extends Block{
public float accumulator = 0;
public Seq<LogicLink> links = new Seq<>();
public boolean checkedDuplicates = false;
//dynamic only for privileged processors
public int ipt = instructionsPerTick;
/** Block of code to run after load. */
public @Nullable Runnable loadBlock;
{
executor.privileged = privileged;
executor.build = this;
}
public void readCompressed(byte[] data, boolean relative){
@@ -474,10 +479,14 @@ public class LogicBlock extends Block{
updateCode(code, true, null);
}
if(enabled && executor.initialized()){
accumulator += edelta() * instructionsPerTick * (consValid() ? 1 : 0);
if(!privileged){
ipt = instructionsPerTick;
}
if(accumulator > maxInstructionScale * instructionsPerTick) accumulator = maxInstructionScale * instructionsPerTick;
if(enabled && executor.initialized()){
accumulator += edelta() * ipt * (consValid() ? 1 : 0);
if(accumulator > maxInstructionScale * ipt) accumulator = maxInstructionScale * ipt;
for(int i = 0; i < (int)accumulator; i++){
executor.runOnce();
@@ -567,7 +576,7 @@ public class LogicBlock extends Block{
@Override
public byte version(){
return 1;
return 2;
}
@Override
@@ -600,13 +609,17 @@ public class LogicBlock extends Block{
//no memory
write.i(0);
if(privileged){
write.s(ipt);
}
}
@Override
public void read(Reads read, byte revision){
super.read(read, revision);
if(revision == 1){
if(revision >= 1){
int compl = read.i();
byte[] bytes = new byte[compl];
read.b(bytes);
@@ -652,6 +665,10 @@ public class LogicBlock extends Block{
}
});
if(privileged && revision >= 2){
ipt = Math.max(read.s(), 1);
}
}
}
}