Ejemplo n.º 1
0
  void doWaitOrders() {
    if (!unit.getMover().hasFoundPost) {
      post = unit.getPos();
    }
    unit.idle();
    // let allies pass
    unit.getMover().separate();

    // return to post if disturbed
    if (post != null && getPostDistance() > FREE_MOVE_RADIUS) {
      stateMachine.pushState(RETURN_POST);
      stateMachine.pushState(WAIT, DISTURB_DURATION);
    }

    // attack nearby enemies
    if (unit.arming.scanning()) {
      stateMachine.pushState(RETURN_POST);
      stateMachine.pushState(AUTO_ATTACK, new ArrayList<>());
    }

    // attack back an attacker
    // note that attackers are also registered on nearby allies for support
    if (isAttacked()) {
      stateMachine.pushState(RETURN_POST);
      stateMachine.pushState(ATTACK_BACK);
    }
  }
Ejemplo n.º 2
0
    @Override
    public FSM parseToFSM() {

      boolean first = true;
      FSM tmp = null;

      boolean isSimple = true;

      for (Expression e : this.disj) {
        if (first) {
          tmp = e.parseToFSM();
          first = false;
          if (e.getType() != RegularExpressionParser.Literal) isSimple = false;
        } else if (e.getType() == RegularExpressionParser.Literal && isSimple) {

          IntDomain dom = tmp.initState.transitions.iterator().next().domain;
          int val = Integer.parseInt(((Literal) e).lit);

          tmp.initState.transitions.iterator().next().domain = dom.union(val);

        } else {
          tmp = tmp.union(e.parseToFSM());
          isSimple = false;
        }
      }
      return tmp;
    }
Ejemplo n.º 3
0
 void doReturnPost() {
   if (getPostDistance() < POST_TOLERANCE) {
     stateMachine.popState();
   } else if (isAttacked()) {
     stateMachine.pushState(ATTACK_BACK);
   } else {
     unit.getMover().separate();
     unit.getMover().seek(post);
   }
 }
Ejemplo n.º 4
0
 void doMoveAttack() {
   post = unit.getPos();
   if (!unit.getMover().hasDestination()) {
     stateMachine.popState();
   } else {
     if (unit.arming.scanning()) {
       stateMachine.pushState(AUTO_ATTACK, new ArrayList<>());
     } else {
       unit.getMover().followPath();
     }
   }
 }
Ejemplo n.º 5
0
 void doAttackBack() {
   if (!isAttacked() || getAggressionPlaceDistance() > PURSUE_RADIUS) {
     stateMachine.popState();
   } else if (unit.arming.acquiring()) {
     unit.arming.attack();
   } else if (unit.arming.scanning()) {
     unit.getMover().seek(unit.arming.getNearestScanned().getMover());
   } else if (getValidNearest(getAttackers()) != null) {
     unit.getMover().seek(getValidNearest(getAttackers()).getMover());
   } else {
     stateMachine.popState();
   }
 }
Ejemplo n.º 6
0
 void doAutoAttack(ArrayList<Unit> enemies) {
   if (isAttacked()) {
     stateMachine.pushState(ATTACK_BACK);
   } else if (getPostDistance() > PURSUE_RADIUS) {
     stateMachine.popState();
   } else if (unit.arming.acquiring()) {
     unit.arming.attack();
   } else if (unit.arming.scanning()) {
     unit.getMover().seek(unit.arming.getNearestScanned().getMover());
   } else if (getValidNearest(enemies) != null) {
     unit.getMover().seek(getValidNearest(enemies).getMover());
   } else {
     stateMachine.popState();
   }
 }
Ejemplo n.º 7
0
 public void update() {
   // TODO moche
   filterAttackers();
   unit.getMover().tryHold = false;
   neighbors = getNeighbors();
   stateMachine.update();
 }
Ejemplo n.º 8
0
 void doMove() {
   post = unit.getPos();
   if (!unit.getMover().hasDestination()) {
     stateMachine.popState();
   } else {
     unit.getMover().followPath();
   }
 }
Ejemplo n.º 9
0
    @Override
    public FSM parseToFSM() {

      FSM c = new FSM();
      FSMState fin = new FSMState();

      c.initState = new FSMState();

      c.allStates.add(c.initState);
      c.allStates.add(fin);

      c.finalStates.add(fin);

      int val = Integer.parseInt(lit);
      IntervalDomain dom = new IntervalDomain(val, val);
      c.initState.addTransition(new FSMTransition(dom, fin));

      return c;
    }
Ejemplo n.º 10
0
 public void visit(FSM fsm) {
   Set<Edge> visited = new HashSet<Edge>();
   Node startNode = fsm.getStartNode();
   for (Edge e : startNode.getSucc()) {
     Vector<Edge> path = new Vector<Edge>();
     path.add(e);
     paths.add(path);
     visited.add(e);
   }
   visit(visited);
 }
Ejemplo n.º 11
0
  void doWait(double duration) {
    // let allies pass
    unit.getMover().separate();

    if (disturbTime == 0) {
      disturbTime = System.currentTimeMillis();
    } else if (disturbTime + duration < System.currentTimeMillis()) {
      disturbTime = 0;
      stateMachine.popState();
    }
  }
Ejemplo n.º 12
0
 void doAttack(Unit u) {
   if (u.destroyed()) {
     post = unit.getPos();
     stateMachine.popState();
   } else if (unit.arming.acquiring(u)) {
     unit.arming.attack(u);
     unit.getMover().setDestinationReached();
   } else if (!unit.getMover().hasDestination()) {
     unit.getMover().seek(u.getMover());
   } else {
     unit.getMover().followPath(u.getMover());
   }
 }
Ejemplo n.º 13
0
 public void orderHold() {
   abandonAll();
   stateMachine.pushState(HOLD);
 }
Ejemplo n.º 14
0
 public void orderAttack(Unit enemy) {
   abandonAll();
   stateMachine.pushState(WAIT_ORDERS);
   stateMachine.pushState(ATTACK, enemy);
 }
Ejemplo n.º 15
0
 public void orderMoveAttack() {
   abandonAll();
   stateMachine.pushState(WAIT_ORDERS);
   stateMachine.pushState(MOVE_ATTACK);
   stateMachine.pushState(STOP);
 }
Ejemplo n.º 16
0
 public void orderMove() {
   abandonAll();
   stateMachine.pushState(WAIT_ORDERS);
   stateMachine.pushState(MOVE);
   stateMachine.pushState(STOP);
 }
Ejemplo n.º 17
0
 public TacticalAI(Unit unit) {
   this.unit = unit;
   stateMachine = new FSM(this);
   stateMachine.pushState(WAIT_ORDERS);
 }
Ejemplo n.º 18
0
 public void abandonAll() {
   post = null;
   aggressionPlace = null;
   aggressions.clear();
   stateMachine.popAll();
 }
Ejemplo n.º 19
0
 void doStop() {
   if (unit.getMover().velocity.equals(Point3D.ORIGIN)) {
     stateMachine.popState();
   }
 }