private IFuture<Void> claimSector(final Task currentImpTask) { final Future<Void> ret = new Future<Void>(); Map<String, Object> props = new HashMap<String, Object>(); props.put(ClaimSectorTask.PROPERTY_DESTINATION, currentImpTask.getTargetPosition()); props.put(ClaimSectorTask.PROPERTY_DIG_SPEED, impBdi.getMyWorkingSpeed()); digtaskid = capa.getEnvironment() .createObjectTask( ClaimSectorTask.PROPERTY_TYPENAME, props, capa.getMySpaceObject().getId()); iplan .invokeInterruptable( new IResultCommand<IFuture<Void>, Void>() { public IFuture<Void> execute(Void args) { return capa.getEnvironment() .waitForTask(digtaskid, capa.getMySpaceObject().getId()); } }) .addResultListener(new DelegationResultListener<Void>(ret)); return ret; }
private IFuture<Void> reachTargetDestination(final Task currentImpTask) { final Future<Void> ret = new Future<Void>(); final Vector2Int currentImpTaskPosition = currentImpTask.getTargetPosition(); Collection<ISpaceObject> spaceObjectsByGridPosition = environment.getSpaceObjectsByGridPosition(currentImpTask.getTargetPosition(), null); for (ISpaceObject spaceObject : spaceObjectsByGridPosition) { if (MapType.DIRT_PATH.toString().equals(spaceObject.getType())) { currentTaskSpaceObject = (SpaceObject) spaceObject; } } if (currentImpTaskPosition != null && currentTaskSpaceObject != null) { // went to the position where the imp can dig from if (currentImpTask.getTargetPosition() != null) { IFuture<AchieveMoveToSector> reachSectorToDigFrom = rplan.dispatchSubgoal(capa.new AchieveMoveToSector(currentImpTask.getTargetPosition())); reachSectorToDigFrom.addResultListener( new ExceptionDelegationResultListener<AbstractCreatureBDI.AchieveMoveToSector, Void>( ret) { public void customResultAvailable(AbstractCreatureBDI.AchieveMoveToSector amt) { claimSector(currentImpTask) .addResultListener( new DelegationResultListener<Void>(ret) { public void customResultAvailable(Void result) { // add new Tile and remove the old, claim the sector ground Map<String, Object> props = new HashMap<String, Object>(); props.put("Task", currentImpTask); props.put( ClaimSectorChangeTileTask.PROPERTY_DESTINATION, currentImpTask.getTargetPosition()); claimtaskid = capa.getEnvironment() .createObjectTask( ClaimSectorChangeTileTask.PROPERTY_TYPENAME, props, capa.getMySpaceObject().getId()); cplan .invokeInterruptable( new IResultCommand<IFuture<Void>, Void>() { public IFuture<Void> execute(Void args) { return capa.getEnvironment() .waitForTask( claimtaskid, capa.getMySpaceObject().getId()); } }) .addResultListener(new DelegationResultListener<Void>(ret)); ret.setResult(null); } }); } }); } else { // TODO: fail!! sector from task should be reachable for destroy // => catch System.out.println("fail!! sector from task should be reachable for destroy "); capa.getMySpaceObject().setProperty(ISObjStrings.PROPERTY_STATUS, "Idle"); rplan.abort(); } } else { System.out.println("ClaimSectorPlan: Task has no Int Position"); rplan.abort(); } return ret; }