Add powerDynamic to Consumers (#5205)

* Add DynamicConsumePower, and powerDynamic to Consumers

* Add period to description of DynamicConsumePower

Co-authored-by: Patrick 'Quezler' Mounier <Quezler@me.com>

* Remove redundant Boolf

Co-authored-by: Patrick 'Quezler' Mounier <Quezler@me.com>
This commit is contained in:
NiChrosia 2021-06-06 18:37:20 -05:00 committed by GitHub
parent 4a922e4c10
commit 79695086c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,20 @@
package mindustry.world.blocks.power;
import arc.func.*;
import mindustry.gen.*;
import mindustry.world.consumers.*;
/** A power consumer that uses a dynamic amount of power. */
public class DynamicConsumePower extends ConsumePower{
private final Floatf<Building> usage;
public DynamicConsumePower(Floatf<Building> usage){
super(0, 0, false);
this.usage = usage;
}
@Override
public float requestedPower(Building entity){
return usage.get(entity);
}
}

View File

@ -68,6 +68,11 @@ public class Consumers{
return add(new ConditionalConsumePower(usage, (Boolf<Building>)cons));
}
/** Creates a consumer that consumes a dynamic amount of power. */
public <T extends Building> ConsumePower powerDynamic(Floatf<T> usage){
return add(new DynamicConsumePower((Floatf<Building>)usage));
}
/**
* Creates a consumer which stores power.
* @param powerCapacity The maximum capacity in power units.