MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / TownGenerateCargo

Function TownGenerateCargo

src/town_cmd.cpp:533–550  ·  view source on GitHub ↗

* 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? */

Source from the content-addressed store, hash-verified

531 * @param affected_by_recession Is this cargo halved during recessions?
532 */
533static 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.

Callers 3

TileLoop_TownFunction · 0.85

Calls 3

EconomyIsInRecessionFunction · 0.85
ScaleByCargoScaleFunction · 0.85
MoveGoodsToStationFunction · 0.85

Tested by

no test coverage detected