2013-12-27 23:59:59 +01:00
|
|
|
package appeng.me;
|
|
|
|
|
2014-07-13 22:45:00 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2014-01-27 05:00:36 +01:00
|
|
|
import java.util.concurrent.Callable;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.world.World;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.exceptions.FailedConnection;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.GridFlags;
|
|
|
|
import appeng.api.networking.GridNotification;
|
|
|
|
import appeng.api.networking.IGrid;
|
|
|
|
import appeng.api.networking.IGridBlock;
|
|
|
|
import appeng.api.networking.IGridCache;
|
2014-09-20 22:24:40 +02:00
|
|
|
import appeng.api.networking.IGridConnectionVisitor;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.IGridConnection;
|
|
|
|
import appeng.api.networking.IGridHost;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.IGridVisitor;
|
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
|
|
|
import appeng.api.networking.events.MENetworkChannelsChanged;
|
|
|
|
import appeng.api.networking.pathing.IPathingGrid;
|
|
|
|
import appeng.api.util.AEColor;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
|
|
|
import appeng.api.util.IReadOnlyCollection;
|
|
|
|
import appeng.core.WorldSettings;
|
2014-03-02 09:35:11 +01:00
|
|
|
import appeng.hooks.TickHandler;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.me.pathfinding.IPathItem;
|
|
|
|
import appeng.util.ReadOnlyCollection;
|
|
|
|
|
|
|
|
public class GridNode implements IGridNode, IPathItem
|
|
|
|
{
|
|
|
|
|
|
|
|
final static private MENetworkChannelsChanged event = new MENetworkChannelsChanged();
|
2014-08-28 10:40:06 +02:00
|
|
|
final static private int channelCount[] = new int[] { 0, 8, 32 };
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
final List<IGridConnection> Connections = new LinkedList();
|
|
|
|
GridStorage myStorage = null;
|
|
|
|
|
|
|
|
IGridBlock gridProxy;
|
|
|
|
Grid myGrid;
|
|
|
|
|
2014-04-23 04:49:03 +02:00
|
|
|
Object visitorIterationNumber = null;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
// connection criteria
|
2014-08-28 10:40:06 +02:00
|
|
|
private int compressedData = 0;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateState()
|
|
|
|
{
|
|
|
|
EnumSet<GridFlags> set = gridProxy.getFlags();
|
|
|
|
|
|
|
|
compressedData = set.contains( GridFlags.CANNOT_CARRY ) ? 0 : (set.contains( GridFlags.DENSE_CAPACITY ) ? 2 : 1);
|
|
|
|
|
|
|
|
compressedData = compressedData | (gridProxy.getGridColor().ordinal() << 3);
|
|
|
|
|
|
|
|
for (ForgeDirection dir : gridProxy.getConnectableSides())
|
|
|
|
compressedData = compressedData | (1 << (dir.ordinal() + 8));
|
|
|
|
|
|
|
|
FindConnections();
|
|
|
|
getInternalGrid();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMaxChannels()
|
|
|
|
{
|
|
|
|
return channelCount[compressedData & 0x03];
|
|
|
|
}
|
|
|
|
|
|
|
|
public AEColor getColor()
|
|
|
|
{
|
|
|
|
return AEColor.values()[(compressedData >> 3) & 0x1F];
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isValidDirection(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
return (compressedData & (1 << (8 + dir.ordinal()))) > 0;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
// old power draw, used to diff
|
|
|
|
public double previousDraw = 0.0;
|
|
|
|
|
|
|
|
private int channelData = 0;
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
public long lastSecurityKey = -1;
|
|
|
|
public int playerID = -1;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPlayerID(int playerID)
|
|
|
|
{
|
|
|
|
if ( playerID >= 0 )
|
|
|
|
this.playerID = playerID;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public int usedChannels()
|
|
|
|
{
|
|
|
|
return channelData >> 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GridNode(IGridBlock what) {
|
|
|
|
gridProxy = what;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadFromNBT(String name, NBTTagCompound nodeData)
|
|
|
|
{
|
|
|
|
if ( myGrid == null )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
|
|
|
NBTTagCompound node = nodeData.getCompoundTag( name );
|
|
|
|
playerID = node.getInteger( "p" );
|
|
|
|
lastSecurityKey = node.getLong( "k" );
|
|
|
|
setGridStorage( WorldSettings.getInstance().getGridStorage( node.getLong( "g" ) ) );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
else
|
|
|
|
throw new RuntimeException( "Loading data after part of a grid, this is invalid." );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void saveToNBT(String name, NBTTagCompound nodeData)
|
|
|
|
{
|
|
|
|
if ( myStorage != null )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
|
|
|
NBTTagCompound node = new NBTTagCompound();
|
|
|
|
|
|
|
|
node.setInteger( "p", playerID );
|
|
|
|
node.setLong( "k", lastSecurityKey );
|
|
|
|
node.setLong( "g", myStorage.getID() );
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
nodeData.setTag( name, node );
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
else
|
|
|
|
nodeData.removeTag( name );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridBlock getGridBlock()
|
|
|
|
{
|
|
|
|
return gridProxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumSet<ForgeDirection> getConnectedSides()
|
|
|
|
{
|
|
|
|
EnumSet<ForgeDirection> set = EnumSet.noneOf( ForgeDirection.class );
|
|
|
|
for (IGridConnection gc : Connections)
|
|
|
|
set.add( gc.getDirection( this ) );
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Class<? extends IGridHost> getMachineClass()
|
|
|
|
{
|
|
|
|
return getMachine().getClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridHost getMachine()
|
|
|
|
{
|
|
|
|
return gridProxy.getMachine();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-20 22:37:36 +02:00
|
|
|
public void beginVisit(IGridVisitor g)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-04-23 04:49:03 +02:00
|
|
|
Object tracker = new Object();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
LinkedList<GridNode> nextRun = new LinkedList();
|
|
|
|
nextRun.add( this );
|
|
|
|
|
2014-04-23 04:49:03 +02:00
|
|
|
visitorIterationNumber = tracker;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-09-20 22:24:40 +02:00
|
|
|
if ( g instanceof IGridConnectionVisitor )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
LinkedList<IGridConnection> nextConn = new LinkedList();
|
2014-09-20 22:24:40 +02:00
|
|
|
IGridConnectionVisitor gcv = (IGridConnectionVisitor) g;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
while (!nextRun.isEmpty())
|
|
|
|
{
|
|
|
|
while (!nextConn.isEmpty())
|
|
|
|
gcv.visitConnection( nextConn.poll() );
|
|
|
|
|
|
|
|
LinkedList<GridNode> thisRun = nextRun;
|
|
|
|
nextRun = new LinkedList();
|
|
|
|
|
|
|
|
for (GridNode n : thisRun)
|
2014-04-23 04:49:03 +02:00
|
|
|
n.visitorConnection( tracker, g, nextRun, nextConn );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (!nextRun.isEmpty())
|
|
|
|
{
|
|
|
|
LinkedList<GridNode> thisRun = nextRun;
|
|
|
|
nextRun = new LinkedList();
|
|
|
|
|
|
|
|
for (GridNode n : thisRun)
|
2014-04-23 04:49:03 +02:00
|
|
|
n.visitorNode( tracker, g, nextRun );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-23 04:49:03 +02:00
|
|
|
private void visitorConnection(Object tracker, IGridVisitor g, LinkedList<GridNode> nextRun, LinkedList<IGridConnection> nextConnections)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( g.visitNode( this ) )
|
|
|
|
{
|
|
|
|
for (IGridConnection gc : getConnections())
|
|
|
|
{
|
|
|
|
GridNode gn = (GridNode) gc.getOtherSide( this );
|
|
|
|
GridConnection gcc = (GridConnection) gc;
|
|
|
|
|
2014-04-23 04:49:03 +02:00
|
|
|
if ( gcc.visitorIterationNumber != tracker )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-04-23 04:49:03 +02:00
|
|
|
gcc.visitorIterationNumber = tracker;
|
2013-12-27 23:59:59 +01:00
|
|
|
nextConnections.add( gc );
|
|
|
|
}
|
|
|
|
|
2014-04-23 04:49:03 +02:00
|
|
|
if ( tracker == gn.visitorIterationNumber )
|
2013-12-27 23:59:59 +01:00
|
|
|
continue;
|
|
|
|
|
2014-04-23 04:49:03 +02:00
|
|
|
gn.visitorIterationNumber = tracker;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
nextRun.add( gn );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-23 04:49:03 +02:00
|
|
|
private void visitorNode(Object tracker, IGridVisitor g, LinkedList<GridNode> nextRun)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( g.visitNode( this ) )
|
|
|
|
{
|
|
|
|
for (IGridConnection gc : getConnections())
|
|
|
|
{
|
|
|
|
GridNode gn = (GridNode) gc.getOtherSide( this );
|
|
|
|
|
2014-04-23 04:49:03 +02:00
|
|
|
if ( tracker == gn.visitorIterationNumber )
|
2013-12-27 23:59:59 +01:00
|
|
|
continue;
|
|
|
|
|
2014-04-23 04:49:03 +02:00
|
|
|
gn.visitorIterationNumber = tracker;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
nextRun.add( gn );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void FindConnections()
|
|
|
|
{
|
2014-09-20 22:40:10 +02:00
|
|
|
if ( !gridProxy.isWorldAccessible() )
|
2013-12-27 23:59:59 +01:00
|
|
|
return;
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
EnumSet<ForgeDirection> newSecurityConnections = EnumSet.noneOf( ForgeDirection.class );
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
DimensionalCoord dc = gridProxy.getLocation();
|
|
|
|
for (ForgeDirection f : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
{
|
|
|
|
IGridHost te = findGridHost( dc.getWorld(), dc.x + f.offsetX, dc.y + f.offsetY, dc.z + f.offsetZ );
|
|
|
|
if ( te != null )
|
|
|
|
{
|
|
|
|
GridNode node = (GridNode) te.getGridNode( f.getOpposite() );
|
|
|
|
if ( node == null )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
boolean isValidConnection = this.canConnect( node, f ) && node.canConnect( this, f.getOpposite() );
|
|
|
|
|
|
|
|
IGridConnection con = null; // find the connection for this
|
|
|
|
// direction..
|
|
|
|
for (IGridConnection c : getConnections())
|
|
|
|
{
|
|
|
|
if ( c.getDirection( this ) == f )
|
|
|
|
{
|
|
|
|
con = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( con != null )
|
|
|
|
{
|
|
|
|
IGridNode os = (IGridNode) con.getOtherSide( this );
|
|
|
|
if ( os == node )
|
|
|
|
{
|
|
|
|
// if this connection is no longer valid, destroy it.
|
|
|
|
if ( !isValidConnection )
|
|
|
|
con.destroy();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-23 08:25:26 +02:00
|
|
|
con.destroy();
|
|
|
|
// throw new GridException( "invalid state found, encountered connection to phantom block." );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( isValidConnection )
|
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
if ( node.lastSecurityKey != -1 )
|
|
|
|
newSecurityConnections.add( f );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// construct a new connection between these two nodes.
|
|
|
|
try
|
|
|
|
{
|
|
|
|
new GridConnection( node, this, f.getOpposite() );
|
|
|
|
}
|
|
|
|
catch (FailedConnection e)
|
|
|
|
{
|
2014-07-08 06:54:28 +02:00
|
|
|
TickHandler.instance.addCallable( node.getWorld(), new Callable() {
|
2014-01-27 05:00:36 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object call() throws Exception
|
|
|
|
{
|
|
|
|
getMachine().securityBreak();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ForgeDirection f : newSecurityConnections)
|
|
|
|
{
|
|
|
|
IGridHost te = findGridHost( dc.getWorld(), dc.x + f.offsetX, dc.y + f.offsetY, dc.z + f.offsetZ );
|
|
|
|
if ( te != null )
|
|
|
|
{
|
|
|
|
GridNode node = (GridNode) te.getGridNode( f.getOpposite() );
|
|
|
|
if ( node == null )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// construct a new connection between these two nodes.
|
|
|
|
try
|
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
new GridConnection( node, this, f.getOpposite() );
|
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
catch (FailedConnection e)
|
|
|
|
{
|
2014-07-08 06:54:28 +02:00
|
|
|
TickHandler.instance.addCallable( node.getWorld(), new Callable() {
|
2014-01-27 05:00:36 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object call() throws Exception
|
|
|
|
{
|
|
|
|
getMachine().securityBreak();
|
|
|
|
return null;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
} );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private IGridHost findGridHost(World world, int x, int y, int z)
|
|
|
|
{
|
|
|
|
if ( world.blockExists( x, y, z ) )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
TileEntity te = world.getTileEntity( x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( te instanceof IGridHost )
|
|
|
|
return (IGridHost) te;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addConnection(IGridConnection gridConnection)
|
|
|
|
{
|
|
|
|
Connections.add( gridConnection );
|
|
|
|
if ( gridConnection.hasDirection() )
|
|
|
|
gridProxy.onGridNotification( GridNotification.ConnectionsChanged );
|
2014-07-13 22:45:00 +02:00
|
|
|
|
|
|
|
final IGridNode gn = this;
|
|
|
|
|
|
|
|
Collections.sort( Connections, new Comparator<IGridConnection>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compare(IGridConnection o1, IGridConnection o2)
|
|
|
|
{
|
2014-09-21 01:26:45 +02:00
|
|
|
boolean preferredA = o1.getOtherSide( gn ).hasFlag( GridFlags.PREFERRED );
|
|
|
|
boolean preferredB = o2.getOtherSide( gn ).hasFlag( GridFlags.PREFERRED );
|
2014-07-13 22:45:00 +02:00
|
|
|
|
2014-09-21 01:26:45 +02:00
|
|
|
return preferredA == preferredB ? 0 : (preferredA ? -1 : 1);
|
2014-07-13 22:45:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void removeConnection(IGridConnection gridConnection)
|
|
|
|
{
|
|
|
|
Connections.remove( gridConnection );
|
|
|
|
if ( gridConnection.hasDirection() )
|
|
|
|
gridProxy.onGridNotification( GridNotification.ConnectionsChanged );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IReadOnlyCollection<IGridConnection> getConnections()
|
|
|
|
{
|
|
|
|
return new ReadOnlyCollection<IGridConnection>( Connections );
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasConnection(IGridNode otherside)
|
|
|
|
{
|
|
|
|
for (IGridConnection gc : Connections)
|
|
|
|
{
|
|
|
|
if ( gc.a() == otherside || gc.b() == otherside )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canConnect(GridNode from, ForgeDirection dir)
|
|
|
|
{
|
2014-08-28 10:40:06 +02:00
|
|
|
if ( !isValidDirection( dir ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( !from.getColor().matches( getColor() ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGrid getGrid()
|
|
|
|
{
|
|
|
|
return myGrid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Grid getInternalGrid()
|
|
|
|
{
|
|
|
|
if ( myGrid == null )
|
|
|
|
myGrid = new Grid( this );
|
|
|
|
|
|
|
|
return myGrid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setGrid(Grid grid)
|
|
|
|
{
|
|
|
|
if ( myGrid == grid )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( myGrid != null )
|
|
|
|
{
|
|
|
|
myGrid.remove( this );
|
|
|
|
|
|
|
|
if ( myGrid.isEmpty() )
|
|
|
|
{
|
|
|
|
myGrid.saveState();
|
|
|
|
|
|
|
|
for (IGridCache c : grid.caches.values())
|
|
|
|
c.onJoin( myGrid.myStorage );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
myGrid = grid;
|
|
|
|
myGrid.add( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void validateGrid()
|
|
|
|
{
|
|
|
|
GridSplitDetector gsd = new GridSplitDetector( getInternalGrid().getPivot() );
|
2014-09-20 22:37:36 +02:00
|
|
|
beginVisit( gsd );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( !gsd.pivotFound )
|
|
|
|
{
|
|
|
|
GridPropagator gp = new GridPropagator( new Grid( this ) );
|
2014-09-20 22:37:36 +02:00
|
|
|
beginVisit( gp );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void destroy()
|
|
|
|
{
|
|
|
|
while (!Connections.isEmpty())
|
|
|
|
{
|
|
|
|
// not part of this network for real anymore.
|
|
|
|
if ( Connections.size() == 1 )
|
|
|
|
setGridStorage( null );
|
|
|
|
|
|
|
|
IGridConnection c = Connections.listIterator().next();
|
|
|
|
GridNode otherSide = (GridNode) c.getOtherSide( this );
|
|
|
|
otherSide.getInternalGrid().pivot = otherSide;
|
|
|
|
c.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( myGrid != null )
|
|
|
|
myGrid.remove( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public World getWorld()
|
|
|
|
{
|
|
|
|
return gridProxy.getLocation().getWorld();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean meetsChannelRequirements()
|
|
|
|
{
|
2014-01-31 22:12:15 +01:00
|
|
|
return (!getGridBlock().getFlags().contains( GridFlags.REQUIRE_CHANNEL ) || getUsedChannels() > 0);
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isActive()
|
|
|
|
{
|
|
|
|
IGrid g = getGrid();
|
|
|
|
if ( g != null )
|
|
|
|
{
|
|
|
|
IPathingGrid pg = g.getCache( IPathingGrid.class );
|
|
|
|
IEnergyGrid eg = g.getCache( IEnergyGrid.class );
|
|
|
|
return meetsChannelRequirements() && eg.isNetworkPowered() && !pg.isNetworkBooting();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canSupportMoreChannels()
|
|
|
|
{
|
2014-08-28 10:40:06 +02:00
|
|
|
return getUsedChannels() < getMaxChannels();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IReadOnlyCollection<IPathItem> getPossibleOptions()
|
|
|
|
{
|
|
|
|
return (ReadOnlyCollection) getConnections();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getLastUsedChannels()
|
|
|
|
{
|
|
|
|
return (channelData >> 8) & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getUsedChannels()
|
|
|
|
{
|
|
|
|
return channelData & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void incrementChannelCount(int usedChannels)
|
|
|
|
{
|
|
|
|
channelData += usedChannels;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setGridStorage(GridStorage s)
|
|
|
|
{
|
|
|
|
myStorage = s;
|
|
|
|
channelData = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GridStorage getGridStorage()
|
|
|
|
{
|
|
|
|
return myStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumSet<GridFlags> getFlags()
|
|
|
|
{
|
|
|
|
return getGridBlock().getFlags();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void finalizeChannels()
|
|
|
|
{
|
|
|
|
if ( getFlags().contains( GridFlags.CANNOT_CARRY ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( getLastUsedChannels() != getUsedChannels() )
|
|
|
|
{
|
|
|
|
channelData = (channelData & 0xff);
|
|
|
|
channelData |= channelData << 8;
|
|
|
|
|
|
|
|
if ( getInternalGrid() != null )
|
|
|
|
getInternalGrid().postEventTo( this, event );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IPathItem getControllerRoute()
|
|
|
|
{
|
|
|
|
if ( Connections.isEmpty() || getFlags().contains( GridFlags.CANNOT_CARRY ) )
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return (IPathItem) Connections.get( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setControllerRoute(IPathItem fast, boolean zeroOut)
|
|
|
|
{
|
|
|
|
if ( zeroOut )
|
|
|
|
channelData &= ~0xff;
|
|
|
|
|
|
|
|
int idx = Connections.indexOf( fast );
|
|
|
|
if ( idx > 0 )
|
|
|
|
{
|
|
|
|
Connections.remove( fast );
|
|
|
|
Connections.add( 0, (IGridConnection) fast );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasFlag(GridFlags flag)
|
|
|
|
{
|
|
|
|
return getGridBlock().getFlags().contains( flag );
|
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
@Override
|
|
|
|
public int getPlayerID()
|
|
|
|
{
|
|
|
|
return playerID;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|