Merge branch 'master' of https://github.com/Anuken/Mindustry into maps_phase_2

This commit is contained in:
Epowerj
2022-08-05 17:06:47 -04:00
14 changed files with 214 additions and 168 deletions

View File

@@ -2755,7 +2755,6 @@ public class Blocks{
//TODO awful name
largePlasmaBore = new BeamDrill("large-plasma-bore"){{
//TODO requirements
requirements(Category.production, with(Items.silicon, 100, Items.oxide, 25, Items.beryllium, 100, Items.tungsten, 70));
consumePower(0.8f);
drillTime = 110f;
@@ -2770,7 +2769,6 @@ public class Blocks{
consumeLiquid(Liquids.nitrogen, 3f / 60f).boost();
}};
//TODO should be crusher or something
impactDrill = new BurstDrill("impact-drill"){{
requirements(Category.production, with(Items.silicon, 70, Items.beryllium, 90, Items.graphite, 60));
drillTime = 60f * 12f;
@@ -2784,13 +2782,14 @@ public class Blocks{
blockedItem = Items.thorium;
researchCostMultiplier = 0.5f;
drillMultipliers.put(Items.beryllium, 2.5f);
fogRadius = 4;
consumePower(160f / 60f);
consumeLiquid(Liquids.water, 0.2f);
}};
//TODO bad name
eruptionDrill = new BurstDrill("eruption-drill"){{
requirements(Category.production, with(Items.silicon, 200, Items.oxide, 20, Items.tungsten, 200, Items.thorium, 120));
drillTime = 60f * 6f;
@@ -2812,6 +2811,8 @@ public class Blocks{
glowColor.a = 0.6f;
fogRadius = 5;
drillMultipliers.put(Items.beryllium, 2.5f);
//TODO different requirements
consumePower(6f);
consumeLiquids(LiquidStack.with(Liquids.hydrogen, 4f / 60f));

View File

@@ -98,8 +98,9 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
//find the next build plan
if(plans.size > 1){
int total = 0;
int size = plans.size;
BuildPlan plan;
while((!within((plan = buildPlan()).tile(), finalPlaceDst) || shouldSkip(plan, core)) && total < plans.size){
while((!within((plan = buildPlan()).tile(), finalPlaceDst) || shouldSkip(plan, core)) && total < size){
plans.removeFirst();
plans.addLast(plan);
total++;

View File

@@ -152,6 +152,13 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
return self();
}
@Override
public void add(){
if(power != null){
power.graph.checkAdd();
}
}
@Override
@Replace
public int tileX(){

View File

@@ -38,7 +38,7 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
//update power graph first, resolve everything
for(Payload pay : payloads){
if(pay instanceof BuildPayload pb && pb.build.power != null){
if(payloadPower == null) payloadPower = new PowerGraph();
if(payloadPower == null) payloadPower = new PowerGraph(false);
//pb.build.team = team;
pb.build.power.graph = null;

View File

@@ -96,7 +96,7 @@ public class Duct extends Block implements Autotiler{
@Override
public void handlePlacementLine(Seq<BuildPlan> plans){
Placement.calculateBridges(plans, (DuctBridge)Blocks.ductBridge, false, b -> b instanceof Duct);
Placement.calculateBridges(plans, (DuctBridge)Blocks.ductBridge, false, b -> b instanceof Duct || b instanceof StackConveyor || b instanceof Conveyor);
}
public class DuctBuild extends Building{

View File

@@ -101,7 +101,7 @@ public class BuildPayload implements Payload{
Draw.z(prevZ - 0.0001f);
drawShadow(1f);
Draw.z(prevZ);
Draw.zTransform(z -> z >= Layer.flyingUnitLow ? z : 0.0011f + Mathf.clamp(z, prevZ - 0.001f, prevZ + 0.9f));
Draw.zTransform(z -> z >= Layer.flyingUnitLow + 1f ? z : 0.0011f + Math.min(Mathf.clamp(z, prevZ - 0.001f, prevZ + 0.9f), Layer.flyingUnitLow - 1f));
build.tile = emptyTile;
build.payloadDraw();
Draw.zTransform();

View File

@@ -18,7 +18,7 @@ public class PowerGraph{
public final Seq<Building> batteries = new Seq<>(false, 16, Building.class);
public final Seq<Building> all = new Seq<>(false, 16, Building.class);
private final PowerGraphUpdater entity;
private final @Nullable PowerGraphUpdater entity;
private final WindowedMean powerBalance = new WindowedMean(60);
private float lastPowerProduced, lastPowerNeeded, lastPowerStored;
private float lastScaledPowerIn, lastScaledPowerOut, lastCapacity;
@@ -34,6 +34,11 @@ public class PowerGraph{
graphID = lastGraphID++;
}
public PowerGraph(boolean noEntity){
entity = null;
graphID = lastGraphID++;
}
public int getID(){
return graphID;
}
@@ -251,11 +256,12 @@ public class PowerGraph{
public void addGraph(PowerGraph graph){
if(graph == this) return;
//other entity should be removed as the graph was merged
graph.entity.remove();
if(graph.entity != null) graph.entity.remove();
for(Building tile : graph.all){
add(tile);
}
checkAdd();
}
public void add(Building build){
@@ -264,14 +270,12 @@ public class PowerGraph{
if(build.power.graph != this || !build.power.init){
//any old graph that is added here MUST be invalid, remove it
if(build.power.graph != null && build.power.graph != this){
build.power.graph.entity.remove();
if(build.power.graph.entity != null) build.power.graph.entity.remove();
}
build.power.graph = this;
build.power.init = true;
all.add(build);
//there's something to update, add the entity
entity.add();
if(build.block.outputsPower && build.block.consumesPower && !build.block.consPower.buffered){
producers.add(build);
@@ -286,13 +290,17 @@ public class PowerGraph{
}
}
public void checkAdd(){
if(entity != null) entity.add();
}
public void clear(){
all.clear();
producers.clear();
consumers.clear();
batteries.clear();
//nothing left
entity.remove();
if(entity != null) entity.remove();
}
public void reflow(Building tile){
@@ -302,6 +310,7 @@ public class PowerGraph{
while(queue.size > 0){
Building child = queue.removeFirst();
add(child);
checkAdd();
for(Building next : child.getPowerConnections(outArray2)){
if(closedSet.add(next.pos())){
queue.addLast(next);
@@ -329,6 +338,7 @@ public class PowerGraph{
//create graph for this branch
PowerGraph graph = new PowerGraph();
graph.checkAdd();
graph.add(other);
//add to queue for BFS
queue.clear();
@@ -353,7 +363,7 @@ public class PowerGraph{
}
//implied empty graph here
entity.remove();
if(entity != null) entity.remove();
}
@Deprecated

View File

@@ -14,6 +14,7 @@ import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import mindustry.world.blocks.heat.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
@@ -61,6 +62,13 @@ public class VariableReactor extends PowerGenerator{
() -> entity.heat / maxHeat));
}
@Override
public void setStats(){
super.setStats();
stats.add(Stat.input, maxHeat, StatUnit.heatUnits);
}
//TODO: draw warmup fraction on block?
public class VariableReactorBuild extends GeneratorBuild implements HeatConsumer{
public float[] sideHeat = new float[4];
@@ -70,7 +78,7 @@ public class VariableReactor extends PowerGenerator{
public void updateTile(){
heat = calculateHeat(sideHeat);
productionEfficiency = Mathf.clamp(heat / maxHeat);
productionEfficiency = Mathf.clamp(heat / maxHeat) * efficiency;
warmup = Mathf.lerpDelta(warmup, productionEfficiency > 0 ? 1f : 0f, warmupSpeed);
if(instability >= 1f){

View File

@@ -3,11 +3,13 @@ package mindustry.world.blocks.production;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.struct.*;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.graphics.*;
import mindustry.type.*;
public class BurstDrill extends Drill{
public float shake = 2f;
@@ -24,6 +26,9 @@ public class BurstDrill extends Drill{
public Color arrowColor = Color.valueOf("feb380"), baseArrowColor = Color.valueOf("6e7080");
public Color glowColor = arrowColor.cpy();
/** Multipliers of drill speed for each item. Defaults to 1. */
public ObjectFloatMap<Item> drillMultipliers = new ObjectFloatMap<>();
public BurstDrill(String name){
super(name);
@@ -40,6 +45,11 @@ public class BurstDrill extends Drill{
return new TextureRegion[]{region, topRegion};
}
@Override
public float getDrillTime(Item item){
return drillTime / drillMultipliers.get(item, 1f);
}
public class BurstDrillBuild extends DrillBuild{
//used so the lights don't fade out immediately
public float smoothProgress = 0f;
@@ -57,6 +67,8 @@ public class BurstDrill extends Drill{
dump(items.has(dominantItem) ? dominantItem : null);
}
float drillTime = getDrillTime(dominantItem);
smoothProgress = Mathf.lerpDelta(smoothProgress, progress / (drillTime - 20f), 0.1f);
if(items.total() <= itemCapacity - dominantItems && dominantItems > 0 && efficiency > 0){

View File

@@ -135,7 +135,7 @@ public class Drill extends Block{
countOre(tile);
if(returnItem != null){
float width = drawPlaceText(Core.bundle.formatFloat("bar.drillspeed", 60f / (drillTime + hardnessDrillMultiplier * returnItem.hardness) * returnCount, 2), x, y, valid);
float width = drawPlaceText(Core.bundle.formatFloat("bar.drillspeed", 60f / getDrillTime(returnItem) * returnCount, 2), x, y, valid);
float dx = x * tilesize + offset - width/2f - 4f, dy = y * tilesize + offset + size * tilesize / 2f + 5, s = iconSmall / 4f;
Draw.mixcol(Color.darkGray, 1f);
Draw.rect(returnItem.fullIcon, dx, dy - 1, s, s);
@@ -156,6 +156,10 @@ public class Drill extends Block{
}
}
public float getDrillTime(Item item){
return drillTime + hardnessDrillMultiplier * item.hardness;
}
@Override
public void setStats(){
super.setStats();
@@ -274,10 +278,12 @@ public class Drill extends Block{
timeDrilled += warmup * delta();
float delay = getDrillTime(dominantItem);
if(items.total() < itemCapacity && dominantItems > 0 && efficiency > 0){
float speed = Mathf.lerp(1f, liquidBoostIntensity, optionalEfficiency) * efficiency;
lastDrillSpeed = (speed * dominantItems * warmup) / (drillTime + hardnessDrillMultiplier * dominantItem.hardness);
lastDrillSpeed = (speed * dominantItems * warmup) / delay;
warmup = Mathf.approachDelta(warmup, speed, warmupSpeed);
progress += delta() * dominantItems * speed * warmup;
@@ -289,8 +295,6 @@ public class Drill extends Block{
return;
}
float delay = drillTime + hardnessDrillMultiplier * dominantItem.hardness;
if(dominantItems > 0 && progress >= delay && items.total() < itemCapacity){
offload(dominantItem);
@@ -302,7 +306,7 @@ public class Drill extends Block{
@Override
public double sense(LAccess sensor){
if(sensor == LAccess.progress && dominantItem != null) return Mathf.clamp(progress / (drillTime + hardnessDrillMultiplier * dominantItem.hardness));
if(sensor == LAccess.progress && dominantItem != null) return Mathf.clamp(progress / getDrillTime(dominantItem));
return super.sense(sensor);
}

View File

@@ -7,8 +7,6 @@ import mindustry.world.meta.*;
/** An abstract class that defines a type of resource that a block can consume. */
public abstract class Consume{
//TODO maybe remove these and make it an interface if possible?
/** If true, this consumer will not influence consumer validity. */
public boolean optional;
/** If true, this consumer will be displayed as a boost input. */
@@ -61,7 +59,4 @@ public abstract class Consume{
}
public void display(Stats stats){}
//TODO this should use efficiency instead - remove or deprecate
//public abstract boolean valid(Building build);
}