From a6f2f3c042da36731eb291510fb5b5e19e9d3c9a Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Sun, 10 Sep 2023 17:09:31 +0200 Subject: [PATCH] Add: [NewGRF] Inspection window for airports. As as the station window combines all station types, accessing the debug view is via the parent of the airport tile only. --- src/newgrf_airport.cpp | 44 ---------------------------- src/newgrf_airport.h | 46 +++++++++++++++++++++++++++++ src/newgrf_debug_gui.cpp | 1 + src/table/newgrf_debug_data.h | 55 +++++++++++++++++++++++++++++++++-- 4 files changed, 100 insertions(+), 46 deletions(-) diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp index 4dffc76cde..93a01f2070 100644 --- a/src/newgrf_airport.cpp +++ b/src/newgrf_airport.cpp @@ -17,50 +17,6 @@ #include "safeguards.h" -/** Resolver for the airport scope. */ -struct AirportScopeResolver : public ScopeResolver { - struct Station *st; ///< Station of the airport for which the callback is run, or \c nullptr for build gui. - byte airport_id; ///< Type of airport for which the callback is run. - byte layout; ///< Layout of the airport to build. - TileIndex tile; ///< Tile for the callback, only valid for airporttile callbacks. - - /** - * Constructor of the scope resolver for an airport. - * @param ro Surrounding resolver. - * @param tile %Tile for the callback, only valid for airporttile callbacks. - * @param st %Station of the airport for which the callback is run, or \c nullptr for build gui. - * @param airport_id Type of airport for which the callback is run. - * @param layout Layout of the airport to build. - */ - AirportScopeResolver(ResolverObject &ro, TileIndex tile, Station *st, byte airport_id, byte layout) - : ScopeResolver(ro), st(st), airport_id(airport_id), layout(layout), tile(tile) - { - } - - uint32_t GetRandomBits() const override; - uint32_t GetVariable(byte variable, uint32_t parameter, bool *available) const override; - void StorePSA(uint pos, int32_t value) override; -}; - -/** Resolver object for airports. */ -struct AirportResolverObject : public ResolverObject { - AirportScopeResolver airport_scope; - - AirportResolverObject(TileIndex tile, Station *st, byte airport_id, byte layout, - CallbackID callback = CBID_NO_CALLBACK, uint32_t callback_param1 = 0, uint32_t callback_param2 = 0); - - ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override - { - switch (scope) { - case VSG_SCOPE_SELF: return &this->airport_scope; - default: return ResolverObject::GetScope(scope, relative); - } - } - - GrfSpecFeature GetFeature() const override; - uint32_t GetDebugID() const override; -}; - /** * Reset airport classes to their default state. * This includes initialising the defaults classes with an empty diff --git a/src/newgrf_airport.h b/src/newgrf_airport.h index e09d16e046..8eec8ad1c0 100644 --- a/src/newgrf_airport.h +++ b/src/newgrf_airport.h @@ -14,6 +14,7 @@ #include "timer/timer_game_calendar.h" #include "newgrf_class.h" #include "newgrf_commons.h" +#include "newgrf_spritegroup.h" #include "tilearea_type.h" /** Copy from station_map.h */ @@ -143,6 +144,51 @@ typedef NewGRFClass AirportClass; void BindAirportSpecs(); +/** Resolver for the airport scope. */ +struct AirportScopeResolver : public ScopeResolver { + struct Station *st; ///< Station of the airport for which the callback is run, or \c nullptr for build gui. + byte airport_id; ///< Type of airport for which the callback is run. + byte layout; ///< Layout of the airport to build. + TileIndex tile; ///< Tile for the callback, only valid for airporttile callbacks. + + /** + * Constructor of the scope resolver for an airport. + * @param ro Surrounding resolver. + * @param tile %Tile for the callback, only valid for airporttile callbacks. + * @param st %Station of the airport for which the callback is run, or \c nullptr for build gui. + * @param airport_id Type of airport for which the callback is run. + * @param layout Layout of the airport to build. + */ + AirportScopeResolver(ResolverObject &ro, TileIndex tile, Station *st, byte airport_id, byte layout) + : ScopeResolver(ro), st(st), airport_id(airport_id), layout(layout), tile(tile) + { + } + + uint32_t GetRandomBits() const override; + uint32_t GetVariable(byte variable, uint32_t parameter, bool *available) const override; + void StorePSA(uint pos, int32_t value) override; +}; + + +/** Resolver object for airports. */ +struct AirportResolverObject : public ResolverObject { + AirportScopeResolver airport_scope; + + AirportResolverObject(TileIndex tile, Station *st, byte airport_id, byte layout, + CallbackID callback = CBID_NO_CALLBACK, uint32_t callback_param1 = 0, uint32_t callback_param2 = 0); + + ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override + { + switch (scope) { + case VSG_SCOPE_SELF: return &this->airport_scope; + default: return ResolverObject::GetScope(scope, relative); + } + } + + GrfSpecFeature GetFeature() const override; + uint32_t GetDebugID() const override; +}; + StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16_t callback); #endif /* NEWGRF_AIRPORT_H */ diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index afef4e9308..d7cd8e7495 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -28,6 +28,7 @@ #include "train.h" #include "roadveh.h" +#include "newgrf_airport.h" #include "newgrf_airporttiles.h" #include "newgrf_debug.h" #include "newgrf_object.h" diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index 2410e68882..7427a5ecc1 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -494,7 +494,7 @@ static const NICallback _nic_airporttiles[] = { class NIHAirportTile : public NIHelper { bool IsInspectable(uint index) const override { return AirportTileSpec::Get(GetAirportGfx(index))->grf_prop.grffile != nullptr; } - uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Station::GetByTile(index)->town->index); } + uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_AIRPORTS, GetStationIndex(index)); } const void *GetInstance(uint index)const override { return nullptr; } const void *GetSpec(uint index) const override { return AirportTileSpec::Get(GetAirportGfx(index)); } void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); } @@ -515,6 +515,57 @@ static const NIFeature _nif_airporttile = { }; +/*** NewGRF airports ***/ + +static const NIVariable _niv_airports[] = { + NIV(0x40, "Layout number"), + NIV(0x48, "bitmask of accepted cargoes"), + NIV(0x60, "amount of cargo waiting"), + NIV(0x61, "time since last cargo pickup"), + NIV(0x62, "rating of cargo"), + NIV(0x63, "time spent on route"), + NIV(0x64, "information about last vehicle picking cargo up"), + NIV(0x65, "amount of cargo acceptance"), + NIV(0x69, "information about cargo accepted in the past"), + NIV(0xF1, "type of the airport"), + NIV(0xF6, "airport block status"), + NIV(0xFA, "built date"), + NIV_END() +}; + +class NIHAiport : public NIHelper { + bool IsInspectable(uint index) const override { return AirportSpec::Get(Station::Get(index)->airport.type)->grf_prop.grffile != nullptr; } + uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Station::Get(index)->town->index); } + const void *GetInstance(uint index)const override { return Station::Get(index); } + const void *GetSpec(uint index) const override { return AirportSpec::Get(Station::Get(index)->airport.type); } + void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, index, Station::Get(index)->airport.tile); } + uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? AirportSpec::Get(Station::Get(index)->airport.type)->grf_prop.grffile->grfid : 0; } + + uint Resolve(uint index, uint var, uint param, bool *avail) const override + { + Station *st = Station::Get(index); + AirportResolverObject ro(st->airport.tile, st, st->airport.type, st->airport.layout); + return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail); + } + + uint GetPSASize(uint index, uint32_t grfid) const override { return cpp_lengthof(PersistentStorage, storage); } + + const int32_t *GetPSAFirstPosition(uint index, uint32_t grfid) const override + { + const Station *st = (const Station *)this->GetInstance(index); + if (st->airport.psa == nullptr) return nullptr; + return (int32_t *)(&st->airport.psa->storage); + } +}; + +static const NIFeature _nif_airport = { + nullptr, + nullptr, + _niv_airports, + new NIHAiport(), +}; + + /*** NewGRF towns ***/ static const NIVariable _niv_towns[] = { @@ -680,7 +731,7 @@ static const NIFeature * const _nifeatures[] = { &_nif_industry, // GSF_INDUSTRIES nullptr, // GSF_CARGOES (has no "physical" objects) nullptr, // GSF_SOUNDFX (has no "physical" objects) - nullptr, // GSF_AIRPORTS (feature not implemented) + &_nif_airport, // GSF_AIRPORTS nullptr, // GSF_SIGNALS (feature not implemented) &_nif_object, // GSF_OBJECTS &_nif_railtype, // GSF_RAILTYPES