* Generate cargo for a house using the binomial algorithm. * @param t The current town. * @param tpe The town production effect. * @param rate The town's product rate for this production. * @param stations Available stations for this house. */
| 577 | * @param stations Available stations for this house. |
| 578 | */ |
| 579 | static void TownGenerateCargoBinomial(Town *t, TownProductionEffect tpe, uint8_t rate, StationFinder &stations) |
| 580 | { |
| 581 | for (const CargoSpec *cs : CargoSpec::town_production_cargoes[tpe]) { |
| 582 | CargoType cargo_type = cs->Index(); |
| 583 | uint32_t r = Random(); |
| 584 | |
| 585 | /* Make a bitmask with up to 32 bits set, one for each potential pax. */ |
| 586 | int genmax = (rate + 7) / 8; |
| 587 | uint32_t genmask = (genmax >= 32) ? 0xFFFFFFFF : ((1 << genmax) - 1); |
| 588 | |
| 589 | /* Mask random value by potential pax and count number of actual pax. */ |
| 590 | uint amt = CountBits(r & genmask) * cs->town_production_multiplier / TOWN_PRODUCTION_DIVISOR; |
| 591 | |
| 592 | TownGenerateCargo(t, cargo_type, amt, stations, true); |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * Tile callback function. |
no test coverage detected