* Perform a circular search around the Lumber Mill in order to find trees to cut * @param i industry */
| 1111 | * @param i industry |
| 1112 | */ |
| 1113 | static 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. |
no test coverage detected