Debug: Allow inspecting industry specs before industry is built

Add debug box to industry chains window
pull/428/head
Jonathan G Rennison 2 years ago
parent c58b94c376
commit 4e5e85e7aa

@ -1887,6 +1887,7 @@ static const NWidgetPart _nested_industry_cargoes_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN, WID_IC_CAPTION), SetDataTip(STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEBUGBOX, COLOUR_BROWN, WID_IC_DEBUG),
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
@ -2856,6 +2857,7 @@ struct IndustryCargoesWindow : public Window {
this->vscroll->SetCount(num_indrows);
this->SetDirty();
this->NotifySmallmap();
this->SetWidgetDisabledState(WID_IC_DEBUG, false);
}
/**
@ -2927,6 +2929,7 @@ struct IndustryCargoesWindow : public Window {
this->vscroll->SetCount(num_indrows);
this->SetDirty();
this->NotifySmallmap();
this->SetWidgetDisabledState(WID_IC_DEBUG, true);
}
/**
@ -3195,6 +3198,18 @@ struct IndustryCargoesWindow : public Window {
{
this->vscroll->SetCapacityFromWidget(this, WID_IC_PANEL, WD_FRAMERECT_TOP + CargoesField::small_height);
}
bool IsNewGRFInspectable() const override
{
return true;
}
void ShowNewGRFInspectWindow() const override
{
if (this->ind_cargo < NUM_INDUSTRYTYPES) {
::ShowNewGRFInspectWindow(GSF_INDUSTRIES, this->ind_cargo | (1 << 26));
}
}
};
const int IndustryCargoesWindow::HOR_TEXT_PADDING = 5; ///< Horizontal padding around the industry type text.

@ -216,6 +216,7 @@ public:
virtual void ExtraInfo(uint index, NIExtraInfoOutput &output) const {}
virtual void SpriteDump(uint index, DumpSpriteGroupPrinter print) const {}
virtual bool ShowExtraInfoOnly(uint index) const { return false; };
virtual bool ShowExtraInfoIncludingGRFIDOnly(uint index) const { return false; };
virtual bool ShowSpriteDumpButton(uint index) const { return false; };
protected:
@ -618,6 +619,8 @@ struct NewGRFInspectWindow : Window {
}
}
if (nih->ShowExtraInfoIncludingGRFIDOnly(index)) return;
const_cast<NewGRFInspectWindow*>(this)->first_variable_line_index = i;
if (nif->variables != nullptr) {

@ -781,13 +781,40 @@ static const NIVariable _niv_industries[] = {
class NIHIndustry : public NIHelper {
bool IsInspectable(uint index) const override { return true; }
bool ShowExtraInfoOnly(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grffile == nullptr; }
bool ShowSpriteDumpButton(uint index) const override { return true; }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Industry::Get(index)->town->index); }
const void *GetInstance(uint index)const override { return Industry::Get(index); }
const void *GetSpec(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type); }
void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_INDUSTRY_NAME, index); }
uint32 GetGRFID(uint index) const override { return (!this->ShowExtraInfoOnly(index)) ? GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grffile->grfid : 0; }
uint GetParent(uint index) const override { return HasBit(index, 26) ? UINT32_MAX : GetInspectWindowNumber(GSF_FAKE_TOWNS, Industry::Get(index)->town->index); }
const void *GetInstance(uint index)const override { return HasBit(index, 26) ? nullptr : Industry::Get(index); }
uint32 GetGRFID(uint index) const override { return (!this->ShowExtraInfoOnly(index)) ? ((const IndustrySpec *)this->GetSpec(index))->grf_prop.grffile->grfid : 0; }
bool ShowExtraInfoOnly(uint index) const override
{
const IndustrySpec *spec = (const IndustrySpec *)this->GetSpec(index);
return spec == nullptr || spec->grf_prop.grffile == nullptr;
}
bool ShowExtraInfoIncludingGRFIDOnly(uint index) const override
{
return HasBit(index, 26);
}
const void *GetSpec(uint index) const override
{
if (HasBit(index, 26)) {
return GetIndustrySpec(GB(index, 0, 16));
} else {
Industry *i = Industry::Get(index);
return i != nullptr ? GetIndustrySpec(i->type) : nullptr;
}
}
void SetStringParameters(uint index) const override
{
if (HasBit(index, 26)) {
SetDParam(0, GetIndustrySpec(GB(index, 0, 16))->name);
} else {
this->SetSimpleStringParameters(STR_INDUSTRY_NAME, index);
}
}
uint Resolve(uint index, uint var, uint param, GetVariableExtra *extra) const override
{
@ -814,47 +841,52 @@ class NIHIndustry : public NIHelper {
{
char buffer[1024];
output.print("Debug Info:");
seprintf(buffer, lastof(buffer), " Index: %u", index);
output.print(buffer);
const Industry *ind = Industry::GetIfValid(index);
if (ind) {
seprintf(buffer, lastof(buffer), " Location: %ux%u (%X), w: %u, h: %u", TileX(ind->location.tile), TileY(ind->location.tile), ind->location.tile, ind->location.w, ind->location.h);
output.print(buffer);
if (ind->neutral_station) {
seprintf(buffer, lastof(buffer), " Neutral station: %u: %s", ind->neutral_station->index, ind->neutral_station->GetCachedName());
output.print(buffer);
}
seprintf(buffer, lastof(buffer), " Nearby stations: %u", (uint) ind->stations_near.size());
if (!HasBit(index, 26)) {
seprintf(buffer, lastof(buffer), " Index: %u", index);
output.print(buffer);
for (const Station *st : ind->stations_near) {
seprintf(buffer, lastof(buffer), " %u: %s", st->index, st->GetCachedName());
const Industry *ind = Industry::GetIfValid(index);
if (ind) {
seprintf(buffer, lastof(buffer), " Location: %ux%u (%X), w: %u, h: %u", TileX(ind->location.tile), TileY(ind->location.tile), ind->location.tile, ind->location.w, ind->location.h);
output.print(buffer);
}
output.print(" Produces:");
for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
if (ind->produced_cargo[i] != CT_INVALID) {
seprintf(buffer, lastof(buffer), " %s: waiting: %u, rate: %u, this month: production: %u, transported: %u, last month: production: %u, transported: %u, (%u/255)",
GetStringPtr(CargoSpec::Get(ind->produced_cargo[i])->name), ind->produced_cargo_waiting[i], ind->production_rate[i], ind->this_month_production[i],
ind->this_month_transported[i], ind->last_month_production[i], ind->last_month_transported[i], ind->last_month_pct_transported[i]);
if (ind->neutral_station) {
seprintf(buffer, lastof(buffer), " Neutral station: %u: %s", ind->neutral_station->index, ind->neutral_station->GetCachedName());
output.print(buffer);
}
}
output.print(" Accepts:");
for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) {
if (ind->accepts_cargo[i] != CT_INVALID) {
seprintf(buffer, lastof(buffer), " %s: waiting: %u",
GetStringPtr(CargoSpec::Get(ind->accepts_cargo[i])->name), ind->incoming_cargo_waiting[i]);
seprintf(buffer, lastof(buffer), " Nearby stations: %u", (uint) ind->stations_near.size());
output.print(buffer);
for (const Station *st : ind->stations_near) {
seprintf(buffer, lastof(buffer), " %u: %s", st->index, st->GetCachedName());
output.print(buffer);
}
output.print(" Produces:");
for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
if (ind->produced_cargo[i] != CT_INVALID) {
seprintf(buffer, lastof(buffer), " %s: waiting: %u, rate: %u, this month: production: %u, transported: %u, last month: production: %u, transported: %u, (%u/255)",
GetStringPtr(CargoSpec::Get(ind->produced_cargo[i])->name), ind->produced_cargo_waiting[i], ind->production_rate[i], ind->this_month_production[i],
ind->this_month_transported[i], ind->last_month_production[i], ind->last_month_transported[i], ind->last_month_pct_transported[i]);
output.print(buffer);
}
}
output.print(" Accepts:");
for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) {
if (ind->accepts_cargo[i] != CT_INVALID) {
seprintf(buffer, lastof(buffer), " %s: waiting: %u",
GetStringPtr(CargoSpec::Get(ind->accepts_cargo[i])->name), ind->incoming_cargo_waiting[i]);
output.print(buffer);
}
}
seprintf(buffer, lastof(buffer), " Counter: %u", ind->counter);
output.print(buffer);
}
}
const IndustrySpec *indsp = GetIndustrySpec(ind->type);
const IndustrySpec *indsp = (const IndustrySpec *)this->GetSpec(index);
if (indsp) {
seprintf(buffer, lastof(buffer), " CBM_IND_PRODUCTION_CARGO_ARRIVAL: %s", HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) ? "yes" : "no");
output.print(buffer);
seprintf(buffer, lastof(buffer), " CBM_IND_PRODUCTION_256_TICKS: %s", HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS) ? "yes" : "no");
output.print(buffer);
seprintf(buffer, lastof(buffer), " Counter: %u", ind->counter);
output.print(buffer);
if ((_settings_game.economy.industry_cargo_scale_factor != 0) && HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) {
seprintf(buffer, lastof(buffer), " Counter production interval: %u", ScaleQuantity(INDUSTRY_PRODUCE_TICKS, -_settings_game.economy.industry_cargo_scale_factor));
output.print(buffer);
@ -870,10 +902,10 @@ class NIHIndustry : public NIHelper {
/* virtual */ void SpriteDump(uint index, DumpSpriteGroupPrinter print) const override
{
const Industry *ind = Industry::GetIfValid(index);
if (ind) {
const IndustrySpec *spec = (const IndustrySpec *)this->GetSpec(index);
if (spec) {
extern void DumpIndustrySpriteGroup(const IndustrySpec *spec, DumpSpriteGroupPrinter print);
DumpIndustrySpriteGroup(GetIndustrySpec(ind->type), std::move(print));
DumpIndustrySpriteGroup(spec, std::move(print));
}
}
};

@ -49,6 +49,7 @@ enum IndustryCargoesWidgets {
WID_IC_SCROLLBAR, ///< Scrollbar of the panel.
WID_IC_CARGO_DROPDOWN, ///< Select cargo dropdown.
WID_IC_IND_DROPDOWN, ///< Select industry dropdown.
WID_IC_DEBUG, ///< Debug button
};
#endif /* WIDGETS_INDUSTRY_WIDGET_H */

Loading…
Cancel
Save