Add function to get name of extended variable ID
Add table for internal variable IDs which aren't mappable externally
This commit is contained in:
@@ -11732,3 +11732,22 @@ uint CountSelectedGRFs(GRFConfig *grfconf)
|
|||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *GetExtendedVariableNameById(int id)
|
||||||
|
{
|
||||||
|
extern const GRFVariableMapDefinition _grf_action2_remappable_variables[];
|
||||||
|
for (const GRFVariableMapDefinition *info = _grf_action2_remappable_variables; info->name != nullptr; info++) {
|
||||||
|
if (id == info->id) {
|
||||||
|
return info->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern const GRFNameOnlyVariableMapDefinition _grf_action2_internal_variable_names[];
|
||||||
|
for (const GRFNameOnlyVariableMapDefinition *info = _grf_action2_internal_variable_names; info->name != nullptr; info++) {
|
||||||
|
if (id == info->id) {
|
||||||
|
return info->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
18
src/newgrf.h
18
src/newgrf.h
@@ -209,6 +209,22 @@ struct GRFVariableMapDefinition {
|
|||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct GRFNameOnlyVariableMapDefinition {
|
||||||
|
const char *name; // nullptr indicates the end of the list
|
||||||
|
int id;
|
||||||
|
|
||||||
|
/** Create empty object used to identify the end of a list. */
|
||||||
|
GRFNameOnlyVariableMapDefinition() :
|
||||||
|
name(nullptr),
|
||||||
|
id(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
GRFNameOnlyVariableMapDefinition(int id, const char *name) :
|
||||||
|
name(name),
|
||||||
|
id(id)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
struct GRFVariableMapEntry {
|
struct GRFVariableMapEntry {
|
||||||
uint16 id = 0;
|
uint16 id = 0;
|
||||||
uint8 feature = 0;
|
uint8 feature = 0;
|
||||||
@@ -450,4 +466,6 @@ const char *GetFeatureString(GrfSpecFeature feature);
|
|||||||
|
|
||||||
void InitGRFGlobalVars();
|
void InitGRFGlobalVars();
|
||||||
|
|
||||||
|
const char *GetExtendedVariableNameById(int id);
|
||||||
|
|
||||||
#endif /* NEWGRF_H */
|
#endif /* NEWGRF_H */
|
||||||
|
@@ -649,14 +649,11 @@ struct NewGRFInspectWindow : Window {
|
|||||||
uint prefix_width = 0;
|
uint prefix_width = 0;
|
||||||
for (const NIVariable *niv = nif->variables; niv->name != nullptr; niv++) {
|
for (const NIVariable *niv = nif->variables; niv->name != nullptr; niv++) {
|
||||||
if (niv->var >= 0x100) {
|
if (niv->var >= 0x100) {
|
||||||
extern const GRFVariableMapDefinition _grf_action2_remappable_variables[];
|
const char *name = GetExtendedVariableNameById(niv->var);
|
||||||
for (const GRFVariableMapDefinition *info = _grf_action2_remappable_variables; info->name != nullptr; info++) {
|
if (name != nullptr) {
|
||||||
if (niv->var == info->id) {
|
|
||||||
char buf[512];
|
char buf[512];
|
||||||
seprintf(buf, lastof(buf), " %s: ", info->name);
|
seprintf(buf, lastof(buf), " %s: ", name);
|
||||||
prefix_width = std::max<uint>(prefix_width, GetStringBoundingBox(buf).width);
|
prefix_width = std::max<uint>(prefix_width, GetStringBoundingBox(buf).width);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -670,27 +667,24 @@ 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) {
|
} else if (niv->var >= 0x100) {
|
||||||
extern const GRFVariableMapDefinition _grf_action2_remappable_variables[];
|
const char *name = GetExtendedVariableNameById(niv->var);
|
||||||
for (const GRFVariableMapDefinition *info = _grf_action2_remappable_variables; info->name != nullptr; info++) {
|
if (name != nullptr) {
|
||||||
if (niv->var == info->id) {
|
|
||||||
if (_current_text_dir == TD_RTL) {
|
if (_current_text_dir == TD_RTL) {
|
||||||
this->DrawString(r, i++, " %s: %08x (%s)", info->name, value, niv->name);
|
this->DrawString(r, i++, " %s: %08x (%s)", name, value, niv->name);
|
||||||
} else {
|
} else {
|
||||||
if (this->log_console) DEBUG(misc, 0, " %s: %08x (%s)", info->name, value, niv->name);
|
if (this->log_console) DEBUG(misc, 0, " %s: %08x (%s)", name, value, niv->name);
|
||||||
|
|
||||||
int offset = i - this->vscroll->GetPosition();
|
int offset = i - this->vscroll->GetPosition();
|
||||||
i++;
|
i++;
|
||||||
if (offset >= 0 && offset < this->vscroll->GetCapacity()) {
|
if (offset >= 0 && offset < this->vscroll->GetCapacity()) {
|
||||||
Rect sr = r.Shrink(WidgetDimensions::scaled.frametext).Shrink(0, offset * this->resize.step_height, 0, 0);
|
Rect sr = r.Shrink(WidgetDimensions::scaled.frametext).Shrink(0, offset * this->resize.step_height, 0, 0);
|
||||||
char buf[512];
|
char buf[512];
|
||||||
seprintf(buf, lastof(buf), " %s: ", info->name);
|
seprintf(buf, lastof(buf), " %s: ", name);
|
||||||
::DrawString(sr.left, sr.right, sr.top, buf, TC_BLACK);
|
::DrawString(sr.left, sr.right, sr.top, buf, TC_BLACK);
|
||||||
seprintf(buf, lastof(buf), "%08x (%s)", value, niv->name);
|
seprintf(buf, lastof(buf), "%08x (%s)", value, niv->name);
|
||||||
::DrawString(sr.left + prefix_width, sr.right, sr.top, buf, TC_BLACK);
|
::DrawString(sr.left + prefix_width, sr.right, sr.top, 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);
|
||||||
|
@@ -197,6 +197,13 @@ extern const GRFVariableMapDefinition _grf_action2_remappable_variables[] = {
|
|||||||
GRFVariableMapDefinition(),
|
GRFVariableMapDefinition(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern const GRFNameOnlyVariableMapDefinition _grf_action2_internal_variable_names[] = {
|
||||||
|
GRFNameOnlyVariableMapDefinition(A2VRI_VEHICLE_CURRENT_SPEED_SCALED, "current speed scaled"),
|
||||||
|
GRFNameOnlyVariableMapDefinition(A2VRI_STATION_INFO_NEARBY_TILES_EXT, "68 (extended)"),
|
||||||
|
GRFNameOnlyVariableMapDefinition(A2VRI_ROADSTOP_INFO_NEARBY_TILES_EXT, "68 (extended)"),
|
||||||
|
GRFNameOnlyVariableMapDefinition(),
|
||||||
|
};
|
||||||
|
|
||||||
/** Action14 Action5 remappable type list */
|
/** Action14 Action5 remappable type list */
|
||||||
extern const Action5TypeRemapDefinition _grf_action5_remappable_types[] = {
|
extern const Action5TypeRemapDefinition _grf_action5_remappable_types[] = {
|
||||||
Action5TypeRemapDefinition("programmable_signals", A5BLOCK_ALLOW_OFFSET, SPR_PROGSIGNAL_BASE, 1, 32, "Programmable pre-signal graphics"),
|
Action5TypeRemapDefinition("programmable_signals", A5BLOCK_ALLOW_OFFSET, SPR_PROGSIGNAL_BASE, 1, 32, "Programmable pre-signal graphics"),
|
||||||
|
@@ -514,12 +514,9 @@ static char *DumpSpriteGroupAdjust(char *p, const char *last, const Deterministi
|
|||||||
};
|
};
|
||||||
|
|
||||||
auto append_extended_var = [&](int var_id) {
|
auto append_extended_var = [&](int var_id) {
|
||||||
extern const GRFVariableMapDefinition _grf_action2_remappable_variables[];
|
const char *name = GetExtendedVariableNameById(var_id);
|
||||||
for (const GRFVariableMapDefinition *info = _grf_action2_remappable_variables; info->name != nullptr; info++) {
|
if (name != nullptr) {
|
||||||
if (var_id == info->id) {
|
p += seprintf(p, last, " (%s)", name);
|
||||||
p += seprintf(p, last, " (%s)", info->name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -560,9 +557,7 @@ static char *DumpSpriteGroupAdjust(char *p, const char *last, const Deterministi
|
|||||||
highlight_tag = (2 << 16) | (adjust.and_mask & 0xFFFF);
|
highlight_tag = (2 << 16) | (adjust.and_mask & 0xFFFF);
|
||||||
}
|
}
|
||||||
p += seprintf(p, last, "var: %X", adjust.variable);
|
p += seprintf(p, last, "var: %X", adjust.variable);
|
||||||
if (adjust.variable == A2VRI_VEHICLE_CURRENT_SPEED_SCALED) {
|
if (adjust.variable >= 0x100) {
|
||||||
p += seprintf(p, last, " (current_speed_scaled)");
|
|
||||||
} else if (adjust.variable >= 0x100) {
|
|
||||||
append_extended_var(adjust.variable);
|
append_extended_var(adjust.variable);
|
||||||
}
|
}
|
||||||
if (adjust.variable == 0x7B && adjust.parameter >= 0x100) {
|
if (adjust.variable == 0x7B && adjust.parameter >= 0x100) {
|
||||||
|
Reference in New Issue
Block a user