Example #1
0
  public List<MapObserver> getNeighborsCloseTo(MapObserver observer, float max) {
    List<MapObserver> ret = new ArrayList<MapObserver>();

    Location aLoc = observer.getLocation();
    float ax = aLoc.x;
    float ay = aLoc.y;

    Location bLoc;
    float deltaX, deltaY;
    double dist;

    for (Block b : notificationArea) {
      synchronized (b.observers) {
        for (MapObserver o : b.observers) {
          if (observer == o) {
            continue; // Skip himself.
          }

          bLoc = o.getLocation();
          deltaX = bLoc.x - ax;
          deltaY = bLoc.y - ay;
          dist = Math.sqrt(deltaX * deltaX + deltaY * deltaY);

          if (dist < max) {
            ret.add(o);
          }
        }
      }
    }

    return ret;
  }
Example #2
0
 public void notifyAppearanceChangeSelfAndNeigh(MapObserver observer) {
   for (Block b : notificationArea) {
     synchronized (b.observers) {
       for (MapObserver o : b.observers) {
         o.notifyAppearanceChange(observer);
       }
     }
   }
 }
Example #3
0
 public void notifyNearChatSelfAndNeigh(MapObserver observer, String text) {
   for (Block b : notificationArea) {
     synchronized (b.observers) {
       for (MapObserver o : b.observers) {
         o.notifyNearChat(observer, text);
       }
     }
   }
 }
Example #4
0
 public void notifyMoveSelfAndNeigh(MapObserver observer) {
   for (Block b : notificationArea) {
     synchronized (b.observers) {
       for (MapObserver o : b.observers) {
         if (observer != o) {
           o.notifyMove(observer);
         }
       }
     }
   }
 }
Example #5
0
 public void makeAwareOfOthers(MapObserver observer) {
   for (Block b : notificationArea) {
     synchronized (b.observers) {
       for (MapObserver o : b.observers) {
         if (observer != o) {
           observer.notifyMove(o); // Brackets all the way down. :)
         }
       }
     }
   }
 }
Example #6
0
 public void notifySelfAboutOthers(MapObserver observer) {
   // TODO: optimize this: send notif only about the cells not in range previously.
   for (Block b : notificationArea) {
     synchronized (b.observers) {
       for (MapObserver o : b.observers) {
         if (observer != o) {
           observer.notifyMove(o);
         }
       }
     }
   }
 }