if (getCategoryForTile(X, Y) == TerrainType.CATEGORY_COUNTRY) { Integer typeToAdd = null; int tileTypeToBuild = randomSelector(3, Math.random()); double myRand = Math.random();
Integer typeToAdd = null; int tileTypeToBuild = randomSelector(3); double myRand = Math.random();
    private void calculateAndPositionTiles(int x, int y, int urbNo, int indNo,        int resNo) {        int cityX = x;        int cityY = y;        int urbanTiles = urbNo;        int industryTiles = indNo;        int resourceTiles = resNo;        ArrayList industriesNotAtCity = new ArrayList(this.industryTerrainTypes);        double tileProbability = (double)PROBABILITY_MULTIPLIER * (urbanTiles +            industryTiles + resourceTiles);        /*         * loop until the correct amount of tiles have been built, sometimes         * all the tiles may not get built due to ocean or something else         * getting in the way, looping round tries a couple more times.         */        int loopCount = 0;        while (((urbanTiles + industryTiles + resourceTiles) > 0) &&                (loopCount < 3)) {            for (int Y = cityY - 2; Y < cityY + 3; Y++) {                for (int X = cityX - 2; X < cityX + 3; X++) {                    if (w.boundsContain(X, Y)) {                        if (Math.random() < tileProbability) {			    //tile is selected, now select a tile to build if			    //the tile has a Country terrain, then build a			    //tile on it, otherwise ignore			    /*			     * TODO site should be better selected on basis of			     * terrain type - e.g. harbours should be next to			     * ocean tiles etc.			     */                            if (getCategoryForTile(X, Y) ==				    TerrainType.CATEGORY_COUNTRY) {                                Integer typeToAdd = null;                                int tileTypeToBuild = randomSelector(3,                                        Math.random());                                double myRand = Math.random();                                if ((tileTypeToBuild == 1) && (urbanTiles > 0)) {                                    urbanTiles--;                                    typeToAdd = (Integer)urbanTerrainTypes.get(randomSelector(                                                urbanTerrainTypes.size(), myRand) -                                            1);                                } else if ((tileTypeToBuild == 2) &&                                        (industryTiles > 0) &&                                        industriesNotAtCity.size() > 0) {                                    /* We only want one of any industry type in the city.*/                                    int i = randomSelector(industriesNotAtCity.size(),                                            myRand) - 1;                                    typeToAdd = (Integer)industriesNotAtCity.remove(i);                                    industryTiles--;                                } else if ((tileTypeToBuild == 3) &&                                        (resourceTiles > 0)) {                                    resourceTiles--;                                    typeToAdd = (Integer)resourceTerrainTypes.get(randomSelector(                                                resourceTerrainTypes.size(),                                                myRand) - 1);                                }                                if (typeToAdd != null) {				    BuildingTile bt = new					BuildingTile(typeToAdd.intValue());                                    tile = w.getTile(X, Y);				    tile = new FreerailsTile(tile, bt);                                    w.setTile(X, Y, tile);                                }                            }                            //end 'Country' check                        }                    }                    //end bounds check                }                //end inner loop            }            //end outer loop            loopCount += 1;        }        //end while    }