aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/pink/objects/handlers/handler.cpp10
-rw-r--r--engines/pink/objects/handlers/handler_timer.cpp9
-rw-r--r--engines/pink/objects/handlers/handler_timer.h2
-rw-r--r--engines/pink/objects/pages/game_page.cpp2
-rw-r--r--engines/pink/objects/pages/game_page.h2
-rw-r--r--engines/pink/objects/side_effect.cpp9
-rw-r--r--engines/pink/pink.cpp4
-rw-r--r--engines/pink/pink.h1
-rw-r--r--engines/pink/resource_mgr.cpp4
-rw-r--r--engines/pink/resource_mgr.h1
10 files changed, 36 insertions, 8 deletions
diff --git a/engines/pink/objects/handlers/handler.cpp b/engines/pink/objects/handlers/handler.cpp
index c5468e1b8d..de296150d0 100644
--- a/engines/pink/objects/handlers/handler.cpp
+++ b/engines/pink/objects/handlers/handler.cpp
@@ -27,6 +27,8 @@
#include <engines/pink/objects/sequences/sequencer.h>
#include <engines/pink/objects/sequences/sequence.h>
#include <engines/pink/objects/actors/lead_actor.h>
+#include <engines/pink/objects/pages/game_page.h>
+#include <engines/pink/pink.h>
#include <common/debug.h>
namespace Pink {
@@ -64,7 +66,13 @@ void HandlerSequences::onMessage(LeadActor *actor) {
Handler::onMessage(actor);
Sequencer *sequencer = actor->getSequencer();
- Sequence *sequence = sequencer->findSequence(_sequences[0]); //actually we must pick random sequence
+ assert(_sequences.size());
+
+ Common::RandomSource &rnd = actor->getPage()->getGame()->getRnd();
+ uint index = rnd.getRandomNumber(_sequences.size() - 1);
+
+ Sequence *sequence = sequencer->findSequence(_sequences[index]);
+
assert(sequence);
sequencer->authorSequence(sequence, 0);
diff --git a/engines/pink/objects/handlers/handler_timer.cpp b/engines/pink/objects/handlers/handler_timer.cpp
index b074772d84..4954f01ea4 100644
--- a/engines/pink/objects/handlers/handler_timer.cpp
+++ b/engines/pink/objects/handlers/handler_timer.cpp
@@ -28,6 +28,9 @@
#include <engines/pink/objects/sequences/sequence.h>
#include <engines/pink/objects/side_effect.h>
#include <engines/pink/objects/actors/lead_actor.h>
+#include <engines/pink/objects/pages/game_page.h>
+#include <engines/pink/pink.h>
+
namespace Pink {
@@ -58,9 +61,11 @@ void HandlerTimerActions::toConsole() {
void HandlerTimerActions::onMessage(LeadActor *actor) {
Handler::onMessage(actor);
- assert(_actions.size() > 0);
+ assert(_actions.size());
if (!actor->isPlaying()){
- Action *action = actor->findAction(_actions[0]);// we must pick random
+ Common::RandomSource &rnd = actor->getPage()->getGame()->getRnd();
+ uint index = rnd.getRandomNumber(_actions.size() - 1);
+ Action *action = actor->findAction(_actions[index]);
assert(action);
actor->setAction(action, 0);
}
diff --git a/engines/pink/objects/handlers/handler_timer.h b/engines/pink/objects/handlers/handler_timer.h
index b355645f99..d40dd6f6c7 100644
--- a/engines/pink/objects/handlers/handler_timer.h
+++ b/engines/pink/objects/handlers/handler_timer.h
@@ -30,7 +30,7 @@ namespace Pink {
class LeadActor;
-//TODO in Peril create HandlerTimerActions when it is request for HandlerTimer
+//TODO: in Peril create HandlerTimerActions when it is request for HandlerTimer
// This class has differences in games
class HandlerTimer : public Handler {
diff --git a/engines/pink/objects/pages/game_page.cpp b/engines/pink/objects/pages/game_page.cpp
index e29a4f8179..16f918d060 100644
--- a/engines/pink/objects/pages/game_page.cpp
+++ b/engines/pink/objects/pages/game_page.cpp
@@ -89,7 +89,7 @@ void GamePage::loadManagers() {
}
PinkEngine *GamePage::getGame() {
- return _module->getGame();
+ return _resMgr.getGame();
}
Sequencer *GamePage::getSequencer() {
diff --git a/engines/pink/objects/pages/game_page.h b/engines/pink/objects/pages/game_page.h
index 6eb29a257d..74d19766b7 100644
--- a/engines/pink/objects/pages/game_page.h
+++ b/engines/pink/objects/pages/game_page.h
@@ -45,8 +45,8 @@ public:
PinkEngine *getGame();
Sequencer *getSequencer();
WalkMgr *getWalkMgr();
-
Module *getModule() const;
+
bool checkValueOfVariable(Common::String &variable, Common::String &value);
void setVariable(Common::String &variable, Common::String &value);
diff --git a/engines/pink/objects/side_effect.cpp b/engines/pink/objects/side_effect.cpp
index 4b290fa054..8e6fb5eb36 100644
--- a/engines/pink/objects/side_effect.cpp
+++ b/engines/pink/objects/side_effect.cpp
@@ -29,6 +29,7 @@
#include <engines/pink/objects/walk/walk_location.h>
#include <engines/pink/objects/walk/walk_mgr.h>
+
namespace Pink {
void SideEffectExit::deserialize(Archive &archive) {
@@ -109,8 +110,12 @@ void SideEffectRandomPageVariable::deserialize(Archive &archive) {
}
void SideEffectRandomPageVariable::execute(LeadActor *actor) {
- // TODO think how to get rand gen here
- actor->getPage()->setVariable(_name, _values[0]); // temporary solution
+ assert(_values.size());
+
+ Common::RandomSource &rnd = actor->getPage()->getGame()->getRnd();
+ uint index = rnd.getRandomNumber(_values.size() - 1);
+
+ actor->getPage()->setVariable(_name, _values[index]);
}
void SideEffectRandomPageVariable::toConsole() {
diff --git a/engines/pink/pink.cpp b/engines/pink/pink.cpp
index b5edbb1a19..ec0ad26be8 100644
--- a/engines/pink/pink.cpp
+++ b/engines/pink/pink.cpp
@@ -199,4 +199,8 @@ void PinkEngine::setVariable(Common::String &variable, Common::String &value) {
_variables[variable] = value;
}
+Common::RandomSource &PinkEngine::getRnd() {
+ return _rnd;
+}
+
} \ No newline at end of file
diff --git a/engines/pink/pink.h b/engines/pink/pink.h
index 114b475069..e5dc3d5dd4 100644
--- a/engines/pink/pink.h
+++ b/engines/pink/pink.h
@@ -75,6 +75,7 @@ public:
OrbFile *getOrb() { return &_orb; }
BroFile *getBro() { return _bro; }
+ Common::RandomSource &getRnd();
bool checkValueOfVariable(Common::String &variable, Common::String &value);
void setVariable(Common::String &variable, Common::String &value);
diff --git a/engines/pink/resource_mgr.cpp b/engines/pink/resource_mgr.cpp
index 158450212b..208b206c50 100644
--- a/engines/pink/resource_mgr.cpp
+++ b/engines/pink/resource_mgr.cpp
@@ -73,4 +73,8 @@ Common::SeekableReadStream *ResourceMgr::getResourceStream(Common::String &name)
_resDescTable[i].offset + _resDescTable[i].size);
}
+PinkEngine *ResourceMgr::getGame() const {
+ return _game;
+}
+
} // End of namespace Pink
diff --git a/engines/pink/resource_mgr.h b/engines/pink/resource_mgr.h
index 8de06b25b2..1188c1226a 100644
--- a/engines/pink/resource_mgr.h
+++ b/engines/pink/resource_mgr.h
@@ -51,6 +51,7 @@ public:
//Common::String loadText(Common::String &name);
Sound *loadSound(Common::String &name);
// loadCEL();
+ PinkEngine *getGame() const;
private:
Common::SeekableReadStream *getResourceStream(Common::String &name);