summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-03-20 16:45:23 +0000
committeralberth <alberth@openttd.org>2010-03-20 16:45:23 +0000
commitc3471d98f3a9a8d3054c4a1fc8c45387a12ed097 (patch)
treefa3b1826ecfd6546f1b646c9387b4b7da9d47e43
parentcced6b35cb83bad1397fc1cd0d42277a85c1fea9 (diff)
downloadopenttd-c3471d98f3a9a8d3054c4a1fc8c45387a12ed097.tar.xz
(svn r19485) -Codechange: Re-implement CalcBridgeLenCostFactor() in a more readable way without changing computed costs.
-rw-r--r--src/tunnelbridge_cmd.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 16fc030f5..6d52328cb 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -73,15 +73,16 @@ void ResetBridges()
*/
int CalcBridgeLenCostFactor(int length)
{
- int n;
- int r;
-
if (length < 2) return length;
+
length -= 2;
- for (n = 0, r = 2;; n++) {
- if (length <= n) return r + length * n;
- r += n * n;
- length -= n;
+ int sum = 2;
+ for (int delta = 1;; delta++) {
+ for (int count = 0; count < delta; count++) {
+ if (length == 0) return sum;
+ sum += delta;
+ length--;
+ }
}
}