truelight@9476: /* $Id$ */ truelight@9476: truelight@9476: /** @file newgrf_house.cpp */ truelight@9476: truelight@9476: #include "stdafx.h" truelight@9476: #include "openttd.h" truelight@9476: #include "functions.h" truelight@9476: #include "variables.h" truelight@9476: #include "debug.h" truelight@9476: #include "viewport.h" glx@9505: #include "landscape.h" truelight@9476: #include "date.h" truelight@9476: #include "town.h" truelight@9476: #include "town_map.h" truelight@9476: #include "sound.h" truelight@9476: #include "sprite.h" truelight@9476: #include "strings.h" truelight@9476: #include "table/strings.h" truelight@9476: #include "table/sprites.h" truelight@9476: #include "table/town_land.h" truelight@9476: #include "newgrf.h" truelight@9476: #include "newgrf_house.h" truelight@9476: #include "newgrf_spritegroup.h" truelight@9476: #include "newgrf_callbacks.h" truelight@9476: #include "newgrf_town.h" truelight@9476: #include "newgrf_sound.h" glx@9624: #include "newgrf_commons.h" truelight@9476: truelight@9476: static BuildingCounts _building_counts; truelight@9476: static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX]; truelight@9476: glx@9624: HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, HOUSE_MAX, INVALID_HOUSE_ID); truelight@9476: truelight@9476: void CheckHouseIDs() truelight@9476: { rubidium@9701: InitializeBuildingCounts(); rubidium@9701: truelight@9476: for (TileIndex t = 0; t < MapSize(); t++) { truelight@9476: HouseID house_id; truelight@9476: truelight@9476: if (!IsTileType(t, MP_HOUSE)) continue; truelight@9476: truelight@9476: house_id = GetHouseType(t); truelight@9476: if (!GetHouseSpecs(house_id)->enabled && house_id >= NEW_HOUSE_OFFSET) { truelight@9476: /* The specs for this type of house are not available any more, so truelight@9476: * replace it with the substitute original house type. */ rubidium@9701: house_id = _house_mngr.GetSubstituteID(house_id); rubidium@9701: SetHouseType(t, house_id); truelight@9476: } rubidium@9701: IncreaseBuildingCount(GetTownByTile(t), house_id); truelight@9476: } truelight@9476: } truelight@9476: truelight@9476: HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid) truelight@9476: { truelight@9476: /* Start from 1 because 0 means that no class has been assigned. */ truelight@9476: for (int i = 1; i != lengthof(_class_mapping); i++) { truelight@9476: HouseClassMapping *map = &_class_mapping[i]; truelight@9476: truelight@9476: if (map->class_id == grf_class_id && map->grfid == grfid) return (HouseClassID)i; truelight@9476: truelight@9476: if (map->class_id == 0 && map->grfid == 0) { truelight@9476: map->class_id = grf_class_id; truelight@9476: map->grfid = grfid; truelight@9476: return (HouseClassID)i; truelight@9476: } truelight@9476: } truelight@9476: return HOUSE_NO_CLASS; truelight@9476: } truelight@9476: truelight@9476: void InitializeBuildingCounts() truelight@9476: { truelight@9476: memset(&_building_counts, 0, sizeof(_building_counts)); truelight@9476: } truelight@9476: truelight@9476: /** truelight@9476: * IncreaseBuildingCount() truelight@9476: * Increase the count of a building when it has been added by a town. truelight@9476: * @param t The town that the building is being built in truelight@9476: * @param house_id The id of the house being added truelight@9476: */ truelight@9476: void IncreaseBuildingCount(Town *t, HouseID house_id) truelight@9476: { truelight@9476: HouseClassID class_id = GetHouseSpecs(house_id)->class_id; truelight@9476: rubidium@9628: if (!_loaded_newgrf_features.has_newhouses) return; truelight@9476: truelight@9476: /* If there are 255 buildings of this type in this town, there are also truelight@9476: * at least that many houses of the same class in the town, and truelight@9476: * therefore on the map as well. */ truelight@9476: if (t->building_counts.id_count[house_id] == 255) return; truelight@9476: truelight@9476: t->building_counts.id_count[house_id]++; truelight@9476: if (_building_counts.id_count[house_id] < 255) _building_counts.id_count[house_id]++; truelight@9476: truelight@9476: /* Similarly, if there are 255 houses of this class in this town, there truelight@9476: * must be at least that number on the map too. */ truelight@9476: if (class_id == HOUSE_NO_CLASS || t->building_counts.class_count[class_id] == 255) return; truelight@9476: truelight@9476: t->building_counts.class_count[class_id]++; truelight@9476: if (_building_counts.class_count[class_id] < 255) _building_counts.class_count[class_id]++; truelight@9476: } truelight@9476: truelight@9476: /** truelight@9476: * DecreaseBuildingCount() truelight@9476: * Decrease the number of a building when it is deleted. truelight@9476: * @param t The town that the building was built in truelight@9476: * @param house_id The id of the house being removed truelight@9476: */ truelight@9476: void DecreaseBuildingCount(Town *t, HouseID house_id) truelight@9476: { truelight@9476: HouseClassID class_id = GetHouseSpecs(house_id)->class_id; truelight@9476: rubidium@9628: if (!_loaded_newgrf_features.has_newhouses) return; truelight@9476: truelight@9476: if (t->building_counts.id_count[house_id] > 0) t->building_counts.id_count[house_id]--; truelight@9476: if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--; truelight@9476: truelight@9476: if (class_id == HOUSE_NO_CLASS) return; truelight@9476: truelight@9476: if (t->building_counts.class_count[class_id] > 0) t->building_counts.class_count[class_id]--; truelight@9476: if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--; truelight@9476: } truelight@9476: truelight@9476: /** truelight@9476: * AfterLoadCountBuildings() truelight@9476: * truelight@9476: * After a savegame has been loaded, count the number of buildings on the map. truelight@9476: */ truelight@9476: void AfterLoadCountBuildings() truelight@9476: { rubidium@9628: if (!_loaded_newgrf_features.has_newhouses) return; truelight@9476: truelight@9476: for (TileIndex t = 0; t < MapSize(); t++) { truelight@9476: if (!IsTileType(t, MP_HOUSE)) continue; truelight@9476: IncreaseBuildingCount(GetTownByTile(t), GetHouseType(t)); truelight@9476: } truelight@9476: } truelight@9476: truelight@9476: truelight@9476: static uint32 HouseGetRandomBits(const ResolverObject *object) truelight@9476: { truelight@9476: const TileIndex tile = object->u.house.tile; truelight@9476: return (tile == INVALID_TILE || !IsTileType(tile, MP_HOUSE)) ? 0 : GetHouseRandomBits(tile); truelight@9476: } truelight@9476: truelight@9476: static uint32 HouseGetTriggers(const ResolverObject *object) truelight@9476: { truelight@9476: const TileIndex tile = object->u.house.tile; truelight@9476: return (tile == INVALID_TILE || !IsTileType(tile, MP_HOUSE)) ? 0 : GetHouseTriggers(tile); truelight@9476: } truelight@9476: truelight@9476: static void HouseSetTriggers(const ResolverObject *object, int triggers) truelight@9476: { truelight@9476: const TileIndex tile = object->u.house.tile; truelight@9476: if (IsTileType(tile, MP_HOUSE)) SetHouseTriggers(tile, triggers); truelight@9476: } truelight@9476: truelight@9476: static uint32 GetNumHouses(HouseID house_id, const Town *town) truelight@9476: { truelight@9476: uint8 map_id_count, town_id_count, map_class_count, town_class_count; truelight@9476: HouseClassID class_id = GetHouseSpecs(house_id)->class_id; truelight@9476: truelight@9476: map_id_count = _building_counts.id_count[house_id]; truelight@9476: map_class_count = _building_counts.class_count[class_id]; truelight@9476: town_id_count = town->building_counts.id_count[house_id]; truelight@9476: town_class_count = town->building_counts.class_count[class_id]; truelight@9476: truelight@9476: return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count; truelight@9476: } truelight@9476: truelight@9476: static uint32 GetGRFParameter(HouseID house_id, byte parameter) truelight@9476: { truelight@9476: const HouseSpec *hs = GetHouseSpecs(house_id); truelight@9476: const GRFFile *file = hs->grffile; truelight@9476: truelight@9476: if (parameter >= file->param_end) return 0; truelight@9476: return file->param[parameter]; truelight@9476: } truelight@9476: glx@9626: uint32 GetNearbyTileInformation(byte parameter, TileIndex tile) glx@9626: { glx@9626: uint32 tile_type; glx@9626: glx@9626: tile = GetNearbyTile(parameter, tile); glx@9626: tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1; glx@9626: rubidium@9703: uint z; rubidium@9703: Slope tileh = GetTileSlope(tile, &z); rubidium@9703: return GetTileType(tile) << 24 | z << 16 | tile_type << 8 | tileh; glx@9626: } glx@9626: truelight@9476: /** truelight@9476: * HouseGetVariable(): truelight@9476: * truelight@9476: * Used by the resolver to get values for feature 07 deterministic spritegroups. truelight@9476: */ truelight@9476: static uint32 HouseGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) truelight@9476: { truelight@9476: const Town *town = object->u.house.town; truelight@9476: TileIndex tile = object->u.house.tile; truelight@9476: HouseID house_id = object->u.house.house_id; truelight@9476: truelight@9476: if (object->scope == VSG_SCOPE_PARENT) { truelight@9476: return TownGetVariable(variable, parameter, available, town); truelight@9476: } truelight@9476: truelight@9476: switch (variable) { truelight@9476: /* Construction stage. */ truelight@9476: case 0x40: return (IsTileType(tile, MP_HOUSE) ? GetHouseBuildingStage(tile) : 0) | OriginalTileRandomiser(TileX(tile), TileY(tile)) << 2; truelight@9476: truelight@9476: /* Building age. */ truelight@9476: case 0x41: return clamp(_cur_year - GetHouseConstructionYear(tile), 0, 0xFF); truelight@9476: truelight@9476: /* Town zone */ truelight@9476: case 0x42: return GetTownRadiusGroup(town, tile); truelight@9476: truelight@9476: /* Terrain type */ truelight@9476: case 0x43: return GetTerrainType(tile); truelight@9476: truelight@9476: /* Number of this type of building on the map. */ truelight@9476: case 0x44: return GetNumHouses(house_id, town); truelight@9476: truelight@9476: /* Whether the town is being created or just expanded. */ truelight@9476: case 0x45: return _generating_world ? 1 : 0; truelight@9476: truelight@9476: /* Current animation frame. */ truelight@9476: case 0x46: return IsTileType(tile, MP_HOUSE) ? GetHouseAnimationFrame(tile) : 0; truelight@9476: truelight@9476: truelight@9476: /* Building counts for old houses with id = parameter. */ truelight@9476: case 0x60: return GetNumHouses(parameter, town); truelight@9476: truelight@9476: /* Building counts for new houses with id = parameter. */ truelight@9476: case 0x61: { truelight@9476: const HouseSpec *hs = GetHouseSpecs(house_id); truelight@9476: if (hs->grffile == NULL) return 0; truelight@9476: glx@9624: HouseID new_house = _house_mngr.GetID(parameter, hs->grffile->grfid); truelight@9476: return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, town); truelight@9476: } truelight@9476: truelight@9476: /* Land info for nearby tiles. */ glx@9626: case 0x62: return GetNearbyTileInformation(parameter, tile); truelight@9476: truelight@9476: /* Read GRF parameter */ truelight@9476: case 0x7F: return GetGRFParameter(object->u.house.house_id, parameter); truelight@9476: } truelight@9476: truelight@9476: DEBUG(grf, 1, "Unhandled house property 0x%X", variable); truelight@9476: truelight@9476: *available = false; truelight@9476: return UINT_MAX; truelight@9476: } truelight@9476: truelight@9476: static const SpriteGroup *HouseResolveReal(const ResolverObject *object, const SpriteGroup *group) truelight@9476: { truelight@9476: /* Houses do not have 'real' groups */ truelight@9476: return NULL; truelight@9476: } truelight@9476: truelight@9476: /** truelight@9476: * NewHouseResolver(): truelight@9476: * truelight@9476: * Returns a resolver object to be used with feature 07 spritegroups. truelight@9476: */ truelight@9476: static void NewHouseResolver(ResolverObject *res, HouseID house_id, TileIndex tile, Town *town) truelight@9476: { truelight@9476: res->GetRandomBits = HouseGetRandomBits; truelight@9476: res->GetTriggers = HouseGetTriggers; truelight@9476: res->SetTriggers = HouseSetTriggers; truelight@9476: res->GetVariable = HouseGetVariable; truelight@9476: res->ResolveReal = HouseResolveReal; truelight@9476: truelight@9476: res->u.house.tile = tile; truelight@9476: res->u.house.town = town; truelight@9476: res->u.house.house_id = house_id; truelight@9476: rubidium@9694: res->callback = CBID_NO_CALLBACK; truelight@9476: res->callback_param1 = 0; truelight@9476: res->callback_param2 = 0; truelight@9476: res->last_value = 0; truelight@9476: res->trigger = 0; truelight@9476: res->reseed = 0; truelight@9476: } truelight@9476: rubidium@9694: uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile) truelight@9476: { truelight@9476: ResolverObject object; truelight@9476: const SpriteGroup *group; truelight@9476: truelight@9476: NewHouseResolver(&object, house_id, tile, town); truelight@9476: object.callback = callback; truelight@9476: object.callback_param1 = param1; glx@9624: object.callback_param2 = param2; truelight@9476: truelight@9476: group = Resolve(GetHouseSpecs(house_id)->spritegroup, &object); truelight@9476: if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; truelight@9476: truelight@9476: return group->g.callback.result; truelight@9476: } truelight@9476: truelight@9476: void DrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte stage, HouseID house_id) truelight@9476: { truelight@9476: const DrawTileSprites *dts = group->g.layout.dts; truelight@9476: const DrawTileSeqStruct *dtss; truelight@9476: truelight@9476: SpriteID image = dts->ground_sprite; truelight@9476: SpriteID pal = dts->ground_pal; truelight@9476: glx@9704: if (IS_CUSTOM_SPRITE(image)) image += stage; glx@9704: truelight@9476: if (GB(image, 0, SPRITE_WIDTH) != 0) DrawGroundSprite(image, pal); truelight@9476: truelight@9476: foreach_draw_tile_seq(dtss, dts->seq) { truelight@9476: if (GB(dtss->image, 0, SPRITE_WIDTH) == 0) continue; truelight@9476: glx@9704: image = dtss->image; truelight@9476: pal = dtss->pal; truelight@9476: glx@9704: if (IS_CUSTOM_SPRITE(image)) image += stage; glx@9704: rubidium@9694: if ((HASBIT(image, SPRITE_MODIFIER_OPAQUE) || !HASBIT(_transparent_opt, TO_HOUSES)) && HASBIT(image, PALETTE_MODIFIER_COLOR)) { truelight@9476: if (pal == 0) { truelight@9476: const HouseSpec *hs = GetHouseSpecs(house_id); glx@9704: if (HASBIT(hs->callback_mask, CBM_HOUSE_COLOUR)) { glx@9704: uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, GetTownByTile(ti->tile), ti->tile); truelight@9476: if (callback != CALLBACK_FAILED) { truelight@9476: /* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */ truelight@9476: pal = HASBIT(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback; truelight@9476: } truelight@9476: } else { truelight@9476: pal = hs->random_colour[OriginalTileRandomiser(ti->x, ti->y)] + PALETTE_RECOLOR_START; truelight@9476: } truelight@9476: } truelight@9476: } else { truelight@9476: pal = PAL_NONE; truelight@9476: } truelight@9476: truelight@9476: if ((byte)dtss->delta_z != 0x80) { truelight@9476: AddSortableSpriteToDraw( truelight@9476: image, pal, truelight@9476: ti->x + dtss->delta_x, ti->y + dtss->delta_y, truelight@9476: dtss->size_x, dtss->size_y, rubidium@9694: dtss->size_z, ti->z + dtss->delta_z, rubidium@9694: HASBIT(_transparent_opt, TO_HOUSES) truelight@9476: ); truelight@9476: } else { glx@9704: AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, HASBIT(_transparent_opt, TO_HOUSES)); truelight@9476: } truelight@9476: } truelight@9476: } truelight@9476: truelight@9476: void DrawNewHouseTile(TileInfo *ti, HouseID house_id) truelight@9476: { truelight@9476: const HouseSpec *hs = GetHouseSpecs(house_id); truelight@9476: const SpriteGroup *group; truelight@9476: ResolverObject object; truelight@9476: rubidium@9694: if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); truelight@9476: truelight@9476: NewHouseResolver(&object, house_id, ti->tile, GetTownByTile(ti->tile)); truelight@9476: truelight@9476: group = Resolve(hs->spritegroup, &object); truelight@9476: if (group == NULL || group->type != SGT_TILELAYOUT) { truelight@9476: /* XXX: This is for debugging purposes really, and shouldn't stay. */ truelight@9476: DrawGroundSprite(SPR_SHADOW_CELL, PAL_NONE); truelight@9476: } else { truelight@9476: /* Limit the building stage to the number of stages supplied. */ truelight@9476: byte stage = GetHouseBuildingStage(ti->tile); truelight@9476: stage = clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1); truelight@9476: DrawTileLayout(ti, group, stage, house_id); truelight@9476: } truelight@9476: } truelight@9476: truelight@9476: void AnimateNewHouseTile(TileIndex tile) truelight@9476: { truelight@9476: const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); truelight@9476: byte animation_speed = hs->animation_speed; truelight@9476: bool frame_set_by_callback = false; truelight@9476: glx@9704: if (HASBIT(hs->callback_mask, CBM_HOUSE_ANIMATION_SPEED)) { glx@9624: uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_SPEED, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); truelight@9476: if (callback_res != CALLBACK_FAILED) animation_speed = clamp(callback_res & 0xFF, 2, 16); truelight@9476: } truelight@9476: truelight@9476: /* An animation speed of 2 means the animation frame changes 4 ticks, and truelight@9476: * increasing this value by one doubles the wait. 2 is the minimum value truelight@9476: * allowed for animation_speed, which corresponds to 120ms, and 16 is the truelight@9476: * maximum, corresponding to around 33 minutes. */ truelight@9476: if (_tick_counter % (1 << animation_speed) != 0) return; truelight@9476: truelight@9476: byte frame = GetHouseAnimationFrame(tile); truelight@9476: byte num_frames = GB(hs->animation_frames, 0, 7); truelight@9476: glx@9704: if (HASBIT(hs->callback_mask, CBM_HOUSE_ANIMATION_NEXT_FRAME)) { truelight@9476: uint32 param = (hs->extra_flags & CALLBACK_1A_RANDOM_BITS) ? Random() : 0; glx@9624: uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_NEXT_FRAME, param, 0, GetHouseType(tile), GetTownByTile(tile), tile); truelight@9476: truelight@9476: if (callback_res != CALLBACK_FAILED) { truelight@9476: frame_set_by_callback = true; truelight@9476: truelight@9476: switch (callback_res & 0xFF) { truelight@9476: case 0xFF: truelight@9476: DeleteAnimatedTile(tile); truelight@9476: break; truelight@9476: case 0xFE: truelight@9476: /* Carry on as normal. */ truelight@9476: frame_set_by_callback = false; truelight@9476: break; truelight@9476: default: truelight@9476: frame = callback_res & 0xFF; truelight@9476: break; truelight@9476: } truelight@9476: truelight@9476: /* If the lower 7 bits of the upper byte of the callback truelight@9476: * result are not empty, it is a sound effect. */ truelight@9476: if (GB(callback_res, 8, 7) != 0) PlayHouseSound(GB(callback_res, 8, 7), tile); truelight@9476: } truelight@9476: } truelight@9476: truelight@9476: if (!frame_set_by_callback) { truelight@9476: if (frame < num_frames) { truelight@9476: frame++; truelight@9476: } else if (frame == num_frames && HASBIT(hs->animation_frames, 7)) { truelight@9476: /* This animation loops, so start again from the beginning */ truelight@9476: frame = 0; truelight@9476: } else { truelight@9476: /* This animation doesn't loop, so stay here */ truelight@9476: DeleteAnimatedTile(tile); truelight@9476: } truelight@9476: } truelight@9476: truelight@9476: SetHouseAnimationFrame(tile, frame); truelight@9476: MarkTileDirtyByTile(tile); truelight@9476: } truelight@9476: truelight@9476: void ChangeHouseAnimationFrame(TileIndex tile, uint16 callback_result) truelight@9476: { truelight@9476: switch (callback_result & 0xFF) { truelight@9476: case 0xFD: /* Do nothing. */ break; truelight@9476: case 0xFE: AddAnimatedTile(tile); break; truelight@9476: case 0xFF: DeleteAnimatedTile(tile); break; truelight@9476: default: truelight@9476: SetHouseAnimationFrame(tile, callback_result & 0xFF); truelight@9476: AddAnimatedTile(tile); truelight@9476: break; truelight@9476: } truelight@9476: /* If the lower 7 bits of the upper byte of the callback truelight@9476: * result are not empty, it is a sound effect. */ truelight@9476: if (GB(callback_result, 8, 7) != 0) PlayHouseSound(GB(callback_result, 8, 7), tile); truelight@9476: } truelight@9476: truelight@9476: bool CanDeleteHouse(TileIndex tile) truelight@9476: { truelight@9476: const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); truelight@9476: truelight@9476: /* Human players are always allowed to remove buildings, as is water and truelight@9476: * anyone using the scenario editor. */ truelight@9476: if ((IsValidPlayer(_current_player) && IsHumanPlayer(_current_player)) truelight@9476: || _current_player == OWNER_WATER || _current_player == OWNER_NONE) return true; truelight@9476: truelight@9476: if (HASBIT(hs->callback_mask, CBM_HOUSE_DENY_DESTRUCTION)) { glx@9624: uint16 callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); truelight@9476: return (callback_res == CALLBACK_FAILED || callback_res == 0); truelight@9476: } else { truelight@9476: return !(hs->extra_flags & BUILDING_IS_PROTECTED); truelight@9476: } truelight@9476: } truelight@9476: truelight@9476: static void AnimationControl(TileIndex tile, uint16 random_bits) truelight@9476: { truelight@9476: const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); truelight@9476: glx@9704: if (HASBIT(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) { truelight@9476: uint32 param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random(); glx@9624: uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_START_STOP, param, 0, GetHouseType(tile), GetTownByTile(tile), tile); truelight@9476: truelight@9476: if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(tile, callback_res); truelight@9476: } truelight@9476: } truelight@9476: truelight@9476: bool NewHouseTileLoop(TileIndex tile) truelight@9476: { truelight@9476: const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); truelight@9476: truelight@9476: if (GetHouseProcessingTime(tile) > 0) { truelight@9476: DecHouseProcessingTime(tile); truelight@9476: return true; truelight@9476: } truelight@9476: glx@9624: /* @todo: Magic with triggers goes here. Got to implement that, one day. .. glx@9624: * Process randomizing of tiles following specs. glx@9624: * Once done, redraw the house glx@9624: * MarkTileDirtyByTile(tile); glx@9624: */ truelight@9476: glx@9704: if (HASBIT(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) { truelight@9476: /* If this house is marked as having a synchronised callback, all the truelight@9476: * tiles will have the callback called at once, rather than when the truelight@9476: * tile loop reaches them. This should only be enabled for the northern truelight@9476: * tile, or strange things will happen (here, and in TTDPatch). */ truelight@9476: if (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) { truelight@9476: uint16 random = GB(Random(), 0, 16); truelight@9476: truelight@9476: if (hs->building_flags & BUILDING_HAS_1_TILE) AnimationControl(tile, random); truelight@9476: if (hs->building_flags & BUILDING_2_TILES_Y) AnimationControl(TILE_ADDXY(tile, 0, 1), random); truelight@9476: if (hs->building_flags & BUILDING_2_TILES_X) AnimationControl(TILE_ADDXY(tile, 1, 0), random); truelight@9476: if (hs->building_flags & BUILDING_HAS_4_TILES) AnimationControl(TILE_ADDXY(tile, 1, 1), random); truelight@9476: } else { truelight@9476: AnimationControl(tile, 0); truelight@9476: } truelight@9476: } truelight@9476: truelight@9476: /* Check callback 21, which determines if a house should be destroyed. */ truelight@9476: if (HASBIT(hs->callback_mask, CBM_HOUSE_DESTRUCTION)) { glx@9624: uint16 callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); truelight@9476: if (callback_res != CALLBACK_FAILED && callback_res > 0) { truelight@9476: ClearTownHouse(GetTownByTile(tile), tile); truelight@9476: return false; truelight@9476: } truelight@9476: } truelight@9476: truelight@9476: SetHouseProcessingTime(tile, hs->processing_time); truelight@9476: return true; truelight@9476: }