aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/math/walkregion.h
blob: 25ded2ff4b430e1da9139473155c4d1dec1f1760 (plain)
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
// -----------------------------------------------------------------------------
// This file is part of Broken Sword 2.5
// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsd�rfer
//
// Broken Sword 2.5 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 of the License, or
// (at your option) any later version.
//
// Broken Sword 2.5 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 Broken Sword 2.5; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// -----------------------------------------------------------------------------

#ifndef SWORD25_WALKREGION_H
#define SWORD25_WALKREGION_H

#include "sword25/kernel/memlog_off.h"
#include <vector>
#include "sword25/kernel/memlog_on.h"

#include "sword25/kernel/common.h"
#include "sword25/math/region.h"

// -----------------------------------------------------------------------------
// Typdefinitionen
// -----------------------------------------------------------------------------

typedef std::vector<BS_Vertex> BS_Path;

// -----------------------------------------------------------------------------
// Klassendefinition
// -----------------------------------------------------------------------------

/**
	@brief Diese Klasse stellt die Region dar, in der sich der Hauptcharakter bewegen kann.
*/
class BS_WalkRegion : public BS_Region
{
	friend class BS_Region;

protected:
	BS_WalkRegion();
	BS_WalkRegion(BS_InputPersistenceBlock & Reader, unsigned int Handle);

public:
	virtual ~BS_WalkRegion();

	virtual bool Init(const BS_Polygon & Contour, const std::vector<BS_Polygon> * pHoles = 0);

	/**
		@brief Ermittelt den k�rzesten Weg zwischen zwei Punkten in der Region.

		Diese Methode verlangt, dass der Startpunkt innerhalb der Region liegt. Der Endpunkt darf au�erhalb der Region liegen. In diesem
		Fall w�hlt die Methode als Endpunkt den Punkt innerhalb der Region, der am dichtesten am Endpunkt liegt.

		@param X1 X-Koordinate des Startpunktes
		@param Y1 Y-Koordinate des Startpunktes
		@param X2 X-Koordinate des Zielpunktes
		@param Y2 Y-Koordinate des Zielpunktes
		@param Path ein leerer BS_Path, der den Ergebnispfad aufnehmen soll
		@return Gibt false zur�ck, fall die Eingaben ung�ltig waren, ansonsten wird true zur�ckgegeben.
	 */
	bool QueryPath(int X1, int Y1, int X2, int Y2, BS_Path & Path) { return QueryPath(BS_Vertex(X1, Y1), BS_Vertex(X2, Y2), Path); }

	/**
		@brief Ermittelt den k�rzesten Weg zwischen zwei Punkten in der Region.

		Diese Methode verlangt, dass der Startpunkt innerhalb der Region liegt. Der Endpunkt darf au�erhalb der Region liegen. In diesem
		Fall w�hlt die Methode als Endpunkt den Punkt innerhalb der Region, der am dichtesten am Endpunkt liegt.
		
		@param StartPoint der Startpunkt
		@param EndPoint der Endpunkt
		@param Path ein leerer BS_Path, der den Ergebnispfad aufnehmen soll
		@return Gibt false zur�ck, fall die Eingaben ung�ltig waren, ansonsten wird true zur�ckgegeben.
	*/
	bool QueryPath(BS_Vertex StartPoint, BS_Vertex EndPoint, BS_Path & Path);

	virtual void SetPos(int X, int Y);

	const std::vector<BS_Vertex> & GetNodes() const { return m_Nodes; }
	const std::vector< std::vector<int> > & GetVisibilityMatrix() const { return m_VisibilityMatrix; }

	virtual bool Persist(BS_OutputPersistenceBlock & Writer);
	virtual bool Unpersist(BS_InputPersistenceBlock & Reader);

private:
	std::vector<BS_Vertex> m_Nodes;
	std::vector< std::vector<int> > m_VisibilityMatrix;

	void InitNodeVector();
	void ComputeVisibilityMatrix();
	bool CheckAndPrepareStartAndEnd(BS_Vertex & Start, BS_Vertex & End) const;
	bool FindPath(const BS_Vertex & Start, const BS_Vertex & End, BS_Path & Path) const;
};

#endif