worked on network power calculations
more of redoing them since i deleted the old ones right off the back when updating to 1.6.2 to remove the chance of errors
This commit is contained in:
parent
640a0e27b2
commit
e6a33285be
1 changed files with 73 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
|||
package dark.assembly.common.machine;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
@ -15,8 +16,27 @@ import dark.core.tile.network.NetworkTileEntities;
|
|||
|
||||
public class NetworkAssembly extends NetworkSharedPower
|
||||
{
|
||||
public Set<TileEntity> powerSources = new HashSet<TileEntity>();
|
||||
public Set<TileEntity> powerLoads = new HashSet<TileEntity>();
|
||||
/** Set of tiles that count as power sources */
|
||||
private Set<TileEntity> powerSources = new HashSet<TileEntity>();
|
||||
/** Set of tiles that count as power loads */
|
||||
private Set<TileEntity> powerLoads = new HashSet<TileEntity>();
|
||||
/** Network last calculation of power required by the network */
|
||||
private float lastNetDemand = 0;
|
||||
/** System time when the last power calculation was made */
|
||||
private long lastDemandCalcTime = 0;
|
||||
/** Network last calculation of power required by the network parts */
|
||||
private float lastNetPartsDemand = 0;
|
||||
/** System time when the last power calculation was made for network parts */
|
||||
private long lastDemandPCalcTime = 0;
|
||||
/** Date instance used to record the tile when last calculation were made */
|
||||
private Date date = new Date();
|
||||
|
||||
/** Average power demand of the entire network */
|
||||
public float averageDemand = 0;
|
||||
/** highest demand the network has seen */
|
||||
public float maxDemand = 0;
|
||||
/** lowest demand the network has seen */
|
||||
public float minDemand = 0;
|
||||
|
||||
public NetworkAssembly(INetworkPart... parts)
|
||||
{
|
||||
|
@ -24,11 +44,61 @@ public class NetworkAssembly extends NetworkSharedPower
|
|||
}
|
||||
|
||||
@Override
|
||||
public NetworkTileEntities newInstance()
|
||||
public NetworkAssembly newInstance()
|
||||
{
|
||||
return new NetworkAssembly();
|
||||
}
|
||||
|
||||
/** Gets the demand of all parts of the network including network parts */
|
||||
public float getNetworkDemand()
|
||||
{
|
||||
float lastDemand = lastNetDemand;
|
||||
float currentDemand = 0;
|
||||
long lastTime = lastDemandCalcTime;
|
||||
long time = date.getTime();
|
||||
if(lastTime == 0)
|
||||
{
|
||||
lastTime = time;
|
||||
}
|
||||
currentDemand += getNetworkPartsDemand();
|
||||
|
||||
|
||||
return currentDemand;
|
||||
}
|
||||
|
||||
/** Gets the demand of all parts contained in the network so to power them first */
|
||||
public float getNetworkPartsDemand()
|
||||
{
|
||||
float lastDemand = lastNetPartsDemand;
|
||||
float currentDemand = 0;
|
||||
long lastTime = lastDemandPCalcTime;
|
||||
long time = date.getTime();
|
||||
if(lastTime == 0)
|
||||
{
|
||||
lastTime = time;
|
||||
}
|
||||
|
||||
for(INetworkPart part : this.getNetworkMemebers())
|
||||
{
|
||||
if(part instanceof TileEntityAssembly)
|
||||
{
|
||||
currentDemand += ((TileEntityAssembly) part).getWattLoad();
|
||||
}
|
||||
}
|
||||
|
||||
lastDemandPCalcTime = time;
|
||||
lastNetPartsDemand = currentDemand;
|
||||
//TODO calculate average
|
||||
return currentDemand;
|
||||
}
|
||||
|
||||
/** Called when the network gets more power then its parts need. Also called after all parts in
|
||||
* the network get there power and is time to start suppling connections */
|
||||
public void supplyPower(float power)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addTile(TileEntity tileEntity, boolean member)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue