SCUMM: complete handling of pending walkTo actions for sentence commands

in v0
This commit is contained in:
Tobias Gunkel 2012-01-22 23:13:58 +01:00
parent 1da715719c
commit fb68456541
4 changed files with 55 additions and 14 deletions

View file

@ -1135,7 +1135,7 @@ void ScummEngine_v0::walkToActorOrObject(int object) {
ActorC64 *a = (ActorC64 *)derefActor(VAR(VAR_EGO), "walkToObject"); ActorC64 *a = (ActorC64 *)derefActor(VAR(VAR_EGO), "walkToObject");
_walkToObject = object; _walkToObject = object;
_walkToObjectIdx = getObjectIndex(object); _walkToObjectState = kWalkToObjectStateWalk;
if (OBJECT_V0_TYPE(object) == kObjectV0TypeActor) { if (OBJECT_V0_TYPE(object) == kObjectV0TypeActor) {
walkActorToActor(VAR(VAR_EGO), OBJECT_V0_ID(object), 4); walkActorToActor(VAR(VAR_EGO), OBJECT_V0_ID(object), 4);
@ -1152,19 +1152,52 @@ void ScummEngine_v0::walkToActorOrObject(int object) {
// actor must not move if frozen // actor must not move if frozen
if (a->_miscflags & kActorMiscFlagFreeze) if (a->_miscflags & kActorMiscFlagFreeze)
a->stopActorMoving(); a->stopActorMoving();
}
bool ScummEngine_v0::checkPendingWalkAction() {
// before a sentence script is executed, it might be necessary to walk to
// and pickup objects before. Check if such an action is pending and handle
// it if available.
if (_walkToObjectState == kWalkToObjectStateDone)
return false;
int actor = VAR(VAR_EGO);
ActorC64 *a = (ActorC64 *)derefActor(actor, "checkAndRunSentenceScript");
// wait until walking or turning action is finished
if (a->_moving)
return true;
// after walking and turning finally execute the script
if (_walkToObjectState == kWalkToObjectStateTurn) {
runSentenceScript();
// change actor facing
} else if (getObjActToObjActDist(actorToObj(actor), _walkToObject) <= 4) {
if (objIsActor(_walkToObject)) { // walk to actor finished
// make actors turn to each other
a->faceToObject(_walkToObject);
int otherActor = objToActor(_walkToObject);
// ignore the plant
if (otherActor != 19) {
Actor *b = derefActor(otherActor, "checkAndRunSentenceScript(2)");
b->faceToObject(actorToObj(actor));
}
} else { // walk to object finished
int x, y, dir;
getObjectXYPos(_walkToObject, x, y, dir);
a->turnToDirection(dir);
}
_walkToObjectState = kWalkToObjectStateTurn;
return true;
} }
_walkToObjectState = kWalkToObjectStateDone;
return false;
} }
void ScummEngine_v0::checkAndRunSentenceScript() { void ScummEngine_v0::checkAndRunSentenceScript() {
if (_walkToObjectIdx) { if (checkPendingWalkAction())
ActorC64 *a = (ActorC64 *)derefActor(VAR(VAR_EGO), "checkAndRunSentenceScript");
if (a->_moving)
return;
// TODO: change actor facing
_walkToObjectIdx = 0;
runSentenceScript();
return; return;
}
if (!_sentenceNum || _sentence[_sentenceNum - 1].freezeCount) if (!_sentenceNum || _sentence[_sentenceNum - 1].freezeCount)
return; return;
@ -1214,7 +1247,7 @@ void ScummEngine_v0::checkAndRunSentenceScript() {
runSentenceScript(); runSentenceScript();
if (_currentMode == kModeKeypad) { if (_currentMode == kModeKeypad) {
_walkToObjectIdx = 0; _walkToObjectState = kWalkToObjectStateDone;
} }
} }

View file

@ -976,7 +976,8 @@ void ScummEngine_v0::resetSentence() {
_activeVerb = kVerbWalkTo; _activeVerb = kVerbWalkTo;
_activeObject = 0; _activeObject = 0;
_activeObject2 = 0; _activeObject2 = 0;
_walkToObjectIdx = 0;
_walkToObjectState = kWalkToObjectStateDone;
_redrawSentenceLine = true; _redrawSentenceLine = true;
} }

View file

@ -39,6 +39,12 @@ protected:
kModeNormal = 3, // normal playing mode kModeNormal = 3, // normal playing mode
}; };
enum WalkToObjectState {
kWalkToObjectStateDone = 0,
kWalkToObjectStateWalk = 1,
kWalkToObjectStateTurn = 2,
};
protected: protected:
byte _currentMode; byte _currentMode;
@ -51,7 +57,7 @@ protected:
int _cmdObject2; // 2nd script object or actor (see OBJECT_V0()) int _cmdObject2; // 2nd script object or actor (see OBJECT_V0())
int _walkToObject; int _walkToObject;
int _walkToObjectIdx; int _walkToObjectState;
bool _redrawSentenceLine; bool _redrawSentenceLine;
public: public:
@ -81,6 +87,7 @@ protected:
virtual void runSentenceScript(); virtual void runSentenceScript();
virtual void checkAndRunSentenceScript(); virtual void checkAndRunSentenceScript();
bool checkPendingWalkAction();
bool checkSentenceComplete(); bool checkSentenceComplete();
virtual void checkExecVerbs(); virtual void checkExecVerbs();
virtual void handleMouseOver(bool updateInventory); virtual void handleMouseOver(bool updateInventory);

View file

@ -699,7 +699,7 @@ void ScummEngine_v0::verbExec() {
_activeObject = 0; _activeObject = 0;
_activeObject2 = 0; _activeObject2 = 0;
} }
_walkToObjectIdx = 0; _walkToObjectState = kWalkToObjectStateDone;
return; return;
} }
@ -845,7 +845,7 @@ void ScummEngine_v0::checkExecVerbs() {
_redrawSentenceLine = true; _redrawSentenceLine = true;
if (_activeVerb == kVerbWalkTo && zone->number == kMainVirtScreen) { if (_activeVerb == kVerbWalkTo && zone->number == kMainVirtScreen) {
_walkToObjectIdx = 0; _walkToObjectState = kWalkToObjectStateDone;
execute = true; execute = true;
} }
} }