Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Map Class Reference

A tile-based representation of the world. More...

#include <map.h>

Collaboration diagram for Map:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Map (long width, long height)
 Create a new map of a particular size.

 Map (const char *filename)
 Create a new map by loading it from a file.

 Map (Map *)
 Create a new map by copying it from another map.

 Map (FILE *)
 Create a new map by loading it from a file pointer.

 Map (std::istringstream &data)
 Not implemented.

 ~Map ()
void load (const char *filename)
 Resets the current map by loading the file passed in.

void load (FILE *f)
 Resets the current map by loading the file from the pointer passed in.

void setSizeMultipler (int _sizeMultiplier)
void scale (long newWidth, long newHeight)
void save (std::stringstream &data)
 unimplemented.

void save (const char *filename)
 Saves the current map out to the designated file.

void save (FILE *f)
 Saves the current map out to the designated file.

Map * clone ()
const char * getMapName ()
void print (int scale=1)
 Do an ASCII/ANSI print out of the map.

long getMapWidth () const
 return the width of the map

long getMapHeight () const
 return the height of the map

void setTileSet (tTileset ts)
 Choose the tileset used for land colors.

tTileset getTileSet ()
 Get the tileset used for land colors.

Tile & getTile (long x, long y)
 Return the tile at location x, y.

tSplit getSplit (long x, long y) const
 Return the split of the tile at x, y.

void setSplit (long x, long y, tSplit split)
 Set the split of the tile at x, y.

long getTerrainType (long x, long y, tSplitSide split=kWholeTile) const
 Get the terrain type of the (split) tile at x, y.

long getTerrainType (long x, long y, tEdge side) const
 Get the terrain type for one side of the tile at x, y.

void setTerrainType (long x, long y, tTerrain type, tSplitSide split=kWholeTile)
 Set the terrain type of the side of the tile at x, y.

long getHeight (long x, long y, tSplitSide split=kWholeTile)
 Get the (flat) height of the tile at x, y.

void setHeight (long x, long y, long height, tSplitSide split=kWholeTile)
 Set the (flat) height of the tile at x, y.

long getCornerHeight (long x, long y, tCorner which, tEdge edge) const
 Set the height of any one corner of a tile.

long getCornerHeight (long x, long y, tCorner which, tSplitSide split=kWholeTile) const
 Get the height of any one corner of a tile.

void setCornerHeight (long x, long y, tCorner which, long height, tSplitSide split=kWholeTile)
 Set the height of any one corner of a tile.

void smoothSetRectHeight (long x1, long y1, long x2, long y2, long h, tTerrain type=kGround)
 Places a rectangle into the map, but also modifies the edges to make the transition smooth.

void setRectHeight (long x1, long y1, long x2, long y2, long h, tTerrain type=kGround)
 Set the height and terrain of a set of tiles.

bool adjacentEdges (long x, long y, tEdge edge) const
 Is the tile at x, y adjacent across the edge?

bool adjacentCorners (long x, long y, tCorner corner) const
bool canStep (long x1, long y1, long x2, long y2) const
void openGLDraw (tDisplay how)
 Does actual OpenGL drawing of the map.

void getOpenGLCoord (int _x, int _y, GLdouble &x, GLdouble &y, GLdouble &z, GLdouble &radius) const
 Get the openGL coordinates of a given tile.

void getPointFromCoordinate (point3d loc, int &px, int &py) const
double getCoordinateScale ()
 Returns the scale multiplier between openGL coordinates and map coordinates.

void setDrawLand (bool land)
 Toggles whether the land is draw when you call openGLDraw.

bool getDrawLand ()
void drawTile (Tile *t, int x, int y, tDisplay how)
 Draw a single tile.

void doVertexColor (tTerrain type, int height, bool darken=false)
 Using OpenGL set the correct color for a particular vertex.

void doNormal (tSplit split, halfTile *t, int x, int y)
 does a rough approximation of the normal for a particular halfTile.

float getEdgeWidthX (int x, int y)
 Returns the edge width between (x, y) and (x+1, y).

float getEdgeWidthY (int x, int y)
 Returns the edge width between (x, y) and (x, y+1).

int getNodeNum (int x, int y, tCorner c=kNone)
 Gets the abstract graph node number for this tile.

void setNodeNum (int num, int x, int y, tCorner c=kNone)
 Sets the abstract graph node number for this tile.

int getRevision ()

Private Member Functions

void loadRaw (FILE *f, int height, int width)
void loadOctile (FILE *f, int height, int width)
void loadOctileCorner (FILE *f, int height, int width)
void saveOctile (FILE *f)
void saveRaw (FILE *f)
bool tryLoadRollingStone (FILE *f)
bool isLegalStone (char c)
void paintRoomInside (int x, int y)
void drawLandQuickly ()

Private Attributes

int width
int height
Tile ** land
bool drawLand
GLuint dList
bool updated
int sizeMultiplier
int revision
char map_name [128]
tMapType mapType
tTileset tileSet

Detailed Description

A tile-based representation of the world.


Constructor & Destructor Documentation

Map::Map (  long  _width,
long  _height
) 
 

Create a new map of a particular size.

A map is an array of tiles according to the height and width of the map.

Map::Map (  const char *  filename  ) 
 

Create a new map by loading it from a file.

Creates a new map and initializes it with the file passed to it.

Map::Map (  Map *  m  ) 
 

Create a new map by copying it from another map.

Creates a new map and initializes it with the map passed to it.

Map::Map (  FILE *  f  ) 
 

Create a new map by loading it from a file pointer.

Creates a new map and initializes it with the file pointer passed to it.

Map::Map (  std::istringstream &  data  ) 
 

Not implemented.

This function is not implemented.

Map::~Map (   ) 
 


Member Function Documentation

bool Map::adjacentCorners (  long  x,
long  y,
tCorner  corner
)  const
 

bool Map::adjacentEdges (  long  x,
long  y,
tEdge  edge
)  const
 

Is the tile at x, y adjacent across the edge?

given an edge (kInternalEdge, kLeftEdge, kRightEdge, kBottomEdge, kTopEdge) returns whether the tiles on both sides of that edge have a smooth boundary that a unit should be able to cross.

bool Map::canStep (  long  x1,
long  y1,
long  x2,
long  y2
)  const
 

Map* Map::clone (   )  [inline]
 

void Map::doNormal (  tSplit  split,
halfTile *  t,
int  x,
int  y
) 
 

does a rough approximation of the normal for a particular halfTile.

(if I recall, this isn't perfect...)

void Map::doVertexColor (  tTerrain  type,
int  vHeight,
bool  darken = false
) 
 

Using OpenGL set the correct color for a particular vertex.

calls the appropriate openGL functions to set the draw color according to the tile height/type

void Map::drawLandQuickly (   )  [private]
 

void Map::drawTile (  Tile *  t,
int  x,
int  y,
tDisplay  how
) 
 

Draw a single tile.

draws a single tile which is at (x, y) in the land (technically we don't have to pass the tile, we could get it from the x,y coordinates)

double Map::getCoordinateScale (   ) 
 

Returns the scale multiplier between openGL coordinates and map coordinates.

If you measure a distance in openGL coordinate space, you can multiply it by this value to convert it to map space, where the distance between adjacent tiles is 1.

long Map::getCornerHeight (  long  x,
long  y,
tCorner  which,
tSplitSide  split = kWholeTile
)  const
 

Get the height of any one corner of a tile.

corner is kTopLeft, kBottomLeft, kTopRight or kBottomRight split is kLeftSide, kRightSide or kWholeTile returns kUndefinedHeight if the split is inconsistant with the tile type The combination of a corner and a split side uniquely define a single height

long Map::getCornerHeight (  long  x,
long  y,
tCorner  which,
tEdge  edge
)  const
 

Set the height of any one corner of a tile.

corner is kTopLeft, kBottomLeft, kTopRight or kBottomRight edge is kBottomEdge, kLeftEdge, kRightEdge, kTopEdge returns kUndefinedHeight if the split is inconsistant with the tile type The combination of a corner and an edge uniquely define a single height

bool Map::getDrawLand (   )  [inline]
 

float Map::getEdgeWidthX (  int  x,
int  y
) 
 

Returns the edge width between (x, y) and (x+1, y).

float Map::getEdgeWidthY (  int  x,
int  y
) 
 

Returns the edge width between (x, y) and (x, y+1).

long Map::getHeight (  long  x,
long  y,
tSplitSide  split = kWholeTile
) 
 

Get the (flat) height of the tile at x, y.

returns the height of a particular tile -- actually just one corner of the tile. If the tile is sloping you'll get back kUndefined and need to get the specific corner heights. returns kUndefinedHeight if the tile is split and you specify the whole tile

long Map::getMapHeight (   )  const [inline]
 

return the height of the map

const char * Map::getMapName (   ) 
 

long Map::getMapWidth (   )  const [inline]
 

return the width of the map

int Map::getNodeNum (  int  x,
int  y,
tCorner  corner = kNone
) 
 

Gets the abstract graph node number for this tile.

Because we have a graph representation of the map as well, we need some way to get back and forth between the representations. This function will get the unique data (nodeNum) for a tile/half tile so that we can go from a tile in the map to a node in the graph.

void Map::getOpenGLCoord (  int  _x,
int  _y,
GLdouble &  x,
GLdouble &  y,
GLdouble &  z,
GLdouble &  radius
)  const
 

Get the openGL coordinates of a given tile.

Given a tile in (x, y) coordinates, it returns the OpenGL space coordinates of that tile along with the radius of the tile square. The map is drawn in the x<->z plane, with the y plane up.

void Map::getPointFromCoordinate (  point3d  loc,
int &  px,
int &  py
)  const
 

int Map::getRevision (   )  [inline]
 

tSplit Map::getSplit (  long  x,
long  y
)  const
 

Return the split of the tile at x, y.

Returns the type of split; either kNoSplit, kForwardSplit, kBackwardSplit

long Map::getTerrainType (  long  x,
long  y,
tEdge  side
)  const
 

Get the terrain type for one side of the tile at x, y.

Gets the terrain type for a particular edge of the type. (kLeftEdge, kRightEdge, kTopEdge, kBottom Edge) This function avoids making you figure out all the ways a tile could be split to get the correct value out.

long Map::getTerrainType (  long  x,
long  y,
tSplitSide  split = kWholeTile
)  const
 

Get the terrain type of the (split) tile at x, y.

Gets the terrain type for this tile. By default it looks for the value of the whole tile. Possible split values are kWholeTile, kLeftSide, and kRightSide.

Tile & Map::getTile (  long  x,
long  y
) 
 

Return the tile at location x, y.

returns a reference to the type at a particular x/y location. (starting from 0)

tTileset Map::getTileSet (   ) 
 

Get the tileset used for land colors.

bool Map::isLegalStone (  char  c  )  [private]
 

void Map::load (  FILE *  f  ) 
 

Resets the current map by loading the file from the pointer passed in.

void Map::load (  const char *  filename  ) 
 

Resets the current map by loading the file passed in.

Resets the current map by loading the file passed in.

void Map::loadOctile (  FILE *  f,
int  height,
int  width
)  [private]
 

void Map::loadOctileCorner (  FILE *  f,
int  height,
int  width
)  [private]
 

void Map::loadRaw (  FILE *  f,
int  height,
int  width
)  [private]
 

void Map::openGLDraw (  tDisplay  how  ) 
 

Does actual OpenGL drawing of the map.

If drawLand has been set (on by default) the ground will be drawn using the appropriate mode: kPolygons, kLines, kPoints kPolygon is the default mode. The map is cached in a display list unless it changes.

void Map::paintRoomInside (  int  x,
int  y
)  [private]
 

void Map::print (  int  _scale = 1  ) 
 

Do an ASCII/ANSI print out of the map.

Moves the cursor to the top of the screen and draws an ASCII version of the map. The map is shrunk by a factor of 2 in the vertical scale, but left normal in the horizontal scale. For the moment we leave ground blank and draw the walls as x/X/^. No other ground type is drawn.

void Map::save (  FILE *  f  ) 
 

Saves the current map out to the designated file.

Saves the current map out to the designated file.

void Map::save (  const char *  filename  ) 
 

Saves the current map out to the designated file.

Saves the current map out to the designated file.

void Map::save (  std::stringstream &  data  ) 
 

unimplemented.

void Map::saveOctile (  FILE *  f  )  [private]
 

void Map::saveRaw (  FILE *  f  )  [private]
 

void Map::scale (  long  newWidth,
long  newHeight
) 
 

void Map::setCornerHeight (  long  x,
long  y,
tCorner  which,
long  cHeight,
tSplitSide  split = kWholeTile
) 
 

Set the height of any one corner of a tile.

corner is kTopLeft, kBottomLeft, kTopRight or kBottomRight split is kLeftSide, kRightSide or kWholeTile The combination of a corner and a split side uniquely define a single height, which is returned.

void Map::setDrawLand (  bool  dLand  ) 
 

Toggles whether the land is draw when you call openGLDraw.

void Map::setHeight (  long  x,
long  y,
long  tHeight,
tSplitSide  split = kWholeTile
) 
 

Set the (flat) height of the tile at x, y.

Split is kWholeTile, kLeftSide or kRightSide.

void Map::setNodeNum (  int  num,
int  x,
int  y,
tCorner  corner = kNone
) 
 

Sets the abstract graph node number for this tile.

Because we have a graph representation of the map as well, we need some way to get back and forth between the representations. This function will set the unique data (nodeNum) for a tile/half tile so that we can go from a tile in the map to a node in the graph.

void Map::setRectHeight (  long  x1,
long  y1,
long  x2,
long  y2,
long  h,
tTerrain  type = kGround
) 
 

Set the height and terrain of a set of tiles.

Sets all the tiles in the region between (x1, y1) (x2, y2) to be the same height and terrain type, with no splits.

void Map::setSizeMultipler (  int  _sizeMultiplier  )  [inline]
 

void Map::setSplit (  long  x,
long  y,
tSplit  split
) 
 

Set the split of the tile at x, y.

Sets how a map is split; either kNoSplit, kForwardSplit, kBackwardSplit

void Map::setTerrainType (  long  x,
long  y,
tTerrain  type,
tSplitSide  split = kWholeTile
) 
 

Set the terrain type of the side of the tile at x, y.

side is one of kWholeTile, kLeftSide or kRightSide If tile is not split and you specify a split side, nothing happens If tile is split and you specify kWholeTile, the split remains, and the terrain is applied to both sides.

void Map::setTileSet (  tTileset  ts  ) 
 

Choose the tileset used for land colors.

Tilesets named xxxTile will draw the map as independant tiles as opposed to a smooth connected map.

void Map::smoothSetRectHeight (  long  x1,
long  y1,
long  x2,
long  y2,
long  h,
tTerrain  type = kGround
) 
 

Places a rectangle into the map, but also modifies the edges to make the transition smooth.

sets a rectangle of with corner coordinates (x1, y1) (x2, y2) but also takes the 1-radius tiles surrounding that rectangle and smooths them so you get a nice fit of land together.

bool Map::tryLoadRollingStone (  FILE *  f  )  [private]
 


Member Data Documentation

GLuint Map::dList [private]
 

bool Map::drawLand [private]
 

int Map::height [private]
 

Tile** Map::land [private]
 

char Map::map_name[128] [private]
 

tMapType Map::mapType [private]
 

int Map::revision [private]
 

int Map::sizeMultiplier [private]
 

tTileset Map::tileSet [private]
 

bool Map::updated [private]
 

int Map::width [private]
 


The documentation for this class was generated from the following files:
Generated on Tue Aug 18 03:43:31 2009 for HOG by doxygen 1.3.4