Added Tests, fixed detected bugs and updated JUnit

This commit is contained in:
Timmeey86
2018-11-22 23:30:49 +01:00
parent 7683e86d8b
commit 560d388df4
6 changed files with 179 additions and 108 deletions

View File

@@ -99,15 +99,22 @@ public class PowerGraph{
}
public void distributePower(float needed, float produced){
if(MathUtils.isEqual(needed,0f)){ return; }
if(MathUtils.isEqual(needed, 0f)){ return; }
float coverage = Math.min(1, produced / needed);
for(Tile consumer : consumers){
Consumers consumes = consumer.block().consumes;
if(consumes.has(ConsumePower.class) && consumes.get(ConsumePower.class).isBuffered){
consumer.entity.power.satisfaction += (1 - consumer.entity.power.satisfaction) * coverage;
}else{
consumer.entity.power.satisfaction = coverage;
if(consumes.has(ConsumePower.class)){
ConsumePower consumePower = consumes.get(ConsumePower.class);
if(consumePower.isBuffered){
// Add a percentage of the requested amount, but limit it to the mission amount.
// TODO This can maybe be calculated without converting to absolute values first
float maximumRate = consumePower.requestedPower(consumer.block(), consumer.entity()) * coverage;
float missingAmount = consumePower.powerCapacity * (1 - consumer.entity.power.satisfaction);
consumer.entity.power.satisfaction += Math.min(missingAmount, maximumRate) / consumePower.powerCapacity;
}else{
consumer.entity.power.satisfaction = coverage;
}
}
}
}
@@ -205,12 +212,12 @@ public class PowerGraph{
@Override
public String toString(){
return "PowerGraph{" +
"producers=" + producers +
", consumers=" + consumers +
", batteries=" + batteries +
", all=" + all +
", lastFrameUpdated=" + lastFrameUpdated +
", graphID=" + graphID +
'}';
"producers=" + producers +
", consumers=" + consumers +
", batteries=" + batteries +
", all=" + all +
", lastFrameUpdated=" + lastFrameUpdated +
", graphID=" + graphID +
'}';
}
}

View File

@@ -12,7 +12,7 @@ public class PowerModule extends BlockModule{
* Blocks will work at a reduced efficiency if this is not equal to 1.0f.
* In case of buffered consumers, this is the percentage of power stored in relation to the maximum capacity.
*/
public float satisfaction;
public float satisfaction = 0.0f;
/** Specifies power which is required additionally, e.g. while a force projector is being shot at. */
public float extraUse = 0f;
public PowerGraph graph = new PowerGraph();