This commit is contained in:
Anuken
2020-08-11 12:48:17 -04:00
parent d85f6c72eb
commit 188171ec03
10 changed files with 36 additions and 19 deletions

View File

@ -6,6 +6,7 @@ import arc.util.*;
import mindustry.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.world.*;
import mindustry.world.blocks.payloads.*;
@ -69,17 +70,22 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc{
boolean dropUnit(UnitPayload payload){
Unit u = payload.unit;
Fx.unitDrop.at(this);
//can't drop ground units
if((tileOn() == null || tileOn().solid()) && u.elevation < 0.1f){
return false;
}
//clients do not drop payloads
if(Vars.net.client()) return true;
u.set(this);
u.trns(Tmp.v1.rnd(Mathf.random(2f)));
u.rotation(rotation);
//reset the ID to a new value to make sure it's synced
u.id = EntityGroup.nextId();
u.add();
Fx.unitDrop.at(u);
return true;
}

View File

@ -42,10 +42,10 @@ public class OverlayRenderer{
if(!rect.setSize(Core.camera.width * 0.9f, Core.camera.height * 0.9f)
.setCenter(Core.camera.position.x, Core.camera.position.y).contains(player.x, player.y)){
Tmp.v1.set(player.x, player.y).sub(player).setLength(indicatorLength);
Tmp.v1.set(player).sub(Vars.player).setLength(indicatorLength);
Lines.stroke(2f, player.team().color);
Lines.lineAngle(player.x + Tmp.v1.x, player.y + Tmp.v1.y, Tmp.v1.angle(), 4f);
Lines.stroke(2f, Vars.player.team().color);
Lines.lineAngle(Vars.player.x + Tmp.v1.x, Vars.player.y + Tmp.v1.y, Tmp.v1.angle(), 4f);
Draw.reset();
}
}

View File

@ -49,7 +49,6 @@ public class TypeIO{
}else if(object instanceof String){
write.b((byte)4);
writeString(write, (String)object);
writeString(write, (String)object);
}else if(object instanceof Content){
Content map = (Content)object;
write.b((byte)5);

View File

@ -45,10 +45,10 @@ public class LAssembler{
}
}
public static LAssembler assemble(String data){
public static LAssembler assemble(String data, int maxInstructions){
LAssembler asm = new LAssembler();
Seq<LStatement> st = read(data);
Seq<LStatement> st = read(data, maxInstructions);
asm.instructions = st.map(l -> l.build(asm)).filter(l -> l != null).toArray(LInstruction.class);
return asm;
@ -65,15 +65,22 @@ public class LAssembler{
}
public static Seq<LStatement> read(String data){
return read(data, Integer.MAX_VALUE);
}
public static Seq<LStatement> read(String data, int max){
//empty data check
if(data == null || data.isEmpty()) return new Seq<>();
Seq<LStatement> statements = new Seq<>();
String[] lines = data.split("[;\n]+");
int index = 0;
for(String line : lines){
//comments
if(line.startsWith("#")) continue;
if(index++ > max) continue;
try{
//yes, I am aware that this can be split with regex, but that's slow and even more incomprehensible
Seq<String> tokens = new Seq<>();

View File

@ -19,6 +19,7 @@ import mindustry.graphics.*;
import mindustry.logic.LStatements.*;
import mindustry.ui.*;
import mindustry.ui.dialogs.*;
import mindustry.world.blocks.logic.*;
public class LCanvas extends Table{
private static final Color backgroundCol = Pal.darkMetal.cpy().mul(0.1f), gridCol = Pal.darkMetal.cpy().mul(0.5f);
@ -56,7 +57,7 @@ public class LCanvas extends Table{
});
dialog.addCloseButton();
dialog.show();
}).height(50f).left().width(400f).marginLeft(10f);
}).height(50f).left().width(400f).marginLeft(10f).disabled(t -> statements.getChildren().size >= LogicBlock.maxInstructions);
}
private void drawGrid(){

View File

@ -47,8 +47,8 @@ public class LExecutor{
}
}
public void load(String data){
load(LAssembler.assemble(data));
public void load(String data, int maxInstructions){
load(LAssembler.assemble(data, maxInstructions));
}
/** Loads with a specified assembler. Resets all variables. */

View File

@ -95,7 +95,10 @@ public abstract class LStatement{
});
t.actions(Actions.alpha(0), Actions.fadeIn(0.3f, Interp.fade));
hideCons.get(t, hide);
t.top().pane(inner -> {
inner.top();
hideCons.get(inner, hide);
}).top();
t.pack();
}

View File

@ -450,10 +450,10 @@ public class LStatements{
stack.clearChildren();
stack.addChild(tables[selected]);
t.pack();
}).size(80f, 50f).checked(selected == fi).group(group);
}).size(80f, 50f).growX().checked(selected == fi).group(group);
}
t.row();
t.add(stack).colspan(3).expand().left();
t.add(stack).colspan(3).width(240f).left();
}));
}, Styles.logict, () -> {}).size(40f).padLeft(-1).color(table.color);
@ -614,7 +614,7 @@ public class LStatements{
//elements need separate conversion logic
@Override
public void setupUI(){
if(elem != null && destIndex > 0 && destIndex < elem.parent.getChildren().size){
if(elem != null && destIndex >= 0 && destIndex < elem.parent.getChildren().size){
dest = (StatementElem)elem.parent.getChildren().get(destIndex);
}
}

View File

@ -85,9 +85,9 @@ public class Administration{
return true;
}else{
if(rate.occurences > Config.interactRateKick.num()){
player.kick("You are interacting with too many blocks.", 1000 * 30);
action.player.kick("You are interacting with too many blocks.", 1000 * 30);
}else{
player.sendMessage("[scarlet]You are interacting with blocks too quickly.");
action.player.sendMessage("[scarlet]You are interacting with blocks too quickly.");
}
return false;

View File

@ -20,8 +20,9 @@ import static mindustry.Vars.*;
public class LogicBlock extends Block{
private static final IntSeq removal = new IntSeq();
public static final int maxInstructions = 2000;
public int maxInstructionScale = 8;
public int maxInstructionScale = 5;
public int instructionsPerTick = 1;
public float range = 8 * 10;
@ -79,7 +80,7 @@ public class LogicBlock extends Block{
try{
//create assembler to store extra variables
LAssembler asm = LAssembler.assemble(str);
LAssembler asm = LAssembler.assemble(str, maxInstructions);
//store connections
for(int i = 0; i < connections.size; i++){
@ -108,7 +109,7 @@ public class LogicBlock extends Block{
e.printStackTrace();
//handle malformed code and replace it with nothing
executor.load("");
executor.load("", maxInstructions);
}
}
}