Codechange: split large function into smaller functions with self-explanatory names

This commit is contained in:
Rubidium
2023-02-25 17:08:43 +01:00
committed by rubidium42
parent a409e4b026
commit 8cbf1be9d6
2 changed files with 227 additions and 198 deletions

View File

@@ -3091,83 +3091,89 @@ static Foundation GetFoundation_Station(TileIndex tile, Slope tileh)
return FlatteningFoundation(tileh);
}
static void FillTileDescRoadStop(TileIndex tile, TileDesc *td)
{
RoadType road_rt = GetRoadTypeRoad(tile);
RoadType tram_rt = GetRoadTypeTram(tile);
Owner road_owner = INVALID_OWNER;
Owner tram_owner = INVALID_OWNER;
if (road_rt != INVALID_ROADTYPE) {
const RoadTypeInfo *rti = GetRoadTypeInfo(road_rt);
td->roadtype = rti->strings.name;
td->road_speed = rti->max_speed / 2;
road_owner = GetRoadOwner(tile, RTT_ROAD);
}
if (tram_rt != INVALID_ROADTYPE) {
const RoadTypeInfo *rti = GetRoadTypeInfo(tram_rt);
td->tramtype = rti->strings.name;
td->tram_speed = rti->max_speed / 2;
tram_owner = GetRoadOwner(tile, RTT_TRAM);
}
if (IsDriveThroughStopTile(tile)) {
/* Is there a mix of owners? */
if ((tram_owner != INVALID_OWNER && tram_owner != td->owner[0]) ||
(road_owner != INVALID_OWNER && road_owner != td->owner[0])) {
uint i = 1;
if (road_owner != INVALID_OWNER) {
td->owner_type[i] = STR_LAND_AREA_INFORMATION_ROAD_OWNER;
td->owner[i] = road_owner;
i++;
}
if (tram_owner != INVALID_OWNER) {
td->owner_type[i] = STR_LAND_AREA_INFORMATION_TRAM_OWNER;
td->owner[i] = tram_owner;
}
}
}
}
void FillTileDescRailStation(TileIndex tile, TileDesc *td)
{
const StationSpec *spec = GetStationSpec(tile);
if (spec != nullptr) {
td->station_class = StationClass::Get(spec->cls_id)->name;
td->station_name = spec->name;
if (spec->grf_prop.grffile != nullptr) {
const GRFConfig *gc = GetGRFConfig(spec->grf_prop.grffile->grfid);
td->grf = gc->GetName();
}
}
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
td->rail_speed = rti->max_speed;
td->railtype = rti->strings.name;
}
void FillTileDescAirport(TileIndex tile, TileDesc *td)
{
const AirportSpec *as = Station::GetByTile(tile)->airport.GetSpec();
td->airport_class = AirportClass::Get(as->cls_id)->name;
td->airport_name = as->name;
const AirportTileSpec *ats = AirportTileSpec::GetByTile(tile);
td->airport_tile_name = ats->name;
if (as->grf_prop.grffile != nullptr) {
const GRFConfig *gc = GetGRFConfig(as->grf_prop.grffile->grfid);
td->grf = gc->GetName();
} else if (ats->grf_prop.grffile != nullptr) {
const GRFConfig *gc = GetGRFConfig(ats->grf_prop.grffile->grfid);
td->grf = gc->GetName();
}
}
static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
{
td->owner[0] = GetTileOwner(tile);
if (IsRoadStopTile(tile)) {
RoadType road_rt = GetRoadTypeRoad(tile);
RoadType tram_rt = GetRoadTypeTram(tile);
Owner road_owner = INVALID_OWNER;
Owner tram_owner = INVALID_OWNER;
if (road_rt != INVALID_ROADTYPE) {
const RoadTypeInfo *rti = GetRoadTypeInfo(road_rt);
td->roadtype = rti->strings.name;
td->road_speed = rti->max_speed / 2;
road_owner = GetRoadOwner(tile, RTT_ROAD);
}
if (tram_rt != INVALID_ROADTYPE) {
const RoadTypeInfo *rti = GetRoadTypeInfo(tram_rt);
td->tramtype = rti->strings.name;
td->tram_speed = rti->max_speed / 2;
tram_owner = GetRoadOwner(tile, RTT_TRAM);
}
if (IsDriveThroughStopTile(tile)) {
/* Is there a mix of owners? */
if ((tram_owner != INVALID_OWNER && tram_owner != td->owner[0]) ||
(road_owner != INVALID_OWNER && road_owner != td->owner[0])) {
uint i = 1;
if (road_owner != INVALID_OWNER) {
td->owner_type[i] = STR_LAND_AREA_INFORMATION_ROAD_OWNER;
td->owner[i] = road_owner;
i++;
}
if (tram_owner != INVALID_OWNER) {
td->owner_type[i] = STR_LAND_AREA_INFORMATION_TRAM_OWNER;
td->owner[i] = tram_owner;
}
}
}
}
td->build_date = BaseStation::GetByTile(tile)->build_date;
if (HasStationTileRail(tile)) {
const StationSpec *spec = GetStationSpec(tile);
if (spec != nullptr) {
td->station_class = StationClass::Get(spec->cls_id)->name;
td->station_name = spec->name;
if (spec->grf_prop.grffile != nullptr) {
const GRFConfig *gc = GetGRFConfig(spec->grf_prop.grffile->grfid);
td->grf = gc->GetName();
}
}
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
td->rail_speed = rti->max_speed;
td->railtype = rti->strings.name;
}
if (IsAirport(tile)) {
const AirportSpec *as = Station::GetByTile(tile)->airport.GetSpec();
td->airport_class = AirportClass::Get(as->cls_id)->name;
td->airport_name = as->name;
const AirportTileSpec *ats = AirportTileSpec::GetByTile(tile);
td->airport_tile_name = ats->name;
if (as->grf_prop.grffile != nullptr) {
const GRFConfig *gc = GetGRFConfig(as->grf_prop.grffile->grfid);
td->grf = gc->GetName();
} else if (ats->grf_prop.grffile != nullptr) {
const GRFConfig *gc = GetGRFConfig(ats->grf_prop.grffile->grfid);
td->grf = gc->GetName();
}
}
if (IsRoadStop(tile)) FillTileDescRoadStop(tile, td);
if (HasStationRail(tile)) FillTileDescRailStation(tile, td);
if (IsAirport(tile)) FillTileDescAirport(tile, td);
StringID str;
switch (GetStationType(tile)) {