mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r25832) -Codechange: Reduce variety of object type test functions.
This commit is contained in:
parent
b1131671d4
commit
2080a8c16f
@ -295,7 +295,7 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
||||
case OBJECT_OWNED_LAND:
|
||||
if (IsTileType(tile, MP_OBJECT) &&
|
||||
IsTileOwner(tile, _current_company) &&
|
||||
IsOwnedLand(tile)) {
|
||||
IsObjectType(tile, OBJECT_OWNED_LAND)) {
|
||||
return_cmd_error(STR_ERROR_YOU_ALREADY_OWN_IT);
|
||||
}
|
||||
break;
|
||||
@ -396,7 +396,7 @@ static void DrawTile_Object(TileInfo *ti)
|
||||
|
||||
static int GetSlopePixelZ_Object(TileIndex tile, uint x, uint y)
|
||||
{
|
||||
if (IsOwnedLand(tile)) {
|
||||
if (IsObjectType(tile, OBJECT_OWNED_LAND)) {
|
||||
int z;
|
||||
Slope tileh = GetTilePixelSlope(tile, &z);
|
||||
|
||||
@ -408,7 +408,7 @@ static int GetSlopePixelZ_Object(TileIndex tile, uint x, uint y)
|
||||
|
||||
static Foundation GetFoundation_Object(TileIndex tile, Slope tileh)
|
||||
{
|
||||
return IsOwnedLand(tile) ? FOUNDATION_NONE : FlatteningFoundation(tileh);
|
||||
return IsObjectType(tile, OBJECT_OWNED_LAND) ? FOUNDATION_NONE : FlatteningFoundation(tileh);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -525,7 +525,7 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
|
||||
|
||||
static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
|
||||
{
|
||||
if (!IsCompanyHQ(tile)) return;
|
||||
if (!IsObjectType(tile, OBJECT_HQ)) return;
|
||||
|
||||
/* HQ accepts passenger and mail; but we have to divide the values
|
||||
* between 4 tiles it occupies! */
|
||||
@ -570,7 +570,7 @@ static void TileLoop_Object(TileIndex tile)
|
||||
|
||||
if (IsTileOnWater(tile)) TileLoop_Water(tile);
|
||||
|
||||
if (!IsCompanyHQ(tile)) return;
|
||||
if (!IsObjectType(tile, OBJECT_HQ)) return;
|
||||
|
||||
/* HQ accepts passenger and mail; but we have to divide the values
|
||||
* between 4 tiles it occupies! */
|
||||
@ -607,7 +607,7 @@ static TrackStatus GetTileTrackStatus_Object(TileIndex tile, TransportType mode,
|
||||
|
||||
static bool ClickTile_Object(TileIndex tile)
|
||||
{
|
||||
if (!IsCompanyHQ(tile)) return false;
|
||||
if (!IsObjectType(tile, OBJECT_HQ)) return false;
|
||||
|
||||
ShowCompany(GetTileOwner(tile));
|
||||
return true;
|
||||
@ -626,7 +626,7 @@ static void AnimateTile_Object(TileIndex tile)
|
||||
*/
|
||||
static bool HasTransmitter(TileIndex tile, void *user)
|
||||
{
|
||||
return IsTransmitterTile(tile);
|
||||
return IsObjectTypeTile(tile, OBJECT_TRANSMITTER);
|
||||
}
|
||||
|
||||
void GenerateObjects()
|
||||
@ -713,9 +713,9 @@ static void ChangeTileOwner_Object(TileIndex tile, Owner old_owner, Owner new_ow
|
||||
{
|
||||
if (!IsTileOwner(tile, old_owner)) return;
|
||||
|
||||
if (IsOwnedLand(tile) && new_owner != INVALID_OWNER) {
|
||||
if (IsObjectType(tile, OBJECT_OWNED_LAND) && new_owner != INVALID_OWNER) {
|
||||
SetTileOwner(tile, new_owner);
|
||||
} else if (IsStatueTile(tile)) {
|
||||
} else if (IsObjectType(tile, OBJECT_STATUE)) {
|
||||
Town *t = Object::GetByTile(tile)->town;
|
||||
ClrBit(t->statues, old_owner);
|
||||
if (new_owner != INVALID_OWNER && !HasBit(t->statues, new_owner)) {
|
||||
|
@ -27,6 +27,29 @@ static inline ObjectType GetObjectType(TileIndex t)
|
||||
return (ObjectType)_m[t].m5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the object on a tile is of a specific type.
|
||||
* @param t Tile to test.
|
||||
* @param type Type to test.
|
||||
* @pre IsTileType(t, MP_OBJECT)
|
||||
* @return True if type matches.
|
||||
*/
|
||||
static inline bool IsObjectType(TileIndex t, ObjectType type)
|
||||
{
|
||||
return GetObjectType(t) == type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a tile is a object tile of a specific type.
|
||||
* @param t Tile to test.
|
||||
* @param type Type to test.
|
||||
* @return True if type matches.
|
||||
*/
|
||||
static inline bool IsObjectTypeTile(TileIndex t, ObjectType type)
|
||||
{
|
||||
return IsTileType(t, MP_OBJECT) && GetObjectType(t) == type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the index of which object this tile is attached to.
|
||||
* @param t the tile
|
||||
@ -39,72 +62,6 @@ static inline ObjectID GetObjectIndex(TileIndex t)
|
||||
return _m[t].m2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given tile have a transmitter?
|
||||
* @param t the tile to inspect.
|
||||
* @return true if and only if the tile has a transmitter.
|
||||
*/
|
||||
static inline bool IsTransmitterTile(TileIndex t)
|
||||
{
|
||||
return IsTileType(t, MP_OBJECT) && GetObjectType(t) == OBJECT_TRANSMITTER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this object tile an 'owned land' tile?
|
||||
* @param t the tile to inspect.
|
||||
* @pre IsTileType(t, MP_OBJECT)
|
||||
* @return true if and only if the tile is an 'owned land' tile.
|
||||
*/
|
||||
static inline bool IsOwnedLand(TileIndex t)
|
||||
{
|
||||
assert(IsTileType(t, MP_OBJECT));
|
||||
return GetObjectType(t) == OBJECT_OWNED_LAND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given tile (pre-)owned by someone (the little flags)?
|
||||
* @param t the tile to inspect.
|
||||
* @return true if and only if the tile is an 'owned land' tile.
|
||||
*/
|
||||
static inline bool IsOwnedLandTile(TileIndex t)
|
||||
{
|
||||
return IsTileType(t, MP_OBJECT) && IsOwnedLand(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this object tile a HQ tile?
|
||||
* @param t the tile to inspect.
|
||||
* @pre IsTileType(t, MP_OBJECT)
|
||||
* @return true if and only if the tile is a HQ tile.
|
||||
*/
|
||||
static inline bool IsCompanyHQ(TileIndex t)
|
||||
{
|
||||
assert(IsTileType(t, MP_OBJECT));
|
||||
return _m[t].m5 == OBJECT_HQ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this object tile a statue?
|
||||
* @param t the tile to inspect.
|
||||
* @pre IsTileType(t, MP_OBJECT)
|
||||
* @return true if and only if the tile is a statue.
|
||||
*/
|
||||
static inline bool IsStatue(TileIndex t)
|
||||
{
|
||||
assert(IsTileType(t, MP_OBJECT));
|
||||
return GetObjectType(t) == OBJECT_STATUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given tile a statue?
|
||||
* @param t the tile to inspect.
|
||||
* @return true if and only if the tile is a statue.
|
||||
*/
|
||||
static inline bool IsStatueTile(TileIndex t)
|
||||
{
|
||||
return IsTileType(t, MP_OBJECT) && IsStatue(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the random bits of this tile.
|
||||
* @param t The tile to get the bits for.
|
||||
|
@ -2572,7 +2572,7 @@ static void TileLoop_Track(TileIndex tile)
|
||||
|
||||
/* Show fences if it's a house, industry, object, road, tunnelbridge or not owned by us. */
|
||||
if (!IsValidTile(tile2) || IsTileType(tile2, MP_HOUSE) || IsTileType(tile2, MP_INDUSTRY) ||
|
||||
IsTileType(tile2, MP_ROAD) || (IsTileType(tile2, MP_OBJECT) && !IsOwnedLand(tile2)) || IsTileType(tile2, MP_TUNNELBRIDGE) || !IsTileOwner(tile2, owner)) {
|
||||
IsTileType(tile2, MP_ROAD) || (IsTileType(tile2, MP_OBJECT) && !IsObjectType(tile2, OBJECT_OWNED_LAND)) || IsTileType(tile2, MP_TUNNELBRIDGE) || !IsTileOwner(tile2, owner)) {
|
||||
fences |= 1 << d;
|
||||
}
|
||||
}
|
||||
|
@ -1444,7 +1444,7 @@ bool AfterLoadGame()
|
||||
|
||||
if (IsSavegameVersionBefore(52)) {
|
||||
for (TileIndex t = 0; t < map_size; t++) {
|
||||
if (IsStatueTile(t)) {
|
||||
if (IsTileType(t, MP_OBJECT) && GetObjectType(t) == OBJECT_STATUE) {
|
||||
_m[t].m2 = CalcClosestTownFromTile(t)->index;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user