diff options
author | whiterandrek | 2018-06-17 19:12:28 +0300 |
---|---|---|
committer | Eugene Sandulenko | 2018-06-28 23:51:32 +0200 |
commit | 4aa908860b12a4b341937d3fa8a5dce23ba2a396 (patch) | |
tree | 74fbd33a35dadee9e8b086df51c5eb6cf40868e6 /engines | |
parent | 9b8d72bfb53ce7b9eacc435f540b2b956f6fb759 (diff) | |
download | scummvm-rg350-4aa908860b12a4b341937d3fa8a5dce23ba2a396.tar.gz scummvm-rg350-4aa908860b12a4b341937d3fa8a5dce23ba2a396.tar.bz2 scummvm-rg350-4aa908860b12a4b341937d3fa8a5dce23ba2a396.zip |
PINK: add Hokus Pokus scripting system
Diffstat (limited to 'engines')
-rw-r--r-- | engines/pink/objects/handlers/handler_timer.cpp | 2 | ||||
-rw-r--r-- | engines/pink/objects/sequences/seq_timer.cpp | 3 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequence.h | 3 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequence_item.cpp | 7 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequencer.cpp | 102 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequencer.h | 9 |
6 files changed, 109 insertions, 17 deletions
diff --git a/engines/pink/objects/handlers/handler_timer.cpp b/engines/pink/objects/handlers/handler_timer.cpp index 46d3d579e4..dc1c9bd152 100644 --- a/engines/pink/objects/handlers/handler_timer.cpp +++ b/engines/pink/objects/handlers/handler_timer.cpp @@ -105,6 +105,8 @@ void HandlerTimerSequences::handle(Actor *actor) { Sequence *sequence = sequencer->findSequence(_sequences[index]); assert(sequence); + + sequencer->authorParallelSequence(sequence, 0); } } // End of namespace Pink diff --git a/engines/pink/objects/sequences/seq_timer.cpp b/engines/pink/objects/sequences/seq_timer.cpp index 95fe53ba67..7270c1a225 100644 --- a/engines/pink/objects/sequences/seq_timer.cpp +++ b/engines/pink/objects/sequences/seq_timer.cpp @@ -54,7 +54,8 @@ void SeqTimer::update() { Actor *actor = _sequencer->_page->findActor(_actor); assert(actor); - if (!_sequencer->findSequenceActorState(actor->getName())) { + if (!_sequencer->findMainSequenceActorState(actor->getName()) && + !_sequencer->findParralelSequenceActorState(actor->getName())) { actor->onTimerMessage(); } } diff --git a/engines/pink/objects/sequences/sequence.h b/engines/pink/objects/sequences/sequence.h index c3439a1737..0e9284654e 100644 --- a/engines/pink/objects/sequences/sequence.h +++ b/engines/pink/objects/sequences/sequence.h @@ -55,6 +55,9 @@ public: public: + bool canAddContext(const Common::String name); + + SequenceContext *_context; Sequencer *_sequencer; Array<SequenceItem *> _items; diff --git a/engines/pink/objects/sequences/sequence_item.cpp b/engines/pink/objects/sequences/sequence_item.cpp index cd21a100da..72fb452432 100644 --- a/engines/pink/objects/sequences/sequence_item.cpp +++ b/engines/pink/objects/sequences/sequence_item.cpp @@ -51,8 +51,9 @@ bool SequenceItem::execute(int index, Sequence *sequence, bool unk2) { actor->setAction(action, unk2); - SequenceActorState *state = sequence->_sequencer->findSequenceActorState(_actor); - state->_index = index; + SequenceActorState *state = sequence->_sequencer->findMainSequenceActorState(_actor); + if (state) + state->_index = index; sequence->_context->_actor = isLeader() ? actor : sequence->_context->_actor; return true; @@ -81,7 +82,7 @@ void SequenceItemLeaderAudio::toConsole() { } bool SequenceItemDefaultAction::execute(int index, Sequence *sequence, bool unk2) { - SequenceActorState *state = sequence->_sequencer->findSequenceActorState(_actor); + SequenceActorState *state = sequence->_sequencer->findMainSequenceActorState(_actor); state->_actionName = _action; return true; } diff --git a/engines/pink/objects/sequences/sequencer.cpp b/engines/pink/objects/sequences/sequencer.cpp index 30048814fb..9c6c7c0ada 100644 --- a/engines/pink/objects/sequences/sequencer.cpp +++ b/engines/pink/objects/sequences/sequencer.cpp @@ -24,7 +24,7 @@ #include "pink/archive.h" #include "pink/pink.h" -#include "pink/objects/actors/actor.h" +#include "pink/objects/actors/lead_actor.h" #include "pink/objects/pages/game_page.h" #include "pink/objects/sequences/sequencer.h" #include "pink/objects/sequences/sequence.h" @@ -60,19 +60,60 @@ Sequence *Sequencer::findSequence(const Common::String &name) { } void Sequencer::authorSequence(Sequence *sequence, bool unk) { - if (_context) { - - } + assert(!_context); if (sequence) { - _context = new SequenceContext(sequence, this); - //unload array of unknown objects + SequenceContext *context = new SequenceContext(sequence, this); + + SequenceContext *confilct; + while(confilct = isContextConflicts(context)) + confilct->_sequence->end(); + + _context = context; _currentSequenceName = sequence->getName(); sequence->init(unk); - } else - _currentSequenceName.clear(); + } +} + +void Sequencer::authorParallelSequence(Sequence *seqeunce, bool unk) { + if (_context && _context->_sequence == seqeunce) + return; + + for (uint i = 0; i < _parrallelContexts.size(); ++i) { + if (_parrallelContexts[i]->_sequence == seqeunce) + return; + } + + const Common::String leadName = _page->getLeadActor()->getName(); + + SequenceContext *context = new SequenceContext(seqeunce, this); + + for (uint i = 0; i < context->_states.size(); ++i) { + if (context->_states[i].getActor() == leadName) { + delete context; + return; + } + } + + for (uint i = 0; i < context->_states.size(); ++i) { + if (findMainSequenceActorState(context->_states[i].getActor())) { + delete context; + return; + } + } + + for (uint i = 0; i < context->_states.size(); ++i) { + if (findParralelSequenceActorState(context->_states[i].getActor())) { + delete context; + return; + } + } + + _parrallelContexts.push_back(context); + seqeunce->start(unk); } + void Sequencer::toConsole() { debug("Sequencer:"); for (uint i = 0; i < _sequences.size(); ++i) { @@ -86,12 +127,27 @@ void Sequencer::toConsole() { void Sequencer::update() { if (_context) _context->_sequence->update(); + + for (uint i = 0; i < _parrallelContexts.size(); ++i) { + _parrallelContexts[i]->_sequence->update(); + } + updateTimers(); } void Sequencer::removeContext(SequenceContext *context) { - delete _context; - _context = nullptr; + if (context == _context) { + delete _context; + _context = nullptr; + return; + } + + for (uint i = 0; i < _parrallelContexts.size(); ++i) { + if (context == _parrallelContexts[i]->_sequence->_context) { + _parrallelContexts.remove_at(i); + break; + } + } } void Sequencer::skipSubSequence() { @@ -119,7 +175,7 @@ void Sequencer::updateTimers() { } } -SequenceActorState *Sequencer::findSequenceActorState(const Common::String &name) { +SequenceActorState *Sequencer::findMainSequenceActorState(const Common::String &name) { if (!_context) return nullptr; @@ -131,6 +187,18 @@ SequenceActorState *Sequencer::findSequenceActorState(const Common::String &name return nullptr; } +SequenceActorState *Sequencer::findParralelSequenceActorState(const Common::String &name) { + for (uint i = 0; i < _parrallelContexts.size(); ++i) { + for (uint j = 0; j < _parrallelContexts[i]->_states.size(); ++j) { + if (_parrallelContexts[i]->_states[j].getActor() == name) + return &_parrallelContexts[i]->_states[j]; + } + } + + return nullptr; +} + + void Sequencer::loadState(Archive &archive) { Sequence *sequence = findSequence(archive.readString()); authorSequence(sequence, 1); @@ -144,4 +212,16 @@ void Sequencer::saveState(Archive &archive) { // add pokus specific } +SequenceContext * Sequencer::isContextConflicts(SequenceContext *context) { + for (uint i = 0; i < _parrallelContexts.size(); ++i) { + for (uint j = 0; j < _parrallelContexts[i]->_states.size(); ++j) { + for (int k = 0; k < context->_states.size(); ++k) { + if (_parrallelContexts[i]->_states[j].getActor() == context->_states[k].getActor()) + return _parrallelContexts[i]; + } + } + } + return nullptr; +} + } // End of namespace Pink diff --git a/engines/pink/objects/sequences/sequencer.h b/engines/pink/objects/sequences/sequencer.h index d34775aec4..d151fc0cde 100644 --- a/engines/pink/objects/sequences/sequencer.h +++ b/engines/pink/objects/sequences/sequencer.h @@ -42,9 +42,11 @@ public: virtual void deserialize(Archive &archive); Sequence *findSequence(const Common::String &name); - SequenceActorState *findSequenceActorState(const Common::String &name); + SequenceActorState *findMainSequenceActorState(const Common::String &name); + SequenceActorState *findParralelSequenceActorState(const Common::String &name); void authorSequence(Sequence *sequence, bool unk); + void authorParallelSequence(Sequence *seqeunce, bool unk); void removeContext(SequenceContext *context); @@ -56,11 +58,14 @@ public: void loadState(Archive &archive); void saveState(Archive &archive); + public: void updateTimers(); + SequenceContext * isContextConflicts(SequenceContext *context); + SequenceContext *_context; - // context array + Common::Array<SequenceContext *> _parrallelContexts; Array<Sequence *> _sequences; Array<SeqTimer *> _timers; Common::String _currentSequenceName; |