aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlukaslw2014-07-14 03:26:17 +0200
committerlukaslw2014-07-14 03:26:17 +0200
commitb0c454fc9ba282f5f72a0c69a6b897e38eaddb82 (patch)
tree52c304d0d2036978354375c01a6aee4e507c9999
parent52dbd8866e418c4f0f7861216e14a70263822949 (diff)
downloadscummvm-rg350-b0c454fc9ba282f5f72a0c69a6b897e38eaddb82.tar.gz
scummvm-rg350-b0c454fc9ba282f5f72a0c69a6b897e38eaddb82.tar.bz2
scummvm-rg350-b0c454fc9ba282f5f72a0c69a6b897e38eaddb82.zip
PRINCE: Pathfinding - bug fixing, first correct path
-rw-r--r--engines/prince/hero.cpp16
-rw-r--r--engines/prince/hero.h17
-rw-r--r--engines/prince/prince.cpp101
-rw-r--r--engines/prince/prince.h6
-rw-r--r--engines/prince/script.cpp8
5 files changed, 91 insertions, 57 deletions
diff --git a/engines/prince/hero.cpp b/engines/prince/hero.cpp
index e91d6a971f..94c7b8b313 100644
--- a/engines/prince/hero.cpp
+++ b/engines/prince/hero.cpp
@@ -38,6 +38,7 @@ Hero::Hero(PrinceEngine *vm, GraphicsMan *graph) : _vm(vm), _graph(graph)
, _specAnim(0), _drawX(0), _drawY(0), _drawZ(0), _zoomFactor(0), _scaleValue(0)
, _shadZoomFactor(0), _shadScaleValue(0), _shadLineLen(0), _shadDrawX(0), _shadDrawY(0)
, _frameXSize(0), _frameYSize(0), _scaledFrameXSize(0), _scaledFrameYSize(0), _color(0)
+ , _coords(nullptr), _dirTab(nullptr), _currCoords(nullptr), _currDirTab(nullptr), _step(0)
{
_zoomBitmap = (byte *)malloc(kZoomBitmapLen);
_shadowBitmap = (byte *)malloc(2 * kShadowBitmapSize);
@@ -788,6 +789,21 @@ void Hero::scrollHero() {
_drawX -= destValue;
}
+void Hero::freeOldMove() {
+ if (_coords != nullptr) {
+ free(_coords);
+ _coords = nullptr;
+ }
+ if (_dirTab != nullptr) {
+ free(_dirTab);
+ _dirTab = nullptr;
+ }
+ _step = 0;
+ _phase = 0;
+ _moveDelay = 0;
+ _state = Hero::STAY;
+}
+
}
/* vim: set tabstop=4 noexpandtab: */
diff --git a/engines/prince/hero.h b/engines/prince/hero.h
index ae33419176..82b4ac7dd7 100644
--- a/engines/prince/hero.h
+++ b/engines/prince/hero.h
@@ -132,6 +132,7 @@ public:
void setShadowScale(int32 shadowScale);
void specialAnim();
void getState();
+ void freeOldMove();
//private:
PrinceEngine *_vm;
@@ -142,8 +143,6 @@ public:
int16 _state;
int16 _middleX; // middle of X
int16 _middleY; // lower part of hero
- int16 _lastDirection;
- int16 _destDirection;
int16 _moveSetType;
int8 _zoomFactor;
@@ -164,16 +163,16 @@ public:
int16 _shadDrawX;
int16 _shadDrawY;
- // Coords array of coordinates
- // DirTab array of directions
- // CurrCoords current coordinations
- // CurrDirTab current direction
- // LastDir previous move direction
- // DestDir
+ byte *_coords; // array of coordinates
+ byte *_dirTab; // array of directions
+ byte *_currCoords; // current coordinations
+ byte *_currDirTab; // current direction
+ int16 _lastDirection; // previous move direction
+ int16 _destDirection;
// LeftRight previous left/right direction
// UpDown previous up/down direction
int32 _phase; // Phase animation phase
- // Step x/y step size depends on direction
+ int16 _step; // Step x/y step size depends on direction
// MaxBoredom stand still timeout
int16 _boredomTime;// Boredom current boredom time in frames
uint16 _boreNum; // Bore anim frame
diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp
index d6b57a39ea..48ffc576a8 100644
--- a/engines/prince/prince.cpp
+++ b/engines/prince/prince.cpp
@@ -94,7 +94,7 @@ PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc)
_traceLineLen(0), _traceLineFlag(0), _rembBitmapTemp(nullptr), _rembBitmap(nullptr), _rembMask(0), _rembX(0), _rembY(0),
_checkBitmapTemp(nullptr), _checkBitmap(nullptr), _checkMask(0), _checkX(0), _checkY(0), _traceLineFirstPointFlag(false),
_coordsBuf2(nullptr), _coords2(nullptr), _coordsBuf3(nullptr), _coords3(nullptr),
- _tracePointFlag(0) {
+ _tracePointFlag(0), _shanLen1(0), _directionTable(nullptr) {
// Debug/console setup
DebugMan.addDebugChannel(DebugChannel::kScript, "script", "Prince Script debug channel");
@@ -2013,7 +2013,9 @@ void PrinceEngine::leftMouseButton() {
_optionsMob = _selectedMob;
if (_optionsMob == -1) {
// @@walkto - TODO
- if (_mainHero->_visible) { // second hero?
+ if (_mainHero->_visible) {
+ //freeHeroAnim();
+ _mainHero->freeOldMove();
_interpreter->storeNewPC(_script->_scriptInfo.usdCode);
int destX, destY;
if (_optionsMob != -1) {
@@ -2026,8 +2028,14 @@ void PrinceEngine::leftMouseButton() {
destY = mousePos.y;
_mainHero->_destDirection = 0; // second hero?
}
- if (makePath(destX, destY)) {
- // Shani movement
+ _mainHero->_coords = makePath(destX, destY);
+ if (_mainHero->_coords != nullptr) {
+ _mainHero->_currCoords = _mainHero->_coords;
+ _mainHero->_dirTab = _directionTable;
+ _mainHero->_currDirTab = _directionTable;
+ _directionTable = nullptr;
+ _mainHero->_state = _mainHero->MOVE;
+ moveShandria();
}
}
return;
@@ -2094,6 +2102,9 @@ void PrinceEngine::leftMouseButton() {
void PrinceEngine::rightMouseButton() {
if (_mouseFlag) {
+ _mainHero->freeOldMove();
+ _secondHero->freeOldMove();
+ _interpreter->storeNewPC(0);
if (_currentPointerNumber < 2) {
enableOptions();
} else {
@@ -3441,7 +3452,6 @@ int PrinceEngine::cpe() {
_checkBitmapTemp = _rembBitmapTemp;
_checkBitmap = _rembBitmap;
_checkMask = _rembMask;
- // add esp, 4 ??
return -1;
}
return 0;
@@ -3480,8 +3490,7 @@ int PrinceEngine::checkLeftDownDir() {
}
_checkX--;
_checkY++;
- cpe();
- return 0;
+ return cpe();
} else {
return -1;
}
@@ -3515,8 +3524,7 @@ int PrinceEngine::checkLeftDir() {
}
}
_checkX--;
- cpe();
- return 0;
+ return cpe();
} else {
return -1;
}
@@ -3529,8 +3537,7 @@ int PrinceEngine::checkDownDir() {
_checkBitmap += kPBW;
_checkBitmapTemp += kPBW;
_checkY++;
- cpe();
- return 0;
+ return cpe();
} else {
return 1;
}
@@ -3549,8 +3556,7 @@ int PrinceEngine::checkUpDir() {
_checkBitmap -= kPBW;
_checkBitmapTemp -= kPBW;
_checkY--;
- cpe();
- return 0;
+ return cpe();
} else {
return 1;
}
@@ -3590,8 +3596,7 @@ int PrinceEngine::checkRightDir() {
}
}
_checkX++;
- cpe();
- return 0;
+ return cpe();
} else {
return -1;
}
@@ -3628,8 +3633,7 @@ int PrinceEngine::checkLeftUpDir() {
}
_checkX--;
_checkY--;
- cpe();
- return 0;
+ return cpe();
} else {
return -1;
}
@@ -3666,8 +3670,7 @@ int PrinceEngine::checkRightDownDir() {
}
_checkX++;
_checkY++;
- cpe();
- return 0;
+ return cpe();
} else {
return -1;
}
@@ -3704,8 +3707,7 @@ int PrinceEngine::checkRightUpDir() {
}
_checkX++;
_checkY--;
- cpe();
- return 0;
+ return cpe();
} else {
return -1;
}
@@ -3933,7 +3935,17 @@ void PrinceEngine::approxPath() {
}
}
-int PrinceEngine::makePath(int destX, int destY) {
+// TODO
+void PrinceEngine::scanDirections() {
+
+}
+
+// TODO
+void PrinceEngine::moveShandria() {
+
+}
+
+byte *PrinceEngine::makePath(int destX, int destY) {
int realDestX = destX;
int realDestY = destY;
_flags->setFlagValue(Flags::MOVEDESTX, destX);
@@ -3963,7 +3975,7 @@ int PrinceEngine::makePath(int destX, int destY) {
//add esp,8
//byemovemove
//eax = -1
- return -1;
+ return nullptr;
}
}
// not_differs
@@ -4004,7 +4016,7 @@ int PrinceEngine::makePath(int destX, int destY) {
byte *choosenCoords = _coords2;
int choosenLength = pathLen1;
if (pathLen1 < pathLen2) {
- chosenCoordsBuf = _coordsBuf2;
+ chosenCoordsBuf = _coordsBuf3;
choosenCoords = _coords3;
choosenLength = pathLen2;
}
@@ -4035,10 +4047,10 @@ int PrinceEngine::makePath(int destX, int destY) {
_coords = _coordsBuf + sizeChoosen;
}
//done_back
- WRITE_UINT32(_coords, -1);
+ WRITE_UINT32(_coords, 0xFFFFFFFF);
freeCoords2();
freeCoords3();
- //scanDirections();
+ scanDirections();
// normal values:
byte *tempCoordsBuf = _coordsBuf; // esi
@@ -4063,12 +4075,11 @@ int PrinceEngine::makePath(int destX, int destY) {
//copy_coords_done:
WRITE_UINT16(newCoords - 4, realDestX);
WRITE_UINT16(newCoords - 2, realDestY);
- WRITE_UINT32(newCoords, -1);
+ WRITE_UINT32(newCoords, 0xFFFFFFFF);
newCoords += 4;
- int shanLen1 = (newCoords - newCoordsBegin); // to global?
- // shr shanLen1, 2 ?
- //return newCoordsBegin;
- return 0;
+ _shanLen1 = (newCoords - newCoordsBegin);
+ //_shanLen1 /= 4 ?
+ return newCoordsBegin; // free memory!
}
}
}
@@ -4077,13 +4088,12 @@ int PrinceEngine::makePath(int destX, int destY) {
_coordsBuf = nullptr;
freeCoords2();
freeCoords3();
- return -1;
+ return nullptr;
} else {
//byemove
- //freeOldMove();
+ _mainHero->freeOldMove();
_mainHero->_state = _mainHero->TURN;
- // eax = -1
- return -1;
+ return nullptr;
}
}
@@ -4105,16 +4115,19 @@ void PrinceEngine::freeCoords3() {
}
void PrinceEngine::testDrawPath() {
- /*
- byte *tempCoords = _coords;
- while (tempCoords != _coordsBuf) {
- int x = READ_UINT16(tempCoords - 2);
- int y = READ_UINT16(tempCoords - 4);
- tempCoords -= 4;
- debug("x: %d, y: %d", x, y);
- _graph->drawPixel(_graph->_frontScreen, x, y);
+ byte *tempCoords = _mainHero->_coords;
+ if (tempCoords != nullptr) {
+ while (1) {
+ int flag = READ_UINT32(tempCoords);
+ if (flag == 0xFFFFFFFF) {
+ break;
+ }
+ int x = READ_UINT16(tempCoords);
+ int y = READ_UINT16(tempCoords + 2);
+ tempCoords += 4;
+ _graph->drawPixel(_graph->_frontScreen, x, y);
+ }
}
- */
}
void PrinceEngine::mainLoop() {
diff --git a/engines/prince/prince.h b/engines/prince/prince.h
index 5dffaf6f73..89c24ec0a5 100644
--- a/engines/prince/prince.h
+++ b/engines/prince/prince.h
@@ -460,6 +460,8 @@ public:
int _traceLineFlag; // return value of plotTraceLine
bool _traceLineFirstPointFlag; // if plotTraceLine after first point
int _tracePointFlag; // return value of plotTracePoint
+ byte *_directionTable;
+ int _shanLen1;
byte *_checkBitmapTemp; //esi
byte *_checkBitmap; // ebp
@@ -481,7 +483,7 @@ public:
} _fpResult;
bool loadPath(const char *resourceName);
- int makePath(int destX, int destY);
+ byte *makePath(int destX, int destY);
void findPoint(int x1, int y1, int x2, int y2);
int fpGetPixelAddr(int x, int y);
int fpGetPixel(int x, int y);
@@ -498,6 +500,8 @@ public:
static void plotTracePoint(int x, int y, int color, void *data);
void specialPlotInside2(int x, int y);
void approxPath();
+ void scanDirections();
+ void moveShandria();
void testDrawPath();
diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp
index 36cd991bfd..14fae2b42f 100644
--- a/engines/prince/script.cpp
+++ b/engines/prince/script.cpp
@@ -1588,10 +1588,12 @@ void Interpreter::O_SETFGCODE() {
void Interpreter::O_STOPHERO() {
uint16 heroId = readScriptFlagValue();
-
+ if (!heroId) {
+ _vm->_mainHero->freeOldMove();
+ } else if (heroId == 1) {
+ _vm->_secondHero->freeOldMove();
+ }
debugInterpreter("O_STOPHERO heroId %d", heroId);
-
- // clear move steps for hero
}
void Interpreter::O_ANIMUPDATEOFF() {