COMPOSER: Implement V1 random events.
This commit is contained in:
parent
81785c6090
commit
d6bfbdd60e
4 changed files with 39 additions and 1 deletions
|
@ -443,6 +443,20 @@ void ComposerEngine::loadLibrary(uint id) {
|
||||||
newLib._keyboardHandlers.push_back(handler);
|
newLib._keyboardHandlers.push_back(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Common::Array<uint16> randResources = library._archive->getResourceIDList(ID_RAND);
|
||||||
|
for (uint i = 0; i < randResources.size(); i++) {
|
||||||
|
Common::SeekableReadStream *stream = library._archive->getResource(ID_RAND, randResources[i]);
|
||||||
|
Common::Array<RandomEvent> &events = _randomEvents[randResources[i]];
|
||||||
|
uint16 count = stream->readUint16LE();
|
||||||
|
for (uint j = 0; j < count; j++) {
|
||||||
|
RandomEvent random;
|
||||||
|
random.scriptId = stream->readUint16LE();
|
||||||
|
random.weight = stream->readUint16LE();
|
||||||
|
events.push_back(random);
|
||||||
|
}
|
||||||
|
delete stream;
|
||||||
|
}
|
||||||
|
|
||||||
// add background sprite, if it exists
|
// add background sprite, if it exists
|
||||||
if (hasResource(ID_BMAP, 1000))
|
if (hasResource(ID_BMAP, 1000))
|
||||||
setBackground(1000);
|
setBackground(1000);
|
||||||
|
@ -470,6 +484,8 @@ void ComposerEngine::unloadLibrary(uint id) {
|
||||||
_anims.clear();
|
_anims.clear();
|
||||||
stopPipes();
|
stopPipes();
|
||||||
|
|
||||||
|
_randomEvents.clear();
|
||||||
|
|
||||||
for (Common::List<Sprite>::iterator j = _sprites.begin(); j != _sprites.end(); j++) {
|
for (Common::List<Sprite>::iterator j = _sprites.begin(); j != _sprites.end(); j++) {
|
||||||
j->_surface.free();
|
j->_surface.free();
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,11 @@ struct KeyboardHandler {
|
||||||
uint16 scriptId;
|
uint16 scriptId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RandomEvent {
|
||||||
|
uint16 weight;
|
||||||
|
uint16 scriptId;
|
||||||
|
};
|
||||||
|
|
||||||
struct Library {
|
struct Library {
|
||||||
uint _id;
|
uint _id;
|
||||||
Archive *_archive;
|
Archive *_archive;
|
||||||
|
@ -182,6 +187,8 @@ private:
|
||||||
Common::List<Animation *> _anims;
|
Common::List<Animation *> _anims;
|
||||||
Common::List<Pipe *> _pipes;
|
Common::List<Pipe *> _pipes;
|
||||||
|
|
||||||
|
Common::HashMap<uint16, Common::Array<RandomEvent> > _randomEvents;
|
||||||
|
|
||||||
void onMouseDown(const Common::Point &pos);
|
void onMouseDown(const Common::Point &pos);
|
||||||
void onMouseMove(const Common::Point &pos);
|
void onMouseMove(const Common::Point &pos);
|
||||||
void onKeyDown(uint16 keyCode);
|
void onKeyDown(uint16 keyCode);
|
||||||
|
|
|
@ -43,6 +43,7 @@ struct Animation;
|
||||||
#define ID_CTBL MKTAG('C','T','B','L') // Color Table
|
#define ID_CTBL MKTAG('C','T','B','L') // Color Table
|
||||||
#define ID_EVNT MKTAG('E','V','N','T') // Event
|
#define ID_EVNT MKTAG('E','V','N','T') // Event
|
||||||
#define ID_PIPE MKTAG('P','I','P','E') // Pipe
|
#define ID_PIPE MKTAG('P','I','P','E') // Pipe
|
||||||
|
#define ID_RAND MKTAG('R','A','N','D') // Random Object
|
||||||
#define ID_SCRP MKTAG('S','C','R','P') // Script
|
#define ID_SCRP MKTAG('S','C','R','P') // Script
|
||||||
#define ID_VARI MKTAG('V','A','R','I') // Variables
|
#define ID_VARI MKTAG('V','A','R','I') // Variables
|
||||||
#define ID_WAVE MKTAG('W','A','V','E') // Wave
|
#define ID_WAVE MKTAG('W','A','V','E') // Wave
|
||||||
|
|
|
@ -922,7 +922,21 @@ bool ComposerEngine::tickOldScript(OldScript *script) {
|
||||||
uint16 randomId;
|
uint16 randomId;
|
||||||
randomId = script->_stream->readUint16LE();
|
randomId = script->_stream->readUint16LE();
|
||||||
debug(3, "kOldOpRunRandom(%d)", randomId);
|
debug(3, "kOldOpRunRandom(%d)", randomId);
|
||||||
warning("V1 random not yet implemented"); // FIXME
|
if (!_randomEvents.contains(randomId)) {
|
||||||
|
warning("kOldOpRunRandom found no entries for id %d", randomId);
|
||||||
|
} else {
|
||||||
|
uint32 randValue = _rnd->getRandomNumberRng(0, 32767);
|
||||||
|
const Common::Array<RandomEvent> &events = _randomEvents[randomId];
|
||||||
|
uint i = 0;
|
||||||
|
for (i = 0; i < events.size(); i++) {
|
||||||
|
if ((i + 1 == events.size()) || (randValue <= events[i].weight)) {
|
||||||
|
runScript(events[i].scriptId);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
randValue -= events[i].weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("unknown oldScript op %d", op);
|
error("unknown oldScript op %d", op);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue