mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-09-02 03:19:10 +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.
|
* Get the tile area for a given station type.
|
||||||
* @param ta tile area to fill.
|
|
||||||
* @param type the type of the area
|
* @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
|
* Obtain the length of a platform
|
||||||
|
@@ -73,38 +73,36 @@ enum TriggerArea : uint8_t {
|
|||||||
TA_WHOLE,
|
TA_WHOLE,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ETileArea : TileArea {
|
/**
|
||||||
ETileArea(const BaseStation *st, TileIndex tile, TriggerArea ta)
|
* Get the tile area of a rail station with trigger area type.
|
||||||
{
|
* @param st The rail station or rail waypoint.
|
||||||
switch (ta) {
|
* @param tile Origin tile.
|
||||||
default: NOT_REACHED();
|
* @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:
|
case TA_TILE:
|
||||||
this->tile = tile;
|
return {tile, 1, 1};
|
||||||
this->w = 1;
|
|
||||||
this->h = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TA_PLATFORM: {
|
case TA_PLATFORM: {
|
||||||
TileIndex start, end;
|
TileIndex start, end;
|
||||||
Axis axis = GetRailStationAxis(tile);
|
Axis axis = GetRailStationAxis(tile);
|
||||||
TileIndexDiff delta = TileOffsByAxis(axis);
|
TileIndexDiff delta = TileOffsByAxis(axis);
|
||||||
|
|
||||||
for (end = tile; IsRailStationTile(end + delta) && IsCompatibleTrainStationTile(end + delta, tile); end += 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 */ }
|
for (start = tile; IsRailStationTile(start - delta) && IsCompatibleTrainStationTile(start - delta, tile); start -= delta) { /* Nothing */ }
|
||||||
|
|
||||||
this->tile = start;
|
return TileArea(start, TileX(end) - TileX(start) + 1, TileY(end) - TileY(start) + 1);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 */
|
/* specindex of 0 (default) is never freeable */
|
||||||
if (specindex == 0) return;
|
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 */
|
/* 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) {
|
if (st->TileBelongsToRailStation(tile) && GetCustomStationSpecIndex(tile) == specindex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -911,10 +908,9 @@ void TriggerStationAnimation(BaseStation *st, TileIndex trigger_tile, StationAni
|
|||||||
if (!st->cached_anim_triggers.Test(trigger)) return;
|
if (!st->cached_anim_triggers.Test(trigger)) return;
|
||||||
|
|
||||||
uint16_t random_bits = Random();
|
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 */
|
/* 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)) {
|
if (st->TileBelongsToRailStation(tile)) {
|
||||||
const StationSpec *ss = GetStationSpec(tile);
|
const StationSpec *ss = GetStationSpec(tile);
|
||||||
if (ss != nullptr && ss->animation.triggers.Test(trigger)) {
|
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;
|
if (IsValidCargoType(cargo_type) && !HasBit(st->cached_cargo_triggers, cargo_type)) return;
|
||||||
|
|
||||||
uint32_t whole_reseed = 0;
|
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. */
|
/* Bitmask of completely empty cargo types to be matched. */
|
||||||
CargoTypes empty_mask{};
|
CargoTypes empty_mask{};
|
||||||
@@ -964,7 +959,7 @@ void TriggerStationRandomisation(BaseStation *st, TileIndex trigger_tile, Statio
|
|||||||
StationRandomTriggers used_random_triggers;
|
StationRandomTriggers used_random_triggers;
|
||||||
|
|
||||||
/* Check all tiles over the station to check if the specindex is still in use */
|
/* 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)) {
|
if (st->TileBelongsToRailStation(tile)) {
|
||||||
const StationSpec *ss = GetStationSpec(tile);
|
const StationSpec *ss = GetStationSpec(tile);
|
||||||
if (ss == nullptr) continue;
|
if (ss == nullptr) continue;
|
||||||
|
@@ -25,8 +25,7 @@
|
|||||||
inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile, StationType station_type)
|
inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile, StationType station_type)
|
||||||
{
|
{
|
||||||
const BaseStation *st = BaseStation::Get(station);
|
const BaseStation *st = BaseStation::Get(station);
|
||||||
TileArea ta;
|
TileArea ta = st->GetTileArea(station_type);
|
||||||
st->GetTileArea(&ta, station_type);
|
|
||||||
|
|
||||||
/* If the rail station is (temporarily) not present, use the station sign to drive near the station */
|
/* 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;
|
if (ta.tile == INVALID_TILE) return st->xy;
|
||||||
|
@@ -184,9 +184,7 @@ public:
|
|||||||
if (v->current_order.IsType(OT_GOTO_STATION)) {
|
if (v->current_order.IsType(OT_GOTO_STATION)) {
|
||||||
StationID station_id = v->current_order.GetDestination().ToStationID();
|
StationID station_id = v->current_order.GetDestination().ToStationID();
|
||||||
const BaseStation *station = BaseStation::Get(station_id);
|
const BaseStation *station = BaseStation::Get(station_id);
|
||||||
TileArea tile_area;
|
for (const auto &tile : station->GetTileArea(StationType::Dock)) {
|
||||||
station->GetTileArea(&tile_area, StationType::Dock);
|
|
||||||
for (const auto &tile : tile_area) {
|
|
||||||
if (IsDockingTile(tile) && IsShipDestinationTile(tile, station_id)) {
|
if (IsDockingTile(tile) && IsShipDestinationTile(tile, station_id)) {
|
||||||
pf.AddOrigin(GetWaterRegionPatchInfo(tile));
|
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;
|
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. */
|
/** 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) {
|
switch (type) {
|
||||||
case StationType::Rail:
|
case StationType::Rail: return this->train_station;
|
||||||
*ta = this->train_station;
|
case StationType::Airport: return this->airport;
|
||||||
return;
|
case StationType::Truck: return this->truck_station;
|
||||||
|
case StationType::Bus: return this->bus_station;
|
||||||
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::Dock:
|
case StationType::Dock:
|
||||||
case StationType::Oilrig:
|
case StationType::Oilrig: return this->docking_station;
|
||||||
*ta = this->docking_station;
|
|
||||||
return;
|
|
||||||
|
|
||||||
default: NOT_REACHED();
|
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) {
|
switch (type) {
|
||||||
case StationType::RailWaypoint:
|
case StationType::RailWaypoint: return this->train_station;
|
||||||
*ta = this->train_station;
|
case StationType::RoadWaypoint: return this->road_waypoint_area;
|
||||||
return;
|
case StationType::Buoy: return {this->xy, 1, 1};
|
||||||
|
|
||||||
case StationType::RoadWaypoint:
|
|
||||||
*ta = this->road_waypoint_area;
|
|
||||||
return;
|
|
||||||
|
|
||||||
case StationType::Buoy:
|
|
||||||
ta->tile = this->xy;
|
|
||||||
ta->w = 1;
|
|
||||||
ta->h = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: NOT_REACHED();
|
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;
|
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
|
uint GetPlatformLength(TileIndex, DiagDirection) const override
|
||||||
{
|
{
|
||||||
|
@@ -60,9 +60,7 @@ private:
|
|||||||
default:
|
default:
|
||||||
NOT_REACHED();
|
NOT_REACHED();
|
||||||
}
|
}
|
||||||
TileArea ta;
|
return this->wp->GetTileArea(type).GetCenterTile();
|
||||||
this->wp->GetTileArea(&ta, type);
|
|
||||||
return ta.GetCenterTile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Reference in New Issue
Block a user