/** * this is where road tiles are made */ public static void starNet(Map mp, TownParam t, Point[] buildings) { Debug.Log("starNet"); Path roadPath = new Path(); for (int iBuilding = 0; iBuilding < t.size; iBuilding++) { //create road between these two buildings //TODELETE //roadPath.push(Pathfinder.findPath(passableTiles, t.center, buildings[iBuilding] , (int)Pathfinder.TileCost.road)); roadPath.push(mp.findPath(t.center, buildings[iBuilding], (int)Pathfinder.TileCost.road)); while (!roadPath.isEmpty()) { Point curPoint = roadPath.pop(); if (Point.inBounds(mp.getDimensions(), curPoint)) { Tile curTile = mp.get(curPoint); if (curTile.equals(new River())) { curTile = new Bridge(); } else if (curTile.equals(new House()) || curTile.equals(new Bridge())) { } //do nothing else { curTile = new Road(); } mp.set(curPoint, curTile); } } } }
public static bool generateTown(Map mp, TownParam t) { Debug.Log(t.toString()); //check for inBounds if (mp.inBounds(t.center)) { Point[] buildings = new Point[t.size]; for (int iBuilding = 0; iBuilding < t.size; iBuilding++) { buildings[iBuilding] = new Point(t.center.getX() + mp.getRNG().nextInt(t.radius * 2) - t.radius, t.center.getY() + mp.getRNG().nextInt(t.radius * 2) - t.radius); if (mp.inBounds(buildings[iBuilding])) { mp.set(buildings[iBuilding], new House()); } } //O(n) //options to connect if (mp.getRNG().nextBool()) //TODO rng in here! { peerPeer(mp, t, buildings); } else { starNet(mp, t, buildings); } /*for(int iBuilding = 0; iBuilding < t.size; iBuilding++) * { * if(Point.inBounds(mp.getX(), mp.getY(), buildings[iBuilding])) * passableTiles[buildings[iBuilding].getX(), buildings[iBuilding].getY()] = new House(); * }*/ } return(true); }
//due to a declaration of static, the constructor /* * //instance fields * readonly int x, y; * Random mp.getRNG(); * //constructors as usual do not use the first two ever * public TownGenerator() : this(new Random(), 0, 0) {} * public TownGenerator(Random newRng) : this(newRng, 0, 0) {} * public TownGenerator(Random newRng, int * xSize, int ySize) * { * x = xSize; * y = ySize; * rng = newRng; * }*/ /** * generate towns method * this default generator will give the least control over how towns are generated. * @param passableTiles * the map over which the road will be generated note that the dimensions of the board should be equivalent to x and y * @param numTowns * the strict number of towns that will be generated * @postcondition, a town is generated AND the roads required to linke them are added */ public static bool generateTowns(Map mp) { //first generate the list of town centers town center TownParam[] towns = new TownParam[mp.getBehavior().number_Of_Towns]; for (int tcLoc = 0; tcLoc < mp.getBehavior().number_Of_Towns; tcLoc++) { //need a way to make the town size consistent towns[tcLoc] = standardTowns[mp.getRNG().nextInt(8)]; towns[tcLoc].center = new Point(mp.getRNG().nextInt(mp.getX()), mp.getRNG().nextInt(mp.getY())); generateTown(mp, towns[tcLoc]); } return(true); }
/** * this is where road tiles are made */ public static void peerPeer(Map mp, TownParam t, Point[] buildings) { Debug.Log("peertopeer"); Path roadPath = new Path(); for (int iBuilding = 1; iBuilding < t.size; iBuilding++) { //create road between these two buildings //legacy code TODELETE //roadPath.push(Pathfinder.findPath(passableTiles, buildings[iBuilding - 1], buildings[iBuilding] , (int)Pathfinder.TileCost.road)); roadPath.push(mp.findPath(buildings[iBuilding - 1], buildings[iBuilding], (int)Pathfinder.TileCost.road)); while (!roadPath.isEmpty()) { Point curPoint = roadPath.pop(); if (Point.inBounds(mp.getX(), mp.getY(), curPoint)) { Tile curTile = mp.get(curPoint); if (curTile.equals(new River())) { curTile = new Bridge(); } else if (curTile.equals(new House()) || curTile.equals(new Bridge())) { } //do nothing else { curTile = new Road(); } mp.set(curPoint, curTile); //mp.get(roadPath.peek()) = curTile; } } } }