diff --git a/src/object_base.h b/src/object_base.h index 05cea0118e..192e371da4 100644 --- a/src/object_base.h +++ b/src/object_base.h @@ -16,7 +16,7 @@ #include "town_type.h" #include "timer/timer_game_calendar.h" -typedef Pool ObjectPool; +using ObjectPool = Pool; extern ObjectPool _object_pool; /** An object, such as transmitter, on the map. */ diff --git a/src/object_map.h b/src/object_map.h index d646a2bfac..a5280c4f8c 100644 --- a/src/object_map.h +++ b/src/object_map.h @@ -47,7 +47,7 @@ inline bool IsObjectTypeTile(Tile t, ObjectType type) inline ObjectID GetObjectIndex(Tile t) { assert(IsTileType(t, MP_OBJECT)); - return t.m2() | t.m5() << 16; + return ObjectID(t.m2() | t.m5() << 16); } /** @@ -76,10 +76,10 @@ inline void MakeObject(Tile t, Owner o, ObjectID index, WaterClass wc, uint8_t r SetTileType(t, MP_OBJECT); SetTileOwner(t, o); SetWaterClass(t, wc); - t.m2() = index; + t.m2() = index.base(); t.m3() = random; t.m4() = 0; - t.m5() = index >> 16; + t.m5() = index.base() >> 16; SB(t.m6(), 2, 4, 0); t.m7() = 0; } diff --git a/src/object_type.h b/src/object_type.h index 75e9ccead7..2bb53d5f1c 100644 --- a/src/object_type.h +++ b/src/object_type.h @@ -10,6 +10,8 @@ #ifndef OBJECT_TYPE_H #define OBJECT_TYPE_H +#include "core/pool_type.hpp" + /** Types of objects. */ typedef uint16_t ObjectType; @@ -25,11 +27,11 @@ static const ObjectType NUM_OBJECTS_PER_GRF = NUM_OBJECTS; ///< Number of suppor static const ObjectType INVALID_OBJECT_TYPE = 0xFFFF; ///< An invalid object /** Unique identifier for an object. */ -typedef uint32_t ObjectID; +using ObjectID = PoolID; struct Object; struct ObjectSpec; -static const ObjectID INVALID_OBJECT = 0xFFFFFFFF; ///< An invalid object +static constexpr ObjectID INVALID_OBJECT = ObjectID::Invalid(); ///< An invalid object #endif /* OBJECT_TYPE_H */ diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 2e6482c727..e79e491ddd 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2113,7 +2113,7 @@ bool AfterLoadGame() o->location.h = size; o->build_date = TimerGameCalendar::date; o->town = type == OBJECT_STATUE ? Town::Get(t.m2()) : CalcClosestTownFromTile(t, UINT_MAX); - t.m2() = o->index; + t.m2() = o->index.base(); Object::IncTypeCount(type); } else { /* We're at an offset, so get the ID from our "root". */