From dd116cfbf01b87c201249d98b2384e2671ff04bf Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 8 Jun 2015 20:37:08 -0400 Subject: SHERLOCK: Add RT map data loading --- engines/sherlock/tattoo/tattoo_map.cpp | 73 ++++++++++++++++++++++++++++++++++ engines/sherlock/tattoo/tattoo_map.h | 18 ++++++++- 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/engines/sherlock/tattoo/tattoo_map.cpp b/engines/sherlock/tattoo/tattoo_map.cpp index ced7ed9a58..3a02d5b7ce 100644 --- a/engines/sherlock/tattoo/tattoo_map.cpp +++ b/engines/sherlock/tattoo/tattoo_map.cpp @@ -21,16 +21,89 @@ */ #include "sherlock/tattoo/tattoo_map.h" +#include "sherlock/sherlock.h" namespace Sherlock { namespace Tattoo { +void MapEntry::clear() { + _iconNum = -1; + _description = ""; +} + +/*-------------------------------------------------------------------------*/ + +TattooMap::TattooMap(SherlockEngine *vm) : Map(vm) { + loadData(); +} + int TattooMap::show() { // TODO return 61; } +void TattooMap::loadData() { + Resources &res = *_vm->_res; + char c; + + Common::SeekableReadStream *stream = res.load("map.txt"); + + _data.resize(100); + for (uint idx = 0; idx < _data.size(); ++idx) + _data[idx].clear(); + + do + { + // Find the start of the number + do { + c = stream->readByte(); + if (stream->pos() >= stream->size()) + return; + } while (c < '0' || c > '9'); + + // Get the scene number + Common::String locStr; + locStr += c; + while ((c = stream->readByte()) != '.') + locStr += c; + MapEntry &mapEntry = _data[atoi(locStr.c_str()) - 1]; + + // Get the location name + while (stream->readByte() != '"') + ; + + while ((c = stream->readByte()) != '"') + mapEntry._description += c; + + // Find the ( specifying the (X,Y) position of the Icon + while (stream->readByte() != '(') + ; + + // Get the X Position of the icon + Common::String numStr; + while ((c = stream->readByte()) != ',') + numStr += c; + mapEntry.x = atoi(numStr.c_str()); + + // Get the Y position of the icon + numStr = ""; + while ((c = stream->readByte()) != ')') + numStr += c; + mapEntry.y = atoi(numStr.c_str()); + + // Find and get the location's icon number + while (stream->readByte() != '#') + ; + + Common::String iconStr; + while (stream->pos() < stream->size() && (c = stream->readByte()) != '\r') + iconStr += c; + + mapEntry._iconNum = atoi(iconStr.c_str()) - 1; + } while (stream->pos() < stream->size()); +} + } // End of namespace Tattoo } // End of namespace Sherlock diff --git a/engines/sherlock/tattoo/tattoo_map.h b/engines/sherlock/tattoo/tattoo_map.h index 750cd90c3b..b0c1a3fbc0 100644 --- a/engines/sherlock/tattoo/tattoo_map.h +++ b/engines/sherlock/tattoo/tattoo_map.h @@ -32,9 +32,25 @@ class SherlockEngine; namespace Tattoo { +struct MapEntry : Common::Point { + int _iconNum; + Common::String _description; + + MapEntry() : Common::Point(), _iconNum(-1) {} + MapEntry(int posX, int posY, int iconNum) : Common::Point(posX, posY), _iconNum(iconNum) {} + void clear(); +}; + class TattooMap : public Map { +private: + Common::Array _data; + + /** + * Load data needed for the map + */ + void loadData(); public: - TattooMap(SherlockEngine *vm) : Map(vm) {} + TattooMap(SherlockEngine *vm); virtual ~TattooMap() {} /** -- cgit v1.2.3