From f7a93f4cd35790e41e18e119c2cadaf223a73e71 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 10 Nov 2024 09:55:09 +0000 Subject: [PATCH] Improve `dev.display.path()` 1. Do not draw foliage with the pause trn. 2. Display the number of steps. 3. If the tile is not walkable (allowed for destination tile), display the number of steps in yellow. --- Source/engine/render/scrollrt.cpp | 32 ++++++++++++++++++++++++------- Source/player.cpp | 10 +++++----- Source/player.h | 4 ++-- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index 271a9a9d58c..0e656c13888 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -477,9 +477,17 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition const MICROS *pMap = &DPieceMicros[levelPieceId]; const uint8_t *tbl = LightTables[lightTableIndex].data(); + const uint8_t *foliageTbl = tbl; #ifdef _DEBUG - if (DebugPath && MyPlayer->IsPositionInPath(tilePosition)) - tbl = GetPauseTRN(); + int walkpathIdx = -1; + Point originalTargetBufferPosition; + if (DebugPath) { + walkpathIdx = MyPlayer->GetPositionPathIndex(tilePosition); + if (walkpathIdx != -1) { + originalTargetBufferPosition = targetBufferPosition; + tbl = GetPauseTRN(); + } + } #endif bool transparency = TileHasAny(tilePosition, TileProperties::Transparent) && TransList[dTransVal[tilePosition.x][tilePosition.y]]; @@ -529,7 +537,7 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition const TileType tileType = levelCelBlock.type(); if (!isFloor || tileType == TileType::TransparentSquare) { if (isFloor && tileType == TileType::TransparentSquare) { - RenderTileFoliage(out, targetBufferPosition, levelCelBlock, tbl); + RenderTileFoliage(out, targetBufferPosition, levelCelBlock, foliageTbl); } else { RenderTile(out, targetBufferPosition, levelCelBlock, getFirstTileMaskLeft(tileType), tbl); } @@ -539,7 +547,7 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition const TileType tileType = levelCelBlock.type(); if (!isFloor || tileType == TileType::TransparentSquare) { if (isFloor && tileType == TileType::TransparentSquare) { - RenderTileFoliage(out, targetBufferPosition + RightFrameDisplacement, levelCelBlock, tbl); + RenderTileFoliage(out, targetBufferPosition + RightFrameDisplacement, levelCelBlock, foliageTbl); } else { RenderTile(out, targetBufferPosition + RightFrameDisplacement, levelCelBlock, getFirstTileMaskRight(tileType), tbl); @@ -554,7 +562,7 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition if (levelCelBlock.hasValue()) { RenderTile(out, targetBufferPosition, levelCelBlock, - transparency ? MaskType::Transparent : MaskType::Solid, tbl); + transparency ? MaskType::Transparent : MaskType::Solid, foliageTbl); } } { @@ -562,11 +570,21 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition if (levelCelBlock.hasValue()) { RenderTile(out, targetBufferPosition + RightFrameDisplacement, levelCelBlock, - transparency ? MaskType::Transparent : MaskType::Solid, tbl); + transparency ? MaskType::Transparent : MaskType::Solid, foliageTbl); } } targetBufferPosition.y -= TILE_HEIGHT; } + +#ifdef _DEBUG + if (DebugPath && walkpathIdx != -1) { + DrawString(out, StrCat(walkpathIdx), + Rectangle(originalTargetBufferPosition + Displacement { 0, -TILE_HEIGHT }, Size { TILE_WIDTH, TILE_HEIGHT }), + TextRenderOptions { + .flags = UiFlags::AlignCenter | UiFlags::VerticalCenter + | (IsTileSolid(tilePosition) ? UiFlags::ColorYellow : UiFlags::ColorWhite) }); + } +#endif } /** @@ -581,7 +599,7 @@ void DrawFloorTile(const Surface &out, Point tilePosition, Point targetBufferPos const uint8_t *tbl = LightTables[lightTableIndex].data(); #ifdef _DEBUG - if (DebugPath && MyPlayer->IsPositionInPath(tilePosition)) + if (DebugPath && MyPlayer->GetPositionPathIndex(tilePosition) != -1) tbl = GetPauseTRN(); #endif diff --git a/Source/player.cpp b/Source/player.cpp index 36eef40d5da..430b5f0451d 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -1653,21 +1653,21 @@ Point Player::GetTargetPosition() const return target; } -bool Player::IsPositionInPath(Point pos) +int Player::GetPositionPathIndex(Point pos) { constexpr Displacement DirectionOffset[8] = { { 0, -1 }, { -1, 0 }, { 1, 0 }, { 0, 1 }, { -1, -1 }, { 1, -1 }, { 1, 1 }, { -1, 1 } }; Point target = position.future; + int i = 0; for (auto step : walkpath) { - if (target == pos) { - return true; - } + if (target == pos) return i; if (step == WALK_NONE) break; if (step > 0) { target += DirectionOffset[step - 1]; } + ++i; } - return false; + return -1; } void Player::Say(HeroSpeech speechId) const diff --git a/Source/player.h b/Source/player.h index 2a6a1d6b194..bbd4ac84a57 100644 --- a/Source/player.h +++ b/Source/player.h @@ -520,9 +520,9 @@ struct Player { Point GetTargetPosition() const; /** - * @brief Check if position is in player's path. + * @brief Returns the index of the given position in `walkpath`, or -1 if not found. */ - bool IsPositionInPath(Point position); + int GetPositionPathIndex(Point position); /** * @brief Says a speech line.