Skip to content

Commit

Permalink
flow change part 2 (havent done it dlc)
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Jan 12, 2025
1 parent e8ee6cc commit 4a8e7b6
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 215 deletions.
4 changes: 2 additions & 2 deletions src/omaloon/content/OlLiquids.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void load(){
addDensity(Liquids.oil, 700);
addViscosity(Liquids.oil, 50);
addDensity(Liquids.cryofluid, 200);
addViscosity(Liquids.cryofluid, 1);
addViscosity(Liquids.cryofluid, 1.2f);
addDensity(glacium, 1300);
addViscosity(glacium, 13);
addDensity(tiredGlacium, 1300);
Expand All @@ -70,7 +70,7 @@ public static void addViscosity(Liquid liquid, float viscosity) {
}

public static float getDensity(@Nullable Liquid liquid) {
return densities.get(liquid, 1.2f);
return densities.get(liquid, 1f);
}

public static float getViscosity(@Nullable Liquid liquid) {
Expand Down
2 changes: 1 addition & 1 deletion src/omaloon/content/blocks/OlDistributionBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static void load() {
researchCost = with(
OlItems.cobalt, 20
);
pressureTransfer = 0.1f;
pumpStrength = 0.1f;
pressureDifference = 20f;
}};

Expand Down
35 changes: 21 additions & 14 deletions src/omaloon/world/blocks/liquid/PressureLiquidPump.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import omaloon.content.*;
import omaloon.utils.*;
import omaloon.world.interfaces.*;
import omaloon.world.meta.*;
Expand All @@ -27,7 +28,7 @@
public class PressureLiquidPump extends Block {
public PressureConfig pressureConfig = new PressureConfig();

public float pressureTransfer = 0.1f;
public float pumpStrength = 0.1f;

public float pressureDifference = 10;

Expand Down Expand Up @@ -115,7 +116,7 @@ public void load() {
public void setStats() {
super.setStats();
pressureConfig.addStats(stats);
stats.add(OlStats.pressureFlow, Mathf.round(pressureTransfer * 60f, 2), OlStats.pressureSecond);
stats.add(OlStats.pressureFlow, Mathf.round(pumpStrength * 60f, 2), OlStats.pressureSecond);
}

public class PressureLiquidPumpBuild extends Building implements HasPressure {
Expand Down Expand Up @@ -266,18 +267,24 @@ public void updateTile() {
HasPressure front = getTo();
HasPressure back = getFrom();

if (front != null && back != null) {
Liquid pumpLiquid = configurable ? Vars.content.liquid(filter) : back.pressure().getMain();
float frontPressure = front.pressure().getPressure(pumpLiquid), backPressure = back.pressure().getPressure(pumpLiquid);
float flow = pressureTransfer/chainSize() * (backPressure - frontPressure + pressureDifference * chainSize());
if (pumpLiquid != null) flow = Mathf.clamp(flow, -front.pressure().liquids[pumpLiquid.id], back.pressure().liquids[pumpLiquid.id]);
if (
front.acceptsPressurizedFluid(back, pumpLiquid, flow) &&
back.outputsPressurizedFluid(front, pumpLiquid, flow)
) {
front.addFluid(pumpLiquid, flow);
back.removeFluid(pumpLiquid, flow);
}
@Nullable Liquid pumpLiquid = configurable ? Vars.content.liquid(filter) : (back == null ? null : back.pressure().getMain());

float frontPressure = front == null ? 0 : front.pressure().getPressure(pumpLiquid);
float backPressure = back == null ? 0 : back.pressure().getPressure(pumpLiquid);

float flow = pumpStrength/chainSize() * ((backPressure + pressureDifference * chainSize()) - frontPressure) / OlLiquids.getViscosity(pumpLiquid);

if (pumpLiquid != null && front != null && back != null) {
flow = Mathf.clamp(flow, -front.pressure().get(pumpLiquid), back.pressure().get(pumpLiquid));
}

if (
front == null || back == null ||
(front.acceptsPressurizedFluid(back, pumpLiquid, flow) &&
back.outputsPressurizedFluid(front, pumpLiquid, flow))
) {
if (front != null) front.addFluid(pumpLiquid, flow);
if (back != null) back.removeFluid(pumpLiquid, flow);
}
}
}
Expand Down
181 changes: 0 additions & 181 deletions src/omaloon/world/blocks/production/Pressurizer.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/omaloon/world/interfaces/HasPressure.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ default void removeFluid(@Nullable Liquid liquid, float amount) {
* method to update pressure related things
*/
default void updatePressure() {
if (nextBuilds().contains(other -> other.pressure().section != this)) pressure().section.updateTransfer();
// if (nextBuilds().contains(other -> other.pressure().section != this)) pressure().section.updateTransfer();

Vars.content.liquids().each(liquid -> {
if (Mathf.round(pressure().getPressure(liquid)) < pressureConfig().minPressure - 1) damage(pressureConfig().underPressureDamage);
Expand Down
83 changes: 67 additions & 16 deletions src/omaloon/world/meta/PressureSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,82 @@ public void updateTransfer() {
});

FloatSeq amounts = new FloatSeq();

for(Entry<HasPressure, HasPressure> entry : links) {
@Nullable Liquid main = entry.value.pressure().getMain();

Vars.content.liquids().each(main -> {
amounts.clear();
for (Entry<HasPressure, HasPressure> entry : links) {
float flow = OlMath.flowRate(entry.value.pressureConfig().fluidCapacity,
entry.key.pressure().getPressure(main),
entry.value.pressure().getPressure(main),
OlLiquids.getViscosity(main)
) / (2f * links.size);

if (
(
flow > 0 ?
(
entry.key.acceptsPressurizedFluid(entry.value, main, flow) &&
entry.value.outputsPressurizedFluid(entry.key, main, flow)
) :
(
entry.value.acceptsPressurizedFluid(entry.key, main, flow) &&
entry.key.outputsPressurizedFluid(entry.value, main, flow)
)
) &&
(entry.key.pressure().get(main) > 0 || entry.value.pressure().get(main) > 0)
) {
amounts.add(flow);
} else {
amounts.add(0);
}
}
for (Entry<HasPressure, HasPressure> entry : links) {
float flow = Mathf.clamp(
amounts.get(links.indexOf(entry)),
-Math.abs(entry.key.pressure().get(main) - entry.value.pressure().get(main))/2f,
Math.abs(entry.key.pressure().get(main) - entry.value.pressure().get(main))/2f
);
// float flow = amounts.get(links.indexOf(entry));
if (flow != 0) {
entry.key.addFluid(main, flow);
entry.value.removeFluid(main, flow);
}
}
});
amounts.clear();
for (Entry<HasPressure, HasPressure> entry : links) {
float flow = OlMath.flowRate(entry.value.pressureConfig().fluidCapacity,
entry.key.pressure().getPressure(main),
entry.value.pressure().getPressure(main),
OlLiquids.getViscosity(main)
)/(2f * links.size);
entry.key.pressure().getPressure(null),
entry.value.pressure().getPressure(null),
OlLiquids.getViscosity(null)
) / (2f * links.size);

if (
entry.key.acceptsPressurizedFluid(entry.value, main, flow) &&
entry.value.outputsPressurizedFluid(entry.key, main, flow)
(
flow > 0 ?
(
entry.key.acceptsPressurizedFluid(entry.value, null, flow) &&
entry.value.outputsPressurizedFluid(entry.key, null, flow)
) : (
entry.value.acceptsPressurizedFluid(entry.key, null, flow) &&
entry.key.outputsPressurizedFluid(entry.value, null, flow)
)
)
) {
amounts.add(flow);
} else {
amounts.add(0);
}
}


for(Entry<HasPressure, HasPressure> entry : links) {
@Nullable Liquid main = entry.value.pressure().getMain();
if (amounts.get(links.indexOf(entry)) != 0) {
entry.key.addFluid(main, amounts.get(links.indexOf(entry)));
entry.value.removeFluid(main, amounts.get(links.indexOf(entry)));
for (Entry<HasPressure, HasPressure> entry : links) {
float flow = Mathf.clamp(
amounts.get(links.indexOf(entry)),
-Math.abs(entry.key.pressure().get(null) - entry.value.pressure().get(null))/2f,
Math.abs(entry.key.pressure().get(null) - entry.value.pressure().get(null))/2f
);
if (flow != 0) {
entry.key.addFluid(null, amounts.get(links.indexOf(entry)));
entry.value.removeFluid(null, amounts.get(links.indexOf(entry)));
}
}
}
Expand Down

0 comments on commit 4a8e7b6

Please sign in to comment.