| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
%module fife |
| 23 |
%{ |
| 24 |
#include "model/metamodel/grids/cellgrid.h" |
| 25 |
#include "model/metamodel/grids/hexgrid.h" |
| 26 |
#include "model/metamodel/grids/squaregrid.h" |
| 27 |
%} |
| 28 |
|
| 29 |
%include "model/metamodel/modelcoords.i" |
| 30 |
|
| 31 |
namespace std { |
| 32 |
%template(ModelCoordinateVector) vector<FIFE::ModelCoordinate>; |
| 33 |
%template(ExactModelCoordinateVector) vector<FIFE::ExactModelCoordinate>; |
| 34 |
} |
| 35 |
|
| 36 |
namespace FIFE { |
| 37 |
%apply std::vector<ExactModelCoordinate> &OUTPUT { std::vector<ExactModelCoordinate>& vtx }; |
| 38 |
class CellGrid { |
| 39 |
public: |
| 40 |
CellGrid(); |
| 41 |
virtual ~CellGrid(); |
| 42 |
void getAccessibleCoordinates(const ModelCoordinate& curpos, std::vector<ModelCoordinate>& coordinates); |
| 43 |
virtual const std::string& getType() const = 0; |
| 44 |
virtual const std::string& getName() const = 0; |
| 45 |
virtual bool isAccessible(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0; |
| 46 |
virtual double getAdjacentCost(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0; |
| 47 |
virtual double getHeuristicCost(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0; |
| 48 |
virtual uint32_t getCellSideCount() const = 0; |
| 49 |
ExactModelCoordinate toMapCoordinates(const ModelCoordinate& layer_coords); |
| 50 |
virtual ExactModelCoordinate toMapCoordinates(const ExactModelCoordinate& layer_coords) = 0; |
| 51 |
virtual ModelCoordinate toLayerCoordinates(const ExactModelCoordinate& map_coord) = 0; |
| 52 |
virtual ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate& map_coord) = 0; |
| 53 |
virtual ModelCoordinate toLayerCoordinatesFromExactLayerCoordinates(const ExactModelCoordinate& exact_layer_coords) = 0; |
| 54 |
virtual void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell) = 0; |
| 55 |
virtual std::vector<ModelCoordinate> getCoordinatesInLine(const ModelCoordinate& start, const ModelCoordinate& end) = 0; |
| 56 |
void setXShift(const double& xshift); |
| 57 |
const double getXShift() const; |
| 58 |
void setYShift(const double yshift); |
| 59 |
const double getYShift() const; |
| 60 |
void setZShift(const double zshift); |
| 61 |
const double getZShift() const; |
| 62 |
void setXScale(const double scale); |
| 63 |
void setYScale(const double scale); |
| 64 |
void setZScale(const double scale); |
| 65 |
const double getXScale() const; |
| 66 |
const double getYScale() const; |
| 67 |
const double getZScale() const; |
| 68 |
void setRotation(const double rotation); |
| 69 |
const double getRotation() const; |
| 70 |
void setAllowDiagonals(const bool allow_diagonals); |
| 71 |
const bool getAllowDiagonals() const; |
| 72 |
}; |
| 73 |
|
| 74 |
class HexGrid: public CellGrid { |
| 75 |
public: |
| 76 |
HexGrid(bool axial = false); |
| 77 |
virtual ~HexGrid(); |
| 78 |
|
| 79 |
bool isAccessible(const ModelCoordinate& curpos, const ModelCoordinate& target); |
| 80 |
const std::string& getType() const; |
| 81 |
const std::string& getName() const; |
| 82 |
double getAdjacentCost(const ModelCoordinate& curpos, const ModelCoordinate& target); |
| 83 |
uint32_t getCellSideCount() const { return 6; } |
| 84 |
ExactModelCoordinate toMapCoordinates(const ExactModelCoordinate& layer_coords); |
| 85 |
ModelCoordinate toLayerCoordinates(const ExactModelCoordinate& map_coord); |
| 86 |
ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate& map_coord); |
| 87 |
ModelCoordinate toLayerCoordinatesFromExactLayerCoordinates(const ExactModelCoordinate& exact_layer_coords); |
| 88 |
void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell); |
| 89 |
std::vector<ModelCoordinate> getCoordinatesInLine(const ModelCoordinate& start, const ModelCoordinate& end); |
| 90 |
}; |
| 91 |
|
| 92 |
class SquareGrid: public CellGrid { |
| 93 |
public: |
| 94 |
SquareGrid(); |
| 95 |
virtual ~SquareGrid(); |
| 96 |
|
| 97 |
const std::string& getType() const; |
| 98 |
const std::string& getName() const; |
| 99 |
bool isAccessible(const ModelCoordinate& curpos, const ModelCoordinate& target); |
| 100 |
double getAdjacentCost(const ModelCoordinate& curpos, const ModelCoordinate& target); |
| 101 |
uint32_t getCellSideCount() const { return 4; } |
| 102 |
ExactModelCoordinate toMapCoordinates(const ExactModelCoordinate& layer_coords); |
| 103 |
ModelCoordinate toLayerCoordinates(const ExactModelCoordinate& map_coord); |
| 104 |
ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate& map_coord); |
| 105 |
ModelCoordinate toLayerCoordinatesFromExactLayerCoordinates(const ExactModelCoordinate& exact_layer_coords); |
| 106 |
void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell); |
| 107 |
std::vector<ModelCoordinate> getCoordinatesInLine(const ModelCoordinate& start, const ModelCoordinate& end); |
| 108 |
}; |
| 109 |
} |