diff options
author | uruk | 2014-06-08 09:53:47 +0200 |
---|---|---|
committer | uruk | 2014-06-08 09:53:47 +0200 |
commit | 9afe6bd570e5445db951792f338d2781ad67d1ee (patch) | |
tree | a6d2b0ff47560b2cce6faff09198bc994cabe645 | |
parent | cfe03245fae13dff869ea6f8c934fb510161e431 (diff) | |
download | scummvm-rg350-9afe6bd570e5445db951792f338d2781ad67d1ee.tar.gz scummvm-rg350-9afe6bd570e5445db951792f338d2781ad67d1ee.tar.bz2 scummvm-rg350-9afe6bd570e5445db951792f338d2781ad67d1ee.zip |
CGE2: Add, implement and use Map.
-rw-r--r-- | engines/cge2/cge2.cpp | 4 | ||||
-rw-r--r-- | engines/cge2/cge2.h | 3 | ||||
-rw-r--r-- | engines/cge2/cge2_main.cpp | 6 | ||||
-rw-r--r-- | engines/cge2/map.cpp | 92 | ||||
-rw-r--r-- | engines/cge2/map.h | 54 | ||||
-rw-r--r-- | engines/cge2/module.mk | 3 |
6 files changed, 156 insertions, 6 deletions
diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 231e72b6f3..b32ca76489 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -38,6 +38,7 @@ #include "cge2/events.h" #include "cge2/talk.h" #include "cge2/cge2_main.h" +#include "cge2/map.h" namespace CGE2 { @@ -71,6 +72,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _vol[i] = nullptr; _eventManager = nullptr; _blinkSprite = nullptr; + _map = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -117,6 +119,7 @@ void CGE2Engine::init() { _point[i] = new V3D(); _sys = new System(this); _eventManager = new EventManager(this); + _map = new Map(this); } void CGE2Engine::deinit() { @@ -149,6 +152,7 @@ void CGE2Engine::deinit() { delete _eventManager; if (_blinkSprite != nullptr) delete _blinkSprite; + delete _map; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index dcbffdf389..4fc8576678 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -57,6 +57,7 @@ class Bitmap; class System; class EventManager; class Font; +class Map; #define kScrWidth 320 #define kScrHeight 240 @@ -109,7 +110,6 @@ public: void showBak(int ref); void loadTab(); int newRandom(int range); - void loadMap(int cav); void openPocket(); void selectPocket(int n); void busy(bool on); @@ -238,6 +238,7 @@ public: Sprite *_vol[2]; EventManager *_eventManager; Sprite *_blinkSprite; + Map *_map; private: void init(); void deinit(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 7d9e715123..e256d72db6 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -34,6 +34,7 @@ #include "cge2/hero.h" #include "cge2/spare.h" #include "cge2/events.h" +#include "cge2/map.h" namespace CGE2 { @@ -416,6 +417,7 @@ void CGE2Engine::caveUp(int cav) { showBak(bakRef); *_eye = *(_eyeTab[_now]); _mouseTop = V2D(this, V3D(0, 1, kScrDepth)).y; + _map->load(_now); _spare->takeCave(_now); openPocket(); @@ -545,10 +547,6 @@ void CGE2Engine::tick() { _mouse->tick(); } -void CGE2Engine::loadMap(int cav) { - warning("STUB: CGE2Engine::loadMap()"); -} - void CGE2Engine::openPocket() { warning("STUB: CGE2Engine::openPocket()"); } diff --git a/engines/cge2/map.cpp b/engines/cge2/map.cpp new file mode 100644 index 0000000000..ed8ce21b3b --- /dev/null +++ b/engines/cge2/map.cpp @@ -0,0 +1,92 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge2/map.h" +#include "cge2/cge2_main.h" + +namespace CGE2 { + +Map::Map(CGE2Engine *vm) :_vm(vm) {} + +Map::~Map() { + _container.clear(); +} + +int Map::convertCoord(int coord) { + return (coord + (kMapGrid >> 1)) & kMapMask; +} + +void Map::load(int cave) { + char fname[] = "%.2d.MAP\0"; + Common::String filename = Common::String::format(fname, cave); + clear(); + if (!_vm->_resman->exist(filename.c_str())) + return; + + EncryptedStream file(_vm, filename.c_str()); + + char tmpStr[kLineMax + 1]; + Common::String line; + + for (line = file.readLine(); !file.eos(); line = file.readLine()) { + if (line.size() == 0) + continue; + + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + + char *currPos = tmpStr; + currPos = strtok(currPos, " (),"); + int x = atoi(currPos); + currPos = strtok(nullptr, " (),"); + int y = atoi(currPos); + _container.push_back(V2D(_vm, convertCoord(x), convertCoord(y))); + + while (true) { + currPos = strtok(nullptr, " (),"); + if (currPos == nullptr) + break; + int x = atoi(currPos); + currPos = strtok(nullptr, " (),"); + int y = atoi(currPos); + _container.push_back(V2D(_vm, convertCoord(x), convertCoord(y))); + } + } +} + +int Map::size() { + return _container.size(); +} + +void Map::clear() { + _container.clear(); +} + +V2D &Map::operator[](int idx) { + return _container[idx]; +} + +} // End of namespace CGE2 diff --git a/engines/cge2/map.h b/engines/cge2/map.h new file mode 100644 index 0000000000..7b792b25dd --- /dev/null +++ b/engines/cge2/map.h @@ -0,0 +1,54 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_MAP_H +#define CGE2_MAP_H + +#include "cge2/vga13h.h" + +namespace CGE2 { + +#define kMapGrid 4 +#define kMapMask (~(kMapGrid - 1)) + +class Map { + CGE2Engine *_vm; + Common::Array<V2D> _container; + + int convertCoord(int coord); +public: + Map(CGE2Engine *vm); + ~Map(); + void load(int cave); + int size(); + void clear(); + V2D &operator[](int idx); +}; + +} // End of namespace CGE2 + +#endif // CGE2_MAP_H diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index 7272ed3829..dc74de5ed6 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -13,7 +13,8 @@ MODULE_OBJS = \ snail.o \ spare.o \ talk.o \ - events.o + events.o \ + map.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) |