From c3471d98f3a9a8d3054c4a1fc8c45387a12ed097 Mon Sep 17 00:00:00 2001 From: alberth Date: Sat, 20 Mar 2010 16:45:23 +0000 Subject: (svn r19485) -Codechange: Re-implement CalcBridgeLenCostFactor() in a more readable way without changing computed costs. --- src/tunnelbridge_cmd.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') 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--; + } } } -- cgit v1.2.3-70-g09d2