summaryrefslogtreecommitdiff
path: root/economy.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2006-08-22 21:14:45 +0000
committertruelight <truelight@openttd.org>2006-08-22 21:14:45 +0000
commitceb523c29f364f24b5e6b68b13249187ff6ac371 (patch)
tree3b5390c9adf2806b379ecf5be65b211d1a2e8b4d /economy.c
parent3cdabcbbac5ae64c132f0162090079d8c5cf3f90 (diff)
downloadopenttd-ceb523c29f364f24b5e6b68b13249187ff6ac371.tar.xz
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
Diffstat (limited to 'economy.c')
-rw-r--r--economy.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/economy.c b/economy.c
index 19fa8952c..1abdda6d7 100644
--- a/economy.c
+++ b/economy.c
@@ -882,12 +882,11 @@ static void FindSubsidyPassengerRoute(FoundRoute *fr)
fr->distance = (uint)-1;
- fr->from = from = GetTown(RandomRange(GetTownArraySize()));
- if (!IsValidTown(from) || from->population < 400)
- return;
+ fr->from = from = GetRandomTown();
+ if (from == NULL || from->population < 400) return;
- fr->to = to = GetTown(RandomRange(GetTownArraySize()));
- if (from == to || !IsValidTown(to) || to->population < 400 || to->pct_pass_transported > 42)
+ fr->to = to = GetRandomTown();
+ if (from == to || to == NULL || to->population < 400 || to->pct_pass_transported > 42)
return;
fr->distance = DistanceManhattan(from->xy, to->xy);
@@ -901,8 +900,8 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
fr->distance = (uint)-1;
- fr->from = i = GetIndustry(RandomRange(GetIndustryArraySize()));
- if (!IsValidIndustry(i)) return;
+ fr->from = i = GetRandomIndustry();
+ if (i == NULL) return;
// Randomize cargo type
if (Random()&1 && i->produced_cargo[1] != CT_INVALID) {
@@ -925,19 +924,19 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
if (cargo == CT_GOODS || cargo == CT_FOOD) {
// The destination is a town
- Town *t = GetTown(RandomRange(GetTownArraySize()));
+ Town *t = GetRandomTown();
// Only want big towns
- if (!IsValidTown(t) || t->population < 900) return;
+ if (t == NULL || t->population < 900) return;
fr->distance = DistanceManhattan(i->xy, t->xy);
fr->to = t;
} else {
// The destination is an industry
- Industry *i2 = GetIndustry(RandomRange(GetIndustryArraySize()));
+ Industry *i2 = GetRandomIndustry();
// The industry must accept the cargo
- if (i == i2 || !IsValidIndustry(i2) ||
+ if (i == i2 || i == NULL ||
(cargo != i2->accepts_cargo[0] &&
cargo != i2->accepts_cargo[1] &&
cargo != i2->accepts_cargo[2]))