aboutsummaryrefslogtreecommitdiff
path: root/engines/dreamweb/pathfind.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/dreamweb/pathfind.cpp')
-rw-r--r--engines/dreamweb/pathfind.cpp232
1 files changed, 126 insertions, 106 deletions
diff --git a/engines/dreamweb/pathfind.cpp b/engines/dreamweb/pathfind.cpp
index f6591d4666..c39070532c 100644
--- a/engines/dreamweb/pathfind.cpp
+++ b/engines/dreamweb/pathfind.cpp
@@ -22,151 +22,128 @@
#include "dreamweb/dreamweb.h"
-namespace DreamGen {
+namespace DreamWeb {
-void DreamGenContext::turnPathOn() {
- turnPathOn(al);
-}
-
-void DreamGenContext::turnPathOn(uint8 param) {
- findOrMake(param, 0xff, data.byte(kRoomnum) + 100);
+void DreamWebEngine::turnPathOn(uint8 param) {
+ findOrMake(param, 0xff, _roomNum + 100);
PathNode *roomsPaths = getRoomsPaths()->nodes;
if (param == 0xff)
return;
roomsPaths[param].on = 0xff;
}
-void DreamGenContext::turnPathOff() {
- turnPathOff(al);
-}
-
-void DreamGenContext::turnPathOff(uint8 param) {
- findOrMake(param, 0x00, data.byte(kRoomnum) + 100);
+void DreamWebEngine::turnPathOff(uint8 param) {
+ findOrMake(param, 0x00, _roomNum + 100);
PathNode *roomsPaths = getRoomsPaths()->nodes;
if (param == 0xff)
return;
roomsPaths[param].on = 0x00;
}
-void DreamGenContext::turnAnyPathOn(uint8 param, uint8 room) {
+void DreamWebEngine::turnAnyPathOn(uint8 param, uint8 room) {
findOrMake(param, 0xff, room + 100);
- PathNode *paths = (PathNode *)getSegment(data.word(kReels)).ptr(kPathdata + 144 * room, 0);
- paths[param].on = 0xff;
+ _pathData[room].nodes[param].on = 0xff;
}
-void DreamGenContext::turnAnyPathOn() {
- turnAnyPathOn(al, ah);
-}
-
-void DreamGenContext::turnAnyPathOff(uint8 param, uint8 room) {
+void DreamWebEngine::turnAnyPathOff(uint8 param, uint8 room) {
findOrMake(param, 0x00, room + 100);
- PathNode *paths = (PathNode *)getSegment(data.word(kReels)).ptr(kPathdata + 144 * room, 0);
- paths[param].on = 0x00;
-}
-
-void DreamGenContext::turnAnyPathOff() {
- turnAnyPathOff(al, ah);
+ _pathData[room].nodes[param].on = 0x00;
}
-RoomPaths *DreamBase::getRoomsPaths() {
- void *result = getSegment(data.word(kReels)).ptr(data.byte(kRoomnum) * 144, 144);
- return (RoomPaths *)result;
+RoomPaths *DreamWebEngine::getRoomsPaths() {
+ return &_pathData[_roomNum];
}
-void DreamBase::faceRightWay() {
+void DreamWebEngine::faceRightWay() {
PathNode *paths = getRoomsPaths()->nodes;
- uint8 dir = paths[data.byte(kManspath)].dir;
- data.byte(kTurntoface) = dir;
- data.byte(kLeavedirection) = dir;
+ uint8 dir = paths[_mansPath].dir;
+ _turnToFace = dir;
+ _leaveDirection = dir;
}
-void DreamBase::setWalk() {
- if (data.byte(kLinepointer) != 254) {
+void DreamWebEngine::setWalk() {
+ if (_linePointer != 254) {
// Already walking
- data.byte(kFinaldest) = data.byte(kPointerspath);
- } else if (data.byte(kPointerspath) == data.byte(kManspath)) {
+ _finalDest = _pointersPath;
+ } else if (_pointersPath == _mansPath) {
// Can't walk
faceRightWay();
- } else if (data.byte(kWatchmode) == 1) {
+ } else if (_vars._watchMode == 1) {
// Holding reel
- data.byte(kDestafterhold) = data.byte(kPointerspath);
- data.byte(kWatchmode) = 2;
- } else if (data.byte(kWatchmode) == 2) {
+ _vars._destAfterHold = _pointersPath;
+ _vars._watchMode = 2;
+ } else if (_vars._watchMode == 2) {
// Can't walk
} else {
- data.byte(kDestination) = data.byte(kPointerspath);
- data.byte(kFinaldest) = data.byte(kPointerspath);
- if (data.word(kMousebutton) != 2 || data.word(kCommandtype) == 3) {
+ _destination = _pointersPath;
+ _finalDest = _pointersPath;
+ if (_mouseButton != 2 || _commandType == 3) {
autoSetWalk();
} else {
- data.byte(kWalkandexam) = 1;
- data.byte(kWalkexamtype) = data.byte(kCommandtype);
- data.byte(kWalkexamnum) = data.byte(kCommand);
+ _walkAndExam = 1;
+ _walkExamType = _commandType;
+ _walkExamNum = _command;
autoSetWalk();
}
}
}
-void DreamBase::autoSetWalk() {
- if (data.byte(kFinaldest) == data.byte(kManspath))
+void DreamWebEngine::autoSetWalk() {
+ if (_finalDest == _mansPath)
return;
const RoomPaths *roomsPaths = getRoomsPaths();
checkDest(roomsPaths);
- data.word(kLinestartx) = roomsPaths->nodes[data.byte(kManspath)].x - 12;
- data.word(kLinestarty) = roomsPaths->nodes[data.byte(kManspath)].y - 12;
- data.word(kLineendx) = roomsPaths->nodes[data.byte(kDestination)].x - 12;
- data.word(kLineendy) = roomsPaths->nodes[data.byte(kDestination)].y - 12;
+ _lineStartX = roomsPaths->nodes[_mansPath].x - 12;
+ _lineStartY = roomsPaths->nodes[_mansPath].y - 12;
+ _lineEndX = roomsPaths->nodes[_destination].x - 12;
+ _lineEndY = roomsPaths->nodes[_destination].y - 12;
bresenhams();
- if (data.byte(kLinedirection) != 0) {
- data.byte(kLinepointer) = data.byte(kLinelength) - 1;
- data.byte(kLinedirection) = 1;
+ if (_lineDirection != 0) {
+ _linePointer = _lineLength - 1;
+ _lineDirection = 1;
return;
}
- data.byte(kLinepointer) = 0;
+ _linePointer = 0;
}
-void DreamBase::checkDest(const RoomPaths *roomsPaths) {
+void DreamWebEngine::checkDest(const RoomPaths *roomsPaths) {
const PathSegment *segments = roomsPaths->segments;
- const uint8 tmp = data.byte(kManspath) << 4;
- uint8 destination = data.byte(kDestination);
+ const uint8 tmp = _mansPath << 4;
+ uint8 destination = _destination;
for (size_t i = 0; i < 24; ++i) {
if ((segments[i].b0 & 0xf0) == tmp &&
- (segments[i].b0 & 0x0f) == data.byte(kDestination)) {
- data.byte(kDestination) = segments[i].b1 & 0x0f;
+ (segments[i].b0 & 0x0f) == _destination) {
+ _destination = segments[i].b1 & 0x0f;
return;
}
if (((segments[i].b0 & 0x0f) << 4) == tmp &&
- ((segments[i].b0 & 0xf0) >> 4) == data.byte(kDestination)) {
+ ((segments[i].b0 & 0xf0) >> 4) == _destination) {
destination = segments[i].b1 & 0x0f;
}
}
- data.byte(kDestination) = destination;
+ _destination = destination;
}
-void DreamBase::findXYFromPath() {
+void DreamWebEngine::findXYFromPath() {
const PathNode *roomsPaths = getRoomsPaths()->nodes;
- data.byte(kRyanx) = roomsPaths[data.byte(kManspath)].x - 12;
- data.byte(kRyany) = roomsPaths[data.byte(kManspath)].y - 12;
-}
-
-void DreamGenContext::checkIfPathIsOn() {
- flags._z = checkIfPathIsOn(al);
+ _ryanX = roomsPaths[_mansPath].x - 12;
+ _ryanY = roomsPaths[_mansPath].y - 12;
}
-bool DreamGenContext::checkIfPathIsOn(uint8 index) {
+bool DreamWebEngine::checkIfPathIsOn(uint8 index) {
RoomPaths *roomsPaths = getRoomsPaths();
uint8 pathOn = roomsPaths->nodes[index].on;
return pathOn == 0xff;
}
-void DreamBase::bresenhams() {
+void DreamWebEngine::bresenhams() {
workoutFrames();
Common::Point *lineData = &_lineData[0];
- int16 startX = (int16)data.word(kLinestartx);
- int16 startY = (int16)data.word(kLinestarty);
- int16 endX = (int16)data.word(kLineendx);
- int16 endY = (int16)data.word(kLineendy);
+ int16 startX = (int16)_lineStartX;
+ int16 startY = (int16)_lineStartY;
+ int16 endX = (int16)_lineEndX;
+ int16 endY = (int16)_lineEndY;
if (endX == startX) {
uint16 deltaY;
@@ -174,15 +151,15 @@ void DreamBase::bresenhams() {
if (endY < startY) {
deltaY = startY - endY;
y = (int8)endY;
- data.byte(kLinedirection) = 1;
+ _lineDirection = 1;
} else {
deltaY = endY - startY;
y = (int8)startY;
- data.byte(kLinedirection) = 0;
+ _lineDirection = 0;
}
++deltaY;
int8 x = (int8)startX;
- data.byte(kLinelength) = deltaY;
+ _lineLength = deltaY;
for (; deltaY; --deltaY) {
lineData->x = x;
lineData->y = y;
@@ -196,14 +173,14 @@ void DreamBase::bresenhams() {
deltaX = startX - endX;
SWAP(startX, endX);
SWAP(startY, endY);
- data.word(kLinestartx) = (uint16)startX;
- data.word(kLinestarty) = (uint16)startY;
- data.word(kLineendx) = (uint16)endX;
- data.word(kLineendy) = (uint16)endY;
- data.byte(kLinedirection) = 1;
+ _lineStartX = (uint16)startX;
+ _lineStartY = (uint16)startY;
+ _lineEndX = (uint16)endX;
+ _lineEndY = (uint16)endY;
+ _lineDirection = 1;
} else {
deltaX = endX - startX;
- data.byte(kLinedirection) = 0;
+ _lineDirection = 0;
}
int16 increment;
@@ -211,7 +188,7 @@ void DreamBase::bresenhams() {
int8 x = (int8)startX;
int8 y = (int8)startY;
++deltaX;
- data.byte(kLinelength) = deltaX;
+ _lineLength = deltaX;
for (; deltaX; --deltaX) {
lineData->x = x;
lineData->y = y;
@@ -230,33 +207,35 @@ void DreamBase::bresenhams() {
}
uint16 delta1, delta2;
+ byte lineRoutine;
+
if (deltaY > deltaX) {
- data.byte(kLineroutine) = 1;
+ lineRoutine = 1;
delta1 = deltaY;
delta2 = deltaX;
} else {
- data.byte(kLineroutine) = 0;
+ lineRoutine = 0;
delta1 = deltaX;
delta2 = deltaY;
}
- data.word(kIncrement1) = delta2 * 2;
+ uint16 increment1 = delta2 * 2;
+ uint16 increment2 = delta2 * 2 - delta1 * 2;
int16 remainder = delta2 * 2 - delta1;
- data.word(kIncrement2) = delta2 * 2 - delta1 * 2;
++delta1;
int8 x = (int8)startX;
int8 y = (int8)startY;
- data.byte(kLinelength) = delta1;
- if (data.byte(kLineroutine) != 1) {
+ _lineLength = delta1;
+ if (lineRoutine != 1) {
for (; delta1; --delta1) {
lineData->x = x;
lineData->y = y;
++lineData;
++x;
if (remainder < 0) {
- remainder += data.word(kIncrement1);
+ remainder += increment1;
} else {
- remainder += data.word(kIncrement2);
+ remainder += increment2;
y += increment;
}
}
@@ -267,25 +246,25 @@ void DreamBase::bresenhams() {
++lineData;
y += increment;
if (remainder < 0) {
- remainder += data.word(kIncrement1);
+ remainder += increment1;
} else {
- remainder += data.word(kIncrement2);
+ remainder += increment2;
++x;
}
}
}
}
-void DreamBase::workoutFrames() {
+void DreamWebEngine::workoutFrames() {
byte tmp;
int diffx, diffy;
// We have to use signed arithmetic here because these values can
// be slightly negative when walking off-screen
- int lineStartX = (int16)data.word(kLinestartx);
- int lineStartY = (int16)data.word(kLinestarty);
- int lineEndX = (int16)data.word(kLineendx);
- int lineEndY = (int16)data.word(kLineendy);
+ int lineStartX = (int16)_lineStartX;
+ int lineStartY = (int16)_lineStartY;
+ int lineEndX = (int16)_lineEndX;
+ int lineEndY = (int16)_lineEndY;
diffx = ABS(lineStartX - lineEndX);
@@ -323,8 +302,49 @@ void DreamBase::workoutFrames() {
}
}
- data.byte(kTurntoface) = tmp & 7;
- data.byte(kTurndirection) = 0;
+ _turnToFace = tmp & 7;
+ _turnDirection = 0;
+}
+
+byte DreamWebEngine::findFirstPath(byte x, byte y) {
+ PathNode *paths = _pathData[_roomNum].nodes;
+
+ for (uint8 index = 0; index < 12; index++) {
+ if (paths[index].x1 == 0xff && paths[index].y1 == 0xff)
+ continue; // "nofirst"
+
+ if (x < paths[index].x1 || y < paths[index].y1)
+ continue; // "nofirst"
+
+ if (x >= paths[index].x2 || y >= paths[index].y2)
+ continue; // "nofirst"
+
+ return paths[index].on; // "gotfirst"
+ }
+
+ return 0;
+}
+
+byte DreamWebEngine::findPathOfPoint(byte x, byte y) {
+ PathNode *paths = _pathData[_roomNum].nodes;
+
+ for (uint8 index = 0; index < 12; index++) {
+ if (paths[index].on != 0xff)
+ continue; // "flunkedit"
+
+ if (paths[index].x1 == 0xff && paths[index].y1 == 0xff)
+ continue; // "flunkedit"
+
+ if (x < paths[index].x1 || y < paths[index].y1)
+ continue; // "flunkedit"
+
+ if (x >= paths[index].x2 || y >= paths[index].y2)
+ continue; // "flunkedit"
+
+ return index; // "gotvalidpath"
+ }
+
+ return 0xff;
}
-} // End of namespace DreamGen
+} // End of namespace DreamWeb