diff options
author | frosch <frosch@openttd.org> | 2010-05-01 13:01:21 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-05-01 13:01:21 +0000 |
commit | 77953032274c3bb49c8b22ff7a2767412586c5a7 (patch) | |
tree | 254b97e9037aec36599ddaa0e32e6ff0e388b5a9 /src/newgrf_house.cpp | |
parent | 36850ba3e86fd9633ae0104caa0cb8b8aeecfc37 (diff) | |
download | openttd-77953032274c3bb49c8b22ff7a2767412586c5a7.tar.xz |
(svn r19743) -Fix: NewGrfs could access map bits of not yet constructed industries and houses during construction callbacks.
Diffstat (limited to 'src/newgrf_house.cpp')
-rw-r--r-- | src/newgrf_house.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index 1f53e2c73..3ca62f5bd 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -99,20 +99,25 @@ void DecreaseBuildingCount(Town *t, HouseID house_id) static uint32 HouseGetRandomBits(const ResolverObject *object) { - const TileIndex tile = object->u.house.tile; - return (tile == INVALID_TILE || !IsTileType(tile, MP_HOUSE)) ? 0 : GetHouseRandomBits(tile); + /* Note: Towns build houses over houses. So during construction checks 'tile' may be a valid but unrelated house. */ + TileIndex tile = object->u.house.tile; + assert(IsValidTile(tile) && (object->u.house.not_yet_constructed || IsTileType(tile, MP_HOUSE))); + return object->u.house.not_yet_constructed ? 0 : GetHouseRandomBits(tile); } static uint32 HouseGetTriggers(const ResolverObject *object) { - const TileIndex tile = object->u.house.tile; - return (tile == INVALID_TILE || !IsTileType(tile, MP_HOUSE)) ? 0 : GetHouseTriggers(tile); + /* Note: Towns build houses over houses. So during construction checks 'tile' may be a valid but unrelated house. */ + TileIndex tile = object->u.house.tile; + assert(IsValidTile(tile) && (object->u.house.not_yet_constructed || IsTileType(tile, MP_HOUSE))); + return object->u.house.not_yet_constructed ? 0 : GetHouseTriggers(tile); } static void HouseSetTriggers(const ResolverObject *object, int triggers) { - const TileIndex tile = object->u.house.tile; - if (IsTileType(tile, MP_HOUSE)) SetHouseTriggers(tile, triggers); + TileIndex tile = object->u.house.tile; + assert(!object->u.house.not_yet_constructed && IsValidTile(tile) && IsTileType(tile, MP_HOUSE)); + SetHouseTriggers(tile, triggers); } static uint32 GetNumHouses(HouseID house_id, const Town *town) @@ -370,6 +375,7 @@ static void NewHouseResolver(ResolverObject *res, HouseID house_id, TileIndex ti res->u.house.tile = tile; res->u.house.town = town; res->u.house.house_id = house_id; + res->u.house.not_yet_constructed = false; res->callback = CBID_NO_CALLBACK; res->callback_param1 = 0; @@ -383,15 +389,18 @@ static void NewHouseResolver(ResolverObject *res, HouseID house_id, TileIndex ti res->grffile = (hs != NULL ? hs->grffile : NULL); } -uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile) +uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile, bool not_yet_constructed) { ResolverObject object; const SpriteGroup *group; + assert(IsValidTile(tile) && (not_yet_constructed || IsTileType(tile, MP_HOUSE))); + NewHouseResolver(&object, house_id, tile, town); object.callback = callback; object.callback_param1 = param1; object.callback_param2 = param2; + object.u.house.not_yet_constructed = not_yet_constructed; group = SpriteGroup::Resolve(HouseSpec::Get(house_id)->spritegroup, &object); if (group == NULL) return CALLBACK_FAILED; |