public void addEntity(int id, Entity entity) { // Disregard the passed id, addEntity(Entity) pulls the id from the // Entity instance. addEntity(entity); }
public void addEntity(Entity entity) { addEntity(entity, true); }
public void addEntities(List<Entity> entities) { for (int i = 0; i < entities.size(); i++) { addEntity(entities.get(i), false); } // We need to delay calculating BV until all units have been added because // C3 network connections will be cleared if the master is not in the game yet. entities.forEach(e -> e.setInitialBV(e.calculateBattleValue(false, false))); processGameEvent(new GameEntityNewEvent(this, entities)); }
/** * This function reloads the game entities into the game at the end of scenario resolution, so that entities are * properly updated and destroyed ones removed */ public void reloadGameEntities() { game.reset(); for (Map.Entry<UUID, Unit> u : units.entrySet()) { Entity en = u.getValue().getEntity(); if (null != en) { game.addEntity(en.getId(), en); } } }
public synchronized void setEntity(int id, Entity entity, Vector<UnitLocation> movePath) { final Entity oldEntity = getEntity(id); if (oldEntity == null) { addEntity(entity); } else { entity.setGame(this); entities.set(entities.indexOf(oldEntity), entity); entityIds.put(id, entity); // Get the collection of positions HashSet<Coords> oldPositions = oldEntity.getOccupiedCoords(); // Update position lookup table updateEntityPositionLookup(entity, oldPositions); // Not sure if this really required if (id > lastEntityId) { lastEntityId = id; } processGameEvent( new GameEntityChangeEvent(this, entity, movePath, oldEntity)); } assert (entities.size() == entityIds.size()) : "Set Entity Failed"; }
private void addUnit(Unit u) { MekHQ.getLogger().log(getClass(), "addUnit()", LogLevel.INFO, //$NON-NLS-1$ "Adding unit: (" + u.getId() + "):" + u); //$NON-NLS-1$ units.put(u.getId(), u); checkDuplicateNamesDuringAdd(u.getEntity()); // Assign an entity ID to our new unit if (Entity.NONE == u.getEntity().getId()) { u.getEntity().setId(game.getNextEntityId()); } game.addEntity(u.getEntity().getId(), u.getEntity()); }
void exportMUL(ForceDescriptor fd) { ArrayList<Entity> list = new ArrayList<>(); fd.addAllEntities(list); //Create a fake game so we can write the entities to a file without adding them to the real game. Game game = new Game(); //Add a player to prevent complaining in the log file Player p = new Player(1, "Observer"); game.addPlayer(1, p); game.setOptions(clientGui.getClient().getGame().getOptions()); list.stream().forEach(en -> { en.setOwner(p); // If we don't set the id, the first unit will be left at -1, which in most cases is interpreted // as no entity en.setId(game.getNextEntityId()); game.addEntity(en); }); configureNetworks(fd); clientGui.saveListFile(list, clientGui.getClient().getLocalPlayer().getName()); }
en.setId(game.getNextEntityId()); game.addEntity(en.getId(), en);
unit.getEntity().setId(game.getNextEntityId()); game.addEntity(unit.getEntity().getId(), unit.getEntity());
entity.setId(entityId); ++ entityId; g.addEntity(entity);