World play area rule

This commit is contained in:
Anuken
2022-02-16 12:45:48 -05:00
parent e2c7c94663
commit 427d43039b
15 changed files with 196 additions and 54 deletions
+57 -2
View File
@@ -1269,11 +1269,15 @@ public class LExecutor{
public static class SetRuleI implements LInstruction{
public LogicRule rule = LogicRule.waveSpacing;
public int value;
public int value, p1, p2, p3, p4;
public SetRuleI(LogicRule rule, int value){
public SetRuleI(LogicRule rule, int value, int p1, int p2, int p3, int p4){
this.rule = rule;
this.value = value;
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
this.p4 = p4;
}
public SetRuleI(){
@@ -1291,11 +1295,62 @@ public class LExecutor{
case dropZoneRadius -> state.rules.dropZoneRadius = exec.numf(value) * 8f;
case unitCap -> state.rules.unitCap = exec.numi(value);
case lighting -> state.rules.lighting = exec.bool(value);
case mapArea -> {
int x = exec.numi(p1), y = exec.numi(p2), w = exec.numi(p3), h = exec.numi(p4);
if(!checkMapArea(x, y, w, h, false)){
Call.setMapArea(x, y, w, h);
}
}
case ambientLight -> state.rules.ambientLight.fromDouble(exec.num(value));
}
}
}
/** @return whether the map area is already set to this value. */
static boolean checkMapArea(int x, int y, int w, int h, boolean set){
x = Math.max(x, 0);
y = Math.max(y, 0);
w = Math.min(world.width(), w);
h = Math.min(world.height(), h);
boolean full = x == 0 && y == 0 && w == world.width() && h == world.height();
if(state.rules.limitMapArea){
if(state.rules.limitX == x && state.rules.limitY == y && state.rules.limitWidth == w && state.rules.limitHeight == h){
return true;
}else if(full){
//disable the rule, covers the whole map
if(set){
state.rules.limitMapArea = false;
if(!headless){
renderer.updateAllDarkness();
}
return false;
}
}
}else if(full){ //was already disabled, no need to change anything
return true;
}
if(set){
state.rules.limitMapArea = true;
state.rules.limitX = x;
state.rules.limitY = y;
state.rules.limitWidth = w;
state.rules.limitHeight = h;
if(!headless){
renderer.updateAllDarkness();
}
}
return false;
}
@Remote(called = Loc.server)
public static void setMapArea(int x, int y, int w, int h){
checkMapArea(x, y, w, h, true);
}
public static class FlushMessageI implements LInstruction{
public MessageType type = MessageType.announce;
public int duration;
+24 -4
View File
@@ -1237,18 +1237,38 @@ public class LStatements{
@RegisterStatement("setrule")
public static class SetRuleStatement extends LStatement{
public LogicRule rule = LogicRule.waveSpacing;
public String value = "100";
public String value = "100", p1 = "0", p2 = "0", p3 = "100", p4 = "100";
@Override
public void build(Table table){
rebuild(table);
}
void rebuild(Table table){
table.clearChildren();
table.button(b -> {
b.label(() -> rule.name()).growX().wrap().labelAlign(Align.center);
b.clicked(() -> showSelect(b, LogicRule.all, rule, o -> rule = o, 2, c -> c.width(150f)));
b.clicked(() -> showSelect(b, LogicRule.all, rule, o -> {
rule = o;
rebuild(table);
}, 2, c -> c.width(150f)));
}, Styles.logict, () -> {}).size(160f, 40f).pad(4f).color(table.color);
table.add(" = ");
field(table, value, s -> value = s);
switch(rule){
case mapArea -> {
fields(table, "x", p1, s -> p1 = s);
fields(table, "y", p2, s -> p2 = s);
row(table);
fields(table, "w", p3, s -> p3 = s);
fields(table, "h", p4, s -> p4 = s);
}
default -> {
field(table, value, s -> value = s);
}
}
}
@Override
@@ -1263,7 +1283,7 @@ public class LStatements{
@Override
public LInstruction build(LAssembler builder){
return new SetRuleI(rule, builder.var(value));
return new SetRuleI(rule, builder.var(value), builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4));
}
}
+1
View File
@@ -9,6 +9,7 @@ public enum LogicRule{
enemyCoreBuildRadius,
dropZoneRadius,
unitCap,
mapArea,
lighting,
ambientLight;