diff --git a/engines/saga2/automap.cpp b/engines/saga2/automap.cpp index fa1762d465c..80cc357a439 100644 --- a/engines/saga2/automap.cpp +++ b/engines/saga2/automap.cpp @@ -553,15 +553,13 @@ int16 openAutoMap() { uint16 closeButtonResID = 0; uint16 scrollButtonResID = 2; - extern int16 currentMapNum; - - updateMapFeatures(currentMapNum); + updateMapFeatures(g_vm->_currentMapNum); // init the resource context handle decRes = resFile->newContext(MKTAG('A', 'M', 'A', 'P'), "Automap Resources"); // debug - _summaryData = LoadResource(decRes, MKTAG('S', 'U', 'M', currentMapNum), "summary data"); + _summaryData = LoadResource(decRes, MKTAG('S', 'U', 'M', g_vm->_currentMapNum), "summary data"); // get the graphics associated with the buttons closeBtnImage = loadButtonRes(decRes, closeButtonResID, numBtnImages); diff --git a/engines/saga2/beegee.cpp b/engines/saga2/beegee.cpp index de493425284..9c9d706e129 100644 --- a/engines/saga2/beegee.cpp +++ b/engines/saga2/beegee.cpp @@ -130,7 +130,6 @@ const static StaticTilePoint AudibilityVector = { 1, 1, 0 }; extern volatile int32 gameTime; -extern int16 currentMapNum; // which map is in use extern uint16 rippedRoofID; extern GameObject *getViewCenterObject(void); @@ -266,7 +265,7 @@ void setAreaSound(const TilePoint &) { TilePoint AudVec = TilePoint(AudibilityVector); regn.max = baseCoords + ((AudVec * r) << kPlatShift) ; ///kTileUVSize; regn.min = baseCoords - ((AudVec * r) << kPlatShift); ///kTileUVSize; - MetaTileIterator mIter(currentMapNum, regn); + MetaTileIterator mIter(g_vm->_currentMapNum, regn); int i = 0; int j = 0; diff --git a/engines/saga2/console.cpp b/engines/saga2/console.cpp index 497d1849e66..d89436f360c 100644 --- a/engines/saga2/console.cpp +++ b/engines/saga2/console.cpp @@ -37,7 +37,6 @@ namespace Saga2 { extern GameObject *objectList; extern WorldMapData *mapList; -extern int16 currentMapNum; Console::Console(Saga2Engine *vm) : GUI::Debugger() { _vm = vm; @@ -394,8 +393,6 @@ bool Console::cmdDumpMap(int argc, const char **argv) { else { gPixelMap drawMap; drawMap.size = _vm->_tileDrawMap.size * atoi(argv[1]); - //drawMap.size.x = mapList[currentMapNum].mapHeight; - //drawMap.size.y = mapList[currentMapNum].mapHeight; drawMap.data = new uint8[drawMap.bytes()](); drawMetaTiles(drawMap); diff --git a/engines/saga2/dispnode.cpp b/engines/saga2/dispnode.cpp index 01028bd78a2..b09545aef8a 100644 --- a/engines/saga2/dispnode.cpp +++ b/engines/saga2/dispnode.cpp @@ -43,7 +43,6 @@ bool centerActorIndicatorEnabled; Imports * ===================================================================== */ -extern int16 currentMapNum; extern WorldMapData *mapList; extern StaticPoint16 fineScroll; @@ -382,8 +381,8 @@ void DisplayNode::drawObject(void) { mCoords.z = 0; // Do not display objects that are on a ripped roof - if ((mt = mapList[currentMapNum].lookupMeta(mCoords)) != NULL) { - if ((rt = mt->ripTable(currentMapNum)) != NULL) { + if ((mt = mapList[g_vm->_currentMapNum].lookupMeta(mCoords)) != NULL) { + if ((rt = mt->ripTable(g_vm->_currentMapNum)) != NULL) { if (objCoords.z >= rt->zTable[tCoords.u][tCoords.v]) { // Disable hit-test on the object's box hitBox.width = -1; diff --git a/engines/saga2/saga2.cpp b/engines/saga2/saga2.cpp index df3bf9f03e1..4e3d4a2c16d 100644 --- a/engines/saga2/saga2.cpp +++ b/engines/saga2/saga2.cpp @@ -90,6 +90,7 @@ Saga2Engine::Saga2Engine(OSystem *syst) _indivControlsFlag = false; _userControlsSetup = false; _fadeDepth = 1; + _currentMapNum = 0; SearchMan.addSubDirectoryMatching(gameDataDir, "res"); SearchMan.addSubDirectoryMatching(gameDataDir, "dos/drivers"); // For Miles Sound files diff --git a/engines/saga2/saga2.h b/engines/saga2/saga2.h index d852285aec7..64a55693b4a 100644 --- a/engines/saga2/saga2.h +++ b/engines/saga2/saga2.h @@ -195,6 +195,7 @@ public: bool _indivControlsFlag; bool _userControlsSetup; int _fadeDepth; + int _currentMapNum; private: diff --git a/engines/saga2/tile.cpp b/engines/saga2/tile.cpp index bf1afda18af..30a13c664a9 100644 --- a/engines/saga2/tile.cpp +++ b/engines/saga2/tile.cpp @@ -197,7 +197,6 @@ StaticTilePoint viewCenter = {0, 0, 0}; // coordinates of view on ma // These two variables define which sectors overlap the view rect. -int16 currentMapNum; // which map is in use int16 lastMapNum; int32 lastUpdateTime; // time of last display update @@ -1513,9 +1512,9 @@ void cleanupMaps(void) { // Set a new current map void setCurrentMap(int mapNum) { - currentMapNum = mapNum; - if (lastMapNum != currentMapNum) { - lastMapNum = currentMapNum; + g_vm->_currentMapNum = mapNum; + if (lastMapNum != g_vm->_currentMapNum) { + lastMapNum = g_vm->_currentMapNum; freeAllTileBanks(); audioEnvironmentSetWorld(mapNum); } @@ -1681,7 +1680,7 @@ void initPlatformCache(void) { * ===================================================================== */ TilePoint XYToUV(const Point32 &pt) { - int32 mapHeight = mapList[currentMapNum].mapHeight; + int32 mapHeight = mapList[g_vm->_currentMapNum].mapHeight; TilePoint coords; // coordinates of the view in U,V @@ -1698,7 +1697,7 @@ TilePoint XYToUV(const Point32 &pt) { * ===================================================================== */ void TileToScreenCoords(const TilePoint &tp, Point16 &p) { - int32 mapHeight = mapList[currentMapNum].mapHeight; + int32 mapHeight = mapList[g_vm->_currentMapNum].mapHeight; // screen coords of the point p.x = (((int32)tp.u - (int32)tp.v) << 1) - tileScroll.x + mapHeight; @@ -1706,7 +1705,7 @@ void TileToScreenCoords(const TilePoint &tp, Point16 &p) { } void TileToScreenCoords(const TilePoint &tp, StaticPoint16 &p) { - int32 mapHeight = mapList[currentMapNum].mapHeight; + int32 mapHeight = mapList[g_vm->_currentMapNum].mapHeight; // screen coords of the point p.x = (((int32)tp.u - (int32)tp.v) << 1) - tileScroll.x + mapHeight; @@ -2495,7 +2494,7 @@ TileInfo *TileIterator::next(TilePoint *loc, StandingTileInfo *stiResult) { * ============================================================================ */ inline void drawMetaRow(gPixelMap &drawMap, TilePoint coords, Point16 pos) { - WorldMapData *curMap = &mapList[currentMapNum]; + WorldMapData *curMap = &mapList[g_vm->_currentMapNum]; int16 uOrg = coords.u * kPlatformWidth, vOrg = coords.v * kPlatformWidth; @@ -2565,7 +2564,7 @@ inline void drawMetaRow(gPixelMap &drawMap, TilePoint coords, Point16 pos) { for (int i = 0; i < layerLimit; i++) { Platform *p; - p = metaPtr->fetchPlatform(currentMapNum, i); + p = metaPtr->fetchPlatform(g_vm->_currentMapNum, i); if (!p) continue; @@ -2606,8 +2605,8 @@ void buildRipTable( int32 *initPtr = (int32 *)ripTable->zTable; // Initialize table - mt->ripTableID(currentMapNum) = ripTable->thisID(); - ripTable->metaID = mt->thisID(currentMapNum); + mt->ripTableID(g_vm->_currentMapNum) = ripTable->thisID(); + ripTable->metaID = mt->thisID(g_vm->_currentMapNum); ripTable->ripID = ripID; for (uint i = 0; @@ -2625,12 +2624,12 @@ void buildRipTable( for (uint i = 0; i < maxPlatforms; i++) { Platform *p; - if ((p = mt->fetchPlatform(currentMapNum, i)) == nullptr) continue; + if ((p = mt->fetchPlatform(g_vm->_currentMapNum, i)) == nullptr) continue; if (p->roofRipID() != ripID) continue; for (; i < maxPlatforms && tilesToGo > 0; i++) { - if ((p = mt->fetchPlatform(currentMapNum, i)) == nullptr) + if ((p = mt->fetchPlatform(g_vm->_currentMapNum, i)) == nullptr) continue; uint16 platHeight = p->height << 3; @@ -2683,7 +2682,7 @@ void buildRipTables(void) { ripTableReg.max.v = (actorCoords.v + regionRadius + kTileUVMask) >> kTileUVShift; - MetaTileIterator mIter(currentMapNum, ripTableReg); + MetaTileIterator mIter(g_vm->_currentMapNum, ripTableReg); // Build meta tile pointer array mt = mIter.first(); @@ -2703,7 +2702,7 @@ void buildRipTables(void) { for (int i = 0; i < mtTableSize; i++) { mt = mtTable[i]; - RipTable *mtRipTable = mt->ripTable(currentMapNum); + RipTable *mtRipTable = mt->ripTable(g_vm->_currentMapNum); // If meta tile aready has a valid object ripping table, simply // recycle it @@ -2779,9 +2778,9 @@ void drawMetaTiles(gPixelMap &drawMap) { // coordinates of the view window on the map in X,Y (in 16 pixel units) viewPos.x = (tileScroll.x >> kTileDXShift) - - (kPlatformWidth * mapList[currentMapNum].mapSize), + - (kPlatformWidth * mapList[g_vm->_currentMapNum].mapSize), viewPos.y = (kPlatformWidth - * mapList[currentMapNum].mapSize + * mapList[g_vm->_currentMapNum].mapSize * kTileDX) - tileScroll.y; @@ -3020,7 +3019,7 @@ void maskPlatform( int16 trFlags; ti = p.fetchTile( - currentMapNum, + g_vm->_currentMapNum, pCoords, origin, &imageData, @@ -3072,7 +3071,7 @@ void maskMetaRow( TilePoint relLoc, Point16 pos, uint16 roofID) { - WorldMapData *curMap = &mapList[currentMapNum]; + WorldMapData *curMap = &mapList[g_vm->_currentMapNum]; int16 uOrg = coords.u * kPlatformWidth, vOrg = coords.v * kPlatformWidth; @@ -3146,7 +3145,7 @@ void maskMetaRow( for (int i = 0; i < layerLimit; i++) { Platform *p; - if ((p = metaPtr->fetchPlatform(currentMapNum, i)) == nullptr) + if ((p = metaPtr->fetchPlatform(g_vm->_currentMapNum, i)) == nullptr) continue; if (p->roofRipID() == roofID && roofID > 0) break; @@ -3191,9 +3190,9 @@ void drawTileMask( // coordinates of the view window on the map in X,Y (in 16 pixel units) viewPos.x = (aPos.x >> kTileDXShift) - - (kPlatformWidth * mapList[currentMapNum].mapSize), + - (kPlatformWidth * mapList[g_vm->_currentMapNum].mapSize), viewPos.y = (kPlatformWidth - * mapList[currentMapNum].mapSize << kTileDXShift) + * mapList[g_vm->_currentMapNum].mapSize << kTileDXShift) - aPos.y; // coordinates of the view window upper left corner in U,V @@ -3777,7 +3776,7 @@ bool pointOnHiddenSurface( SurfaceType surfaceType) { assert(surfaceType == surfaceVertU || surfaceType == surfaceVertV); - WorldMapData *curMap = &mapList[currentMapNum]; + WorldMapData *curMap = &mapList[g_vm->_currentMapNum]; TilePoint testCoords, mCoords, @@ -3829,14 +3828,14 @@ bool pointOnHiddenSurface( int16 h, trFlags; - if ((p = mt->fetchPlatform(currentMapNum, i)) == nullptr) + if ((p = mt->fetchPlatform(g_vm->_currentMapNum, i)) == nullptr) continue; if (!(p->flags & plVisible) || platformRipped(p)) continue; // Fetch the tile at this location adjTile = p->fetchTile( - currentMapNum, + g_vm->_currentMapNum, tCoords, origin, h, @@ -3870,7 +3869,7 @@ StaticTilePoint pickTile(Point32 pos, const TilePoint &protagPos, StaticTilePoint *floorResult, ActiveItemPtr *pickTAI) { - WorldMapData *curMap = &mapList[currentMapNum]; + WorldMapData *curMap = &mapList[g_vm->_currentMapNum]; StaticTilePoint result = {0, 0, 0}; TilePoint pickCoords, @@ -3963,7 +3962,7 @@ StaticTilePoint pickTile(Point32 pos, Platform *p; StandingTileInfo sti; - if ((p = mt->fetchPlatform(currentMapNum, i)) == nullptr) + if ((p = mt->fetchPlatform(g_vm->_currentMapNum, i)) == nullptr) continue; if (platformRipped(p)) break; @@ -3972,7 +3971,7 @@ StaticTilePoint pickTile(Point32 pos, // Fetch the tile at this location ti = p->fetchTAGInstance( - currentMapNum, + g_vm->_currentMapNum, tCoords, origin, &imageData, @@ -4318,7 +4317,7 @@ void updateMainDisplay(void) { setCurrentMap(currentWorld->mapNum); } - WorldMapData *curMap = &mapList[currentMapNum]; + WorldMapData *curMap = &mapList[g_vm->_currentMapNum]; StaticPoint32 scrollCenter, scrollDelta; @@ -4473,7 +4472,7 @@ const int mappingRadius = 2; void markMetaAsVisited(const TilePoint &pt) { // If (they have cartography) { - WorldMapData *curMap = &mapList[currentMapNum]; + WorldMapData *curMap = &mapList[g_vm->_currentMapNum]; uint16 *mapData = curMap->map->mapData; TilePoint metaCoords = pt >> (kTileUVShift + kPlatShift); diff --git a/engines/saga2/tileload.cpp b/engines/saga2/tileload.cpp index 827320cbd4f..e9498b19943 100644 --- a/engines/saga2/tileload.cpp +++ b/engines/saga2/tileload.cpp @@ -40,7 +40,6 @@ const uint16 tileBankCount = 64; const uint32 tileImageID = MKTAG('T', 'I', 'L', 0); -extern int16 currentMapNum; extern hResource *objResFile; extern hResContext *tileRes; // tile resource handle @@ -121,7 +120,7 @@ void drawPlatform( uint8 *imageData; int16 trFlags; - TileInfo *ti = p.fetchTile(currentMapNum, pCoords, origin, &imageData, h, trFlags); + TileInfo *ti = p.fetchTile(g_vm->_currentMapNum, pCoords, origin, &imageData, h, trFlags); if (ti == NULL) continue; diff --git a/engines/saga2/transit.cpp b/engines/saga2/transit.cpp index b556b038a18..24439f67b12 100644 --- a/engines/saga2/transit.cpp +++ b/engines/saga2/transit.cpp @@ -35,8 +35,6 @@ namespace Saga2 { -extern int16 currentMapNum; // which map is in use - /* ===================================================================== * Prototypes * ===================================================================== */ @@ -78,7 +76,7 @@ void dayNightUpdate(void) { lightLevel, MAX_LIGHT); - if (currentMapNum == 0) + if (g_vm->_currentMapNum == 0) g_vm->_pal->beginFade(&g_vm->_pal->_newPalette, 100); } @@ -86,7 +84,7 @@ void dayNightUpdate(void) { gPalettePtr neededPalette; gPalette currentPalette; - neededPalette = currentMapNum == 0 ? &g_vm->_pal->_newPalette : g_vm->_pal->_noonPalette; + neededPalette = g_vm->_currentMapNum == 0 ? &g_vm->_pal->_newPalette : g_vm->_pal->_noonPalette; g_vm->_pal->getCurrentPalette(¤tPalette); if (memcmp(¤tPalette, neededPalette, sizeof(gPalette)) != 0) g_vm->_pal->setCurrentPalette(neededPalette); @@ -129,7 +127,7 @@ void fadeUp(void) { drawMainDisplay(); reDrawScreen(); enablePaletteChanges(); - g_vm->_pal->beginFade(currentMapNum != 0 ? g_vm->_pal->_noonPalette : &g_vm->_pal->_newPalette, 20); + g_vm->_pal->beginFade(g_vm->_currentMapNum != 0 ? g_vm->_pal->_noonPalette : &g_vm->_pal->_newPalette, 20); while (g_vm->_pal->updatePalette()) ; } }