Debug: Add support for showing extended variables in object debug window

This commit is contained in:
Jonathan G Rennison
2022-02-08 18:59:56 +00:00
parent 038e96bfb0
commit 2959221066
2 changed files with 40 additions and 1 deletions

View File

@@ -110,7 +110,7 @@ static const int CBM_NO_BIT = UINT8_MAX;
/** Representation on the NewGRF variables. */ /** Representation on the NewGRF variables. */
struct NIVariable { struct NIVariable {
const char *name; const char *name;
byte var; uint16 var;
}; };
struct NIExtraInfoOutput { struct NIExtraInfoOutput {
@@ -551,6 +551,20 @@ struct NewGRFInspectWindow : Window {
if (nif->variables != nullptr) { if (nif->variables != nullptr) {
this->DrawString(r, i++, "Variables:"); this->DrawString(r, i++, "Variables:");
uint prefix_width = 0;
for (const NIVariable *niv = nif->variables; niv->name != nullptr; niv++) {
if (niv->var >= 0x100) {
extern const GRFVariableMapDefinition _grf_action2_remappable_variables[];
for (const GRFVariableMapDefinition *info = _grf_action2_remappable_variables; info->name != nullptr; info++) {
if (niv->var == info->id) {
char buf[512];
seprintf(buf, lastof(buf), " %s: ", info->name);
prefix_width = std::max<uint>(prefix_width, GetStringBoundingBox(buf).width);
break;
}
}
}
}
for (const NIVariable *niv = nif->variables; niv->name != nullptr; niv++) { for (const NIVariable *niv = nif->variables; niv->name != nullptr; niv++) {
GetVariableExtra extra; GetVariableExtra extra;
uint param = HasVariableParameter(niv->var) ? NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][niv->var - 0x60] : 0; uint param = HasVariableParameter(niv->var) ? NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][niv->var - 0x60] : 0;
@@ -560,6 +574,28 @@ struct NewGRFInspectWindow : Window {
if (HasVariableParameter(niv->var)) { if (HasVariableParameter(niv->var)) {
this->DrawString(r, i++, " %02x[%02x]: %08x (%s)", niv->var, param, value, niv->name); this->DrawString(r, i++, " %02x[%02x]: %08x (%s)", niv->var, param, value, niv->name);
} else if (niv->var >= 0x100) {
extern const GRFVariableMapDefinition _grf_action2_remappable_variables[];
for (const GRFVariableMapDefinition *info = _grf_action2_remappable_variables; info->name != nullptr; info++) {
if (niv->var == info->id) {
if (_current_text_dir == TD_RTL) {
this->DrawString(r, i++, " %s: %08x (%s)", info->name, value, niv->name);
} else {
if (this->log_console) DEBUG(misc, 0, " %s: %08x (%s)", info->name, value, niv->name);
int offset = i - this->vscroll->GetPosition();
i++;
if (offset >= 0 && offset < this->vscroll->GetCapacity()) {
char buf[512];
seprintf(buf, lastof(buf), " %s: ", info->name);
::DrawString(r.left + LEFT_OFFSET, r.right - RIGHT_OFFSET, r.top + TOP_OFFSET + (offset * this->resize.step_height), buf, TC_BLACK);
seprintf(buf, lastof(buf), "%08x (%s)", value, niv->name);
::DrawString(r.left + LEFT_OFFSET + prefix_width, r.right - RIGHT_OFFSET, r.top + TOP_OFFSET + (offset * this->resize.step_height), buf, TC_BLACK);
}
}
break;
}
}
} else { } else {
this->DrawString(r, i++, " %02x: %08x (%s)", niv->var, value, niv->name); this->DrawString(r, i++, " %02x: %08x (%s)", niv->var, value, niv->name);
} }

View File

@@ -18,6 +18,7 @@
#include "../object_map.h" #include "../object_map.h"
#include "../waypoint_base.h" #include "../waypoint_base.h"
#include "../string_func_extra.h" #include "../string_func_extra.h"
#include "../newgrf_extension.h"
/* Helper for filling property tables */ /* Helper for filling property tables */
#define NIP(prop, base, variable, type, name) { name, (ptrdiff_t)cpp_offsetof(base, variable), cpp_sizeof(base, variable), prop, type } #define NIP(prop, base, variable, type, name) { name, (ptrdiff_t)cpp_offsetof(base, variable), cpp_sizeof(base, variable), prop, type }
@@ -842,6 +843,8 @@ static const NIVariable _niv_objects[] = {
NIV(0x62, "land info of nearby tiles"), NIV(0x62, "land info of nearby tiles"),
NIV(0x63, "animation stage of nearby tiles"), NIV(0x63, "animation stage of nearby tiles"),
NIV(0x64, "distance on nearest object with given type"), NIV(0x64, "distance on nearest object with given type"),
NIV(A2VRI_OBJECT_FOUNDATION_SLOPE, "slope after foundation applied"),
NIV(A2VRI_OBJECT_FOUNDATION_SLOPE_CHANGE, "slope after foundation applied xor non-foundation slope"),
NIV_END() NIV_END()
}; };