2021-05-01 22:05:36 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2021-05-01 22:05:36 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2021-05-01 22:05:36 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-06-08 23:52:21 +00:00
|
|
|
#ifndef TRECISION_PATHFINDING_H
|
|
|
|
#define TRECISION_PATHFINDING_H
|
2021-05-01 22:30:38 +00:00
|
|
|
|
2021-05-16 21:48:56 +00:00
|
|
|
#include "trecision/struct.h"
|
|
|
|
#include "common/serializer.h"
|
2021-05-01 22:05:36 +00:00
|
|
|
|
|
|
|
namespace Trecision {
|
2021-05-25 06:47:05 +00:00
|
|
|
|
2021-05-10 23:21:41 +00:00
|
|
|
struct SSortPan {
|
|
|
|
int _num;
|
|
|
|
float _min;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SPathNode {
|
|
|
|
float _x, _z;
|
|
|
|
float _dist;
|
|
|
|
int16 _oldPanel;
|
|
|
|
int16 _curPanel;
|
2021-05-11 23:58:07 +00:00
|
|
|
|
|
|
|
void clear() {
|
|
|
|
_x = _z = 0.0f;
|
|
|
|
_dist = 0.0f;
|
|
|
|
_oldPanel = 0;
|
|
|
|
_curPanel = 0;
|
|
|
|
}
|
2021-05-10 23:21:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SPan {
|
|
|
|
float _x1, _z1;
|
|
|
|
float _x2, _z2;
|
|
|
|
float _h;
|
|
|
|
int _flags;
|
2021-05-23 12:34:27 +00:00
|
|
|
int16 _nearPanel1;
|
|
|
|
int16 _nearPanel2;
|
|
|
|
int8 _col1;
|
|
|
|
int8 _col2;
|
2021-05-11 23:58:07 +00:00
|
|
|
|
|
|
|
void clear() {
|
|
|
|
_x1 = _z1 = 0.0f;
|
|
|
|
_x2 = _z2 = 0.0f;
|
|
|
|
_h = 0.0f;
|
|
|
|
_flags = 0;
|
2021-05-23 12:34:27 +00:00
|
|
|
_nearPanel1 = _nearPanel2 = 0;
|
2021-05-11 23:58:07 +00:00
|
|
|
_col1 = _col2 = 0;
|
|
|
|
}
|
2021-05-10 23:21:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SStep {
|
|
|
|
float _px, _pz;
|
|
|
|
float _dx, _dz;
|
|
|
|
float _theta;
|
|
|
|
int _curAction;
|
|
|
|
int _curFrame;
|
|
|
|
int16 _curPanel;
|
2021-05-11 23:58:07 +00:00
|
|
|
|
|
|
|
void clear() {
|
|
|
|
_px = _pz = 0.0f;
|
|
|
|
_dx = _dz = 0.0f;
|
|
|
|
_theta = 0.0f;
|
|
|
|
_curAction = 0;
|
|
|
|
_curFrame = 0;
|
|
|
|
_curPanel = 0;
|
|
|
|
}
|
2021-05-10 23:21:41 +00:00
|
|
|
};
|
2021-05-01 22:05:36 +00:00
|
|
|
|
2021-06-08 23:52:21 +00:00
|
|
|
class TrecisionEngine;
|
2021-05-03 19:33:23 +00:00
|
|
|
|
|
|
|
class PathFinding3D {
|
|
|
|
TrecisionEngine *_vm;
|
|
|
|
|
2021-05-09 21:11:31 +00:00
|
|
|
SPathNode _pathNode[MAXPATHNODES];
|
2021-05-14 20:07:27 +00:00
|
|
|
float _invP[3][3];
|
|
|
|
int _numPathNodes;
|
|
|
|
float _x3d, _y3d, _z3d;
|
|
|
|
float _curX, _curZ;
|
|
|
|
float _lookX, _lookZ;
|
2021-05-23 12:34:27 +00:00
|
|
|
int32 _panelNum;
|
|
|
|
int16 _oldPanel;
|
2021-06-09 23:06:32 +00:00
|
|
|
int _actorPos;
|
|
|
|
int _forcedActorPos;
|
2021-05-14 20:07:27 +00:00
|
|
|
|
2021-05-20 22:15:46 +00:00
|
|
|
bool pointInside(int pan, float x, float z) const;
|
2021-05-09 21:11:31 +00:00
|
|
|
void sortPanel();
|
|
|
|
void pointOut();
|
|
|
|
void invPointProject(int x, int y);
|
|
|
|
bool intersectLinePanel(SPan *p, float x, float y, float z);
|
|
|
|
bool intersectLineFloor(float x, float y, float z);
|
|
|
|
bool intersectLineLine(float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd);
|
2021-05-14 20:07:27 +00:00
|
|
|
void findShortPath();
|
|
|
|
float evalPath(int a, float destX, float destZ, int nearP);
|
|
|
|
void lookAt(float x, float z);
|
|
|
|
void buildFramelist();
|
|
|
|
void displayPath();
|
2021-05-23 12:34:27 +00:00
|
|
|
bool findAttachedPanel(int16 srcPanel, int16 destPanel);
|
2021-05-14 20:07:27 +00:00
|
|
|
void sortPath();
|
2021-05-09 22:19:02 +00:00
|
|
|
|
2021-05-03 19:33:23 +00:00
|
|
|
public:
|
|
|
|
PathFinding3D(TrecisionEngine *vm);
|
|
|
|
~PathFinding3D();
|
|
|
|
|
|
|
|
int _curStep;
|
|
|
|
int _lastStep;
|
2021-05-23 12:34:27 +00:00
|
|
|
int16 _curPanel;
|
2021-05-14 20:07:27 +00:00
|
|
|
int _numSortPanel;
|
2021-05-03 19:33:23 +00:00
|
|
|
|
|
|
|
int8 _characterGoToPosition;
|
|
|
|
bool _characterInMovement;
|
|
|
|
SSortPan _sortPan[32];
|
|
|
|
SStep _step[MAXSTEP];
|
|
|
|
SPan _panel[MAXPANELSINROOM];
|
|
|
|
|
|
|
|
void findPath();
|
|
|
|
void setPosition(int num);
|
|
|
|
void goToPosition(int num);
|
|
|
|
int nextStep();
|
|
|
|
void initSortPan();
|
2021-05-31 04:05:49 +00:00
|
|
|
void read3D(Common::SeekableReadStreamEndian *ff);
|
2021-05-09 17:55:25 +00:00
|
|
|
void reset(uint16 idx, float px, float pz, float theta);
|
2021-05-09 21:11:31 +00:00
|
|
|
void whereIs(int px, int py);
|
|
|
|
void actorOrder();
|
2021-05-14 20:07:27 +00:00
|
|
|
void syncGameStream(Common::Serializer &ser);
|
2021-06-09 23:06:32 +00:00
|
|
|
int getActorPos() const { return _actorPos; }
|
|
|
|
void setForcedActorPos(int actorPos) { _forcedActorPos = actorPos; }
|
2021-05-15 19:06:24 +00:00
|
|
|
};
|
2021-05-01 22:05:36 +00:00
|
|
|
|
2021-05-15 19:06:24 +00:00
|
|
|
} // End of namespace Trecision
|
2021-05-01 22:05:36 +00:00
|
|
|
#endif
|
|
|
|
|