/** * Gets the Radiance at the given position, if present, or null if there is no light source there. * @param position the position to look up * @return the Radiance at the given position, or null if none is present there */ public Radiance get(Coord position) { return lights.get(position); }
/** * Gets the element at the given Coord position. * @param c the position to get an element from * @return the element if it exists or null otherwise */ public E get(Coord c) { SpatialTriple<I, E> gotten = positionMapping.get(c); if(gotten != null) return gotten.element; return null; }
/** * Gets the element with the given identity. * @param i the identity of the element to get * @return the element if it exists or null otherwise */ public E get(I i) { SpatialTriple<I, E> gotten = itemMapping.get(i); if(gotten != null) return gotten.element; return null; }
/** * If a FakeLanguageGen is known and is in {@link #registered}, this allows you to look up that FakeLanguageGen by * name (using a name from {@link #registeredNames}). * @param name a String name such as "English", "Korean Romanized", or "Russian Authentic" * @return a FakeLanguageGen corresponding to the given name, or null if none was found */ public static FakeLanguageGen get(String name) { return registry.get(name); } /**
/** * Gets the position of the element with the given identity. * @param i the identity of the element to get a position from * @return the position of the element if it exists or null otherwise */ public Coord getPosition(I i) { SpatialTriple<I, E> gotten = itemMapping.get(i); if(gotten != null) return gotten.position; return null; }
/** * Gets the identity of the element at the given Coord position. * @param c the position to get an identity from * @return the identity of the element if it exists at the given position or null otherwise */ public I getIdentity(Coord c) { SpatialTriple<I, E> gotten = positionMapping.get(c); if(gotten != null) return gotten.id; return null; }
/** * Changes the element's value associated with id. The key id should exist before calling this; if there is no * matching id, this returns null. * @param id the identity of the element to modify * @param newValue the element value to replace the previous element with. * @return the previous element value associated with id */ public E modify(I id, E newValue) { SpatialTriple<I, E> gotten = itemMapping.get(id); if(gotten != null) { E previous = gotten.element; gotten.element = newValue; return previous; } return null; } /**
/** * Changes the element's value associated with pos. The key pos should exist before calling this; if there is no * matching position, this returns null. * @param pos the position of the element to modify * @param newValue the element value to replace the previous element with. * @return the previous element value associated with id */ public E positionalModify(Coord pos, E newValue) { SpatialTriple<I, E> gotten = positionMapping.get(pos); if(gotten != null) { E previous = gotten.element; gotten.element = newValue; return previous; } return null; }
public List<V> getMany(Collection<K> keys) { if(keys == null) return new ArrayList<>(1); ArrayList<V> vals = new ArrayList<>(keys.size()); for(K k : keys) { vals.add(get(k)); } return vals; } /**
/** * Given an Iterable (such as a List, Set, or other Collection) of Coord, gets all elements in this SpatialMap that * share a position with one of the Coord objects in positions and returns them as an ArrayList of elements. * @param positions an Iterable (such as a List or Set) of Coord * @return an ArrayList, possibly empty, of elements that share a position with a Coord in positions */ public ArrayList<E> getManyPositions(Iterable<Coord> positions) { ArrayList<E> gotten = new ArrayList<>(); SpatialTriple<I, E> ie; for(Coord p : positions) { if((ie = positionMapping.get(p)) != null) gotten.add(ie.element); } return gotten; }
/** * Gets the Radiance at the given position, if present, or null if there is no light source there. * @param x the x-position to look up * @param y the y-position to look up * @return the Radiance at the given position, or null if none is present there */ public Radiance get(int x, int y) { return lights.get(Coord.get(x, y)); } /**
/** * If a Radiance is present at oldPosition, this will move it to newPosition and overwrite any existing Radiance at * newPosition. If no Radiance is present at oldPosition, this does nothing. * @param oldPosition the Coord to move a Radiance from * @param newPosition the Coord to move a Radiance to * @return this for chaining */ public LightingHandler moveLight(Coord oldPosition, Coord newPosition) { Radiance old = lights.get(oldPosition); if(old == null) return this; lights.alter(oldPosition, newPosition); return this; }
/** * Removes the entry for the specified key only if it is currently * mapped to the specified value. * * @param key key with which the specified value is associated * @param value value expected to be associated with the specified key * @return {@code true} if the value was removed */ public boolean remove(Object key, Object value) { if (containsKey(key) && Objects.equals(get(key), value)) { remove(key); return true; } else return false; }
/** * Looks up the given kind in the Map of biases this stores, and generates a random number using this object's RNG. * If the kind is in the Map, this adjusts the generated number so it matches a distribution that would have the * expected average the kind was associated with. The returned number will be a double between 0.0 and 1.0 * (exclusive on 1.0). If the kind is not in the map, this generates a double using RNG and no further changes. * @param kind the kind of bias to look up * @return a random double between 0.0 and 1.0, potentially influenced by the bias associated with kind, if present */ public double biasedDouble(String kind) { Double d = biases.get(kind); if(d == null) return rng.nextDouble(); return quantile(d); }
/** * Looks up the given kind in the Map of biases this stores, and generates a random number using this object's RNG. * If the kind is in the Map, this adjusts the generated number so it matches a distribution that would have the * expected average the kind was associated with. The returned number will be a float between 0.0 and 1.0 * (exclusive on 1.0). If the kind is not in the map, this generates a float using RNG and no further changes. * @param kind the kind of bias to look up * @return a random float between 0.0 and 1.0, potentially influenced by the bias associated with kind, if present */ public float biasedFloat(String kind) { Double d = biases.get(kind); if(d == null) return rng.nextFloat(); return (float) quantile(d); }
/** * Marks a cell as producing a sound with the given loudness; this can be placed on a wall or unreachable area, * but that may cause the sound to be un-hear-able. A sound emanating from a cell on one side of a 2-cell-thick * wall will only radiate sound on one side, which can be used for certain effects. A sound emanating from a cell * in a 1-cell-thick wall will radiate on both sides. * @param pt * @param loudness The number of cells the sound should spread away using the current measurement. */ public void setSound(Coord pt, double loudness) { if(!initialized) return; if(sounds.containsKey(pt) && sounds.get(pt) >= loudness) return; sounds.put(pt, loudness); }
/** * Looks up the given kind in the Map of biases this stores, and generates a random number using this object's RNG. * If the kind is in the Map, this adjusts the generated number so it matches a distribution that would have the * expected average the kind was associated with. The returned number will be a positive int in either case. If the * kind is not in the map, this generates a positive int, using 31 bits instead of RNG's normal 32 bits since it * never generates negative numbers. * @param kind the kind of bias to look up * @return a random 31-bit positive int, potentially influenced by the bias associated with kind, if present */ public int biasedInt(String kind) { Double d = biases.get(kind); if(d == null) return rng.nextInt() >>> 1; return (int)(quantile(d) * Integer.MAX_VALUE); }
private void putModule(short[] module) { char[][] unp = CoordPacker.unpackChar(module, '.', '#'); MapModule mm = new MapModule(ArrayTools.insert(unp, ArrayTools.fill('#', unp.length + 2, unp[0].length + 2), 1, 1)); //short[] b = CoordPacker.rectangle(1 + mm.max.x, 1 + mm.max.y); //modules.put(b, mm); //inverseModules.put(CoordPacker.negatePacked(b), mm); ArrayList<MapModule> mms = modules.get(mm.category); if (mms == null) { mms = new ArrayList<>(16); mms.add(mm); modules.put(mm.category, mms); } else mms.add(mm); }
/** * Marks a cell as producing a sound with the given loudness; this can be placed on a wall or unreachable area, * but that may cause the sound to be un-hear-able. A sound emanating from a cell on one side of a 2-cell-thick * wall will only radiate sound on one side, which can be used for certain effects. A sound emanating from a cell * in a 1-cell-thick wall will radiate on both sides. * @param x * @param y * @param loudness The number of cells the sound should spread away using the current measurement. */ public void setSound(int x, int y, double loudness) { if(!initialized) return; Coord pt = Coord.get(x, y); if(sounds.containsKey(pt) && sounds.get(pt) >= loudness) return; sounds.put(pt, loudness); }
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]); } }