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; }
public void notifyAppearanceChangeSelfAndNeigh(MapObserver observer) { for (Block b : notificationArea) { synchronized (b.observers) { for (MapObserver o : b.observers) { o.notifyAppearanceChange(observer); } } } }
public void notifyNearChatSelfAndNeigh(MapObserver observer, String text) { for (Block b : notificationArea) { synchronized (b.observers) { for (MapObserver o : b.observers) { o.notifyNearChat(observer, text); } } } }
public void notifyMoveSelfAndNeigh(MapObserver observer) { for (Block b : notificationArea) { synchronized (b.observers) { for (MapObserver o : b.observers) { if (observer != o) { o.notifyMove(observer); } } } } }
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. :) } } } } }
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); } } } } }