diff options
author | rubidium <rubidium@openttd.org> | 2007-07-08 17:40:04 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-07-08 17:40:04 +0000 |
commit | 283a06e4a195fabea413c55e236586a880c794f6 (patch) | |
tree | e8b08f0eebf44557962f1210eb8b7887d9d999bf /src/industry_cmd.cpp | |
parent | fd2d67784911fc545883f3911790ecc38d43e0e0 (diff) | |
download | openttd-283a06e4a195fabea413c55e236586a880c794f6.tar.xz |
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
Diffstat (limited to 'src/industry_cmd.cpp')
-rw-r--r-- | src/industry_cmd.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 0162f7ce5..6429f2ff1 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -330,12 +330,36 @@ static Slope GetSlopeTileh_Industry(TileIndex tile, Slope tileh) static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac) { - const IndustryTileSpec *itspec = GetIndustryTileSpec(GetIndustryGfx(tile)); - CargoID a; + IndustryGfx gfx = GetIndustryGfx(tile); + const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); + + /* When we have to use a callback, we put our data in the next two variables */ + CargoID raw_accepts_cargo[lengthof(itspec->accepts_cargo)]; + uint8 raw_acceptance[lengthof(itspec->acceptance)]; + + /* And then these will always point to a same sized array with the required data */ + const CargoID *accepts_cargo = itspec->accepts_cargo; + const uint8 *acceptance = itspec->acceptance; + + if (HASBIT(itspec->callback_flags, CBM_INDT_ACCEPT_CARGO)) { + uint16 res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, GetIndustryByTile(tile), tile); + if (res != CALLBACK_FAILED) { + accepts_cargo = raw_accepts_cargo; + for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile); + } + } + + if (HASBIT(itspec->callback_flags, CBM_INDT_CARGO_ACCEPTANCE)) { + uint16 res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, GetIndustryByTile(tile), tile); + if (res != CALLBACK_FAILED) { + acceptance = raw_acceptance; + for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_acceptance[i] = GB(res, i * 4, 4); + } + } for (byte i = 0; i < lengthof(itspec->accepts_cargo); i++) { - a = itspec->accepts_cargo[i]; - if (a != CT_INVALID) ac[a] = itspec->acceptance[i]; + CargoID a = accepts_cargo[i]; + if (a != CT_INVALID) ac[a] = acceptance[i]; } } |