From 5a328ce28f4edfe3da0c261d7abc884aa6af94a2 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 22 Jun 2016 23:20:14 -0400 Subject: TITANIC: Completed CPetRooms methods --- engines/titanic/game/television.cpp | 6 +- engines/titanic/npcs/deskbot.cpp | 8 +- engines/titanic/pet_control/pet_control.cpp | 12 -- engines/titanic/pet_control/pet_control.h | 135 ++++++++++++++++++-- engines/titanic/pet_control/pet_rooms.cpp | 153 +++++++++++++++++++---- engines/titanic/pet_control/pet_rooms.h | 53 ++++++-- engines/titanic/pet_control/pet_rooms_glyphs.cpp | 7 ++ engines/titanic/pet_control/pet_rooms_glyphs.h | 4 +- engines/titanic/room_flags.cpp | 7 ++ engines/titanic/room_flags.h | 31 +++-- 10 files changed, 341 insertions(+), 75 deletions(-) (limited to 'engines/titanic') diff --git a/engines/titanic/game/television.cpp b/engines/titanic/game/television.cpp index 5127712cad..a3f8ec3391 100644 --- a/engines/titanic/game/television.cpp +++ b/engines/titanic/game/television.cpp @@ -277,10 +277,12 @@ bool CTelevision::TurnOn(CTurnOn *msg) { bool CTelevision::LightsMsg(CLightsMsg *msg) { CPetControl *pet = getPetControl(); + bool flag = false; + if (pet) - pet->fn4(); + flag = pet->isRoom59706(); - if (msg->_field8 || !_turnOn) + if (msg->_field8 || !flag) _turnOn = true; return true; diff --git a/engines/titanic/npcs/deskbot.cpp b/engines/titanic/npcs/deskbot.cpp index a52d7c7e4d..2af758b598 100644 --- a/engines/titanic/npcs/deskbot.cpp +++ b/engines/titanic/npcs/deskbot.cpp @@ -197,7 +197,7 @@ bool CDeskbot::TrueTalkTriggerActionMsg(CTrueTalkTriggerActionMsg *msg) { if (getPassengerClass() == 1) { CPetControl *petControl = getPetControl(); if (petControl) - petControl->roomFn2(4); + petControl->changeLocationClass(4); } break; @@ -205,7 +205,7 @@ bool CDeskbot::TrueTalkTriggerActionMsg(CTrueTalkTriggerActionMsg *msg) { if (getPassengerClass() == 1) { CPetControl *petControl = getPetControl(); if (petControl) - petControl->roomFn2(3); + petControl->changeLocationClass(3); } break; @@ -213,7 +213,7 @@ bool CDeskbot::TrueTalkTriggerActionMsg(CTrueTalkTriggerActionMsg *msg) { if (getPassengerClass() == 1) { CPetControl *petControl = getPetControl(); if (petControl) - petControl->roomFn2(2); + petControl->changeLocationClass(2); } break; @@ -221,7 +221,7 @@ bool CDeskbot::TrueTalkTriggerActionMsg(CTrueTalkTriggerActionMsg *msg) { if (getPassengerClass() == 1) { CPetControl *petControl = getPetControl(); if (petControl) - petControl->roomFn2(1); + petControl->changeLocationClass(1); } break; diff --git a/engines/titanic/pet_control/pet_control.cpp b/engines/titanic/pet_control/pet_control.cpp index e7bf1eeb7a..45b5ac3c93 100644 --- a/engines/titanic/pet_control/pet_control.cpp +++ b/engines/titanic/pet_control/pet_control.cpp @@ -188,10 +188,6 @@ bool CPetControl::fn1(int val) { return false; } -void CPetControl::fn4() { - warning("TODO: CPetControl::fn4"); -} - PetArea CPetControl::setArea(PetArea newArea) { if (newArea == _currentArea || !isUnlocked()) return _currentArea; @@ -520,14 +516,6 @@ CString CPetControl::getFullViewName() { return gameManager ? gameManager->getFullViewName() : CString(); } -void CPetControl::addRandomRoom(int passClassNum) { - _rooms.addRandomRoom(passClassNum); -} - -int CPetControl::roomFn2(int val) { - return _rooms.fn2(val); -} - void CPetControl::resetDials(int flag) { if (flag == 1) _conversations.resetDials(_activeNPCName); diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h index 652a6e8c83..c9056a7b32 100644 --- a/engines/titanic/pet_control/pet_control.h +++ b/engines/titanic/pet_control/pet_control.h @@ -166,8 +166,6 @@ public: void fn3(CTreeItem *item); - void fn4(); - /** * Sets the currently viewed area within the PET */ @@ -306,13 +304,6 @@ public: */ CString getFullViewName(); - /** - * Adds a random room to the room list - */ - void addRandomRoom(int passClassNum); - - int roomFn2(int val); - /** * Resets the dial display to reflect new values */ @@ -322,10 +313,136 @@ public: void incC0() { ++_fieldC0; } void decC0() { --_fieldC0; } + /* CPetRooms methods */ + + /** + * Adds a random room to the room list + */ + void addRandomRoom(int passClassNum) { + _rooms.addRandomRoom(passClassNum); + } + + /** + * Change the current location passenger class + */ + bool changeLocationClass(int newClassNum) { + return _rooms.changeLocationClass(newClassNum); + } + + /** + * Returns true if the Rooms list has a room with the given flags + */ + bool hasRoomFlags() const { + return _rooms.hasRoomFlags(getRoomFlags()); + } + + uint getRoomFlags() const { + return _rooms.getRoomFlags(); + } + + /** + * Set the current elevator number to use for room glyphs + */ + void setRoomsElevatorNum(int elevNum) { + _rooms.setElevatorNum(elevNum); + } + + /** + * Get the current elevator number used by room glyphs + */ + int getRoomsElevatorNum() const { + return _rooms.getElevatorNum(); + } + + /** + * Set the current floor number to use for room glyphs + */ + void setRoomsFloorNum(int floorNum) { + _rooms.setFloorNum(floorNum); + } + + /** + * Get the current floor number used by room glyphs + */ + int getRoomsFloorNum() const { + return _rooms.getFloorNum(); + } + + /** + * Set the current room number to use for room glyphs + */ + void setRoomsRoomNum(int roomNum) { + _rooms.setRoomNum(roomNum); + } + + /** + * Get the current floor number used by room glyphs + */ + int getRoomsRoomNum() const { + return _rooms.getRoomNum(); + } + + void setRooms1D0(int v) { + _rooms.set1D0(v); + } + int getRooms1D0() const { + return _rooms.get1D0(); + } + void setRooms1CC(int v) { + _rooms.set1CC(v); + } + int getRooms1CC() const { + return _rooms.get1CC(); + } + + /** + * Reset the highlight + */ + void resetRoomsHighlight() { + _rooms.resetHighlight(); + } + + int getRoomsMode1Flags() const { + return _rooms.mode1Flags(); + } + + uint getSpecialRoomFlags(const CString &name) { + return CRoomFlags::getSpecialRoomFlags(name); + } + /** * Get mail destination given the specified flags */ int getMailDest(const CRoomFlags &roomFlags) const; + + bool testRooms5(uint roomFlags) { + return CRoomFlags(roomFlags).not5(); + } + + int getRoomsRoomNum1() const { + return _rooms.getMode1RoomNum(); + } + int getRoomsFloorNum1() const { + return _rooms.getMode1FloorNum(); + } + int getRoomsElevatorNum1() const { + return _rooms.getMode1ElevatorNum(); + } + + void setRooms1D4(int val) { + _rooms.set1D4(val); + } + + bool isRoom59706() const { + return CRoomFlags(getRoomFlags()).is59706(); + } + + /** + * Returns true if the passed room flags indicate the room has a succubus + */ + bool isSuccUBusRoom(const CRoomFlags &roomFlags) { + return roomFlags.isSuccUBusRoomFlags(); + } }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_rooms.cpp b/engines/titanic/pet_control/pet_rooms.cpp index b98c68c174..9db5adc7de 100644 --- a/engines/titanic/pet_control/pet_rooms.cpp +++ b/engines/titanic/pet_control/pet_rooms.cpp @@ -30,7 +30,7 @@ CPetRooms::CPetRooms() : _chevRightOnDim(nullptr), _chevRightOffDim(nullptr), _chevLeftOnLit(nullptr), _chevLeftOffLit(nullptr), _chevRightOnLit(nullptr), _chevRightOffLit(nullptr), - _field1C0(0), _field1C4(0), _field1C8(0), _field1CC(0), + _floorNum(0), _elevatorNum(0), _roomNum(0), _field1CC(0), _field1D0(0), _field1D4(0) { } @@ -95,7 +95,22 @@ bool CPetRooms::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { } bool CPetRooms::checkDragEnd(CGameObject *item) { - warning("TODO: CPetRooms::checkDragEnd"); + // Ignore any item drops except valid mail items + if (!item->_isMail) + return false; + + uint roomFlags = item->_id; + CPetRoomsGlyph *glyph = _glyphs.findGlyphByFlags(roomFlags); + if (glyph) { + if (_glyphs.findGlyphByFlags(0)) { + _glyphs.highlight(glyph); + return false; + } + + roomFlags = 0; + } + + addRoom(roomFlags, true); return false; } @@ -119,9 +134,9 @@ void CPetRooms::load(SimpleFile *file, int param) { _glyphItem.setMode((RoomGlyphMode)file->readNumber()); file->readNumber(); - _field1C0 = file->readNumber(); - _field1C4 = file->readNumber(); - _field1C8 = file->readNumber(); + _floorNum = file->readNumber(); + _elevatorNum = file->readNumber(); + _roomNum = file->readNumber(); _field1CC = file->readNumber(); _field1D0 = file->readNumber(); _field1D4 = file->readNumber(); @@ -135,9 +150,9 @@ void CPetRooms::postLoad() { void CPetRooms::save(SimpleFile *file, int indent) const { _glyphs.save2(file, indent); _glyphItem.save2(file, indent); - file->writeNumberLine(_field1C0, indent); - file->writeNumberLine(_field1C4, indent); - file->writeNumberLine(_field1C8, indent); + file->writeNumberLine(_floorNum, indent); + file->writeNumberLine(_elevatorNum, indent); + file->writeNumberLine(_roomNum, indent); file->writeNumberLine(_field1CC, indent); file->writeNumberLine(_field1D0, indent); file->writeNumberLine(_field1D4, indent); @@ -157,7 +172,26 @@ CPetText *CPetRooms::getText() { } CGameObject *CPetRooms::getBackground(int index) { - return nullptr; + switch (index) { + case 8: + return _chevLeftOnDim; + case 9: + return _chevLeftOffDim; + case 10: + return _chevLeftOnLit; + case 11: + return _chevLeftOffLit; + case 12: + return _chevRightOnDim; + case 13: + return _chevRightOffDim; + case 14: + return _chevRightOnLit; + case 15: + return _chevRightOffLit; + default: + return nullptr; + } } bool CPetRooms::setupControl(CPetControl *petControl) { @@ -191,20 +225,54 @@ bool CPetRooms::setupControl(CPetControl *petControl) { } void CPetRooms::resetHighlight() { - _glyphItem.setMode(fn1()); + _glyphItem.setRoomFlags(getRoomFlags()); _glyphs.resetHighlight(); _glyphItem.updateTooltip(); areaChanged(PET_ROOMS); } -RoomGlyphMode CPetRooms::fn1() { - warning("TODO: CPetRooms::fn1"); - return RGM_0; -} +uint CPetRooms::getRoomFlags() const { + CRoomFlags roomFlags; + CString roomName = _petControl->getRoomName(); + + uint flags = roomFlags.getSpecialRoomFlags(roomName); + if (flags) + return flags; + + int classNum = roomFlags.whatPassengerClass(_floorNum); + roomFlags.setPassengerClassBits(classNum); + roomFlags.setFloorNum(_floorNum); + + switch (classNum) { + case 1: + roomFlags.setElevatorNum(_elevatorNum); + roomFlags.setRoomBits(_roomNum); + break; + + case 2: + if (_roomNum > 0) { + if (_roomNum >= 3) { + roomFlags.setElevatorNum(_elevatorNum == 1 || _elevatorNum == 2 ? 1 : 3); + } else { + roomFlags.setElevatorNum(_elevatorNum == 1 || _elevatorNum == 2 ? 2 : 4); + } + + roomFlags.setRoomBits(((_roomNum - 1) & 1) + (_field1CC > 1 ? 3 : 2)); + } else { + roomFlags.setRoomBits(0); + } + break; -int CPetRooms::fn2(int val) { - warning("TODO: CPetRooms::fn2"); - return 0; + case 3: + roomFlags.setElevatorNum(_elevatorNum); + roomFlags.setRoomBits(_roomNum + _field1CC * 6 - 6); + break; + + default: + break; + } + + return roomFlags.get(); } void CPetRooms::areaChanged(PetArea area) { @@ -219,11 +287,11 @@ void CPetRooms::addRandomRoom(int passClassNum) { CRoomFlags roomFlags; roomFlags.setRandomLocation(passClassNum, _field1D4); - if (addRoom(roomFlags, true)) { - + glyph = addRoom(roomFlags, true); + if (glyph) { + glyph->setMode(RGM_1); + _glyphs.highlight(glyph); } - - warning("TODO: CPetRooms::addRoom"); } CPetRoomsGlyph *CPetRooms::addRoom(uint roomFlags, bool highlight) { @@ -268,4 +336,47 @@ uint CPetRooms::mode1Flags() const { return glyph ? glyph->getRoomFlags() : 0; } +bool CPetRooms::changeLocationClass(int newClassNum) { + CPetRoomsGlyph *glyph = _glyphs.findMode1(); + if (!glyph) + return 0; + + glyph->changeLocation(newClassNum); + return true; +} + +bool CPetRooms::hasRoomFlags(uint roomFlags) const { + for (CPetRoomsGlyphs::const_iterator i = _glyphs.begin(); i != _glyphs.end(); ++i) { + const CPetRoomsGlyph *glyph = static_cast(*i); + if (glyph->isModeValid() && glyph->getRoomFlags() == roomFlags) + return true; + } + + return false; +} + +int CPetRooms::getMode1RoomNum() const { + uint flags = mode1Flags(); + if (!flags) + return 0; + + return CRoomFlags(flags).getRoomNum(); +} + +int CPetRooms::getMode1FloorNum() const { + uint flags = mode1Flags(); + if (!flags) + return 0; + + return CRoomFlags(flags).getFloorNum(); +} + +int CPetRooms::getMode1ElevatorNum() const { + uint flags = mode1Flags(); + if (!flags) + return 0; + + return CRoomFlags(flags).getElevatorNum(); +} + } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_rooms.h b/engines/titanic/pet_control/pet_rooms.h index a8a83af753..1e7468ac1b 100644 --- a/engines/titanic/pet_control/pet_rooms.h +++ b/engines/titanic/pet_control/pet_rooms.h @@ -43,9 +43,9 @@ private: CGameObject *_chevRightOffLit; CPetGfxElement _plinth; CPetText _text; - int _field1C0; - int _field1C4; - int _field1C8; + int _floorNum; + int _elevatorNum; + int _roomNum; int _field1CC; int _field1D0; int _field1D4; @@ -60,13 +60,6 @@ private: */ Point getGlyphPos() const { return Point(509, 388); } - /** - * Reset the highlight - */ - void resetHighlight(); - - RoomGlyphMode fn1(); - void areaChanged(PetArea area); /** @@ -78,8 +71,6 @@ private: * Adds a glyph to the list */ CPetRoomsGlyph *addGlyph(uint roomFlags, bool highlight); - - uint mode1Flags() const; public: CPetRooms(); @@ -155,12 +146,48 @@ public: virtual CGameObject *getBackground(int index); + /** + * Reset the highlight + */ + void resetHighlight(); + /** * Adds a random room to the glyph list */ void addRandomRoom(int passClassNum); - int fn2(int val); + /** + * Change the current location passenger class + */ + bool changeLocationClass(int newClassNum); + + /** + * Returns true if a room glyph exists with the given flags + */ + bool hasRoomFlags(uint roomFlags) const; + + int getMode1RoomNum() const; + int getMode1FloorNum() const; + int getMode1ElevatorNum() const; + + /** + * Gets room flags to use for glyphs + */ + uint getRoomFlags() const; + + uint mode1Flags() const; + + void setFloorNum(int floorNum) { _floorNum = floorNum; } + int getFloorNum() const { return _floorNum; } + void setElevatorNum(int elevNum) { _elevatorNum = elevNum; } + int getElevatorNum() const { return _elevatorNum; } + void setRoomNum(int roomNum) { _roomNum = roomNum; } + int getRoomNum() const { return _roomNum; } + void set1CC(int val) { _field1CC = val; } + int get1CC() const { return _field1CC; } + void set1D0(int val) { _field1D0 = val; } + int get1D0() const { return _field1D0; } + void set1D4(int val) { _field1D4 = val; } }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_rooms_glyphs.cpp b/engines/titanic/pet_control/pet_rooms_glyphs.cpp index 1048180369..786049791e 100644 --- a/engines/titanic/pet_control/pet_rooms_glyphs.cpp +++ b/engines/titanic/pet_control/pet_rooms_glyphs.cpp @@ -23,6 +23,7 @@ #include "titanic/pet_control/pet_rooms_glyphs.h" #include "titanic/pet_control/pet_section.h" #include "titanic/support/screen_manager.h" +#include "titanic/room_flags.h" namespace Titanic { @@ -83,6 +84,12 @@ void CPetRoomsGlyph::proc39() { } +void CPetRoomsGlyph::changeLocation(int newClassNum) { + CRoomFlags roomFlags(_roomFlags); + roomFlags.changeLocation(newClassNum); + _roomFlags = roomFlags.get(); +} + /*------------------------------------------------------------------------*/ void CPetRoomsGlyphs::save2(SimpleFile *file, int indent) const { diff --git a/engines/titanic/pet_control/pet_rooms_glyphs.h b/engines/titanic/pet_control/pet_rooms_glyphs.h index 1d6ded7af9..98ddcc74e9 100644 --- a/engines/titanic/pet_control/pet_rooms_glyphs.h +++ b/engines/titanic/pet_control/pet_rooms_glyphs.h @@ -78,7 +78,7 @@ public: /** * Set the room flags for the glyph */ - void setFoomFlags(uint flags) { _roomFlags = flags; } + void setRoomFlags(uint flags) { _roomFlags = flags; } /** * Get the room flags for the glyph @@ -92,6 +92,8 @@ public: */ void setMode(RoomGlyphMode mode) { _mode = mode; } + void changeLocation(int newClassNum); + bool isModeValid() const { return _mode != RGM_0; } bool isMode1() const { return _mode == RGM_1; } bool isMode2() const { return _mode == RGM_2; } diff --git a/engines/titanic/room_flags.cpp b/engines/titanic/room_flags.cpp index b64b6509ca..ac378e20c1 100644 --- a/engines/titanic/room_flags.cpp +++ b/engines/titanic/room_flags.cpp @@ -509,4 +509,11 @@ void CRoomFlags::setRandomLocation(int classNum, bool flag) { } while (_data == 0x59706); } +int CRoomFlags::whatPassengerClass(int floorNum) { + if (is2To19(floorNum)) + return 1; + + return is20To27(floorNum) ? 2 : 3; +} + } // End of namespace Titanic diff --git a/engines/titanic/room_flags.h b/engines/titanic/room_flags.h index 553e0a32d6..dfb7c89d96 100644 --- a/engines/titanic/room_flags.h +++ b/engines/titanic/room_flags.h @@ -33,8 +33,6 @@ private: private: int getConditionally() const; - bool not5() const { return getConditionally() != 5; } - /** * Returns true if the current flags appear in the * list of transport rooms @@ -50,11 +48,6 @@ private: */ void setElevatorBits(uint val); - /** - * Set the bits for the passenger class - */ - void setPassengerClassBits(uint val); - /** * Set the bits for the floor number */ @@ -81,11 +74,9 @@ private: */ bool isTitania() const { return _data == 0x8A397; } - 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; } + static bool is2To19(uint v) { return v >= 2 && v <= 19; } + static bool is20To27(uint v) { return v >= 20 && v <= 27; } + static bool is28To38(uint v) { return v >= 28 && v <= 38; } public: CRoomFlags() : _data(0) {} CRoomFlags(uint data) : _data(data) {} @@ -104,7 +95,7 @@ public: /** * Gets the special flags for a transport or succubus room */ - uint getSpecialRoomFlags(const CString &roomName); + static uint getSpecialRoomFlags(const CString &roomName); /** * Returns true if the current flags are in the succubus list @@ -143,6 +134,11 @@ public: */ uint getPassengerClassBits() const; + /** + * Set the bits for the passenger class + */ + void setPassengerClassBits(uint val); + /** * Gets the passenger class number */ @@ -218,6 +214,15 @@ public: * Gets the succubus room name associated with the current room flags */ CString getSuccUBusRoomName() const; + + /** + * Returns what passenger class a particular floor number belongs to + */ + static int whatPassengerClass(int floorNum); + + bool not5() const { return getConditionally() != 5; } + + bool is59706() const { return _data == 0x59706; } }; } // End of namespace Titanic -- cgit v1.2.3