From 022e28bec74b766fcb5e422f46e7fd60c3e529a8 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Thu, 24 Sep 2015 20:21:34 +0200 Subject: [PATCH] STARK: Add an opcode to know if an anim script has been reached --- engines/stark/resources/animscript.cpp | 5 +++++ engines/stark/resources/animscript.h | 3 +++ engines/stark/resources/command.cpp | 9 +++++++++ engines/stark/resources/command.h | 3 ++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/engines/stark/resources/animscript.cpp b/engines/stark/resources/animscript.cpp index e9bc644b86b..652894487cb 100644 --- a/engines/stark/resources/animscript.cpp +++ b/engines/stark/resources/animscript.cpp @@ -158,6 +158,11 @@ uint32 AnimScript::getDurationStartingWithItem(AnimScriptItem *startItem) { return duration; } +bool AnimScript::hasReached(AnimScriptItem *item) { + int32 index = findItemIndex(item); + return _nextItemIndex >= index; +} + int32 AnimScript::findItemIndex(AnimScriptItem *item) { if (!item) { return 0; diff --git a/engines/stark/resources/animscript.h b/engines/stark/resources/animscript.h index 18c742f4e64..e120eea4674 100644 --- a/engines/stark/resources/animscript.h +++ b/engines/stark/resources/animscript.h @@ -69,6 +69,9 @@ public: */ uint32 getDurationStartingWithItem(AnimScriptItem *startItem); + /** Is the current script item later in the script when compared to the specified one? */ + bool hasReached(AnimScriptItem *item); + protected: void goToNextItem(); int32 findItemIndex(AnimScriptItem *item); diff --git a/engines/stark/resources/command.cpp b/engines/stark/resources/command.cpp index 6196e189b15..796bda0d2f3 100644 --- a/engines/stark/resources/command.cpp +++ b/engines/stark/resources/command.cpp @@ -203,6 +203,8 @@ Command *Command::execute(uint32 callMode, Script *script) { return opIsScriptActive(_arguments[2].referenceValue); case kIsRandom: return opIsRandom(_arguments[2].intValue); + case kIsAnimScriptItemReached: + return opIsAnimScriptItemReached(_arguments[2].referenceValue); case kIsItemOnPlace: return opIsItemOnPlace(_arguments[2].referenceValue, _arguments[3].referenceValue); case kIsItemNearPlace: @@ -1016,6 +1018,13 @@ Command *Command::opIsRandom(int32 chance) { return nextCommandIf(value < chance); } +Command *Command::opIsAnimScriptItemReached(const ResourceReference &animScriptItemRef) { + AnimScriptItem *animScriptItem = animScriptItemRef.resolve(); + AnimScript *animScript = animScriptItem->findParent(); + + return nextCommandIf(animScript->hasReached(animScriptItem)); +} + Command *Command::opIsItemOnPlace(const ResourceReference &itemRef, const ResourceReference &positionRef) { FloorPositionedItem *item = itemRef.resolve(); diff --git a/engines/stark/resources/command.h b/engines/stark/resources/command.h index 2607d7e7071..592dd5a4a50 100644 --- a/engines/stark/resources/command.h +++ b/engines/stark/resources/command.h @@ -146,7 +146,7 @@ public: kIsKnowledgeIntegerLower = 173, kIsScriptActive = 174, kIsRandom = 175, - + kIsAnimScriptItemReached = 176, kIsItemOnPlace = 177, kIsAnimPlaying = 179, @@ -252,6 +252,7 @@ protected: Command *opIsKnowledgeIntegerLower(const ResourceReference &knowledgeRef, int32 value); Command *opIsScriptActive(const ResourceReference &scriptRef); Command *opIsRandom(int32 chance); + Command *opIsAnimScriptItemReached(const ResourceReference &animScriptItemRef); Command *opIsItemNearPlace(const ResourceReference &itemRef, const ResourceReference &positionRef, int32 testDistance); Command *opIsItemOnPlace(const ResourceReference &itemRef, const ResourceReference &positionRef); Command *opIsAnimPlaying(const ResourceReference &animRef);