Logic rule instruction / Lock erekir proc sectors

This commit is contained in:
Anuken
2022-02-10 09:36:31 -05:00
parent 63ef847690
commit 04c2bbc24d
16 changed files with 179 additions and 17 deletions

View File

@@ -3177,7 +3177,7 @@ public class Blocks{
new RegionPart("-back"){{
progress = PartProgress.warmup;
mirror = true;
rotMove = 40f;
moveRot = 40f;
x = 22 / 4f;
y = -1f / 4f;
moveY = 6f / 4f;
@@ -3187,7 +3187,7 @@ public class Blocks{
new RegionPart("-front"){{
progress = PartProgress.warmup;
mirror = true;
rotMove = 40f;
moveRot = 40f;
x = 20 / 4f;
y = 17f / 4f;
moveX = 1f;
@@ -3296,7 +3296,7 @@ public class Blocks{
mirror = true;
moveX = 2f * 4f / 3f;
moveY = -0.5f;
rotMove = -40f;
moveRot = -40f;
under = true;
heatColor = Color.red.cpy();
}});

View File

@@ -2542,7 +2542,7 @@ public class UnitTypes{
under = true;
moveX = 0.75f;
moveY = 0.75f;
rotMove = 82f;
moveRot = 82f;
x = 37 / 4f;
y = 8 / 4f;
}},
@@ -2578,7 +2578,7 @@ public class UnitTypes{
heatColor = new Color(1f, 0.1f, 0.1f);
mirror = true;
under = true;
rotMove = -40f * fi;
moveRot = -40f * fi;
moveX = 3f;
layerOffset = -0.002f;
@@ -2845,7 +2845,7 @@ public class UnitTypes{
y = 10f / 4f;
moveY = 1f - fi * 3f;
moveX = fi * 0.5f;
rotMove = -30f - fi * 15f;
moveRot = -30f - fi * 15f;
}});
}
@@ -3020,7 +3020,7 @@ public class UnitTypes{
heatColor = Color.valueOf("9c50ff");
x = 5 / 4f;
y = 0f;
rotMove = -33f;
moveRot = -33f;
moveY = -1f;
moveX = -1f;
under = true;
@@ -3059,7 +3059,7 @@ public class UnitTypes{
parts.add(new RegionPart("-fin"){{
mirror = true;
progress = PartProgress.life.mul(3f).curve(Interp.pow5In);
rotMove = 32f;
moveRot = 32f;
rotation = -6f;
moveY = 1.5f;
x = 3f / 4f;

View File

@@ -1617,6 +1617,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
return switch(sensor){
case x -> World.conv(x);
case y -> World.conv(y);
case color -> Color.toDoubleBits(team.color.r, team.color.g, team.color.b, 1f);
case dead -> !isValid() ? 1 : 0;
case team -> team.id;
case health -> health;

View File

@@ -2,6 +2,7 @@ package mindustry.entities.comp;
import arc.*;
import arc.func.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
@@ -195,6 +196,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
case commanded -> controller instanceof FormationAI && isValid() ? 1 : 0;
case payloadCount -> ((Object)this) instanceof Payloadc pay ? pay.payloads().size : 0;
case size -> hitSize / tilesize;
case color -> Color.toDoubleBits(team.color.r, team.color.g, team.color.b, 1f);
default -> Float.NaN;
};
}

View File

@@ -38,6 +38,21 @@ public abstract class DrawPart{
}
}
public static class PartMove{
public PartProgress progress = PartProgress.warmup;
public float x, y, rot;
public PartMove(PartProgress progress, float x, float y, float rot){
this.progress = progress;
this.x = x;
this.y = y;
this.rot = rot;
}
public PartMove(){
}
}
public interface PartProgress{
/** Reload of the weapon - 1 right after shooting, 0 when ready to fire*/
PartProgress

View File

@@ -31,11 +31,12 @@ public class RegionPart extends DrawPart{
public Blending blending = Blending.normal;
public float layer = -1, layerOffset = 0f;
public float outlineLayerOffset = -0.001f;
public float rotation, rotMove;
public float x, y, moveX, moveY;
public float x, y, rotation;
public float moveX, moveY, moveRot;
public @Nullable Color color, colorTo;
public Color heatColor = Pal.turretHeat.cpy();
public Seq<DrawPart> children = new Seq<>();
public Seq<PartMove> moves = new Seq<>();
public RegionPart(String region){
this.suffix = region;
@@ -61,6 +62,17 @@ public class RegionPart extends DrawPart{
float prevZ = Draw.z();
float prog = progress.getClamp(params);
float mx = moveX * prog, my = moveY * prog, mr = moveRot * prog;
if(moves.size > 0){
for(int i = 0; i < moves.size; i++){
var move = moves.get(i);
float p = move.progress.getClamp(params);
mx += move.x * p;
my += move.y * p;
mr += move.rot * p;
}
}
int len = mirror && params.sideOverride == -1 ? 2 : 1;
@@ -71,12 +83,12 @@ public class RegionPart extends DrawPart{
//can be null
var region = drawRegion ? regions[Math.min(i, regions.length - 1)] : null;
float sign = (i == 0 ? 1 : -1) * params.sideMultiplier;
Tmp.v1.set((x + moveX * prog) * sign, y + moveY * prog).rotate(params.rotation - 90);
Tmp.v1.set((x + mx) * sign, y + my).rotate(params.rotation - 90);
float
rx = params.x + Tmp.v1.x,
ry = params.y + Tmp.v1.y,
rot = rotMove * prog * sign + params.rotation - 90;
rot = mr * sign + params.rotation - 90;
Draw.xscl = sign;
@@ -113,9 +125,9 @@ public class RegionPart extends DrawPart{
for(int s = 0; s < len; s++){
int i = (params.sideOverride == -1 ? s : params.sideOverride);
float sign = (i == 1 ? -1 : 1) * params.sideMultiplier;
Tmp.v1.set((x + moveX * prog) * sign, y + moveY * prog).rotate(params.rotation - 90);
Tmp.v1.set((x + mx) * sign, y + my).rotate(params.rotation - 90);
childParam.set(params.warmup, params.reload, params.smoothReload, params.heat, params.x + Tmp.v1.x, params.y + Tmp.v1.y, i * sign + rotMove * prog * sign + params.rotation);
childParam.set(params.warmup, params.reload, params.smoothReload, params.heat, params.x + Tmp.v1.x, params.y + Tmp.v1.y, i * sign + mr * sign + params.rotation);
childParam.sideMultiplier = params.sideMultiplier;
childParam.life = params.life;
childParam.sideOverride = i;

View File

@@ -894,6 +894,11 @@ public class MobileInput extends InputHandler implements GestureListener{
unit.lookAt(unit.prefRotation());
}
//validate payload, if it's a destroyed unit/building, remove it
if(payloadTarget instanceof Healthc h && !h.isValid()){
payloadTarget = null;
}
if(payloadTarget != null && unit instanceof Payloadc pay){
targetPos.set(payloadTarget);
attractDst = 0f;

View File

@@ -1,6 +1,7 @@
package mindustry.logic;
import arc.func.*;
import arc.graphics.*;
import arc.struct.*;
import arc.util.*;
import mindustry.*;
@@ -99,10 +100,20 @@ public class LAssembler{
//parse hex/binary syntax
if(symbol.startsWith("0b")) return Strings.parseLong(symbol, 2, 2, symbol.length(), invalidNum);
if(symbol.startsWith("0x")) return Strings.parseLong(symbol, 16, 2, symbol.length(), invalidNum);
if(symbol.startsWith("%") && (symbol.length() == 7 || symbol.length() == 9)) return parseColor(symbol);
return Strings.parseDouble(symbol, invalidNum);
}
double parseColor(String symbol){
int
r = Strings.parseInt(symbol, 16, 0, 1, 3),
g = Strings.parseInt(symbol, 16, 0, 3, 5),
b = Strings.parseInt(symbol, 16, 0, 5, 7),
a = symbol.length() == 9 ? Strings.parseInt(symbol, 16, 0, 7, 9) : 255;
return Color.toDoubleBits(r, g, b, a);
}
/** Adds a constant value by name. */
public BVar putConst(String name, Object value){
BVar var = putVar(name);

View File

@@ -1187,5 +1187,33 @@ public class LExecutor{
}
}
public static class SetRuleI implements LInstruction{
public LogicRule rule = LogicRule.waveSpacing;
public int value;
public SetRuleI(LogicRule rule, int value){
this.rule = rule;
this.value = value;
}
public SetRuleI(){
}
@Override
public void run(LExecutor exec){
switch(rule){
case waveTimer -> state.rules.waveTimer = exec.bool(value);
case waves -> state.rules.waves = exec.bool(value);
case attackMode -> state.rules.attackMode = exec.bool(value);
case waveSpacing -> state.rules.waveSpacing = exec.numf(value) * 60f;
case enemyCoreBuildRadius -> state.rules.enemyCoreBuildRadius = exec.numf(value) * 8f;
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 ambientLight -> state.rules.ambientLight.fromDouble(exec.num(value));
}
}
}
//endregion
}

View File

@@ -6,6 +6,7 @@ import arc.graphics.*;
import arc.scene.style.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.*;
import mindustry.annotations.Annotations.*;
import mindustry.ctype.*;
@@ -1205,4 +1206,37 @@ public class LStatements{
return new SpawnUnitI(builder.var(type), builder.var(x), builder.var(y), builder.var(rotation), builder.var(team), effect, builder.var(result));
}
}
@RegisterStatement("setrule")
public static class SetRuleStatement extends LStatement{
public LogicRule rule = LogicRule.waveSpacing;
public String value = "100";
@Override
public void build(Table table){
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)));
}, Styles.logict, () -> {}).size(150f, 40f).pad(4f).color(table.color);
table.add(" = ");
field(table, value, s -> value = s);
}
@Override
public boolean privileged(){
return true;
}
@Override
public Color color(){
return Pal.logicWorld;
}
@Override
public LInstruction build(LAssembler builder){
return new SetRuleI(rule, builder.var(value));
}
}
}

View File

@@ -0,0 +1,15 @@
package mindustry.logic;
public enum LogicRule{
waveTimer,
waves,
waveSpacing,
attackMode,
enemyCoreBuildRadius,
dropZoneRadius,
unitCap,
lighting,
ambientLight;
public static final LogicRule[] all = values();
}

View File

@@ -53,6 +53,11 @@ public abstract class PlanetGenerator extends BasicGenerator implements HexMeshe
}
}
/** @return whether to allow landing on the specified procedural sector */
public boolean allowLanding(Sector sector){
return sector.hasBase() || sector.near().contains(Sector::hasBase);
}
public void addWeather(Sector sector, Rules rules){
//apply weather based on terrain

View File

@@ -64,6 +64,12 @@ public class ErekirPlanetGenerator extends PlanetGenerator{
return Loadouts.basicBastion;
}
@Override
public boolean allowLanding(Sector sector){
//TODO disallowed for now
return false;
}
float rawHeight(Vec3 position){
return Simplex.noise3d(seed, octaves, persistence, 1f/heightScl, 10f + position.x, 10f + position.y, 10f + position.z);
}

View File

@@ -331,7 +331,10 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
return node == null || node.parent == null || node.parent.content.unlocked();
}
return sector.hasBase() || sector.near().contains(Sector::hasBase); //near an occupied sector
return sector.planet.generator != null ?
//use planet impl when possible
sector.planet.generator.allowLanding(sector) :
sector.hasBase() || sector.near().contains(Sector::hasBase); //near an occupied sector
}
Sector findLauncher(Sector to){

View File

@@ -23,6 +23,7 @@ import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.graphics.MultiPacker.*;
import mindustry.logic.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.blocks.*;
@@ -37,7 +38,7 @@ import java.util.*;
import static mindustry.Vars.*;
public class Block extends UnlockableContent{
public class Block extends UnlockableContent implements Senseable{
/** If true, buildings have an ItemModule. */
public boolean hasItems;
/** If true, buildings have a LiquidModule. */
@@ -1148,4 +1149,28 @@ public class Block extends UnlockableContent{
req.rotation = Mathf.mod(req.rotation + 2, 4);
}
}
@Override
public double sense(LAccess sensor){
return switch(sensor){
case color -> Color.toDoubleBits(mapColor.r, mapColor.g, mapColor.b, mapColor.a);
case health, maxHealth -> health;
case size -> size * tilesize;
case itemCapacity -> itemCapacity;
case liquidCapacity -> liquidCapacity;
case powerCapacity -> consumes.hasPower() && consumes.getPower().buffered ? consumes.getPower().capacity : 0f;
default -> Double.NaN;
};
}
@Override
public double sense(Content content){
return Double.NaN;
}
@Override
public Object senseObject(LAccess sensor){
if(sensor == LAccess.name) return name;
return noSensed;
}
}