1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef NUVIE_PATHFINDER_PATH_H
24 #define NUVIE_PATHFINDER_PATH_H
25 
26 #include "ultima/nuvie/core/nuvie_defs.h"
27 #include "ultima/nuvie/pathfinder/path_finder.h"
28 
29 namespace Ultima {
30 namespace Nuvie {
31 
32 class MapCoord;
33 
34 /* Abstract for a class that provides the path-search routines and cost methods
35  * to a PathFinder. This includes useful default methods, and path handling.
36  */
37 class Path {
38 protected:
39 	MapCoord *path; // list of tiles in the path, set by create_path()
40 	uint32 step_count; // number of locations in the path
41 	uint32 path_size; // allocated elements in list
42 	PathFinder *pf;
43 
44 	void add_step(MapCoord loc);
45 	bool check_dir(const MapCoord &loc, MapCoord &rel);
46 	bool check_loc(const MapCoord &loc);
47 	void set_path_size(int alloc_size);
48 
49 public:
50 	Path();
51 	virtual ~Path();
set_pathfinder(PathFinder * pathfinder)52 	void set_pathfinder(PathFinder *pathfinder) {
53 		pf = pathfinder;
54 	}
55 
56 	/* The pathfinding routine. Can return success or failure of a search. */
57 	virtual bool path_search(MapCoord &start, MapCoord &goal) = 0;
58 	void delete_path();
59 	virtual bool have_path();
60 
61 	/* Returns the real cost of moving from a node (or location) to a
62 	   neighboring node. (a single step) */
63 	virtual sint32 step_cost(MapCoord &c1, MapCoord &c2) = 0;
64 
65 	/* Estimate highest possible cost from s to g */
66 	virtual uint32 path_cost_est(MapCoord &s, MapCoord &g);
67 	/* Returns maximum score of any single node in the search of a path with
68 	   a certain estimated cost.*/
69 	virtual uint32 get_max_score(uint32 cost);
70 
71 	virtual MapCoord get_first_step();
72 	virtual MapCoord get_last_step();
73 	virtual MapCoord get_step(uint32 step_index);
74 	virtual void get_path(MapCoord **path_start, uint32 &path_size);
get_num_steps()75 	uint32 get_num_steps() {
76 		return step_count;
77 	}
78 
79 	virtual bool remove_first_step();
80 };
81 
82 } // End of namespace Nuvie
83 } // End of namespace Ultima
84 
85 #endif
86