From 6eac69f45a436535e6c56e27cb144eed8719317f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 5 Nov 2016 11:02:39 -0400 Subject: TITANIC: Replaced int passenger class with PassengerClass enum --- engines/titanic/core/game_object.cpp | 12 ++++----- engines/titanic/core/game_object.h | 8 +++--- engines/titanic/game_location.h | 5 ++++ engines/titanic/game_state.cpp | 12 ++++----- engines/titanic/game_state.h | 4 +-- engines/titanic/moves/restricted_move.cpp | 4 +-- engines/titanic/npcs/deskbot.cpp | 31 ++++++++++++----------- engines/titanic/npcs/deskbot.h | 2 +- engines/titanic/npcs/titania.cpp | 2 +- engines/titanic/pet_control/pet_control.cpp | 2 +- engines/titanic/pet_control/pet_control.h | 4 +-- engines/titanic/pet_control/pet_conversations.cpp | 2 +- engines/titanic/pet_control/pet_rooms.cpp | 4 +-- engines/titanic/pet_control/pet_rooms.h | 5 ++-- engines/titanic/room_flags.cpp | 26 +++++++++---------- engines/titanic/room_flags.h | 5 +++- 16 files changed, 69 insertions(+), 59 deletions(-) diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index 3738108c69..545868b582 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -1336,17 +1336,17 @@ CMusicRoom *CGameObject::getMusicRoom() const { return gameManager ? &gameManager->_musicRoom : nullptr; } -int CGameObject::getPassengerClass() const { +PassengerClass CGameObject::getPassengerClass() const { CGameManager *gameManager = getGameManager(); - return gameManager ? gameManager->_gameState._passengerClass : 3; + return gameManager ? gameManager->_gameState._passengerClass : THIRD_CLASS; } -int CGameObject::getPriorClass() const { +PassengerClass CGameObject::getPriorClass() const { CGameManager *gameManager = getGameManager(); - return gameManager ? gameManager->_gameState._priorClass : 3; + return gameManager ? gameManager->_gameState._priorClass : THIRD_CLASS; } -void CGameObject::setPassengerClass(int newClass) { +void CGameObject::setPassengerClass(PassengerClass newClass) { if (newClass >= 1 && newClass <= 4) { // Change the passenger class CGameManager *gameMan = getGameManager(); @@ -1581,7 +1581,7 @@ void CGameObject::petMoveToHiddenRoom() { } } -void CGameObject::petReassignRoom(int passClassNum) { +void CGameObject::petReassignRoom(PassengerClass passClassNum) { CPetControl *petControl = getPetControl(); if (petControl) petControl->reassignRoom(passClassNum); diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index 066e51960d..ae35e2ba5b 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -452,7 +452,7 @@ protected: /** * Set's the player's passenger class */ - void setPassengerClass(int newClass); + void setPassengerClass(PassengerClass newClass); /** * Overrides whether the object's movie has audio timing @@ -712,12 +712,12 @@ public: /** * Return the player's passenger class */ - int getPassengerClass() const; + PassengerClass getPassengerClass() const; /** * Return the player's previous passenger class */ - int getPriorClass() const; + PassengerClass getPriorClass() const; /** * Sets the mail identifier for an object @@ -884,7 +884,7 @@ public: /** * Gives the player a new assigned room in the specified passenger class */ - void petReassignRoom(int passClassNum); + void petReassignRoom(PassengerClass passClassNum); /** * Sets a new area in the PET diff --git a/engines/titanic/game_location.h b/engines/titanic/game_location.h index f145d36340..87416f6cd7 100644 --- a/engines/titanic/game_location.h +++ b/engines/titanic/game_location.h @@ -30,6 +30,11 @@ namespace Titanic { +enum PassengerClass { + UNCHECKED = 4, THIRD_CLASS = 3, SECOND_CLASS = 2, FIRST_CLASS = 1, + NO_CLASS = 0 +}; + class CGameState; class CGameLocation { diff --git a/engines/titanic/game_state.cpp b/engines/titanic/game_state.cpp index bebc2ed8b4..8eae028387 100644 --- a/engines/titanic/game_state.cpp +++ b/engines/titanic/game_state.cpp @@ -45,10 +45,10 @@ bool CGameStateMovieList::clear() { /*------------------------------------------------------------------------*/ CGameState::CGameState(CGameManager *gameManager) : - _gameManager(gameManager), _gameLocation(this), - _passengerClass(0), _priorClass(0), _mode(GSMODE_NONE), - _seasonNum(SEASON_SUMMER), _petActive(false), _field1C(false), _quitGame(false), - _field24(0), _nodeChangeCtr(0), _nodeEnterTicks(0), _field38(0) { + _gameManager(gameManager), _gameLocation(this), _passengerClass(NO_CLASS), + _priorClass(NO_CLASS), _mode(GSMODE_NONE), _seasonNum(SEASON_SUMMER), + _petActive(false), _field1C(false), _quitGame(false), _field24(0), + _nodeChangeCtr(0), _nodeEnterTicks(0), _field38(0) { } void CGameState::save(SimpleFile *file) const { @@ -64,8 +64,8 @@ void CGameState::save(SimpleFile *file) const { void CGameState::load(SimpleFile *file) { _petActive = file->readNumber() != 0; - _passengerClass = file->readNumber(); - _priorClass = file->readNumber(); + _passengerClass = (PassengerClass)file->readNumber(); + _priorClass = (PassengerClass)file->readNumber(); _seasonNum = (Season)file->readNumber(); _field24 = file->readNumber(); _field38 = file->readNumber(); diff --git a/engines/titanic/game_state.h b/engines/titanic/game_state.h index 77b4ded79f..ba1dff2a45 100644 --- a/engines/titanic/game_state.h +++ b/engines/titanic/game_state.h @@ -64,8 +64,8 @@ public: CGameManager *_gameManager; CGameLocation _gameLocation; CGameStateMovieList _movieList; - int _passengerClass; - int _priorClass; + PassengerClass _passengerClass; + PassengerClass _priorClass; GameStateMode _mode; Season _seasonNum; bool _petActive; diff --git a/engines/titanic/moves/restricted_move.cpp b/engines/titanic/moves/restricted_move.cpp index b1040a3554..aed204abdc 100644 --- a/engines/titanic/moves/restricted_move.cpp +++ b/engines/titanic/moves/restricted_move.cpp @@ -51,7 +51,7 @@ bool CRestrictedMove::MouseButtonDownMsg(CMouseButtonDownMsg *msg) { if (classNum <= _classNum) { // Okay to change to the given destination changeView(_destination); - } else if (classNum != 4) { + } else if (classNum != UNCHECKED) { petDisplayMessage(1, CLASS_NOT_ALLOWED_AT_DEST); } else if (compareRoomNameTo("EmbLobby")) { playSound("a#17.wav"); @@ -68,7 +68,7 @@ bool CRestrictedMove::EnterViewMsg(CEnterViewMsg *msg) { int classNum = getPassengerClass(); bool flag = classNum > _classNum; - if (classNum == 4) { + if (classNum == UNCHECKED) { if (compareRoomNameTo("EmbLobby")) flag = false; else if (compareViewNameTo("Titania.Node 1.S")) diff --git a/engines/titanic/npcs/deskbot.cpp b/engines/titanic/npcs/deskbot.cpp index baf5db5fee..3a65b6f5bb 100644 --- a/engines/titanic/npcs/deskbot.cpp +++ b/engines/titanic/npcs/deskbot.cpp @@ -52,7 +52,8 @@ END_MESSAGE_MAP() int CDeskbot::_v1; int CDeskbot::_v2; -CDeskbot::CDeskbot() : CTrueTalkNPC(), _deskbotActive(false), _classNum(0) { +CDeskbot::CDeskbot() : CTrueTalkNPC(), _deskbotActive(false), + _classNum(NO_CLASS) { } void CDeskbot::save(SimpleFile *file, int indent) { @@ -70,7 +71,7 @@ void CDeskbot::load(SimpleFile *file) { _v1 = file->readNumber(); _v2 = file->readNumber(); _deskbotActive = file->readNumber(); - _classNum = file->readNumber(); + _classNum = (PassengerClass)file->readNumber(); CTrueTalkNPC::load(file); } @@ -116,7 +117,7 @@ bool CDeskbot::MovieEndMsg(CMovieEndMsg *msg) { dec54(); unlockMouse(); playSound("z#47.wav"); - _classNum = false; + _classNum = NO_CLASS; } _npcFlags &= ~NPCFLAG_10000; @@ -174,21 +175,21 @@ bool CDeskbot::TrueTalkTriggerActionMsg(CTrueTalkTriggerActionMsg *msg) { petSetArea(PET_CONVERSATION); playClip("ReprogramPETInHand", MOVIE_NOTIFY_OBJECT); _npcFlags |= NPCFLAG_10000; - _classNum = msg->_param1; + _classNum = (PassengerClass)msg->_param1; switch (_classNum) { - case 1: + case FIRST_CLASS: petDisplayMessage(UPGRADED_TO_FIRST_CLASS); setPassengerClass(_classNum); petReassignRoom(_classNum); break; - case 2: + case SECOND_CLASS: petDisplayMessage(UPGRADED_TO_SECOND_CLASS); setPassengerClass(_classNum); petReassignRoom(_classNum); break; - case 3: - setPassengerClass(3); + case THIRD_CLASS: + setPassengerClass(THIRD_CLASS); petReassignRoom(_classNum); break; default: @@ -199,31 +200,31 @@ bool CDeskbot::TrueTalkTriggerActionMsg(CTrueTalkTriggerActionMsg *msg) { if (getPassengerClass() == 1) { CPetControl *petControl = getPetControl(); if (petControl) - petControl->changeLocationClass(4); + petControl->changeLocationClass(UNCHECKED); } break; case 21: - if (getPassengerClass() == 1) { + if (getPassengerClass() == FIRST_CLASS) { CPetControl *petControl = getPetControl(); if (petControl) - petControl->changeLocationClass(3); + petControl->changeLocationClass(THIRD_CLASS); } break; case 22: - if (getPassengerClass() == 1) { + if (getPassengerClass() == FIRST_CLASS) { CPetControl *petControl = getPetControl(); if (petControl) - petControl->changeLocationClass(2); + petControl->changeLocationClass(SECOND_CLASS); } break; case 23: - if (getPassengerClass() == 1) { + if (getPassengerClass() == FIRST_CLASS) { CPetControl *petControl = getPetControl(); if (petControl) - petControl->changeLocationClass(1); + petControl->changeLocationClass(FIRST_CLASS); } break; diff --git a/engines/titanic/npcs/deskbot.h b/engines/titanic/npcs/deskbot.h index ab48d63546..1b462f6584 100644 --- a/engines/titanic/npcs/deskbot.h +++ b/engines/titanic/npcs/deskbot.h @@ -45,7 +45,7 @@ private: static int _v2; public: bool _deskbotActive; - int _classNum; + PassengerClass _classNum; public: CLASSDEF; CDeskbot(); diff --git a/engines/titanic/npcs/titania.cpp b/engines/titanic/npcs/titania.cpp index aa92ddd166..db0c85d5f5 100644 --- a/engines/titanic/npcs/titania.cpp +++ b/engines/titanic/npcs/titania.cpp @@ -180,7 +180,7 @@ bool CTitania::ActMsg(CActMsg *msg) { CActMsg actMsg("Woken"); actMsg.execute("MouthSlot"); actMsg.execute("VisionCentreSlot"); - setPassengerClass(4); + setPassengerClass(UNCHECKED); addTimer(1000); } else { diff --git a/engines/titanic/pet_control/pet_control.cpp b/engines/titanic/pet_control/pet_control.cpp index 689ff0162f..294a99bbb1 100644 --- a/engines/titanic/pet_control/pet_control.cpp +++ b/engines/titanic/pet_control/pet_control.cpp @@ -696,7 +696,7 @@ void CPetControl::resetDials0() { int CPetControl::getMailDest(const CRoomFlags &roomFlags) const { if (!roomFlags.isSuccUBusRoomFlags()) - return roomFlags.getPassengerClassNum(); + return (int)roomFlags.getPassengerClassNum(); return roomFlags.getSuccUBusNum(roomFlags.getSuccUBusRoomName()); } diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h index e95643b967..cdef505104 100644 --- a/engines/titanic/pet_control/pet_control.h +++ b/engines/titanic/pet_control/pet_control.h @@ -422,14 +422,14 @@ public: /** * Gives the player a new assigned room in the specified passenger class */ - void reassignRoom(int passClassNum) { + void reassignRoom(PassengerClass passClassNum) { _rooms.reassignRoom(passClassNum); } /** * Change the current location passenger class */ - bool changeLocationClass(int newClassNum) { + bool changeLocationClass(PassengerClass newClassNum) { return _rooms.changeLocationClass(newClassNum); } diff --git a/engines/titanic/pet_control/pet_conversations.cpp b/engines/titanic/pet_control/pet_conversations.cpp index 03cdefbd34..57076fece5 100644 --- a/engines/titanic/pet_control/pet_conversations.cpp +++ b/engines/titanic/pet_control/pet_conversations.cpp @@ -427,7 +427,7 @@ int CPetConversations::canSummonBot(const CString &name) { void CPetConversations::summonBot(const CString &name) { if (_petControl) { - if (_petControl->getPassengerClass() >= 4) { + if (_petControl->getPassengerClass() >= UNCHECKED) { _petControl->displayMessage(AT_LEAST_3RD_CLASS_FOR_HELP); } else { _petControl->summonBot(name, 0); diff --git a/engines/titanic/pet_control/pet_rooms.cpp b/engines/titanic/pet_control/pet_rooms.cpp index 7a0c23c9b9..a10bd0d63d 100644 --- a/engines/titanic/pet_control/pet_rooms.cpp +++ b/engines/titanic/pet_control/pet_rooms.cpp @@ -277,7 +277,7 @@ uint CPetRooms::getRoomFlags() const { return roomFlags.get(); } -void CPetRooms::reassignRoom(int passClassNum) { +void CPetRooms::reassignRoom(PassengerClass passClassNum) { CPetRoomsGlyph *glyph = _glyphs.findAssignedRoom(); if (glyph) // Flag the old assigned room as no longer assigned @@ -330,7 +330,7 @@ CPetRoomsGlyph *CPetRooms::addGlyph(uint roomFlags, bool highlight_) { } } -bool CPetRooms::changeLocationClass(int newClassNum) { +bool CPetRooms::changeLocationClass(PassengerClass newClassNum) { CPetRoomsGlyph *glyph = _glyphs.findAssignedRoom(); if (!glyph) return 0; diff --git a/engines/titanic/pet_control/pet_rooms.h b/engines/titanic/pet_control/pet_rooms.h index 28d6553a33..efc7e3c969 100644 --- a/engines/titanic/pet_control/pet_rooms.h +++ b/engines/titanic/pet_control/pet_rooms.h @@ -26,6 +26,7 @@ #include "titanic/pet_control/pet_section.h" #include "titanic/pet_control/pet_text.h" #include "titanic/pet_control/pet_rooms_glyphs.h" +#include "titanic/game_location.h" namespace Titanic { @@ -155,12 +156,12 @@ public: /** * Gives the player a new assigned room in the specified passenger class */ - void reassignRoom(int passClassNum); + void reassignRoom(PassengerClass passClassNum); /** * Change the current location passenger class */ - bool changeLocationClass(int newClassNum); + bool changeLocationClass(PassengerClass newClassNum); /** * Returns true if a room glyph exists with the given flags diff --git a/engines/titanic/room_flags.cpp b/engines/titanic/room_flags.cpp index 9be8ea3d33..8b1c15d74c 100644 --- a/engines/titanic/room_flags.cpp +++ b/engines/titanic/room_flags.cpp @@ -112,7 +112,7 @@ int CRoomFlags::getRoomArea() const { uint v6 = getElevatorNum(); if (v6 >= 1 && v6 <= 4) { - uint v7 = getPassengerClassNum() - 1; + uint v7 = (int)getPassengerClassNum() - 1; if (v7) { uint v8 = v7 - 1; if (v8) { @@ -241,14 +241,14 @@ uint CRoomFlags::getPassengerClassBits() const { } CString CRoomFlags::getPassengerClassDesc() const { - int classNum = getPassengerClassNum(); + PassengerClass classNum = getPassengerClassNum(); switch (classNum) { - case 1: + case FIRST_CLASS: return "1st class"; - case 2: + case SECOND_CLASS: return "2nd class"; - case 3: + case THIRD_CLASS: return "SGT class"; default: return "no class"; @@ -373,25 +373,25 @@ void CRoomFlags::changeLocation(int action) { uint floorNum = getFloorNum(); uint roomNum = getRoomNum(); uint elevatorNum = getElevatorNum(); - uint classNum = getPassengerClassNum(); + PassengerClass classNum = getPassengerClassNum(); uint v10, v11, v12, v13; switch (classNum) { - case 1: + case FIRST_CLASS: v10 = 2; v11 = 19; v12 = 1; v13 = 3; break; - case 2: + case SECOND_CLASS: v10 = 20; v11 = 27; v12 = 1; v13 = (elevatorNum & 1) ? 3 : 4; break; - case 3: + case THIRD_CLASS: v10 = 28; v11 = 38; v12 = 1; @@ -442,16 +442,16 @@ bool CRoomFlags::compareClassElevator(uint flags1, uint flags2) { uint elev1 = f1.getElevatorNum(); uint elev2 = f2.getElevatorNum(); - uint class1 = f1.getPassengerClassNum(); - uint class2 = f2.getPassengerClassNum(); + PassengerClass class1 = f1.getPassengerClassNum(); + PassengerClass class2 = f2.getPassengerClassNum(); - if (class1 > 0 && class1 < 3) { + if (class1 == FIRST_CLASS || class1 == SECOND_CLASS) { if (elev1 == 2) elev1 = 1; else if (elev1 == 4) elev1 = 3; } - if (class2 > 0 && class2 < 3) { + if (class2 == FIRST_CLASS || class2 == SECOND_CLASS) { if (elev2 == 2) elev2 = 1; else if (elev2 == 4) diff --git a/engines/titanic/room_flags.h b/engines/titanic/room_flags.h index f0f90f80d1..5e21173b64 100644 --- a/engines/titanic/room_flags.h +++ b/engines/titanic/room_flags.h @@ -24,6 +24,7 @@ #define TITANIC_ROOM_FLAGS_H #include "titanic/support/string.h" +#include "titanic/game_location.h" namespace Titanic { @@ -142,7 +143,9 @@ public: /** * Gets the passenger class number */ - uint getPassengerClassNum() const { return getPassengerClassBits(); } + PassengerClass getPassengerClassNum() const { + return (PassengerClass)getPassengerClassBits(); + } /** * Get a description for the passenger class -- cgit v1.2.3