From 669b3f2e041530062ccd6b485e6fca6bbc816b1a Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 8 Oct 2022 21:53:56 +0100 Subject: [PATCH] Debug: Add GRF inspect window support for cargoes --- src/industry_gui.cpp | 6 +-- src/table/newgrf_debug_data.h | 78 ++++++++++++++++++++++++++++++++++- src/widgets/industry_widget.h | 1 - 3 files changed, 80 insertions(+), 5 deletions(-) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 039ef8a1c4..423c62bf46 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1887,7 +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_DEBUGBOX, COLOUR_BROWN), NWidget(WWT_SHADEBOX, COLOUR_BROWN), NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN), NWidget(WWT_STICKYBOX, COLOUR_BROWN), @@ -2857,7 +2857,6 @@ struct IndustryCargoesWindow : public Window { this->vscroll->SetCount(num_indrows); this->SetDirty(); this->NotifySmallmap(); - this->SetWidgetDisabledState(WID_IC_DEBUG, false); } /** @@ -2929,7 +2928,6 @@ struct IndustryCargoesWindow : public Window { this->vscroll->SetCount(num_indrows); this->SetDirty(); this->NotifySmallmap(); - this->SetWidgetDisabledState(WID_IC_DEBUG, true); } /** @@ -3208,6 +3206,8 @@ struct IndustryCargoesWindow : public Window { { if (this->ind_cargo < NUM_INDUSTRYTYPES) { ::ShowNewGRFInspectWindow(GSF_INDUSTRIES, this->ind_cargo | (1 << 26)); + } else { + ::ShowNewGRFInspectWindow(GSF_CARGOES, this->ind_cargo - NUM_INDUSTRYTYPES); } } }; diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index 6eb5bead2a..3e5aa9b00d 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -922,6 +922,82 @@ static const NIFeature _nif_industry = { }; +/*** NewGRF cargos ***/ + +#define NICC(cb_id, bit) NIC(cb_id, CargoSpec, callback_mask, bit) +static const NICallback _nic_cargo[] = { + NICC(CBID_CARGO_PROFIT_CALC, CBM_CARGO_PROFIT_CALC), + NICC(CBID_CARGO_STATION_RATING_CALC, CBM_CARGO_STATION_RATING_CALC), + NIC_END() +}; + +class NIHCargo : public NIHelper { + bool IsInspectable(uint index) const override { return true; } + bool ShowExtraInfoOnly(uint index) const override { return CargoSpec::Get(index)->grffile == nullptr; } + bool ShowSpriteDumpButton(uint index) const override { return true; } + uint GetParent(uint index) const override { return UINT32_MAX; } + const void *GetInstance(uint index)const override { return nullptr; } + const void *GetSpec(uint index) const override { return CargoSpec::Get(index); } + void SetStringParameters(uint index) const override { SetDParam(0, CargoSpec::Get(index)->name); } + uint32 GetGRFID(uint index) const override { return (!this->ShowExtraInfoOnly(index)) ? CargoSpec::Get(index)->grffile->grfid : 0; } + + uint Resolve(uint index, uint var, uint param, GetVariableExtra *extra) const override + { + return 0; + } + + void ExtraInfo(uint index, NIExtraInfoOutput &output) const override + { + char buffer[1024]; + + output.print("Debug Info:"); + seprintf(buffer, lastof(buffer), " Index: %u", index); + output.print(buffer); + + const CargoSpec *spec = CargoSpec::Get(index); + seprintf(buffer, lastof(buffer), " Bit: %2u, Label: %c%c%c%c, Callback mask: 0x%02X", + spec->bitnum, + spec->label >> 24, spec->label >> 16, spec->label >> 8, spec->label, + spec->callback_mask); + output.print(buffer); + char *b = buffer + seprintf(buffer, lastof(buffer), " Cargo class: %s%s%s%s%s%s%s%s%s%s%s", + (spec->classes & CC_PASSENGERS) != 0 ? "passenger, " : "", + (spec->classes & CC_MAIL) != 0 ? "mail, " : "", + (spec->classes & CC_EXPRESS) != 0 ? "express, " : "", + (spec->classes & CC_ARMOURED) != 0 ? "armoured, " : "", + (spec->classes & CC_BULK) != 0 ? "bulk, " : "", + (spec->classes & CC_PIECE_GOODS) != 0 ? "piece goods, " : "", + (spec->classes & CC_LIQUID) != 0 ? "liquid, " : "", + (spec->classes & CC_REFRIGERATED) != 0 ? "refrigerated, " : "", + (spec->classes & CC_HAZARDOUS) != 0 ? "hazardous, " : "", + (spec->classes & CC_COVERED) != 0 ? "covered/sheltered, " : "", + (spec->classes & CC_SPECIAL) != 0 ? "special, " : ""); + if (b[-2] == ',') b[-2] = 0; + output.print(buffer); + + seprintf(buffer, lastof(buffer), " Weight: %u, Capacity multiplier: %u", spec->weight, spec->multiplier); + output.print(buffer); + seprintf(buffer, lastof(buffer), " Initial payment: %d, Current payment: " OTTD_PRINTF64 ", Transit days: (%u, %u)", + spec->initial_payment, (int64)spec->current_payment, spec->transit_days[0], spec->transit_days[1]); + output.print(buffer); + seprintf(buffer, lastof(buffer), " Freight: %s, Town effect: %u", spec->is_freight ? "yes" : "no", spec->town_effect); + output.print(buffer); + } + + /* virtual */ void SpriteDump(uint index, DumpSpriteGroupPrinter print) const override + { + DumpSpriteGroup(CargoSpec::Get(index)->group, std::move(print)); + } +}; + +static const NIFeature _nif_cargo = { + nullptr, + _nic_cargo, + nullptr, + new NIHCargo(), +}; + + /*** NewGRF signals ***/ void DumpTileSignalsInfo(char *buffer, const char *last, uint index, NIExtraInfoOutput &output) { @@ -1681,7 +1757,7 @@ static const NIFeature * const _nifeatures[] = { nullptr, // GSF_GLOBALVAR (has no "physical" objects) &_nif_industrytile, // GSF_INDUSTRYTILES &_nif_industry, // GSF_INDUSTRIES - nullptr, // GSF_CARGOES (has no "physical" objects) + &_nif_cargo, // GSF_CARGOES (has no "physical" objects) nullptr, // GSF_SOUNDFX (has no "physical" objects) nullptr, // GSF_AIRPORTS (feature not implemented) &_nif_signals, // GSF_SIGNALS diff --git a/src/widgets/industry_widget.h b/src/widgets/industry_widget.h index 5a5c5e935e..5e3a656c1f 100644 --- a/src/widgets/industry_widget.h +++ b/src/widgets/industry_widget.h @@ -49,7 +49,6 @@ 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 */