diff options
Diffstat (limited to 'engines/saga')
-rw-r--r-- | engines/saga/actor.cpp | 262 | ||||
-rw-r--r-- | engines/saga/actor.h | 59 | ||||
-rw-r--r-- | engines/saga/actor_walk.cpp | 30 | ||||
-rw-r--r-- | engines/saga/events.cpp | 27 | ||||
-rw-r--r-- | engines/saga/events.h | 11 | ||||
-rw-r--r-- | engines/saga/isomap.cpp | 11 |
6 files changed, 168 insertions, 232 deletions
diff --git a/engines/saga/actor.cpp b/engines/saga/actor.cpp index 6d2fded39c..9a4643ebcf 100644 --- a/engines/saga/actor.cpp +++ b/engines/saga/actor.cpp @@ -42,12 +42,38 @@ namespace Saga { ActorData::ActorData() { - memset(this, 0, sizeof(*this)); -} + _frames = NULL; + _frameListResourceId = 0; + _speechColor = 0; + _inScene = false; + + _actorFlags = 0; + _currentAction = 0; + _facingDirection = 0; + _actionDirection = 0; + _actionCycle = 0; + _targetObject = 0; + _lastZone = NULL; + + _cycleFrameSequence = 0; + _cycleDelay = 0; + _cycleTimeCount = 0; + _cycleFlags = 0; + + _fallVelocity = 0; + _fallAcceleration = 0; + _fallPosition = 0; + + _dragonBaseFrame = 0; + _dragonStepCycle = 0; + _dragonMoveType = 0; + + _frameNumber = 0; -ActorData::~ActorData() { - if (!_shareFrames) - free(_frames); + _walkStepsCount = 0; + _walkStepIndex = 0; + + _walkFrameSequence = 0; } void ActorData::saveState(Common::OutSaveFile *out) { @@ -190,24 +216,13 @@ Actor::Actor(SagaEngine *vm) : _vm(vm) { int i; byte *stringsPointer; size_t stringsLength; - ActorData *actor; - ObjectData *obj; debug(9, "Actor::Actor()"); _handleActionDiv = 15; - _actors = NULL; - _actorsCount = 0; - - _objs = NULL; - _objsCount = 0; - #ifdef ACTOR_DEBUG _debugPointsCount = 0; #endif - _protagStates = NULL; - _protagStatesCount = 0; - _pathList.resize(600); _pathListIndex = 0; @@ -243,12 +258,11 @@ Actor::Actor(SagaEngine *vm) : _vm(vm) { } if (_vm->getGameId() == GID_ITE) { - _actorsCount = ITE_ACTORCOUNT; - _actors = (ActorData **)malloc(_actorsCount * sizeof(*_actors)); - for (i = 0; i < _actorsCount; i++) { - actor = _actors[i] = new ActorData(); - actor->_id = actorIndexToId(i); + _actors.resize(ITE_ACTORCOUNT); + i = 0; + for (ActorDataArray::iterator actor = _actors.begin(); actor != _actors.end(); ++actor, i++) { actor->_index = i; + actor->_id = actorIndexToId(actor->_index); debug(9, "init actor id=%d index=%d", actor->_id, actor->_index); actor->_nameIndex = ITE_ActorTable[i].nameIndex; actor->_scriptEntrypointNumber = ITE_ActorTable[i].scriptEntrypointNumber; @@ -270,12 +284,11 @@ Actor::Actor(SagaEngine *vm) : _vm(vm) { warning("Disabling actor Id=%d index=%d", actor->_id, actor->_index); } } - _objsCount = ITE_OBJECTCOUNT; - _objs = (ObjectData **)malloc(_objsCount * sizeof(*_objs)); - for (i = 0; i < _objsCount; i++) { - obj = _objs[i] = new ObjectData(); - obj->_id = objIndexToId(i); + _objs.resize(ITE_OBJECTCOUNT); + i = 0; + for (ObjectDataArray::iterator obj = _objs.begin(); obj != _objs.end(); ++obj, i++) { obj->_index = i; + obj->_id = objIndexToId(obj->_index); debug(9, "init obj id=%d index=%d", obj->_id, obj->_index); obj->_nameIndex = ITE_ObjectTable[i].nameIndex; obj->_scriptEntrypointNumber = ITE_ObjectTable[i].scriptEntrypointNumber; @@ -294,54 +307,33 @@ Actor::Actor(SagaEngine *vm) : _vm(vm) { Actor::~Actor() { debug(9, "Actor::~Actor()"); - - //release resources - freeProtagStates(); - freeActorList(); - freeObjList(); -} - -void Actor::freeProtagStates() { - int i; - for (i = 0; i < _protagStatesCount; i++) { - free(_protagStates[i]._frames); - } - free(_protagStates); - _protagStates = NULL; - _protagStatesCount = 0; } -void Actor::loadFrameList(int frameListResourceId, ActorFrameSequence *&framesPointer, int &framesCount) { +void Actor::loadFrameList(int frameListResourceId, ActorFrameSequences &frames) { byte *resourcePointer; size_t resourceLength; debug(9, "Loading frame resource id %d", frameListResourceId); _vm->_resource->loadResource(_actorContext, frameListResourceId, resourcePointer, resourceLength); - framesCount = resourceLength / 16; - debug(9, "Frame resource contains %d frames (res length is %d)", framesCount, (int)resourceLength); - - framesPointer = (ActorFrameSequence *)malloc(sizeof(ActorFrameSequence) * framesCount); - if (framesPointer == NULL && framesCount != 0) { - memoryError("Actor::loadFrameList"); - } + frames.resize(resourceLength / 16); + debug(9, "Frame resource contains %d frames (res length is %d)", frames.size(), (int)resourceLength); MemoryReadStreamEndian readS(resourcePointer, resourceLength, _actorContext->isBigEndian()); - for (int i = 0; i < framesCount; i++) { - debug(9, "frameType %d", i); + for (ActorFrameSequences::iterator frame = frames.begin(); frame != frames.end(); ++frame) { for (int orient = 0; orient < ACTOR_DIRECTIONS_COUNT; orient++) { // Load all four orientations - framesPointer[i].directions[orient].frameIndex = readS.readUint16(); + frame->directions[orient].frameIndex = readS.readUint16(); if (_vm->getGameId() == GID_ITE) { - framesPointer[i].directions[orient].frameCount = readS.readSint16(); + frame->directions[orient].frameCount = readS.readSint16(); } else { - framesPointer[i].directions[orient].frameCount = readS.readByte(); + frame->directions[orient].frameCount = readS.readByte(); readS.readByte(); } - if (framesPointer[i].directions[orient].frameCount < 0) - warning("frameCount < 0 (%d)", framesPointer[i].directions[orient].frameCount); - debug(9, "frameIndex %d frameCount %d", framesPointer[i].directions[orient].frameIndex, framesPointer[i].directions[orient].frameCount); + if (frame->directions[orient].frameCount < 0) + warning("frameCount < 0 (%d)", frame->directions[orient].frameCount); + debug(9, "frameIndex %d frameCount %d", frame->directions[orient].frameIndex, frame->directions[orient].frameCount); } } @@ -352,9 +344,8 @@ bool Actor::loadActorResources(ActorData *actor) { bool gotSomething = false; if (actor->_frameListResourceId) { - loadFrameList(actor->_frameListResourceId, actor->_frames, actor->_framesCount); - - actor->_shareFrames = false; + loadFrameList(actor->_frameListResourceId, actor->_framesContainer); + actor->_frames = &actor->_framesContainer; gotSomething = true; } else { @@ -374,28 +365,18 @@ bool Actor::loadActorResources(ActorData *actor) { return gotSomething; } -void Actor::freeActorList() { - int i; - ActorData *actor; - for (i = 0; i < _actorsCount; i++) { - actor = _actors[i]; - delete actor; - } - free(_actors); - _actors = NULL; - _actorsCount = 0; -} - void Actor::loadActorSpriteList(ActorData *actor) { uint lastFrame = 0; uint curFrameIndex; int resourceId = actor->_spriteListResourceId; - - for (int i = 0; i < actor->_framesCount; i++) { - for (int orient = 0; orient < ACTOR_DIRECTIONS_COUNT; orient++) { - curFrameIndex = actor->_frames[i].directions[orient].frameIndex; - if (curFrameIndex > lastFrame) { - lastFrame = curFrameIndex; + + if (actor->_frames != NULL) { + for (ActorFrameSequences::const_iterator i = actor->_frames->begin(); i != actor->_frames->end(); ++i) { + for (int orient = 0; orient < ACTOR_DIRECTIONS_COUNT; orient++) { + curFrameIndex = i->directions[orient].frameIndex; + if (curFrameIndex > lastFrame) { + lastFrame = curFrameIndex; + } } } } @@ -417,7 +398,6 @@ void Actor::loadActorSpriteList(ActorData *actor) { void Actor::loadActorList(int protagonistIdx, int actorCount, int actorsResourceID, int protagStatesCount, int protagStatesResourceID) { int i, j; - ActorData *actor; byte* actorListData; size_t actorListLength; byte walk[128]; @@ -427,23 +407,19 @@ void Actor::loadActorList(int protagonistIdx, int actorCount, int actorsResource int walkStepCount; int stateResourceId; - freeActorList(); - _vm->_resource->loadResource(_actorContext, actorsResourceID, actorListData, actorListLength); - _actorsCount = actorCount; - - if (actorListLength != (uint)_actorsCount * ACTOR_INHM_SIZE) { + if (actorListLength != (uint)actorCount * ACTOR_INHM_SIZE) { error("Actor::loadActorList wrong actorlist length"); } MemoryReadStream actorS(actorListData, actorListLength); - _actors = (ActorData **)malloc(_actorsCount * sizeof(*_actors)); - for (i = 0; i < _actorsCount; i++) { - actor = _actors[i] = new ActorData(); - actor->_id = objectIndexToId(kGameObjectActor, i); //actorIndexToId(i); + _actors.resize(actorCount); + i = 0; + for (ActorDataArray::iterator actor = _actors.begin(); actor != _actors.end(); ++actor, i++) { actor->_index = i; + actor->_id = objectIndexToId(kGameObjectActor, actor->_index); //actorIndexToId(i); debug(4, "init actor id=0x%X index=%d", actor->_id, actor->_index); actorS.readUint32LE(); //next displayed actorS.readByte(); //type @@ -509,25 +485,20 @@ void Actor::loadActorList(int protagonistIdx, int actorCount, int actorsResource } free(actorListData); - _actors[protagonistIdx]->_flags |= kProtagonist | kExtended; + _actors[protagonistIdx]._flags |= kProtagonist | kExtended; - for (i = 0; i < _actorsCount; i++) { - actor = _actors[i]; + for (ActorDataArray::iterator actor = _actors.begin(); actor != _actors.end(); ++actor) { //if (actor->_flags & kProtagonist) { loadActorResources(actor); //break; //} } - _centerActor = _protagonist = _actors[protagonistIdx]; + _centerActor = _protagonist = &_actors[protagonistIdx]; _protagState = 0; if (protagStatesResourceID) { - if (!_protagonist->_shareFrames) - free(_protagonist->_frames); - freeProtagStates(); - - _protagStates = (ProtagStateData *)malloc(sizeof(ProtagStateData) * protagStatesCount); + _protagStates.resize(protagStatesCount); byte *idsResourcePointer; size_t idsResourceLength; @@ -544,49 +515,31 @@ void Actor::loadActorList(int protagonistIdx, int actorCount, int actorsResource for (i = 0; i < protagStatesCount; i++) { stateResourceId = statesIds.readUint32LE(); - loadFrameList(stateResourceId, _protagStates[i]._frames, _protagStates[i]._framesCount); + loadFrameList(stateResourceId, _protagStates[i]._frames); } free(idsResourcePointer); - _protagonist->_frames = _protagStates[_protagState]._frames; - _protagonist->_framesCount = _protagStates[_protagState]._framesCount; - _protagonist->_shareFrames = true; + _protagonist->_frames = &_protagStates[_protagState]._frames; } - _protagStatesCount = protagStatesCount; -} - -void Actor::freeObjList() { - int i; - ObjectData *object; - for (i = 0; i < _objsCount; i++) { - object = _objs[i]; - delete object; - } - free(_objs); - _objs = NULL; - _objsCount = 0; } void Actor::loadObjList(int objectCount, int objectsResourceID) { - int i; + uint i; int frameListResourceId; - ObjectData *object; byte* objectListData; size_t objectListLength; - freeObjList(); _vm->_resource->loadResource(_actorContext, objectsResourceID, objectListData, objectListLength); - _objsCount = objectCount; + _objs.resize(objectCount); MemoryReadStream objectS(objectListData, objectListLength); - _objs = (ObjectData **)malloc(_objsCount * sizeof(*_objs)); - for (i = 0; i < _objsCount; i++) { - object = _objs[i] = new ObjectData(); - object->_id = objectIndexToId(kGameObjectObject, i); + i = 0; + for (ObjectDataArray::iterator object = _objs.begin(); object != _objs.end(); ++object, i++) { object->_index = i; + object->_id = objectIndexToId(kGameObjectObject, object->_index); debug(9, "init object id=%d index=%d", object->_id, object->_index); objectS.readUint32LE(); //next displayed objectS.readByte(); //type @@ -669,7 +622,7 @@ ObjectData *Actor::getObj(uint16 objId) { if (!validObjId(objId)) error("Actor::getObj Wrong objId 0x%X", objId); - obj = _objs[objIdToIndex(objId)]; + obj = &_objs[objIdToIndex(objId)]; if (obj->_disabled) error("Actor::getObj disabled objId 0x%X", objId); @@ -692,7 +645,7 @@ ActorData *Actor::getActor(uint16 actorId) { return _protagonist; } - actor = _actors[actorIdToIndex(actorId)]; + actor = &_actors[actorIdToIndex(actorId)]; if (actor->_disabled) error("Actor::getActor disabled actorId 0x%X", actorId); @@ -705,12 +658,8 @@ void Actor::setProtagState(int state) { #ifdef ENABLE_IHNM if (_vm->getGameId() == GID_IHNM) { - if (!_protagonist->_shareFrames) - free(_protagonist->_frames); - _protagonist->_frames = _protagStates[state]._frames; - _protagonist->_framesCount = _protagStates[state]._framesCount; - _protagonist->_shareFrames = true; + _protagonist->_frames = &_protagStates[state]._frames; } #endif @@ -773,15 +722,18 @@ 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); + ActorFrameSequences *frames; + frames = actor->_frames; + if (_vm->getGameId() == GID_ITE) { - if (frameType >= actor->_framesCount) { - warning("Actor::getActorFrameRange Wrong frameType 0x%X (%d) actorId 0x%X", frameType, actor->_framesCount, actorId); + if (uint(frameType) >= frames->size()) { + warning("Actor::getActorFrameRange Wrong frameType 0x%X (%d) actorId 0x%X", frameType, frames->size(), actorId); return &def; } fourDirection = actorDirectionsLUT[actor->_facingDirection]; - return &actor->_frames[frameType].directions[fourDirection]; + return &(*frames)[frameType].directions[fourDirection]; } #ifdef ENABLE_IHNM @@ -792,12 +744,12 @@ ActorFrameRange *Actor::getActorFrameRange(uint16 actorId, int frameType) { // Both of them are invisible and immovable // There is no point to keep throwing warnings about this, the original checks for // a valid framecount too - if (actor->_framesCount == 0) { + if ((frames == NULL) || (frames->empty())) { return &def; } - frameType = CLIP(frameType, 0, actor->_framesCount - 1); + frameType = CLIP(frameType, 0, int(frames->size() - 1)); fourDirection = actorDirectionsLUT[actor->_facingDirection]; - return &actor->_frames[frameType].directions[fourDirection]; + return &(*frames)[frameType].directions[fourDirection]; } #endif @@ -1061,9 +1013,6 @@ void Actor::drawOrderListAdd(const CommonObjectDataPointer& element, CompareFunc } void Actor::createDrawOrderList() { - int i; - ActorData *actor; - ObjectData *obj; CompareFunction compareFunction = 0; if (_vm->_scene->getFlags() & kSceneFlagISO) { @@ -1078,8 +1027,7 @@ void Actor::createDrawOrderList() { } _drawOrderList.clear(); - for (i = 0; i < _actorsCount; i++) { - actor = _actors[i]; + for (ActorDataArray::iterator actor = _actors.begin(); actor != _actors.end(); ++actor) { if (!actor->_inScene) continue; @@ -1089,8 +1037,7 @@ void Actor::createDrawOrderList() { } } - for (i = 0; i < _objsCount; i++) { - obj = _objs[i]; + for (ObjectDataArray::iterator obj = _objs.begin(); obj != _objs.end(); ++obj) { if (obj->_disabled) continue; @@ -1279,9 +1226,9 @@ void Actor::actorSpeech(uint16 actorId, const char **strings, int stringsCount, // Check Script::sfDropObject for the other part of this hack if (_vm->getGameId() == GID_IHNM && _vm->_scene->currentChapterNumber() == 3 && _vm->_scene->currentSceneNumber() == 59 && _activeSpeech.sampleResourceId == 286) { - for (i = 0; i < _objsCount; i++) { - if (_objs[i]->_id == 16385) { // the compact disk - _objs[i]->_sceneNumber = 59; + for (ObjectDataArray::iterator obj = _objs.begin(); obj != _objs.end(); ++obj) { + if (obj->_id == 16385) { // the compact disk + obj->_sceneNumber = 59; break; } } @@ -1353,36 +1300,31 @@ void Actor::abortSpeech() { } void Actor::saveState(Common::OutSaveFile *out) { - uint16 i; out->writeSint16LE(getProtagState()); - for (i = 0; i < _actorsCount; i++) { - ActorData *a = _actors[i]; - a->saveState(out); + for (ActorDataArray::iterator actor = _actors.begin(); actor != _actors.end(); ++actor) { + actor->saveState(out); } - for (i = 0; i < _objsCount; i++) { - ObjectData *o = _objs[i]; - o->saveState(out); + for (ObjectDataArray::iterator obj = _objs.begin(); obj != _objs.end(); ++obj) { + obj->saveState(out); } } void Actor::loadState(Common::InSaveFile *in) { - int32 i; int16 protagState = in->readSint16LE(); - if (protagState != 0 || _protagonist->_shareFrames) + if (protagState != 0 || (_protagonist->shareFrames())) { setProtagState(protagState); + } - for (i = 0; i < _actorsCount; i++) { - ActorData *a = _actors[i]; - a->loadState(_vm->getCurrentLoadVersion(), in); + for (ActorDataArray::iterator actor = _actors.begin(); actor != _actors.end(); ++actor) { + actor->loadState(_vm->getCurrentLoadVersion(), in); } - for (i = 0; i < _objsCount; i++) { - ObjectData *o = _objs[i]; - o->loadState(in); + for (ObjectDataArray::iterator obj = _objs.begin(); obj != _objs.end(); ++obj) { + obj->loadState(in); } } diff --git a/engines/saga/actor.h b/engines/saga/actor.h index ede2ee714b..2b6b5c2a3b 100644 --- a/engines/saga/actor.h +++ b/engines/saga/actor.h @@ -196,7 +196,7 @@ struct ActorFrameSequence { ActorFrameRange directions[ACTOR_DIRECTIONS_COUNT]; }; -//typedef Common::Array<ActorFrameSequence> ActorFrameSequences; +typedef Common::Array<ActorFrameSequence> ActorFrameSequences; uint pathLine(PointList &pointList, uint idx, const Point &point1, const Point &point2); @@ -325,6 +325,21 @@ public: _screenDepth = in->readSint32LE(); _screenScale = in->readSint32LE(); } + + CommonObjectData() { + _disabled = false; + _index = 0; + _id = 0; + _scriptEntrypointNumber = 0; + + _flags = 0; + _nameIndex = 0; + _sceneNumber = 0; + _spriteListResourceId = 0; + + _screenDepth = 0; + _screenScale = 0; + } }; typedef CommonObjectData *CommonObjectDataPointer; @@ -335,19 +350,21 @@ class ObjectData: public CommonObjectData { public: //constant uint16 _interactBits; + ObjectData() { - memset(this, 0, sizeof(*this)); + _interactBits = 0; } }; +typedef Common::Array<ObjectData> ObjectDataArray; + class ActorData: public CommonObjectData { public: //constant SpriteList _spriteList; // sprite list data - bool _shareFrames; - ActorFrameSequence *_frames; // Actor's frames - int _framesCount; // Actor's frames count + ActorFrameSequences *_frames; // Actor's frames + ActorFrameSequences _framesContainer; // Actor's frames int _frameListResourceId; // Actor's frame list resource id byte _speechColor; // Actor dialogue color @@ -391,18 +408,21 @@ public: public: ActorData(); - ~ActorData(); void saveState(Common::OutSaveFile *out); void loadState(uint32 version, Common::InSaveFile *in); void cycleWrap(int cycleLimit); void addWalkStepPoint(const Point &point); + bool shareFrames() { + return ((_frames != NULL) && (_frames != &_framesContainer)); + } }; +typedef Common::Array<ActorData> ActorDataArray; + struct ProtagStateData { - ActorFrameSequence *_frames; // Actor's frames - int _framesCount; // Actor's frames count + ActorFrameSequences _frames; // Actor's frames }; @@ -447,15 +467,17 @@ public: void cmdActorWalkTo(int argc, const char **argv); - bool validActorId(uint16 id) { return (id == ID_PROTAG) || ((id >= objectIndexToId(kGameObjectActor, 0)) && (id < objectIndexToId(kGameObjectActor, _actorsCount))); } + bool validActorId(uint16 id) { + return (id == ID_PROTAG) || ((id >= objectIndexToId(kGameObjectActor, 0)) && (id < objectIndexToId(kGameObjectActor, _actors.size()))); + } int actorIdToIndex(uint16 id) { return (id == ID_PROTAG) ? 0 : objectIdToIndex(id); } uint16 actorIndexToId(int index) { return (index == 0) ? ID_PROTAG : objectIndexToId(kGameObjectActor, index); } ActorData *getActor(uint16 actorId); - ActorData *getFirstActor() { return _actors[0]; } + ActorData *getFirstActor() { return &_actors.front(); } // clarification: Obj - means game object, such Hat, Spoon etc, Object - means Actor,Obj,HitZone,StepZone - bool validObjId(uint16 id) { return (id >= objectIndexToId(kGameObjectObject, 0)) && (id < objectIndexToId(kGameObjectObject, _objsCount)); } + bool validObjId(uint16 id) { return (id >= objectIndexToId(kGameObjectObject, 0)) && (id < objectIndexToId(kGameObjectObject, _objs.size())); } int objIdToIndex(uint16 id) { return objectIdToIndex(id); } uint16 objIndexToId(int index) { return objectIndexToId(kGameObjectObject, index); } ObjectData *getObj(uint16 objId); @@ -522,18 +544,14 @@ public: void setProtagState(int state); int getProtagState() { return _protagState; } - void freeProtagStates(); - - void freeActorList(); void loadActorList(int protagonistIdx, int actorCount, int actorsResourceID, int protagStatesCount, int protagStatesResourceID); - void freeObjList(); void loadObjList(int objectCount, int objectsResourceID); protected: friend class Script; bool loadActorResources(ActorData *actor); - void loadFrameList(int frameListResourceId, ActorFrameSequence *&framesPointer, int &framesCount); + void loadFrameList(int frameListResourceId, ActorFrameSequences &frames); private: void stepZoneAction(ActorData *actor, const HitZone *hitZone, bool exit, bool stopped); void loadActorSpriteList(ActorData *actor); @@ -581,11 +599,9 @@ private: protected: //constants - int _actorsCount; - ActorData **_actors; + ActorDataArray _actors; - int _objsCount; - ObjectData **_objs; + ObjectDataArray _objs; SagaEngine *_vm; ResourceContext *_actorContext; @@ -610,8 +626,7 @@ protected: bool _dragonHunt; private: - ProtagStateData *_protagStates; - int _protagStatesCount; + Common::Array<ProtagStateData> _protagStates; //path stuff struct PathNode { diff --git a/engines/saga/actor_walk.cpp b/engines/saga/actor_walk.cpp index b6e74fa2bf..5a8ea0c856 100644 --- a/engines/saga/actor_walk.cpp +++ b/engines/saga/actor_walk.cpp @@ -179,9 +179,8 @@ void Actor::actorFaceTowardsPoint(uint16 actorId, const Location &toLocation) { } void Actor::updateActorsScene(int actorsEntrance) { - int i, j; + int j; int followerDirection; - ActorData *actor; Location tempLocation; Location possibleLocation; Point delta; @@ -196,14 +195,13 @@ void Actor::updateActorsScene(int actorsEntrance) { _activeSpeech.playing = false; _protagonist = NULL; - for (i = 0; i < _actorsCount; i++) { - actor = _actors[i]; + for (ActorDataArray::iterator actor = _actors.begin(); actor != _actors.end(); ++actor) { actor->_inScene = false; actor->_spriteList.clear(); if (actor->_disabled) { continue; } - if ((actor->_flags & (kProtagonist | kFollower)) || (i == 0)) { + if ((actor->_flags & (kProtagonist | kFollower)) || (actor->_index == 0)) { if (actor->_flags & kProtagonist) { actor->_finalTarget = actor->_location; _centerActor = _protagonist = actor; @@ -266,8 +264,7 @@ void Actor::updateActorsScene(int actorsEntrance) { followerDirection = _protagonist->_facingDirection + 3; calcScreenPosition(_protagonist); - for (i = 0; i < _actorsCount; i++) { - actor = _actors[i]; + for (ActorDataArray::iterator actor = _actors.begin(); actor != _actors.end(); ++actor) { if (actor->_flags & (kFollower)) { actor->_facingDirection = actor->_actionDirection = _protagonist->_facingDirection; actor->_currentAction = kActionWait; @@ -323,8 +320,6 @@ void Actor::updateActorsScene(int actorsEntrance) { } void Actor::handleActions(int msec, bool setup) { - int i; - ActorData *actor; ActorFrameRange *frameRange; int state; int speed; @@ -336,12 +331,11 @@ void Actor::handleActions(int msec, bool setup) { Point hitPoint; Location pickLocation; - for (i = 0; i < _actorsCount; i++) { - actor = _actors[i]; + for (ActorDataArray::iterator actor = _actors.begin(); actor != _actors.end(); ++actor) { if (!actor->_inScene) continue; - if ((_vm->getGameId() == GID_ITE) && (i == ACTOR_DRAGON_INDEX)) { + if ((_vm->getGameId() == GID_ITE) && (actor->_index == ACTOR_DRAGON_INDEX)) { moveDragon(actor); continue; } @@ -866,8 +860,6 @@ bool Actor::followProtagonist(ActorData *actor) { bool Actor::actorWalkTo(uint16 actorId, const Location &toLocation) { ActorData *actor; - ActorData *anotherActor; - int i; Rect testBox; Rect testBox2; @@ -943,7 +935,7 @@ bool Actor::actorWalkTo(uint16 actorId, const Location &toLocation) { int max = _vm->getGameId() == GID_ITE ? 8 : 4; - for (i = 1; i < max; i++) { + for (int i = 1; i < max; i++) { pointAdd = pointFrom; pointAdd.y += i; if (_vm->_scene->canWalk(pointAdd)) { @@ -978,9 +970,7 @@ bool Actor::actorWalkTo(uint16 actorId, const Location &toLocation) { collision.x = ACTOR_COLLISION_WIDTH * actor->_screenScale / (256 * 2); collision.y = ACTOR_COLLISION_HEIGHT * actor->_screenScale / (256 * 2); - - for (i = 0; (i < _actorsCount) && (_barrierCount < ACTOR_BARRIERS_MAX); i++) { - anotherActor = _actors[i]; + for (ActorDataArray::iterator anotherActor = _actors.begin(); (anotherActor != _actors.end()) && (_barrierCount < ACTOR_BARRIERS_MAX); ++anotherActor) { if (!anotherActor->_inScene) continue; if (anotherActor == actor) @@ -1067,8 +1057,8 @@ bool Actor::actorWalkTo(uint16 actorId, const Location &toLocation) { return false; } else { if (actor->_flags & kProtagonist) { - _actors[1]->_actorFlags &= ~kActorNoFollow; // TODO: mark all actors with kFollower flag, not only 1 and 2 - _actors[2]->_actorFlags &= ~kActorNoFollow; + _actors[1]._actorFlags &= ~kActorNoFollow; // TODO: mark all actors with kFollower flag, not only 1 and 2 + _actors[2]._actorFlags &= ~kActorNoFollow; } actor->_currentAction = (actor->_walkStepsCount >= ACTOR_MAX_STEPS_COUNT) ? kActionWalkToLink : kActionWalkToPoint; actor->_walkFrameSequence = getFrameType(kFrameWalk); diff --git a/engines/saga/events.cpp b/engines/saga/events.cpp index 193d20289d..50784fbabd 100644 --- a/engines/saga/events.cpp +++ b/engines/saga/events.cpp @@ -563,29 +563,16 @@ int Events::handleInterval(Event *event) { return kEvStDelete; } -// Schedules an event in the event list; returns a pointer to the scheduled -// event suitable for chaining if desired. -EventColumns *Events::queue(const Event &event) { - EventColumns tmp; - - _eventList.push_back(tmp); - EventColumns *res; - res = &_eventList.back(); - res->push_back(event); - - initializeEvent(res->back()); - - return res; -} - -// Places a 'add_event' on the end of an event chain given by 'head_event' -// (head_event may be in any position in the event chain) -EventColumns *Events::chain(EventColumns *eventColumns, const Event &addEvent) { +EventColumns *Events::chain(EventColumns *eventColumns, const Event &event) { + if (eventColumns == NULL) { - return queue(addEvent); + EventColumns tmp; + + _eventList.push_back(tmp); + eventColumns = &_eventList.back(); } - eventColumns->push_back(addEvent); + eventColumns->push_back(event); initializeEvent(eventColumns->back()); return eventColumns; diff --git a/engines/saga/events.h b/engines/saga/events.h index a6e42513ad..135c0beb55 100644 --- a/engines/saga/events.h +++ b/engines/saga/events.h @@ -168,8 +168,15 @@ class Events { void handleEvents(long msec); void clearList(bool playQueuedMusic = true); void freeList(); - EventColumns *queue(const Event &event); - EventColumns *chain(EventColumns *eventColumns, const Event &addEvent); + + // Schedules an event in the event list; returns a pointer to the scheduled + // event columns suitable for chaining if desired. + EventColumns *queue(const Event &event) { + return chain(NULL, event); + } + + // Places a 'event' on the end of an event columns given by 'eventColumns' + EventColumns *chain(EventColumns *eventColumns, const Event &event); private: int handleContinuous(Event *event); diff --git a/engines/saga/isomap.cpp b/engines/saga/isomap.cpp index 00903c4ae4..baa1189939 100644 --- a/engines/saga/isomap.cpp +++ b/engines/saga/isomap.cpp @@ -1161,8 +1161,6 @@ void IsoMap::placeOnTileMap(const Location &start, Location &result, int16 dista int16 vBase; int16 u; int16 v; - int i; - ActorData *actor; TilePoint tilePoint; uint16 dir; int16 dist; @@ -1183,8 +1181,7 @@ void IsoMap::placeOnTileMap(const Location &start, Location &result, int16 dista memset( &_searchArray, 0, sizeof(_searchArray)); - for (i = 0; i < _vm->_actor->_actorsCount; i++) { - actor = _vm->_actor->_actors[i]; + for (ActorDataArray::const_iterator actor = _vm->_actor->_actors.begin(); actor != _vm->_actor->_actors.end(); ++actor) { if (!actor->_inScene) continue; u = (actor->_location.u() >> 4) - uBase; @@ -1471,7 +1468,6 @@ void IsoMap::findDragonTilePath(ActorData* actor,const Location &start, const Lo } void IsoMap::findTilePath(ActorData* actor, const Location &start, const Location &end) { - ActorData *other; int i; int16 u; int16 v; @@ -1511,10 +1507,9 @@ void IsoMap::findTilePath(ActorData* actor, const Location &start, const Locatio if (!(actor->_actorFlags & kActorNoCollide) && (_vm->_scene->currentSceneResourceId() != ITE_SCENE_OVERMAP)) { - for (i = 0; i < _vm->_actor->_actorsCount; i++) { - other = _vm->_actor->_actors[i]; + for (ActorDataArray::const_iterator other = _vm->_actor->_actors.begin(); other != _vm->_actor->_actors.end(); ++other) { if (!other->_inScene) continue; - if (other == actor) continue; + if (other->_id == actor->_id) continue; u = (other->_location.u() >> 4) - uBase; v = (other->_location.v() >> 4) - vBase; |