Skip to content

Commit

Permalink
Fix #295: Adjust version_openttd for OpenTTD >= 12.0. (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
frosch123 authored Jun 27, 2023
1 parent cc7aa4a commit 518b83e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
26 changes: 20 additions & 6 deletions nml/expression/functioncall.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,31 @@ def builtin_getbits(name, args, pos):
@builtin
def builtin_version_openttd(name, args, pos):
"""
version_openttd(major, minor, revision[, build]) builtin function.
version_openttd(major, minor[, revision[, build]]) builtin function.
For OpenTTD >= 12.0 only 2 parameters may be passed.
For OpenTTD < 12.0 3 to 4 parameters may be passed.
@return The version information encoded in a double-word.
"""
if len(args) > 4 or len(args) < 3:
raise generic.ScriptError(name + "() must have 3 or 4 parameters", pos)
if len(args) < 2:
raise generic.ScriptError(name + "() must have at least 2 parameters", pos)

major = args[0].reduce_constant().value
minor = args[1].reduce_constant().value
revision = args[2].reduce_constant().value
build = args[3].reduce_constant().value if len(args) == 4 else 0x80000
return ConstantNumeric((major << 28) | (minor << 24) | (revision << 20) | build)

if major >= 12:
if len(args) != 2:
raise generic.ScriptError(name + "() must have at exactly 2 parameters for OpenTTD >= 12.0", pos)

return ConstantNumeric(((16 + major) << 24) | (minor << 20))
else:
if len(args) > 4:
raise generic.ScriptError(name + "() must have at most 4 parameters", pos)

revision = args[2].reduce_constant().value if len(args) >= 3 else 0
build = args[3].reduce_constant().value if len(args) >= 4 else 0x80000
return ConstantNumeric((major << 28) | (minor << 24) | (revision << 20) | build)


@builtins("cargotype_available", "railtype_available", "roadtype_available", "tramtype_available")
Expand Down
12 changes: 12 additions & 0 deletions regression/005_error.nml
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
// Regression test for error(..) statements (ActionB)
error(NOTICE, USED_WITH, string(STR_REGRESSION_CARE));
error(FATAL, string(STR_REGRESSION_ERROR), string(STR_ANSWER), 14, param[1] + 12 * param[2]);

if (version_openttd(1,11,0) > openttd_version) {
error(FATAL, REQUIRES_OPENTTD, string(STR_REGRESSION_ERROR));
}

if (version_openttd(12,0) > openttd_version) {
error(FATAL, REQUIRES_OPENTTD, string(STR_REGRESSION_ERROR));
}

if (version_openttd(16,0) > openttd_version) {
error(FATAL, REQUIRES_OPENTTD, string(STR_REGRESSION_ERROR));
}
Binary file modified regression/expected/005_error.grf
Binary file not shown.
45 changes: 45 additions & 0 deletions regression/expected/005_error.nfo
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,48 @@

6 * 42 0B 03 7F FF "Something bad (tm) has happened." 00 "42" 00 7F 7E

// param[126] = param[161]
7 * 5 0D 7E \D= A1 00

// param[127] = (param[126] - 453509120)
8 * 9 0D 7F \D- 7E FF \dx1B080000

// param[127] = (param[127] << -31)
9 * 9 0D 7F \Du<< 7F FF \dxFFFFFFE1

10 * 9 09 7F 04 \7= \dx00000000 02

11 * 61 0B 03 1F 06 "De wissels zijn bevroren, onze excuses voor het ongemak." 00

12 * 37 0B 03 7F 06 "Something bad (tm) has happened." 00

// param[126] = param[161]
13 * 5 0D 7E \D= A1 00

// param[127] = (param[126] - 469762048)
14 * 9 0D 7F \D- 7E FF \dx1C000000

// param[127] = (param[127] << -31)
15 * 9 0D 7F \Du<< 7F FF \dxFFFFFFE1

16 * 9 09 7F 04 \7= \dx00000000 02

17 * 61 0B 03 1F 06 "De wissels zijn bevroren, onze excuses voor het ongemak." 00

18 * 37 0B 03 7F 06 "Something bad (tm) has happened." 00

// param[126] = param[161]
19 * 5 0D 7E \D= A1 00

// param[127] = (param[126] - 536870912)
20 * 9 0D 7F \D- 7E FF \dx20000000

// param[127] = (param[127] << -31)
21 * 9 0D 7F \Du<< 7F FF \dxFFFFFFE1

22 * 9 09 7F 04 \7= \dx00000000 02

23 * 61 0B 03 1F 06 "De wissels zijn bevroren, onze excuses voor het ongemak." 00

24 * 37 0B 03 7F 06 "Something bad (tm) has happened." 00

0 comments on commit 518b83e

Please sign in to comment.