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

Function FindSubsidyPassengerRoute

src/subsidy.cpp:236–261  ·  view source on GitHub ↗

* Tries to create a passenger subsidy between two towns. * @return True iff the subsidy was created. */

Source from the content-addressed store, hash-verified

234 * @return True iff the subsidy was created.
235 */
236bool 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
263bool FindSubsidyCargoDestination(CargoType cargo_type, Source src);
264

Callers 1

subsidy.cppFile · 0.85

Calls 7

RandomRangeFunction · 0.85
DistanceManhattanFunction · 0.85
CheckSubsidyDuplicateFunction · 0.85
CreateSubsidyFunction · 0.85
GetPercentTransportedMethod · 0.80
sizeMethod · 0.45
IndexMethod · 0.45

Tested by

no test coverage detected