Пример #1
0
 /*     */ public NavPath findPath(float sx, float sy, float tx, float ty, boolean optimize)
       /*     */ {
   /*  91 */ Space source = findSpace(sx, sy);
   /*  92 */ Space target = findSpace(tx, ty);
   /*     */
   /*  94 */ if ((source == null) || (target == null)) {
     /*  95 */ return null;
     /*     */ }
   /*     */
   /*  98 */ for (int i = 0; i < this.spaces.size(); i++) {
     /*  99 */ ((Space) this.spaces.get(i)).clearCost();
     /*     */ }
   /* 101 */ target.fill(source, tx, ty, 0.0F);
   /* 102 */ if (target.getCost() == 3.4028235E+38F) {
     /* 103 */ return null;
     /*     */ }
   /* 105 */ if (source.getCost() == 3.4028235E+38F) {
     /* 106 */ return null;
     /*     */ }
   /*     */
   /* 109 */ NavPath path = new NavPath();
   /* 110 */ path.push(new Link(sx, sy, null));
   /* 111 */ if (source.pickLowestCost(target, path)) {
     /* 112 */ path.push(new Link(tx, ty, null));
     /* 113 */ if (optimize) {
       /* 114 */ optimize(path);
       /*     */ }
     /* 116 */ return path;
     /*     */ }
   /*     */
   /* 119 */ return null;
   /*     */ }
Пример #2
0
 /*     */ private void optimize(NavPath path) /*     */ {
   /* 161 */ int pt = 0;
   /*     */
   /* 163 */ while (pt < path.length() - 2) {
     /* 164 */ float sx = path.getX(pt);
     /* 165 */ float sy = path.getY(pt);
     /* 166 */ float nx = path.getX(pt + 2);
     /* 167 */ float ny = path.getY(pt + 2);
     /*     */
     /* 169 */ if (isClear(sx, sy, nx, ny, 0.1F)) /* 170 */ path.remove(pt + 1);
     /*     */ else /* 172 */ pt++;
     /*     */ }
   /*     */ }