Mercurial > hg > openttd
changeset 15970:8aa446dec4e5 draft
(svn r20658) -Codechange: add the colour of an object to the object instance
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sat, 28 Aug 2010 18:28:34 +0000 (2010-08-28) |
parents | dbe7d60ea2fa |
children | 4a7b8f4d73dc |
files | src/object_base.h src/object_cmd.cpp src/saveload/afterload.cpp src/saveload/object_sl.cpp |
diffstat | 4 files changed, 29 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/object_base.h +++ b/src/object_base.h @@ -23,9 +23,10 @@ /** An object, such as transmitter, on the map. */ 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 + 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() {}
--- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -59,9 +59,21 @@ TileArea ta(tile, GB(spec->size, 0, 4), GB(spec->size, 4, 4)); Object *o = new Object(); - o->location = ta; - o->town = town == NULL ? CalcClosestTownFromTile(tile) : town; - o->build_date = _date; + o->location = ta; + 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);
--- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2279,6 +2279,15 @@ } } + /* 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();