* Generate cargo for a house, scaled by the current economy scale. * @param t The current town. * @param ct Type of cargo to generate, usually CT_PASSENGERS or CT_MAIL. * @param amount The number of cargo units. * @param stations Available stations for this house. * @param affected_by_recession Is this cargo halved during recessions? */
| 531 | * @param affected_by_recession Is this cargo halved during recessions? |
| 532 | */ |
| 533 | static void TownGenerateCargo(Town *t, CargoType cargo, uint amount, StationFinder &stations, bool affected_by_recession) |
| 534 | { |
| 535 | if (amount == 0) return; |
| 536 | |
| 537 | /* All production is halved during a recession (except for NewGRF-supplied town cargo). */ |
| 538 | if (affected_by_recession && EconomyIsInRecession()) { |
| 539 | amount = (amount + 1) >> 1; |
| 540 | } |
| 541 | |
| 542 | /* Scale by cargo scale setting. */ |
| 543 | amount = ScaleByCargoScale(amount, true); |
| 544 | if (amount == 0) return; |
| 545 | |
| 546 | /* Actually generate cargo and update town statistics. */ |
| 547 | auto &supplied = t->GetOrCreateCargoSupplied(cargo); |
| 548 | supplied.history[THIS_MONTH].production += amount; |
| 549 | supplied.history[THIS_MONTH].transported += MoveGoodsToStation(cargo, amount, {t->index, SourceType::Town}, stations.GetStations());; |
| 550 | } |
| 551 | |
| 552 | /** |
| 553 | * Generate cargo for a house using the original algorithm. |
no test coverage detected