aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/startrek/actors.cpp4
-rw-r--r--engines/startrek/awaymission.cpp25
-rw-r--r--engines/startrek/room.cpp22
-rw-r--r--engines/startrek/room.h11
-rw-r--r--engines/startrek/startrek.h9
5 files changed, 37 insertions, 34 deletions
diff --git a/engines/startrek/actors.cpp b/engines/startrek/actors.cpp
index 24434eb995..b8d185e0fb 100644
--- a/engines/startrek/actors.cpp
+++ b/engines/startrek/actors.cpp
@@ -670,7 +670,7 @@ int StarTrekEngine::findObjectAt(int x, int y) {
while (offset != _room->getHotspotEnd()) {
uint16 word = _room->readRdfWord(offset);
if (word & 0x8000) {
- if ((word & actionBit) && isPointInPolygon((int16 *)(_room->_rdfData + offset + 6), x, y)) {
+ if ((word & actionBit) && _room->isPointInPolygon(offset + 6, x, y)) {
int actorIndex = _room->readRdfWord(offset + 6);
_objectHasWalkPosition = true;
_objectWalkPosition.x = _room->readRdfWord(offset + 2);
@@ -681,7 +681,7 @@ int StarTrekEngine::findObjectAt(int x, int y) {
int numVertices = _room->readRdfWord(offset + 8);
offset = offset + 10 + numVertices * 4;
} else {
- if (isPointInPolygon((int16 *)(_room->_rdfData + offset), x, y)) {
+ if (_room->isPointInPolygon(offset, x, y)) {
int actorIndex = _room->readRdfWord(offset);
return actorIndex;
}
diff --git a/engines/startrek/awaymission.cpp b/engines/startrek/awaymission.cpp
index 08016c158b..5db4f42248 100644
--- a/engines/startrek/awaymission.cpp
+++ b/engines/startrek/awaymission.cpp
@@ -679,32 +679,11 @@ void StarTrekEngine::handleAwayMissionAction() {
}
}
-bool StarTrekEngine::isPointInPolygon(int16 *data, int16 x, int16 y) {
- int16 numVertices = data[1];
- int16 *vertData = &data[2];
-
- for (int i = 0; i < numVertices; i++) {
- Common::Point p1(vertData[0], vertData[1]);
- Common::Point p2;
- if (i == numVertices - 1) // Loop to 1st vertex
- p2 = Common::Point(data[2], data[3]);
- else
- p2 = Common::Point(vertData[2], vertData[3]);
-
- if ((p2.x - p1.x) * (y - p1.y) - (p2.y - p1.y) * (x - p1.x) < 0)
- return false;
-
- vertData += 2;
- }
-
- return true;
-}
-
void StarTrekEngine::checkTouchedLoadingZone(int16 x, int16 y) {
int16 offset = _room->getFirstDoorPolygonOffset();
while (offset != _room->getDoorPolygonEndOffset()) {
- if (isPointInPolygon((int16 *)(_room->_rdfData + offset), x, y)) {
+ if (_room->isPointInPolygon(offset, x, y)) {
uint16 var = _room->readRdfWord(offset);
if (_activeDoorWarpHotspot != var) {
_activeDoorWarpHotspot = var;
@@ -722,7 +701,7 @@ void StarTrekEngine::checkTouchedLoadingZone(int16 x, int16 y) {
offset = _room->getFirstWarpPolygonOffset();
while (offset != _room->getWarpPolygonEndOffset()) {
- if (isPointInPolygon((int16 *)(_room->_rdfData + offset), x, y)) {
+ if (_room->isPointInPolygon(offset, x, y)) {
uint16 var = _room->readRdfWord(offset);
if (_activeWarpHotspot != var) {
_activeWarpHotspot = var;
diff --git a/engines/startrek/room.cpp b/engines/startrek/room.cpp
index 9fc0431e81..f3b853acde 100644
--- a/engines/startrek/room.cpp
+++ b/engines/startrek/room.cpp
@@ -756,4 +756,26 @@ void Room::mccoyScan(int direction, TextRef text, bool changeDirection, bool fro
showText(TX_SPEAKER_MCCOY, text, fromRDF);
}
+bool Room::isPointInPolygon(int16 offset, int16 x, int16 y) {
+ int16 *data = (int16 *)(_rdfData + offset);
+ int16 numVertices = data[1];
+ int16 *vertData = &data[2];
+
+ for (int i = 0; i < numVertices; i++) {
+ Common::Point p1(vertData[0], vertData[1]);
+ Common::Point p2;
+ if (i == numVertices - 1) // Loop to 1st vertex
+ p2 = Common::Point(data[2], data[3]);
+ else
+ p2 = Common::Point(vertData[2], vertData[3]);
+
+ if ((p2.x - p1.x) * (y - p1.y) - (p2.y - p1.y) * (x - p1.x) < 0)
+ return false;
+
+ vertData += 2;
+ }
+
+ return true;
+}
+
} // End of namespace StarTrek
diff --git a/engines/startrek/room.h b/engines/startrek/room.h
index 6aeed92c41..be88008c4d 100644
--- a/engines/startrek/room.h
+++ b/engines/startrek/room.h
@@ -142,6 +142,7 @@ public:
* all rooms).
*/
Common::Point getBeamInPosition(int crewmanIndex);
+
/**
* This is analagous to above, but instead of beaming in, they just appear in a spot.
* Used sparingly, ie. in feather's serpent when appearing in cave after Quetzecoatl
@@ -149,6 +150,16 @@ public:
*/
Common::Point getSpawnPosition(int crewmanIndex);
+ /**
+ * Returns true if the given position is contained in a polygon.
+ *
+ * The data passed contains the following words in this order:
+ * * Index of polygon (unused here)
+ * * Number of vertices in polygon
+ * * For each vertex: x and y coordinates.
+ */
+ bool isPointInPolygon(int16 offset, int16 x, int16 y);
+
byte *_rdfData;
private:
diff --git a/engines/startrek/startrek.h b/engines/startrek/startrek.h
index 1e4e330ecb..5967283203 100644
--- a/engines/startrek/startrek.h
+++ b/engines/startrek/startrek.h
@@ -295,15 +295,6 @@ public:
bool checkItemInteractionExists(int action, int activeItem, int passiveItem, int16 arg6);
void handleAwayMissionAction();
- /**
- * Returns true if the given position is contained in a polygon.
- *
- * The data passed contains the following words in this order:
- * * Index of polygon (unused here)
- * * Number of vertices in polygon
- * * For each vertex: x and y coordinates.
- */
- bool isPointInPolygon(int16 *data, int16 x, int16 y);
void checkTouchedLoadingZone(int16 x, int16 y);
/**
* Updates any nonzero away mission timers, and invokes ACTION_TIMER_EXPIRED when any one