Make liquid production blocks dump as much output as possible
This commit is contained in:
@@ -52,7 +52,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
//region vars and initialization
|
//region vars and initialization
|
||||||
static final float timeToSleep = 60f * 1, recentDamageTime = 60f * 5f;
|
static final float timeToSleep = 60f * 1, recentDamageTime = 60f * 5f;
|
||||||
static final ObjectSet<Building> tmpTiles = new ObjectSet<>();
|
static final ObjectSet<Building> tmpTiles = new ObjectSet<>();
|
||||||
static final Seq<Building> tempBuilds = new Seq<>();
|
static final Seq<Building> tempBuilds = new Seq<>(Building.class);
|
||||||
static final BuildTeamChangeEvent teamChangeEvent = new BuildTeamChangeEvent();
|
static final BuildTeamChangeEvent teamChangeEvent = new BuildTeamChangeEvent();
|
||||||
static final BuildDamageEvent bulletDamageEvent = new BuildDamageEvent();
|
static final BuildDamageEvent bulletDamageEvent = new BuildDamageEvent();
|
||||||
static int sleepingEntities = 0;
|
static int sleepingEntities = 0;
|
||||||
@@ -827,26 +827,66 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
|
|
||||||
//TODO entire liquid system is awful
|
//TODO entire liquid system is awful
|
||||||
public void dumpLiquid(Liquid liquid){
|
public void dumpLiquid(Liquid liquid){
|
||||||
dumpLiquid(liquid, 2f);
|
dumpLiquid(liquid, -1);
|
||||||
}
|
|
||||||
|
|
||||||
public void dumpLiquid(Liquid liquid, float scaling){
|
|
||||||
dumpLiquid(liquid, scaling, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param outputDir output liquid direction relative to rotation, or -1 to use any direction. */
|
/** @param outputDir output liquid direction relative to rotation, or -1 to use any direction. */
|
||||||
public void dumpLiquid(Liquid liquid, float scaling, int outputDir){
|
public void dumpLiquid(Liquid liquid, int outputDir){
|
||||||
int dump = this.cdump;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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;
|
if(liquids.get(liquid) <= 0.0001f) return;
|
||||||
|
|
||||||
|
int dump = this.cdump;
|
||||||
|
|
||||||
if(!net.client() && state.isCampaign() && team == state.rules.defaultTeam) liquid.unlock();
|
if(!net.client() && state.isCampaign() && team == state.rules.defaultTeam) liquid.unlock();
|
||||||
|
|
||||||
for(int i = 0; i < proximity.size; i++){
|
for(int i = 0; i < proximity.size; i++){
|
||||||
incrementDump(proximity.size);
|
incrementDump(proximity.size);
|
||||||
|
|
||||||
Building other = proximity.get((i + dump) % proximity.size);
|
Building other = proximity.get((i + dump) % proximity.size);
|
||||||
if(outputDir != -1 && (outputDir + rotation) % 4 != relativeTo(other)) continue;
|
|
||||||
|
|
||||||
other = other.getLiquidDestination(self(), liquid);
|
other = other.getLiquidDestination(self(), liquid);
|
||||||
|
|
||||||
@@ -854,7 +894,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
float ofract = other.liquids.get(liquid) / other.block.liquidCapacity;
|
float ofract = other.liquids.get(liquid) / other.block.liquidCapacity;
|
||||||
float fract = liquids.get(liquid) / block.liquidCapacity;
|
float fract = liquids.get(liquid) / block.liquidCapacity;
|
||||||
|
|
||||||
if(ofract < fract) transferLiquid(other, (fract - ofract) * block.liquidCapacity / scaling, liquid);
|
if(ofract < fract) transferLiquid(other, (fract - ofract) * block.liquidCapacity, liquid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class LiquidBridge extends ItemBridge{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doDump(){
|
public void doDump(){
|
||||||
dumpLiquid(liquids.current(), 1f);
|
dumpLiquid(liquids.current());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,7 @@ public class LiquidRouter extends LiquidBlock{
|
|||||||
public class LiquidRouterBuild extends LiquidBuild{
|
public class LiquidRouterBuild extends LiquidBuild{
|
||||||
@Override
|
@Override
|
||||||
public void updateTile(){
|
public void updateTile(){
|
||||||
if(liquids.currentAmount() > 0.01f){
|
distributeLiquid(liquids.current());
|
||||||
dumpLiquid(liquids.current());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ public class GenericCrafter extends Block{
|
|||||||
for(int i = 0; i < outputLiquids.length; i++){
|
for(int i = 0; i < outputLiquids.length; i++){
|
||||||
int dir = liquidOutputDirections.length > i ? liquidOutputDirections[i] : -1;
|
int dir = liquidOutputDirections.length > i ? liquidOutputDirections[i] : -1;
|
||||||
|
|
||||||
dumpLiquid(outputLiquids[i].liquid, 2f, dir);
|
dumpLiquid(outputLiquids[i].liquid, dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user