Skip to content

Commit

Permalink
Revert "Make liquid production blocks dump as much output as possible"
Browse files Browse the repository at this point in the history
This reverts commit 574ae0b
  • Loading branch information
Anuken committed Feb 5, 2025
1 parent 3891950 commit c08ebc1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 55 deletions.
4 changes: 2 additions & 2 deletions core/src/mindustry/content/Blocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,7 @@ public static void load(){
liquidPadding = 6f/4f;
researchCostMultiplier = 4;
solid = true;
health = 600;
health = 400;
}};

reinforcedLiquidTank = new LiquidRouter("reinforced-liquid-tank"){{
Expand All @@ -2279,7 +2279,7 @@ public static void load(){
solid = true;
liquidCapacity = 2700f;
liquidPadding = 2f;
health = 1200;
health = 900;
}};

//endregion
Expand Down
59 changes: 9 additions & 50 deletions core/src/mindustry/entities/comp/BuildingComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
//region vars and initialization
static final float timeToSleep = 60f * 1, recentDamageTime = 60f * 5f;
static final ObjectSet<Building> tmpTiles = new ObjectSet<>();
static final Seq<Building> tempBuilds = new Seq<>(Building.class);
static final Seq<Building> tempBuilds = new Seq<>();
static final BuildTeamChangeEvent teamChangeEvent = new BuildTeamChangeEvent();
static final BuildDamageEvent bulletDamageEvent = new BuildDamageEvent();
static int sleepingEntities = 0;
Expand Down Expand Up @@ -827,67 +827,26 @@ public void handleLiquid(Building source, Liquid liquid, float amount){

//TODO entire liquid system is awful
public void dumpLiquid(Liquid liquid){
dumpLiquid(liquid, -1);
dumpLiquid(liquid, 2f);
}

/** @param outputDir output liquid direction relative to rotation, or -1 to use any direction. */
public void dumpLiquid(Liquid liquid, int outputDir){
float amount = liquids.get(liquid);

if(amount <= 0.0001f) return;

if(!net.client() && state.isCampaign() && team == state.rules.defaultTeam) liquid.unlock();

float sum = 0f;
tempBuilds.clear();

for(int i = 0; i < proximity.size; i++){
Building other = proximity.get(i);

if(outputDir != -1 && (outputDir + rotation) % 4 != relativeTo(other)) continue;

other = other.getLiquidDestination(self(), liquid);

if(other != null && other.liquids != null && canDumpLiquid(other, liquid) && other.acceptLiquid(self(), liquid)){
//I don't want huge-capacity blocks hogging all the output, so cap their 'weight' by the amount.
sum += Math.min(amount, other.block.liquidCapacity - other.liquids.get(liquid));

tempBuilds.add(other);
}
}

//nothing to output.
if(sum <= 0.00001f){
return;
}

var outputs = tempBuilds.items;
int outputSize = tempBuilds.size;
for(int i = 0; i < outputSize; i++){
Building other = outputs[i];

float maxOutput = Math.min(amount, other.block.liquidCapacity - other.liquids.get(liquid));
//fraction of total possible output that this block represents.
float fraction = maxOutput / sum;

//note: transferLiquid already clamps the amount by capacity.
transferLiquid(other, fraction * amount, liquid);
}
public void dumpLiquid(Liquid liquid, float scaling){
dumpLiquid(liquid, scaling, -1);
}

/** Tries to evenly distribute the specified liquid to nearby blocks. This method will likely be removed in the future! */
public void distributeLiquid(Liquid liquid){
if(liquids.get(liquid) <= 0.0001f) return;
float scaling = 2f;

/** @param outputDir output liquid direction relative to rotation, or -1 to use any direction. */
public void dumpLiquid(Liquid liquid, float scaling, int outputDir){
int dump = this.cdump;

if(liquids.get(liquid) <= 0.0001f) return;

if(!net.client() && state.isCampaign() && team == state.rules.defaultTeam) liquid.unlock();

for(int i = 0; i < proximity.size; i++){
incrementDump(proximity.size);

Building other = proximity.get((i + dump) % proximity.size);
if(outputDir != -1 && (outputDir + rotation) % 4 != relativeTo(other)) continue;

other = other.getLiquidDestination(self(), liquid);

Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/world/blocks/liquid/LiquidBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void updateTransport(Building other){

@Override
public void doDump(){
dumpLiquid(liquids.current());
dumpLiquid(liquids.current(), 1f);
}
}
}
2 changes: 1 addition & 1 deletion core/src/mindustry/world/blocks/liquid/LiquidRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public TextureRegion[] icons(){
public class LiquidRouterBuild extends LiquidBuild{
@Override
public void updateTile(){
distributeLiquid(liquids.current());
dumpLiquid(liquids.current());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public void dumpOutputs(){
for(int i = 0; i < outputLiquids.length; i++){
int dir = liquidOutputDirections.length > i ? liquidOutputDirections[i] : -1;

dumpLiquid(outputLiquids[i].liquid, dir);
dumpLiquid(outputLiquids[i].liquid, 2f, dir);
}
}
}
Expand Down

0 comments on commit c08ebc1

Please sign in to comment.