Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PFWaypointCollection.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2011 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library 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 Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef PF_WAYPOINT_COLLECTION_H
22 #define PF_WAYPOINT_COLLECTION_H
23 
24 #include "../Math_LIB/MPath.h"
25 #include "../CD_LIB/CDGrid.h"
26 
27 namespace OpenSkyNet {
28  namespace PF {
35  public:
37  struct lessThan {
38  bool operator()(const Math::Point<int>& p1_, const Math::Point<int>& p2_) const {
39  if (p1_.x() < p2_.x()) return true;
40  else if (p1_.x() > p2_.x()) return false;
41  else if (p1_.y() < p2_.y()) return true;
42  else if (p1_.y() > p2_.y()) return false;
43  else if (p1_.z() < p2_.z()) return true;
44  else if (p1_.z() > p2_.z()) return false;
45  return false;
46  }
47  };
49  struct WhoGoesWhereDef {
50  std::set<Math::Point<int>, lessThan> _drivBins;
51  std::set<Math::Point<int>, lessThan> _targBins;
52  std::vector<Math::Point<> > _pathPoints;
53  protected:
54  bool findBin(const Math::Point<int>& bin_, const std::set<Math::Point<int>, lessThan>& bins_) const;
55  public:
56  inline bool findDrivBin(const Math::Point<int>& drivBin_) const {
57  return findBin(drivBin_,_drivBins);
58  }
59  inline bool findTargBin(const Math::Point<int>& targBin_) const {
60  return findBin(targBin_,_targBins);
61  }
62  };
63  std::vector<WhoGoesWhereDef*> _defs;
64  private:
65  Math::Point<> _initMaxCorner;
66  Math::Point<> _maxCorner;
67  Math::Point<> _size;
68  Math::Point<Utils::uint> _axisDivisions;
69  Math::Point<> _binSize;
70  public:
72  void loadWPC(const char* wPC_);
73 
77  return Math::Point<int>(static_cast<int>(floor((_maxCorner.x() - pos_.x())/_binSize.x())),
78  static_cast<int>(floor((_maxCorner.y() - pos_.y())/_binSize.y())),
79  static_cast<int>(floor((_maxCorner.z() - pos_.z())/_binSize.z())));
80  }
81 
83  inline bool getWPCBin(const Math::Point<>& pos_, Math::Point<int>& wPCBin_) const {
84  wPCBin_ = getWPCBin(pos_);
85 
86  if ((((((wPCBin_.x() < 0) || (wPCBin_.y() < 0)) || (wPCBin_.z() < 0)) ||
87  (wPCBin_.x() >= static_cast<int>(_axisDivisions.x()))) ||
88  (wPCBin_.y() >= static_cast<int>(_axisDivisions.y()))) ||
89  (wPCBin_.z() >= static_cast<int>(_axisDivisions.z())))
90  return false;
91  return true;
92  }
93 
96  Math::Point<int> wPCBin(getWPCBin(pos_));
97  wPCBin.x() = wPCBin.x() < 0 ? 0 : wPCBin.x();
98  wPCBin.y() = wPCBin.y() < 0 ? 0 : wPCBin.y();
99  wPCBin.z() = wPCBin.z() < 0 ? 0 : wPCBin.z();
100 
101  return Math::Point<int>(static_cast<Utils::uint>(wPCBin.x()) >= _axisDivisions.x() ? _axisDivisions.x()-1 : wPCBin.x(),
102  static_cast<Utils::uint>(wPCBin.y()) >= _axisDivisions.y() ? _axisDivisions.y()-1 : wPCBin.y(),
103  static_cast<Utils::uint>(wPCBin.z()) >= _axisDivisions.z() ? _axisDivisions.z()-1 : wPCBin.z());
104  }
105 
108  inline Math::Point<int> getWPCBin(const Math::Point<int>& gridBin_, const CD::Grid* grid_) const {
109  Math::Point<> gridBinCenter(grid_->getMaxCorner() - grid_->getBinSize()/2.0f);
110  gridBinCenter -= grid_->getBinSize()*gridBin_;
111  return getWPCBin(gridBinCenter);
112  }
113 
116  inline bool getWPCBin(const Math::Point<int>& gridBin_, const CD::Grid* grid_, Math::Point<int>& wPCBin_) const {
117  wPCBin_ = getWPCBin(gridBin_,grid_);
118 
119  if ((((((wPCBin_.x() < 0) || (wPCBin_.y() < 0)) || (wPCBin_.z() < 0)) ||
120  (wPCBin_.x() >= static_cast<int>(_axisDivisions.x()))) ||
121  (wPCBin_.y() >= static_cast<int>(_axisDivisions.y()))) ||
122  (wPCBin_.z() >= static_cast<int>(_axisDivisions.z())))
123  return false;
124  return true;
125  }
126 
128  inline Math::Point<int> getNearestWPCBin(const Math::Point<int>& gridBin_, const CD::Grid* grid_) const {
129  Math::Point<int> wPCBin(getWPCBin(gridBin_,grid_));
130  wPCBin.x() = wPCBin.x() < 0 ? 0 : wPCBin.x();
131  wPCBin.y() = wPCBin.y() < 0 ? 0 : wPCBin.y();
132  wPCBin.z() = wPCBin.z() < 0 ? 0 : wPCBin.z();
133 
134  return Math::Point<int>(static_cast<Utils::uint>(wPCBin.x()) >= _axisDivisions.x() ? _axisDivisions.x()-1 : wPCBin.x(),
135  static_cast<Utils::uint>(wPCBin.y()) >= _axisDivisions.y() ? _axisDivisions.y()-1 : wPCBin.y(),
136  static_cast<Utils::uint>(wPCBin.z()) >= _axisDivisions.z() ? _axisDivisions.z()-1 : wPCBin.z());
137  }
138 
140  int getWGWDIndex(Math::Point<int>& drivBin_, Math::Point<int>& targBin_, const CD::Grid* grid_) const;
141 
143  int getWGWDIndex(const Math::Point<>& drivPos_, const Math::Point<>& targPos_) const;
144 
147  void getPath(int wGWDIndex_, const Math::Point<>& drivPos_, const Math::Point<>& targPos_, Math::Path& path_) const;
148 
150  inline const Math::Point<>& getMaxCorner() const { return _maxCorner; }
151 
153  inline void translate(const Math::Point<>& delta_) { _maxCorner += delta_; }
154 
156  inline const Math::Point<>& getSize() const { return _size; }
157 
159  inline const Math::Point<Utils::uint>& getAxisDivs() const { return _axisDivisions; }
160 
163  inline const Math::Point<>& getBinSize() const { return _binSize; }
164  };
165  }
166 }
167 
168 #endif //PF_WAYPOINT_COLLECTION_H
const Math::Point< Utils::uint > & getAxisDivs() const
Definition: PFWaypointCollection.h:159
std::set< Math::Point< int >, lessThan > _targBins
Definition: PFWaypointCollection.h:51
bool findTargBin(const Math::Point< int > &targBin_) const
Definition: PFWaypointCollection.h:59
std::vector< Math::Point<> > _pathPoints
Definition: PFWaypointCollection.h:52
Math::Point< int > getNearestWPCBin(const Math::Point< int > &gridBin_, const CD::Grid *grid_) const
Definition: PFWaypointCollection.h:128
std::vector< WhoGoesWhereDef * > _defs
Definition: PFWaypointCollection.h:63
T & y()
Definition: MPoint.h:65
T & x()
Definition: MPoint.h:64
bool getWPCBin(const Math::Point< int > &gridBin_, const CD::Grid *grid_, Math::Point< int > &wPCBin_) const
Definition: PFWaypointCollection.h:116
const Math::Point & getMaxCorner() const
Definition: CDGrid.h:228
Definition: PFWaypointCollection.h:34
bool operator()(const Math::Point< int > &p1_, const Math::Point< int > &p2_) const
Definition: PFWaypointCollection.h:38
Math::Point< int > getWPCBin(const Math::Point< int > &gridBin_, const CD::Grid *grid_) const
Definition: PFWaypointCollection.h:108
const Math::Point & getBinSize() const
Definition: CDGrid.h:242
const Math::Point & getSize() const
Definition: PFWaypointCollection.h:156
Math::Point< int > getWPCBin(const Math::Point<> &pos_) const
Definition: PFWaypointCollection.h:76
Definition: PFWaypointCollection.h:37
int getWGWDIndex(Math::Point< int > &drivBin_, Math::Point< int > &targBin_, const CD::Grid *grid_) const
std::set< Math::Point< int >, lessThan > _drivBins
Definition: PFWaypointCollection.h:50
unsigned int uint
Definition: UTypes.h:39
T & z()
Definition: MPoint.h:66
bool findBin(const Math::Point< int > &bin_, const std::set< Math::Point< int >, lessThan > &bins_) const
Definition: PFWaypointCollection.h:49
void loadWPC(const char *wPC_)
bool getWPCBin(const Math::Point<> &pos_, Math::Point< int > &wPCBin_) const
Definition: PFWaypointCollection.h:83
Math::Point< int > getNearestWPCBin(const Math::Point<> &pos_) const
Definition: PFWaypointCollection.h:95
bool findDrivBin(const Math::Point< int > &drivBin_) const
Definition: PFWaypointCollection.h:56
Definition: CDGrid.h:92
void getPath(int wGWDIndex_, const Math::Point<> &drivPos_, const Math::Point<> &targPos_, Math::Path &path_) const
void translate(const Math::Point<> &delta_)
Definition: PFWaypointCollection.h:153
float pos_[3]
Definition: ViewerApp.h:31
const Math::Point & getMaxCorner() const
Definition: PFWaypointCollection.h:150
Definition: MPath.h:31
const Math::Point & getBinSize() const
Definition: PFWaypointCollection.h:163