protected void createLevelPortalAt(final int type, final int x, final int y) {
if (logger.isDebugEnabled()) {
logger.debug("Portal stairs at " + this + ": " + x + "," + y);
}
Portal portal;
if (type != 5) {
portal = new Portal();
} else {
portal = new OneWayPortalDestination();
}
portal.setPosition(x, y);
assignPortalID(portal);
add(portal);
boolean assigned = false;
if (isInterior()) {
// The algo doesn't work on interiors
return;
}
for (final IRPZone i : SingletonRepository.getRPWorld()) {
final StendhalRPZone zone = (StendhalRPZone) i;
if (zone.isInterior()) {
continue;
}
/*
* Portals in the correct direction?
*/
if (type == 2) {
/* portal stairs up */
if ((zone.getLevel() - getLevel()) != 1) {
continue;
}
} else if (type == 3) {
/* portal stairs down */
if ((zone.getLevel() - getLevel()) != -1) {
continue;
}
} else {
/* one way portal - POTENTIALLY WRONG LEVEL */
/* Should they always go down (drop only)? */
if (Math.abs(zone.getLevel() - getLevel()) != 1) {
continue;
}
}
final Portal target = zone.getPortal(
portal.getX() + getX() - zone.getX(), portal.getY()
+ getY() - zone.getY());
if (target == null) {
continue;
}
logger.debug(zone + " contains " + target);
if (target.loaded()) {
logger.debug(target + " already loaded");
continue;
}
if (type != 5) {
portal.setDestination(zone.getName(),
zone.assignPortalID(target));
}
target.setDestination(getName(), portal.getIdentifier());
logger.debug("Portals LINKED");
logger.debug(portal);
logger.debug(target);
assigned = true;