FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
location.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 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 #ifndef FIFE_LOCATION_H
23 #define FIFE_LOCATION_H
24 
25 // Standard C++ library includes
26 #include <iostream>
27 
28 // 3rd party library includes
29 
30 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line
32 // First block: files included from the FIFE root src directory
33 // Second block: files included from the same folder
35 #include "util/base/exception.h"
36 
37 namespace FIFE {
38  class Map;
39  class Layer;
40 
41  class Location {
42  public:
45  Location();
46 
49  Location(const Location& loc);
50 
53  Location(Layer* layer);
54 
57  ~Location();
58 
61  void reset();
62 
65  Location& operator=(const Location& rhs);
66 
69  inline bool operator==(const Location& loc) const {
70  return ((m_layer == loc.m_layer) && (m_exact_layer_coords == loc.m_exact_layer_coords));
71  }
72 
75  inline bool operator!=(const Location& loc) const {
76  return !(*this == loc);
77  }
78 
83  Map* getMap() const;
84 
88  void setLayer(Layer* layer);
89 
93  Layer* getLayer() const;
94 
101  void setExactLayerCoordinates(const ExactModelCoordinate& coordinates);
102 
109  void setLayerCoordinates(const ModelCoordinate& coordinates);
110 
114  void setMapCoordinates(const ExactModelCoordinate& coordinates);
115 
121 
126 
134 
139 
143  ModelCoordinate getLayerCoordinates(const Layer* layer) const;
144 
149 
153  double getCellOffsetDistance() const;
154 
160  bool isValid() const;
161 
165  double getMapDistanceTo(const Location& location) const;
166 
171  double getLayerDistanceTo(const Location& location) const;
172 
173  private:
174  bool isValid(const Layer* layer) const;
175 
178  };
179 
184  std::ostream& operator<<(std::ostream&, const Location&);
185 }
186 #endif //FIFE_LOCATION_H
bool operator!=(const Location &loc) const
Compares unequality of two locations.
Definition: location.h:75
void setLayerCoordinates(const ModelCoordinate &coordinates)
Sets "cell precise" layer coordinates to this location.
Definition: location.cpp:94
void setExactLayerCoordinates(const ExactModelCoordinate &coordinates)
Sets precise layer coordinates to this location.
Definition: location.cpp:87
ExactModelCoordinate m_exact_layer_coords
Definition: location.h:177
void setLayer(Layer *layer)
Sets layer where this location is pointing to.
Definition: location.cpp:79
void setMapCoordinates(const ExactModelCoordinate &coordinates)
Sets map coordinates to this location.
Definition: location.cpp:98
Location()
Default constructor.
Definition: location.cpp:39
void reset()
Resets location (so that layer and coordinate information becomes invalid)
Definition: location.cpp:57
double getCellOffsetDistance() const
Gets offset distance from cell center.
Definition: location.cpp:157
Layer * getLayer() const
Gets the layer where this location is pointing to.
Definition: location.cpp:83
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
Definition: location.cpp:113
Map * getMap() const
Gets the map where this location is pointing to.
Definition: location.cpp:72
bool operator==(const Location &loc) const
Compares equality of two locations.
Definition: location.h:69
std::ostream & operator<<(std::ostream &os, const Location &l)
Stream output operator.
Definition: location.cpp:164
A basic layer on a map.
Definition: layer.h:99
bool isValid() const
Tells if location is valid Location is valid if:
Definition: location.cpp:121
ExactModelCoordinate & getExactLayerCoordinatesRef()
Gets reference to exact layer coordinates.
Definition: location.cpp:105
Location & operator=(const Location &rhs)
Assignment operator.
Definition: location.cpp:64
~Location()
Destructor.
Definition: location.cpp:54
A container of Layer(s).
Definition: map.h:88
double getMapDistanceTo(const Location &location) const
Gets distance in map coordinates to another location on the Map.
Definition: location.cpp:169
double getLayerDistanceTo(const Location &location) const
Gets layer distance to another location.
Definition: location.cpp:180
ExactModelCoordinate getExactLayerCoordinates() const
Gets exact layer coordinates set to this location.
Definition: location.cpp:109
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
Definition: location.cpp:117
Layer * m_layer
Definition: location.h:176