1
0
Fork 0

Codechange: explicitly initialise Object member variables

pull/13608/head
Rubidium 2025-02-18 17:52:56 +01:00 committed by rubidium42
parent 6eb2dec338
commit 8682f39966
2 changed files with 9 additions and 12 deletions

View File

@ -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() {}

View File

@ -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. */