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");
_walkToObject = object;
_walkToObjectIdx = getObjectIndex(object);
_walkToObjectState = kWalkToObjectStateWalk;
if (OBJECT_V0_TYPE(object) == kObjectV0TypeActor) {
walkActorToActor(VAR(VAR_EGO), OBJECT_V0_ID(object), 4);
@ -1153,18 +1153,51 @@ void ScummEngine_v0::walkToActorOrObject(int object) {
if (a->_miscflags & kActorMiscFlagFreeze)
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() {
if (_walkToObjectIdx) {
ActorC64 *a = (ActorC64 *)derefActor(VAR(VAR_EGO), "checkAndRunSentenceScript");
if (a->_moving)
if (checkPendingWalkAction())
return;
// TODO: change actor facing
_walkToObjectIdx = 0;
runSentenceScript();
return;
}
if (!_sentenceNum || _sentence[_sentenceNum - 1].freezeCount)
return;
@ -1214,7 +1247,7 @@ void ScummEngine_v0::checkAndRunSentenceScript() {
runSentenceScript();
if (_currentMode == kModeKeypad) {
_walkToObjectIdx = 0;
_walkToObjectState = kWalkToObjectStateDone;
}
}

View file

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

View file

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

View file

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