| 410 | } |
| 411 | |
| 412 | static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted) |
| 413 | { |
| 414 | IndustryGfx gfx = GetIndustryGfx(tile); |
| 415 | const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); |
| 416 | const Industry *ind = Industry::GetByTile(tile); |
| 417 | |
| 418 | /* Starting point for acceptance */ |
| 419 | auto accepts_cargo = itspec->accepts_cargo; |
| 420 | auto cargo_acceptance = itspec->acceptance; |
| 421 | |
| 422 | if (itspec->special_flags.Test(IndustryTileSpecialFlag::AcceptsAllCargo)) { |
| 423 | /* Copy all accepted cargoes from industry itself */ |
| 424 | for (const auto &a : ind->accepted) { |
| 425 | auto pos = std::ranges::find(accepts_cargo, a.cargo); |
| 426 | if (pos == std::end(accepts_cargo)) { |
| 427 | /* Not found, insert */ |
| 428 | pos = std::ranges::find(accepts_cargo, INVALID_CARGO); |
| 429 | if (pos == std::end(accepts_cargo)) continue; // nowhere to place, give up on this one |
| 430 | *pos = a.cargo; |
| 431 | } |
| 432 | cargo_acceptance[std::distance(std::begin(accepts_cargo), pos)] += 8; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if (itspec->callback_mask.Test(IndustryTileCallbackMask::AcceptCargo)) { |
| 437 | /* Try callback for accepts list, if success override all existing accepts */ |
| 438 | uint16_t res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, Industry::GetByTile(tile), tile); |
| 439 | if (res != CALLBACK_FAILED) { |
| 440 | accepts_cargo.fill(INVALID_CARGO); |
| 441 | for (uint i = 0; i < INDUSTRY_ORIGINAL_NUM_INPUTS; i++) accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | if (itspec->callback_mask.Test(IndustryTileCallbackMask::CargoAcceptance)) { |
| 446 | /* Try callback for acceptance list, if success override all existing acceptance */ |
| 447 | uint16_t res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, Industry::GetByTile(tile), tile); |
| 448 | if (res != CALLBACK_FAILED) { |
| 449 | cargo_acceptance.fill(0); |
| 450 | for (uint i = 0; i < INDUSTRY_ORIGINAL_NUM_INPUTS; i++) cargo_acceptance[i] = GB(res, i * 4, 4); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | for (size_t i = 0; i < std::size(itspec->accepts_cargo); i++) { |
| 455 | CargoType cargo = accepts_cargo[i]; |
| 456 | if (!IsValidCargoType(cargo) || cargo_acceptance[i] <= 0) continue; // work only with valid cargoes |
| 457 | |
| 458 | /* Add accepted cargo */ |
| 459 | acceptance[cargo] += cargo_acceptance[i]; |
| 460 | |
| 461 | /* Maybe set 'always accepted' bit (if it's not set already) */ |
| 462 | if (HasBit(always_accepted, cargo)) continue; |
| 463 | |
| 464 | /* Test whether the industry itself accepts the cargo type */ |
| 465 | if (ind->IsCargoAccepted(cargo)) continue; |
| 466 | |
| 467 | /* If the industry itself doesn't accept this cargo, set 'always accepted' bit */ |
| 468 | SetBit(always_accepted, cargo); |
| 469 | } |
nothing calls this directly
no test coverage detected