MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CalcBridgeLenCostFactor

Function CalcBridgeLenCostFactor

src/tunnelbridge_cmd.cpp:94–107  ·  view source on GitHub ↗

* Calculate the price factor for building a long bridge. * Basically the cost delta is 1,1, 1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5, 6,6,6,6,6,6, 7,7,7,7,7,7,7, 8,8,8,8,8,8,8,8, * @param length Length of the bridge. * @return Price factor for the bridge. */

Source from the content-addressed store, hash-verified

92 * @return Price factor for the bridge.
93 */
94int CalcBridgeLenCostFactor(int length)
95{
96 if (length < 2) return length;
97
98 length -= 2;
99 int sum = 2;
100 for (int delta = 1;; delta++) {
101 for (int count = 0; count < delta; count++) {
102 if (length == 0) return sum;
103 sum += delta;
104 length--;
105 }
106 }
107}
108
109/**
110 * Get the foundation for a bridge.

Callers 3

CmdBuildBridgeFunction · 0.85
ShowBuildBridgeWindowFunction · 0.85
GetPriceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected