mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-13 11:29:48 +07:00
Methods renamed / Better build request handling
This commit is contained in:
parent
103f655fa4
commit
d8c997b355
@ -186,7 +186,7 @@ public class WaveInfoDialog extends FloatingDialog{
|
||||
}).width(80f);
|
||||
|
||||
a.add(" + ");
|
||||
a.addField(Strings.fixed(Math.max((Mathf.isZero(group.unitScaling) ? 0 : 1f / group.unitScaling), 0), 2), TextFieldFilter.floatsOnly, text -> {
|
||||
a.addField(Strings.fixed(Math.max((Mathf.zero(group.unitScaling) ? 0 : 1f / group.unitScaling), 0), 2), TextFieldFilter.floatsOnly, text -> {
|
||||
if(Strings.canParsePositiveFloat(text)){
|
||||
group.unitScaling = 1f / Strings.parseFloat(text);
|
||||
updateWaves();
|
||||
|
@ -34,39 +34,36 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
default void updateBuilding(){
|
||||
float finalPlaceDst = state.rules.infiniteResources ? Float.MAX_VALUE : placeDistance;
|
||||
Unit unit = (Unit)this;
|
||||
|
||||
//remove already completed build requests
|
||||
removal.clear();
|
||||
for(BuildRequest req : buildQueue()){
|
||||
removal.add(req);
|
||||
}
|
||||
removal.addAll(buildQueue());
|
||||
|
||||
buildQueue().clear();
|
||||
Structs.filter(buildQueue(), req -> {
|
||||
Tile tile = world.tile(req.x, req.y);
|
||||
return tile == null || (req.breaking && tile.block() == Blocks.air) || (!req.breaking && (tile.rotation() == req.rotation || !req.block.rotate) && tile.block() == req.block);
|
||||
});
|
||||
|
||||
for(BuildRequest request : removal){
|
||||
Tile tile = world.tile(request.x, request.y);
|
||||
TileEntity core = unit.getClosestCore();
|
||||
|
||||
if(!(tile == null || (request.breaking && tile.block() == Blocks.air) ||
|
||||
(!request.breaking && (tile.rotation() == request.rotation || !request.block.rotate) && tile.block() == request.block))){
|
||||
buildQueue().addLast(request);
|
||||
//nothing to build.
|
||||
if(buildRequest() == null) return;
|
||||
|
||||
//find the next build request
|
||||
if(buildQueue().size > 1){
|
||||
int total = 0;
|
||||
BuildRequest req;
|
||||
while((dst((req = buildRequest()).tile()) > finalPlaceDst || shouldSkip(req, core)) && total < buildQueue().size){
|
||||
buildQueue().removeFirst();
|
||||
buildQueue().addLast(req);
|
||||
total++;
|
||||
}
|
||||
}
|
||||
|
||||
BuildRequest current = buildRequest();
|
||||
|
||||
if(current == null){
|
||||
return;
|
||||
}
|
||||
|
||||
Tile tile = world.tile(current.x, current.y);
|
||||
|
||||
if(dst(tile) > finalPlaceDst){
|
||||
if(buildQueue().size > 1){
|
||||
buildQueue().removeFirst();
|
||||
buildQueue().addLast(current);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(!(tile.block() instanceof BuildBlock)){
|
||||
if(!current.initialized && canCreateBlocks() && !current.breaking && Build.validPlace(getTeam(), current.x, current.y, current.block, current.rotation)){
|
||||
Call.beginPlace(getTeam(), current.x, current.y, current.block, current.rotation);
|
||||
@ -78,8 +75,6 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
}
|
||||
}
|
||||
|
||||
TileEntity core = unit.getClosestCore();
|
||||
|
||||
if(tile.entity instanceof BuildEntity && !current.initialized){
|
||||
Core.app.post(() -> Events.fire(new BuildSelectEvent(tile, unit.getTeam(), this, current.breaking)));
|
||||
current.initialized = true;
|
||||
@ -111,9 +106,17 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
}
|
||||
}
|
||||
|
||||
current.stuck = Mathf.equal(current.progress, entity.progress);
|
||||
current.progress = entity.progress;
|
||||
}
|
||||
|
||||
/** @return whether this request should be skipped, in favor of the next one. */
|
||||
default boolean shouldSkip(BuildRequest request, @Nullable TileEntity core){
|
||||
//requests that you have at least *started* are considered
|
||||
if(state.rules.infiniteResources || request.breaking || !request.initialized) return false;
|
||||
return request.stuck && !core.items.has(request.block.requirements);
|
||||
}
|
||||
|
||||
/** Returns the queue for storing build requests. */
|
||||
Queue<BuildRequest> buildQueue();
|
||||
|
||||
@ -287,8 +290,8 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
|
||||
/** Last progress.*/
|
||||
public float progress;
|
||||
/** Whether construction has started for this request.*/
|
||||
public boolean initialized, worldContext = true;
|
||||
/** Whether construction has started for this request, and other special variables.*/
|
||||
public boolean initialized, worldContext = true, stuck;
|
||||
|
||||
/** Visual scale. Used only for rendering.*/
|
||||
public float animScale = 0f;
|
||||
|
@ -30,7 +30,7 @@ public class LoopControl{
|
||||
data.curVolume = Mathf.lerpDelta(data.curVolume, data.volume * avol, 0.2f);
|
||||
|
||||
boolean play = data.curVolume > 0.01f;
|
||||
float pan = Mathf.isZero(data.total, 0.0001f) ? 0f : sound.calcPan(data.sum.x / data.total, data.sum.y / data.total);
|
||||
float pan = Mathf.zero(data.total, 0.0001f) ? 0f : sound.calcPan(data.sum.x / data.total, data.sum.y / data.total);
|
||||
if(data.soundID <= 0){
|
||||
if(play){
|
||||
data.soundID = sound.loop(data.curVolume, 1f, pan);
|
||||
|
@ -63,7 +63,7 @@ public class Bar extends Element{
|
||||
if(fraction == null) return;
|
||||
|
||||
float computed = Mathf.clamp(fraction.get());
|
||||
if(!Mathf.isEqual(lastValue, computed)){
|
||||
if(!Mathf.equal(lastValue, computed)){
|
||||
blink = 1f;
|
||||
lastValue = computed;
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ public class JoinDialog extends FloatingDialog{
|
||||
|
||||
Cell cell = ((Table)pane.getParent()).getCell(button);
|
||||
|
||||
if(!Mathf.isEqual(cell.minWidth(), pw)){
|
||||
if(!Mathf.equal(cell.minWidth(), pw)){
|
||||
cell.width(pw);
|
||||
cell.padLeft(pad);
|
||||
pane.getParent().invalidateHierarchy();
|
||||
|
@ -533,7 +533,7 @@ public class Block extends BlockStorage{
|
||||
float capacity = cons.capacity;
|
||||
|
||||
bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("bar.poweramount", Float.isNaN(entity.power.satisfaction * capacity) ? "<ERROR>" : (int)(entity.power.satisfaction * capacity)) :
|
||||
Core.bundle.get("bar.power"), () -> Pal.powerBar, () -> Mathf.isZero(cons.requestedPower(entity)) && entity.power.graph.getPowerProduced() + entity.power.graph.getBatteryStored() > 0f ? 1f : entity.power.satisfaction));
|
||||
Core.bundle.get("bar.power"), () -> Pal.powerBar, () -> Mathf.zero(cons.requestedPower(entity)) && entity.power.graph.getPowerProduced() + entity.power.graph.getBatteryStored() > 0f ? 1f : entity.power.satisfaction));
|
||||
}
|
||||
|
||||
if(hasItems && configurable){
|
||||
|
@ -200,7 +200,7 @@ public class Conveyor extends Block implements Autotiler{
|
||||
|
||||
if(maxmove > minmove){
|
||||
pos.y += maxmove;
|
||||
if(Mathf.isEqual(pos.x, 0, 0.1f)){
|
||||
if(Mathf.equal(pos.x, 0, 0.1f)){
|
||||
pos.x = 0f;
|
||||
}
|
||||
pos.x = Mathf.lerpDelta(pos.x, 0, 0.1f);
|
||||
|
@ -196,7 +196,7 @@ public class ItemBridge extends Block{
|
||||
entity.uptime = 0f;
|
||||
}else{
|
||||
|
||||
if(entity.cons.valid() && (!hasPower || Mathf.isZero(1f - entity.power.satisfaction))){
|
||||
if(entity.cons.valid() && (!hasPower || Mathf.zero(1f - entity.power.satisfaction))){
|
||||
entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, 0.04f);
|
||||
}else{
|
||||
entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f);
|
||||
|
@ -75,7 +75,7 @@ public class ImpactReactor extends PowerGenerator{
|
||||
boolean prevOut = getPowerProduction(tile) <= consumes.getPower().requestedPower(entity);
|
||||
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
||||
if(Mathf.isEqual(entity.warmup, 1f, 0.001f)){
|
||||
if(Mathf.equal(entity.warmup, 1f, 0.001f)){
|
||||
entity.warmup = 1f;
|
||||
}
|
||||
|
||||
|
@ -47,9 +47,9 @@ public class PowerGraph{
|
||||
}
|
||||
|
||||
public float getSatisfaction(){
|
||||
if(Mathf.isZero(lastPowerProduced)){
|
||||
if(Mathf.zero(lastPowerProduced)){
|
||||
return 0f;
|
||||
}else if(Mathf.isZero(lastPowerNeeded)){
|
||||
}else if(Mathf.zero(lastPowerNeeded)){
|
||||
return 1f;
|
||||
}
|
||||
return Mathf.clamp(lastPowerProduced / lastPowerNeeded);
|
||||
@ -112,7 +112,7 @@ public class PowerGraph{
|
||||
|
||||
public float useBatteries(float needed){
|
||||
float stored = getBatteryStored();
|
||||
if(Mathf.isEqual(stored, 0f)) return 0f;
|
||||
if(Mathf.equal(stored, 0f)) return 0f;
|
||||
|
||||
float used = Math.min(stored, needed);
|
||||
float consumedPowerPercentage = Math.min(1.0f, needed / stored);
|
||||
@ -129,7 +129,7 @@ public class PowerGraph{
|
||||
float capacity = getBatteryCapacity();
|
||||
//how much of the missing in each battery % is charged
|
||||
float chargedPercent = Math.min(excess/capacity, 1f);
|
||||
if(Mathf.isEqual(capacity, 0f)) return 0f;
|
||||
if(Mathf.equal(capacity, 0f)) return 0f;
|
||||
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
@ -145,13 +145,13 @@ public class PowerGraph{
|
||||
|
||||
public void distributePower(float needed, float produced){
|
||||
//distribute even if not needed. this is because some might be requiring power but not using it; it updates consumers
|
||||
float coverage = Mathf.isZero(needed) && Mathf.isZero(produced) ? 0f : Mathf.isZero(needed) ? 1f : Math.min(1, produced / needed);
|
||||
float coverage = Mathf.zero(needed) && Mathf.zero(produced) ? 0f : Mathf.zero(needed) ? 1f : Math.min(1, produced / needed);
|
||||
for(Tile consumer : consumers){
|
||||
Consumers consumes = consumer.block().consumes;
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
if(consumePower.buffered){
|
||||
if(!Mathf.isZero(consumePower.capacity)){
|
||||
if(!Mathf.zero(consumePower.capacity)){
|
||||
// Add an equal percentage of power to all buffers, based on the global power coverage in this graph
|
||||
float maximumRate = consumePower.requestedPower(consumer.entity) * coverage * consumer.entity.delta();
|
||||
consumer.entity.power.satisfaction = Mathf.clamp(consumer.entity.power.satisfaction + maximumRate / consumePower.capacity);
|
||||
@ -198,7 +198,7 @@ public class PowerGraph{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!Mathf.isEqual(powerNeeded, powerProduced)){
|
||||
if(!Mathf.equal(powerNeeded, powerProduced)){
|
||||
if(powerNeeded > powerProduced){
|
||||
powerProduced += useBatteries(powerNeeded - powerProduced);
|
||||
}else if(powerProduced > powerNeeded){
|
||||
|
@ -41,9 +41,9 @@ public class AmmoListValue<T extends UnlockableContent> implements StatValue{
|
||||
sep(bt, Core.bundle.format("bullet.splashdamage", (int)type.splashDamage, Strings.fixed(type.splashDamageRadius / tilesize, 1)));
|
||||
}
|
||||
|
||||
if(!Mathf.isEqual(type.ammoMultiplier, 1f))
|
||||
if(!Mathf.equal(type.ammoMultiplier, 1f))
|
||||
sep(bt, Core.bundle.format("bullet.multiplier", (int)type.ammoMultiplier));
|
||||
if(!Mathf.isEqual(type.reloadMultiplier, 1f))
|
||||
if(!Mathf.equal(type.reloadMultiplier, 1f))
|
||||
sep(bt, Core.bundle.format("bullet.reload", Strings.fixed(type.reloadMultiplier, 1)));
|
||||
|
||||
if(type.knockback > 0){
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=900a4966bf9b05272c8b0c258dc534540c0628fb
|
||||
archash=4082a8d53d41e79d3eb735d0daf4c0f412066f3e
|
||||
|
Loading…
Reference in New Issue
Block a user