/** * Runs if we need to wait for a game tick. * * @param helper * @return */ public TickResult runForTick(AIHelper helper) { synchronized (tickHelperMutex) { printError(); synchronized (activeStrategyMutex) { if (activeStrategy != null) { TickResult tickResult = activeStrategy.gameTick(helper); if (tickResult == TickResult.NO_MORE_WORK || tickResult == TickResult.ABORT) { activeStrategy.setActive(false, helper); activeStrategy = null; activeStrategyMutex.notifyAll(); } else { return tickResult; } } } if (scriptWaitingForTick) { tickHelper = helper; scriptInsideTick = true; scriptWaitingForTick = false; tickHelperMutex.notifyAll(); while (scriptInsideTick) { try { tickHelperMutex.wait(); } catch (InterruptedException e) { } } tickHelper = null; } return finished ? TickResult.NO_MORE_WORK : TickResult.TICK_HANDLED; } }
@Override public void setActiveStrategy(ScriptStrategy strategy, AIHelper helper) { synchronized (activeStrategyMutex) { if (activeStrategy != null) { activeStrategy.setActive(false, helper); } activeStrategy = strategy == null ? null : strategy.getStrategy(); if (activeStrategy != null) { activeStrategy.setActive(true, helper); } activeStrategyMutex.notifyAll(); } }
public boolean hasFailed() { return strategy.hasFailed(); }
@Override protected void onDeactivate(AIHelper helper) { scriptRunner.stop(); super.onDeactivate(helper); }
@Override protected void onActivate(AIHelper helper) { Thread scriptThread = new Thread(scriptRunner); scriptThread.start(); super.onActivate(helper); }