summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2007-10-06 00:23:30 +0000
committerbelugas <belugas@openttd.org>2007-10-06 00:23:30 +0000
commit6f7f7afba4733835ace6283a3ef1fced9042beb0 (patch)
treeb6b9024ae3866c7232fea3e069e2a748630890ed
parentdf9392a7372b5492a51b01569d88dee017ab66c2 (diff)
downloadopenttd-6f7f7afba4733835ace6283a3ef1fced9042beb0.tar.xz
(svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
-rw-r--r--src/newgrf_industries.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index 327891c2d..867bd7a44 100644
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -213,16 +213,20 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
/* player info */
case 0x45: {
- byte colour1, colour2; ///< Not initializing these two will give some kind of random
+ byte colours;
bool is_ai = false;
+
if (IsValidPlayer(industry->founder)) {
const Player *p = GetPlayer(industry->founder);
const Livery *l = &p->livery[LS_DEFAULT];
+
is_ai = p->is_ai;
- colour1 = l->colour1;
- colour2 = l->colour2;
+ colours = l->colour1 + l->colour2 * 16;
+ } else {
+ colours = GB(Random(), 0, 8);
}
- return industry->founder | (is_ai ? 0x10000 : 0) | ((colour1 + colour2 * 16) << 24);
+
+ return industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24);
}
/* Get industry ID at offset param */