test_class.file: omicron-core/src/test/java/com/lyndir/omicron/api/ExtractorModuleTest.java
test_class.identifier: ExtractorModuleTest
test_class.superclass: extends AbstractTest
test_case.body: @Test
      public void testOnNewTurn()
              throws Exception {
  
          // Create an extractor unit on a tile with fuel.
          ExtractorModule extractorModule = ExtractorModule.createWithStandardResourceCost().resourceType( ResourceType.FUEL ).speed( 5 );
          ContainerModule unconnectedContainerModule = ContainerModule.createWithStandardResourceCost()
                                                                      .resourceType( ResourceType.FUEL )
                                                                      .capacity( 3 );
          createUnit( testUnitType( "Extractor", extractorModule ), 0, 0 );
          createUnit( testUnitType( "Unconnected Container", unconnectedContainerModule ), 3, 0 );
          extractorModule.getGameObject().getLocation().get().setResourceQuantity( ResourceType.FUEL, 10 );
  
          // There is no connected container yet, mining should fail.
          assertEquals( (int) extractorModule.getGameObject().getLocation().get().getResourceQuantity( ResourceType.FUEL ).get(), 10 );
          extractorModule.onNewTurn();
          assertEquals( (int) extractorModule.getGameObject().getLocation().get().getResourceQuantity( ResourceType.FUEL ).get(), 10 );
  
          // Create a connected container unit.
          ContainerModule smallConnectedContainerModule = ContainerModule.createWithStandardResourceCost()
                                                                         .resourceType( ResourceType.FUEL )
                                                                         .capacity( 3 );
          createUnit( testUnitType( "Small Connected Container", smallConnectedContainerModule ), 1, 0 );
  
          // Now we should be able to mine enough to fill the container.
          assertEquals( smallConnectedContainerModule.getAvailable(), 3 );
          extractorModule.onNewTurn();
          assertEquals( (int) extractorModule.getGameObject().getLocation().get().getResourceQuantity( ResourceType.FUEL ).get(), 7 );
          assertEquals( smallConnectedContainerModule.getAvailable(), 0 );
          extractorModule.onNewTurn();
          assertEquals( (int) extractorModule.getGameObject().getLocation().get().getResourceQuantity( ResourceType.FUEL ).get(), 7 );
          assertEquals( smallConnectedContainerModule.getAvailable(), 0 );
  
          // Create a bigger connected container unit.
          ContainerModule bigConnectedContainerModule = ContainerModule.createWithStandardResourceCost()
                                                                       .resourceType( ResourceType.FUEL )
                                                                       .capacity( 15 );
          createUnit( testUnitType( "Big Connected Container", bigConnectedContainerModule ), 0, 1 );
  
          // Now we should be able to mine enough to max out the extractor's speed and then empty the tile.
          assertEquals( smallConnectedContainerModule.getAvailable(), 0 );
          assertEquals( bigConnectedContainerModule.getAvailable(), 15 );
          extractorModule.onNewTurn();
          assertEquals( (int) extractorModule.getGameObject().getLocation().get().getResourceQuantity( ResourceType.FUEL ).get(), 2 );
          assertEquals( bigConnectedContainerModule.getAvailable(), 10 );
          extractorModule.onNewTurn();
          assertFalse( extractorModule.getGameObject().getLocation().get().getResourceQuantity( ResourceType.FUEL ).isPresent() );
          assertEquals( bigConnectedContainerModule.getAvailable(), 8 );
          assertEquals( bigConnectedContainerModule.getStock(), 7 );
      }
test_case.class_method_signature: ExtractorModuleTest.testOnNewTurn()
test_case.full_signature: @Test public void testOnNewTurn()
test_case.identifier: testOnNewTurn
test_case.invocations: speed resourceType createWithStandardResourceCost capacity resourceType createWithStandardResourceCost createUnit testUnitType createUnit testUnitType setResourceQuantity get getLocation getGameObject assertEquals get getResourceQuantity get getLocation getGameObject onNewTurn assertEquals get getResourceQuantity get getLocation getGameObject capacity resourceType createWithStandardResourceCost createUnit testUnitType assertEquals getAvailable onNewTurn assertEquals get getResourceQuantity get getLocation getGameObject assertEquals getAvailable onNewTurn assertEquals get getResourceQuantity get getLocation getGameObject assertEquals getAvailable capacity resourceType createWithStandardResourceCost createUnit testUnitType assertEquals getAvailable assertEquals getAvailable onNewTurn assertEquals get getResourceQuantity get getLocation getGameObject assertEquals getAvailable onNewTurn assertFalse isPresent getResourceQuantity get getLocation getGameObject assertEquals getAvailable assertEquals getStock
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testOnNewTurn()
focal_class.declarator: logger = Logger.get( ExtractorModule.class )
focal_class.modifier: @SuppressWarnings("UnusedDeclaration")
      private static final
focal_class.original_string: @SuppressWarnings("UnusedDeclaration")
      private static final Logger logger = Logger.get( ExtractorModule.class );
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: resourceType
focal_class.modifier: private final
focal_class.original_string: private final ResourceType resourceType;
focal_class.type: ResourceType
focal_class.var_name: resourceType
focal_class.declarator: speed
focal_class.modifier: private final
focal_class.original_string: private final int          speed;
focal_class.type: int
focal_class.var_name: speed
focal_class.file: omicron-core/src/main/java/com/lyndir/omicron/api/ExtractorModule.java
focal_class.identifier: ExtractorModule
focal_class.interfaces: implements IExtractorModule, IExtractorModuleController
focal_class.class_method_signature: ExtractorModule.ExtractorModule(final ImmutableResourceCost resourceCost, final ResourceType resourceType, final int speed)
focal_class.full_signature: protected  ExtractorModule(final ImmutableResourceCost resourceCost, final ResourceType resourceType, final int speed)
focal_class.identifier: ExtractorModule
focal_class.modifiers: protected
focal_class.parameters: (final ImmutableResourceCost resourceCost, final ResourceType resourceType, final int speed)
focal_class.signature:  ExtractorModule(final ImmutableResourceCost resourceCost, final ResourceType resourceType, final int speed)
focal_class.class_method_signature: ExtractorModule.createWithStandardResourceCost()
focal_class.full_signature: static Builder0 createWithStandardResourceCost()
focal_class.identifier: createWithStandardResourceCost
focal_class.modifiers: static
focal_class.parameters: ()
focal_class.return: Builder0
focal_class.signature: Builder0 createWithStandardResourceCost()
focal_class.class_method_signature: ExtractorModule.createWithExtraResourceCost(final ImmutableResourceCost resourceCost)
focal_class.full_signature: static Builder0 createWithExtraResourceCost(final ImmutableResourceCost resourceCost)
focal_class.identifier: createWithExtraResourceCost
focal_class.modifiers: static
focal_class.parameters: (final ImmutableResourceCost resourceCost)
focal_class.return: Builder0
focal_class.signature: Builder0 createWithExtraResourceCost(final ImmutableResourceCost resourceCost)
focal_class.class_method_signature: ExtractorModule.getResourceType()
focal_class.full_signature: @Override public ResourceType getResourceType()
focal_class.identifier: getResourceType
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: ResourceType
focal_class.signature: ResourceType getResourceType()
focal_class.class_method_signature: ExtractorModule.getSpeed()
focal_class.full_signature: @Override public int getSpeed()
focal_class.identifier: getSpeed
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getSpeed()
focal_class.class_method_signature: ExtractorModule.onReset()
focal_class.full_signature: @Override protected void onReset()
focal_class.identifier: onReset
focal_class.modifiers: @Override protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void onReset()
focal_class.class_method_signature: ExtractorModule.onNewTurn()
focal_class.full_signature: @Override protected void onNewTurn()
focal_class.identifier: onNewTurn
focal_class.modifiers: @Override protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void onNewTurn()
focal_class.class_method_signature: ExtractorModule.getController()
focal_class.full_signature: @Override public IExtractorModuleController getController()
focal_class.identifier: getController
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: IExtractorModuleController
focal_class.signature: IExtractorModuleController getController()
focal_class.class_method_signature: ExtractorModule.getModule()
focal_class.full_signature: @Override public IExtractorModule getModule()
focal_class.identifier: getModule
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: IExtractorModule
focal_class.signature: IExtractorModule getModule()
focal_class.superclass: extends Module
focal_method.body: @Override
      protected void onNewTurn() {
          // Mine some resources.
          Tile location = getGameObject().getLocation().get();
          Maybe<Integer> availableResources = location.getResourceQuantity( resourceType );
          if (!availableResources.isPresent())
              // No resources left to mine.
              return;
  
          int newAvailableResources = Math.max( 0, availableResources.get() - speed );
          int minedResources = availableResources.get() - newAvailableResources;
          if (!availableResources.isPresent())
              // No speed left for mining.
              return;
  
          // Initialize path finding functions.
          PredicateNN<IGameObject> foundFunction = gameObject -> {
              for (final ContainerModule containerModule : gameObject.getModules( ModuleType.CONTAINER ))
                  if (containerModule.getAvailable() > 0)
                      return true;
  
              return false;
          };
          NNFunctionNN<PathUtils.Step<IGameObject>, Double> costFunction = gameObjectStep -> 1d;
          NNFunctionNN<IGameObject, Stream<? extends IGameObject>> neighboursFunction = neighbour -> //
                  neighbour.getLocation().get().neighbours().stream() //
                          .map( new Function<ITile, IGameObject>() {
                              @Override
                              public IGameObject apply(final ITile tile) {
                                  return tile.getContents().orNull();
                              }
                          } ).filter( gameObject -> gameObject != null );
  
          // Find paths to containers and deposit mined resources.
          while (minedResources > 0) {
              Optional<PathUtils.Path<IGameObject>> path = PathUtils.find( getGameObject(), foundFunction, costFunction,
                                                                           Constants.MAX_DISTANCE_TO_CONTAINER, neighboursFunction );
              if (!path.isPresent())
                  // No more containers with available capacity.
                  break;
  
              for (final ContainerModule containerModule : path.get().getTarget().getModules( ModuleType.CONTAINER ))
                  minedResources -= containerModule.addStock( minedResources );
          }
  
          // If we have minedResources left that we weren't able to stock, put them back in the tile (ie. don't extract them).
          newAvailableResources += minedResources;
  
          // Update the amount of resources left in the tile after this turn's extraction.
          location.setResourceQuantity( resourceType, newAvailableResources );
          logger.trc( "unstocked resources: %d %s, left in tile: %d", minedResources, resourceType, newAvailableResources );
      }
focal_method.class_method_signature: ExtractorModule.onNewTurn()
focal_method.full_signature: @Override protected void onNewTurn()
focal_method.identifier: onNewTurn
focal_method.invocations: get getLocation getGameObject getResourceQuantity isPresent max get get isPresent getModules getAvailable filter map stream neighbours get getLocation orNull getContents find getGameObject isPresent getModules getTarget get addStock setResourceQuantity trc
focal_method.modifiers: @Override protected
focal_method.parameters: ()
focal_method.return: void
focal_method.signature: void onNewTurn()