diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 5ecf9680a6..e83df24519 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -965,7 +965,14 @@ GrfSpecFeature GetGrfSpecFeature(TileIndex tile) switch (GetStationType(tile)) { case STATION_RAIL: return GSF_STATIONS; case STATION_AIRPORT: return GSF_AIRPORTTILES; - default: return GSF_INVALID; + + case STATION_BUS: + case STATION_TRUCK: + case STATION_ROADWAYPOINT: + return GSF_ROADSTOPS; + + default: + return GSF_INVALID; } } } diff --git a/src/newgrf_roadstop.cpp b/src/newgrf_roadstop.cpp index 2f511c600f..b95955d9ce 100644 --- a/src/newgrf_roadstop.cpp +++ b/src/newgrf_roadstop.cpp @@ -459,3 +459,29 @@ void StationUpdateRoadStopCachedTriggers(BaseStation *st) } } } + +void DumpRoadStopSpriteGroup(const BaseStation *st, const RoadStopSpec *spec, std::function print) +{ + CargoID ctype = CT_DEFAULT_NA; + + if (st == nullptr) { + /* No station, so we are in a purchase list */ + ctype = CT_PURCHASE; + } else if (Station::IsExpected(st)) { + const Station *station = Station::From(st); + /* Pick the first cargo that we have waiting */ + for (const CargoSpec *cs : CargoSpec::Iterate()) { + if (spec->grf_prop.spritegroup[cs->Index()] != nullptr && + station->goods[cs->Index()].cargo.TotalCount() > 0) { + ctype = cs->Index(); + break; + } + } + } + + if (spec->grf_prop.spritegroup[ctype] == nullptr) { + ctype = CT_DEFAULT; + } + + DumpSpriteGroup(spec->grf_prop.spritegroup[ctype], std::move(print)); +} diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index f680719424..22bc2a45a0 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2247,6 +2247,8 @@ CommandCost RemoveRoadWaypointStop(TileIndex tile, DoCommandFlag flags) uint specindex = GetCustomRoadStopSpecIndex(tile); + DeleteNewGRFInspectWindow(GSF_ROADSTOPS, tile); + DoClearSquare(tile); wp->rect.AfterRemoveTile(wp, tile); @@ -2341,6 +2343,8 @@ CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags) uint specindex = GetCustomRoadStopSpecIndex(tile); + DeleteNewGRFInspectWindow(GSF_ROADSTOPS, tile); + if (IsDriveThroughStopTile(tile)) { /* Clears the tile for us */ cur_stop->ClearDriveThrough(); diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index 76ed5ec5b5..18e52662f6 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -10,6 +10,7 @@ #include "../newgrf_house.h" #include "../newgrf_engine.h" #include "../newgrf_roadtype.h" +#include "../newgrf_roadstop.h" #include "../newgrf_cargo.h" #include "../date_func.h" #include "../timetable.h" @@ -1370,24 +1371,64 @@ static const NIFeature _nif_roadtype = { new NIHRoadType(), }; -/*** ***/ - static const NIVariable _nif_roadstops[] = { - NIV(0x40, "test"), + NIV(0x40, "view/rotation"), + NIV(0x41, "stop type"), + NIV(0x42, "terrain type"), + NIV(0x43, "road type"), + NIV(0x44, "tram type"), + NIV(0x45, "town zone"), + NIV(0x46, "player info"), + 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_END(), }; class NIHRoadStop : public NIHelper { - bool IsInspectable(uint index) const override { return false; } - 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 nullptr; } - void SetStringParameters(uint index) const override { } - uint32 GetGRFID(uint index) const override { return 0; } + bool IsInspectable(uint index) const override { return GetRoadStopSpec(index) != nullptr; } + bool ShowSpriteDumpButton(uint index) const override { return true; } + uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, BaseStation::GetByTile(index)->town->index); } + const void *GetInstance(uint index)const override { return nullptr; } + const void *GetSpec(uint index) const override { return GetRoadStopSpec(index); } + void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); } + uint32 GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetRoadStopSpec(index)->grf_prop.grffile->grfid : 0; } uint Resolve(uint index, uint var, uint param, GetVariableExtra *extra) const override { - return UINT32_MAX; + int view = GetRoadStopDir(index); + if (IsDriveThroughStopTile(index)) view += 4; + RoadStopResolverObject ro(GetRoadStopSpec(index), BaseStation::GetByTile(index), index, nullptr, GetStationType(index), view); + return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, extra); + } + + void ExtraInfo(uint index, NIExtraInfoOutput &output) const override + { + char buffer[1024]; + output.print("Debug Info:"); + const RoadStopSpec *spec = GetRoadStopSpec(index); + if (spec) { + uint class_id = RoadStopClass::Get(spec->cls_id)->global_id; + seprintf(buffer, lastof(buffer), " class ID: %c%c%c%c, spec ID: %u", class_id >> 24, class_id >> 16, class_id >> 8, class_id, spec->spec_id); + output.print(buffer); + seprintf(buffer, lastof(buffer), " spec: stop type: %u, draw mode: %u, cargo triggers: 0x" OTTD_PRINTFHEX64, spec->stop_type, spec->draw_mode, spec->cargo_triggers); + output.print(buffer); + + const BaseStation *st = BaseStation::GetByTile(index); + seprintf(buffer, lastof(buffer), " stop random bits: %02X", st->GetRoadStopRandomBits(index)); + output.print(buffer); + } + } + + /* virtual */ void SpriteDump(uint index, std::function print) const override + { + extern void DumpRoadStopSpriteGroup(const BaseStation *st, const RoadStopSpec *spec, std::function print); + DumpRoadStopSpriteGroup(BaseStation::GetByTile(index), GetRoadStopSpec(index), std::move(print)); } }; @@ -1420,7 +1461,7 @@ static const NIFeature * const _nifeatures[] = { &_nif_airporttile, // GSF_AIRPORTTILES &_nif_roadtype, // GSF_ROADTYPES &_nif_roadtype, // GSF_TRAMTYPES - &_nif_roadstop, // GSF_ROADSTATIONS + &_nif_roadstop, // GSF_ROADSTOPS &_nif_town, // GSF_FAKE_TOWNS &_nif_station_struct, // GSF_FAKE_STATION_STRUCT };