diff --git a/src/autoreplace.cpp b/src/autoreplace.cpp --- a/src/autoreplace.cpp +++ b/src/autoreplace.cpp @@ -57,10 +57,8 @@ EngineID EngineReplacement(EngineRenewLi CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, DoCommandFlag flags) { - EngineRenew *er; - /* Check if the old vehicle is already in the list */ - er = GetEngineReplacement(*erl, old_engine, group); + EngineRenew *er = GetEngineReplacement(*erl, old_engine, group); if (er != NULL) { if (flags & DC_EXEC) er->to = new_engine; return CommandCost(); diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -195,8 +195,6 @@ CommandCost CmdBuildBridge(TileIndex end { RailType railtype = INVALID_RAILTYPE; RoadTypes roadtypes = ROADTYPES_NONE; - CommandCost cost(EXPENSES_CONSTRUCTION); - Owner owner; /* unpack parameters */ BridgeType bridge_type = GB(p2, 0, 8); @@ -266,6 +264,8 @@ CommandCost CmdBuildBridge(TileIndex end if (z_start != z_end) return_cmd_error(STR_ERROR_BRIDGEHEADS_NOT_SAME_HEIGHT); + CommandCost cost(EXPENSES_CONSTRUCTION); + Owner owner; if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) && GetOtherBridgeEnd(tile_start) == tile_end && GetTunnelBridgeTransportType(tile_start) == transport_type) { @@ -481,7 +481,6 @@ CommandCost CmdBuildBridge(TileIndex end CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { TransportType transport_type = (TransportType)GB(p1, 9, 1); - CommandCost cost(EXPENSES_CONSTRUCTION); _build_tunnel_endtile = 0; if (transport_type == TRANSPORT_RAIL) { @@ -524,6 +523,7 @@ CommandCost CmdBuildTunnel(TileIndex sta /* Number of tiles at which the cost increase coefficient per tile is halved */ int tiles_bump = 25; + CommandCost cost(EXPENSES_CONSTRUCTION); Slope end_tileh; for (;;) { end_tile += delta; @@ -640,14 +640,11 @@ static inline CommandCost CheckAllowRemo */ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags) { - Town *t = NULL; - TileIndex endtile; - CommandCost ret = CheckAllowRemoveTunnelBridge(tile); ret.SetGlobalErrorMessage(); if (ret.Failed()) return ret; - endtile = GetOtherTunnelEnd(tile); + TileIndex endtile = GetOtherTunnelEnd(tile); ret = TunnelBridgeIsFree(tile, endtile); ret.SetGlobalErrorMessage(); @@ -655,6 +652,7 @@ static CommandCost DoClearTunnel(TileInd _build_tunnel_endtile = endtile; + Town *t = NULL; if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { t = ClosestTownFromTile(tile, UINT_MAX); // town penalty rating @@ -711,24 +709,20 @@ static CommandCost DoClearTunnel(TileInd */ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags) { - DiagDirection direction; - TileIndexDiff delta; - TileIndex endtile; - Town *t = NULL; - CommandCost ret = CheckAllowRemoveTunnelBridge(tile); ret.SetGlobalErrorMessage(); if (ret.Failed()) return ret; - endtile = GetOtherBridgeEnd(tile); + TileIndex endtile = GetOtherBridgeEnd(tile); ret = TunnelBridgeIsFree(tile, endtile); ret.SetGlobalErrorMessage(); if (ret.Failed()) return ret; - direction = GetTunnelBridgeDirection(tile); - delta = TileOffsByDiagDir(direction); + DiagDirection direction = GetTunnelBridgeDirection(tile); + TileIndexDiff delta = TileOffsByDiagDir(direction); + Town *t = NULL; if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { t = ClosestTownFromTile(tile, UINT_MAX); // town penalty rating @@ -925,7 +919,6 @@ static void DrawBridgeTramBits(int x, in */ static void DrawTile_TunnelBridge(TileInfo *ti) { - SpriteID image; TransportType transport_type = GetTunnelBridgeTransportType(ti->tile); DiagDirection tunnelbridge_direction = GetTunnelBridgeDirection(ti->tile); @@ -951,6 +944,7 @@ static void DrawTile_TunnelBridge(TileIn bool catenary = false; + SpriteID image; if (transport_type == TRANSPORT_RAIL) { image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.tunnel; } else {