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.

(cherry picked from commit a6f2f3c042)
pull/603/head
Michael Lutz 9 months ago committed by Jonathan G Rennison
parent f6eadf19c6
commit 5cc623cb3c

@ -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 GetRandomBits() const override;
uint32 GetVariable(uint16 variable, uint32 parameter, GetVariableExtra *extra) const override;
void StorePSA(uint pos, int32 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 callback_param1 = 0, uint32 callback_param2 = 0);
ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, VarSpriteGroupScopeOffset relative = 0) override
{
switch (scope) {
case VSG_SCOPE_SELF: return &this->airport_scope;
default: return ResolverObject::GetScope(scope, relative);
}
}
GrfSpecFeature GetFeature() const override;
uint32 GetDebugID() const override;
};
/**
* Reset airport classes to their default state.
* This includes initialising the defaults classes with an empty

@ -14,6 +14,7 @@
#include "date_type.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<AirportSpec, AirportClassID, APC_MAX> 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 GetRandomBits() const override;
uint32 GetVariable(uint16 variable, uint32 parameter, GetVariableExtra *extra) const override;
void StorePSA(uint pos, int32 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 callback_param1 = 0, uint32 callback_param2 = 0);
ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, VarSpriteGroupScopeOffset relative = 0) override
{
switch (scope) {
case VSG_SCOPE_SELF: return &this->airport_scope;
default: return ResolverObject::GetScope(scope, relative);
}
}
GrfSpecFeature GetFeature() const override;
uint32 GetDebugID() const override;
};
StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16 callback);
#endif /* NEWGRF_AIRPORT_H */

@ -32,6 +32,7 @@
#include "train.h"
#include "roadveh.h"
#include "newgrf_airport.h"
#include "newgrf_airporttiles.h"
#include "newgrf_debug.h"
#include "newgrf_object.h"

@ -1717,7 +1717,7 @@ static const NIVariable _niv_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 GetTownInspectWindowNumber(Station::GetByTile(index)->town); }
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); }
@ -1751,6 +1751,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, GetVariableExtra *extra) 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, extra);
}
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[] = {
@ -2260,15 +2311,15 @@ static const NIFeature * const _nifeatures[] = {
&_nif_vehicle, // GSF_SHIPS
&_nif_vehicle, // GSF_AIRCRAFT
&_nif_station, // GSF_STATIONS
nullptr, // GSF_CANALS (no callbacks/action2 implemented)
nullptr, // GSF_BRIDGES (no callbacks/action2)
nullptr, // GSF_CANALS (no callbacks/action2 implemented)
nullptr, // GSF_BRIDGES (no callbacks/action2)
&_nif_house, // GSF_HOUSES
nullptr, // GSF_GLOBALVAR (has no "physical" objects)
nullptr, // GSF_GLOBALVAR (has no "physical" objects)
&_nif_industrytile, // GSF_INDUSTRYTILES
&_nif_industry, // GSF_INDUSTRIES
&_nif_cargo, // GSF_CARGOES (has no "physical" objects)
nullptr, // GSF_SOUNDFX (has no "physical" objects)
nullptr, // GSF_AIRPORTS (feature not implemented)
nullptr, // GSF_SOUNDFX (has no "physical" objects)
&_nif_airport, // GSF_AIRPORTS
&_nif_signals, // GSF_SIGNALS
&_nif_object, // GSF_OBJECTS
&_nif_railtype, // GSF_RAILTYPES

Loading…
Cancel
Save