public void write (Kryo kryo, Output output, ObjectFloatMap map) { int length = map.size; output.writeVarInt(length, true); output.writeBoolean(false); // whether type is written (in case future version of ObjectFloatMap supports type awareness) Serializer keySerializer = null; if (keyGenericType != null) { if (keySerializer == null) keySerializer = kryo.getSerializer(keyGenericType); keyGenericType = null; } for (Iterator iter = map.iterator(); iter.hasNext();) { ObjectFloatMap.Entry entry = (ObjectFloatMap.Entry)iter.next(); if (keySerializer != null) { kryo.writeObject(output, entry.key, keySerializer); } else kryo.writeClassAndObject(output, entry.key); output.writeFloat(entry.value); } }
@Override public void nextDay() { Weather previous = current; current = null; for (ObjectFloatMap.Entry<Class<? extends Weather>> entry : probabilities.entries()) { if (Shadow.rand.nextFloat() <= entry.value) { try { current = entry.key.getConstructor(Level.class).newInstance(level); break; } catch (Exception e) { e.printStackTrace(); } } } if (previous != null) { previous.stop(); } if (current != null) { current.start(); } }
private static ObjectFloatMap<Character> generateDefaultCharIntervals () { ObjectFloatMap<Character> map = new ObjectFloatMap<Character>(); map.put(' ', 0.0f); map.put(':', 1.5f); map.put(',', 2.5f); map.put('.', 2.5f); map.put('!', 5.0f); map.put('?', 5.0f); map.put('\n', 20f); return map; }
public ObjectFloatMap read (Kryo kryo, Input input, Class<ObjectFloatMap> type) { int length = input.readVarInt(true); input.readBoolean(); // currently unused ObjectFloatMap map = create(length); Class keyClass = null; Serializer keySerializer = null; if (keyGenericType != null) { keyClass = keyGenericType; if (keySerializer == null) keySerializer = kryo.getSerializer(keyClass); keyGenericType = null; } kryo.reference(map); for (int i = 0; i < length; i++) { Object key; if (keySerializer != null) { key = kryo.readObject(input, keyClass, keySerializer); } else key = kryo.readClassAndObject(input); float value = input.readFloat(); map.put(key, value); } return map; }
@SuppressWarnings({ "rawtypes", "unchecked" }) public ObjectFloatMap<Faction> getFactionsScores(Map<String, Object> effectsMap) { ObjectFloatMap<Faction> scores = new ObjectFloatMap<>(Faction.values().length); for (Entry<String, Object> effect : effectsMap.entrySet()) { Effect e = effects.get(effect.getKey()); e.addFactionsScores(scores, effect.getValue()); } return scores; }
private ObjectFloatMap<Faction> getFactionsScores(Discovery discovery) { ObjectFloatMap<Faction> scores = effects.getFactionsScores(discovery.effects); for (String group : discovery.groups) if (Policy.get(group) != null) { for (Faction f : Faction.values()) scores.put(f, scores.get(f, 0f) * 1.5f); scores.getAndIncrement(Faction.CULTURAL, 0, 0.5f); } if (scores.size == 0) scores.getAndIncrement(Faction.CULTURAL, 0, 0.5f); return scores; }
public Research(Discovery target, Collection<Discovery> previous) { this.target = target; this.previous = previous; this.factions = new ObjectFloatMap<>(); for (Faction f : Faction.values()) { factions.put(f, target.factions.get(f, 0f)); for (Discovery p : previous) factions.getAndIncrement(f, 0f, p.factions.get(f, 0f) * 0.5f); } }
protected ObjectFloatMap create (int size) { return new ObjectFloatMap(size); }
@Override public void addFactionsScores(ObjectFloatMap<Faction> scores, Number value) { float delta = value.intValue(); scores.getAndIncrement(Faction.MILITARY, 0, delta / 2f); scores.getAndIncrement(Faction.ECONOMIC, 0, delta); }
@Override public void addFactionsScores(ObjectFloatMap<Faction> scores, Number value) { float delta = value.intValue(); scores.getAndIncrement(Faction.ECONOMIC, 0, delta / 2f); scores.getAndIncrement(Faction.CULTURAL, 0, delta); }
@Override public void addFactionsScores(ObjectFloatMap<Faction> scores, Number value) { float delta = value.intValue(); scores.getAndIncrement(Faction.MILITARY, 0, delta * 3f); scores.getAndIncrement(Faction.CULTURAL, 0, -delta * 3f); }
@Override public void addFactionsScores(ObjectFloatMap<Faction> scores, String value) { scores.getAndIncrement(Faction.MILITARY, 0, 3f); scores.getAndIncrement(Faction.ECONOMIC, 0, 1f); scores.getAndIncrement(Faction.CULTURAL, 0, 0.5f); }
@Override public void addFactionsScores(ObjectFloatMap<Faction> scores, Number value) { float delta = value.intValue(); scores.getAndIncrement(Faction.CULTURAL, 0, delta * 2); }
@Override public void addFactionsScores(ObjectFloatMap<Faction> scores, Number value) { float delta = value.intValue(); scores.getAndIncrement(Faction.ECONOMIC, 0, delta * 2); scores.getAndIncrement(Faction.CULTURAL, 0, delta / 2); }
void addFactionsScores(ObjectFloatMap<Faction> scores, V value);