Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missiles to tile data debug command #7701

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions Source/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "engine/load_cel.hpp"
#include "engine/point.hpp"
#include "lighting.h"
#include "missiles.h"
#include "monster.h"
#include "plrmsg.h"
#include "utils/str_case.hpp"
Expand Down Expand Up @@ -144,19 +145,20 @@ void SetDebugGridTextType(DebugGridTextItem value)
SelectedDebugGridTextItem = value;
}

bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer)
bool GetDebugGridText(Point dungeonCoords, std::string &debugGridText)
{
int info = 0;
int blankValue = 0;
debugGridText.clear();
Point megaCoords = dungeonCoords.worldToMega();
switch (SelectedDebugGridTextItem) {
case DebugGridTextItem::coords:
*BufCopy(debugGridTextBuffer, dungeonCoords.x, ":", dungeonCoords.y) = '\0';
StrAppend(debugGridText, dungeonCoords.x, ":", dungeonCoords.y);
return true;
case DebugGridTextItem::cursorcoords:
if (dungeonCoords != cursPosition)
return false;
*BufCopy(debugGridTextBuffer, dungeonCoords.x, ":", dungeonCoords.y) = '\0';
StrAppend(debugGridText, dungeonCoords.x, ":", dungeonCoords.y);
return true;
case DebugGridTextItem::objectindex: {
info = 0;
Expand All @@ -167,23 +169,21 @@ bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer)
break;
}
case DebugGridTextItem::microTiles: {
std::string result;
const MICROS &micros = DPieceMicros[dPiece[dungeonCoords.x][dungeonCoords.y]];
for (const LevelCelBlock tile : micros.mt) {
if (!tile.hasValue()) break;
if (!result.empty()) result += '\n';
StrAppend(result, tile.frame(), " ");
if (!debugGridText.empty()) debugGridText += '\n';
StrAppend(debugGridText, tile.frame(), " ");
switch (tile.type()) {
case TileType::Square: StrAppend(result, "S"); break;
case TileType::TransparentSquare: StrAppend(result, "T"); break;
case TileType::LeftTriangle: StrAppend(result, "<"); break;
case TileType::RightTriangle: StrAppend(result, ">"); break;
case TileType::LeftTrapezoid: StrAppend(result, "\\"); break;
case TileType::RightTrapezoid: StrAppend(result, "/"); break;
case TileType::Square: StrAppend(debugGridText, "S"); break;
case TileType::TransparentSquare: StrAppend(debugGridText, "T"); break;
case TileType::LeftTriangle: StrAppend(debugGridText, "<"); break;
case TileType::RightTriangle: StrAppend(debugGridText, ">"); break;
case TileType::LeftTrapezoid: StrAppend(debugGridText, "\\"); break;
case TileType::RightTrapezoid: StrAppend(debugGridText, "/"); break;
}
}
if (result.empty()) return false;
*BufCopy(debugGridTextBuffer, result) = '\0';
if (debugGridText.empty()) return false;
return true;
} break;
case DebugGridTextItem::dPiece:
Expand All @@ -209,6 +209,16 @@ bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer)
case DebugGridTextItem::dMonster:
info = dMonster[dungeonCoords.x][dungeonCoords.y];
break;
case DebugGridTextItem::missiles: {
for (auto &missile : Missiles) {
if (missile.position.tile == dungeonCoords) {
if (!debugGridText.empty()) debugGridText += '\n';
debugGridText.append(std::to_string((int)missile._mitype));
}
}
if (debugGridText.empty()) return false;
return true;
} break;
case DebugGridTextItem::dCorpse:
info = dCorpse[dungeonCoords.x][dungeonCoords.y];
break;
Expand Down Expand Up @@ -251,7 +261,7 @@ bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer)
}
if (info == blankValue)
return false;
*BufCopy(debugGridTextBuffer, info) = '\0';
StrAppend(debugGridText, info);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion Source/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ enum class DebugGridTextItem : uint16_t {
dFlags,
dPlayer,
dMonster,
missiles,
dCorpse,
dObject,
dItem,
Expand Down Expand Up @@ -73,7 +74,7 @@ bool IsDebugGridTextNeeded();
bool IsDebugGridInMegatiles();
DebugGridTextItem GetDebugGridTextType();
void SetDebugGridTextType(DebugGridTextItem value);
bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer);
bool GetDebugGridText(Point dungeonCoords, std::string &debugGridText);
bool IsDebugAutomapHighlightNeeded();
bool ShouldHighlightDebugAutomapTile(Point position);
void AddDebugAutomapMonsterHighlight(std::string_view name);
Expand Down
6 changes: 3 additions & 3 deletions Source/engine/render/scrollrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ void DrawView(const Surface &out, Point startPosition)
if (debugGridTextNeeded || DebugGrid) {
// force redrawing or debug stuff stays on panel on 640x480 resolution
RedrawEverything();
char debugGridTextBuffer[10];
std::string debugGridText;
bool megaTiles = IsDebugGridInMegatiles();

for (auto [dunCoordVal, pixelCoords] : DebugCoordsMap) {
Expand All @@ -1169,11 +1169,11 @@ void DrawView(const Surface &out, Point startPosition)
pixelCoords += Displacement { 0, TILE_HEIGHT / 2 };
if (*GetOptions().Graphics.zoom)
pixelCoords *= 2;
if (debugGridTextNeeded && GetDebugGridText(dunCoords, debugGridTextBuffer)) {
if (debugGridTextNeeded && GetDebugGridText(dunCoords, debugGridText)) {
Size tileSize = { TILE_WIDTH, TILE_HEIGHT };
if (*GetOptions().Graphics.zoom)
tileSize *= 2;
DrawString(out, debugGridTextBuffer, { pixelCoords - Displacement { 0, tileSize.height }, tileSize },
DrawString(out, debugGridText, { pixelCoords - Displacement { 0, tileSize.height }, tileSize },
{ .flags = UiFlags::ColorRed | UiFlags::AlignCenter | UiFlags::VerticalCenter });
}
if (DebugGrid) {
Expand Down
3 changes: 2 additions & 1 deletion Source/lua/modules/dev/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::string DebugCmdFullbright(std::optional<bool> on)

std::string DebugCmdShowTileData(std::optional<std::string_view> dataType)
{
static const std::array<std::string_view, 22> DataTypes {
static const std::array<std::string_view, 23> DataTypes {
"microTiles",
"dPiece",
"dTransVal",
Expand All @@ -51,6 +51,7 @@ std::string DebugCmdShowTileData(std::optional<std::string_view> dataType)
"dFlags",
"dPlayer",
"dMonster",
"missiles",
"dCorpse",
"dObject",
"dItem",
Expand Down
Loading