forked from mirror/OpenTTD
(svn r19485) -Codechange: Re-implement CalcBridgeLenCostFactor() in a more readable way without changing computed costs.
This commit is contained in:
@@ -73,15 +73,16 @@ void ResetBridges()
|
|||||||
*/
|
*/
|
||||||
int CalcBridgeLenCostFactor(int length)
|
int CalcBridgeLenCostFactor(int length)
|
||||||
{
|
{
|
||||||
int n;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
if (length < 2) return length;
|
if (length < 2) return length;
|
||||||
|
|
||||||
length -= 2;
|
length -= 2;
|
||||||
for (n = 0, r = 2;; n++) {
|
int sum = 2;
|
||||||
if (length <= n) return r + length * n;
|
for (int delta = 1;; delta++) {
|
||||||
r += n * n;
|
for (int count = 0; count < delta; count++) {
|
||||||
length -= n;
|
if (length == 0) return sum;
|
||||||
|
sum += delta;
|
||||||
|
length--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user