MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / TestTownOwnsBridge

Function TestTownOwnsBridge

src/town_cmd.cpp:99–113  ·  view source on GitHub ↗

* Check if a town 'owns' a bridge. * Bridges do not directly have an owner, so we check the tiles adjacent to the bridge ends. * If either adjacent tile belongs to the town then it will be assumed that the town built * the bridge. * @param tile The bridge tile to test * @param t The town we are interested in * @return true If town 'owns' a bridge. */

Source from the content-addressed store, hash-verified

97 * @return true If town 'owns' a bridge.
98 */
99static bool TestTownOwnsBridge(TileIndex tile, const Town *t)
100{
101 if (!IsTileOwner(tile, OWNER_TOWN)) return false;
102
103 TileIndex adjacent = tile + TileOffsByDiagDir(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
104 bool town_owned = IsTileType(adjacent, MP_ROAD) && IsTileOwner(adjacent, OWNER_TOWN) && GetTownIndex(adjacent) == t->index;
105
106 if (!town_owned) {
107 /* Or other adjacent road */
108 adjacent = tile + TileOffsByDiagDir(ReverseDiagDir(GetTunnelBridgeDirection(GetOtherTunnelBridgeEnd(tile))));
109 town_owned = IsTileType(adjacent, MP_ROAD) && IsTileOwner(adjacent, OWNER_TOWN) && GetTownIndex(adjacent) == t->index;
110 }
111
112 return town_owned;
113}
114
115Town::~Town()
116{

Callers 2

~TownMethod · 0.85
CmdDeleteTownFunction · 0.85

Calls 7

IsTileOwnerFunction · 0.85
TileOffsByDiagDirFunction · 0.85
ReverseDiagDirFunction · 0.85
GetTunnelBridgeDirectionFunction · 0.85
IsTileTypeFunction · 0.85
GetTownIndexFunction · 0.85
GetOtherTunnelBridgeEndFunction · 0.85

Tested by

no test coverage detected