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

Function ChopLumberMillTrees

src/industry_cmd.cpp:1113–1141  ·  view source on GitHub ↗

* Perform a circular search around the Lumber Mill in order to find trees to cut * @param i industry */

Source from the content-addressed store, hash-verified

1111 * @param i industry
1112 */
1113static void ChopLumberMillTrees(Industry *i)
1114{
1115 /* Don't process lumber mill if cargo is not set up correctly. */
1116 auto itp = std::begin(i->produced);
1117 if (itp == std::end(i->produced) || !IsValidCargoType(itp->cargo)) return;
1118
1119 /* We only want to cut trees if all tiles are completed. */
1120 for (TileIndex tile_cur : i->location) {
1121 if (i->TileBelongsToIndustry(tile_cur)) {
1122 if (!IsIndustryCompleted(tile_cur)) return;
1123 }
1124 }
1125
1126 for (auto tile : SpiralTileSequence(i->location.tile, 40)) { // 40x40 tiles to search.
1127 if (!IsTileType(tile, MP_TREES) || GetTreeGrowth(tile) < TreeGrowthStage::Grown) continue;
1128
1129 /* found a tree */
1130 _industry_sound_ctr = 1;
1131 _industry_sound_tile = tile;
1132 if (_settings_client.sound.ambient) SndPlayTileFx(SND_38_LUMBER_MILL_1, tile);
1133
1134 AutoRestoreBackup<CompanyID> cur_company(_current_company, OWNER_NONE);
1135 Command<CMD_LANDSCAPE_CLEAR>::Do(DoCommandFlag::Execute, tile);
1136
1137 /* Add according value to waiting cargo. */
1138 itp->waiting = ClampTo<uint16_t>(itp->waiting + ScaleByCargoScale(45, false));
1139 break;
1140 }
1141}
1142
1143/**
1144 * Helper for ProduceIndustryGoods that scales and produces cargos.

Callers 1

ProduceIndustryGoodsFunction · 0.85

Calls 10

IsValidCargoTypeFunction · 0.85
IsIndustryCompletedFunction · 0.85
SpiralTileSequenceClass · 0.85
IsTileTypeFunction · 0.85
GetTreeGrowthFunction · 0.85
SndPlayTileFxFunction · 0.85
ScaleByCargoScaleFunction · 0.85
TileBelongsToIndustryMethod · 0.80
beginFunction · 0.50
endFunction · 0.50

Tested by

no test coverage detected