mirror of https://github.com/OpenTTD/OpenTTD
(svn r20658) -Codechange: add the colour of an object to the object instance
parent
b376f8ae15
commit
e0ba6550d2
|
@ -26,6 +26,7 @@ struct Object : ObjectPool::PoolItem<&_object_pool> {
|
|||
Town *town; ///< Town the object is built in
|
||||
TileArea location; ///< Location of the object
|
||||
Date build_date; ///< Date of construction
|
||||
byte colour; ///< Colour of the object, for display purpose
|
||||
|
||||
/** Make sure the object isn't zeroed. */
|
||||
Object() {}
|
||||
|
|
|
@ -63,6 +63,18 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town)
|
|||
o->town = town == NULL ? CalcClosestTownFromTile(tile) : town;
|
||||
o->build_date = _date;
|
||||
|
||||
/* If nothing owns the object, the colour will be random. Otherwise
|
||||
* get the colour from the company's livery settings. */
|
||||
if (owner == OWNER_NONE) {
|
||||
o->colour = Random();
|
||||
} else {
|
||||
const Livery *l = Company::Get(owner)->livery;
|
||||
o->colour = l->colour1 + l->colour2 * 16;
|
||||
}
|
||||
|
||||
/* If the object wants only one colour, then give it that colour. */
|
||||
if ((spec->flags & OBJECT_FLAG_2CC_COLOUR) == 0) o->colour &= 0xF;
|
||||
|
||||
assert(o->town != NULL);
|
||||
|
||||
TILE_AREA_LOOP(t, ta) {
|
||||
|
|
|
@ -2279,6 +2279,15 @@ bool AfterLoadGame()
|
|||
}
|
||||
}
|
||||
|
||||
/* Add (random) colour to all objects. */
|
||||
if (CheckSavegameVersion(148)) {
|
||||
Object *o;
|
||||
FOR_ALL_OBJECTS(o) {
|
||||
Owner owner = GetTileOwner(o->location.tile);
|
||||
o->colour = (owner == OWNER_NONE) ? Random() & 0xF : Company::Get(owner)->livery->colour1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Road stops is 'only' updating some caches */
|
||||
AfterLoadRoadStops();
|
||||
AfterLoadLabelMaps();
|
||||
|
|
|
@ -22,6 +22,7 @@ static const SaveLoad _object_desc[] = {
|
|||
SLE_VAR(Object, location.h, SLE_FILE_U8 | SLE_VAR_U16),
|
||||
SLE_REF(Object, town, REF_TOWN),
|
||||
SLE_VAR(Object, build_date, SLE_UINT32),
|
||||
SLE_CONDVAR(Object, colour, SLE_UINT8, 148, SL_MAX_VERSION),
|
||||
|
||||
SLE_END()
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue