diff options
-rw-r--r-- | src/newgrf.cpp | 16 | ||||
-rw-r--r-- | src/newgrf.h | 2 | ||||
-rw-r--r-- | src/newgrf_spritegroup.cpp | 2 |
3 files changed, 14 insertions, 6 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp index e5fc2a1c1..b6461a6ce 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -5443,9 +5443,10 @@ void CheckForMissingSprites() * * @param param variable number (as for VarAction2, for Action7/9/D you have to subtract 0x80 first). * @param value returns the value of the variable. + * @param grffile NewGRF querying the variable * @return true iff the variable is known and the value is returned in 'value'. */ -bool GetGlobalVariable(byte param, uint32 *value) +bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile) { switch (param) { case 0x00: // current date @@ -5546,9 +5547,16 @@ bool GetGlobalVariable(byte param, uint32 *value) /* case 0x1F: // locale dependent settings not implemented to avoid desync */ - case 0x20: // snow line height - *value = _settings_game.game_creation.landscape == LT_ARCTIC ? GetSnowLine() * TILE_HEIGHT : 0xFF; + case 0x20: { // snow line height + byte snowline = GetSnowLine(); + if (_settings_game.game_creation.landscape == LT_ARCTIC && snowline <= MAX_TILE_HEIGHT) { + *value = Clamp(snowline * (grffile->grf_version >= 8 ? 1 : TILE_HEIGHT), 0, 0xFE); + } else { + /* No snow */ + *value = 0xFF; + } return true; + } case 0x21: // OpenTTD version *value = _openttd_newgrf_version; @@ -5574,7 +5582,7 @@ static uint32 GetParamVal(byte param, uint32 *cond_val) { /* First handle variable common with VarAction2 */ uint32 value; - if (GetGlobalVariable(param - 0x80, &value)) return value; + if (GetGlobalVariable(param - 0x80, &value, _cur.grffile)) return value; /* Non-common variable */ switch (param) { diff --git a/src/newgrf.h b/src/newgrf.h index 4ffd99aa8..bd6c673e8 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -174,7 +174,7 @@ void ResetPersistentNewGRFData(); void CDECL grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3); bool HasGrfMiscBit(GrfMiscBit bit); -bool GetGlobalVariable(byte param, uint32 *value); +bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile); StringID MapGRFStringID(uint32 grfid, StringID str); void ShowNewGRFError(); diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp index 2c89aa000..1ebf5bcf7 100644 --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -42,7 +42,7 @@ static inline uint32 GetVariable(const ResolverObject *object, byte variable, ui { /* First handle variables common with Action7/9/D */ uint32 value; - if (GetGlobalVariable(variable, &value)) return value; + if (GetGlobalVariable(variable, &value, object->grffile)) return value; /* Non-common variable */ switch (variable) { |