Show worldpos.h syntax highlighted
/***************************************************************************
worldpos.h - description
-------------------
begin : Thu Nov 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 WORLDPOS_H_INCLUDED
#define WORLDPOS_H_INCLUDED
#include <boost/operators.hpp>
#include <utility>
class MapPos;
class MapTilePos;
class Rotation;
class CL_OutputSource;
class CL_InputSource;
/**
* An accurate position on a specific tile on the map.
* Represents a position on the map. Contains a position on a tile
* and the coordinates of that tile. Encompasses the properties
* of both a MapPos and a MapTilePos.
* \see MapPos, MapTilePos
*/
class WorldPos:
boost::equality_comparable<WorldPos,
boost::additive<WorldPos,
boost::multiplicative<WorldPos, float
> > > {
private:
/**
* Coords.
*/
float x, y;
public:
/**
* Default constructor (0, 0).
*/
WorldPos();
/**
* Constructor.
* \param mx Map x coordinate.
* \param my Map y coordinate.
* \param tx MapTile x coordinate.
* \param ty MapTile y coordinate.
*/
WorldPos(int mx, int my, float tx, float ty);
/**
* Constructor.
* \param wx World x coordinate.
* \param wy World y coordinate.
*/
WorldPos(float wx, float wy);
/**
* Copy constructor.
*/
WorldPos(const WorldPos& p);
/**
* Converting copy constructor.
*/
explicit WorldPos(const MapPos& p);
/**
* Assignment operator.
*/
WorldPos& operator=(const WorldPos& p);
/**
* Accessor.
*/
float getX() const;
/**
* Accessor.
*/
float getY() const;
/**
* Mutator.
*/
void setX(float nx);
/**
* Mutator.
*/
void setY(float ny);
/**
* Accessor.
*/
int getMapX() const;
/**
* Accessor.
*/
int getMapY() const;
/**
* Accessor.
*/
float getTileX() const;
/**
* Accessor.
*/
float getTileY() const;
/**
* Does this point to the same tile as \p p?
* \return true if this and the given MapPos point to the
* same tile.
*/
bool sameTile(const MapPos& p) const;
/**
* Is the \p pos within \p rangeSq of this?
* \param pos The pos to check.
* \param rangeSq The square of the range.
*/
bool near(const WorldPos& pos, float rangeSq) const;
/**
* Equality.
*/
bool operator==(const WorldPos& p) const;
/**
* Movement.
*/
WorldPos& operator+=(const WorldPos& p);
/**
* Direction.
*/
WorldPos& operator-=(const WorldPos& p);
/**
* Make length of this from pos (0, 0) become 1. Normalise size.
*/
void normalise();
/**
* Size.
*/
WorldPos& operator*=(float n);
/**
* Size.
*/
WorldPos& operator/=(float n);
/**
* Calculate the square of the distance between this and \p p.
*/
float distanceSquared(const WorldPos& p) const;
/**
* Cast. This will never return (1, 1).
*/
MapTilePos getTile() const;
/**
* Cast.
*/
MapPos getMap() const;
/**
* Spins the pos.
* \param r Amount
* \param width Width of the map.
* \param height Height of the map.
*/
void rotate(const Rotation& r, int width, int height);
/**
* Return the two positions that make up this WorldPos.
*/
std::pair<MapPos, MapTilePos> split() const;
/**
* Inject this class into \p os.
*/
void inject(CL_OutputSource& os) const;
/**
* Read a WorldPos from \p is and return it.
*/
static WorldPos extract(CL_InputSource& is);
};
/**
* Adding a MapPos and a MapTilePos to get a complete WorldPos.
*/
WorldPos operator+(const MapPos& mp, const MapTilePos& tp);
/**
* Write a WorldPos to an ostream. Useful for debugging.
*/
std::ostream& operator<<(std::ostream& os, const WorldPos& p);
#endif /* ndef WORLDPOS_INCLUDED */
See more files for this project here