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

View File

@@ -42,10 +42,10 @@ public class OverlayRenderer{
if(!rect.setSize(Core.camera.width * 0.9f, Core.camera.height * 0.9f) 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)){ .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.stroke(2f, Vars.player.team().color);
Lines.lineAngle(player.x + Tmp.v1.x, player.y + Tmp.v1.y, Tmp.v1.angle(), 4f); Lines.lineAngle(Vars.player.x + Tmp.v1.x, Vars.player.y + Tmp.v1.y, Tmp.v1.angle(), 4f);
Draw.reset(); Draw.reset();
} }
} }

View File

@@ -49,7 +49,6 @@ public class TypeIO{
}else if(object instanceof String){ }else if(object instanceof String){
write.b((byte)4); write.b((byte)4);
writeString(write, (String)object); writeString(write, (String)object);
writeString(write, (String)object);
}else if(object instanceof Content){ }else if(object instanceof Content){
Content map = (Content)object; Content map = (Content)object;
write.b((byte)5); 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(); 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); asm.instructions = st.map(l -> l.build(asm)).filter(l -> l != null).toArray(LInstruction.class);
return asm; return asm;
@@ -65,15 +65,22 @@ public class LAssembler{
} }
public static Seq<LStatement> read(String data){ 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 //empty data check
if(data == null || data.isEmpty()) return new Seq<>(); if(data == null || data.isEmpty()) return new Seq<>();
Seq<LStatement> statements = new Seq<>(); Seq<LStatement> statements = new Seq<>();
String[] lines = data.split("[;\n]+"); String[] lines = data.split("[;\n]+");
int index = 0;
for(String line : lines){ for(String line : lines){
//comments //comments
if(line.startsWith("#")) continue; if(line.startsWith("#")) continue;
if(index++ > max) continue;
try{ try{
//yes, I am aware that this can be split with regex, but that's slow and even more incomprehensible //yes, I am aware that this can be split with regex, but that's slow and even more incomprehensible
Seq<String> tokens = new Seq<>(); Seq<String> tokens = new Seq<>();

View File

@@ -19,6 +19,7 @@ import mindustry.graphics.*;
import mindustry.logic.LStatements.*; import mindustry.logic.LStatements.*;
import mindustry.ui.*; import mindustry.ui.*;
import mindustry.ui.dialogs.*; import mindustry.ui.dialogs.*;
import mindustry.world.blocks.logic.*;
public class LCanvas extends Table{ public class LCanvas extends Table{
private static final Color backgroundCol = Pal.darkMetal.cpy().mul(0.1f), gridCol = Pal.darkMetal.cpy().mul(0.5f); 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.addCloseButton();
dialog.show(); 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(){ private void drawGrid(){

View File

@@ -47,8 +47,8 @@ public class LExecutor{
} }
} }
public void load(String data){ public void load(String data, int maxInstructions){
load(LAssembler.assemble(data)); load(LAssembler.assemble(data, maxInstructions));
} }
/** Loads with a specified assembler. Resets all variables. */ /** 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)); 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(); t.pack();
} }

View File

@@ -450,10 +450,10 @@ public class LStatements{
stack.clearChildren(); stack.clearChildren();
stack.addChild(tables[selected]); stack.addChild(tables[selected]);
t.pack(); t.pack();
}).size(80f, 50f).checked(selected == fi).group(group); }).size(80f, 50f).growX().checked(selected == fi).group(group);
} }
t.row(); 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); }, Styles.logict, () -> {}).size(40f).padLeft(-1).color(table.color);
@@ -614,7 +614,7 @@ public class LStatements{
//elements need separate conversion logic //elements need separate conversion logic
@Override @Override
public void setupUI(){ 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); dest = (StatementElem)elem.parent.getChildren().get(destIndex);
} }
} }

View File

@@ -85,9 +85,9 @@ public class Administration{
return true; return true;
}else{ }else{
if(rate.occurences > Config.interactRateKick.num()){ 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{ }else{
player.sendMessage("[scarlet]You are interacting with blocks too quickly."); action.player.sendMessage("[scarlet]You are interacting with blocks too quickly.");
} }
return false; return false;

View File

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