Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.95 KB | None | 0 0
  1. // AI  
  2.  
  3.         public void setTree(Tree tree) {
  4.         this.tree = tree;
  5.     }
  6.    
  7.     private void chopTrees() throws SuspendExecution {
  8.         while (started) {
  9.             Tree tree = (this.tree != null ? this.tree : unit.getWorld().getNearestTree(new Point(unit.getX(),unit.getY())));
  10.             if (tree == null) {
  11.                 unit.stopChopping();
  12.                 return;
  13.             }
  14.            
  15.             moveTo(tree.getPosition());
  16.            
  17.             if (!chop(tree))
  18.                 continue;
  19.            
  20.             WoodStorage storage = unit.getWorld().getNearestWoodStorage(unit.getPosition());
  21.             Point p1 = storage.getDeliveryPoint();
  22.             Point p2 = storage.getPosition();
  23.             p2.translate(p1.x,p1.y);
  24.             moveTo(p2);
  25.            
  26.             storeInto(storage);
  27.            
  28.             if (this.tree != null) {
  29.                 this.tree = null;
  30.                 unit.stopChopping();
  31.             }
  32.         }
  33.     }
  34.  
  35.  
  36. // Unit
  37.  
  38. public void startChopping() {
  39.         unitAI.startAI();
  40.     }
  41.    
  42.     public void stopChopping() {
  43.         unitAI.stopAI();
  44.     }
  45.    
  46.     public void chop(Tree tree) {
  47.         unitAI.setTree(tree);
  48.         startChopping();
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement