forked from gecube/opencaesar3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_finding.hpp
109 lines (86 loc) · 2.95 KB
/
path_finding.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// This file is part of openCaesar3.
//
// openCaesar3 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 3 of the License, or
// (at your option) any later version.
//
// openCaesar3 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with openCaesar3. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright 2012-2013 Gregoire Athanase, gathanase@gmail.com
#ifndef PATH_FINDING_HPP
#define PATH_FINDING_HPP
#include "building.hpp"
#include "enums.hpp"
#include "serializer.hpp"
#include <list>
class PathWay : public Serializable
{
public:
PathWay();
PathWay(const PathWay ©);
void init(Tilemap &tilemap, Tile &origin);
int getLength() const;
Tile &getOrigin() const;
Tile &getDestination() const;
bool isReverse() const;
void begin();
void rbegin();
virtual DirectionType getNextDirection();
bool isDestination() const;
void setNextDirection(const DirectionType direction);
void setNextTile(Tile &tile);
bool contains(Tile &tile);
std::list<Tile*>& getAllTiles();
void prettyPrint() const;
void serialize(OutputSerialStream &stream);
void unserialize(InputSerialStream &stream);
private:
Tilemap *_tilemap;
Tile *_origin;
int _destinationI;
int _destinationJ;
std::vector<DirectionType> _directionList;
std::vector<DirectionType>::iterator _directionIt;
std::vector<DirectionType>::reverse_iterator _directionIt_reverse;
std::list<Tile*> _tileList;
bool _isReverse;
};
bool operator<(const PathWay &v1, const PathWay &v2);
class Tilemap;
class City;
class Propagator
{
public:
Propagator();
/** propagate some data in the road network
* param origin : propagation origin
* param oCompletedBranches: result of the propagation: road=destination, pathWay=path
*/
void init(Road& origin);
void init(std::list<Road*>& origin);
void init(Construction& origin);
void propagate(const int maxDistance);
void getReachedRoads(std::map<Road*, PathWay> &oPathWayList);
void getReachedBuildings(const BuildingType buildingType, std::map<Building*, PathWay> &oPathWayList);
/** finds the shortest path between origin and destination
* returns True if a path exists
* the path is returned in oPathWay
*/
bool getPath(Road &destination, PathWay &oPathWay);
bool getPath(Building &destination, PathWay &oPathWay);
/** returns all paths starting at origin */
void getAllPaths(const int maxDistance, std::list<PathWay> &oPathWayList);
private:
std::set<PathWay> _activeBranches;
std::map<Road*, PathWay> _completedBranches;
City *_city;
Tilemap *_tilemap;
};
#endif