From 53852dd52de16221829a888a724394d5af390fa9 Mon Sep 17 00:00:00 2001 From: Andrew Kurushin Date: Fri, 24 Dec 2004 10:22:01 +0000 Subject: - fix of 8 to 4 direction conversion - added sfSetActorState function svn-id: r16288 --- saga/actor.cpp | 8 ++++++-- saga/script.h | 4 +++- saga/sfuncs.cpp | 32 +++++++++++++++++++++++++------- saga/sthread.cpp | 37 ++++++++++++++++++++++++++++++------- 4 files changed, 64 insertions(+), 17 deletions(-) (limited to 'saga') diff --git a/saga/actor.cpp b/saga/actor.cpp index f80b3a7bcd..c4c1b2af3b 100644 --- a/saga/actor.cpp +++ b/saga/actor.cpp @@ -157,7 +157,9 @@ bool Actor::loadActorResources(ActorData * actor) { for (orient = 0; orient < ACTOR_DIRECTIONS_COUNT; orient++) { // Load all four orientations framesPointer[i].directions[orient].frameIndex = readS.readUint16(); - framesPointer[i].directions[orient].frameCount = readS.readUint16(); + framesPointer[i].directions[orient].frameCount = readS.readSint16(); + if (framesPointer[i].directions[orient].frameCount < 0) + warning("frameCount < 0", framesPointer[i].directions[orient].frameCount); if (framesPointer[i].directions[orient].frameIndex > lastFrame) { lastFrame = framesPointer[i].directions[orient].frameIndex; } @@ -228,6 +230,7 @@ void Actor::updateActorsScene() { ActorFrameRange *Actor::getActorFrameRange(uint16 actorId, int frameType) { ActorData *actor; + int fourDirection; actor = getActor(actorId); if (actor->disabled) @@ -239,7 +242,8 @@ ActorFrameRange *Actor::getActorFrameRange(uint16 actorId, int frameType) { if ((actor->facingDirection < kDirUp) || (actor->facingDirection > kDirUpLeft)) error("Actor::getActorFrameRange Wrong direction 0x%X actorId 0x%X", actor->facingDirection, actorId); - return &actor->frames[frameType].directions[actor->facingDirection]; + fourDirection = ActorDirectectionsLUT[actor->facingDirection]; + return &actor->frames[frameType].directions[fourDirection]; } void Actor::handleSpeech(int msec) { diff --git a/saga/script.h b/saga/script.h index 78c42779bf..65dd100ecf 100644 --- a/saga/script.h +++ b/saga/script.h @@ -112,6 +112,7 @@ enum CycleFlags { struct SCRIPT_THREAD { int flags; // ThreadFlags int waitType; // ThreadWaitTypes + void *threadObj; // which object we're handling uint sleepTime; int ep_num; // Entrypoint number @@ -262,6 +263,7 @@ public: void SThreadCompleteThread(void); int SThreadDestroy(SCRIPT_THREAD *thread); + void wakeUpActorThread(int waitType, void *threadObj); void wakeUpThreads(int waitType); void wakeUpThreadsDelayed(int waitType, int sleepTime); @@ -310,7 +312,7 @@ private: int SF_startAnim(SCRIPTFUNC_PARAMS); int SF_actorWalkToAsync(SCRIPTFUNC_PARAMS); int SF_enableZone(SCRIPTFUNC_PARAMS); - int SF_setActorState(SCRIPTFUNC_PARAMS); + int sfSetActorState(SCRIPTFUNC_PARAMS); int scriptMoveTo(SCRIPTFUNC_PARAMS); int SF_sceneEq(SCRIPTFUNC_PARAMS); int SF_dropObject(SCRIPTFUNC_PARAMS); diff --git a/saga/sfuncs.cpp b/saga/sfuncs.cpp index ad1604e472..5d87049945 100644 --- a/saga/sfuncs.cpp +++ b/saga/sfuncs.cpp @@ -74,7 +74,7 @@ void Script::setupScriptFuncList(void) { OPCODE(SF_startAnim), OPCODE(SF_actorWalkToAsync), OPCODE(SF_enableZone), - OPCODE(SF_setActorState), + OPCODE(sfSetActorState), OPCODE(scriptMoveTo), OPCODE(SF_sceneEq), OPCODE(SF_dropObject), @@ -247,6 +247,7 @@ int Script::sfSetActorFacing(SCRIPTFUNC_PARAMS) { actor = _vm->_actor->getActor(actorId); actor->facingDirection = actor->actionDirection = actorDirection; + actor->targetObject = ID_NOTHING; return SUCCESS; } @@ -507,11 +508,24 @@ int Script::SF_enableZone(SCRIPTFUNC_PARAMS) { } // Script function #29 (0x1D) -int Script::SF_setActorState(SCRIPTFUNC_PARAMS) { - ScriptDataWord param1 = thread->pop(); - ScriptDataWord param2 = thread->pop(); +// Param1: actor id +// Param2: current action +int Script::sfSetActorState(SCRIPTFUNC_PARAMS) { + uint16 actorId; + int currentAction; + ActorData *actor; + + actorId = getSWord(thread->pop()); + currentAction = getSWord(thread->pop()); + + actor = _vm->_actor->getActor(actorId); + + if ((currentAction >= kActionWalkToPoint) && (currentAction <= kActionWalkToPoint)) { + wakeUpActorThread(kWaitTypeWalk, actor); + } + actor->currentAction = currentAction; + actor->actorFlags &= ~kActorBackwards; - debug(1, "stub: SF_setActorState(%d, %d)", param1, param2); return SUCCESS; } @@ -742,8 +756,11 @@ int Script::sfSetFrame(SCRIPTFUNC_PARAMS) { frameRange = _vm->_actor->getActorFrameRange(actorId, frameType); - if (frameRange->frameCount <= frameOffset) - error("Wrong frameOffset 0x%X", frameOffset); + if (frameRange->frameCount <= frameOffset) { + // frameRange = _vm->_actor->getActorFrameRange(actorId, frameType); + + warning("Wrong frameOffset 0x%X", frameOffset); + } actor->frameNumber = frameRange->frameIndex + frameOffset; if (actor->currentAction != kActionFall) { @@ -839,6 +856,7 @@ int Script::sfPlaceActor(SCRIPTFUNC_PARAMS) { actor->location.x = actorLocation.x; actor->location.y = actorLocation.y; actor->facingDirection = actor->actionDirection = actorDirection; + if (frameType >= 0) { frameRange = _vm->_actor->getActorFrameRange(actorId, frameType); diff --git a/saga/sthread.cpp b/saga/sthread.cpp index 98e3d6c547..34d4af07ae 100644 --- a/saga/sthread.cpp +++ b/saga/sthread.cpp @@ -63,6 +63,18 @@ SCRIPT_THREAD *Script::SThreadCreate() { return new_thread; } +void Script::wakeUpActorThread(int waitType, void *threadObj) { + SCRIPT_THREAD *thread; + ScriptThreadList::iterator threadIterator; + + for (threadIterator = _threadList.begin(); threadIterator != _threadList.end(); ++threadIterator) { + thread = threadIterator.operator->(); + if ((thread->flags & kTFlagWaiting) && (thread->waitType == waitType) && (thread->threadObj == threadObj)) { + thread->flags &= ~kTFlagWaiting; + } + } +} + void Script::wakeUpThreads(int waitType) { SCRIPT_THREAD *thread; ScriptThreadList::iterator threadIterator; @@ -109,15 +121,26 @@ int Script::executeThreads(uint msec) { continue; } - if ((thread->flags & kTFlagWaiting) && (thread->waitType == kWaitTypeDelay)) { - if (thread->sleepTime < msec) { - thread->sleepTime = 0; + if (thread->flags & kTFlagWaiting) { + + if (thread->waitType == kWaitTypeDelay) { + if (thread->sleepTime < msec) { + thread->sleepTime = 0; + } else { + thread->sleepTime -= msec; + } + + if (thread->sleepTime == 0) + thread->flags &= ~kTFlagWaiting; } else { - thread->sleepTime -= msec; + if (thread->waitType == kWaitTypeWalk) { + ActorData *actor; + actor = (ActorData *)thread->threadObj; + if (actor->currentAction == kActionWait) { + thread->flags &= ~kTFlagWaiting; + } + } } - - if (thread->sleepTime == 0) - thread->flags &= ~kTFlagWaiting; } if (!(thread->flags & kTFlagWaiting)) -- cgit v1.2.3