aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinterGrascph2016-05-13 16:13:19 +0200
committerBendegúz Nagy2016-08-26 23:02:22 +0200
commit6d5f8e2757d04d47208f096795cb3755fd8a16f2 (patch)
tree47341cbaadafb4f498c0ca640455732df1013834
parent253730787de69da9b914f41138f7a54214f41eff (diff)
downloadscummvm-rg350-6d5f8e2757d04d47208f096795cb3755fd8a16f2.tar.gz
scummvm-rg350-6d5f8e2757d04d47208f096795cb3755fd8a16f2.tar.bz2
scummvm-rg350-6d5f8e2757d04d47208f096795cb3755fd8a16f2.zip
DM: Add wrapper class around raw map bytes
-rw-r--r--engines/dm/dungeonman.cpp37
-rw-r--r--engines/dm/dungeonman.h52
2 files changed, 61 insertions, 28 deletions
diff --git a/engines/dm/dungeonman.cpp b/engines/dm/dungeonman.cpp
index 80239e14fe..b94382e9b7 100644
--- a/engines/dm/dungeonman.cpp
+++ b/engines/dm/dungeonman.cpp
@@ -282,36 +282,43 @@ void DungeonMan::setCurrentMap(uint16 mapIndex) {
= &_dunData.columnsCumulativeSquareThingCount[_dunData.mapsFirstColumnIndex[mapIndex]];
}
-byte DungeonMan::getSquare(int16 mapX, int16 mapY) {
+
+Square DungeonMan::getSquare(int16 mapX, int16 mapY) {
bool isInXBounds = (mapX >= 0) && (mapX < _currMap.width);
bool isInYBounds = (mapY >= 0) && (mapY < _currMap.height);
if (isInXBounds && isInYBounds)
return _currMap.data[mapX][mapY];
- int16 tmpSquare;
+
+ Square tmpSquare;
if (isInYBounds) {
- tmpSquare = getSquareType(_currMap.data[0][mapY]);
- if (mapX == -1 && (tmpSquare == kCorridorElemType || tmpSquare == kPitElemType))
- return (kWallElemType << 5) | kWallEastRandOrnAllowed;
+ Square tmpSquare(_currMap.data[0][mapY]);
+ if (mapX == -1 && (tmpSquare.getType() == kCorridorElemType || tmpSquare.getType() == kPitElemType))
+ return Square(kWallElemType).set(kWallEastRandOrnAllowed);
- tmpSquare = getSquareType(_currMap.data[_currMap.width - 1][mapY]);
- if (mapX == _currMap.width && (tmpSquare == kCorridorElemType || tmpSquare == kPitElemType))
- return (kWallElemType << 5) | kWallWestRandOrnAllowed;
+ tmpSquare.set(_currMap.data[_currMap.width - 1][mapY]);
+ if (mapX == _currMap.width && (tmpSquare.getType() == kCorridorElemType || tmpSquare.getType() == kPitElemType))
+ return Square(kWallElemType).set(kWallWestRandOrnAllowed);
} else if (isInXBounds) {
- tmpSquare = getSquareType(_currMap.data[mapX][0]);
- if (mapY == -1 && (tmpSquare == kCorridorElemType || tmpSquare == kPitElemType))
- return (kWallElemType << 5) | kWallSouthRandOrnAllowed;
+ tmpSquare.set(_currMap.data[mapX][0]);
+ if (mapY == -1 && (tmpSquare.getType() == kCorridorElemType || tmpSquare.getType() == kPitElemType))
+ return Square(kWallElemType).set(kWallSouthRandOrnAllowed);
- tmpSquare = getSquareType(_currMap.data[mapX][_currMap.height - 1]);
- if (mapY == _currMap.height && (tmpSquare == kCorridorElemType || tmpSquare == kPitElemType))
+ tmpSquare.set(_currMap.data[mapX][_currMap.height - 1]);
+ if (mapY == _currMap.height && (tmpSquare.getType() == kCorridorElemType || tmpSquare.getType() == kPitElemType))
return (kWallElemType << 5) | kWallNorthRandOrnAllowed;
}
- return kWallElemType << 5;
+ return Square(kWallElemType);
}
-byte DungeonMan::getRelSquare(direction dir, int16 stepsForward, int16 stepsRight, int16 posX, int16 posY) {
+Square DungeonMan::getRelSquare(direction dir, int16 stepsForward, int16 stepsRight, int16 posX, int16 posY) {
mapCoordsAfterRelMovement(dir, stepsForward, stepsForward, posX, posY);
return getSquare(posX, posY);
+}
+
+Thing DungeonMan::getSqureFirstThingIndex(int16 mapX, int16 mapY) {
+ //if (mapX < 0 || mapX >= _currMap.width || mapY < 0 || mapY >= _currMap.height || !(_currMap.data[mapX] & kThingListPresent))
+ return Thing();
} \ No newline at end of file
diff --git a/engines/dm/dungeonman.h b/engines/dm/dungeonman.h
index dbe13d3018..8c7ed84bb3 100644
--- a/engines/dm/dungeonman.h
+++ b/engines/dm/dungeonman.h
@@ -26,7 +26,27 @@ enum ThingType {
kThingTypeTotal = 16 // +1 than the last
}; // @ C[00..15]_THING_TYPE_...
-enum ElementType {
+
+enum SquareMask {
+ kWallWestRandOrnAllowed = 0x1,
+ kWallSouthRandOrnAllowed = 0x2,
+ kWallEastRandOrnAllowed = 0x4,
+ kWallNorthRandOrnAllowed = 0x8,
+ kPitImaginary = 0x1,
+ kPitInvisible = 0x4,
+ kPitOpen = 0x8,
+ kStairsUp = 0x4,
+ kStairsNorthSouthOrient = 0x8,
+ kDoorNorthSouthOrient = 0x8,
+ kTeleporterVisible = 0x4,
+ kTeleporterOpen = 0x8,
+ kFakeWallImaginary = 0x1,
+ kFakeWallOpen = 0x4,
+ kFakeWallRandOrnOrFootPAllowed = 0x8,
+ kThingListPresent = 0x10
+};
+
+enum SquareType {
kChampionElemType = -2,
kCreatureElemType = -1,
kWallElemType = 0,
@@ -42,11 +62,17 @@ enum ElementType {
kStairsFrontElemType = 19
}; // @ C[-2..19]_ELEMENT_...
-enum WallOrnMask {
- kWallWestRandOrnAllowed = 0x1,
- kWallSouthRandOrnAllowed = 0x2,
- kWallEastRandOrnAllowed = 0x4,
- kWallNorthRandOrnAllowed = 0x8
+class Square {
+ byte dat;
+public:
+ Square(byte dat = 0) : dat(dat) {}
+ Square(SquareType type) { setType(type); }
+ Square &set(byte dat) { this->dat = dat; return *this; }
+ Square &set(SquareMask mask) { dat |= mask; return *this; }
+ bool get(SquareMask mask) { return dat & mask; }
+ SquareType getType() { return (SquareType)(dat >> 5); } // @ M34_SQUARE_TYPE
+ Square &setType(SquareType type) { dat = (dat & 0x1F) | type << 5; return *this; }
+ byte toByte() { return dat; } // I don't like 'em casts
};
@@ -169,12 +195,12 @@ class DungeonMan {
DungeonMan(const DungeonMan &other); // no implementation on purpose
void operator=(const DungeonMan &rhs); // no implementation on purpose
- byte getSquare(int16 mapX, int16 mapY); // @ F0151_DUNGEON_GetSquare
- byte getRelSquare(direction dir, int16 stepsForward, int16 stepsRight, int16 posX, int16 posY); // @ F0152_DUNGEON_GetRelativeSquare
-
- ElementType getSquareType(int16 square) { return (ElementType)(square << 5); } // @ M34_SQUARE_TYPE
+ Square getSquare(int16 mapX, int16 mapY); // @ F0151_DUNGEON_GetSquare
+ Square getRelSquare(direction dir, int16 stepsForward, int16 stepsRight, int16 posX, int16 posY); // @ F0152_DUNGEON_GetRelativeSquare
void decompressDungeonFile(); // @ F0455_FLOPPY_DecompressDungeon
+
+ Thing getSqureFirstThingIndex(int16 mapX, int16 mapY); // @ F0160_DUNGEON_GetSquareFirstThingIndex
public:
DungeonMan(DMEngine *dmEngine);
~DungeonMan();
@@ -182,9 +208,9 @@ public:
void loadDungeonFile(); // @ F0434_STARTEND_IsLoadDungeonSuccessful_CPSC
void setCurrentMap(uint16 mapIndex); // @ F0173_DUNGEON_SetCurrentMap
void mapCoordsAfterRelMovement(direction dir, int16 stepsForward, int16 stepsRight, int16 &posX, int16 &posY); // @ F0150_DUNGEON_UpdateMapCoordinatesAfterRelativeMovement
- ElementType getRelSquareType(direction dir, int16 stepsForward, int16 stepsRight, int16 posX, int16 posY) {
- return getSquareType(getRelSquare(dir, stepsForward, stepsRight, posX, posY));
- }// @ F0153_DUNGEON_GetRelativeSquareType
+ SquareType getRelSquareType(direction dir, int16 stepsForward, int16 stepsRight, int16 posX, int16 posY) {
+ return Square(getRelSquare(dir, stepsForward, stepsRight, posX, posY)).getType();
+ } // @ F0153_DUNGEON_GetRelativeSquareType
};
}