mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-09-01 19:09:09 +00:00
Codechange: Remove output pointer from GetTileArea(). (#14530)
This simplifies things and removes undocumented type `ETileArea`
This commit is contained in:
@@ -130,11 +130,10 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
|
||||
|
||||
/**
|
||||
* Get the tile area for a given station type.
|
||||
* @param ta tile area to fill.
|
||||
* @param type the type of the area
|
||||
* @return The tile area.
|
||||
*/
|
||||
virtual void GetTileArea(TileArea *ta, StationType type) const = 0;
|
||||
|
||||
virtual TileArea GetTileArea(StationType type) const = 0;
|
||||
|
||||
/**
|
||||
* Obtain the length of a platform
|
||||
|
@@ -73,38 +73,36 @@ enum TriggerArea : uint8_t {
|
||||
TA_WHOLE,
|
||||
};
|
||||
|
||||
struct ETileArea : TileArea {
|
||||
ETileArea(const BaseStation *st, TileIndex tile, TriggerArea ta)
|
||||
{
|
||||
switch (ta) {
|
||||
default: NOT_REACHED();
|
||||
/**
|
||||
* Get the tile area of a rail station with trigger area type.
|
||||
* @param st The rail station or rail waypoint.
|
||||
* @param tile Origin tile.
|
||||
* @param ta Trigger area type.
|
||||
* @return The tile area.
|
||||
*/
|
||||
TileArea GetRailTileArea(const BaseStation *st, TileIndex tile, TriggerArea ta)
|
||||
{
|
||||
switch (ta) {
|
||||
default: NOT_REACHED();
|
||||
|
||||
case TA_TILE:
|
||||
this->tile = tile;
|
||||
this->w = 1;
|
||||
this->h = 1;
|
||||
break;
|
||||
case TA_TILE:
|
||||
return {tile, 1, 1};
|
||||
|
||||
case TA_PLATFORM: {
|
||||
TileIndex start, end;
|
||||
Axis axis = GetRailStationAxis(tile);
|
||||
TileIndexDiff delta = TileOffsByAxis(axis);
|
||||
case TA_PLATFORM: {
|
||||
TileIndex start, end;
|
||||
Axis axis = GetRailStationAxis(tile);
|
||||
TileIndexDiff delta = TileOffsByAxis(axis);
|
||||
|
||||
for (end = tile; IsRailStationTile(end + delta) && IsCompatibleTrainStationTile(end + delta, tile); end += delta) { /* Nothing */ }
|
||||
for (start = tile; IsRailStationTile(start - delta) && IsCompatibleTrainStationTile(start - delta, tile); start -= delta) { /* Nothing */ }
|
||||
for (end = tile; IsRailStationTile(end + delta) && IsCompatibleTrainStationTile(end + delta, tile); end += delta) { /* Nothing */ }
|
||||
for (start = tile; IsRailStationTile(start - delta) && IsCompatibleTrainStationTile(start - delta, tile); start -= delta) { /* Nothing */ }
|
||||
|
||||
this->tile = start;
|
||||
this->w = TileX(end) - TileX(start) + 1;
|
||||
this->h = TileY(end) - TileY(start) + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case TA_WHOLE:
|
||||
st->GetTileArea(this, Station::IsExpected(st) ? StationType::Rail : StationType::RailWaypoint);
|
||||
break;
|
||||
return TileArea(start, TileX(end) - TileX(start) + 1, TileY(end) - TileY(start) + 1);
|
||||
}
|
||||
|
||||
case TA_WHOLE:
|
||||
return st->GetTileArea(Station::IsExpected(st) ? StationType::Rail : StationType::RailWaypoint);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -745,9 +743,8 @@ void DeallocateSpecFromStation(BaseStation *st, uint8_t specindex)
|
||||
/* specindex of 0 (default) is never freeable */
|
||||
if (specindex == 0) return;
|
||||
|
||||
ETileArea area = ETileArea(st, INVALID_TILE, TA_WHOLE);
|
||||
/* Check all tiles over the station to check if the specindex is still in use */
|
||||
for (TileIndex tile : area) {
|
||||
for (TileIndex tile : GetRailTileArea(st, INVALID_TILE, TA_WHOLE)) {
|
||||
if (st->TileBelongsToRailStation(tile) && GetCustomStationSpecIndex(tile) == specindex) {
|
||||
return;
|
||||
}
|
||||
@@ -911,10 +908,9 @@ void TriggerStationAnimation(BaseStation *st, TileIndex trigger_tile, StationAni
|
||||
if (!st->cached_anim_triggers.Test(trigger)) return;
|
||||
|
||||
uint16_t random_bits = Random();
|
||||
ETileArea area = ETileArea(st, trigger_tile, tas[static_cast<size_t>(trigger)]);
|
||||
|
||||
/* Check all tiles over the station to check if the specindex is still in use */
|
||||
for (TileIndex tile : area) {
|
||||
for (TileIndex tile : GetRailTileArea(st, trigger_tile, tas[static_cast<size_t>(trigger)])) {
|
||||
if (st->TileBelongsToRailStation(tile)) {
|
||||
const StationSpec *ss = GetStationSpec(tile);
|
||||
if (ss != nullptr && ss->animation.triggers.Test(trigger)) {
|
||||
@@ -951,7 +947,6 @@ void TriggerStationRandomisation(BaseStation *st, TileIndex trigger_tile, Statio
|
||||
if (IsValidCargoType(cargo_type) && !HasBit(st->cached_cargo_triggers, cargo_type)) return;
|
||||
|
||||
uint32_t whole_reseed = 0;
|
||||
ETileArea area = ETileArea(st, trigger_tile, tas[static_cast<size_t>(trigger)]);
|
||||
|
||||
/* Bitmask of completely empty cargo types to be matched. */
|
||||
CargoTypes empty_mask{};
|
||||
@@ -964,7 +959,7 @@ void TriggerStationRandomisation(BaseStation *st, TileIndex trigger_tile, Statio
|
||||
StationRandomTriggers used_random_triggers;
|
||||
|
||||
/* Check all tiles over the station to check if the specindex is still in use */
|
||||
for (TileIndex tile : area) {
|
||||
for (TileIndex tile : GetRailTileArea(st, trigger_tile, tas[static_cast<size_t>(trigger)])) {
|
||||
if (st->TileBelongsToRailStation(tile)) {
|
||||
const StationSpec *ss = GetStationSpec(tile);
|
||||
if (ss == nullptr) continue;
|
||||
|
@@ -25,8 +25,7 @@
|
||||
inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile, StationType station_type)
|
||||
{
|
||||
const BaseStation *st = BaseStation::Get(station);
|
||||
TileArea ta;
|
||||
st->GetTileArea(&ta, station_type);
|
||||
TileArea ta = st->GetTileArea(station_type);
|
||||
|
||||
/* If the rail station is (temporarily) not present, use the station sign to drive near the station */
|
||||
if (ta.tile == INVALID_TILE) return st->xy;
|
||||
|
@@ -184,9 +184,7 @@ public:
|
||||
if (v->current_order.IsType(OT_GOTO_STATION)) {
|
||||
StationID station_id = v->current_order.GetDestination().ToStationID();
|
||||
const BaseStation *station = BaseStation::Get(station_id);
|
||||
TileArea tile_area;
|
||||
station->GetTileArea(&tile_area, StationType::Dock);
|
||||
for (const auto &tile : tile_area) {
|
||||
for (const auto &tile : station->GetTileArea(StationType::Dock)) {
|
||||
if (IsDockingTile(tile) && IsShipDestinationTile(tile, station_id)) {
|
||||
pf.AddOrigin(GetWaterRegionPatchInfo(tile));
|
||||
}
|
||||
|
@@ -579,7 +579,7 @@ public:
|
||||
|
||||
uint32_t GetNewGRFVariable(const ResolverObject &object, uint8_t variable, uint8_t parameter, bool &available) const override;
|
||||
|
||||
void GetTileArea(TileArea *ta, StationType type) const override;
|
||||
TileArea GetTileArea(StationType type) const override;
|
||||
};
|
||||
|
||||
/** Iterator to iterate over all tiles belonging to an airport. */
|
||||
|
@@ -411,30 +411,15 @@ static Station *GetClosestDeletedStation(TileIndex tile)
|
||||
}
|
||||
|
||||
|
||||
void Station::GetTileArea(TileArea *ta, StationType type) const
|
||||
TileArea Station::GetTileArea(StationType type) const
|
||||
{
|
||||
switch (type) {
|
||||
case StationType::Rail:
|
||||
*ta = this->train_station;
|
||||
return;
|
||||
|
||||
case StationType::Airport:
|
||||
*ta = this->airport;
|
||||
return;
|
||||
|
||||
case StationType::Truck:
|
||||
*ta = this->truck_station;
|
||||
return;
|
||||
|
||||
case StationType::Bus:
|
||||
*ta = this->bus_station;
|
||||
return;
|
||||
|
||||
case StationType::Rail: return this->train_station;
|
||||
case StationType::Airport: return this->airport;
|
||||
case StationType::Truck: return this->truck_station;
|
||||
case StationType::Bus: return this->bus_station;
|
||||
case StationType::Dock:
|
||||
case StationType::Oilrig:
|
||||
*ta = this->docking_station;
|
||||
return;
|
||||
|
||||
case StationType::Oilrig: return this->docking_station;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
@@ -32,23 +32,12 @@ void DrawWaypointSprite(int x, int y, StationClassID station_class, uint16_t sta
|
||||
}
|
||||
}
|
||||
|
||||
void Waypoint::GetTileArea(TileArea *ta, StationType type) const
|
||||
TileArea Waypoint::GetTileArea(StationType type) const
|
||||
{
|
||||
switch (type) {
|
||||
case StationType::RailWaypoint:
|
||||
*ta = this->train_station;
|
||||
return;
|
||||
|
||||
case StationType::RoadWaypoint:
|
||||
*ta = this->road_waypoint_area;
|
||||
return;
|
||||
|
||||
case StationType::Buoy:
|
||||
ta->tile = this->xy;
|
||||
ta->w = 1;
|
||||
ta->h = 1;
|
||||
break;
|
||||
|
||||
case StationType::RailWaypoint: return this->train_station;
|
||||
case StationType::RoadWaypoint: return this->road_waypoint_area;
|
||||
case StationType::Buoy: return {this->xy, 1, 1};
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ struct Waypoint final : SpecializedStation<Waypoint, true> {
|
||||
|
||||
uint32_t GetNewGRFVariable(const struct ResolverObject &object, uint8_t variable, uint8_t parameter, bool &available) const override;
|
||||
|
||||
void GetTileArea(TileArea *ta, StationType type) const override;
|
||||
TileArea GetTileArea(StationType type) const override;
|
||||
|
||||
uint GetPlatformLength(TileIndex, DiagDirection) const override
|
||||
{
|
||||
|
@@ -60,9 +60,7 @@ private:
|
||||
default:
|
||||
NOT_REACHED();
|
||||
}
|
||||
TileArea ta;
|
||||
this->wp->GetTileArea(&ta, type);
|
||||
return ta.GetCenterTile();
|
||||
return this->wp->GetTileArea(type).GetCenterTile();
|
||||
}
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user