From bc0a839175899462bc4a79a6e4f3853ac5ee9aaf Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 14 Jun 2015 15:34:11 -0400 Subject: SHERLOCK: RT: Move more methods from Sprite to TattooPerson --- engines/sherlock/objects.cpp | 130 ---------------------------- engines/sherlock/objects.h | 15 +--- engines/sherlock/tattoo/tattoo_people.cpp | 136 +++++++++++++++++++++++++++++- engines/sherlock/tattoo/tattoo_people.h | 20 +++++ engines/sherlock/tattoo/tattoo_talk.cpp | 2 +- 5 files changed, 156 insertions(+), 147 deletions(-) (limited to 'engines') diff --git a/engines/sherlock/objects.cpp b/engines/sherlock/objects.cpp index e9c6b00c9a..1c74f62d5d 100644 --- a/engines/sherlock/objects.cpp +++ b/engines/sherlock/objects.cpp @@ -38,38 +38,6 @@ namespace Sherlock { #define CLEAR_DIST_X 5 #define CLEAR_DIST_Y 0 -struct AdjustWalk { - char _vgsName[9]; - int _xAdjust; - int _flipXAdjust; - int _yAdjust; -} ; - -#define NUM_ADJUSTED_WALKS 21 -static const AdjustWalk ADJUST_WALKS[NUM_ADJUSTED_WALKS] = { - { "TUPRIGHT", -7, -19, 6 }, - { "TRIGHT", 8, -14, 0 }, - { "TDOWNRG", 14, -12, 0 }, - { "TWUPRIGH", 12, 4, 2 }, - { "TWRIGHT", 31, -14, 0 }, - { "TWDOWNRG", 6, -24, 0 }, - { "HTUPRIGH", 2, -20, 0 }, - { "HTRIGHT", 28, -20, 0 }, - { "HTDOWNRG", 8, -2, 0 }, - { "GTUPRIGH", 4, -12, 0 }, - { "GTRIGHT", 12, -16, 0 }, - { "GTDOWNRG", 10, -18, 0 }, - { "JTUPRIGH", 8, -10, 0 }, - { "JTRIGHT", 22, -6, 0 }, - { "JTDOWNRG", 4, -20, 0 }, - { "CTUPRIGH", 10, 0, 0 }, - { "CTRIGHT", 26, -22, 0 }, - { "CTDOWNRI", 16, 4, 0 }, - { "ITUPRIGH", 0, 0, 0 }, - { "ITRIGHT", 20, 0, 0 }, - { "ITDOWNRG", 8, 0, 0 } -}; - SherlockEngine *BaseObject::_vm; bool BaseObject::_countCAnimFrames; @@ -844,104 +812,6 @@ const Common::Rect Sprite::getOldBounds() const { return Common::Rect(_oldPosition.x, _oldPosition.y, _oldPosition.x + _oldSize.x, _oldPosition.y + _oldSize.y); } -void Sprite::setObjTalkSequence(int seq) { - assert(seq != -1 && _type == CHARACTER); - - if (_seqTo) { - // reset to previous value - _walkSequences[_sequenceNumber]._sequences[_frameNumber] = _seqTo; - _seqTo = 0; - } - - _sequenceNumber = _gotoSeq; - _frameNumber = 0; - checkWalkGraphics(); -} - -void Sprite::checkWalkGraphics() { - People &people = *_vm->_people; - - if (_images == nullptr) { - freeAltGraphics(); - return; - } - - Common::String filename = Common::String::format("%s.vgs", _walkSequences[_sequenceNumber]._vgsName.c_str()); - - // Set the adjust depending on if we have to fine tune the x position of this particular graphic - _adjust.x = _adjust.y = 0; - - for (int idx = 0; idx < NUM_ADJUSTED_WALKS; ++idx) { - if (!scumm_strnicmp(_walkSequences[_sequenceNumber]._vgsName.c_str(), ADJUST_WALKS[idx]._vgsName, - strlen(ADJUST_WALKS[idx]._vgsName))) { - if (_walkSequences[_sequenceNumber]._horizFlip) - _adjust.x = ADJUST_WALKS[idx]._flipXAdjust; - else - _adjust.x = ADJUST_WALKS[idx]._xAdjust; - - _adjust.y = ADJUST_WALKS[idx]._yAdjust; - break; - } - } - - // See if we're already using Alternate Graphics - if (_altSeq) { - // See if the VGS file called for is different than the alternate graphics already loaded - if (!_walkSequences[_sequenceNumber]._vgsName.compareToIgnoreCase(_walkSequences[_altSeq - 1]._vgsName)) { - // Different AltGraphics, Free the old ones - freeAltGraphics(); - } - } - - // If there is no Alternate Sequence set, see if we need to load a new one - if (!_altSeq) { - int npcNum = -1; - // Find which NPC this is so we can check the name of the graphics loaded - for (int idx = 0; idx < MAX_CHARACTERS; ++idx) { - if (this == &people[idx]) { - npcNum = idx; - break; - } - } - - if (npcNum != -1) { - // See if the VGS file called for is different than the main graphics which are already loaded - if (!filename.compareToIgnoreCase(people[npcNum]._walkVGSName)) { - // See if this is one of the more used Walk Graphics stored in WALK.LIB - for (int idx = 0; idx < NUM_IN_WALK_LIB; ++idx) { - if (!scumm_stricmp(filename.c_str(), WALK_LIB_NAMES[idx])) { - people._useWalkLib = true; - break; - } - } - - _altImages = new ImageFile(filename); - people._useWalkLib = false; - - _altSeq = _sequenceNumber + 1; - } - } - } - - // If this is a different seqeunce from the current sequence, reset the appropriate variables - if (_sequences != &_walkSequences[_sequenceNumber]._sequences[0]) { - _seqTo = _seqCounter = _seqCounter2 = _seqStack = _startSeq = 0; - _sequences = &_walkSequences[_sequenceNumber]._sequences[0]; - _seqSize = _walkSequences[_sequenceNumber]._sequences.size(); - } - - setImageFrame(); -} - -void Sprite::freeAltGraphics() { - if (_altImages != nullptr) { - delete _altImages; - _altImages = nullptr; - } - - _altSeq = 0; -} - /*----------------------------------------------------------------*/ void WalkSequence::load(Common::SeekableReadStream &s) { diff --git a/engines/sherlock/objects.h b/engines/sherlock/objects.h index 4f22e75dbf..f29c7890ab 100644 --- a/engines/sherlock/objects.h +++ b/engines/sherlock/objects.h @@ -258,15 +258,10 @@ public: * @param seq Which sequence to use (if there's more than 1) * @remarks 1: First talk seq, 2: second talk seq, etc. */ - virtual void setObjTalkSequence(int seq) = 0; + virtual void setObjTalkSequence(int seq) {} }; class Sprite: public BaseObject { -protected: - /** - * Free the alternate graphics used by NPCs - */ - void freeAltGraphics(); public: Common::String _name; Common::String _examine; // Examine in-depth description @@ -314,7 +309,7 @@ public: * @param seq Which sequence to use (if there's more than 1) * @remarks 1: First talk seq, 2: second talk seq, etc. */ - virtual void setObjTalkSequence(int seq); + virtual void setObjTalkSequence(int seq) {} /** * Return frame width @@ -331,12 +326,6 @@ public: */ const Common::Rect getOldBounds() const; - /** - * Checks a sprite associated with an NPC to see if the frame sequence specified - * in the sequence number uses alternate graphics, and if so if they need to be loaded - */ - void checkWalkGraphics(); - /** * This adjusts the sprites position, as well as it's animation sequence: */ diff --git a/engines/sherlock/tattoo/tattoo_people.cpp b/engines/sherlock/tattoo/tattoo_people.cpp index bb57ec93cf..72abdc371d 100644 --- a/engines/sherlock/tattoo/tattoo_people.cpp +++ b/engines/sherlock/tattoo/tattoo_people.cpp @@ -30,6 +30,38 @@ namespace Sherlock { namespace Tattoo { #define FACING_PLAYER 16 +#define NUM_ADJUSTED_WALKS 21 + +struct AdjustWalk { + char _vgsName[9]; + int _xAdjust; + int _flipXAdjust; + int _yAdjust; +} ; + +static const AdjustWalk ADJUST_WALKS[NUM_ADJUSTED_WALKS] = { + { "TUPRIGHT", -7, -19, 6 }, + { "TRIGHT", 8, -14, 0 }, + { "TDOWNRG", 14, -12, 0 }, + { "TWUPRIGH", 12, 4, 2 }, + { "TWRIGHT", 31, -14, 0 }, + { "TWDOWNRG", 6, -24, 0 }, + { "HTUPRIGH", 2, -20, 0 }, + { "HTRIGHT", 28, -20, 0 }, + { "HTDOWNRG", 8, -2, 0 }, + { "GTUPRIGH", 4, -12, 0 }, + { "GTRIGHT", 12, -16, 0 }, + { "GTDOWNRG", 10, -18, 0 }, + { "JTUPRIGH", 8, -10, 0 }, + { "JTRIGHT", 22, -6, 0 }, + { "JTDOWNRG", 4, -20, 0 }, + { "CTUPRIGH", 10, 0, 0 }, + { "CTRIGHT", 26, -22, 0 }, + { "CTDOWNRI", 16, 4, 0 }, + { "ITUPRIGH", 0, 0, 0 }, + { "ITRIGHT", 20, 0, 0 }, + { "ITDOWNRG", 8, 0, 0 } +}; static const int WALK_SPEED_X[99] = { 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 98, 90, 90, 90, 90, 90, 91, 90, 90, @@ -71,6 +103,15 @@ TattooPerson::TattooPerson() : Person() { _npcPause = false; } +void TattooPerson::freeAltGraphics() { + if (_altImages != nullptr) { + delete _altImages; + _altImages = nullptr; + } + + _altSeq = 0; +} + void TattooPerson::adjustSprite() { People &people = *_vm->_people; TattooScene &scene = *(TattooScene *)_vm->_scene; @@ -455,6 +496,95 @@ Common::Point TattooPerson::getSourcePoint() const { _position.y / FIXED_INT_MULTIPLIER); } +void TattooPerson::setObjTalkSequence(int seq) { + assert(seq != -1 && _type == CHARACTER); + + if (_seqTo) { + // reset to previous value + _walkSequences[_sequenceNumber]._sequences[_frameNumber] = _seqTo; + _seqTo = 0; + } + + _sequenceNumber = _gotoSeq; + _frameNumber = 0; + checkWalkGraphics(); +} + +void TattooPerson::checkWalkGraphics() { + People &people = *_vm->_people; + + if (_images == nullptr) { + freeAltGraphics(); + return; + } + + Common::String filename = Common::String::format("%s.vgs", _walkSequences[_sequenceNumber]._vgsName.c_str()); + + // Set the adjust depending on if we have to fine tune the x position of this particular graphic + _adjust.x = _adjust.y = 0; + + for (int idx = 0; idx < NUM_ADJUSTED_WALKS; ++idx) { + if (!scumm_strnicmp(_walkSequences[_sequenceNumber]._vgsName.c_str(), ADJUST_WALKS[idx]._vgsName, + strlen(ADJUST_WALKS[idx]._vgsName))) { + if (_walkSequences[_sequenceNumber]._horizFlip) + _adjust.x = ADJUST_WALKS[idx]._flipXAdjust; + else + _adjust.x = ADJUST_WALKS[idx]._xAdjust; + + _adjust.y = ADJUST_WALKS[idx]._yAdjust; + break; + } + } + + // See if we're already using Alternate Graphics + if (_altSeq) { + // See if the VGS file called for is different than the alternate graphics already loaded + if (!_walkSequences[_sequenceNumber]._vgsName.compareToIgnoreCase(_walkSequences[_altSeq - 1]._vgsName)) { + // Different AltGraphics, Free the old ones + freeAltGraphics(); + } + } + + // If there is no Alternate Sequence set, see if we need to load a new one + if (!_altSeq) { + int npcNum = -1; + // Find which NPC this is so we can check the name of the graphics loaded + for (int idx = 0; idx < MAX_CHARACTERS; ++idx) { + if (this == &people[idx]) { + npcNum = idx; + break; + } + } + + if (npcNum != -1) { + // See if the VGS file called for is different than the main graphics which are already loaded + if (!filename.compareToIgnoreCase(people[npcNum]._walkVGSName)) { + // See if this is one of the more used Walk Graphics stored in WALK.LIB + for (int idx = 0; idx < NUM_IN_WALK_LIB; ++idx) { + if (!scumm_stricmp(filename.c_str(), WALK_LIB_NAMES[idx])) { + people._useWalkLib = true; + break; + } + } + + _altImages = new ImageFile(filename); + people._useWalkLib = false; + + _altSeq = _sequenceNumber + 1; + } + } + } + + // If this is a different seqeunce from the current sequence, reset the appropriate variables + if (_sequences != &_walkSequences[_sequenceNumber]._sequences[0]) { + _seqTo = _seqCounter = _seqCounter2 = _seqStack = _startSeq = 0; + _sequences = &_walkSequences[_sequenceNumber]._sequences[0]; + _seqSize = _walkSequences[_sequenceNumber]._sequences.size(); + } + + setImageFrame(); +} + /*----------------------------------------------------------------*/ TattooPeople::TattooPeople(SherlockEngine *vm) : People(vm) { @@ -479,7 +609,7 @@ void TattooPeople::setListenSequence(int speaker, int sequenceNum) { obj.setObjTalkSequence(sequenceNum); } else if (objNum != -1) { objNum -= 256; - Person &person = *_data[objNum]; + TattooPerson &person = (*this)[objNum]; int newDir = person._sequenceNumber; switch (person._sequenceNumber) { @@ -546,7 +676,7 @@ void TattooPeople::setListenSequence(int speaker, int sequenceNum) { } void TattooPeople::setTalkSequence(int speaker, int sequenceNum) { - People &people = *_vm->_people; + TattooPeople &people = *(TattooPeople *)_vm->_people; Scene &scene = *_vm->_scene; TattooTalk &talk = *(TattooTalk *)_vm->_talk; @@ -569,7 +699,7 @@ void TattooPeople::setTalkSequence(int speaker, int sequenceNum) { } else if (objNum != -1) { objNum -= 256; - Person &person = people[objNum]; + TattooPerson &person = people[objNum]; int newDir = person._sequenceNumber; switch (newDir) { diff --git a/engines/sherlock/tattoo/tattoo_people.h b/engines/sherlock/tattoo/tattoo_people.h index 25a76b66f9..5fb94cc559 100644 --- a/engines/sherlock/tattoo/tattoo_people.h +++ b/engines/sherlock/tattoo/tattoo_people.h @@ -74,6 +74,11 @@ enum TattooSequences { class TattooPerson: public Person { private: bool checkCollision() const; + + /** + * Free the alternate graphics used by NPCs + */ + void freeAltGraphics(); protected: /** * Get the source position for a character potentially affected by scaling @@ -112,6 +117,12 @@ public: */ void pushNPCPath(); + /** + * Checks a sprite associated with an NPC to see if the frame sequence specified + * in the sequence number uses alternate graphics, and if so if they need to be loaded + */ + void checkWalkGraphics(); + /** * This adjusts the sprites position, as well as it's animation sequence: */ @@ -127,6 +138,15 @@ public: * in a straight line */ virtual void setWalking(); + + /** + * Adjusts the frame and sequence variables of a sprite that corresponds to the current speaker + * so that it points to the beginning of the sequence number's talk sequence in the object's + * sequence buffer + * @param seq Which sequence to use (if there's more than 1) + * @remarks 1: First talk seq, 2: second talk seq, etc. + */ + virtual void setObjTalkSequence(int seq); }; class TattooPeople : public People { diff --git a/engines/sherlock/tattoo/tattoo_talk.cpp b/engines/sherlock/tattoo/tattoo_talk.cpp index 9f6d68945f..c64ae2e805 100644 --- a/engines/sherlock/tattoo/tattoo_talk.cpp +++ b/engines/sherlock/tattoo/tattoo_talk.cpp @@ -518,7 +518,7 @@ OpcodeReturn TattooTalk::cmdSetNPCPosition(const byte *&str) { int npcNum = *++str - 1; ++str; TattooPeople &people = *(TattooPeople *)_vm->_people; - Person &person = people[npcNum]; + TattooPerson &person = people[npcNum]; int32 posX = (str[0] - 1) * 256 + str[1] - 1; if (posX > 16384) posX = -1 * (posX - 16384); -- cgit v1.2.3