Show mappos.cpp syntax highlighted
/***************************************************************************
mappos.cpp - description
-------------------
begin : Tue Nov 26 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. *
* *
***************************************************************************/
#include <mappos.h>
#include <rotation.h>
MapPos::MapPos(): x(0), y(0) {
}
MapPos::MapPos(int px, int py): x(px), y(py) {
}
MapPos::MapPos(const MapPos& p): x(p.x), y(p.y) {
}
bool MapPos::operator==(const MapPos& p) const {
return x == p.x && y == p.y;
}
MapPos& MapPos::operator+=(const MapPos& p) {
x += p.x;
y += p.y;
return *this;
}
MapPos& MapPos::operator-=(const MapPos& p) {
x -= p.x;
y -= p.y;
return *this;
}
int MapPos::getX() const {
return x;
}
int MapPos::getY() const {
return y;
}
void MapPos::set(int px, int py) {
x = px;
y = py;
}
void MapPos::rotate(const Rotation& r, int width, int height) {
int ox = x;
int oy = y;
switch (r.getClock()) {
case 1:
x = height - oy - 1;
y = ox;
break;
case 2:
x = width - ox - 1;
y = height - oy - 1;
break;
case 3:
x = oy;
y = width - ox - 1;
break;
default:
break;
}
}
void MapPos::inject(CL_OutputSource& os) const {
os.write_int32(x);
os.write_int32(y);
}
MapPos MapPos::extract(CL_InputSource& is) {
// NOTE Order of parameter evaluation is NOT guaranteed.
int x = is.read_int32();
int y = is.read_int32();
return MapPos(x, y);
}
See more files for this project here