Browse Source

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.
pull/7521/head
Gleb Mazovetskiy 1 year ago
parent
commit
f7a93f4cd3
  1. 32
      Source/engine/render/scrollrt.cpp
  2. 10
      Source/player.cpp
  3. 4
      Source/player.h

32
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

10
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

4
Source/player.h

@ -520,9 +520,9 @@ public:
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.

Loading…
Cancel
Save