aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlyssa Milburn2011-11-05 16:00:02 +0100
committerAlyssa Milburn2011-11-05 16:00:02 +0100
commitd6bfbdd60eb89ac56991efb851cbde4225a56c5c (patch)
tree6607413684471351f844c6c1cbb3db48e5a74b09
parent81785c60909b4a051afdd2f8050dbfc23d071b17 (diff)
downloadscummvm-rg350-d6bfbdd60eb89ac56991efb851cbde4225a56c5c.tar.gz
scummvm-rg350-d6bfbdd60eb89ac56991efb851cbde4225a56c5c.tar.bz2
scummvm-rg350-d6bfbdd60eb89ac56991efb851cbde4225a56c5c.zip
COMPOSER: Implement V1 random events.
-rw-r--r--engines/composer/composer.cpp16
-rw-r--r--engines/composer/composer.h7
-rw-r--r--engines/composer/resource.h1
-rw-r--r--engines/composer/scripting.cpp16
4 files changed, 39 insertions, 1 deletions
diff --git a/engines/composer/composer.cpp b/engines/composer/composer.cpp
index 17c14ddba9..556dad7e94 100644
--- a/engines/composer/composer.cpp
+++ b/engines/composer/composer.cpp
@@ -443,6 +443,20 @@ void ComposerEngine::loadLibrary(uint id) {
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
if (hasResource(ID_BMAP, 1000))
setBackground(1000);
@@ -470,6 +484,8 @@ void ComposerEngine::unloadLibrary(uint id) {
_anims.clear();
stopPipes();
+ _randomEvents.clear();
+
for (Common::List<Sprite>::iterator j = _sprites.begin(); j != _sprites.end(); j++) {
j->_surface.free();
}
diff --git a/engines/composer/composer.h b/engines/composer/composer.h
index 02dbca53b2..cebe977517 100644
--- a/engines/composer/composer.h
+++ b/engines/composer/composer.h
@@ -101,6 +101,11 @@ struct KeyboardHandler {
uint16 scriptId;
};
+struct RandomEvent {
+ uint16 weight;
+ uint16 scriptId;
+};
+
struct Library {
uint _id;
Archive *_archive;
@@ -182,6 +187,8 @@ private:
Common::List<Animation *> _anims;
Common::List<Pipe *> _pipes;
+ Common::HashMap<uint16, Common::Array<RandomEvent> > _randomEvents;
+
void onMouseDown(const Common::Point &pos);
void onMouseMove(const Common::Point &pos);
void onKeyDown(uint16 keyCode);
diff --git a/engines/composer/resource.h b/engines/composer/resource.h
index cc1985edd2..e0052cd868 100644
--- a/engines/composer/resource.h
+++ b/engines/composer/resource.h
@@ -43,6 +43,7 @@ struct Animation;
#define ID_CTBL MKTAG('C','T','B','L') // Color Table
#define ID_EVNT MKTAG('E','V','N','T') // Event
#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_VARI MKTAG('V','A','R','I') // Variables
#define ID_WAVE MKTAG('W','A','V','E') // Wave
diff --git a/engines/composer/scripting.cpp b/engines/composer/scripting.cpp
index a4c78c3a39..3a201c841a 100644
--- a/engines/composer/scripting.cpp
+++ b/engines/composer/scripting.cpp
@@ -922,7 +922,21 @@ bool ComposerEngine::tickOldScript(OldScript *script) {
uint16 randomId;
randomId = script->_stream->readUint16LE();
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;
default:
error("unknown oldScript op %d", op);