Skip to content

Commit

Permalink
SCUMM: complete handling of pending walkTo actions for sentence commands
Browse files Browse the repository at this point in the history
in v0
  • Loading branch information
tobigun committed Feb 11, 2012
1 parent 1da7157 commit fb68456
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
53 changes: 43 additions & 10 deletions engines/scumm/script.cpp
Expand Up @@ -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);
Expand All @@ -1152,19 +1152,52 @@ void ScummEngine_v0::walkToActorOrObject(int object) {
// actor must not move if frozen
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)
return;
// TODO: change actor facing
_walkToObjectIdx = 0;
runSentenceScript();
if (checkPendingWalkAction())
return;
}

if (!_sentenceNum || _sentence[_sentenceNum - 1].freezeCount)
return;
Expand Down Expand Up @@ -1214,7 +1247,7 @@ void ScummEngine_v0::checkAndRunSentenceScript() {

runSentenceScript();
if (_currentMode == kModeKeypad) {
_walkToObjectIdx = 0;
_walkToObjectState = kWalkToObjectStateDone;
}
}

Expand Down
3 changes: 2 additions & 1 deletion engines/scumm/script_v0.cpp
Expand Up @@ -976,7 +976,8 @@ void ScummEngine_v0::resetSentence() {
_activeVerb = kVerbWalkTo;
_activeObject = 0;
_activeObject2 = 0;
_walkToObjectIdx = 0;

_walkToObjectState = kWalkToObjectStateDone;
_redrawSentenceLine = true;
}

Expand Down
9 changes: 8 additions & 1 deletion engines/scumm/scumm_v0.h
Expand Up @@ -39,6 +39,12 @@ class ScummEngine_v0 : public ScummEngine_v2 {
kModeNormal = 3, // normal playing mode
};

enum WalkToObjectState {
kWalkToObjectStateDone = 0,
kWalkToObjectStateWalk = 1,
kWalkToObjectStateTurn = 2,
};

protected:
byte _currentMode;

Expand All @@ -51,7 +57,7 @@ class ScummEngine_v0 : public ScummEngine_v2 {
int _cmdObject2; // 2nd script object or actor (see OBJECT_V0())

int _walkToObject;
int _walkToObjectIdx;
int _walkToObjectState;
bool _redrawSentenceLine;

public:
Expand Down Expand Up @@ -81,6 +87,7 @@ class ScummEngine_v0 : public ScummEngine_v2 {

virtual void runSentenceScript();
virtual void checkAndRunSentenceScript();
bool checkPendingWalkAction();
bool checkSentenceComplete();
virtual void checkExecVerbs();
virtual void handleMouseOver(bool updateInventory);
Expand Down
4 changes: 2 additions & 2 deletions engines/scumm/verbs.cpp
Expand Up @@ -699,7 +699,7 @@ void ScummEngine_v0::verbExec() {
_activeObject = 0;
_activeObject2 = 0;
}
_walkToObjectIdx = 0;
_walkToObjectState = kWalkToObjectStateDone;
return;
}

Expand Down Expand Up @@ -845,7 +845,7 @@ void ScummEngine_v0::checkExecVerbs() {

_redrawSentenceLine = true;
if (_activeVerb == kVerbWalkTo && zone->number == kMainVirtScreen) {
_walkToObjectIdx = 0;
_walkToObjectState = kWalkToObjectStateDone;
execute = true;
}
}
Expand Down

0 comments on commit fb68456

Please sign in to comment.