public void performCustomStep(int iStep, Object o) { if (iStep == AI_OP_FIND_WAY) { MapPosition mp = (MapPosition) o; rcMy.calculateRoute( getParentObject().getPositionX(), getParentObject().getPositionY(), mp.getPositionX(), mp.getPositionY(), true); } if (iStep == AI_OP_CHECK_POS) { MapSquare mp = (MapSquare) o; if ((mp.getFirstPosition().getPositionX() != getParentObject().getPositionX()) || (mp.getFirstPosition().getPositionY() != getParentObject().getPositionY())) { /* We are not on the position we should have been! Recalculate the route! */ clearStepCache(); rcMy.calculateRoute( getParentObject().getPositionX(), getParentObject().getPositionY(), mp.getSecondPosition().getPositionX(), mp.getSecondPosition().getPositionY(), true); } } }
/** * Creates an image for the requested map square * * @param mapSquare The square an image is requested for. * @return BufferedImage The image requested. */ private BufferedImage createSquare(MapSquare mapSquare) { BufferedImage newImage = new BufferedImage( ImageBank.FEATUREWIDTH, ImageBank.FEATUREHEIGHT, BufferedImage.TYPE_INT_ARGB); Graphics2D bSurface = newImage.createGraphics(); int left = 0; int right = ImageBank.FEATUREWIDTH - 1; int top = 0; int bottom = ImageBank.FEATUREHEIGHT - 1; if (mapSquare.isSolidRock()) { bSurface.setColor(Color.WHITE); bSurface.fillRect(left, top, ImageBank.FEATUREWIDTH, ImageBank.FEATUREHEIGHT); return newImage; } bSurface.setColor(Color.BLACK); bSurface.fillRect(left, top, ImageBank.FEATUREWIDTH, ImageBank.FEATUREHEIGHT); // draw the features. do so regardless of existence SquareFeature[] features = mapSquare.getSquareFeatures(); if (features[0].featureDetected()) bSurface.drawImage(features[0].getSquareImage(), null, 0, 0); if (features[1].featureDetected()) bSurface.drawImage(features[1].getSquareImage(), null, 0, 0); // draw walls bSurface.setColor(Color.WHITE); switch (mapSquare.getWallType(Direction.North)) { case MapSquare.BYTE_WALLDOOR: bSurface.drawLine(left + 4, top, left + 4, top + 1); bSurface.drawLine(right - 4, top, right - 4, top + 1); bSurface.drawLine(left, top, left + 4, top); bSurface.drawLine(right - 4, top, right, top); break; case MapSquare.BYTE_WALLHIDDENDOOR: case MapSquare.BYTE_WALLROCK: bSurface.drawLine(left, top, right, top); break; case MapSquare.BYTE_WALLFOUNDDOOR: bSurface.drawLine(left, top, left + 5, top); bSurface.drawLine(right - 5, top, right, top); bSurface.drawLine(left + 4, top + 1, right - 4, top + 1); break; } switch (mapSquare.getWallType(Direction.East)) { case MapSquare.BYTE_WALLDOOR: bSurface.drawLine(right, top, right, top + 4); bSurface.drawLine(right, bottom - 4, right, bottom); bSurface.drawLine(right, top + 4, right - 1, top + 4); bSurface.drawLine(right, bottom - 4, right - 1, bottom - 4); break; case MapSquare.BYTE_WALLHIDDENDOOR: case MapSquare.BYTE_WALLROCK: bSurface.drawLine(right, top, right, bottom); break; case MapSquare.BYTE_WALLFOUNDDOOR: bSurface.drawLine(right, top, right, top + 5); bSurface.drawLine(right, bottom - 5, right, bottom); bSurface.drawLine(right - 1, top + 4, right - 1, bottom - 4); break; } switch (mapSquare.getWallType(Direction.South)) { case MapSquare.BYTE_WALLDOOR: bSurface.drawLine(left, bottom, left + 4, bottom); bSurface.drawLine(right - 4, bottom, right, bottom); bSurface.drawLine(left + 4, bottom, left + 4, bottom - 1); bSurface.drawLine(right - 4, bottom, right - 4, bottom - 1); break; case MapSquare.BYTE_WALLHIDDENDOOR: case MapSquare.BYTE_WALLROCK: bSurface.drawLine(left, bottom, right, bottom); break; case MapSquare.BYTE_WALLFOUNDDOOR: bSurface.drawLine(left, bottom, left + 5, bottom); bSurface.drawLine(right - 5, bottom, right, bottom); bSurface.drawLine(left + 4, bottom - 1, right - 4, bottom - 1); break; } switch (mapSquare.getWallType(Direction.West)) { case MapSquare.BYTE_WALLDOOR: bSurface.drawLine(left, top, left, top + 4); bSurface.drawLine(left, bottom - 4, left, bottom); bSurface.drawLine(left, top + 4, left + 1, top + 4); bSurface.drawLine(left, bottom - 4, left + 1, bottom - 4); break; case MapSquare.BYTE_WALLHIDDENDOOR: case MapSquare.BYTE_WALLROCK: bSurface.drawLine(left, top, left, bottom); break; case MapSquare.BYTE_WALLFOUNDDOOR: bSurface.drawLine(left, top, left, top + 5); bSurface.drawLine(left, bottom - 5, left, bottom); bSurface.drawLine(left + 1, top + 4, left + 1, bottom - 4); break; } return newImage; }