/** * Get a Set of all identities used for values in this data structure, returning a OrderedSet (defensively * copying the key set used internally) for its stable iteration order. * @return a OrderedSet of I corresponding to the identities present in this data structure. */ public OrderedSet<I> identities() { return new OrderedSet<>(itemMapping.keySet()); }
/** * Iterates through identity keys in insertion order. * @return an Iterator of generic type I */ public Iterator<I> identityIterator() { return itemMapping.keySet().iterator(); }
/** * Get a Set of all positions used for values in this data structure, returning a OrderedSet (defensively copying * the key set used internally) for its stable iteration order. * @return a OrderedSet of Coord corresponding to the positions present in this data structure. */ public OrderedSet<Coord> positions() { return new OrderedSet<>(positionMapping.keySet()); } /**
/** * Iterates through positions in insertion order; has less predictable iteration order than the other iterators. * @return an Iterator of Coord */ public Iterator<Coord> positionIterator() { return positionMapping.keySet().iterator(); } /**
/** * Gets all the rooms this found during construction, returning them as an ArrayList of 2D char arrays, where an * individual room is "masked" so only its contents have normal map chars and the rest have only '#'. * @return an ArrayList of 2D char arrays representing rooms. */ public ArrayList<char[][]> findRooms() { ArrayList<char[][]> rs = new ArrayList<>(rooms.size()); for(GreasedRegion r : rooms.keySet()) { rs.add(r.mask(map, '#')); } return rs; }
/** * Gets all the corridors this found during construction, returning them as an ArrayList of 2D char arrays, where an * individual corridor is "masked" so only its contents have normal map chars and the rest have only '#'. * @return an ArrayList of 2D char arrays representing corridors. */ public ArrayList<char[][]> findCorridors() { ArrayList<char[][]> cs = new ArrayList<>(corridors.size()); for(GreasedRegion c : corridors.keySet()) { cs.add(c.mask(map, '#')); } return cs; }
/** * Gets all the caves this found during construction, returning them as an ArrayList of 2D char arrays, where an * individual room is "masked" so only its contents have normal map chars and the rest have only '#'. Will only * return a non-empty collection if the two-arg constructor was used and the environment contains caves. * @return an ArrayList of 2D char arrays representing caves. */ public ArrayList<char[][]> findCaves() { ArrayList<char[][]> vs = new ArrayList<>(caves.size()); for(GreasedRegion v : caves.keySet()) { vs.add(v.mask(map, '#')); } return vs; } /**
private void preloadLights() { Iterator<Coord> it = lights.keySet().iterator(); Coord pos; while (it.hasNext()) { pos = it.next(); if(resMap[pos.x][pos.y] >= 1.0) it.remove(); } lightSources = lights.keySet().toArray(new Coord[lights.size()]); lightBrightnesses = new int[lights.size()]; for (int i = 0; i < lightSources.length; i++) { lightBrightnesses[i] = lights.get(lightSources[i]); } }
/** * Gets all the rooms, corridors, and caves this found during construction, returning them as an ArrayList of 2D * char arrays, where an individual room or corridor is "masked" so only its contents have normal map chars and the * rest have only '#'. * @return an ArrayList of 2D char arrays representing rooms, corridors, or caves. */ public ArrayList<char[][]> findRegions() { ArrayList<char[][]> rs = new ArrayList<char[][]>(rooms.size() + corridors.size() + caves.size()); for(GreasedRegion r : rooms.keySet()) { rs.add(r.mask(map, '#')); } for(GreasedRegion c : corridors.keySet()) { rs.add(c.mask(map, '#')); } for(GreasedRegion v : caves.keySet()) { rs.add(v.mask(map, '#')); } return rs; } private static char[][] defaultFill(int width, int height)
List<List<GreasedRegion>> near = rooms.getMany(GreasedRegion.whichContain(x, y, rooms.keySet())); for (List<GreasedRegion> links : near) { for(GreasedRegion n : links) near = corridors.getMany(GreasedRegion.whichContain(x, y, corridors.keySet())); for (List<GreasedRegion> links : near) { for (GreasedRegion n : links) { near = caves.getMany(GreasedRegion.whichContain(x, y, caves.keySet())); for (List<GreasedRegion> links : near) { for(GreasedRegion n : links)
/** * Takes an x, y position and finds the room, corridor, or cave at that position, if there is one, returning the * same 2D char array format as the other methods. * @param x the x coordinate of a position that should be in a room or corridor * @param y the y coordinate of a position that should be in a room or corridor * @return a masked 2D char array where anything not in the current region is '#' */ public char[][] regionAt(int x, int y) { OrderedSet<GreasedRegion> regions = GreasedRegion.whichContain(x, y, rooms.keySet()); regions.addAll(GreasedRegion.whichContain(x, y, corridors.keySet())); regions.addAll(GreasedRegion.whichContain(x, y, caves.keySet())); GreasedRegion found; if(regions.isEmpty()) found = new GreasedRegion(width, height); else found = regions.first(); return found.mask(map, '#'); }
volume = Integer.MAX_VALUE; int sz = entries.size(); ArrayList<Coord> spillers = new ArrayList<>(entries.keySet()); ArrayList<Double> biases = new ArrayList<>(sz);
/** * Gets an OrderedSet of OrderedSet of Coord, where each inner OrderedSet of Coord refers to a room's * corners, and each Coord is one of those corners. There are more uses for corner placement than I can list. This * doesn't always identify all corners, since it only finds ones in rooms, and a cave too close to a corner can * cause that corner to be ignored. * @return a set of sets of Coord where each set of Coord is a room's corners */ public OrderedSet<OrderedSet<Coord>> getCorners() { if(corners == null) { corners = new OrderedSet<>(32); GreasedRegion working = new GreasedRegion(finder.width, finder.height); for(GreasedRegion region : finder.rooms.keySet()) { working.remake(region).expand().retract8way().xor(region).andNot(nonRoom); OrderedSet<Coord> os = new OrderedSet<>(working.asCoords()); corners.add(os); } } return corners; } /**
for (GreasedRegion room : finder.rooms.keySet()) { if(flooded.intersects(tmp.remake(room).expand8way())) change.add(room);
/** * Gets an OrderedSet of OrderedSet of Coord, where each inner OrderedSet of Coord refers to a placement * region along a straight wall with length 3 or more, not including corners. Each Coord refers to a single cell * along the straight wall. This could be useful for placing weapon racks in armories, chalkboards in schoolrooms * (tutorial missions, perhaps?), or even large paintings/murals in palaces. * @return a set of sets of Coord where each set of Coord is a wall's viable placement for long things along it */ public OrderedSet<OrderedSet<Coord>> getAlongStraightWalls() { if(alongStraightWalls == null) { alongStraightWalls = new OrderedSet<>(32); GreasedRegion working = new GreasedRegion(finder.width, finder.height); for(GreasedRegion region : finder.rooms.keySet()) { working.remake(region).retract().fringe().andNot(nonRoom); for (GreasedRegion sp : working.split()) { if (sp.size() >= 3) alongStraightWalls.add(arrayToSet(sp.asCoords())); } } } return alongStraightWalls; }
for(GreasedRegion region : finder.rooms.keySet()) {