"Recolouring" is a most interesting and helpful feature in coding newGRFs. It allows to change the colouring of vehicles, stations, buildings, industries, objects, etc, in-game without providing extra graphics sprites. E.g., the original "company colour" feature of TTD is build on this mechanism.
In TTDPatch and OpenTTD, the original recolouring feature has been enhanced. E.g., it can be used now to introduce cargo loads for vehicles without providing any extra graphics sprites, just by recolouring a "mock" cargo sprite. This is most easily being done for bulk cargo (coal, iron ore, copper ore, sand, lime, potash, ...). It could also be used to change vehicles real life's liveries.
Recolouring in m4nfo is built on colour tables. These tables provide the new colours to be used when a vehicle/station/house/.. is to be re-coloured. There might be many colour tables, all put into a spriteblock(), and a specific table is referenced by its index (0: "petrol", 1: "black" in that example).
There are three different ways to recolour. The first one is "simple recolouring", it uses one colour table to recolour one colour each (mock colour -> resulting colour). The second possibility is to include the normal company colour as well. This needs 16 colour tables, one for each of the company colours. The third way would be to use the "two company colours" feature together with explicit recolouring, this would need 256 colour tables per colour.
In consequence, m4nfo provides three different functions to index the appropriate colour tables:
| Function | Description |
| getcolour(<Byte>) | Access recolour table |
| getcolour_pluscc(<Byte>) | Access 16 recolour tables |
| getcolour_plus2cc(<Byte>) | Access 256 recolour tables |
This function addresses a colour table by the given parameter, which is the index of that colour table inside its spriteblock(). See also example for CB_RCOL.
spriteblock(ALLOCATE,
...
// +B6 "ET87_green"
colourtable(DOSMAP,
c0 .. cf, 59 5a 5b 5c 5d 5e 58 59 5a 5b 5c 5d 12 13 14 15
)
// +B7 "ET87_cream/red"
colourtable(DOSMAP,
c0 .. cf, 22 23 24 25 26 27 b3 b4 b5 a2 b6 a3 b4 a2 b6 a3
)
// +B8 "ET87_red"
colourtable(DOSMAP,
c0 .. cf, b4 b5 a2 b6 a3 a4 b3 b4 b5 a2 b6 a3 12 13 14 15
)
)
...
def(ET87GREEN) getcolour(0xB6)
def(ET87BEIGE) getcolour(0xB7)
def(ET87RED) getcolour(0xB8)
...
def(3) yearbuilt(
ref(ET87GREEN) if(< 1932)
ref(ET87BEIGE) if(1932 .. 1949)
ref(ET87RED) else
)
...
def(9) callback(
ref(3) if(CB_RCOL) // recolouring
ref(2) else // graphics
)
This function addresses a colour table by the given parameter, which is the index of that colour table inside its spriteblock(). See also example for CB_RCOL.