mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
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.
This commit is contained in:
parent
e6c02ebee6
commit
a6f2f3c042
@ -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
|
||||
|
@ -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<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_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 */
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user