Exemple #1
0
    /**
     * 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;
      }
    }
Exemple #2
0
 @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();
   }
 }
Exemple #3
0
 public boolean hasFailed() {
   return strategy.hasFailed();
 }
Exemple #4
0
 @Override
 protected void onDeactivate(AIHelper helper) {
   scriptRunner.stop();
   super.onDeactivate(helper);
 }
Exemple #5
0
 @Override
 protected void onActivate(AIHelper helper) {
   Thread scriptThread = new Thread(scriptRunner);
   scriptThread.start();
   super.onActivate(helper);
 }