* Tile callback function. * * Tile callback function. Periodic tick handler for the tiles of a town. * @param tile been asked to do its stuff */
| 600 | * @param tile been asked to do its stuff |
| 601 | */ |
| 602 | static void TileLoop_Town(TileIndex tile) |
| 603 | { |
| 604 | HouseID house_id = GetHouseType(tile); |
| 605 | |
| 606 | /* NewHouseTileLoop returns false if Callback 21 succeeded, i.e. the house |
| 607 | * doesn't exist any more, so don't continue here. */ |
| 608 | if (house_id >= NEW_HOUSE_OFFSET && !NewHouseTileLoop(tile)) return; |
| 609 | |
| 610 | if (!IsHouseCompleted(tile)) { |
| 611 | /* Construction is not completed, so we advance a construction stage. */ |
| 612 | AdvanceHouseConstruction(tile); |
| 613 | return; |
| 614 | } |
| 615 | |
| 616 | const HouseSpec *hs = HouseSpec::Get(house_id); |
| 617 | |
| 618 | /* If the lift has a destination, it is already an animated tile. */ |
| 619 | if (hs->building_flags.Test(BuildingFlag::IsAnimated) && |
| 620 | house_id < NEW_HOUSE_OFFSET && |
| 621 | !LiftHasDestination(tile) && |
| 622 | Chance16(1, 2)) { |
| 623 | AddAnimatedTile(tile); |
| 624 | } |
| 625 | |
| 626 | Town *t = Town::GetByTile(tile); |
| 627 | uint32_t r = Random(); |
| 628 | |
| 629 | StationFinder stations(TileArea(tile, 1, 1)); |
| 630 | |
| 631 | if (hs->callback_mask.Test(HouseCallbackMask::ProduceCargo)) { |
| 632 | for (uint i = 0; i < 256; i++) { |
| 633 | uint16_t callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, r, house_id, t, tile); |
| 634 | |
| 635 | if (callback == CALLBACK_FAILED || callback == CALLBACK_HOUSEPRODCARGO_END) break; |
| 636 | |
| 637 | CargoType cargo = GetCargoTranslation(GB(callback, 8, 7), hs->grf_prop.grffile); |
| 638 | if (!IsValidCargoType(cargo)) continue; |
| 639 | |
| 640 | uint amt = GB(callback, 0, 8); |
| 641 | if (amt == 0) continue; |
| 642 | |
| 643 | /* NewGRF-supplied town cargos are not affected by recessions. */ |
| 644 | TownGenerateCargo(t, cargo, amt, stations, false); |
| 645 | } |
| 646 | } else { |
| 647 | switch (_settings_game.economy.town_cargogen_mode) { |
| 648 | case TCGM_ORIGINAL: |
| 649 | /* Original (quadratic) cargo generation algorithm */ |
| 650 | TownGenerateCargoOriginal(t, TPE_PASSENGERS, hs->population, stations); |
| 651 | TownGenerateCargoOriginal(t, TPE_MAIL, hs->mail_generation, stations); |
| 652 | break; |
| 653 | |
| 654 | case TCGM_BITCOUNT: |
| 655 | /* Binomial distribution per tick, by a series of coin flips */ |
| 656 | /* Reduce generation rate to a 1/4, using tile bits to spread out distribution. |
| 657 | * As tick counter is incremented by 256 between each call, we ignore the lower 8 bits. */ |
| 658 | if (GB(TimerGameTick::counter, 8, 2) == GB(tile.base(), 0, 2)) { |
| 659 | TownGenerateCargoBinomial(t, TPE_PASSENGERS, hs->population, stations); |
nothing calls this directly
no test coverage detected