Skip to content

Commit c84aebc

Browse files
committed
fix something
1 parent da3e91d commit c84aebc

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

core/src/com/unciv/models/ruleset/unique/Countables.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ object Countables {
9191

9292
private fun parseExpression(expression: String): List<String> {
9393
val regex = Regex(
94-
"(?:^|(?<=]))\\s*(\\[[^\\[\\]]*(?:\\[[^\\[\\]]*][^\\[\\]]*)*])|([+\\-*/%^()])|(\\d+)"
94+
"(\\[[^\\[\\]]*(?:\\[[^\\[\\]]*][^\\[\\]]*)*])|([+\\-*/%^()])|(\\d+)"
9595
)
9696
val matches = regex.findAll(expression)
9797
val tokens = mutableListOf<String>()
@@ -104,8 +104,10 @@ object Countables {
104104
tokens.add(token)
105105
}
106106
}
107+
println("tokens: $tokens")
107108
return tokens
108109
}
110+
109111
private fun calculateExpression(tokens: List<String>, stateForConditionals: StateForConditionals): Int? {
110112
val outputQueue = mutableListOf<String>()
111113
val operatorStack = mutableListOf<String>()
@@ -115,8 +117,7 @@ object Countables {
115117
outputQueue.add(token)
116118
} else if (token.startsWith("[") && token.endsWith("]")) {
117119
val innerToken = token.substring(1, token.length - 1)
118-
val value = simpleCountableAmount(innerToken, stateForConditionals)
119-
if (value == null) return null
120+
val value = simpleCountableAmount(innerToken, stateForConditionals) ?: return null
120121
outputQueue.add(value.toString())
121122
} else if (token == "(") {
122123
operatorStack.add(token)

docs/Modders/Unique-parameters.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,12 @@ This can make a difference for e.g. local resources, which are counted per city.
356356
Allowed *complex* values:
357357
- `[complex value]`
358358
- `[complex value] + [complex value]` - such as `[Cities] + 1`
359-
- `[complex value] - [complex value]` - such as `[Cities] - 1`
360-
- `[complex value] * [complex value]` - such as `[Cities] * 2`
361-
- `[complex value] / [complex value]` - such as `[Cities] / 2`
362-
- `[complex value] % [complex value]` - such as `[Cities] % 2`
363-
- `[complex value] ^ [complex value]` - such as `[Cities] ^ 2`
359+
- `[complex value] - [complex value]`
360+
- `[complex value] * [complex value]`
361+
- `[complex value] / [complex value]`
362+
- `[complex value] % [complex value]`
363+
- `[complex value] ^ [complex value]`
364364

365-
In addition, complex nested expressions can also be used, such as: `([Cities] + [turns]) * 2 + [Units]`. Note that the precedence of the five operations follows mathematical intuition: exponentiation has the highest precedence, followed by multiplication, division, and modulus, and then addition and subtraction have the lowest precedence. If you need to adjust the precedence, please use parentheses.
365+
In addition, complex nested expressions can also be used, such as: `([Cities] + [turns]) * 2 + [Units]`. Note that the precedence of the 6 operations follows mathematical intuition: exponentiation(`^`) has the highest precedence, followed by multiplication(`*`), division(`/`), and modulus(`%`), and then addition(`+`) and subtraction(`-`) have the lowest precedence. If you need to adjust the precedence, please use parentheses.
366366

367-
Specifically, when calculating n/0 or n%0 , although these operations are meaningless, we still compute them as 0.
367+
Specifically, when calculating `n/0` or `n%0` , although these operations are meaningless, we still compute them as `0`.

0 commit comments

Comments
 (0)