diff options
author | Paul Gilbert | 2016-06-22 08:00:20 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-07-15 19:23:57 -0400 |
commit | 23da68350dee0b211cdcf29734146ac71583044b (patch) | |
tree | 5fb6df0d3b6bed30cac8931cd162792fd8656040 | |
parent | 4f85562c47d6e4b16e9b0e8e018e09635bf4ba9d (diff) | |
download | scummvm-rg350-23da68350dee0b211cdcf29734146ac71583044b.tar.gz scummvm-rg350-23da68350dee0b211cdcf29734146ac71583044b.tar.bz2 scummvm-rg350-23da68350dee0b211cdcf29734146ac71583044b.zip |
TITANIC: Finished CRoomFlags methods
-rw-r--r-- | engines/titanic/pet_control/pet_control.cpp | 7 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_control.h | 6 | ||||
-rw-r--r-- | engines/titanic/room_flags.cpp | 121 | ||||
-rw-r--r-- | engines/titanic/room_flags.h | 53 |
4 files changed, 166 insertions, 21 deletions
diff --git a/engines/titanic/pet_control/pet_control.cpp b/engines/titanic/pet_control/pet_control.cpp index bc2ab036b2..f7973e008b 100644 --- a/engines/titanic/pet_control/pet_control.cpp +++ b/engines/titanic/pet_control/pet_control.cpp @@ -533,4 +533,11 @@ void CPetControl::resetDials(int flag) { _conversations.resetDials(_activeNPCName); } +int CPetControl::getMailDest(const CRoomFlags &roomFlags) const { + if (!roomFlags.isSuccUBusRoomFlags()) + return roomFlags.getPassengerClassNum(); + + return roomFlags.getSuccUBusNum(roomFlags.getSuccUBusRoomName()); +} + } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h index 3dee76fea6..758069e5f1 100644 --- a/engines/titanic/pet_control/pet_control.h +++ b/engines/titanic/pet_control/pet_control.h @@ -36,6 +36,7 @@ #include "titanic/pet_control/pet_real_life.h" #include "titanic/pet_control/pet_remote.h" #include "titanic/pet_control/pet_rooms.h" +#include "titanic/room_flags.h" namespace Titanic { @@ -319,6 +320,11 @@ public: bool getC0() const { return _fieldC0 > 0; } void incC0() { ++_fieldC0; } void decC0() { --_fieldC0; } + + /** + * Get mail destination given the specified flags + */ + int getMailDest(const CRoomFlags &roomFlags) const; }; } // End of namespace Titanic diff --git a/engines/titanic/room_flags.cpp b/engines/titanic/room_flags.cpp index ac3ae4943b..b64b6509ca 100644 --- a/engines/titanic/room_flags.cpp +++ b/engines/titanic/room_flags.cpp @@ -21,6 +21,7 @@ */ #include "titanic/room_flags.h" +#include "titanic/titanic.h" namespace Titanic { @@ -99,6 +100,43 @@ int CRoomFlags::getRoomCategory() const { return tempFlags.getRoomArea() != 5; } +int CRoomFlags::getRoomArea() const { + if (isSuccUBusRoomFlags()) + return 4; + + if (!getBit0()) { + uint v3 = getFloorNum(); + if (v3 <= 38) { + uint v4 = getRoomNum(); + if (v4 <= 18) { + uint v6 = getElevatorNum(); + + if (v6 >= 1 && v6 <= 4) { + uint v7 = getPassengerClassNum() - 1; + if (v7) { + uint v8 = v7 - 1; + if (v8) { + if (v8 == 1 && is28To38(v3) && (v6 & 1) && v4 >= 1) + return 3; + } else if (is20To27(v3)) { + if (v6 & 1) { + if (v4 >= 1 && v4 <= 3) + return 2; + } else if (v4 >= 1 && v4 <= 4) { + return 2; + } + } + } else if (is2To19(v3) && v4 >= 1 && v4 <= 3) { + return 1; + } + } + } + } + } + + return 5; +} + CString CRoomFlags::getRoomDesc() const { switch (getRoomArea()) { case 1: @@ -286,11 +324,6 @@ uint CRoomFlags::getRoomBits() const { return (_data >> ROOM_SHIFT) & ROOM_MASK; } -uint CRoomFlags::getRoomArea() const { - warning("TODO: CRoomFlags::getRoomArea"); - return 0; -} - bool CRoomFlags::isSuccUBusRoomFlags() const { for (int idx = 0; idx < SUCCUBUS_ROOMS_SIZE; ++idx) { if (SUCCUBUS_ROOMS[idx]._roomFlags == _data) @@ -318,7 +351,7 @@ uint CRoomFlags::getSpecialRoomFlags(const CString &roomName) { return 0; } -uint CRoomFlags::getSuccUBusNum(const CString &roomName) { +uint CRoomFlags::getSuccUBusNum(const CString &roomName) const { for (int idx = 0; idx < SUCCUBUS_ROOMS_SIZE; ++idx) { if (!roomName.compareTo(SUCCUBUS_ROOMS[idx]._roomName)) return SUCCUBUS_ROOMS[idx]._succubusNum; @@ -400,4 +433,80 @@ void CRoomFlags::changeLocation(int action) { setRoomBits(roomNum); } +bool CRoomFlags::compareFlags(CRoomFlags flags1, CRoomFlags flags2) const { + if (flags1.getFloorNum() != flags2.getFloorNum()) + return false; + + uint elev1 = flags1.getElevatorNum(); + uint elev2 = flags2.getElevatorNum(); + uint class1 = getPassengerClassNum(); + uint class2 = getPassengerClassNum(); + + if (class1 > 0 && class1 < 3) { + if (elev1 == 2) + elev1 = 1; + else if (elev1 == 4) + elev1 = 3; + } + if (class2 > 0 && class2 < 3) { + if (elev2 == 2) + elev2 = 1; + else if (elev2 == 4) + elev2 = 3; + } + + return elev1 == elev2; +} + +bool CRoomFlags::compareLocation(uint roomFlags) { + CRoomFlags flags(roomFlags); + + return getElevatorNum() == flags.getElevatorBits() && + getFloorNum() == flags.getFloorNum() && + getRoomNum() == flags.getRoomNum(); +} + +void CRoomFlags::setRandomLocation(int classNum, bool flag) { + uint minRoom, elevNum, maxRoom, maxFloor, minFloor; + + do { + switch (classNum) { + case 1: + minFloor = 2; + maxFloor = 19; + minRoom = 1; + maxRoom = 3; + elevNum = g_vm->getRandomNumber(flag ? 2 : 3); + break; + + case 2: + minFloor = 20; + maxFloor = 27; + elevNum = g_vm->getRandomNumber(flag ? 2 : 3); + minRoom = 1; + maxRoom = ((elevNum - 1) & 1) ? 3 : 4; + break; + + case 3: + minRoom = 1; + minFloor = 28; + maxFloor = 38; + maxRoom = 18; + elevNum = g_vm->getRandomNumber(1); + if (elevNum == 1) + elevNum = 2; + break; + + default: + return; + } + + uint floorNum = minFloor + g_vm->getRandomNumber(maxFloor - minFloor); + uint roomNum = minRoom + g_vm->getRandomNumber(maxRoom - minRoom); + setElevatorBits(elevNum); + setRoomBits(roomNum); + setFloorNum(floorNum); + } while (_data == 0x59706); +} + } // End of namespace Titanic diff --git a/engines/titanic/room_flags.h b/engines/titanic/room_flags.h index 961452535e..553e0a32d6 100644 --- a/engines/titanic/room_flags.h +++ b/engines/titanic/room_flags.h @@ -43,6 +43,8 @@ private: int getRoomCategory() const; + int getRoomArea() const; + /** * Set the bits for the elevator number */ @@ -63,27 +65,27 @@ private: */ uint decodeFloorBits(uint bits) const; - uint getRoomArea() const; - /** - * Returns true if the current flags are in the succubus list + * Compares two room flags together */ - bool isSuccUBusRoomFlags() const; + bool compareFlags(CRoomFlags flags1, CRoomFlags flags2) const; /** - * Gets the special flags for a transport or succubus room + * Compares the current flags against the specified flags + * for a matching elevator, floor, and room */ - uint getSpecialRoomFlags(const CString &roomName); + bool compareLocation(uint roomFlags); /** - * Gets the succubus number associated with a given room + * Returns true if the current flags is for Titania's room */ - uint getSuccUBusNum(const CString &roomName); + bool isTitania() const { return _data == 0x8A397; } - /** - * Gets the succubus room name associated with the current room flags - */ - CString getSuccUBusRoomName() const; + bool is59706() const { return _data == 0x59706; } + + bool is2To19(uint v) const { return v >= 2 && v <= 19; } + bool is20To27(uint v) const { return v >= 20 && v <= 27; } + bool is28To38(uint v) const { return v >= 28 && v <= 38; } public: CRoomFlags() : _data(0) {} CRoomFlags(uint data) : _data(data) {} @@ -99,9 +101,15 @@ public: */ uint get() const { return _data; } - bool test5(const CRoomFlags &roomFlags) const { - return roomFlags.not5(); - } + /** + * Gets the special flags for a transport or succubus room + */ + uint getSpecialRoomFlags(const CString &roomName); + + /** + * Returns true if the current flags are in the succubus list + */ + bool isSuccUBusRoomFlags() const; /** * Get a description for the room @@ -195,6 +203,21 @@ public: * Change the passenger class */ void changeLocation(int action); + + /** + * Sets a random destination in the flags + */ + void setRandomLocation(int classNum, bool flag); + + /** + * Gets the succubus number associated with a given room + */ + uint getSuccUBusNum(const CString &roomName) const; + + /** + * Gets the succubus room name associated with the current room flags + */ + CString getSuccUBusRoomName() const; }; } // End of namespace Titanic |