I was working to get rid of any HasNext instance in the code and I came across a weird problem. Please consider the following code:
Code: Select all
function PathBuilder::BuildRoadPiece(fromTile, toTile, tileType, length, estimateCost) {
local buildSucceded = false;
switch (tileType) {
case Tile.ROAD:
...
break;
case Tile.TUNNEL:
...
break;
case Tile.BRIDGE:
// Find the cheapest and fastest bridge.
local bridgeTypes = AIBridgeList_Length(length);
local bestBridgeType = null;
// for (local bridge = bridgeTypes.Begin(); bridgeTypes.HasNext(); bridge = bridgeTypes.Next()) {
foreach (bridge, value in bridgeTypes) {
if (bestBridgeType == null || (AIBridge.GetPrice(bestBridgeType, length) > AIBridge.GetPrice(bridge, length) && AIBridge.GetMaxSpeed(bridge) >= maxSpeed))
bestBridgeType = bridge;
}
// Connect the bridge to the other end. Because the first road tile after the bridge has to
// be straight, we have to substract a tile in the opposite direction from where the bridge is
// going. Because we calculated the pathlist in the other direction, the direction is in the
// opposite direction so we need to add it.
buildSucceded = AIBridge.BuildBridge(AIVehicle.VT_ROAD, bestBridgeType, fromTile, toTile);
break;
default:
assert(false);
}
// Next check if the build was succesful, and if not store all relevant information.
if (!buildSucceded) {
// If the error is such we are unable to solve, stop.
if (!estimateCost && !CheckError([fromTile, toTile, tileType, length]))
return false;
}
return true;
}
Code: Select all
for (local bridge = bridgeTypes.Begin(); bridgeTypes.HasNext(); bridge = bridgeTypes.Next()) {
Code: Select all
foreach (bridge, value in bridgeTypes) {
Code: Select all
// Next check if the build was succesful, and if not store all relevant information.
if (!buildSucceded) {
Thanks in advance!
Bram