diff options
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/src/map.cpp b/src/map.cpp index f8c4e007e..8225aded1 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -622,7 +622,8 @@ Map::Map(int width, int height, int tileWidth, int tileHeight): mDrawY(-1), mDrawScrollX(-1), mDrawScrollY(-1), - mRedrawMap(true) + mRedrawMap(true), + mBeingOpacity(false) { const int size = mWidth * mHeight; @@ -639,6 +640,13 @@ Map::Map(int width, int height, int tileWidth, int tileHeight): config.addListener("OverlayDetail", this); config.addListener("guialpha", this); + config.addListener("beingopacity", this); + + mOpacity = config.getFloatValue("guialpha"); + if (mOpacity != 1.0f) + mBeingOpacity = config.getBoolValue("beingopacity"); + else + mBeingOpacity = false; #ifdef USE_OPENGL mOpenGL = config.getIntValue("opengl"); @@ -651,6 +659,7 @@ Map::~Map() { config.removeListener("OverlayDetail", this); config.removeListener("guialpha", this); + config.removeListener("beingopacity", this); // delete metadata, layers, tilesets and overlays delete[] mMetaTiles; @@ -675,9 +684,24 @@ Map::~Map() void Map::optionChanged(const std::string &value) { if (value == "OverlayDetail") + { mOverlayDetail = config.getIntValue("OverlayDetail"); + } else if (value == "guialpha") + { mOpacity = config.getFloatValue("guialpha"); + if (mOpacity != 1.0f) + mBeingOpacity = config.getBoolValue("beingopacity"); + else + mBeingOpacity = false; + } + else if (value == "beingopacity") + { + if (mOpacity != 1.0f) + mBeingOpacity = config.getBoolValue("beingopacity"); + else + mBeingOpacity = false; + } } void Map::initializeAmbientLayers() @@ -895,7 +919,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) } // Dont draw if gui opacity == 1 - if (mOpacity != 1.0f) + if (mBeingOpacity && mOpacity != 1.0f) { // Draws beings with a lower opacity to make them visible // even when covered by a wall or some other elements... @@ -1360,7 +1384,7 @@ Path Map::findPath(int startX, int startY, int destX, int destY, return path; // Reset starting tile's G cost to 0 - MetaTile *startTile = getMetaTile(startX, startY); + MetaTile *startTile = &mMetaTiles[startX + startY * mWidth]; startTile->Gcost = 0; // Add the start point to the open list @@ -1383,21 +1407,26 @@ Path Map::findPath(int startX, int startY, int destX, int destY, // Put the current tile on the closed list curr.tile->whichList = mOnClosedList; + const int curWidth = curr.y * mWidth; + // Check the adjacent tiles for (int dy = -1; dy <= 1; dy++) { + const int y = curr.y + dy; + const int yWidth = y * mWidth; + const int dy1 = std::abs(y - destY); + for (int dx = -1; dx <= 1; dx++) { // Calculate location of tile to check const int x = curr.x + dx; - const int y = curr.y + dy; // Skip if if we're checking the same tile we're leaving from, // or if the new location falls outside of the map boundaries if ((dx == 0 && dy == 0) || !contains(x, y)) continue; - MetaTile *newTile = getMetaTile(x, y); + MetaTile *newTile = &mMetaTiles[x + yWidth]; // Skip if the tile is on the closed list or is not walkable // unless its the destination tile @@ -1414,8 +1443,9 @@ Path Map::findPath(int startX, int startY, int destX, int destY, // corner. if (dx != 0 && dy != 0) { - MetaTile *t1 = getMetaTile(curr.x, curr.y + dy); - MetaTile *t2 = getMetaTile(curr.x + dx, curr.y); + MetaTile *t1 = &mMetaTiles[curr.x + + (curr.y + dy) * mWidth]; + MetaTile *t2 = &mMetaTiles[curr.x + dx + curWidth]; //+++ here need check block must depend on player abilities. if (!t1 || !t2 || ((t1->blockmask | t2->blockmask) @@ -1463,9 +1493,9 @@ Path Map::findPath(int startX, int startY, int destX, int destY, work reliably if the heuristic cost is higher than the real cost. In particular, using Manhattan distance is forbidden here. */ - int dx = std::abs(x - destX), dy = std::abs(y - destY); - newTile->Hcost = std::abs(dx - dy) * basicCost + - std::min(dx, dy) * (basicCost * 362 / 256); + int dx1 = std::abs(x - destX); + newTile->Hcost = std::abs(dx1 - dy1) * basicCost + + std::min(dx1, dy1) * (basicCost * 362 / 256); // Set the current tile as the parent of the new tile newTile->parentX = curr.x; @@ -1538,7 +1568,7 @@ Path Map::findPath(int startX, int startY, int destX, int destY, path.push_front(Position(pathX, pathY)); // Find out the next parent - MetaTile *tile = getMetaTile(pathX, pathY); + MetaTile *tile = &mMetaTiles[pathX + pathY * mWidth]; pathX = tile->parentX; pathY = tile->parentY; } |