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 TRECISION_PATHFINDING_H
24 #define TRECISION_PATHFINDING_H
25 
26 #include "trecision/struct.h"
27 #include "common/serializer.h"
28 
29 namespace Trecision {
30 
31 struct SSortPan {
32 	int _num;
33 	float _min;
34 };
35 
36 struct SPathNode {
37 	float _x, _z;
38 	float _dist;
39 	int16 _oldPanel;
40 	int16 _curPanel;
41 
clearSPathNode42 	void clear() {
43 		_x = _z = 0.0f;
44 		_dist = 0.0f;
45 		_oldPanel = 0;
46 		_curPanel = 0;
47 	}
48 };
49 
50 struct SPan {
51 	float _x1, _z1;
52 	float _x2, _z2;
53 	float _h;
54 	int _flags;
55 	int16 _nearPanel1;
56 	int16 _nearPanel2;
57 	int8 _col1;
58 	int8 _col2;
59 
clearSPan60 	void clear() {
61 		_x1 = _z1 = 0.0f;
62 		_x2 = _z2 = 0.0f;
63 		_h = 0.0f;
64 		_flags = 0;
65 		_nearPanel1 = _nearPanel2 = 0;
66 		_col1 = _col2 = 0;
67 	}
68 };
69 
70 struct SStep {
71 	float _px, _pz;
72 	float _dx, _dz;
73 	float _theta;
74 	int _curAction;
75 	int _curFrame;
76 	int16 _curPanel;
77 
clearSStep78 	void clear() {
79 		_px = _pz = 0.0f;
80 		_dx = _dz = 0.0f;
81 		_theta = 0.0f;
82 		_curAction = 0;
83 		_curFrame = 0;
84 		_curPanel = 0;
85 	}
86 };
87 
88 class TrecisionEngine;
89 
90 class PathFinding3D {
91 	TrecisionEngine *_vm;
92 
93 	SPathNode _pathNode[MAXPATHNODES];
94 	float _invP[3][3];
95 	int _numPathNodes;
96 	float _x3d, _y3d, _z3d;
97 	float _curX, _curZ;
98 	float _lookX, _lookZ;
99 	int32 _panelNum;
100 	int16 _oldPanel;
101 	int _actorPos;
102 	int _forcedActorPos;
103 
104 	bool pointInside(int pan, float x, float z) const;
105 	void sortPanel();
106 	void pointOut();
107 	void invPointProject(int x, int y);
108 	bool intersectLinePanel(SPan *p, float x, float y, float z);
109 	bool intersectLineFloor(float x, float y, float z);
110 	bool intersectLineLine(float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd);
111 	void findShortPath();
112 	float evalPath(int a, float destX, float destZ, int nearP);
113 	void lookAt(float x, float z);
114 	void buildFramelist();
115 	void displayPath();
116 	bool findAttachedPanel(int16 srcPanel, int16 destPanel);
117 	void sortPath();
118 
119 public:
120 	PathFinding3D(TrecisionEngine *vm);
121 	~PathFinding3D();
122 
123 	int _curStep;
124 	int _lastStep;
125 	int16 _curPanel;
126 	int _numSortPanel;
127 
128 	int8 _characterGoToPosition;
129 	bool _characterInMovement;
130 	SSortPan _sortPan[32];
131 	SStep _step[MAXSTEP];
132 	SPan _panel[MAXPANELSINROOM];
133 
134 	void findPath();
135 	void setPosition(int num);
136 	void goToPosition(int num);
137 	int nextStep();
138 	void initSortPan();
139 	void read3D(Common::SeekableReadStreamEndian *ff);
140 	void reset(uint16 idx, float px, float pz, float theta);
141 	void whereIs(int px, int py);
142 	void actorOrder();
143 	void syncGameStream(Common::Serializer &ser);
getActorPos()144 	int getActorPos() const { return _actorPos; }
setForcedActorPos(int actorPos)145 	void setForcedActorPos(int actorPos) { _forcedActorPos = actorPos; }
146 };
147 
148 } // End of namespace Trecision
149 #endif
150 
151