diff options
Diffstat (limited to 'engines/lure')
-rw-r--r-- | engines/lure/debugger.cpp | 10 | ||||
-rw-r--r-- | engines/lure/game.cpp | 2 | ||||
-rw-r--r-- | engines/lure/hotspots.cpp | 23 | ||||
-rw-r--r-- | engines/lure/hotspots.h | 9 | ||||
-rw-r--r-- | engines/lure/menu.cpp | 6 | ||||
-rw-r--r-- | engines/lure/res.cpp | 64 | ||||
-rw-r--r-- | engines/lure/res_struct.cpp | 82 | ||||
-rw-r--r-- | engines/lure/res_struct.h | 103 | ||||
-rw-r--r-- | engines/lure/room.cpp | 10 | ||||
-rw-r--r-- | engines/lure/surface.cpp | 63 | ||||
-rw-r--r-- | engines/lure/surface.h | 4 |
11 files changed, 183 insertions, 193 deletions
diff --git a/engines/lure/debugger.cpp b/engines/lure/debugger.cpp index e5d1995861..1526db8ce8 100644 --- a/engines/lure/debugger.cpp +++ b/engines/lure/debugger.cpp @@ -121,7 +121,7 @@ bool Debugger::cmd_listRooms(int argc, const char **argv) { DebugPrintf("Available rooms are:\n"); for (RoomDataList::iterator i = rooms.begin(); i != rooms.end(); ++i) { - RoomData *room = *i; + RoomData *room = (*i).get(); // Explictly note the second drawbridge room as "Alt" if (room->roomNumber == 49) { strings.getString(47, buffer); @@ -245,7 +245,7 @@ bool Debugger::cmd_hotspots(int argc, const char **argv) { // Loop for displaying active hotspots HotspotList::iterator i; for (i = res.activeHotspots().begin(); i != res.activeHotspots().end(); ++i) { - Hotspot *hotspot = *i; + Hotspot *hotspot = (*i).get(); if (hotspot->nameId() == 0) strcpy(buffer, "none"); else strings.getString(hotspot->nameId(), buffer); @@ -259,7 +259,7 @@ bool Debugger::cmd_hotspots(int argc, const char **argv) { HotspotDataList::iterator i; for (i = res.hotspotData().begin(); i != res.hotspotData().end(); ++i) { - HotspotData *hotspot = *i; + HotspotData *hotspot = (*i).get(); if (hotspot->roomNumber == roomNumber) { if (hotspot->nameId == 0) strcpy(buffer, "none"); @@ -411,7 +411,7 @@ bool Debugger::cmd_room(int argc, const char **argv) { else { RoomExitHotspotList::iterator i; for (i = exits.begin(); i != exits.end(); ++i) { - RoomExitHotspotData *rec = *i; + RoomExitHotspotData *rec = (*i).get(); DebugPrintf("\nArea - (%d,%d)-(%d,%d) Room=%d Cursor=%d Hotspot=%xh", rec->xs, rec->ys, rec->xe, rec->ye, rec->destRoomNumber, rec->cursorNum, rec->hotspotId); @@ -426,7 +426,7 @@ bool Debugger::cmd_room(int argc, const char **argv) { else { RoomExitList::iterator i2; for (i2 = room->exits.begin(); i2 != room->exits.end(); ++i2) { - RoomExitData *rec2 = *i2; + RoomExitData *rec2 = (*i2).get(); DebugPrintf("\nExit - (%d,%d)-(%d,%d) Dest=%d,(%d,%d) Dir=%s Sequence=%xh", rec2->xs, rec2->ys, rec2->xe, rec2->ye, rec2->roomNumber, diff --git a/engines/lure/game.cpp b/engines/lure/game.cpp index dfdcbfe956..c87f81618a 100644 --- a/engines/lure/game.cpp +++ b/engines/lure/game.cpp @@ -72,7 +72,7 @@ void Game::tick() { uint16 *idList = new uint16[res.activeHotspots().size()]; int idSize = 0; for (i = res.activeHotspots().begin(); i != res.activeHotspots().end(); ++i) { - Hotspot *hotspot = *i; + Hotspot *hotspot = (*i).get(); if (!_preloadFlag || ((hotspot->layer() != 0xff) && (hotspot->hotspotId() < FIRST_NONCHARACTER_ID))) diff --git a/engines/lure/hotspots.cpp b/engines/lure/hotspots.cpp index 542432a9d5..ba9f9362ff 100644 --- a/engines/lure/hotspots.cpp +++ b/engines/lure/hotspots.cpp @@ -224,7 +224,10 @@ void Hotspot::setAnimationIndex(int animIndex) { Resources &r = Resources::getReference(); // Get the animation specified - HotspotAnimData *tempAnim = r.animRecords()[animIndex]; + HotspotAnimList::iterator anim = r.animRecords().begin(); + for (int i = 0; i < animIndex; i++) + ++anim; + HotspotAnimData *tempAnim = (*anim).get(); _animId = tempAnim->animRecordId; if (_data) @@ -1161,7 +1164,7 @@ bool Hotspot::doorCloseCheck(uint16 doorId) { HotspotList::iterator i; HotspotList &lst = res.activeHotspots(); for (i = lst.begin(); i != lst.end(); ++i) { - Hotspot *hsCurrent = *i; + Hotspot *hsCurrent = (*i).get(); // Skip entry if it's the door or the character if ((hsCurrent->hotspotId() == hotspotId()) || @@ -1868,7 +1871,7 @@ void Hotspot::doStatus(HotspotData *hotspot) { HotspotDataList &list = res.hotspotData(); HotspotDataList::iterator i; for (i = list.begin(); i != list.end(); ++i) { - HotspotData *rec = *i; + HotspotData *rec = (*i).get(); if (rec->roomNumber == PLAYER_ID) { if (numItems++ == 0) strcat(buffer, ": "); @@ -3421,7 +3424,7 @@ void HotspotTickHandlers::talkAnimHandler(Hotspot &h) { if (i != entries.end()) ++i; for (; i != entries.end(); ++i) { - entry = *i; + entry = (*i).get(); uint8 flags = (uint8) (entry->descId >> 14); if (flags == 3) // Skip the entry @@ -4345,9 +4348,9 @@ void PathFinder::list(char *buffer) { printf("Pathfinder::list\n"); } - ManagedList<WalkingActionEntry *>::iterator i; + WalkingActionList::iterator i; for (i = _list.begin(); i != _list.end(); ++i) { - WalkingActionEntry *e = *i; + WalkingActionEntry *e = (*i).get(); if (buffer) { sprintf(buffer, "Direction=%d, numSteps=%d\n", e->direction(), e->numSteps()); buffer += strlen(buffer); @@ -4469,9 +4472,9 @@ void PathFinder::saveToStream(Common::WriteStream *stream) { stream->write(_layer, sizeof(RoomPathsDecompressedData)); // Save any active step sequence - ManagedList<WalkingActionEntry *>::iterator i; + WalkingActionList::iterator i; for (i = _list.begin(); i != _list.end(); ++i) { - WalkingActionEntry *entry = *i; + WalkingActionEntry *entry = (*i).get(); stream->writeByte(entry->direction()); stream->writeSint16LE(entry->rawSteps()); } @@ -4491,7 +4494,7 @@ void PathFinder::loadFromStream(Common::ReadStream *stream) { uint8 direction; while ((direction = stream->readByte()) != 0xff) { int steps = stream->readSint16LE(); - _list.push_back(new WalkingActionEntry((Direction) direction, steps)); + _list.push_back(WalkingActionList::value_type(new WalkingActionEntry((Direction) direction, steps))); } _stepCtr = stream->readSint16LE(); } @@ -4640,7 +4643,7 @@ bool Support::isCharacterInList(uint16 *lst, int numEntries, uint16 charId) { void HotspotList::saveToStream(WriteStream *stream) { HotspotList::iterator i; for (i = begin(); i != end(); ++i) { - Hotspot *hotspot = *i; + Hotspot *hotspot = (*i).get(); debugC(ERROR_INTERMEDIATE, kLureDebugAnimations, "Saving hotspot %xh", hotspot->hotspotId()); bool dynamicObject = hotspot->hotspotId() != hotspot->originalId(); stream->writeUint16LE(hotspot->originalId()); diff --git a/engines/lure/hotspots.h b/engines/lure/hotspots.h index fcbaae1a13..c6bc56a94d 100644 --- a/engines/lure/hotspots.h +++ b/engines/lure/hotspots.h @@ -112,7 +112,8 @@ class PathFinder { private: Hotspot *_hotspot; bool _inUse; - ManagedList<WalkingActionEntry *> _list; + typedef Common::List<Common::SharedPtr<WalkingActionEntry> > WalkingActionList; + WalkingActionList _list; RoomPathsDecompressedData _layer; int _stepCtr; bool _inProgress; @@ -134,10 +135,10 @@ private: void scanLine(int numScans, int changeAmount, uint16 *&pEnd, int &v); void add(Direction dir, int steps) { - _list.push_front(new WalkingActionEntry(dir, steps)); + _list.push_front(WalkingActionList::value_type(new WalkingActionEntry(dir, steps))); } void addBack(Direction dir, int steps) { - _list.push_back(new WalkingActionEntry(dir, steps)); + _list.push_back(WalkingActionList::value_type(new WalkingActionEntry(dir, steps))); } public: PathFinder(Hotspot *h); @@ -470,7 +471,7 @@ public: void loadFromStream(Common::ReadStream *stream); }; -class HotspotList: public ManagedList<Hotspot *> { +class HotspotList: public Common::List<Common::SharedPtr<Hotspot> > { public: void saveToStream(WriteStream *stream); void loadFromStream(ReadStream *stream); diff --git a/engines/lure/menu.cpp b/engines/lure/menu.cpp index a221b628ab..cecc415499 100644 --- a/engines/lure/menu.cpp +++ b/engines/lure/menu.cpp @@ -273,7 +273,7 @@ uint16 PopupMenu::ShowInventory() { HotspotDataList::iterator i; for (i = rsc.hotspotData().begin(); i != rsc.hotspotData().end(); ++i) { - HotspotData *hotspot = *i; + HotspotData *hotspot = (*i).get(); if (hotspot->roomNumber == PLAYER_ID) { idList[itemCtr] = hotspot->hotspotId; char *hotspotName = itemNames[itemCtr++] = (char *) malloc(MAX_HOTSPOT_NAME_SIZE); @@ -314,7 +314,7 @@ uint16 PopupMenu::ShowItems(Action contextAction, uint16 roomNumber) { // Loop for rooms for (ir = rooms.begin(); ir != rooms.end(); ++ir) { - RoomData *roomData = *ir; + RoomData *roomData = (*ir).get(); // Pre-condition checks for whether to skip room if ((roomData->hdrFlags != 15) && ((roomData->hdrFlags & fields.hdrFlagMask()) == 0)) continue; @@ -334,7 +334,7 @@ uint16 PopupMenu::ShowItems(Action contextAction, uint16 roomNumber) { // Loop for hotspots for (ih = hotspots.begin(); ih != hotspots.end(); ++ih) { - HotspotData *hotspot = *ih; + HotspotData *hotspot = (*ih).get(); if ((hotspot->headerFlags != 15) && ((hotspot->headerFlags & fields.hdrFlagMask()) == 0)) diff --git a/engines/lure/res.cpp b/engines/lure/res.cpp index ec8d95676c..ce35b50243 100644 --- a/engines/lure/res.cpp +++ b/engines/lure/res.cpp @@ -127,7 +127,7 @@ void Resources::reloadData() { RoomResource *rec = (RoomResource *) (mb->data() + offsetVal); RoomData *newEntry = new RoomData(rec, paths); - _roomData.push_back(newEntry); + _roomData.push_back(RoomDataList::value_type(newEntry)); uint8 numExits = rec->numExits; if (numExits > 0) { @@ -136,7 +136,7 @@ void Resources::reloadData() { for (uint16 exitCtr = 0; exitCtr < numExits; ++exitCtr, ++exitRes) { RoomExitData *exit = new RoomExitData(exitRes); - newEntry->exits.push_back(exit); + newEntry->exits.push_back(RoomExitList::value_type(exit)); } } } @@ -158,7 +158,7 @@ void Resources::reloadData() { (mb->data() + offsetVal); while (READ_LE_UINT16(&re->hotspotId) != 0xffff) { RoomExitHotspotData *newEntry = new RoomExitHotspotData(re); - room->exitHotspots.push_back(newEntry); + room->exitHotspots.push_back(RoomExitHotspotList::value_type(newEntry)); ++re; } } @@ -172,7 +172,7 @@ void Resources::reloadData() { RoomExitJoinResource *joinRec = (RoomExitJoinResource *) mb->data(); while (READ_LE_UINT16(&joinRec->hotspot1Id) != 0xffff) { RoomExitJoinData *newEntry = new RoomExitJoinData(joinRec); - _exitJoins.push_back(newEntry); + _exitJoins.push_back(RoomExitJoinList::value_type(newEntry)); GET_NEXT(joinRec, RoomExitJoinResource); } @@ -195,7 +195,7 @@ void Resources::reloadData() { ++offset; while (READ_LE_UINT16(offset) != 0xffff) { RandomActionSet *actionSet = new RandomActionSet(offset); - _randomActions.push_back(actionSet); + _randomActions.push_back(RandomActionList::value_type(actionSet)); } // Loop through loading the schedules @@ -203,7 +203,7 @@ void Resources::reloadData() { while ((startOffset = READ_LE_UINT16(++offset)) != 0xffff) { CharacterScheduleResource *res = (CharacterScheduleResource *) (mb->data() + startOffset); CharacterScheduleSet *newEntry = new CharacterScheduleSet(res, ++ctr); - _charSchedules.push_back(newEntry); + _charSchedules.push_back(CharacterScheduleList::value_type(newEntry)); } delete mb; @@ -212,7 +212,7 @@ void Resources::reloadData() { HotspotResource *hsRec = (HotspotResource *) mb->data(); while (READ_LE_UINT16(&hsRec->hotspotId) != 0xffff) { HotspotData *newEntry = new HotspotData(hsRec); - _hotspotData.push_back(newEntry); + _hotspotData.push_back(HotspotDataList::value_type(newEntry)); GET_NEXT(hsRec, HotspotResource); } @@ -223,7 +223,7 @@ void Resources::reloadData() { HotspotOverrideResource *hsoRec = (HotspotOverrideResource *) mb->data(); while (READ_LE_UINT16(&hsoRec->hotspotId) != 0xffff) { HotspotOverrideData *newEntry = new HotspotOverrideData(hsoRec); - _hotspotOverrides.push_back(newEntry); + _hotspotOverrides.push_back(HotspotOverrideList::value_type(newEntry)); ++hsoRec; } delete mb; @@ -233,7 +233,7 @@ void Resources::reloadData() { HotspotAnimResource *animRec = (HotspotAnimResource *) mb->data(); while (READ_LE_UINT16(&animRec->animRecordId) != 0xffff) { HotspotAnimData *newEntry = new HotspotAnimData(animRec); - _animData.push_back(newEntry); + _animData.push_back(HotspotAnimList::value_type(newEntry)); // Handle any direction frames AnimRecordTemp dirEntries[4] = { @@ -248,7 +248,7 @@ void Resources::reloadData() { (mb->data() + offsetVal); while (READ_LE_UINT16(&moveRec->frameNumber) != 0xffff) { MovementData *newMove = new MovementData(moveRec); - dirEntries[dirCtr].list->push_back(newMove); + dirEntries[dirCtr].list->push_back(MovementDataList::value_type(newMove)); ++moveRec; } } @@ -279,7 +279,7 @@ void Resources::reloadData() { HotspotActionList *list = new HotspotActionList( recordId, mb->data() + offsetVal); - _actionsList.push_back(list); + _actionsList.push_back(HotspotActionSet::value_type(list)); } delete mb; @@ -291,7 +291,7 @@ void Resources::reloadData() { uint16 *offsets = (uint16 *) (mb->data() + READ_LE_UINT16(&thHeader->offset)); TalkHeaderData *newEntry = new TalkHeaderData(hotspotId, offsets); - _talkHeaders.push_back(newEntry); + _talkHeaders.push_back(TalkHeaderList::value_type(newEntry)); ++thHeader; } delete mb; @@ -316,18 +316,18 @@ void Resources::reloadData() { TalkDataResource *entry = (TalkDataResource *) (dataStart + READ_LE_UINT16(&tdHeader->listOffset)); while (READ_LE_UINT16(&entry->preSequenceId) != 0xffff) { TalkEntryData *newEntry = new TalkEntryData(entry); - data->entries.push_back(newEntry); + data->entries.push_back(TalkEntryList::value_type(newEntry)); ++entry; } entry = (TalkDataResource *) (dataStart + READ_LE_UINT16(&tdHeader->responsesOffset)); while (READ_LE_UINT16(&entry->preSequenceId) != 0xffff) { TalkEntryData *newEntry = new TalkEntryData(entry); - data->responses.push_back(newEntry); + data->responses.push_back(TalkEntryList::value_type(newEntry)); ++entry; } - _talkData.push_back(data); + _talkData.push_back(TalkDataList::value_type(data)); ++tdHeader; } delete mb; @@ -337,7 +337,7 @@ void Resources::reloadData() { RoomExitCoordinateEntryResource *coordRec = (RoomExitCoordinateEntryResource *) mb->data(); while (READ_LE_UINT16(coordRec) != 0xffff) { RoomExitCoordinates *newEntry = new RoomExitCoordinates(coordRec); - _coordinateList.push_back(newEntry); + _coordinateList.push_back(RoomExitCoordinatesList::value_type(newEntry)); ++coordRec; } delete mb; @@ -346,7 +346,7 @@ void Resources::reloadData() { mb = d.getEntry(EXIT_HOTSPOT_ID_LIST); RoomExitIndexedHotspotResource *indexedRec = (RoomExitIndexedHotspotResource *) mb->data(); while (READ_LE_UINT16(indexedRec) != 0xffff) { - _indexedRoomExitHospots.push_back(new RoomExitIndexedHotspotData(indexedRec)); + _indexedRoomExitHospots.push_back(RoomExitIndexedHotspotList::value_type(new RoomExitIndexedHotspotData(indexedRec))); indexedRec++; } @@ -373,7 +373,7 @@ RoomExitJoinData *Resources::getExitJoin(uint16 hotspotId) { RoomExitJoinList::iterator i; for (i = _exitJoins.begin(); i != _exitJoins.end(); ++i) { - RoomExitJoinData *rec = *i; + RoomExitJoinData *rec = (*i).get(); if ((rec->hotspots[0].hotspotId == hotspotId) || (rec->hotspots[1].hotspotId == hotspotId)) return rec; } @@ -389,7 +389,7 @@ RoomData *Resources::getRoom(uint16 roomNumber) { RoomDataList::iterator i; for (i = _roomData.begin(); i != _roomData.end(); ++i) { - RoomData *rec = *i; + RoomData *rec = (*i).get(); if (rec->roomNumber == roomNumber) return rec; ++rec; } @@ -446,7 +446,7 @@ HotspotData *Resources::getHotspot(uint16 hotspotId) { HotspotDataList::iterator i; for (i = _hotspotData.begin(); i != _hotspotData.end(); ++i) { - HotspotData *rec = *i; + HotspotData *rec = (*i).get(); if (rec->hotspotId == hotspotId) return rec; } @@ -457,7 +457,7 @@ Hotspot *Resources::getActiveHotspot(uint16 hotspotId) { HotspotList::iterator i; for (i = _activeHotspots.begin(); i != _activeHotspots.end(); ++i) { - Hotspot *rec = *i; + Hotspot *rec = (*i).get(); if (rec->hotspotId() == hotspotId) return rec; } @@ -469,7 +469,7 @@ HotspotOverrideData *Resources::getHotspotOverride(uint16 hotspotId) { HotspotOverrideList::iterator i; for (i = _hotspotOverrides.begin(); i != _hotspotOverrides.end(); ++i) { - HotspotOverrideData *rec = *i; + HotspotOverrideData *rec = (*i).get(); if (rec->hotspotId == hotspotId) return rec; } @@ -480,7 +480,7 @@ HotspotAnimData *Resources::getAnimation(uint16 animRecordId) { HotspotAnimList::iterator i; for (i = _animData.begin(); i != _animData.end(); ++i) { - HotspotAnimData *rec = *i; + HotspotAnimData *rec = (*i).get(); if (rec->animRecordId == animRecordId) return rec; } @@ -492,7 +492,7 @@ int Resources::getAnimationIndex(HotspotAnimData *animData) { int index = 0; for (i = _animData.begin(); i != _animData.end(); ++i, ++index) { - HotspotAnimData *rec = *i; + HotspotAnimData *rec = (*i).get(); if (rec == animData) return index; } @@ -511,7 +511,7 @@ uint16 Resources::getHotspotAction(uint16 actionsOffset, Action action) { TalkHeaderData *Resources::getTalkHeader(uint16 hotspotId) { TalkHeaderList::iterator i; for (i = _talkHeaders.begin(); i != _talkHeaders.end(); ++i) { - TalkHeaderData *rec = *i; + TalkHeaderData *rec = (*i).get(); if (rec->characterId == hotspotId) return rec; } return NULL; @@ -637,7 +637,7 @@ Hotspot *Resources::addHotspot(uint16 hotspotId) { HotspotData *hData = getHotspot(hotspotId); assert(hData); Hotspot *hotspot = new Hotspot(hData); - _activeHotspots.push_back(hotspot); + _activeHotspots.push_back(HotspotList::value_type(hotspot)); if (hotspotId < FIRST_NONCHARACTER_ID) { // Default characters to facing upwards until they start moving @@ -649,14 +649,14 @@ Hotspot *Resources::addHotspot(uint16 hotspotId) { } void Resources::addHotspot(Hotspot *hotspot) { - _activeHotspots.push_back(hotspot); + _activeHotspots.push_back(HotspotList::value_type(hotspot)); } void Resources::deactivateHotspot(uint16 hotspotId, bool isDestId) { HotspotList::iterator i = _activeHotspots.begin(); while (i != _activeHotspots.end()) { - Hotspot *h = *i; + Hotspot *h = (*i).get(); if ((!isDestId && (h->hotspotId() == hotspotId)) || (isDestId && (h->destHotspotId() == hotspotId) && (h->hotspotId() == 0xffff))) { _activeHotspots.erase(i); @@ -671,7 +671,7 @@ void Resources::deactivateHotspot(Hotspot *hotspot) { HotspotList::iterator i = _activeHotspots.begin(); while (i != _activeHotspots.end()) { - Hotspot *h = *i; + Hotspot *h = (*i).get(); if (h == hotspot) { _activeHotspots.erase(i); break; @@ -686,7 +686,7 @@ uint16 Resources::numInventoryItems() { HotspotDataList &list = _hotspotData; HotspotDataList::iterator i; for (i = list.begin(); i != list.end(); ++i) { - HotspotData *rec = *i; + HotspotData *rec = (*i).get(); if (rec->roomNumber == PLAYER_ID) ++numItems; } @@ -715,7 +715,7 @@ void Resources::setTalkData(uint16 offset) { TalkDataList::iterator i; for (i = _talkData.begin(); i != _talkData.end(); ++i) { - TalkData *rec = *i; + TalkData *rec = (*i).get(); if (rec->recordId == offset) { _activeTalkData = rec; return; @@ -732,7 +732,7 @@ void Resources::saveToStream(Common::WriteStream *stream) { // Save out the schedule for any non-active NPCs HotspotDataList::iterator i; for (i = _hotspotData.begin(); i != _hotspotData.end(); ++i) { - HotspotData *rec = *i; + HotspotData *rec = (*i).get(); if (!rec->npcSchedule.isEmpty()) { Hotspot *h = getActiveHotspot(rec->hotspotId); if (h == NULL) { diff --git a/engines/lure/res_struct.cpp b/engines/lure/res_struct.cpp index 0903586c98..fcb6b874be 100644 --- a/engines/lure/res_struct.cpp +++ b/engines/lure/res_struct.cpp @@ -151,7 +151,7 @@ bool RoomExitData::insideRect(int16 xp, int16 yp) { RoomExitData *RoomExitList::checkExits(int16 xp, int16 yp) { iterator i; for (i = begin(); i != end(); i++) { - RoomExitData *rec = *i; + RoomExitData *rec = (*i).get(); if (rec->insideRect(xp, yp)) { return rec; } @@ -285,7 +285,7 @@ void RoomDataList::saveToStream(WriteStream *stream) { RoomDataList::iterator i; for (i = begin(); i != end(); ++i) { - RoomData *rec = *i; + RoomData *rec = (*i).get(); stream->writeByte(rec->flags); const byte *pathData = rec->paths.data(); stream->write(pathData, ROOM_PATHS_HEIGHT * ROOM_PATHS_WIDTH); @@ -297,7 +297,7 @@ void RoomDataList::loadFromStream(ReadStream *stream) { byte data[ROOM_PATHS_HEIGHT * ROOM_PATHS_WIDTH]; for (i = begin(); i != end(); ++i) { - RoomData *rec = *i; + RoomData *rec = (*i).get(); rec->flags = stream->readByte(); stream->read(data, ROOM_PATHS_HEIGHT * ROOM_PATHS_WIDTH); rec->paths.load(data); @@ -322,7 +322,7 @@ RoomExitJoinData::RoomExitJoinData(RoomExitJoinResource *rec) { void RoomExitJoinList::saveToStream(WriteStream *stream) { for (RoomExitJoinList::iterator i = begin(); i != end(); ++i) { - RoomExitJoinData *rec = *i; + RoomExitJoinData *rec = (*i).get(); stream->writeUint16LE(rec->hotspots[0].hotspotId); stream->writeUint16LE(rec->hotspots[1].hotspotId); @@ -339,7 +339,7 @@ void RoomExitJoinList::saveToStream(WriteStream *stream) { void RoomExitJoinList::loadFromStream(ReadStream *stream) { for (RoomExitJoinList::iterator i = begin(); i != end(); ++i) { - RoomExitJoinData *rec = *i; + RoomExitJoinData *rec = (*i).get(); uint16 hotspot1Id = stream->readUint16LE(); if (hotspot1Id == 0xffff) error("Invalid room exit join list"); @@ -371,7 +371,7 @@ HotspotActionData::HotspotActionData(HotspotActionResource *rec) { uint16 HotspotActionList::getActionOffset(Action action) { iterator i; for (i = begin(); i != end(); ++i) { - HotspotActionData *rec = *i; + HotspotActionData *rec = (*i).get(); if (rec->action == action) return rec->sequenceOffset; } @@ -539,7 +539,7 @@ void HotspotData::loadFromStream(ReadStream *stream) { void HotspotDataList::saveToStream(WriteStream *stream) { iterator i; for (i = begin(); i != end(); ++i) { - HotspotData *hotspot = *i; + HotspotData *hotspot = (*i).get(); stream->writeUint16LE(hotspot->hotspotId); hotspot->saveToStream(stream); } @@ -585,7 +585,7 @@ bool MovementDataList::getFrame(uint16 currentFrame, int16 &xChange, iterator i; for (i = begin(); i != end(); ++i) { - MovementData *rec = *i; + MovementData *rec = (*i).get(); if (foundFlag || (i == begin())) { xChange = rec->xChange; yChange = rec->yChange; @@ -624,14 +624,14 @@ HotspotActionList::HotspotActionList(uint16 id, byte *data) { GET_NEXT(actionRec, HotspotActionResource)) { HotspotActionData *actionEntry = new HotspotActionData(actionRec); - push_back(actionEntry); + push_back(HotspotActionList::value_type(actionEntry)); } } HotspotActionList *HotspotActionSet::getActions(uint16 recordId) { HotspotActionSet::iterator i; for (i = begin(); i != end(); ++i) { - HotspotActionList *list = *i; + HotspotActionList *list = (*i).get(); if (list->recordId == recordId) return list; } @@ -697,7 +697,7 @@ TalkEntryData *TalkData::getResponse(int index) { ++i; } - return *i; + return (*i).get(); } // The following class acts as a container for all the NPC conversations @@ -705,11 +705,11 @@ TalkEntryData *TalkData::getResponse(int index) { void TalkDataList::saveToStream(WriteStream *stream) { TalkDataList::iterator i; for (i = begin(); i != end(); ++i) { - TalkData *rec = *i; + TalkData *rec = (*i).get(); TalkEntryList::iterator i2; for (i2 = rec->entries.begin(); i2 != rec->entries.end(); ++i2) { - TalkEntryData *entry = *i2; + TalkEntryData *entry = (*i2).get(); stream->writeUint16LE(entry->descId); } } @@ -718,11 +718,11 @@ void TalkDataList::saveToStream(WriteStream *stream) { void TalkDataList::loadFromStream(ReadStream *stream) { TalkDataList::iterator i; for (i = begin(); i != end(); ++i) { - TalkData *rec = *i; + TalkData *rec = (*i).get(); TalkEntryList::iterator i2; for (i2 = rec->entries.begin(); i2 != rec->entries.end(); ++i2) { - TalkEntryData *entry = *i2; + TalkEntryData *entry = (*i2).get(); entry->descId = stream->readUint16LE(); } } @@ -780,7 +780,7 @@ void SequenceDelayList::add(uint16 delay, uint16 seqOffset, bool canClear) { debugC(ERROR_DETAILED, kLureDebugScripts, "Delay List add sequence=%xh delay=%d canClear=%d", seqOffset, delay, (int)canClear); SequenceDelayData *entry = new SequenceDelayData(delay, seqOffset, canClear); - push_front(entry); + push_front(SequenceDelayList::value_type(entry)); } void SequenceDelayList::tick() { @@ -790,7 +790,7 @@ void SequenceDelayList::tick() { debugC(ERROR_DETAILED, kLureDebugScripts, "Delay List check start at time %d", currTime); for (i = begin(); i != end(); i++) { - SequenceDelayData *entry = *i; + SequenceDelayData *entry = (*i).get(); debugC(ERROR_DETAILED, kLureDebugScripts, "Delay List check %xh at time %d", entry->sequenceOffset, entry->timeoutCtr); if (currTime >= entry->timeoutCtr) { @@ -807,7 +807,7 @@ void SequenceDelayList::clear(bool forceClear) { SequenceDelayList::iterator i = begin(); while (i != end()) { - SequenceDelayData *entry = *i; + SequenceDelayData *entry = (*i).get(); if (entry->canClear || forceClear) i = erase(i); else @@ -820,7 +820,7 @@ void SequenceDelayList::saveToStream(WriteStream *stream) { SequenceDelayList::iterator i; for (i = begin(); i != end(); ++i) { - SequenceDelayData *entry = *i; + SequenceDelayData *entry = (*i).get(); stream->writeUint16LE(entry->sequenceOffset); stream->writeUint32LE((currTime > entry->timeoutCtr ) ? 0 : entry->timeoutCtr - currTime); @@ -838,7 +838,7 @@ void SequenceDelayList::loadFromStream(ReadStream *stream) { while ((seqOffset = stream->readUint16LE()) != 0) { uint32 delay = currTime + stream->readUint32LE(); bool canClear = stream->readByte() != 0; - push_back(SequenceDelayData::load(delay, seqOffset, canClear)); + push_back(SequenceDelayList::value_type(SequenceDelayData::load(delay, seqOffset, canClear))); } } @@ -913,9 +913,9 @@ CharacterScheduleEntry *CharacterScheduleEntry::next() { if (_parent) { CharacterScheduleSet::iterator i; for (i = _parent->begin(); i != _parent->end(); ++i) { - if (*i == this) { + if ((*i).get() == this) { ++i; - CharacterScheduleEntry *result = (i == _parent->end()) ? NULL : *i; + CharacterScheduleEntry *result = (i == _parent->end()) ? NULL : (*i).get(); return result; } } @@ -933,7 +933,7 @@ CharacterScheduleSet::CharacterScheduleSet(CharacterScheduleResource *rec, uint1 while (rec->action != 0) { CharacterScheduleEntry *r = new CharacterScheduleEntry(this, rec); - push_back(r); + push_back(CharacterScheduleSet::value_type(r)); } _id = setId; @@ -962,7 +962,7 @@ CharacterScheduleEntry *CharacterScheduleList::getEntry(uint16 id, CharacterSche if (i == end()) error("Invalid index %d specified for support data set", id >> 8); - currentSet = *i; + currentSet = (*i).get(); } // Get the indexed instruction in the specified set @@ -975,7 +975,7 @@ CharacterScheduleEntry *CharacterScheduleList::getEntry(uint16 id, CharacterSche if (i == currentSet->end()) error("Invalid index %d specified within support data set", id & 0x3ff); - return *i; + return (*i).get(); } uint16 CharacterScheduleSet::getId(CharacterScheduleEntry *rec) { @@ -985,7 +985,7 @@ uint16 CharacterScheduleSet::getId(CharacterScheduleEntry *rec) { iterator i; for (i = begin(); i != end(); ++i, ++result) - if (*i == rec) break; + if ((*i).get() == rec) break; if (i == end()) error("Parent child relationship missing in character schedule set"); return result; @@ -1015,7 +1015,7 @@ RandomActionSet::~RandomActionSet() { RandomActionSet *RandomActionList::getRoom(uint16 roomNumber) { iterator i; for (i = begin(); i != end(); ++i) { - RandomActionSet *v = *i; + RandomActionSet *v = (*i).get(); if (v->roomNumber() == roomNumber) return v; } @@ -1058,7 +1058,7 @@ RoomExitIndexedHotspotData::RoomExitIndexedHotspotData(RoomExitIndexedHotspotRes uint16 RoomExitIndexedHotspotList::getHotspot(uint16 roomNumber, uint8 hotspotIndexId) { iterator i; for (i = begin(); i != end(); ++i) { - RoomExitIndexedHotspotData *entry = *i; + RoomExitIndexedHotspotData *entry = (*i).get(); if ((entry->roomNumber == roomNumber) && (entry->hotspotIndex == hotspotIndexId)) return entry->hotspotId; } @@ -1080,7 +1080,7 @@ PausedCharacter::PausedCharacter(uint16 SrcCharId, uint16 DestCharId) { void PausedCharacterList::reset(uint16 hotspotId) { iterator i; for (i = begin(); i != end(); ++i) { - PausedCharacter *rec = *i; + PausedCharacter *rec = (*i).get(); if (rec->srcCharId == hotspotId) { rec->counter = 1; @@ -1094,7 +1094,7 @@ void PausedCharacterList::countdown() { iterator i = begin(); while (i != end()) { - PausedCharacter *rec = *i; + PausedCharacter *rec = (*i).get(); --rec->counter; // Handle reflecting counter to hotspot @@ -1115,7 +1115,7 @@ void PausedCharacterList::scan(Hotspot &h) { if (h.blockedState() != BS_NONE) { for (i = begin(); i != end(); ++i) { - PausedCharacter *rec = *i; + PausedCharacter *rec = (*i).get(); if (rec->srcCharId == h.hotspotId()) { rec->counter = IDLE_COUNTDOWN_SIZE; @@ -1145,7 +1145,7 @@ int PausedCharacterList::check(uint16 charId, int numImpinging, uint16 *impingin // calling character and the impinging list entry bool foundEntry = false; for (i = res.pausedList().begin(); !foundEntry && (i != res.pausedList().end()); ++i) { - PausedCharacter *rec = *i; + PausedCharacter *rec = (*i).get(); foundEntry = (rec->srcCharId == charId) && (rec->destCharId == hotspot->hotspotId()); } @@ -1161,7 +1161,7 @@ int PausedCharacterList::check(uint16 charId, int numImpinging, uint16 *impingin // Add a new paused character entry PausedCharacter *entry = new PausedCharacter(charId, hotspot->hotspotId()); - res.pausedList().push_back(entry); + res.pausedList().push_back(PausedCharacterList::value_type(entry)); charHotspot->setBlockedState(BS_INITIAL); if (hotspot->hotspotId() < START_EXIT_ID) { @@ -1444,7 +1444,7 @@ CurrentActionEntry *CurrentActionEntry::loadFromStream(ReadStream *stream) { } void CurrentActionStack::list(char *buffer) { - ManagedList<CurrentActionEntry *>::iterator i; + ActionsList::iterator i; if (buffer) { sprintf(buffer, "CurrentActionStack::list num_actions=%d\n", size()); @@ -1454,7 +1454,7 @@ void CurrentActionStack::list(char *buffer) { printf("CurrentActionStack::list num_actions=%d\n", size()); for (i = _actions.begin(); i != _actions.end(); ++i) { - CurrentActionEntry *entry = *i; + CurrentActionEntry *entry = (*i).get(); if (buffer) { sprintf(buffer, "style=%d room#=%d", entry->action(), entry->roomNumber()); buffer += strlen(buffer); @@ -1508,7 +1508,7 @@ void CurrentActionStack::list(char *buffer) { } void CurrentActionStack::saveToStream(WriteStream *stream) { - ManagedList<CurrentActionEntry *>::iterator i; + ActionsList::iterator i; debugC(ERROR_DETAILED, kLureDebugAnimations, "Saving hotspot action stack"); char buffer[MAX_DESC_SIZE]; @@ -1516,7 +1516,7 @@ void CurrentActionStack::saveToStream(WriteStream *stream) { debugC(ERROR_DETAILED, kLureDebugAnimations, "%s", buffer); for (i = _actions.begin(); i != _actions.end(); ++i) { - CurrentActionEntry *rec = *i; + CurrentActionEntry *rec = (*i).get(); rec->saveToStream(stream); } stream->writeByte(0xff); // End of list marker @@ -1528,15 +1528,15 @@ void CurrentActionStack::loadFromStream(ReadStream *stream) { _actions.clear(); while ((rec = CurrentActionEntry::loadFromStream(stream)) != NULL) - _actions.push_back(rec); + _actions.push_back(ActionsList::value_type(rec)); } void CurrentActionStack::copyFrom(CurrentActionStack &stack) { - ManagedList<CurrentActionEntry *>::iterator i; + ActionsList::iterator i; for (i = stack._actions.begin(); i != stack._actions.end(); ++i) { - CurrentActionEntry *rec = *i; - _actions.push_back(new CurrentActionEntry(rec)); + CurrentActionEntry *rec = (*i).get(); + _actions.push_back(ActionsList::value_type(new CurrentActionEntry(rec))); } } diff --git a/engines/lure/res_struct.h b/engines/lure/res_struct.h index dca23add78..e2f596292b 100644 --- a/engines/lure/res_struct.h +++ b/engines/lure/res_struct.h @@ -29,6 +29,7 @@ #include "lure/luredefs.h" #include "common/list.h" #include "common/file.h" +#include "common/ptr.h" namespace Lure { @@ -249,53 +250,6 @@ struct SoundDescResource { #include "common/pack-end.h" // END STRUCT PACKING -/** - * Class template for a derived list that destroys the contained - * object when the record containing it is destroyed. It's not - * perfect, since the underlying list doesn't have virtual - * methods, but it's sufficient for my usage. - */ -template <class T> -class ManagedList: public Common::List<T> { - typedef typename Common::List<T> Common_List; -public: - ~ManagedList() { - clear(); - } - - void clear() { - typename Common_List::iterator i = Common_List::begin(); - while (i != Common_List::end()) { - T v = *i; - i = Common_List::erase(i); - delete v; - } - } - - typename Common_List::iterator erase(typename Common_List::iterator pos) { - T obj = *pos; - typename Common_List::iterator result = Common_List::erase(pos); - delete obj; - return result; - } - - typename Common_List::iterator erase(typename Common_List::iterator first, - typename Common_List::iterator last) { - - while (first != last) - erase(first++); - - return last; - } - - T operator[](int index) { - typename Common_List::iterator i = Common_List::begin(); - while (index-- > 0) - ++i; - return *i; - } -}; - /** Enumeration used for direction facings */ enum Direction {UP, DOWN, LEFT, RIGHT, NO_DIRECTION}; @@ -312,7 +266,7 @@ public: uint16 destRoomNumber; }; -typedef ManagedList<RoomExitHotspotData *> RoomExitHotspotList; +typedef Common::List<Common::SharedPtr<RoomExitHotspotData> > RoomExitHotspotList; class RoomExitData { public: @@ -326,7 +280,7 @@ public: uint16 x, y; }; -class RoomExitList: public ManagedList<RoomExitData *> { +class RoomExitList: public Common::List<Common::SharedPtr<RoomExitData> > { public: RoomExitData *checkExits(int16 xp, int16 yp); }; @@ -381,7 +335,7 @@ public: RoomPathsData paths; }; -class RoomDataList: public ManagedList<RoomData *> { +class RoomDataList: public Common::List<Common::SharedPtr<RoomData> > { public: void saveToStream(WriteStream *stream); void loadFromStream(ReadStream *stream); @@ -404,7 +358,7 @@ public: byte blocked; }; -class RoomExitJoinList: public ManagedList<RoomExitJoinData *> { +class RoomExitJoinList: public Common::List<Common::SharedPtr<RoomExitJoinData> > { public: void saveToStream(WriteStream *stream); void loadFromStream(ReadStream *stream); @@ -418,7 +372,7 @@ public: uint16 sequenceOffset; }; -class HotspotActionList: public ManagedList<HotspotActionData *> { +class HotspotActionList: public Common::List<Common::SharedPtr<HotspotActionData> > { public: uint16 recordId; @@ -426,7 +380,7 @@ public: uint16 getActionOffset(Action action); }; -class HotspotActionSet: public ManagedList<HotspotActionList *> { +class HotspotActionSet: public Common::List<Common::SharedPtr<HotspotActionList> > { public: HotspotActionList *getActions(uint16 recordId); }; @@ -503,7 +457,8 @@ public: class CurrentActionStack { private: - ManagedList<CurrentActionEntry *> _actions; + typedef Common::List<Common::SharedPtr<CurrentActionEntry> > ActionsList; + ActionsList _actions; void validateStack() { if (_actions.size() > 20) error("NPC character got an excessive number of pending actions"); @@ -521,27 +476,27 @@ public: void list() { list(NULL); } void addBack(CurrentAction newAction, uint16 roomNum) { - _actions.push_back(new CurrentActionEntry(newAction, roomNum)); + _actions.push_back(ActionsList::value_type(new CurrentActionEntry(newAction, roomNum))); validateStack(); } void addBack(CurrentAction newAction, CharacterScheduleEntry *rec, uint16 roomNum) { - _actions.push_back(new CurrentActionEntry(newAction, rec, roomNum)); + _actions.push_back(ActionsList::value_type(new CurrentActionEntry(newAction, rec, roomNum))); validateStack(); } void addBack(Action newAction, uint16 roomNum, uint16 param1, uint16 param2) { - _actions.push_back(new CurrentActionEntry(newAction, roomNum, param1, param2)); + _actions.push_back(ActionsList::value_type(new CurrentActionEntry(newAction, roomNum, param1, param2))); validateStack(); } void addFront(CurrentAction newAction, uint16 roomNum) { - _actions.push_front(new CurrentActionEntry(newAction, roomNum)); + _actions.push_front(ActionsList::value_type(new CurrentActionEntry(newAction, roomNum))); validateStack(); } void addFront(CurrentAction newAction, CharacterScheduleEntry *rec, uint16 roomNum) { - _actions.push_front(new CurrentActionEntry(newAction, rec, roomNum)); + _actions.push_front(ActionsList::value_type(new CurrentActionEntry(newAction, rec, roomNum))); validateStack(); } void addFront(Action newAction, uint16 roomNum, uint16 param1, uint16 param2) { - _actions.push_front(new CurrentActionEntry(newAction, roomNum, param1, param2)); + _actions.push_front(ActionsList::value_type(new CurrentActionEntry(newAction, roomNum, param1, param2))); validateStack(); } @@ -612,7 +567,7 @@ public: void loadFromStream(ReadStream *stream); }; -class HotspotDataList: public ManagedList<HotspotData *> { +class HotspotDataList: public Common::List<Common::SharedPtr<HotspotData> > { public: void saveToStream(WriteStream *stream); void loadFromStream(ReadStream *stream); @@ -626,7 +581,7 @@ public: int16 xs, xe, ys, ye; }; -typedef ManagedList<HotspotOverrideData *> HotspotOverrideList; +typedef Common::List<Common::SharedPtr<HotspotOverrideData> > HotspotOverrideList; class MovementData { public: @@ -637,7 +592,7 @@ public: int16 yChange; }; -class MovementDataList: public ManagedList<MovementData *> { +class MovementDataList: public Common::List<Common::SharedPtr<MovementData> > { public: bool getFrame(uint16 currentFrame, int16 &xChange, int16 &yChange, uint16 &nextFrame); @@ -659,7 +614,7 @@ public: MovementDataList upFrames, downFrames; }; -typedef ManagedList<HotspotAnimData *> HotspotAnimList; +typedef Common::List<Common::SharedPtr<HotspotAnimData> > HotspotAnimList; // Talk header list @@ -675,7 +630,7 @@ public: uint16 getEntry(int index); }; -typedef ManagedList<TalkHeaderData *> TalkHeaderList; +typedef Common::List<Common::SharedPtr<TalkHeaderData> > TalkHeaderList; class TalkEntryData { public: @@ -686,7 +641,7 @@ public: uint16 postSequenceId; }; -typedef ManagedList<TalkEntryData *> TalkEntryList; +typedef Common::List<Common::SharedPtr<TalkEntryData> > TalkEntryList; class TalkData { public: @@ -700,7 +655,7 @@ public: TalkEntryData *getResponse(int index); }; -class TalkDataList: public ManagedList<TalkData *> { +class TalkDataList: public Common::List<Common::SharedPtr<TalkData> > { public: void saveToStream(WriteStream *stream); void loadFromStream(ReadStream *stream); @@ -722,7 +677,7 @@ public: RoomExitCoordinateData &getData(uint16 destRoomNumber); }; -class RoomExitCoordinatesList: public ManagedList<RoomExitCoordinates *> { +class RoomExitCoordinatesList: public Common::List<Common::SharedPtr<RoomExitCoordinates> > { public: RoomExitCoordinates &getEntry(uint16 roomNumber); }; @@ -736,7 +691,7 @@ public: uint16 hotspotId; }; -class RoomExitIndexedHotspotList: public ManagedList<RoomExitIndexedHotspotData *> { +class RoomExitIndexedHotspotList: public Common::List<Common::SharedPtr<RoomExitIndexedHotspotData> > { public: uint16 getHotspot(uint16 roomNumber, uint8 hotspotIndexId); }; @@ -755,7 +710,7 @@ public: bool canClear; }; -class SequenceDelayList: public ManagedList<SequenceDelayData *> { +class SequenceDelayList: public Common::List<Common::SharedPtr<SequenceDelayData> > { public: void add(uint16 delay, uint16 seqOffset, bool canClear); void tick(); @@ -769,7 +724,7 @@ public: extern const int actionNumParams[NPC_JUMP_ADDRESS+1]; -class CharacterScheduleSet: public ManagedList<CharacterScheduleEntry *> { +class CharacterScheduleSet: public Common::List<Common::SharedPtr<CharacterScheduleEntry> > { private: uint16 _id; public: @@ -778,7 +733,7 @@ public: uint16 id() { return _id; } }; -class CharacterScheduleList: public ManagedList<CharacterScheduleSet *> { +class CharacterScheduleList: public Common::List<Common::SharedPtr<CharacterScheduleSet> > { public: CharacterScheduleEntry *getEntry(uint16 id, CharacterScheduleSet *currentSet = NULL); }; @@ -815,7 +770,7 @@ public: void loadFromStream(Common::ReadStream *stream); }; -class RandomActionList: public ManagedList<RandomActionSet *> { +class RandomActionList: public Common::List<Common::SharedPtr<RandomActionSet> > { public: RandomActionSet *getRoom(uint16 roomNumber); void saveToStream(Common::WriteStream *stream); @@ -834,7 +789,7 @@ public: class Hotspot; -class PausedCharacterList: public ManagedList<PausedCharacter *> { +class PausedCharacterList: public Common::List<Common::SharedPtr<PausedCharacter> > { public: void reset(uint16 hotspotId); void countdown(); diff --git a/engines/lure/room.cpp b/engines/lure/room.cpp index 8fe9b85d1c..cf4363f6fd 100644 --- a/engines/lure/room.cpp +++ b/engines/lure/room.cpp @@ -138,7 +138,7 @@ void Room::leaveRoom() { HotspotList &list = r.activeHotspots(); HotspotList::iterator i = list.begin(); while (i != list.end()) { - Hotspot *h = i.operator*(); + Hotspot *h = (i.operator*()).get(); if (!h->persistant()) { i = list.erase(i); } else { @@ -153,7 +153,7 @@ void Room::loadRoomHotspots() { HotspotDataList::iterator i; for (i = list.begin(); i != list.end(); ++i) { - HotspotData *rec = *i; + HotspotData *rec = (*i).get(); if ((rec->hotspotId < 0x7530) && (rec->roomNumber == _roomNumber) && (rec->layer != 0)) @@ -178,7 +178,7 @@ void Room::checkRoomHotspots() { // Loop for each range of hotspot Ids for (int ctr = 0; ctr < 4; ++ctr) { for (i = list.begin(); i != list.end(); ++i) { - entry = *i; + entry = (*i).get(); if ((entry->hotspotId < rangeStart[ctr]) || (entry->hotspotId > rangeEnd[ctr])) // Hotspot outside range, so skip it continue; @@ -252,7 +252,7 @@ CursorType Room::checkRoomExits() { RoomExitHotspotList::iterator i; for (i = exits.begin(); i != exits.end(); ++i) { - RoomExitHotspotData *rec = *i; + RoomExitHotspotData *rec = (*i).get(); skipFlag = false; if (rec->hotspotId != 0) { @@ -449,7 +449,7 @@ void Room::update() { List<Hotspot *> tempList; List<Hotspot *>::iterator iTemp; for (i = hotspots.begin(); i != hotspots.end(); ++i) { - Hotspot *h = i.operator*(); + Hotspot *h = (i.operator*()).get(); if ((h->layer() != 1) || (h->roomNumber() != _roomNumber) || h->skipFlag() || !h->isActiveAnimation()) continue; diff --git a/engines/lure/surface.cpp b/engines/lure/surface.cpp index 1b85ef939b..64394545d1 100644 --- a/engines/lure/surface.cpp +++ b/engines/lure/surface.cpp @@ -1288,7 +1288,7 @@ CopyProtectionDialog::CopyProtectionDialog() { h->setColourOffset(ptr->startColour); h->setAnimation(ptr->animId); - _hotspots.push_back(h); + _hotspots.push_back(HotspotsList::value_type(h)); } ++ptr; @@ -1309,9 +1309,30 @@ bool CopyProtectionDialog::show() { s->copyTo(&screen.screen(), 0, MENUBAR_Y_SIZE); delete s; + // Get needed hotspots + HotspotsList::iterator hotspot0 = _hotspots.begin(); + HotspotsList::iterator hotspot1 = _hotspots.begin(); + for (int i = 0; i < 1; i++) + ++hotspot1; + HotspotsList::iterator hotspot2 = _hotspots.begin(); + for (int i = 0; i < 2; i++) + ++hotspot2; + HotspotsList::iterator hotspot3 = _hotspots.begin(); + for (int i = 0; i < 3; i++) + ++hotspot3; + HotspotsList::iterator hotspot4 = _hotspots.begin(); + for (int i = 0; i < 4; i++) + ++hotspot4; + HotspotsList::iterator hotspot5 = _hotspots.begin(); + for (int i = 0; i < 5; i++) + ++hotspot5; + HotspotsList::iterator hotspot6 = _hotspots.begin(); + for (int i = 0; i < 6; i++) + ++hotspot6; + // Add wording header and display screen - _hotspots[2]->setFrameNumber(1); - _hotspots[2]->copyTo(&screen.screen()); + (hotspot2->get())->setFrameNumber(1); + (hotspot2->get())->copyTo(&screen.screen()); screen.update(); screen.setPalette(&p); @@ -1321,8 +1342,8 @@ bool CopyProtectionDialog::show() { } while (!events.interruptableDelay(100)); // Change title text to selection - _hotspots[2]->setFrameNumber(0); - _hotspots[2]->copyTo(&screen.screen()); + (hotspot2->get())->setFrameNumber(0); + (hotspot2->get())->copyTo(&screen.screen()); screen.update(); // Clear any prior try @@ -1334,15 +1355,21 @@ bool CopyProtectionDialog::show() { if ((events.event().kbd.keycode == Common::KEYCODE_BACKSPACE) && (_charIndex > 0)) { // Remove the last number typed --_charIndex; - _hotspots[_charIndex + 3]->setFrameNumber(10); // Blank space - _hotspots[_charIndex + 3]->copyTo(&screen.screen()); + HotspotsList::iterator tmpHotspot = _hotspots.begin(); + for (int i = 0; i < _charIndex + 3; i++) + ++tmpHotspot; + (tmpHotspot->get())->setFrameNumber(10); // Blank space + (tmpHotspot->get())->copyTo(&screen.screen()); screen.update(); } else if ((events.event().kbd.keycode >= Common::KEYCODE_0) && (events.event().kbd.keycode <= Common::KEYCODE_9)) { + HotspotsList::iterator tmpHotspot = _hotspots.begin(); + for (int i = 0; i < _charIndex + 3; i++) + ++tmpHotspot; // Number pressed - _hotspots[_charIndex + 3]->setFrameNumber(events.event().kbd.ascii - '0'); - _hotspots[_charIndex + 3]->copyTo(&screen.screen()); + (tmpHotspot->get())->setFrameNumber(events.event().kbd.ascii - '0'); + (tmpHotspot->get())->copyTo(&screen.screen()); ++_charIndex; } @@ -1360,11 +1387,11 @@ bool CopyProtectionDialog::show() { return false; // At this point, two page numbers have been entered - validate them - int page1 = (_hotspots[3]->frameNumber() * 10) + _hotspots[4]->frameNumber(); - int page2 = (_hotspots[5]->frameNumber() * 10) + _hotspots[6]->frameNumber(); + int page1 = ((hotspot3->get())->frameNumber() * 10) + (hotspot4->get())->frameNumber(); + int page2 = ((hotspot5->get())->frameNumber() * 10) + (hotspot6->get())->frameNumber(); - if ((page1 == pageNumbers[_hotspots[0]->frameNumber()]) && - (page2 == pageNumbers[_hotspots[1]->frameNumber()])) + if ((page1 == pageNumbers[(hotspot0->get())->frameNumber()]) && + (page2 == pageNumbers[(hotspot1->get())->frameNumber()])) return true; } @@ -1377,10 +1404,12 @@ void CopyProtectionDialog::chooseCharacters() { int char1 = _rnd.getRandomNumber(19); int char2 = _rnd.getRandomNumber(19); - _hotspots[0]->setFrameNumber(char1); - _hotspots[0]->copyTo(&screen.screen()); - _hotspots[1]->setFrameNumber(char2); - _hotspots[1]->copyTo(&screen.screen()); + HotspotsList::iterator curHotspot = _hotspots.begin(); + (curHotspot->get())->setFrameNumber(char1); + (curHotspot->get())->copyTo(&screen.screen()); + ++curHotspot; + (curHotspot->get())->setFrameNumber(char2); + (curHotspot->get())->copyTo(&screen.screen()); screen.update(); } diff --git a/engines/lure/surface.h b/engines/lure/surface.h index 73b7090287..49208fa057 100644 --- a/engines/lure/surface.h +++ b/engines/lure/surface.h @@ -28,6 +28,7 @@ #include "common/str.h" +#include "common/ptr.h" #include "lure/disk.h" #include "lure/luredefs.h" @@ -140,7 +141,8 @@ public: class CopyProtectionDialog { private: Common::RandomSource _rnd; - ManagedList<Hotspot *> _hotspots; + typedef Common::List<Common::SharedPtr<Hotspot> > HotspotsList; + HotspotsList _hotspots; int _charIndex; void chooseCharacters(); |