wyvern.common.util
Class Borderer

java.lang.Object
  extended bywyvern.common.util.Borderer

public abstract class Borderer
extends java.lang.Object

This class handles choosing terrain borders. It determines whether borders are required and caches information about them for later.

The methods of this class are unsynchronized and unprotected against access by multiple threads. The class is shared by the game client and the map editor, although the map editor uses a subclass that doesn't try to fetch images that it can't find.

Version:
1.0, Jul 02, 1998
Author:
Steve Yegge

Constructor Summary
Borderer()
          Constructs a new Borderer
 
Method Summary
 java.awt.Image[] chooseBorders(int x, int y, TerrainInfo[][] map)
          Chooses a set of borders for a given location in the map.
 java.awt.Image getBorder(int tile, int number)
          Gets the numbered border for a tile.
 java.lang.String getBorderBase(java.lang.String terrain)
          Returns the base for the border bitmap given a terrain type.
protected  java.lang.String getImageName(int tile)
          Looks up an image from its tile number.
protected abstract  java.awt.Image loadImage(java.lang.String name)
          Loads the image file given its name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Borderer

public Borderer()
Constructs a new Borderer

Method Detail

chooseBorders

public java.awt.Image[] chooseBorders(int x,
                                      int y,
                                      TerrainInfo[][] map)
Chooses a set of borders for a given location in the map.

Parameters:
map - an array of TerrainInfo objects. It must be at least large enough to examine the 8 adjacent neighbors of the passed location in the array; thus the minimum size is 3x3.
x - the array x index to choose borders for
y - the array y index to choose borders for
Returns:
an array of border Images to draw at this square, or null if there are no borders to draw. Any of the elements of the returned array may also be null, if that particular border number isn't to be drawn here.

getBorder

public java.awt.Image getBorder(int tile,
                                int number)
Gets the numbered border for a tile.

Parameters:
tile - the tile number of the image whose borders we want
number - the border number (1-20) to load
Returns:
the border Image, which as a side-effect is cached.

getBorderBase

public java.lang.String getBorderBase(java.lang.String terrain)
Returns the base for the border bitmap given a terrain type.

Parameters:
terrain - the terrain, e.g. "terrain/clover"
Returns:
e.g. "terrain/borders/clover/cloverBorder"

loadImage

protected abstract java.awt.Image loadImage(java.lang.String name)
Loads the image file given its name. The client version does this by trying to load it, and if it fails, asking the server to send it over. The mapedit version just loads the image directly.

Parameters:
name - something like "terrain/borders/forest/forestBorder10"
Returns:
the image (prepends art root, appends extension, loads it)

getImageName

protected java.lang.String getImageName(int tile)
Looks up an image from its tile number. This is handled differently in the client and map editor - the map editor always has the image available, via the TileRegistry. The client has to go to the image cache and see if it's available from the server yet.

Parameters:
tile - the tile number to look up
Returns:
the relative image path and name