public void write (Kryo kryo, Output output, ObjectIntMap map) { int length = map.size; output.writeVarInt(length, true); output.writeBoolean(false); // whether type is written (in case future version of ObjectIntMap 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();) { ObjectIntMap.Entry entry = (ObjectIntMap.Entry)iter.next(); if (keySerializer != null) { kryo.writeObject(output, entry.key, keySerializer); } else kryo.writeClassAndObject(output, entry.key); output.writeInt(entry.value); } }
private IActionResult calcResult(Creature creature, Grid2D.Coordinate cell) { Vector2 position = tmp.set(cell.x(), cell.y()); ObjectIntMap<Creature> targets = new ObjectIntMap<Creature>(); for (int i = cell.x() - MathUtils.ceil(radius); i <= cell.x() + radius; i++) { for (int j = cell.y() - MathUtils.ceil(radius); j <= cell.y() + radius; j++) { if (position.dst(i, j) <= radius) { WorldObject object = creature.world.get(i, j); if (object instanceof Creature && ((Creature) object).get(Attribute.canBeSelected) && !((Creature) object).get(Attribute.frozen)) { targets.put((Creature) object, i == cell.x() && j == cell.y() ? epicenterTurns : turns); } } } } return new IceStormResult(owner, creature, cell, targets); }
public ObjectIntMap read (Kryo kryo, Input input, Class<ObjectIntMap> type) { int length = input.readVarInt(true); input.readBoolean(); // currently unused ObjectIntMap 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); int value = input.readInt(); map.put(key, value); } return map; }
private void fetchAttributes () throws Exception { IntBuffer params = $getValue__params(); IntBuffer type = $getValue__type(); int program = $getValue__program(); ObjectIntMap<String> attributes = $getValue__attributes(); ObjectIntMap<String> attributeTypes = $getValue__attributeTypes(); ObjectIntMap<String> attributeSizes = $getValue__attributeSizes(); params.clear(); Gdx.gl20.glGetProgramiv(program, GL20.GL_ACTIVE_ATTRIBUTES, params); int numAttributes = params.get(0); String[] attributeNames = new String[numAttributes]; for (int i = 0; i < numAttributes; i++) { params.clear(); params.put(0, 1); type.clear(); String name = Gdx.gl20.glGetActiveAttrib(program, i, params, type); int location = Gdx.gl20.glGetAttribLocation(program, name); attributes.put(name, location); attributeTypes.put(name, type.get(0)); attributeSizes.put(name, params.get(0)); attributeNames[i] = name; } $setValue_attributeNames(attributeNames); }
private void fetchUniforms () throws Exception { IntBuffer params = $getValue__params(); IntBuffer type = $getValue__type(); int program = $getValue__program(); ObjectIntMap<String> uniforms = $getValue__uniforms(); ObjectIntMap<String> uniformTypes = $getValue__uniformTypes(); ObjectIntMap<String> uniformSizes = $getValue__uniformSizes(); params.clear(); Gdx.gl20.glGetProgramiv(program, GL20.GL_ACTIVE_UNIFORMS, params); int numUniforms = params.get(0); String[] uniformNames = new String[numUniforms]; for (int i = 0; i < numUniforms; i++) { params.clear(); params.put(0, 1); type.clear(); String name = Gdx.gl20.glGetActiveUniform(program, i, params, type); int location = Gdx.gl20.glGetUniformLocation(program, name); uniforms.put(name, location); uniformTypes.put(name, type.get(0)); uniformSizes.put(name, params.get(0)); uniformNames[i] = name; } $setValue_uniformNames(uniformNames); }
public com.badlogic.gdx.utils.ObjectIntMap $getValue__uniforms() throws Exception { if($gen_uniforms == null) { $gen_uniforms = com.badlogic.gdx.graphics.glutils.ShaderProgram.class.getDeclaredField("uniforms"); net.ncguy.argent.utils.ReflectionUtils.setCompletelyAccessible($gen_uniforms); } return (com.badlogic.gdx.utils.ObjectIntMap)$gen_uniforms.get(this); }
public void $setValue_uniforms(com.badlogic.gdx.utils.ObjectIntMap var) throws Exception { if($gen_uniforms == null) { $gen_uniforms = com.badlogic.gdx.graphics.glutils.ShaderProgram.class.getDeclaredField("uniforms"); net.ncguy.argent.utils.ReflectionUtils.setCompletelyAccessible($gen_uniforms); } $gen_uniforms.set(this, (com.badlogic.gdx.utils.ObjectIntMap)var); }
public com.badlogic.gdx.utils.ObjectIntMap $getValue__uniformTypes() throws Exception { if($gen_uniformTypes == null) { $gen_uniformTypes = com.badlogic.gdx.graphics.glutils.ShaderProgram.class.getDeclaredField("uniformTypes"); net.ncguy.argent.utils.ReflectionUtils.setCompletelyAccessible($gen_uniformTypes); } return (com.badlogic.gdx.utils.ObjectIntMap)$gen_uniformTypes.get(this); }
public void $setValue_uniformTypes(com.badlogic.gdx.utils.ObjectIntMap var) throws Exception { if($gen_uniformTypes == null) { $gen_uniformTypes = com.badlogic.gdx.graphics.glutils.ShaderProgram.class.getDeclaredField("uniformTypes"); net.ncguy.argent.utils.ReflectionUtils.setCompletelyAccessible($gen_uniformTypes); } $gen_uniformTypes.set(this, (com.badlogic.gdx.utils.ObjectIntMap)var); }
public com.badlogic.gdx.utils.ObjectIntMap $getValue__uniformSizes() throws Exception { if($gen_uniformSizes == null) { $gen_uniformSizes = com.badlogic.gdx.graphics.glutils.ShaderProgram.class.getDeclaredField("uniformSizes"); net.ncguy.argent.utils.ReflectionUtils.setCompletelyAccessible($gen_uniformSizes); } return (com.badlogic.gdx.utils.ObjectIntMap)$gen_uniformSizes.get(this); }
public void $setValue_uniformSizes(com.badlogic.gdx.utils.ObjectIntMap var) throws Exception { if($gen_uniformSizes == null) { $gen_uniformSizes = com.badlogic.gdx.graphics.glutils.ShaderProgram.class.getDeclaredField("uniformSizes"); net.ncguy.argent.utils.ReflectionUtils.setCompletelyAccessible($gen_uniformSizes); } $gen_uniformSizes.set(this, (com.badlogic.gdx.utils.ObjectIntMap)var); }
public com.badlogic.gdx.utils.ObjectIntMap $getValue__attributes() throws Exception { if($gen_attributes == null) { $gen_attributes = com.badlogic.gdx.graphics.glutils.ShaderProgram.class.getDeclaredField("attributes"); net.ncguy.argent.utils.ReflectionUtils.setCompletelyAccessible($gen_attributes); } return (com.badlogic.gdx.utils.ObjectIntMap)$gen_attributes.get(this); }
public void $setValue_attributes(com.badlogic.gdx.utils.ObjectIntMap var) throws Exception { if($gen_attributes == null) { $gen_attributes = com.badlogic.gdx.graphics.glutils.ShaderProgram.class.getDeclaredField("attributes"); net.ncguy.argent.utils.ReflectionUtils.setCompletelyAccessible($gen_attributes); } $gen_attributes.set(this, (com.badlogic.gdx.utils.ObjectIntMap)var); }
public com.badlogic.gdx.utils.ObjectIntMap $getValue__attributeTypes() throws Exception { if($gen_attributeTypes == null) { $gen_attributeTypes = com.badlogic.gdx.graphics.glutils.ShaderProgram.class.getDeclaredField("attributeTypes"); net.ncguy.argent.utils.ReflectionUtils.setCompletelyAccessible($gen_attributeTypes); } return (com.badlogic.gdx.utils.ObjectIntMap)$gen_attributeTypes.get(this); }
public void $setValue_attributeTypes(com.badlogic.gdx.utils.ObjectIntMap var) throws Exception { if($gen_attributeTypes == null) { $gen_attributeTypes = com.badlogic.gdx.graphics.glutils.ShaderProgram.class.getDeclaredField("attributeTypes"); net.ncguy.argent.utils.ReflectionUtils.setCompletelyAccessible($gen_attributeTypes); } $gen_attributeTypes.set(this, (com.badlogic.gdx.utils.ObjectIntMap)var); }
public com.badlogic.gdx.utils.ObjectIntMap $getValue__attributeSizes() throws Exception { if($gen_attributeSizes == null) { $gen_attributeSizes = com.badlogic.gdx.graphics.glutils.ShaderProgram.class.getDeclaredField("attributeSizes"); net.ncguy.argent.utils.ReflectionUtils.setCompletelyAccessible($gen_attributeSizes); } return (com.badlogic.gdx.utils.ObjectIntMap)$gen_attributeSizes.get(this); }
public void $setValue_attributeSizes(com.badlogic.gdx.utils.ObjectIntMap var) throws Exception { if($gen_attributeSizes == null) { $gen_attributeSizes = com.badlogic.gdx.graphics.glutils.ShaderProgram.class.getDeclaredField("attributeSizes"); net.ncguy.argent.utils.ReflectionUtils.setCompletelyAccessible($gen_attributeSizes); } $gen_attributeSizes.set(this, (com.badlogic.gdx.utils.ObjectIntMap)var); }
public LevelResult(ObjectIntMap<Die> addedExperience, ObjectMap<Fraction, Player> players, Player viewer) { this.addedExperience = addedExperience; this.players = players; this.viewer = viewer; }
@Override public IFuture<Void> visualize(final IceStormResult result) { final Future<Void> future = new Future<Void>(); final ParticleActor particleActor = new ParticleActor("ability-" + result.ability.name).freeOnComplete(); particleActor.getColor().a = 0; final Vector2 position = tmp.set(result.coordinate.x() + 0.5f, result.coordinate.y() + 0.5f).scl(ViewController.CELL_SIZE); particleActor.setPosition(position.x, position.y + 160); visualizer.viewController.effectLayer.addActor(particleActor); SoundManager.instance.playSound("ability-fireball"); visualizer.viewController.scroller.centerOn(result.coordinate.x(), result.coordinate.y()); particleActor.addAction(alpha(1f, 0.5f)); particleActor.addAction(sequence( moveTo(position.x, position.y, 1f), run(new Runnable() { @Override public void run() { particleActor.effect.allowCompletion(); final ParticleActor hitActor = new ParticleActor("ability-" + result.ability.name + "-hit").freeOnComplete(); hitActor.setPosition(position.x, position.y); visualizer.viewController.spawnLayer.addActor(hitActor); SoundManager.instance.playSound("ability-freeze-hit"); visualizer.viewController.world.stage.addAction(Actions.delay(0.5f, Actions.run(future))); if (result.targets.size == 0) return; for (ObjectIntMap.Entry<Creature> e : result.targets) { showFreeze(e.key); } } }) )); return future; }
public void setPotions(ObjectIntMap<Ability> potionCount) { potions.clear(); for (Ability potion : potionCount.keys()) { int currentCount = potions.get(potion, 0); int newCount = potionCount.get(potion, 0); if (currentCount != newCount) { potions.put(potion, newCount); onPotionCountChanged.dispatch(potion); } } }
public boolean canWithdraw(ObjectIntMap<Item> items) { for (Item item : items.keys()) { int count = items.get(item, 0); if (count > this.items.get(item, 0)) return false; } return true; }
public int potionsCount() { int r = 0; ObjectIntMap.Values v = potions.values(); while (v.hasNext()) { r += v.next(); } return r; }
public int itemsCount(Item.Type type) { int r = 0; for (ObjectIntMap.Entry<Item> e : items.entries()) { if (e.key.type == type) r += e.value; } return r; }
public Die(ProfessionDescription profession, String name, int exp, Array<Ability> abilities, ObjectIntMap<Ability> inventory) { this.profession = profession; this.name = name; this.exp = exp; this.abilities = abilities; this.inventory = inventory; Iterator<Ability> it = abilities.iterator(); while (it.hasNext()) { Ability ability = it.next(); if (ability != null && !profession.ignoreRequirements && (!ability.requirement.isSatisfied(this))) { inventory.getAndIncrement(ability, 0, 1); it.remove(); } } int used = getUsedSkill(); int total = getTotalSkill(); if (used > total) { System.out.print(name + " has skill overdraft, " + used + " > " + total + ", inventory = "); } while (abilities.size > 0 && getUsedSkill() > getTotalSkill()) { Ability popped = abilities.pop(); if (popped != null) inventory.getAndIncrement(popped, 0, 1); } if (used > total) System.out.println(inventory); while (abilities.size < 6) abilities.add(null); }
private IActionResult calcResult(Creature creature, Grid2D.Coordinate cell) { Vector2 position = tmp.set(cell.x(), cell.y()); Array<Creature> underAttack = new Array<Creature>(); Array<Creature> killed = new Array<Creature>(); ObjectIntMap<Creature> expResults = new ObjectIntMap<Creature>(); for (int i = cell.x() - MathUtils.ceil(radius); i <= cell.x() + radius; i++) { for (int j = cell.y() - MathUtils.ceil(radius); j <= cell.y() + radius; j++) { if (position.dst(i, j) <= radius) { WorldObject object = creature.world.get(i, j); if (object instanceof Creature && ((Creature) object).get(Attribute.canBeSelected)) { underAttack.add((Creature) object); } } } } for (Creature c : underAttack) { int attackLevel = (c.getX() == cell.x() && c.getY() == cell.y()) ? this.epicenterAttackLevel : this.attackLevel; int defenceLevel = c.get(Attribute.defenceFor(attackType)); if (attackLevel > defenceLevel) { killed.add(c); if (creature.inRelation(Creature.CreatureRelation.enemy, c)) { expResults.getAndIncrement(creature, 0, ExpHelper.expForKill(creature, c)); } } else { if (creature.inRelation(Creature.CreatureRelation.enemy, c)) { expResults.put(c, ExpHelper.expForDefence(creature, c)); } else { expResults.put(c, ExpHelper.MIN_EXP); } } } return new FirestormResult(creature, owner, underAttack, killed, expResults, cell); }
private IActionResult calcResult(Creature creature, Grid2D.Coordinate coordinate) { ProfessionDescription profession = Config.professions.get(professionName); Array<Ability> abilities = new Array<Ability>(); for (String abilityName : abilityNames) { abilities.add(Config.abilities.get(abilityName)); } Die die = new Die(profession, summonedName, 10000000, abilities, new ObjectIntMap<Ability>()); Creature summoned = new Creature(die, creature.player, creature.player.fraction + "@s-" + creature.player.nextSummonedId()); summoned.set(Attribute.canBeResurrected, Boolean.FALSE); return new SummonResult(owner, creature, coordinate, summoned); }
public ChainLightningResult(Creature caster, Ability ability, Array<Creature> chain, Array<Creature> killed, ObjectIntMap<Creature> addedExp) { super(); this.caster = caster; this.ability = ability; this.chain = chain; this.killed = killed; this.addedExp = addedExp; }
public FirestormResult(Creature caster, Ability ability, Array<Creature> underAttack, Array<Creature> killed, ObjectIntMap<Creature> addedExp, Grid2D.Coordinate cell) { super(); this.caster = caster; this.ability = ability; this.underAttack = underAttack; this.killed = killed; this.addedExp = addedExp; this.cell = cell; }
public static Comparator<? super Ability> countComparator(UserData userData) { final ObjectIntMap<Ability> counts = new ObjectIntMap<Ability>(); for (Die die : userData.dice()) { for (ObjectIntMap.Entry<Ability> e : die.inventory) counts.getAndIncrement(e.key, e.value, e.value); for (Ability ability : die.abilities) if (ability != null) counts.getAndIncrement(ability, 0, 1); } return new Comparator<Ability>() { @Override public int compare(Ability o1, Ability o2) { return counts.get(o1, 0) - counts.get(o2, 0); } }; }
private void awaitSpawning(final PvpPlayState state) { Logger.debug("server: await for spawning of other clients"/*, new RuntimeException()*/); final ObjectMap<IParticipant, Spawned> data = new ObjectMap<IParticipant, Spawned>(); register(SpawnedToServer.class, new IMessageProcessor<SpawnedToServer>() { int toSpawn = session.getAll().size; @Override public void receive(IParticipant from, SpawnedToServer message) { Player player = state.participantsToPlayers.get(from); data.put(from, new Spawned(message.dice, message.potions, player.fraction)); ObjectIntMap<Item> rolled = session.getMode().metaLevel.drop.roll(); applyDrop(rolled, message.dice); if (data.size == toSpawn) { for (ObjectMap.Entry<String, ? extends IParticipant> entry : session.getAll().entries()) { IParticipant spawnedParticipant = entry.value; Spawned spawned = data.get(spawnedParticipant); for (IParticipant toNotify : session.getAll().values()) { if (spawnedParticipant == toNotify) continue; Logger.debug("server: notify " + toNotify + " about spawned " + spawned); sendTo(toNotify, spawned); } } Array<? extends Creature> creatures = state.world.byType(Creature.class); creatures.sort(Ability.INITIATIVE_COMPARATOR); unregister(SpawnedToServer.class); Logger.debug("server: start!"); awaitRestart(); sendToAll(new Start(creatures)); } } }); }
private void updateResult() { if (outputResult != null) { outputResult.remove(); outputResult = null; } res.clear(); for (ItemIcon i : inputs.values()) { if (i != null) { res.getAndIncrement(i.item, 0, 1); } } Ability ability = null; for (Ability check : recipes) { ObjectIntMap<Item> cost = check.ingredients; if (inputMatches(res, cost)) { ability = check; break; } } if (ability != null) { outputResult = new AbilityIcon(ability); addActor(outputResult); outputResult.setPosition( output.getX() + (output.getWidth() - outputResult.getWidth()) * 0.5f, output.getY() + (output.getHeight() - outputResult.getHeight()) * 0.5f ); } }
public static boolean isEmpty(ObjectIntMap<?> potions) { ObjectIntMap.Values values = potions.values(); while (values.hasNext()) { if (values.next() != 0) return false; } return true; }
public static int countPositive(ObjectIntMap<?> items) { int i = 0; for (ObjectIntMap.Entry<?> entry : items) { if (entry.value > 0) i++; } return i; }
/** lazily intialized in {@link Keys#valueOf(String)} */ private static void initializeKeyNames () { keyNames = new ObjectIntMap<String>(); for (int i = 0; i < 256; i++) { String name = toString(i); if (name != null) keyNames.put(name, i); } }
/** * Compute the target influence on all tiles around the starting position. * <p> * Note: resulting target can be negative. It stops on tiles where there is no * influence from source AND target is not positive. */ private ObjectIntMap<Influence> getTargetInfluence(Entity source, MapPosition startPos, int startingPower) { Map<Terrain, Integer> costs = terrainCosts(source); Queue<Pos> frontier = new PriorityQueue<>(); frontier.add(new Pos(startPos, startingPower)); ObjectIntMap<Influence> targets = new ObjectIntMap<>(); targets.put(map.getInfluenceAt(startPos), startingPower); while (!frontier.isEmpty()) { Pos current = frontier.poll(); for (MapPosition next : map.getNeighbors(current.pos)) { Influence inf = map.getInfluenceAt(next); if (!inf.terrain.moveBlock()) { int newTarget = current.target - costs.get(inf.terrain); int oldTarget = targets.get(inf, Integer.MIN_VALUE); if (newTarget > oldTarget) { targets.put(inf, newTarget); /* * Increase only one tile from already influenced tiles. Decreases * wherever we have some influence (makes no sense to decrease * elsewhere. */ if (inf.hasInfluence(source)) frontier.offer(new Pos(next, newTarget)); } } } } return targets; }
protected ObjectIntMap create (int size) { return new ObjectIntMap(size); }
public void setPotions(ObjectIntMap<Ability> potions) { this.potions.putAll(potions); }
public void earn(ObjectIntMap<Item> items) { for (Item item : items.keys()) { earnedItems.getAndIncrement(item, 0, items.get(item, 0)); } }
public void withdrawItems(ObjectIntMap<Item> cost) { for (Item item : cost.keys()) { decrementItemCount(item, cost.get(item, 0)); } }
public Die() { abilities = new Array<Ability>(); inventory = new ObjectIntMap<Ability>(); }