diff --git a/src/object_base.h b/src/object_base.h index 544fc9ffec..163f771c65 100644 --- a/src/object_base.h +++ b/src/object_base.h @@ -21,15 +21,17 @@ extern ObjectPool _object_pool; /** An object, such as transmitter, on the map. */ struct Object : ObjectPool::PoolItem<&_object_pool> { - ObjectType type; ///< Type of the object - Town *town; ///< Town the object is built in - TileArea location; ///< Location of the object - TimerGameCalendar::Date build_date; ///< Date of construction - uint8_t colour; ///< Colour of the object, for display purpose - uint8_t view; ///< The view setting for this object + ObjectType type = INVALID_OBJECT_TYPE; ///< Type of the object + Town *town = nullptr; ///< Town the object is built in + TileArea location{INVALID_TILE, 0, 0}; ///< Location of the object + TimerGameCalendar::Date build_date{}; ///< Date of construction + uint8_t colour = 0; ///< Colour of the object, for display purpose + uint8_t view = 0; ///< The view setting for this object /** Make sure the object isn't zeroed. */ Object() {} + Object(ObjectType type, Town *town, TileArea location, TimerGameCalendar::Date build_date, uint8_t view) : + type(type), town(town), location(location), build_date(build_date), view(view) {} /** Make sure the right destructor is called as well! */ ~Object() {} diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index 99d2b96792..59da8bc7af 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -90,12 +90,7 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u const ObjectSpec *spec = ObjectSpec::Get(type); TileArea ta(tile, GB(spec->size, HasBit(view, 0) ? 4 : 0, 4), GB(spec->size, HasBit(view, 0) ? 0 : 4, 4)); - Object *o = new Object(); - o->type = type; - o->location = ta; - o->town = town == nullptr ? CalcClosestTownFromTile(tile) : town; - o->build_date = TimerGameCalendar::date; - o->view = view; + Object *o = new Object(type, town == nullptr ? CalcClosestTownFromTile(tile) : town, ta, TimerGameCalendar::date, view); /* If nothing owns the object, the colour will be random. Otherwise * get the colour from the company's livery settings. */