Skip to content

Commit

Permalink
SHERLOCK: Implement more scene loading and setNPCPath
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 24, 2015
1 parent ad008b5 commit 83c911c
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 6 deletions.
2 changes: 1 addition & 1 deletion engines/sherlock/objects.h
Expand Up @@ -107,7 +107,7 @@ struct WalkSequence {
bool _horizFlip;
Common::Array<byte> _sequences;

WalkSequence() : _vgsName(nullptr), _horizFlip(false) {}
WalkSequence() : _horizFlip(false) {}
const byte &operator[](int idx) { return _sequences[idx]; }

/**
Expand Down
12 changes: 12 additions & 0 deletions engines/sherlock/people.cpp
Expand Up @@ -80,6 +80,18 @@ void WalkSequence::load(Common::SeekableReadStream &s) {

/*----------------------------------------------------------------*/

Person::Person() : Sprite(), _walkLoaded(false), _npcIndex(0), _npcStack(0), _npcPause(false) {
Common::fill(&_npcPath[0], &_npcPath[MAX_NPC_PATH], 0);
}

void Person::clearNPC() {
Common::fill(&_npcPath[0], &_npcPath[MAX_NPC_PATH], 0);
_npcIndex = _npcStack = 0;
_npcName = "";
}

/*----------------------------------------------------------------*/

People::People(SherlockEngine *vm) : _vm(vm), _player(_data[0]) {
_holmesOn = true;
_oldWalkSequence = -1;
Expand Down
18 changes: 16 additions & 2 deletions engines/sherlock/people.h
Expand Up @@ -34,7 +34,9 @@ enum PeopleId {
PLAYER = 0,
AL = 0,
PEG = 1,
MAX_PLAYERS = 6
MAX_PLAYERS = 6,
MAX_NPC = 5,
MAX_NPC_PATH = 200
};

// Animation sequence identifiers for characters
Expand Down Expand Up @@ -66,11 +68,23 @@ class Person : public Sprite {
bool _walkLoaded;
Common::String _portrait;

// NPC related fields
int _npcIndex;
int _npcStack;
bool _npcPause;
byte _npcPath[MAX_NPC_PATH];
Common::String _npcName;

// Rose Tattoo fields
Common::String _walkVGSName; // Name of walk library person is using
Common::Array<WalkSequence> _walkSequences;
public:
Person() : Sprite(), _walkLoaded(false) {}
Person();

/**
* Clear the NPC related data
*/
void clearNPC();
};

class SherlockEngine;
Expand Down
53 changes: 53 additions & 0 deletions engines/sherlock/scene.cpp
Expand Up @@ -249,6 +249,7 @@ bool Scene::loadScene(const Common::String &filename) {
SaveManager &saves = *_vm->_saves;
Screen &screen = *_vm->_screen;
Sound &sound = *_vm->_sound;
Talk &talk = *_vm->_talk;
UserInterface &ui = *_vm->_ui;
bool flag;

Expand All @@ -264,6 +265,36 @@ bool Scene::loadScene(const Common::String &filename) {
_cAnim.clear();
_sequenceBuffer.clear();

// Check if it's a scene we need to keep trakc track of how many times we've visited
for (int idx = (int)_sceneTripCounters.size() - 1; idx >= 0; --idx) {
if (_sceneTripCounters[idx]._sceneNumber == _currentScene) {
if (--_sceneTripCounters[idx]._numTimes == 0) {
_vm->setFlags(_sceneTripCounters[idx]._flag);
_sceneTripCounters.remove_at(idx);
}
}
}

if (IS_ROSE_TATTOO) {
// Set the NPC paths for the scene
setNPCPath(0);

// Handle loading music for the scene
if (sound._midiDrvLoaded) {
if (talk._scriptMoreFlag != 1 && talk._scriptMoreFlag != 3)
sound._nextSongName = Common::String::format("res%02d", _currentScene);

// If it's a new song, then start it up
if (sound._currentSongName.compareToIgnoreCase(sound._nextSongName)) {
if (sound.loadSong(sound._nextSongName)) {
sound.setMIDIVolume(sound._musicVolume);
if (sound._musicOn)
sound.startSong();
}
}
}
}

//
// Load the room resource file for the scene
//
Expand Down Expand Up @@ -1585,4 +1616,26 @@ void Scene::synchronize(Common::Serializer &s) {
}
}

void Scene::setNPCPath(int npc) {
People &people = *_vm->_people;
Talk &talk = *_vm->_talk;

people[npc].clearNPC();
people[npc]._name = Common::String::format("WATS%.2dA", _currentScene);

// If we're in the middle of a script that will continue once the scene is loaded,
// return without calling the path script
if (talk._scriptMoreFlag == 1 || talk._scriptMoreFlag == 3)
return;

// Turn off all the NPCs, since the talk script will turn them back on as needed
for (uint idx = 0; idx < MAX_NPC; ++idx)
people[idx + 1]._type = INVALID;

// Call the path script for the scene
Common::String pathFile = Common::String::format("PATH%.2dA", _currentScene);
talk.talkTo(pathFile);
}


} // End of namespace Sherlock
18 changes: 18 additions & 0 deletions engines/sherlock/scene.h
Expand Up @@ -128,6 +128,16 @@ class ScaleZone: public Common::Rect {
void load(Common::SeekableReadStream &s);
};

struct SceneTripEntry {
bool _flag;
int _sceneNumber;
int _numTimes;

SceneTripEntry() : _flag(false), _sceneNumber(0), _numTimes(0) {}
SceneTripEntry(bool flag, int sceneNumber, int numTimes) : _flag(flag),
_sceneNumber(sceneNumber), _numTimes(numTimes) {}
};

class Scene {
private:
SherlockEngine *_vm;
Expand Down Expand Up @@ -212,6 +222,7 @@ class Scene {
bool _doBgAnimDone;
int _tempFadeStyle;
int _cAnimFramePause;
Common::Array<SceneTripEntry> _sceneTripCounters;
public:
Scene(SherlockEngine *vm);
~Scene();
Expand Down Expand Up @@ -291,6 +302,13 @@ class Scene {
* Synchronize the data for a savegame
*/
void synchronize(Common::Serializer &s);

/**
* Resets the NPC path information when entering a new scene.
* @remarks The default talk file for the given NPC is set to WATS##A, where ## is
* the scene number being entered
*/
void setNPCPath(int npc);
};

} // End of namespace Sherlock
Expand Down
17 changes: 15 additions & 2 deletions engines/sherlock/sound.cpp
Expand Up @@ -58,6 +58,8 @@ Sound::Sound(SherlockEngine *vm, Audio::Mixer *mixer) : _vm(vm), _mixer(mixer) {
_soundPlaying = false;
_soundIsOn = &_soundPlaying;
_curPriority = 0;
_midiDrvLoaded = false;
_musicVolume = 0;

_soundOn = true;
_musicOn = true;
Expand Down Expand Up @@ -231,12 +233,19 @@ void Sound::stopMusic() {
warning("TODO: Sound::stopMusic");
}

int Sound::loadSong(int songNumber) {
bool Sound::loadSong(int songNumber) {
// TODO
warning("TODO: Sound::loadSong");
return 0;
return false;
}

bool Sound::loadSong(const Common::String &name) {
// TODO
warning("TODO: Sound::loadSong");
return false;
}


void Sound::startSong() {
// TODO
warning("TODO: Sound::startSong");
Expand Down Expand Up @@ -264,5 +273,9 @@ void Sound::freeDigiSound() {
_soundPlaying = false;
}

void Sound::setMIDIVolume(int volume) {
// TODO
}

} // End of namespace Sherlock

7 changes: 6 additions & 1 deletion engines/sherlock/sound.h
Expand Up @@ -58,6 +58,9 @@ class Sound {
bool _soundPlaying;
bool *_soundIsOn;
byte *_digiBuf;
bool _midiDrvLoaded;
Common::String _currentSongName, _nextSongName;
int _musicVolume;
public:
Sound(SherlockEngine *vm, Audio::Mixer *mixer);

Expand Down Expand Up @@ -94,7 +97,8 @@ class Sound {
/**
* Load a specified song
*/
int loadSong(int songNumber);
bool loadSong(int songNumber);
bool loadSong(const Common::String &name);

/**
* Start playing a song
Expand All @@ -119,6 +123,7 @@ class Sound {
void stopSndFuncPtr(int v1, int v2);
void waitTimerRoland(uint time);
void freeDigiSound();
void setMIDIVolume(int volume);
};

} // End of namespace Sherlock
Expand Down

0 comments on commit 83c911c

Please sign in to comment.