Skip to content

Commit

Permalink
PRINCE: Pathfinding progress
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Jul 10, 2014
1 parent 1b1238d commit b711899
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 30 deletions.
24 changes: 12 additions & 12 deletions engines/prince/common.h
Expand Up @@ -26,18 +26,18 @@
namespace Prince {

enum Direction {
LD = 0,
L = 1,
LG = 2,
PD = 3,
P = 4,
PG = 5,
GL = 6,
G = 7,
GP = 8,
DL = 9,
D = 10,
DP = 11
kDirLD = 0,
kDirL = 1,
kDirLU = 2,
kDirRD = 3,
kDirR = 4,
kDirRU = 5,
kDirUL = 6,
kDirU = 7,
kDirUR = 8,
kDirDL = 9,
kDirD = 10,
kDirDR = 11
};

}
Expand Down
134 changes: 116 additions & 18 deletions engines/prince/prince.cpp
Expand Up @@ -89,8 +89,8 @@ PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc)
_invOptionsStep(20), _optionsNumber(7), _invOptionsNumber(5), _optionsColor1(236), _optionsColor2(252),
_dialogWidth(600), _dialogHeight(0), _dialogLineSpace(10), _dialogColor1(220), _dialogColor2(223),
_dialogFlag(false), _dialogLines(0), _dialogText(nullptr), _mouseFlag(1),
_roomPathBitmap(nullptr), _destX(0), _destY(0), _destX2(0), _destY2(0), _fpFlag(0), _fpX(0), _fpY(0),
_fpX1(0), _fpY1(0) {
_roomPathBitmap(nullptr), _roomPathBitmapTemp(nullptr), _destX(0), _destY(0), _destX2(0), _destY2(0),
_fpFlag(0), _fpX(0), _fpY(0), _fpX1(0), _fpY1(0) {

// Debug/console setup
DebugMan.addDebugChannel(DebugChannel::kScript, "script", "Prince Script debug channel");
Expand Down Expand Up @@ -176,6 +176,7 @@ PrinceEngine::~PrinceEngine() {
delete _secondHero;

free(_roomPathBitmap);
free(_roomPathBitmapTemp);
}

GUI::Debugger *PrinceEngine::getDebugger() {
Expand Down Expand Up @@ -296,6 +297,7 @@ void PrinceEngine::init() {
_secondHero->loadAnimSet(3);

_roomPathBitmap = (byte *)malloc(kPathBitmapLen);
_roomPathBitmapTemp = (byte *)malloc(kPathBitmapLen);

BackgroundAnim tempBackAnim;
tempBackAnim._seq._currRelative = 0;
Expand Down Expand Up @@ -2714,10 +2716,10 @@ void PrinceEngine::findPoint(int x1, int y1, int x2, int y2) {
_fpFlag = 1;
if (fpGetPixelAddr(_destX2, _destY2)) {
//bye
//eax = _destX;
//ebx = _destY;
//ecx = _destX2;
//edx = _destY2;
_fpResult.x1 = _destX;
_fpResult.y1 = _destY;
_fpResult.x2 = _destX2;
_fpResult.y2 = _destY2;
return;
}
}
Expand Down Expand Up @@ -2802,33 +2804,129 @@ void PrinceEngine::findPoint(int x1, int y1, int x2, int y2) {
}
}
//bye
//eax = _destX;
//ebx = _destY;
//ecx = _destX2;
//edx = _destY2;
_fpResult.x1 = _destX;
_fpResult.y1 = _destY;
_fpResult.x2 = _destX2;
_fpResult.y2 = _destY2;
return;
}
}

Direction PrinceEngine::makeDirection(int x1, int y1, int x2, int y2) {
if (x1 != x2) {
if (y1 != y2) {
if (x1 > x2) {
if (y1 > y2) {
if (x1 - x2 >= y1 - y2) {
return kDirLU;
} else {
return kDirUL;
}
} else {
if (x1 - x2 >= y2 - y1) {
return kDirLD;
} else {
return kDirDL;
}
}
} else {
if (y1 > y2) {
if (x2 - x1 >= y1 - y2) {
return kDirRU;
} else {
return kDirUR;
}
} else {
if (x2 - x1 >= y2 - y1) {
return kDirRD;
} else {
return kDirDR;
}
}
}
} else {
if (x1 >= x2) {
return kDirL;
} else {
return kDirR;
}
}
} else {
if (y1 >= y2) {
return kDirU;
} else {
return kDirD;
}
}
}

int PrinceEngine::tracePath(int x1, int y1, int x2, int y2) {
for (int i = 0; i < kPathBitmapLen; i++) {
_roomPathBitmapTemp[i] = 0;
}
//pop ecx eax
//mov edi,o CoordsBuf
//mov d Coords,edi
if (x1 != x2 || y1 != y2) {
//not_same
_destX = x1;
_destY = y1;
_destX2 = x2;
_destY2 = y2;
makeDirection(x1, y1, x2, y2);
return 0;
} else {
//error1:
return 1;
}
}

void PrinceEngine::makePath(int destX, int destY) {
int pathLen1 = 0; // global?
int pathLen2 = 0; // global?
int stX = 0; // global?
int stY = 0; // global?

int realDestX = destX;
int realDestY = destY;
int realDestX = destX; // global?
int realDestY = destY; // global?
_flags->setFlagValue(Flags::MOVEDESTX, destX);
_flags->setFlagValue(Flags::MOVEDESTY, destY);

int ebp = -2;
int currX = _mainHero->_middleX; // second hero
int currY = _mainHero->_middleY;

int eax = currX / 2;
int ebx = currY / 2;
int ecx = destX / 2;
int edx = destY / 2;
int x1 = currX / 2;
int y1 = currY / 2;
int x2 = destX / 2;
int y2 = destY / 2;

if ((currX / 2 != destX / 2) && (currY / 2 != destY / 2)) {
if ((x1 != x2) && (y1 != y2)) {
//not_just_turn
findPoint(currX / 2, currY / 2, destX / 2, destY / 2);
findPoint(x1, y1, x2, y2);
if (x2 != _fpResult.x1 || y2 != _fpResult.y1) {
// differs
if (!_flags->getFlagValue(Flags::EXACTMOVE)) {
realDestX = destX;
realDestY = destY;
_flags->setFlagValue(Flags::MOVEDESTX, destX);
_flags->setFlagValue(Flags::MOVEDESTY, destY);
} else {
//byemove2
//add esp,8
//byemovemove
//eax = -1
return;
}
}
// not_differs
pathLen1 = 0;
pathLen2 = 0;
stX = x1; // stXY
stY = y1; // stXY + 2

tracePath(x1, y1, x2, y2);

} else {
//byemove
//freeOldMove();
Expand Down
12 changes: 12 additions & 0 deletions engines/prince/prince.h
Expand Up @@ -435,6 +435,7 @@ class PrinceEngine : public Engine {
static const int16 kPathGridStep = 2;
static const int32 kPathBitmapLen = (kMaxPicHeight / kPathGridStep * kMaxPicWidth / kPathGridStep) / 8;
byte *_roomPathBitmap; // PL - Sala
byte *_roomPathBitmapTemp; // PL -SSala

int _destX;
int _destY;
Expand All @@ -445,12 +446,23 @@ class PrinceEngine : public Engine {
int _fpY;
int _fpX1;
int _fpY1;
Direction _direction;

struct fpResult {
int x1;
int y1;
int x2;
int y2;
} _fpResult;

bool loadPath(const char *resourceName);
void makePath(int destX, int destY);
void findPoint(int x1, int y1, int x2, int y2);
bool fpGetPixelAddr(int x, int y);
bool fpGetPixel(int x, int y);
int tracePath(int x1, int y1, int x2, int y2);
Direction makeDirection(int x1, int y1, int x2, int y2);
void approxPath();

int testAnimNr;
int testAnimFrame;
Expand Down

0 comments on commit b711899

Please sign in to comment.