public RegionMap(final int expected, final float f) { super(expected, f); hasher = CrossHash.shortHasher; CoordPacker.init(); }
public OrganicMapGenerator(double noiseMin, double noiseMax, int width, int height, IRNG rng) { CoordPacker.init(); this.rng = rng; this.width = Math.max(3, width); this.height = Math.max(3, height); this.noiseMin = Math.min(0.9, Math.max(-1.0, noiseMin)); this.noiseMax = Math.min(1.0, Math.max(noiseMin + 0.05, noiseMax)); map = new char[this.width][this.height]; environment = new int[this.width][this.height]; }
/** * A convenience wrapper for getting a packed-data representation of all floors ('.') in map, for randomCell(). * If you want other chars or more chars than just the period, you can use CoordPacker.pack() with a char[][] map * and one or more chars to find as the parameters. This is the same as calling {@code CoordPacker.pack(map, '.')}. * * @param map a char[][] that uses '.' to represent floors * @return all floors in map in packed data format (a special short array) that can be given to randomCell() */ public static short[] packedFloors(char[][] map) { CoordPacker.init(); return CoordPacker.pack(map, '.'); }
/** * Finds a random Coord where the x and y match up to a [x][y] location that is encoded as "on" in packed. * This is useful when you have used {@code DungeonUtility.packedFloors(char[][] map)} to encode all floors in map, * or {@code CoordPacker.pack(char[][] map, char... yes)} to encode all cells in a char[][] map that match a * particular type, like '.' for floors or '~' for deep water, and want to efficiently get one randomly-chosen tile * from it. Calling pack() is likely slightly less efficient than using randomFloor(), but it only needs to be done * once per map and cell type, and this method should be substantially more efficient when the type of cell is * uncommon on the map. * Uses this class' rng field for pseudo-random number generation. * * @param packed a packed array produced by CoordPacker encoding the cells to choose from as "on" * @return a Coord that corresponds to a '.' in map, or (-1, -1) if a '.' cannot be found or if map is too small */ public Coord randomCell(short[] packed) { CoordPacker.init(); return CoordPacker.singleRandom(packed, rng); }
/** * A constructor for a Region that takes a specifically-formatted short array (packed data), as produced by * CoordPacker or sometimes other classes, like RegionMap or RoomFinder. If you don't have such data, the other * constructors are recommended instead. * <br> * Note: arrays of Hilbert indices are occasionally returned in CoordPacker as a different kind of short array, but * those methods are always noted as such and those short arrays won't make sense if passed to this constructor. * They may result in a technically-valid Region with random-seeming contents. In general, if a method in * CoordPacker returns a short array (most of them do), but the name contains Hilbert, it may return the wrong kind * (an array of Hilbert indices is wrong, packed data is right); check the documentation for that method. * @param packedData a short array as produced by CoordPacker (usually), or sometimes RoomFinder or RegionMap */ public Region(short[] packedData) { CoordPacker.init(); raw = new short[packedData.length]; System.arraycopy(packedData, 0, raw, 0, packedData.length); coords = allPacked(raw); dirty = false; }
/** * A constructor that copies another Region so this Region will have the same contents. If the other Region is * "dirty", this won't perform "cleanup" on it, but will ensure that this Region is "clean" at creation. * None of the reference types in other will be used directly in this Region, so changes made to this Region won't * be reflected in other. * @param other another Region to copy into this one */ public Region(Region other) { CoordPacker.init(); raw = new short[other.raw.length]; System.arraycopy(other.raw, 0, raw, 0, raw.length); if(other.dirty) { coords = allPacked(raw); } else { coords = new Coord[other.coords.length]; System.arraycopy(other.coords, 0, coords, 0, coords.length); } dirty = false; }
/** * A constructor for a Region that takes a Collection of Coord, such as a List or Set, and encodes all of them in * the Region. * @param points a Collection of Coord that will be stored in this Region, none can be null */ public Region(Collection<Coord> points) { CoordPacker.init(); raw = packSeveral(points); coords = allPacked(raw); dirty = false; }
/** * A constructor for a Region that takes an array or vararg of Coord and encodes all of them in the Region. * @param points an array or vararg of Coord that will be stored in this Region, none can be null */ public Region(Coord... points) { CoordPacker.init(); raw = packSeveral(points); coords = allPacked(raw); dirty = false; } /**
/** * A constructor for a Region that takes a 2D double array, usually produced by DijkstraMap, and a maximum value, * and stores only Coord positions that correspond to values no greater than maximum. * This won't behave as-expected if you give it a double[][] that FOV produces; there's a different * constructor for that purpose. * @param dijkstraMap a 2D double array as produced by DijkstraMap * @param maximum the highest value that a position can have in dijkstraMap and still be given a Coord in this */ public Region(double[][] dijkstraMap, double maximum) { CoordPacker.init(); raw = pack(dijkstraMap, maximum); coords = allPacked(raw); dirty = false; }
/** * A constructor for a Region that takes a 2D double array, usually the kind produced by FOV, and stores only Coord * positions that correspond to values greater than 0.0 (actually, greater than epsilon, which here is 0.0001). * This won't behave as-expected if you give it a double[][] that DijkstraMap produces; there's a different * constructor for that purpose. * @param fovMap a 2D double array as produced by FOV */ public Region(double[][] fovMap) { CoordPacker.init(); raw = pack(fovMap); coords = allPacked(raw); dirty = false; }
/** * A constructor for a circular Region (possibly truncated at the edges) with a Coord center, an int radius, and a * maximum width and height that the Coords in this Region will not exceed. * @param center the center of the circular Region * @param circleRadius the radius as an int * @param mapWidth one more than the maximum x-position of any Coord this will contain * @param mapHeight one more than the maximum y-position of any Coord this will contain */ public Region(Coord center, int circleRadius, int mapWidth, int mapHeight) { CoordPacker.init(); raw = circle(center, circleRadius, mapWidth, mapHeight); coords = allPacked(raw); dirty = false; }
/** * A constructor for a Region that takes a 2D char array, the kind produced by most map/dungeon generators in this * library, and a vararg or array of char that will have their Coord positions used where those chars appear in map. * This is optimized for the common case of a single char in using if you only want to, for example, store '.' to * make a Region of floors, or '#' for walls. * @param map a 2D char array that is usually the kind returned by a dungeon or map generator * @param using an array or vararg of char that will have their Coords used where they appear in map */ public Region(char[][] map, char... using) { CoordPacker.init(); raw = pack(map, using); coords = allPacked(raw); dirty = false; }
CoordPacker.init(); ArrayList<Color> colors = new ArrayList<>((steps > 1) ? steps : 1); colors.add(filter(fromColor));
/** * A constructor for a rectangular Region that stores Coords for the area from (minX,minY) at the minimum corner to * (width + minX - 1, height + minY - 1) at the maximum corner. All parameters should be non-negative and less than * 256, and height and width will be reduced if a Coord in the rectangle would extend to 256 in either dimension. * This doesn't take two Coords as parameters because that would be confusing with the constructor that takes a * vararg or array of Coord for its parameters. * @param minX lowest x-coordinate in the rectangle; should be between 0 and 255 * @param minY lowest y-coordinate in the rectangle; should be between 0 and 255 * @param width total width of the rectangle; must be non-negative * @param height total height of the rectangle; must be non-negative */ public Region(int minX, int minY, int width, int height) { CoordPacker.init(); raw = rectangle(minX, minY, width, height); coords = allPacked(raw); dirty = false; } /**
/** * Constructs a Zone of Influence map. Takes a (quite possibly jagged) array of arrays of Coord influences, where * the elements of the outer array represent different groups of influencing "factions" or groups that exert control * over nearby areas, and the Coord elements of the inner array represent individual spots that are part of those * groups and share influence with all Coord in the same inner array. Also takes a char[][] for a map, which can be * the simplified map with only '#' for walls and '.' for floors, or the final map (with chars like '~' for deep * water as well as walls and floors), and a Radius enum that will be used to determine how distance is calculated. * <br> * Call calculate() when you want information out of this. * @param influences an outer array containing influencing groups, each an array containing Coords that influence * @param map a char[][] that is used as a map; should be bounded * @param measurement a Radius enum that corresponds to how distance should be measured */ public ZOI(Coord[][] influences, char[][] map, Radius measurement) { CoordPacker.init(); this.influences = influences; packedGroups = new short[influences.length][]; this.map = map; radius = measurement; dijkstra = new DijkstraMap(map, DijkstraMap.findMeasurement(measurement)); } /**
/** * Constructs a Zone of Influence map. Takes an arrays of Coord influences, where each Coord is treated as both a * one-element group of influencing "factions" or groups that exert control over nearby areas, and the individual * spot that makes up one of those groups and spreads influence. Also takes a char[][] for a map, which can be the * simplified map with only '#' for walls and '.' for floors, or the final map (with chars like '~' for deep water * as well as walls and floors), and a Radius enum that will be used to determine how distance is calculated. * <br> * Essentially, this is the same as constructing a ZOI with a Coord[][] where each inner array has only one element. * <br> * Call calculate() when you want information out of this. * @param influences an array containing Coords that each have their own independent influence * @param map a char[][] that is used as a map; should be bounded * @param measurement a Radius enum that corresponds to how distance should be measured * @see squidpony.squidmath.PoissonDisk for a good way to generate evenly spaced Coords that can be used here */ public ZOI(Coord[] influences, char[][] map, Radius measurement) { CoordPacker.init(); this.influences = new Coord[influences.length][]; for (int i = 0; i < influences.length; i++) { this.influences[i] = new Coord[] { influences[i] }; } packedGroups = new short[influences.length][]; this.map = map; radius = measurement; dijkstra = new DijkstraMap(map, DijkstraMap.findMeasurement(measurement)); }
CoordPacker.init(); this.map = ArrayTools.copy(map); environment = ArrayTools.fill(DungeonUtility.ROOM_FLOOR, this.map.length, this.map[0].length);
/** * Make a ModularMapGenerator with the given height, width, and RNG. Use this if you want to seed the RNG. * * @param width The width of the dungeon in cells * @param height The height of the dungeon in cells * @param rng The RNG to use for all purposes in this class; if it is any kind of IStatefulRNG, then it will be * used as-is; otherwise, a new GWTRNG will be used, randomly seeded by this parameter */ public ModularMapGenerator(int width, int height, IRNG rng) { CoordPacker.init(); this.rng = (rng instanceof IStatefulRNG) ? (IStatefulRNG) rng : new GWTRNG(rng.nextLong()); utility = new DungeonUtility(this.rng); rebuildSeed = this.rng.getState(); this.height = height; this.width = width; map = new char[width][height]; environment = new int[width][height]; for (int x = 0; x < this.width; x++) { Arrays.fill(map[x], '#'); } initModules(); }
CoordPacker.init(); map = ArrayTools.copy(CoordPacker.unpackChar(packed, width, height, '.', '#')); environment = ArrayTools.fill(DungeonUtility.ROOM_FLOOR, this.map.length, this.map[0].length);
/** * Copies all fields from copying and makes a new DungeonGenerator. * * @param copying the DungeonGenerator to copy */ public ModularMapGenerator(ModularMapGenerator copying) { CoordPacker.init(); rng = new StatefulRNG(copying.rng.getState()); utility = new DungeonUtility(rng); rebuildSeed = rng.getState(); height = copying.height; width = copying.width; map = ArrayTools.copy(copying.map); environment = ArrayTools.copy(copying.environment); layout = new RegionMap<>(copying.layout); modules = new OrderedMap<>(copying.modules); displacement = new OrderedMap<>(copying.displacement); }