/** * Returns the individual player assigned the index parameter. */ protected IPlayer getPlayer(int idx) { return getGame().getPlayer(idx); }
private void receiveEntityAdd(Packet packet) { @SuppressWarnings("unchecked") List<Integer> entityIds = (List<Integer>) packet.getObject(0); @SuppressWarnings("unchecked") List<Entity> entities = (List<Entity>) packet.getObject(1); assert (entityIds.size() == entities.size()); for (int i = 0; i < entityIds.size(); i++) { assert (entityIds.get(i) == entities.get(i).getId()); } getGame().addEntities(entities); }
/** * Loads the turn list from the data in the packet */ @SuppressWarnings("unchecked") private void receiveTurns(Packet packet) { getGame().setTurnVector((List<GameTurn>) packet.getObject(0)); }
/** * Loads the board from the data in the net command. */ private void receiveBoard(Packet c) { Board newBoard = (Board) c.getObject(0); getGame().setBoard(newBoard); }
/** * Loads the entities from the data in the net command. */ @SuppressWarnings("unchecked") private void receiveEntities(Packet c) { List<Entity> newEntities = (List<Entity>) c.getObject(0); List<Entity> newOutOfGame = (List<Entity>) c.getObject(1); // Replace the entities in the game. getGame().setEntitiesVector(newEntities); if (newOutOfGame != null) { getGame().setOutOfGameEntitiesVector(newOutOfGame); } }
@SuppressWarnings("unchecked") private void receiveSendingMinefields(Packet packet) { getGame().setMinefields((Vector<Minefield>) packet.getObject(0)); }
@SuppressWarnings("unchecked") private void receiveIlluminatedHexes(Packet p) { getGame().setIlluminatedPositions((HashSet<Coords>) p.getObject(0)); }
@SuppressWarnings("unchecked") private void receiveDeployMinefields(Packet packet) { getGame().addMinefields((Vector<Minefield>) packet.getObject(0)); }
private void receiveRevealMinefield(Packet packet) { getGame().addMinefield((Minefield) packet.getObject(0)); }
private void receiveRemoveMinefield(Packet packet) { getGame().removeMinefield((Minefield) packet.getObject(0)); }
public Precognition(Princess owner) { this.owner = owner; this.game = new Game(); getGame().addGameListener(new GameListenerAdapter() { @Override public void gameEntityChange(GameEntityChangeEvent changeEvent) { getEventsToProcess().add(changeEvent); wakeUp(); } @Override public void gamePhaseChange(GamePhaseChangeEvent changeEvent) { getEventsToProcess().add(changeEvent); wakeUp(); } }); setPathEnumerator(new PathEnumerator(owner, getGame())); // Initialize ECM Info, especially important if Princess added mid-game ecmInfo = ComputeECM.computeAllEntitiesECMInfo( getGame().getEntitiesVector()); }
@SuppressWarnings("unchecked") private void receiveUpdateMinefields(Packet packet) { // only update information if you know about the minefield Vector<Minefield> newMines = new Vector<>(); for (Minefield mf : (Vector<Minefield>) packet.getObject(0)) { if (getOwner().getLocalPlayer().containsMinefield(mf)) { newMines.add(mf); } } if (newMines.size() > 0) { getGame().resetMinefieldDensity(newMines); } }
private void receiveEntityRemove(Packet packet) { @SuppressWarnings("unchecked") List<Integer> entityIds = (List<Integer>) packet.getObject(0); int condition = packet.getIntValue(1); // Move the unit to its final resting place. getGame().removeEntities(entityIds, condition); }
@SuppressWarnings("unchecked") private void receiveBuildingCollapse(Packet packet) { getGame().getBoard().collapseBuilding((Vector<Coords>) packet.getObject(0)); }
@SuppressWarnings("unchecked") private void receiveBuildingUpdate(Packet packet) { getGame().getBoard().updateBuildings((Vector<Building>) packet.getObject(0)); }
/** * Loads entity update data from the data in the net command. */ @SuppressWarnings("unchecked") private void receiveEntityUpdate(Packet c) { int eindex = c.getIntValue(0); Entity entity = (Entity) c.getObject(1); Vector<UnitLocation> movePath = (Vector<UnitLocation>) c.getObject(2); // Replace this entity in the game. getGame().setEntity(eindex, entity, movePath); }
/** * receive and process an entity nova network mode change packet * * @param c The packet containing the change. */ private void receiveEntityNovaNetworkModeChange(Packet c) { final String METHOD_NAME = "receiveEntityNovaNetworkModeChange(Packet)"; try { int entityId = c.getIntValue(0); String networkID = c.getObject(1).toString(); Entity e = getGame().getEntity(entityId); if (e != null) { e.setNewRoundNovaNetworkString(networkID); } } catch (Exception ex) { getOwner().log(getClass(), METHOD_NAME, ex); } }
@SuppressWarnings("unchecked") private void receiveEntityVisibilityIndicator(Packet packet) { Entity e = getGame().getEntity(packet.getIntValue(0)); if (e != null) { // we may not have this entity due to double blind e.setEverSeenByEnemy(packet.getBooleanValue(1)); e.setVisibleToEnemy(packet.getBooleanValue(2)); e.setDetectedByEnemy(packet.getBooleanValue(3)); e.setWhoCanSee((Vector<IPlayer>)packet.getObject(4)); e.setWhoCanDetect((Vector<IPlayer>)packet.getObject(5)); // this next call is only needed sometimes, but we'll just // call it everytime getGame().processGameEvent(new GameEntityChangeEvent(this, e)); } }
public void run() { final String METHOD_NAME = "run()"; getOwner().methodBegin(getClass(), METHOD_NAME); try { // todo There's probably a better way to handle this than a loop that only exits on an error. //noinspection InfiniteLoopStatement while (!getDone().get()) { if (!getEventsToProcess().isEmpty()) { processGameEvents(); ecmInfo = ComputeECM.computeAllEntitiesECMInfo( getGame().getEntitiesVector()); } else if (!getDirtyUnits().isEmpty()) { Entity entity = getGame().getEntity(getDirtyUnits().pollFirst()); if ((entity != null) && isEntityOnMap(entity)) { unPause(); getOwner().log(getClass(), METHOD_NAME, "recalculating paths for " + entity.getDisplayName()); getPathEnumerator().recalculateMovesFor(entity); getOwner().log(getClass(), METHOD_NAME, "finished recalculating paths for " + entity .getDisplayName()); } } else if (getWaitWhenDone().get()) { waitForUnpause(); // paused for a reason } else { waitForUnpause(); // idling because there's nothing to do } } } finally { getOwner().methodEnd(getClass(), METHOD_NAME); } }
/** * Receives player information from the message packet. */ private void receivePlayerInfo(Packet c) { int pindex = c.getIntValue(0); IPlayer newPlayer = (IPlayer) c.getObject(1); if (getPlayer(newPlayer.getId()) == null) { getGame().addPlayer(pindex, newPlayer); } else { getGame().setPlayer(pindex, newPlayer); } PreferenceManager.getClientPreferences().setLastPlayerColor( newPlayer.getColorIndex()); PreferenceManager.getClientPreferences().setLastPlayerCategory( newPlayer.getCamoCategory()); PreferenceManager.getClientPreferences().setLastPlayerCamoName( newPlayer.getCamoFileName()); }