}
if ( updateNetwork )
{
if ( !booting )
myGrid.postEvent( new MENetworkBootingStatusChange() );
booting = true;
updateNetwork = false;
instance++;
channelsInUse = 0;
if ( !AEConfig.instance.isFeatureEnabled( AEFeature.Channels ) )
{
int used = calculateRequiredChannels();
int nodes = myGrid.getNodes().size();
ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 );
channelsByBlocks = nodes * used;
channelPowerUsage = channelsByBlocks / 128.0;
myGrid.getPivot().beginVisit( new AdHocChannelUpdater( used ) );
}
else if ( controllerState == ControllerState.NO_CONTROLLER )
{
int requiredChannels = calculateRequiredChannels();
int used = requiredChannels;
if ( requiredChannels > 8 )
used = 0;
int nodes = myGrid.getNodes().size();
channelsInUse = used;
ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 );
channelsByBlocks = nodes * used;
channelPowerUsage = channelsByBlocks / 128.0;
myGrid.getPivot().beginVisit( new AdHocChannelUpdater( used ) );
}
else if ( controllerState == ControllerState.CONTROLLER_CONFLICT )
{
ticksUntilReady = 20;
myGrid.getPivot().beginVisit( new AdHocChannelUpdater( 0 ) );
}
else
{
int nodes = myGrid.getNodes().size();
ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 );
HashSet<IPathItem> closedList = new HashSet<IPathItem>();
semiOpen = new HashSet<IPathItem>();
// myGrid.getPivot().beginVisit( new AdHocChannelUpdater( 0 )
// );
for (IGridNode node : myGrid.getMachines( TileController.class ))
{
closedList.add( (IPathItem) node );
for (IGridConnection gcc : node.getConnections())
{
GridConnection gc = (GridConnection) gcc;
if ( !(gc.getOtherSide( node ).getMachine() instanceof TileController) )
{
List<IPathItem> open = new LinkedList<IPathItem>();
closedList.add( gc );
open.add( gc );
gc.setControllerRoute( (GridNode) node, true );
active.add( new PathSegment( this, open, semiOpen, closedList ) );
}
}
}
}
}
if ( !active.isEmpty() || ticksUntilReady > 0 )
{
Iterator<PathSegment> i = active.iterator();
while (i.hasNext())
{
PathSegment pat = i.next();
if ( pat.step() )
{
pat.isDead = true;
i.remove();
}
}
ticksUntilReady--;
if ( active.isEmpty() && ticksUntilReady <= 0 )
{
if ( controllerState == ControllerState.CONTROLLER_ONLINE )
{
final Iterator<TileController> controllerIterator = this.controllers.iterator();
if (controllerIterator.hasNext())
{
final TileController controller = controllerIterator.next();
controller.getGridNode( ForgeDirection.UNKNOWN ).beginVisit( new ControllerChannelUpdater() );
}
}
// check for achievements
achievementPost();
booting = false;
channelPowerUsage = channelsByBlocks / 128.0;
myGrid.postEvent( new MENetworkBootingStatusChange() );
}
}
}