2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
package appeng.me.cache;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.networking.GridFlags;
|
|
|
|
import appeng.api.networking.IGrid;
|
|
|
|
import appeng.api.networking.IGridBlock;
|
|
|
|
import appeng.api.networking.IGridConnection;
|
|
|
|
import appeng.api.networking.IGridHost;
|
|
|
|
import appeng.api.networking.IGridMultiblock;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.IGridStorage;
|
|
|
|
import appeng.api.networking.events.MENetworkBootingStatusChange;
|
|
|
|
import appeng.api.networking.events.MENetworkChannelChanged;
|
|
|
|
import appeng.api.networking.events.MENetworkControllerChange;
|
|
|
|
import appeng.api.networking.events.MENetworkEventSubscribe;
|
|
|
|
import appeng.api.networking.pathing.ControllerState;
|
|
|
|
import appeng.api.networking.pathing.IPathingGrid;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
|
|
|
import appeng.core.AEConfig;
|
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.core.stats.Achievements;
|
|
|
|
import appeng.me.GridConnection;
|
|
|
|
import appeng.me.GridNode;
|
|
|
|
import appeng.me.pathfinding.AdHocChannelUpdater;
|
|
|
|
import appeng.me.pathfinding.ControllerChannelUpdater;
|
|
|
|
import appeng.me.pathfinding.ControllerValidator;
|
|
|
|
import appeng.me.pathfinding.IPathItem;
|
|
|
|
import appeng.me.pathfinding.PathSegment;
|
|
|
|
import appeng.tile.networking.TileController;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
public class PathGridCache implements IPathingGrid
|
|
|
|
{
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private final LinkedList<PathSegment> active = new LinkedList<PathSegment>();
|
|
|
|
private final Set<TileController> controllers = new HashSet<TileController>();
|
|
|
|
private final Set<IGridNode> requireChannels = new HashSet<IGridNode>();
|
|
|
|
private final Set<IGridNode> blockDense = new HashSet<IGridNode>();
|
|
|
|
private final IGrid myGrid;
|
|
|
|
private int channelsInUse = 0;
|
|
|
|
private int channelsByBlocks = 0;
|
|
|
|
private double channelPowerUsage = 0.0;
|
|
|
|
private boolean recalculateControllerNextTick = true;
|
|
|
|
private boolean updateNetwork = true;
|
|
|
|
private boolean booting = false;
|
|
|
|
private ControllerState controllerState = ControllerState.NO_CONTROLLER;
|
|
|
|
private int ticksUntilReady = 20;
|
|
|
|
private int lastChannels = 0;
|
2014-09-28 22:20:14 +02:00
|
|
|
private HashSet<IPathItem> semiOpen = new HashSet<IPathItem>();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public PathGridCache( final IGrid g )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myGrid = g;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdateTick()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.recalculateControllerNextTick )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.recalcController();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.updateNetwork )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.booting )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myGrid.postEvent( new MENetworkBootingStatusChange() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.booting = true;
|
|
|
|
this.updateNetwork = false;
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setChannelsInUse( 0 );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !AEConfig.instance.isFeatureEnabled( AEFeature.Channels ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final int used = this.calculateRequiredChannels();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final int nodes = this.myGrid.getNodes().size();
|
2014-12-29 15:13:47 +01:00
|
|
|
this.ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 );
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setChannelsByBlocks( nodes * used );
|
|
|
|
this.setChannelPowerUsage( this.getChannelsByBlocks() / 128.0 );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myGrid.getPivot().beginVisit( new AdHocChannelUpdater( used ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( this.controllerState == ControllerState.NO_CONTROLLER )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final int requiredChannels = this.calculateRequiredChannels();
|
2014-09-24 02:26:27 +02:00
|
|
|
int used = requiredChannels;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( requiredChannels > 8 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
used = 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final int nodes = this.myGrid.getNodes().size();
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setChannelsInUse( used );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 );
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setChannelsByBlocks( nodes * used );
|
|
|
|
this.setChannelPowerUsage( this.getChannelsByBlocks() / 128.0 );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myGrid.getPivot().beginVisit( new AdHocChannelUpdater( used ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( this.controllerState == ControllerState.CONTROLLER_CONFLICT )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.ticksUntilReady = 20;
|
|
|
|
this.myGrid.getPivot().beginVisit( new AdHocChannelUpdater( 0 ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final int nodes = this.myGrid.getNodes().size();
|
2014-12-29 15:13:47 +01:00
|
|
|
this.ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 );
|
2015-09-25 23:10:56 +02:00
|
|
|
final HashSet<IPathItem> closedList = new HashSet<IPathItem>();
|
2014-12-29 15:13:47 +01:00
|
|
|
this.semiOpen = new HashSet<IPathItem>();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
// myGrid.getPivot().beginVisit( new AdHocChannelUpdater( 0 )
|
|
|
|
// );
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final IGridNode node : this.myGrid.getMachines( TileController.class ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
closedList.add( (IPathItem) node );
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final IGridConnection gcc : node.getConnections() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final GridConnection gc = (GridConnection) gcc;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !( gc.getOtherSide( node ).getMachine() instanceof TileController ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final List<IPathItem> open = new LinkedList<IPathItem>();
|
2014-09-24 02:26:27 +02:00
|
|
|
closedList.add( gc );
|
|
|
|
open.add( gc );
|
|
|
|
gc.setControllerRoute( (GridNode) node, true );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.active.add( new PathSegment( this, open, this.semiOpen, closedList ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.active.isEmpty() || this.ticksUntilReady > 0 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final Iterator<PathSegment> i = this.active.iterator();
|
2015-04-03 08:54:31 +02:00
|
|
|
while( i.hasNext() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final PathSegment pat = i.next();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pat.step() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
pat.setDead( true );
|
2014-09-24 02:26:27 +02:00
|
|
|
i.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.ticksUntilReady--;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.active.isEmpty() && this.ticksUntilReady <= 0 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.controllerState == ControllerState.CONTROLLER_ONLINE )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-10-04 19:00:41 +02:00
|
|
|
final Iterator<TileController> controllerIterator = this.controllers.iterator();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( controllerIterator.hasNext() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-10-04 19:00:41 +02:00
|
|
|
final TileController controller = controllerIterator.next();
|
|
|
|
controller.getGridNode( ForgeDirection.UNKNOWN ).beginVisit( new ControllerChannelUpdater() );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for achievements
|
2014-12-29 15:13:47 +01:00
|
|
|
this.achievementPost();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.booting = false;
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setChannelPowerUsage( this.getChannelsByBlocks() / 128.0 );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myGrid.postEvent( new MENetworkBootingStatusChange() );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void removeNode( final IGridNode gridNode, final IGridHost machine )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( machine instanceof TileController )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.controllers.remove( machine );
|
|
|
|
this.recalculateControllerNextTick = true;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final EnumSet<GridFlags> flags = gridNode.getGridBlock().getFlags();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( flags.contains( GridFlags.REQUIRE_CHANNEL ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.requireChannels.remove( gridNode );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( flags.contains( GridFlags.CANNOT_CARRY_COMPRESSED ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.blockDense.remove( gridNode );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.repath();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void addNode( final IGridNode gridNode, final IGridHost machine )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( machine instanceof TileController )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.controllers.add( (TileController) machine );
|
|
|
|
this.recalculateControllerNextTick = true;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final EnumSet<GridFlags> flags = gridNode.getGridBlock().getFlags();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( flags.contains( GridFlags.REQUIRE_CHANNEL ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.requireChannels.add( gridNode );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( flags.contains( GridFlags.CANNOT_CARRY_COMPRESSED ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.blockDense.add( gridNode );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.repath();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void onSplit( final IGridStorage storageB )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void onJoin( final IGridStorage storageB )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void populateGridStorage( final IGridStorage storage )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void recalcController()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.recalculateControllerNextTick = false;
|
2015-09-25 23:10:56 +02:00
|
|
|
final ControllerState old = this.controllerState;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.controllers.isEmpty() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.controllerState = ControllerState.NO_CONTROLLER;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IGridNode startingNode = this.controllers.iterator().next().getGridNode( ForgeDirection.UNKNOWN );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( startingNode == null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.controllerState = ControllerState.CONTROLLER_CONFLICT;
|
2014-09-24 02:26:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final DimensionalCoord dc = startingNode.getGridBlock().getLocation();
|
|
|
|
final ControllerValidator cv = new ControllerValidator( dc.x, dc.y, dc.z );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
startingNode.beginVisit( cv );
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
if( cv.isValid() && cv.getFound() == this.controllers.size() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.controllerState = ControllerState.CONTROLLER_ONLINE;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.controllerState = ControllerState.CONTROLLER_CONFLICT;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( old != this.controllerState )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myGrid.postEvent( new MENetworkControllerChange() );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private int calculateRequiredChannels()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.semiOpen.clear();
|
|
|
|
|
2015-09-25 22:52:41 +02:00
|
|
|
int depth = 0;
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final IGridNode nodes : this.requireChannels )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
if( !this.semiOpen.contains( nodes ) )
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IGridBlock gb = nodes.getGridBlock();
|
|
|
|
final EnumSet<GridFlags> flags = gb.getFlags();
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
if( flags.contains( GridFlags.COMPRESSED_CHANNEL ) && !this.blockDense.isEmpty() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return 9;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
depth++;
|
|
|
|
|
|
|
|
if( flags.contains( GridFlags.MULTIBLOCK ) )
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IGridMultiblock gmb = (IGridMultiblock) gb;
|
|
|
|
final Iterator<IGridNode> i = gmb.getMultiblockNodes();
|
2015-04-03 08:54:31 +02:00
|
|
|
while( i.hasNext() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.semiOpen.add( (IPathItem) i.next() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return depth;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private void achievementPost()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.lastChannels != this.getChannelsInUse() && AEConfig.instance.isFeatureEnabled( AEFeature.Channels ) )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
final Achievements currentBracket = this.getAchievementBracket( this.getChannelsInUse() );
|
2015-09-25 23:10:56 +02:00
|
|
|
final Achievements lastBracket = this.getAchievementBracket( this.lastChannels );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( currentBracket != lastBracket && currentBracket != null )
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final Set<Integer> players = new HashSet<Integer>();
|
|
|
|
for( final IGridNode n : this.requireChannels )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
players.add( n.getPlayerID() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final int id : players )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
Platform.addStat( id, currentBracket.getAchievement() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-08 15:42:42 +02:00
|
|
|
this.lastChannels = this.getChannelsInUse();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
private Achievements getAchievementBracket( final int ch )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ch < 8 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
if( ch < 128 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return Achievements.Networking1;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ch < 2048 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return Achievements.Networking2;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
return Achievements.Networking3;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@MENetworkEventSubscribe
|
2015-09-25 23:10:56 +02:00
|
|
|
void updateNodReq( final MENetworkChannelChanged ev )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IGridNode gridNode = ev.node;
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
if( gridNode.getGridBlock().getFlags().contains( GridFlags.REQUIRE_CHANNEL ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.requireChannels.add( gridNode );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.requireChannels.remove( gridNode );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
this.repath();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean isNetworkBooting()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return !this.active.isEmpty() && !this.booting;
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public ControllerState getControllerState()
|
|
|
|
{
|
|
|
|
return this.controllerState;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public void repath()
|
|
|
|
{
|
|
|
|
// clean up...
|
|
|
|
this.active.clear();
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setChannelsByBlocks( 0 );
|
2015-04-03 08:54:31 +02:00
|
|
|
this.updateNetwork = true;
|
|
|
|
}
|
2015-10-08 15:42:42 +02:00
|
|
|
|
|
|
|
double getChannelPowerUsage()
|
|
|
|
{
|
|
|
|
return this.channelPowerUsage;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setChannelPowerUsage( final double channelPowerUsage )
|
|
|
|
{
|
|
|
|
this.channelPowerUsage = channelPowerUsage;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getChannelsByBlocks()
|
|
|
|
{
|
|
|
|
return this.channelsByBlocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setChannelsByBlocks( final int channelsByBlocks )
|
|
|
|
{
|
|
|
|
this.channelsByBlocks = channelsByBlocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getChannelsInUse()
|
|
|
|
{
|
|
|
|
return this.channelsInUse;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setChannelsInUse( final int channelsInUse )
|
|
|
|
{
|
|
|
|
this.channelsInUse = channelsInUse;
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|