2013-12-27 23:59:59 +01:00
|
|
|
package appeng.me.cache;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import appeng.api.networking.IGrid;
|
|
|
|
import appeng.api.networking.IGridHost;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.IGridStorage;
|
|
|
|
import appeng.api.networking.events.MENetworkBootingStatusChange;
|
|
|
|
import appeng.api.networking.events.MENetworkEventSubscribe;
|
|
|
|
import appeng.api.networking.spatial.ISpatialCache;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
|
|
|
import appeng.api.util.IReadOnlyCollection;
|
2014-02-09 06:08:27 +01:00
|
|
|
import appeng.core.AEConfig;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.me.cluster.implementations.SpatialPylonCluster;
|
|
|
|
import appeng.tile.spatial.TileSpatialIOPort;
|
|
|
|
import appeng.tile.spatial.TileSpatialPylon;
|
|
|
|
|
2014-10-04 08:08:28 +02:00
|
|
|
public class SpatialPylonCache implements ISpatialCache
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
long powerRequired = 0;
|
2014-09-21 00:46:09 +02:00
|
|
|
double efficiency = 0.0;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
DimensionalCoord captureMin;
|
|
|
|
DimensionalCoord captureMax;
|
|
|
|
boolean isValid = false;
|
|
|
|
|
2014-09-28 22:20:14 +02:00
|
|
|
List<TileSpatialIOPort> ioPorts = new LinkedList<TileSpatialIOPort>();
|
|
|
|
HashMap<SpatialPylonCluster, SpatialPylonCluster> clusters = new HashMap<SpatialPylonCluster, SpatialPylonCluster>();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
boolean needsUpdate = false;
|
|
|
|
|
|
|
|
final IGrid myGrid;
|
|
|
|
|
|
|
|
public SpatialPylonCache(IGrid g) {
|
|
|
|
myGrid = g;
|
|
|
|
}
|
|
|
|
|
2014-03-05 08:27:42 +01:00
|
|
|
@Override
|
|
|
|
public long requiredPower()
|
|
|
|
{
|
|
|
|
return powerRequired;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasRegion()
|
|
|
|
{
|
|
|
|
return captureMin != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isValidRegion()
|
|
|
|
{
|
|
|
|
return hasRegion() && isValid;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DimensionalCoord getMin()
|
|
|
|
{
|
|
|
|
return captureMin;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DimensionalCoord getMax()
|
|
|
|
{
|
|
|
|
return captureMax;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reset(IGrid grid)
|
|
|
|
{
|
|
|
|
int reqX = 0;
|
|
|
|
int reqY = 0;
|
|
|
|
int reqZ = 0;
|
2014-09-21 00:46:42 +02:00
|
|
|
int requirePylonBlocks = 1;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
double minPower = 0;
|
|
|
|
double maxPower = 0;
|
|
|
|
|
2014-09-28 22:20:14 +02:00
|
|
|
clusters = new HashMap<SpatialPylonCluster, SpatialPylonCluster>();
|
|
|
|
ioPorts = new LinkedList<TileSpatialIOPort>();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
for (IGridNode gm : grid.getMachines( TileSpatialIOPort.class ))
|
|
|
|
{
|
|
|
|
ioPorts.add( (TileSpatialIOPort) gm.getMachine() );
|
|
|
|
}
|
|
|
|
|
|
|
|
IReadOnlyCollection<IGridNode> set = grid.getMachines( TileSpatialPylon.class );
|
|
|
|
for (IGridNode gm : set)
|
|
|
|
{
|
2014-03-07 07:15:25 +01:00
|
|
|
if ( gm.meetsChannelRequirements() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
SpatialPylonCluster c = ((TileSpatialPylon) gm.getMachine()).getCluster();
|
|
|
|
if ( c != null )
|
|
|
|
clusters.put( c, c );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
captureMax = null;
|
|
|
|
captureMin = null;
|
|
|
|
isValid = true;
|
|
|
|
|
|
|
|
int pylonBlocks = 0;
|
|
|
|
for (SpatialPylonCluster cl : clusters.values())
|
|
|
|
{
|
|
|
|
if ( captureMax == null )
|
|
|
|
captureMax = cl.max.copy();
|
|
|
|
if ( captureMin == null )
|
|
|
|
captureMin = cl.min.copy();
|
|
|
|
|
|
|
|
pylonBlocks += cl.tileCount();
|
|
|
|
|
|
|
|
captureMin.x = Math.min( captureMin.x, cl.min.x );
|
|
|
|
captureMin.y = Math.min( captureMin.y, cl.min.y );
|
|
|
|
captureMin.z = Math.min( captureMin.z, cl.min.z );
|
|
|
|
|
|
|
|
captureMax.x = Math.max( captureMax.x, cl.max.x );
|
|
|
|
captureMax.y = Math.max( captureMax.y, cl.max.y );
|
|
|
|
captureMax.z = Math.max( captureMax.z, cl.max.z );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( hasRegion() )
|
|
|
|
{
|
|
|
|
isValid = captureMax.x - captureMin.x > 1 && captureMax.y - captureMin.y > 1 && captureMax.z - captureMin.z > 1;
|
|
|
|
|
|
|
|
for (SpatialPylonCluster cl : clusters.values())
|
|
|
|
{
|
|
|
|
switch (cl.currentAxis)
|
|
|
|
{
|
|
|
|
case X:
|
|
|
|
|
|
|
|
isValid = isValid && ((captureMax.y == cl.min.y || captureMin.y == cl.max.y) || (captureMax.z == cl.min.z || captureMin.z == cl.max.z))
|
|
|
|
&& ((captureMax.y == cl.max.y || captureMin.y == cl.min.y) || (captureMax.z == cl.max.z || captureMin.z == cl.min.z));
|
|
|
|
|
|
|
|
break;
|
|
|
|
case Y:
|
|
|
|
|
|
|
|
isValid = isValid && ((captureMax.x == cl.min.x || captureMin.x == cl.max.x) || (captureMax.z == cl.min.z || captureMin.z == cl.max.z))
|
|
|
|
&& ((captureMax.x == cl.max.x || captureMin.x == cl.min.x) || (captureMax.z == cl.max.z || captureMin.z == cl.min.z));
|
|
|
|
|
|
|
|
break;
|
|
|
|
case Z:
|
|
|
|
|
|
|
|
isValid = isValid && ((captureMax.y == cl.min.y || captureMin.y == cl.max.y) || (captureMax.x == cl.min.x || captureMin.x == cl.max.x))
|
|
|
|
&& ((captureMax.y == cl.max.y || captureMin.y == cl.min.y) || (captureMax.x == cl.max.x || captureMin.x == cl.min.x));
|
|
|
|
|
|
|
|
break;
|
|
|
|
case UNFORMED:
|
|
|
|
isValid = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reqX = captureMax.x - captureMin.x;
|
|
|
|
reqY = captureMax.y - captureMin.y;
|
|
|
|
reqZ = captureMax.z - captureMin.z;
|
2014-09-21 00:46:42 +02:00
|
|
|
requirePylonBlocks = Math.max( 6, ((reqX * reqZ + reqX * reqY + reqY * reqZ) * 3) / 8 );
|
2014-08-28 23:15:49 +02:00
|
|
|
|
2014-09-21 00:46:42 +02:00
|
|
|
efficiency = (double) pylonBlocks / (double) requirePylonBlocks;
|
2014-08-28 23:15:49 +02:00
|
|
|
|
2014-09-21 00:46:09 +02:00
|
|
|
if ( efficiency > 1.0 )
|
|
|
|
efficiency = 1.0;
|
|
|
|
if ( efficiency < 0.0 )
|
|
|
|
efficiency = 0.0;
|
2014-08-28 23:15:49 +02:00
|
|
|
|
2014-02-09 06:08:27 +01:00
|
|
|
minPower = (double) reqX * (double) reqY * reqZ * AEConfig.instance.spatialPowerMultiplier;
|
2014-09-28 11:47:17 +02:00
|
|
|
maxPower = Math.pow( minPower, AEConfig.instance.spatialPowerExponent );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-09-21 00:46:09 +02:00
|
|
|
double affective_efficiency = Math.pow( efficiency, 0.25 );
|
|
|
|
powerRequired = (long) (affective_efficiency * minPower + (1.0 - affective_efficiency) * maxPower);
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
for (SpatialPylonCluster cl : clusters.values())
|
|
|
|
{
|
|
|
|
boolean myWasValid = cl.isValid;
|
|
|
|
cl.isValid = isValid;
|
|
|
|
if ( myWasValid != isValid )
|
|
|
|
cl.updateStatus( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-06 06:45:14 +01:00
|
|
|
@Override
|
2014-09-20 22:46:41 +02:00
|
|
|
public float currentEfficiency()
|
2014-03-06 06:45:14 +01:00
|
|
|
{
|
2014-09-21 00:46:09 +02:00
|
|
|
return (float) efficiency * 100;
|
2014-03-06 06:45:14 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@MENetworkEventSubscribe
|
|
|
|
public void bootingRender(MENetworkBootingStatusChange c)
|
|
|
|
{
|
|
|
|
reset( myGrid );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-04 17:11:29 +01:00
|
|
|
public void onUpdateTick()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-04 17:11:29 +01:00
|
|
|
public void addNode(IGridNode node, IGridHost machine)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-04 17:11:29 +01:00
|
|
|
public void removeNode(IGridNode node, IGridHost machine)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSplit(IGridStorage storageB)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onJoin(IGridStorage storageB)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void populateGridStorage(IGridStorage storage)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|