* Tries to create a passenger subsidy between two towns. * @return True iff the subsidy was created. */
| 234 | * @return True iff the subsidy was created. |
| 235 | */ |
| 236 | bool FindSubsidyPassengerRoute() |
| 237 | { |
| 238 | if (!Subsidy::CanAllocateItem()) return false; |
| 239 | |
| 240 | /* Pick a random TPE_PASSENGER type */ |
| 241 | uint32_t r = RandomRange(static_cast<uint>(CargoSpec::town_production_cargoes[TPE_PASSENGERS].size())); |
| 242 | CargoType cargo_type = CargoSpec::town_production_cargoes[TPE_PASSENGERS][r]->Index(); |
| 243 | |
| 244 | const Town *src = Town::GetRandom(); |
| 245 | if (src->cache.population < SUBSIDY_PAX_MIN_POPULATION || |
| 246 | src->GetPercentTransported(cargo_type) > SUBSIDY_MAX_PCT_TRANSPORTED) { |
| 247 | return false; |
| 248 | } |
| 249 | |
| 250 | const Town *dst = Town::GetRandom(); |
| 251 | if (dst->cache.population < SUBSIDY_PAX_MIN_POPULATION || src == dst) { |
| 252 | return false; |
| 253 | } |
| 254 | |
| 255 | if (DistanceManhattan(src->xy, dst->xy) > SUBSIDY_MAX_DISTANCE) return false; |
| 256 | if (CheckSubsidyDuplicate(cargo_type, {src->index, SourceType::Town}, {dst->index, SourceType::Town})) return false; |
| 257 | |
| 258 | CreateSubsidy(cargo_type, {src->index, SourceType::Town}, {dst->index, SourceType::Town}); |
| 259 | |
| 260 | return true; |
| 261 | } |
| 262 | |
| 263 | bool FindSubsidyCargoDestination(CargoType cargo_type, Source src); |
| 264 |
no test coverage detected