Merge branch 'master' into port-field

This commit is contained in:
Antsiferov Andrew
2021-01-03 14:54:02 +03:00
committed by GitHub
20 changed files with 90 additions and 40 deletions

View File

@@ -45,6 +45,7 @@ public class AndroidLauncher extends AndroidApplication{
handler.uncaughtException(thread, error); handler.uncaughtException(thread, error);
}else{ }else{
error.printStackTrace(); error.printStackTrace();
Log.err(error);
System.exit(1); System.exit(1);
} }
}); });

View File

@@ -112,3 +112,4 @@ Catchears
younggam younggam
simba-fs simba-fs
RedRadiation RedRadiation
Marko Zajc

View File

@@ -32,6 +32,7 @@ public class BaseAI{
private static final Seq<Tile> tmpTiles = new Seq<>(); private static final Seq<Tile> tmpTiles = new Seq<>();
private static int correct = 0, incorrect = 0; private static int correct = 0, incorrect = 0;
private static boolean anyDrills;
private int lastX, lastY, lastW, lastH; private int lastX, lastY, lastW, lastH;
private boolean triedWalls, foundPath; private boolean triedWalls, foundPath;
@@ -200,7 +201,7 @@ public class BaseAI{
int cx = x - (int)rotator.x; int cx = x - (int)rotator.x;
int cy = y - (int)rotator.y; int cy = y - (int)rotator.y;
//chekc valid placeability //check valid placeability
for(Stile tile : result.tiles){ for(Stile tile : result.tiles){
int realX = tile.x + cx, realY = tile.y + cy; int realX = tile.x + cx, realY = tile.y + cy;
if(!Build.validPlace(tile.block, data.team, realX, realY, tile.rotation)){ if(!Build.validPlace(tile.block, data.team, realX, realY, tile.rotation)){
@@ -217,16 +218,18 @@ public class BaseAI{
//make sure at least X% of resource requirements are met //make sure at least X% of resource requirements are met
correct = incorrect = 0; correct = incorrect = 0;
anyDrills = false;
if(part.required instanceof Item){ if(part.required instanceof Item){
for(Stile tile : result.tiles){ for(Stile tile : result.tiles){
if(tile.block instanceof Drill){ if(tile.block instanceof Drill){
anyDrills = true;
tile.block.iterateTaken(tile.x + cx, tile.y + cy, (ex, ey) -> { tile.block.iterateTaken(tile.x + cx, tile.y + cy, (ex, ey) -> {
Tile res = world.rawTile(ex, ey); Tile res = world.rawTile(ex, ey);
if(res.drop() == part.required){ if(res.drop() == part.required){
correct ++; correct ++;
}else{ }else if(res.drop() != null){
incorrect ++; incorrect ++;
} }
}); });
@@ -235,7 +238,7 @@ public class BaseAI{
} }
//fail if not enough fit requirements //fail if not enough fit requirements
if((float)correct / incorrect < correctPercent){ if(anyDrills && (incorrect != 0 || correct == 0)){
return false; return false;
} }

View File

@@ -20,6 +20,9 @@ import static arc.Core.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class Renderer implements ApplicationListener{ public class Renderer implements ApplicationListener{
/** These are global variables, for headless access. Cached. */
public static float laserOpacity = 0.5f, bridgeOpacity = 0.75f;
public final BlockRenderer blocks = new BlockRenderer(); public final BlockRenderer blocks = new BlockRenderer();
public final MinimapRenderer minimap = new MinimapRenderer(); public final MinimapRenderer minimap = new MinimapRenderer();
public final OverlayRenderer overlays = new OverlayRenderer(); public final OverlayRenderer overlays = new OverlayRenderer();
@@ -29,7 +32,6 @@ public class Renderer implements ApplicationListener{
public @Nullable Bloom bloom; public @Nullable Bloom bloom;
public FrameBuffer effectBuffer = new FrameBuffer(); public FrameBuffer effectBuffer = new FrameBuffer();
public float laserOpacity = 1f;
public boolean animateShields, drawWeather = true; public boolean animateShields, drawWeather = true;
/** minZoom = zooming out, maxZoom = zooming in */ /** minZoom = zooming out, maxZoom = zooming in */
public float minZoom = 1.5f, maxZoom = 6f; public float minZoom = 1.5f, maxZoom = 6f;
@@ -71,6 +73,7 @@ public class Renderer implements ApplicationListener{
camerascale = Mathf.lerpDelta(camerascale, dest, 0.1f); camerascale = Mathf.lerpDelta(camerascale, dest, 0.1f);
if(Mathf.equal(camerascale, dest, 0.001f)) camerascale = dest; if(Mathf.equal(camerascale, dest, 0.001f)) camerascale = dest;
laserOpacity = settings.getInt("lasersopacity") / 100f; laserOpacity = settings.getInt("lasersopacity") / 100f;
bridgeOpacity = settings.getInt("bridgeopacity") / 100f;
animateShields = settings.getBool("animatedshields"); animateShields = settings.getBool("animatedshields");
if(landTime > 0){ if(landTime > 0){

View File

@@ -108,7 +108,7 @@ abstract class BuilderComp implements Posc, Teamc, Rotc{
plans.removeFirst(); plans.removeFirst();
return; return;
} }
}else if((tile.team() != team && tile.team() != Team.derelict) || (!current.breaking && cb.cblock != current.block)){ }else if((tile.team() != team && tile.team() != Team.derelict) || (!current.breaking && (cb.cblock != current.block || cb.tile != current.tile()))){
plans.removeFirst(); plans.removeFirst();
return; return;
} }

View File

@@ -136,7 +136,9 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
int rot = (int)((rotation + 45f) / 90f) % 4; int rot = (int)((rotation + 45f) / 90f) % 4;
payload.place(on, rot); payload.place(on, rot);
if(isPlayer()) payload.build.lastAccessed = getPlayer().name; if(getControllerName() != null){
payload.build.lastAccessed = getControllerName();
}
Fx.unitDrop.at(tile); Fx.unitDrop.at(tile);
Fx.placeBlock.at(on.drawx(), on.drawy(), on.block().size); Fx.placeBlock.at(on.drawx(), on.drawy(), on.block().size);

View File

@@ -445,6 +445,15 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
remove(); remove();
} }
/** @return name of direct or indirect player controller. */
@Override
public @Nullable String getControllerName(){
if(isPlayer()) return getPlayer().name;
if(controller instanceof LogicAI ai && ai.controller != null) return ai.controller.lastAccessed;
if(controller instanceof FormationAI ai && ai.leader != null && ai.leader.isPlayer()) return ai.leader.getPlayer().name;
return null;
}
@Override @Override
public void display(Table table){ public void display(Table table){
type.display(self(), table); type.display(self(), table);

View File

@@ -387,15 +387,13 @@ public class LStatements{
public static class RadarStatement extends LStatement{ public static class RadarStatement extends LStatement{
public RadarTarget target1 = RadarTarget.enemy, target2 = RadarTarget.any, target3 = RadarTarget.any; public RadarTarget target1 = RadarTarget.enemy, target2 = RadarTarget.any, target3 = RadarTarget.any;
public RadarSort sort = RadarSort.distance; public RadarSort sort = RadarSort.distance;
public String radar = "0", sortOrder = "1", output = "result"; public String radar = "turret1", sortOrder = "1", output = "result";
@Override @Override
public void build(Table table){ public void build(Table table){
table.defaults().left(); table.defaults().left();
if(buildFrom()){ if(buildFrom()){
radar = "turret1";
table.add(" from "); table.add(" from ");
fields(table, radar, v -> radar = v); fields(table, radar, v -> radar = v);

View File

@@ -3,6 +3,7 @@ package mindustry.logic;
import arc.*; import arc.*;
import arc.func.*; import arc.func.*;
import arc.scene.ui.TextButton.*; import arc.scene.ui.TextButton.*;
import arc.util.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.logic.LStatements.*; import mindustry.logic.LStatements.*;
import mindustry.ui.*; import mindustry.ui.*;
@@ -90,16 +91,20 @@ public class LogicDialog extends BaseDialog{
onResize(() -> canvas.rebuild()); onResize(() -> canvas.rebuild());
} }
public void show(String code, Cons<String> consumer){ public void show(String code, Cons<String> modified){
canvas.statements.clearChildren(); canvas.statements.clearChildren();
canvas.rebuild(); canvas.rebuild();
try{ try{
canvas.load(code); canvas.load(code);
}catch(Throwable t){ }catch(Throwable t){
t.printStackTrace(); Log.err(t);
canvas.load(""); canvas.load("");
} }
this.consumer = consumer; this.consumer = result -> {
if(!result.equals(code)){
modified.get(result);
}
};
show(); show();
} }

View File

@@ -47,7 +47,12 @@ public class CrashSender{
public static void send(Throwable exception, Cons<File> writeListener){ public static void send(Throwable exception, Cons<File> writeListener){
try{ try{
exception.printStackTrace(); try{
//log to file
Log.err(exception);
}catch(Throwable no){
exception.printStackTrace();
}
//try saving game data //try saving game data
try{ try{

View File

@@ -563,25 +563,32 @@ public class JoinDialog extends BaseDialog{
transient Host lastHost; transient Host lastHost;
void setIP(String ip){ void setIP(String ip){
try{
//parse ip:port, if unsuccessful, use default values boolean isIpv6 = Strings.count(ip, ':') > 1;
if(ip.lastIndexOf(':') != -1 && ip.lastIndexOf(':') != ip.length() - 1){ if(isIpv6 && ip.lastIndexOf("]:") != -1 && ip.lastIndexOf("]:") != ip.length() - 1){
try{ int idx = ip.indexOf("]:");
this.ip = ip.substring(1, idx);
this.port = Integer.parseInt(ip.substring(idx + 2, ip.length()));
}else if(!isIpv6 && ip.lastIndexOf(':') != -1 && ip.lastIndexOf(':') != ip.length() - 1){
int idx = ip.lastIndexOf(':'); int idx = ip.lastIndexOf(':');
this.ip = ip.substring(0, idx); this.ip = ip.substring(0, idx);
this.port = Integer.parseInt(ip.substring(idx + 1)); this.port = Integer.parseInt(ip.substring(idx + 1));
}catch(Exception e){ }else{
this.ip = ip; this.ip = ip;
this.port = Vars.port; this.port = Vars.port;
} }
}else{ }catch(Exception e){
this.ip = ip; this.ip = ip;
this.port = Vars.port; this.port = Vars.port;
} }
} }
String displayIP(){ String displayIP(){
return ip + (port != Vars.port ? ":" + port : ""); if(Strings.count(ip, ':') > 1){
return port != Vars.port ? "[" + ip + "]:" + port : ip;
}else{
return ip + (port != Vars.port ? ":" + port : "");
}
} }
public Server(){ public Server(){

View File

@@ -45,7 +45,10 @@ public class Build{
build.setDeconstruct(previous); build.setDeconstruct(previous);
build.prevBuild = prevBuild; build.prevBuild = prevBuild;
tile.build.health = tile.build.maxHealth * prevPercent; tile.build.health = tile.build.maxHealth * prevPercent;
if(unit != null && unit.isPlayer()) tile.build.lastAccessed = unit.getPlayer().name;
if(unit != null && unit.getControllerName() != null){
tile.build.lastAccessed = unit.getControllerName();
}
Core.app.post(() -> Events.fire(new BlockBuildBeginEvent(tile, team, unit, true))); Core.app.post(() -> Events.fire(new BlockBuildBeginEvent(tile, team, unit, true)));
} }
@@ -64,7 +67,7 @@ public class Build{
//auto-rotate the block to the correct orientation and bail out //auto-rotate the block to the correct orientation and bail out
if(tile.team() == team && tile.block == result && tile.build != null && tile.block.quickRotate){ if(tile.team() == team && tile.block == result && tile.build != null && tile.block.quickRotate){
if(unit != null && unit.isPlayer()) tile.build.lastAccessed = unit.getPlayer().name; if(unit != null && unit.getControllerName() != null) tile.build.lastAccessed = unit.getControllerName();
tile.build.rotation = Mathf.mod(rotation, 4); tile.build.rotation = Mathf.mod(rotation, 4);
tile.build.updateProximity(); tile.build.updateProximity();
tile.build.noSleep(); tile.build.noSleep();
@@ -90,7 +93,7 @@ public class Build{
build.setConstruct(previous.size == sub.size ? previous : Blocks.air, result); build.setConstruct(previous.size == sub.size ? previous : Blocks.air, result);
build.prevBuild = prevBuild; build.prevBuild = prevBuild;
if(unit != null && unit.isPlayer()) build.lastAccessed = unit.getPlayer().name; if(unit != null && unit.getControllerName() != null) build.lastAccessed = unit.getControllerName();
result.placeBegan(tile, previous); result.placeBegan(tile, previous);

View File

@@ -78,8 +78,8 @@ public class ConstructBlock extends Block{
tile.build.overwrote(prev); tile.build.overwrote(prev);
} }
if(builder != null && builder.isPlayer()){ if(builder != null && builder.getControllerName() != null){
tile.build.lastAccessed = builder.getPlayer().name; tile.build.lastAccessed = builder.getControllerName();
} }
} }

View File

@@ -1,9 +1,9 @@
package mindustry.world.blocks.distribution; package mindustry.world.blocks.distribution;
import arc.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*; import arc.math.*;
import arc.math.geom.*; import arc.math.geom.*;
import mindustry.core.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.world.*; import mindustry.world.*;
@@ -36,9 +36,8 @@ public class ExtendingItemBridge extends ItemBridge{
ex *= uptime; ex *= uptime;
ey *= uptime; ey *= uptime;
float opacity = Core.settings.getInt("bridgeopacity") / 100f; if(Mathf.zero(Renderer.bridgeOpacity)) return;
if(Mathf.zero(opacity)) return; Draw.alpha(Renderer.bridgeOpacity);
Draw.alpha(opacity);
Lines.stroke(8f); Lines.stroke(8f);
Lines.line(bridgeRegion, Lines.line(bridgeRegion,
@@ -59,7 +58,7 @@ public class ExtendingItemBridge extends ItemBridge{
Draw.color(); Draw.color();
for(int a = 0; a < arrows; a++){ for(int a = 0; a < arrows; a++){
Draw.alpha(Mathf.absin(a / (float)arrows - time / 100f, 0.1f, 1f) * uptime * opacity); Draw.alpha(Mathf.absin(a / (float)arrows - time / 100f, 0.1f, 1f) * uptime * Renderer.bridgeOpacity);
Draw.rect(arrowRegion, Draw.rect(arrowRegion,
x + Geometry.d4(i).x * (tilesize / 2f + a * 6f + 2) * uptime, x + Geometry.d4(i).x * (tilesize / 2f + a * 6f + 2) * uptime,
y + Geometry.d4(i).y * (tilesize / 2f + a * 6f + 2) * uptime, y + Geometry.d4(i).y * (tilesize / 2f + a * 6f + 2) * uptime,

View File

@@ -10,6 +10,7 @@ import arc.struct.IntSet.*;
import arc.util.*; import arc.util.*;
import arc.util.io.*; import arc.util.io.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.core.*;
import mindustry.entities.units.*; import mindustry.entities.units.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
@@ -70,6 +71,9 @@ public class ItemBridge extends Block{
} }
public void drawBridge(BuildPlan req, float ox, float oy, float flip){ public void drawBridge(BuildPlan req, float ox, float oy, float flip){
if(Mathf.zero(Renderer.bridgeOpacity)) return;
Draw.alpha(Renderer.bridgeOpacity);
Lines.stroke(8f); Lines.stroke(8f);
Tmp.v1.set(ox, oy).sub(req.drawx(), req.drawy()).setLength(tilesize/2f); Tmp.v1.set(ox, oy).sub(req.drawx(), req.drawy()).setLength(tilesize/2f);
@@ -84,6 +88,8 @@ public class ItemBridge extends Block{
Draw.rect(arrowRegion, (req.drawx() + ox) / 2f, (req.drawy() + oy) / 2f, Draw.rect(arrowRegion, (req.drawx() + ox) / 2f, (req.drawy() + oy) / 2f,
Angles.angle(req.drawx(), req.drawy(), ox, oy) + flip); Angles.angle(req.drawx(), req.drawy(), ox, oy) + flip);
Draw.reset();
} }
@Override @Override
@@ -321,13 +327,12 @@ public class ItemBridge extends Block{
Tile other = world.tile(link); Tile other = world.tile(link);
if(!linkValid(tile, other)) return; if(!linkValid(tile, other)) return;
float opacity = Core.settings.getInt("bridgeopacity") / 100f; if(Mathf.zero(Renderer.bridgeOpacity)) return;
if(Mathf.zero(opacity)) return;
int i = relativeTo(other.x, other.y); int i = relativeTo(other.x, other.y);
Draw.color(Color.white, Color.black, Mathf.absin(Time.time, 6f, 0.07f)); Draw.color(Color.white, Color.black, Mathf.absin(Time.time, 6f, 0.07f));
Draw.alpha(Math.max(uptime, 0.25f) * opacity); Draw.alpha(Math.max(uptime, 0.25f) * Renderer.bridgeOpacity);
Draw.rect(endRegion, x, y, i * 90 + 90); Draw.rect(endRegion, x, y, i * 90 + 90);
Draw.rect(endRegion, other.drawx(), other.drawy(), i * 90 + 270); Draw.rect(endRegion, other.drawx(), other.drawy(), i * 90 + 270);
@@ -350,7 +355,7 @@ public class ItemBridge extends Block{
Draw.color(); Draw.color();
for(int a = 0; a < arrows; a++){ for(int a = 0; a < arrows; a++){
Draw.alpha(Mathf.absin(a / (float)arrows - time / 100f, 0.1f, 1f) * uptime * opacity); Draw.alpha(Mathf.absin(a / (float)arrows - time / 100f, 0.1f, 1f) * uptime * Renderer.bridgeOpacity);
Draw.rect(arrowRegion, Draw.rect(arrowRegion,
x + Geometry.d4(i).x * (tilesize / 2f + a * 4f + time % 4f), x + Geometry.d4(i).x * (tilesize / 2f + a * 4f + time % 4f),
y + Geometry.d4(i).y * (tilesize / 2f + a * 4f + time % 4f), i * 90f); y + Geometry.d4(i).y * (tilesize / 2f + a * 4f + time % 4f), i * 90f);

View File

@@ -167,6 +167,16 @@ public class StackConveyor extends Block implements Autotiler{
} }
} }
//cannot load when facing
if(state == stateLoad){
for(Building near : proximity){
if(near instanceof StackConveyorBuild && near.front() == this){
state = stateMove;
break;
}
}
}
//update other conveyor state when this conveyor's state changes //update other conveyor state when this conveyor's state changes
if(state != lastState){ if(state != lastState){
proxUpdating = true; proxUpdating = true;

View File

@@ -477,9 +477,7 @@ public class LogicBlock extends Block{
@Override @Override
public void buildConfiguration(Table table){ public void buildConfiguration(Table table){
table.button(Icon.pencil, Styles.clearTransi, () -> { table.button(Icon.pencil, Styles.clearTransi, () -> {
Vars.ui.logic.show(code, code -> { Vars.ui.logic.show(code, code -> configure(compress(code, relativeConnections())));
configure(compress(code, relativeConnections()));
});
}).size(40); }).size(40);
} }

View File

@@ -159,7 +159,7 @@ public class PowerNode extends PowerBlock{
protected void setupColor(float satisfaction){ protected void setupColor(float satisfaction){
Draw.color(laserColor1, laserColor2, (1f - satisfaction) * 0.86f + Mathf.absin(3f, 0.1f)); Draw.color(laserColor1, laserColor2, (1f - satisfaction) * 0.86f + Mathf.absin(3f, 0.1f));
Draw.alpha(renderer == null ? 0.5f : renderer.laserOpacity); Draw.alpha(Renderer.laserOpacity);
} }
protected void drawLaser(Team team, float x1, float y1, float x2, float y2, int size1, int size2){ protected void drawLaser(Team team, float x1, float y1, float x2, float y2, int size1, int size2){
@@ -391,7 +391,7 @@ public class PowerNode extends PowerBlock{
public void draw(){ public void draw(){
super.draw(); super.draw();
if(Mathf.zero(renderer.laserOpacity)) return; if(Mathf.zero(Renderer.laserOpacity)) return;
Draw.z(Layer.power); Draw.z(Layer.power);
setupColor(power.graph.getSatisfaction()); setupColor(power.graph.getSatisfaction());

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=47b5f71c468d3cec66b6721aeb7f7602ddb468d7 archash=5e9176c3feefa5ee2f14b08f82da1f01f790e64a

View File

@@ -255,6 +255,7 @@ public class IOSLauncher extends IOSApplication.Delegate{
}catch(Throwable t){ }catch(Throwable t){
//attempt to log the exception //attempt to log the exception
CrashSender.log(t); CrashSender.log(t);
Log.err(t);
//rethrow the exception so it actually crashes //rethrow the exception so it actually crashes
throw t; throw t;
} }