/** * This function will generate a city with a grid lay out. 4 rounds running * North and South and 4 roads running east west * * @author Torren (Jason Tighe) * @return */ public ArrayList<BuildingTemplate> generateCity(boolean genericRoad) { int width = mapSettings.getBoardWidth(); int height = mapSettings.getBoardHeight(); int roads = mapSettings.getCityBlocks(); roads = (roads * Math.min(width, height)) / 16; // scale for bigger maps String cityType = mapSettings.getCityType(); cityPlan = new HashSet<Coords>(); if (genericRoad) { addGenericRoad(); } if (cityType.equalsIgnoreCase("HUB")) buildHubCity(width, height, roads); else if (cityType.equalsIgnoreCase("METRO")) buildMetroCity(width, height); else if (cityType.equalsIgnoreCase("GRID")) buildGridCity(width, height, (roads + 5) / 6); else if (cityType.equalsIgnoreCase("TOWN")) return buildTown(width, height, roads, mapSettings.getTownSize()); else return new ArrayList<BuildingTemplate>(); return placeBuildings(0); }
private Coords extendRoad(Coords coords, int nextDirection, int roadStyle) { Coords next = selectNextGrid(nextDirection, coords); if (board.contains(next) && hexNeedsBridge(board.getHex(next))) { if (nextDirection == E || nextDirection == W) { nextDirection = coords.direction(next); } Coords end = tryToBuildBridge(coords, nextDirection); return end; } connectHexes(coords, next, roadStyle); connectHexes(next, coords, roadStyle); return next; }
private ArrayList<BuildingTemplate> buildTown(int maxX, int maxY, int roads, int size) { buildHubCity(maxX, maxY, roads * size / 100); return placeBuildings(Math.min(maxX, maxY) * size / 200); }
if (!hexNeedsBridge(board.getHex(next))) { end = next; break; addBridge(board.getHex(c), exits, elev1, cf); connectHexes(start, hexes.firstElement(), 1); connectHexes(end, hexes.lastElement(), 1);
CityBuilder cityBuilder = new CityBuilder(mapSettings, result); if (buildings.size() == 0) { buildings = cityBuilder.generateCity(roadNeeded);
private void buildMetroCity(int maxX, int maxY) { int midX = maxX / 2; int midY = maxY / 2; cityPlan.add(new Coords(midX, midY)); // have the city hub be the mid point with all the hexes around it // cleared out for (int hex = 0; hex < 6; hex++) cityPlan.add(new Coords(Coords.xInDir(midX, midY, hex), Coords .yInDir(midX, midY, hex))); // first east west road Coords coords = new Coords(-1, midY / 2); buildStraightRoad(coords, E, 1); // second east west road coords = new Coords(-1, midY + (midY / 2)); buildStraightRoad(coords, E, 1); // First North South Road coords = new Coords(midX / 2, -1); buildStraightRoad(coords, S, 1); // second North South Road coords = new Coords(midX + (midX / 2), -1); buildStraightRoad(coords, S, 1); for (int dir = 0; dir < 8; dir++) { coords = new Coords(midX, midY); buildStraightRoad(coords, dir, 2); } }
private void connectHexes(Coords src, Coords dest, int roadStyle) { if (board.contains(src)) { IHex hex = board.getHex(src); ITerrain t = hex.getTerrain(Terrains.ROAD); if (t == null) { t = hex.getTerrain(Terrains.BRIDGE); } if (t == null) { addRoad(hex, src.direction(dest), roadStyle); } else { t.setExit(src.direction(dest), true); } } }
/** * Adds an Road to the map. Goes from one border to another, and has one * turn in it. Map must be at least 3x3. */ private void addGenericRoad() { Coords c = new Coords(Compute.randomInt(board.getWidth()), Compute .randomInt(board.getHeight())); int side0 = Compute.randomInt(6); int side1 = Compute.randomInt(5); if (side1 >= side0) { side1++; } buildStraightRoad(c, side0, 1); buildStraightRoad(c, side1, 1); } }
private void buildGridCity(int maxX, int maxY, int roads) { for (int y = 0; y < roads; y++) { int startY = Compute.randomInt(maxY / roads) + ((y * maxY) / roads); // int start = Compute.randomInt(2); Coords coords = new Coords(-1, startY); int roadStyle = Compute.randomInt(2) + 1; int dir = Compute.randomInt(2) + NE; buildStraightRoad(coords, dir, roadStyle); startY = Compute.randomInt(maxY / roads) + ((y * maxY) / roads); coords = new Coords(maxX, startY); dir = Compute.randomInt(2) + SW; buildStraightRoad(coords, dir, roadStyle); } for (int x = 0; x < roads; x++) { int startX = Compute.randomInt(maxX / roads) + (x * (maxX / roads)); Coords coords = new Coords(startX, -1); int roadStyle = Compute.randomInt(2) + 1; buildStraightRoad(coords, S, roadStyle); } }