File: pathFinder.h

package info (click to toggle)
attal 0.9.2-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,992 kB
  • ctags: 5,972
  • sloc: cpp: 44,510; sh: 134; makefile: 45
file content (182 lines) | stat: -rw-r--r-- 4,204 bytes parent folder | download | duplicates (2)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/****************************************************************
**
** Attal : Lords of Doom
**
** pathFinder.h
** Compute pathes in the map
**
** Version : $Id: pathFinder.h,v 1.4 2004/08/01 11:30:19 audoux Exp $
**
** Author(s) : Pascal Audoux
**
** Date : 04/08/2000
**
** Licence :    
**	This program 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 2, or (at your option)
**      any later version.
**
**	This program 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.
**
****************************************************************/

 
#ifndef PATHFINDER_H
#define PATHFINDER_H


// generic include files
// include files for QT
#include <qptrlist.h>
#include <qptrstack.h>
// application specific includes
#include "libCommon/log.h"
#include "libCommon/genericCell.h"
#include "libCommon/genericMap.h"
#include "libCommon/genericFightMap.h"
#include "libCommon/genericFightCell.h"

#define COST_DIRECT 2
#define COST_DIAG 3

/** Structure for representing a path on the adventure map */
struct PathCell {
	GenericCell * cell;
	PathCell * prev;
       	int dist;

	friend bool sup( PathCell * a, PathCell * b )
        { return (a->dist > b->dist); }
};

/** structure of pathCell allowing to get the smallest */
class Pile : public QPtrList<PathCell>
{
public:
	/** Constructor */
	Pile();

	/** Return the pathcell with smallest dist */
	PathCell * takeSmallest();

};

/** Structure for representing a path on the fight map */
struct PathFightCell {
	GenericFightCell * cell;
	PathFightCell * prev;
       	int dist;

	friend bool sup( PathFightCell * a, PathFightCell * b )
        { return (a->dist>b->dist); }
};

/*
class FightPile : public QPtrList<PathFightCell>
{
public:
	** Constructor *
	FightPile();

	** Return the pathcell with smallest dist *
	PathFightCell * takeSmallest();

};
*/

/*              ------------------------------
 *                         PathFinder
 *              ------------------------------ */



/** Find the shortest path from A to B on the map */
class PathFinder
{

public:
	/** Constructor */
	PathFinder();

	/** Constructor */
	PathFinder( int h, int w, GenericMap * m );

	/** Destructor */
	~PathFinder();

        /** Reinit the pathfinder with current map */
	void reinit( GenericMap  * m );

	/** Precompute paths */
	void computePath( GenericCell * start );

	/** Return true if there is a path between 'start' and 'dest' */
	bool isPath( GenericCell * dest );

	int getDist( GenericCell * dest );

	/** Return true if there is a 'near path' between 'start' and 'dest' */
	bool isNearPath( GenericCell * dest );

	/** Return the 'near cell' */
	GenericCell * getNearCell( GenericCell * dest );

	/** Give next cell to go for dest */
	QPtrStack<GenericCell> * giveCells( GenericCell * dest );
	
	/** Give next near cell to go for dest */	
	QPtrStack<GenericCell> * giveNearCells( GenericCell * dest );
	
	/** Clear path */
	void clear();
	
	/** Change map */
	void newMap( int h, int w, GenericMap * m );

	GenericCell * getStartCell();
	
private:
	int _width, _height;	
	PathCell ** _table;
	PathCell * _start;
	
	void compute( Pile *, GenericCell *, PathCell *, int cost = 0 );
};

/*              ------------------------------
 *                         PathFightFinder
 *              ------------------------------ */



/** Find the shortest path from A to B on the map */
class PathFightFinder
{
 
public:
	/** Constructor */
	PathFightFinder( int w, int h, GenericFightMap * m );
	
	/** Destructor */
	~PathFightFinder();
	
        /** Reinit the pathfinder with current map */
	void reinit( GenericFightMap  * m );

	/** Precompute paths */
	void computePath( GenericFightCell * start );

	/** Give next cell to go for X, Y */
	QPtrStack<GenericFightCell> * giveCells( GenericFightCell * dest );
	
private:
	int _width, _height;	
	PathFightCell ** _table;
	PathFightCell * _start;
};
  
#endif // PATHFINDER_H