Mercurial > fife-parpg
annotate engine/core/pathfinder/linearpather/linearpather.h @ 273:815354ba295e
* Added function to fife_utils: getUserDataDirectory. Returns the proper path to save setting and data files depending on OS.
* Made rio_de_hola save its settings in the proper location.
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 16 Jun 2009 14:24:26 +0000 |
parents | b04a2faf7d86 |
children |
rev | line source |
---|---|
272
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 /*************************************************************************** |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 * Copyright (C) 2005-2008 by the FIFE team * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 * http://www.fifengine.de * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 * This file is part of FIFE. * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 * * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 * FIFE is free software; you can redistribute it and/or * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 * License as published by the Free Software Foundation; either * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 * * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 * This library is distributed in the hope that it will be useful, * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 * Lesser General Public License for more details. * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 * * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 * License along with this library; if not, write to the * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 * Free Software Foundation, Inc., * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 ***************************************************************************/ |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 #ifndef FIFE_PATHFINDER_LINEAR_H |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 #define FIFE_PATHFINDER_LINEAR_H |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 // Standard C++ library includes |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 #include <map> |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 // 3rd party library includes |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 // FIFE includes |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 // These includes are split up in two parts, separated by one empty line |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 // First block: files included from the FIFE root src directory |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 // Second block: files included from the same folder |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 #include "model/structures/location.h" |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 #include "model/structures/map.h" |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 #include "model/metamodel/abstractpather.h" |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 namespace FIFE { |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 /** Naive pathfinder implementation |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 */ |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 class LinearPather: public AbstractPather { |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 public: |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 LinearPather(): m_session_counter(0), m_map(NULL) {} |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 virtual ~LinearPather() {} |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 int getNextLocation(const Instance* instance, const Location& target, |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 double speed, Location& nextLocation, |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 Location& facingLocation, int session_id=-1, |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 int priority = MEDIUM_PRIORITY); |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 void update() { } |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 bool cancelSession(const int session_id) { |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 m_session2face.erase(session_id); |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 return true; |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 } |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 std::string getName() const { return "LinearPather"; } |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 private: |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 std::map< int, Location > m_session2face; |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 unsigned int m_session_counter; |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 Map* m_map; |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 }; |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 } |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 #endif |
b04a2faf7d86
* Reverted the latest pathfinding module changes as they broke building trunk
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
70 |