Show map.h syntax highlighted
/***************************************************************************
map.h - description
-------------------
begin : Wed Aug 14 2002
copyright : (C) 2002 by Brendon Higgins
email : freepop-devel@lists.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef MAP_H_INCLUDED
#define MAP_H_INCLUDED
#include <maptile.h>
#include <mappos.h>
#include <boost/utility.hpp>
#include <vector>
#include <string>
class Corner;
class WorldPos;
class CL_InputSource;
/**
* Contains the world map.
* Has a list of MapTiles to represent each tile
* of the map. A point on the map can be lowered/raised in such
* a way that all adjacent points are also moved to maintain
* a continuous (hilly or flat) landscape.
* Client/Server editions have different list types, so
* each supplies its own.
*/
class Map: boost::noncopyable {
public:
/**
* Name of the map tile raise channel.
*/
static const std::string NET_RAISE;
/**
* Name of the map tile lower channel.
*/
static const std::string NET_LOWER;
public:
/**
* Constructs a new map of the given dimensions.
*/
Map(int w, int h);
/**
* Constructs a new map, dimensions taken from \p is.
* This is necessary to guarantee the dimensions are read in the correct
* order. The order of evaluation of parameters is undefined in C++, so
* if you use Map(is.read_int32(), is.read_int32()) the second parameter
* might be evaluated first, thus swapping width and height. This avoids
* that problem.
*/
Map(CL_InputSource& is);
/**
* Destructor.
*/
virtual ~Map();
/**
* Get the width of the map.
*/
int getWidth() const;
/**
* Get the height of the map.
*/
int getHeight() const;
/**
* Get the tile at \p p.
*/
virtual const MapTile* getTile(const MapPos& p) const = 0;
/**
* Get the tile at \p p.
*/
virtual MapTile* getTile(const MapPos& p) = 0;
/**
* Get the tile at \p p.
*/
virtual const MapTile* getTile(const WorldPos& p) const = 0;
/**
* Get the tile at \p p.
*/
virtual MapTile* getTile(const WorldPos& p) = 0;
/**
* Raises the \p c corner of the tile at \p p and all other adjacent
* corners as required. As adjacent tiles are pulled this function is only
* called virtually for the first tile, subsequent iterations call
* Map::raiseTileCornerInt() directly. If you want to be called virtually
* for each tile override raiseTileCornerInt().
*/
virtual void raiseTileCorner(const MapPos& p, const Corner& c);
/**
* Lowers the \p c corner of the tile at \p p and all other adjacent
* corners as required (if not already at sea level). As adjacent tiles are
* pulled this function is only called virtually for the first tile,
* subsequent iterations call Map::lowerTileCornerInt() directly. If you
* want to be called virtually for each tile override lowerTileCornerInt().
*/
virtual void lowerTileCorner(const MapPos& p, const Corner& c);
/**
* Like raiseTileCorner() but virtually called for every tile that
* moves.
*/
virtual void raiseTileCornerInt(const MapPos& p, const Corner& c);
/**
* Like lowerTileCorner() but virtually called for every tile that
* moves.
*/
virtual void lowerTileCornerInt(const MapPos& p, const Corner& c);
/**
* Finds the location on the map of the tile \p t.
* \note This assumes that \p t is indeed somewhere on the map.
*/
virtual MapPos findPos(const MapTile& t) const;
/**
* Is the tile at \p pos flat?
*/
bool isFlat(const MapPos& pos) const;
/**
* Is the tile at \p pos flat?
*/
bool isFlat(const WorldPos& pos) const;
/**
* Is \p pos in the sea?
*/
bool isSea(const WorldPos& pos) const;
/**
* Finds the height at the given pos on the map.
*/
float getZ(const WorldPos& p) const;
/**
* Get a random map pos, valid on the map.
* Ie, 0 <= X < width, 0 <= Y < height
* \deprecated
*/
MapPos getRandomPos() const;
/**
* Check that \p p is within map bounds.
* \note A WorldPos at any edge of a map is invalid, but a MapPos of the
* tile at the edge is valid.
*/
virtual bool isValid(const MapPos& p) const;
/**
* Check that \p p is within map bounds.
* \note A WorldPos at any edge of a map is invalid, but a MapPos of the
* tile at the edge is valid.
*/
virtual bool isValid(const WorldPos& p) const;
protected:
/**
* The width of the map in tile units.
*/
int width;
/**
* The height of the map in tile units.
*/
int height;
/**
* Get the tile at the local location, ignoring display rotation, etc.
*/
virtual const MapTile* getTileLocal(const MapPos& p) const;
/**
* Get the tile at the local location, ignoring display rotation, etc.
*/
virtual MapTile* getTileLocal(const MapPos& p);
/**
* Checks if a tile corner is different to an adjacent one,
* and raises if necessary.
*
* \param p Coordinates of tile to pull.
* \param z Height that corner should be at.
* \param c The ID of the corner to pull.
*/
virtual void pullTileCornerUp(const MapPos& p, unsigned int z,
const Corner& c);
/**
* Checks if a tile corner is different to an adjacent
* one, and lowers if necessary.
*
* \param p Coordinates of tile to pull.
* \param z Height that corner should be at.
* \param c The ID of the corner to pull.
*/
virtual void pullTileCornerDown(const MapPos& p, unsigned int z,
const Corner& c);
};
#endif /* ndef MAP_H_INCLUDED */
See more files for this project here