diff options
Diffstat (limited to 'engines/lure/res_struct.cpp')
-rw-r--r-- | engines/lure/res_struct.cpp | 202 |
1 files changed, 94 insertions, 108 deletions
diff --git a/engines/lure/res_struct.cpp b/engines/lure/res_struct.cpp index 222f55b5dc..aee4f11215 100644 --- a/engines/lure/res_struct.cpp +++ b/engines/lure/res_struct.cpp @@ -278,13 +278,11 @@ void RoomPathsData::decompress(RoomPathsDecompressedData &dataOut, int character // Room data class -void RoomDataList::saveToStream(Common::WriteStream *stream) { - RoomDataList::iterator i; - - for (i = begin(); i != end(); ++i) { - RoomData *rec = (*i).get(); - stream->writeByte(rec->flags); - const byte *pathData = rec->paths.data(); +void RoomDataList::saveToStream(Common::WriteStream *stream) const { + for (RoomDataList::const_iterator i = begin(); i != end(); ++i) { + RoomData const &rec = **i; + stream->writeByte(rec.flags); + const byte *pathData = rec.paths.data(); stream->write(pathData, ROOM_PATHS_HEIGHT * ROOM_PATHS_WIDTH); } } @@ -294,10 +292,10 @@ void RoomDataList::loadFromStream(Common::ReadStream *stream) { byte data[ROOM_PATHS_HEIGHT * ROOM_PATHS_WIDTH]; for (i = begin(); i != end(); ++i) { - RoomData *rec = (*i).get(); - rec->flags = stream->readByte(); + RoomData &rec = **i; + rec.flags = stream->readByte(); stream->read(data, ROOM_PATHS_HEIGHT * ROOM_PATHS_WIDTH); - rec->paths.load(data); + rec.paths.load(data); } } @@ -317,17 +315,17 @@ RoomExitJoinData::RoomExitJoinData(RoomExitJoinResource *rec) { blocked = rec->blocked; } -void RoomExitJoinList::saveToStream(Common::WriteStream *stream) { - for (RoomExitJoinList::iterator i = begin(); i != end(); ++i) { - RoomExitJoinData *rec = (*i).get(); - - stream->writeUint16LE(rec->hotspots[0].hotspotId); - stream->writeUint16LE(rec->hotspots[1].hotspotId); - stream->writeByte(rec->hotspots[0].currentFrame); - stream->writeByte(rec->hotspots[0].destFrame); - stream->writeByte(rec->hotspots[1].currentFrame); - stream->writeByte(rec->hotspots[1].destFrame); - stream->writeByte(rec->blocked); +void RoomExitJoinList::saveToStream(Common::WriteStream *stream) const { + for (RoomExitJoinList::const_iterator i = begin(); i != end(); ++i) { + RoomExitJoinData const &rec = **i; + + stream->writeUint16LE(rec.hotspots[0].hotspotId); + stream->writeUint16LE(rec.hotspots[1].hotspotId); + stream->writeByte(rec.hotspots[0].currentFrame); + stream->writeByte(rec.hotspots[0].destFrame); + stream->writeByte(rec.hotspots[1].currentFrame); + stream->writeByte(rec.hotspots[1].destFrame); + stream->writeByte(rec.blocked); } // Write end of list marker @@ -336,21 +334,21 @@ void RoomExitJoinList::saveToStream(Common::WriteStream *stream) { void RoomExitJoinList::loadFromStream(Common::ReadStream *stream) { for (RoomExitJoinList::iterator i = begin(); i != end(); ++i) { - RoomExitJoinData *rec = (*i).get(); + RoomExitJoinData &rec = **i; uint16 hotspot1Id = stream->readUint16LE(); if (hotspot1Id == 0xffff) error("Invalid room exit join list"); uint16 hotspot2Id = stream->readUint16LE(); - if ((rec->hotspots[0].hotspotId != hotspot1Id) || - (rec->hotspots[1].hotspotId != hotspot2Id)) + if ((rec.hotspots[0].hotspotId != hotspot1Id) || + (rec.hotspots[1].hotspotId != hotspot2Id)) break; - rec->hotspots[0].currentFrame = stream->readByte(); - rec->hotspots[0].destFrame = stream->readByte(); - rec->hotspots[1].currentFrame = stream->readByte(); - rec->hotspots[1].destFrame = stream->readByte(); - rec->blocked = stream->readByte(); + rec.hotspots[0].currentFrame = stream->readByte(); + rec.hotspots[0].destFrame = stream->readByte(); + rec.hotspots[1].currentFrame = stream->readByte(); + rec.hotspots[1].destFrame = stream->readByte(); + rec.blocked = stream->readByte(); } // Read final end of list marker @@ -368,8 +366,8 @@ HotspotActionData::HotspotActionData(HotspotActionResource *rec) { uint16 HotspotActionList::getActionOffset(Action action) { iterator i; for (i = begin(); i != end(); ++i) { - HotspotActionData *rec = (*i).get(); - if (rec->action == action) return rec->sequenceOffset; + HotspotActionData const &rec = **i; + if (rec.action == action) return rec.sequenceOffset; } return 0; @@ -435,7 +433,7 @@ HotspotData::HotspotData(HotspotResource *rec) { npcScheduleId = READ_LE_UINT16(&rec->npcSchedule); } -void HotspotData::saveToStream(Common::WriteStream *stream) { +void HotspotData::saveToStream(Common::WriteStream *stream) const { // Write out the basic fields stream->writeUint16LE(nameId); stream->writeUint16LE(descId); @@ -534,12 +532,11 @@ void HotspotData::loadFromStream(Common::ReadStream *stream) { // Hotspot data list -void HotspotDataList::saveToStream(Common::WriteStream *stream) { - iterator i; - for (i = begin(); i != end(); ++i) { - HotspotData *hotspot = (*i).get(); - stream->writeUint16LE(hotspot->hotspotId); - hotspot->saveToStream(stream); +void HotspotDataList::saveToStream(Common::WriteStream *stream) const { + for (const_iterator i = begin(); i != end(); ++i) { + HotspotData const &hotspot = **i; + stream->writeUint16LE(hotspot.hotspotId); + hotspot.saveToStream(stream); } stream->writeUint16LE(0); } @@ -582,14 +579,14 @@ bool MovementDataList::getFrame(uint16 currentFrame, int16 &xChange, iterator i; for (i = begin(); i != end(); ++i) { - MovementData *rec = (*i).get(); + MovementData const &rec = **i; if (foundFlag || (i == begin())) { - xChange = rec->xChange; - yChange = rec->yChange; - nextFrame = rec->frameNumber; + xChange = rec.xChange; + yChange = rec.yChange; + nextFrame = rec.frameNumber; if (foundFlag) return true; } - if (rec->frameNumber == currentFrame) foundFlag = true; + if (rec.frameNumber == currentFrame) foundFlag = true; } return true; @@ -699,15 +696,12 @@ TalkEntryData *TalkData::getResponse(int index) { // The following class acts as a container for all the NPC conversations -void TalkDataList::saveToStream(Common::WriteStream *stream) { - TalkDataList::iterator i; - for (i = begin(); i != end(); ++i) { - TalkData *rec = (*i).get(); - TalkEntryList::iterator i2; +void TalkDataList::saveToStream(Common::WriteStream *stream) const { + for (TalkDataList::const_iterator i = begin(); i != end(); ++i) { + TalkData const &rec = **i; - for (i2 = rec->entries.begin(); i2 != rec->entries.end(); ++i2) { - TalkEntryData *entry = (*i2).get(); - stream->writeUint16LE(entry->descId); + for (TalkEntryList::const_iterator i2 = rec.entries.begin(); i2 != rec.entries.end(); ++i2) { + stream->writeUint16LE((*i2)->descId); } } } @@ -715,12 +709,10 @@ void TalkDataList::saveToStream(Common::WriteStream *stream) { void TalkDataList::loadFromStream(Common::ReadStream *stream) { TalkDataList::iterator i; for (i = begin(); i != end(); ++i) { - TalkData *rec = (*i).get(); - TalkEntryList::iterator i2; + TalkData const &rec = **i; - for (i2 = rec->entries.begin(); i2 != rec->entries.end(); ++i2) { - TalkEntryData *entry = (*i2).get(); - entry->descId = stream->readUint16LE(); + for (TalkEntryList::const_iterator i2 = rec.entries.begin(); i2 != rec.entries.end(); ++i2) { + (*i2)->descId = stream->readUint16LE(); } } } @@ -785,17 +777,17 @@ void SequenceDelayList::tick() { g_system->getMillis()); for (i = begin(); i != end(); ++i) { - SequenceDelayData *entry = (*i).get(); - debugC(ERROR_DETAILED, kLureDebugScripts, "Delay List check %xh at time %d", entry->sequenceOffset, entry->timeoutCtr); + SequenceDelayData &entry = **i; + debugC(ERROR_DETAILED, kLureDebugScripts, "Delay List check %xh at time %d", entry.sequenceOffset, entry.timeoutCtr); - if (entry->timeoutCtr <= GAME_FRAME_DELAY) { + if (entry.timeoutCtr <= GAME_FRAME_DELAY) { // Timeout reached - delete entry from list and execute the sequence - uint16 seqOffset = entry->sequenceOffset; + uint16 seqOffset = entry.sequenceOffset; erase(i); Script::execute(seqOffset); return; } else { - entry->timeoutCtr -= GAME_FRAME_DELAY; + entry.timeoutCtr -= GAME_FRAME_DELAY; } } } @@ -804,22 +796,19 @@ void SequenceDelayList::clear(bool forceClear) { SequenceDelayList::iterator i = begin(); while (i != end()) { - SequenceDelayData *entry = (*i).get(); - if (entry->canClear || forceClear) + if ((*i)->canClear || forceClear) i = erase(i); else ++i; } } -void SequenceDelayList::saveToStream(Common::WriteStream *stream) { - SequenceDelayList::iterator i; - - for (i = begin(); i != end(); ++i) { - SequenceDelayData *entry = (*i).get(); - stream->writeUint16LE(entry->sequenceOffset); - stream->writeUint32LE(entry->timeoutCtr); - stream->writeByte(entry->canClear); +void SequenceDelayList::saveToStream(Common::WriteStream *stream) const { + for (SequenceDelayList::const_iterator i = begin(); i != end(); ++i) { + SequenceDelayData const &entry = **i; + stream->writeUint16LE(entry.sequenceOffset); + stream->writeUint32LE(entry.timeoutCtr); + stream->writeByte(entry.canClear); } stream->writeUint16LE(0); @@ -1016,7 +1005,7 @@ RandomActionSet *RandomActionList::getRoom(uint16 roomNumber) { return NULL; } -void RandomActionSet::saveToStream(Common::WriteStream *stream) { +void RandomActionSet::saveToStream(Common::WriteStream *stream) const { stream->writeByte(numActions()); for (int actionIndex = 0; actionIndex < _numActions; ++actionIndex) stream->writeByte((byte)_types[actionIndex]); @@ -1030,8 +1019,8 @@ void RandomActionSet::loadFromStream(Common::ReadStream *stream) { } -void RandomActionList::saveToStream(Common::WriteStream *stream) { - for (iterator i = begin(); i != end(); ++i) +void RandomActionList::saveToStream(Common::WriteStream *stream) const { + for (const_iterator i = begin(); i != end(); ++i) (*i)->saveToStream(stream); } @@ -1052,9 +1041,9 @@ RoomExitIndexedHotspotData::RoomExitIndexedHotspotData(RoomExitIndexedHotspotRes uint16 RoomExitIndexedHotspotList::getHotspot(uint16 roomNumber, uint8 hotspotIndexId) { iterator i; for (i = begin(); i != end(); ++i) { - RoomExitIndexedHotspotData *entry = (*i).get(); - if ((entry->roomNumber == roomNumber) && (entry->hotspotIndex == hotspotIndexId)) - return entry->hotspotId; + RoomExitIndexedHotspotData const &entry = **i; + if ((entry.roomNumber == roomNumber) && (entry.hotspotIndex == hotspotIndexId)) + return entry.hotspotId; } // No hotspot @@ -1074,12 +1063,12 @@ PausedCharacter::PausedCharacter(uint16 SrcCharId, uint16 DestCharId) { void PausedCharacterList::reset(uint16 hotspotId) { iterator i; for (i = begin(); i != end(); ++i) { - PausedCharacter *rec = (*i).get(); + PausedCharacter &rec = **i; - if (rec->srcCharId == hotspotId) { - rec->counter = 1; - if (rec->destCharId < START_EXIT_ID) - rec->charHotspot->pauseCtr = 1; + if (rec.srcCharId == hotspotId) { + rec.counter = 1; + if (rec.destCharId < START_EXIT_ID) + rec.charHotspot->pauseCtr = 1; } } } @@ -1088,15 +1077,15 @@ void PausedCharacterList::countdown() { iterator i = begin(); while (i != end()) { - PausedCharacter *rec = (*i).get(); - --rec->counter; + PausedCharacter &rec = **i; + --rec.counter; // Handle reflecting counter to hotspot - if (rec->destCharId < START_EXIT_ID) - rec->charHotspot->pauseCtr = rec->counter + 1; + if (rec.destCharId < START_EXIT_ID) + rec.charHotspot->pauseCtr = rec.counter + 1; // If counter has reached zero, remove entry from list - if (rec->counter == 0) + if (rec.counter == 0) i = erase(i); else ++i; @@ -1109,13 +1098,13 @@ void PausedCharacterList::scan(Hotspot &h) { if (h.blockedState() != BS_NONE) { for (i = begin(); i != end(); ++i) { - PausedCharacter *rec = (*i).get(); + PausedCharacter &rec = **i; - if (rec->srcCharId == h.hotspotId()) { - rec->counter = IDLE_COUNTDOWN_SIZE; + if (rec.srcCharId == h.hotspotId()) { + rec.counter = IDLE_COUNTDOWN_SIZE; - if (rec->destCharId < START_EXIT_ID) - rec->charHotspot->pauseCtr = IDLE_COUNTDOWN_SIZE; + if (rec.destCharId < START_EXIT_ID) + rec.charHotspot->pauseCtr = IDLE_COUNTDOWN_SIZE; } } } @@ -1139,9 +1128,9 @@ 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).get(); - foundEntry = (rec->srcCharId == charId) && - (rec->destCharId == hotspot->hotspotId()); + PausedCharacter const &rec = **i; + foundEntry = (rec.srcCharId == charId) && + (rec.destCharId == hotspot->hotspotId()); } if (foundEntry) @@ -1196,7 +1185,7 @@ BarEntry &BarmanLists::getDetails(uint16 roomNumber) { error("Invalid room %d specified for barman details retrieval", roomNumber); } -void BarmanLists::saveToStream(Common::WriteStream *stream) { +void BarmanLists::saveToStream(Common::WriteStream *stream) const { for (int index = 0; index < 3; ++index) { uint16 value = (_barList[index].currentCustomer == NULL) ? 0 : (_barList[index].currentCustomer - &_barList[index].customers[0]) / sizeof(BarEntry) + 1; @@ -1296,7 +1285,7 @@ void ValueTableData::setField(FieldName fieldName, uint16 value) { setField((uint16) fieldName, value); } -void ValueTableData::saveToStream(Common::WriteStream *stream) { +void ValueTableData::saveToStream(Common::WriteStream *stream) const { // Write out the special fields stream->writeUint16LE(_numGroats); stream->writeSint16LE(_playerNewPos.position.x); @@ -1371,7 +1360,7 @@ void CurrentActionEntry::setSupportData(uint16 entryId) { setSupportData(newEntry); } -void CurrentActionEntry::saveToStream(Common::WriteStream *stream) { +void CurrentActionEntry::saveToStream(Common::WriteStream *stream) const { debugC(ERROR_DETAILED, kLureDebugAnimations, "Saving hotspot action entry dyn=%d id=%d", hasSupportData(), hasSupportData() ? supportData().id() : 0); stream->writeByte((uint8) _action); @@ -1443,11 +1432,11 @@ Common::String CurrentActionStack::getDebugInfo() const { buffer += Common::String::format("CurrentActionStack::list num_actions=%d\n", size()); for (i = _actions.begin(); i != _actions.end(); ++i) { - CurrentActionEntry *entry = (*i).get(); - buffer += Common::String::format("style=%d room#=%d", entry->action(), entry->roomNumber()); + CurrentActionEntry const &entry = **i; + buffer += Common::String::format("style=%d room#=%d", entry.action(), entry.roomNumber()); - if (entry->hasSupportData()) { - CharacterScheduleEntry &rec = entry->supportData(); + if (entry.hasSupportData()) { + CharacterScheduleEntry &rec = entry.supportData(); buffer += Common::String::format(", action=%d params=", rec.action()); @@ -1466,16 +1455,13 @@ Common::String CurrentActionStack::getDebugInfo() const { return buffer; } -void CurrentActionStack::saveToStream(Common::WriteStream *stream) { - ActionsList::iterator i; - +void CurrentActionStack::saveToStream(Common::WriteStream *stream) const { debugC(ERROR_DETAILED, kLureDebugAnimations, "Saving hotspot action stack"); Common::String buffer = getDebugInfo(); debugC(ERROR_DETAILED, kLureDebugAnimations, "%s", buffer.c_str()); - for (i = _actions.begin(); i != _actions.end(); ++i) { - CurrentActionEntry *rec = (*i).get(); - rec->saveToStream(stream); + for (ActionsList::const_iterator i = _actions.begin(); i != _actions.end(); ++i) { + (*i)->saveToStream(stream); } stream->writeByte(0xff); // End of list marker debugC(ERROR_DETAILED, kLureDebugAnimations, "Finished saving hotspot action stack"); |