public void rollInitAndResolveTies() { if (getOptions().booleanOption(OptionsConstants.RPG_INDIVIDUAL_INITIATIVE)) { Vector<TurnOrdered> vRerolls = new Vector<TurnOrdered>(); for (int i = 0; i < entities.size(); i++) { Entity e = entities.get(i); if (initiativeRerollRequests.contains(getTeamForPlayer(e.getOwner()))) { vRerolls.add(e); } } TurnOrdered.rollInitAndResolveTies(getEntitiesVector(), vRerolls, false); } else { TurnOrdered.rollInitAndResolveTies(teams, initiativeRerollRequests, getOptions().booleanOption(OptionsConstants.INIT_INITIATIVE_STREAK_COMPENSATION)); } initiativeRerollRequests.removeAllElements(); }
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"; }
/** * Determine if the given set of coordinates has a gun emplacement on the roof of a building. * @param c The coordinates to check */ public boolean hasRooftopGunEmplacement(Coords c) { Building building = getBoard().getBuildingAt(c); if(building == null) { return false; } IHex hex = getBoard().getHex(c); for (Entity entity : getEntitiesVector(c, true)) { if (entity.hasETypeFlag(Entity.ETYPE_GUN_EMPLACEMENT) && entity.getElevation() == hex.ceiling()) { return true; } } return false; }
reset(); break; case PHASE_TARGETING: resetActions(); break; case PHASE_MOVEMENT: resetActions(); break; case PHASE_FIRING: resetActions(); break; case PHASE_PHYSICAL: resetActions(); break; case PHASE_DEPLOYMENT: resetActions(); break; case PHASE_INITIATIVE: resetActions(); resetCharges(); resetRams(); break; resetCharges(); resetRams(); break; default: processGameEvent(new GamePhaseChangeEvent(this, oldPhase, phase));
public boolean gameTimerIsExpired() { return ((getOptions().booleanOption(OptionsConstants.VICTORY_USE_GAME_TURN_LIMIT)) && (getRoundCount() == getOptions() .intOption(OptionsConstants.VICTORY_GAME_TURN_LIMIT))); }
/** * 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); } } }
Game g = new Game(); g.addPlayer(player.getId(), player); entity.setId(entityId); ++ entityId; g.addEntity(entity); g.getOptions().initialize(); String optionFile = p.getString(PARAM_GAME_OPTIONS_FILE); if (optionFile == null) { g.getOptions().loadOptions(); } else { g.getOptions().loadOptions(new MegaMekFile(scenarioFile.getParentFile(), optionFile).getFile(), true); g.getPlanetaryConditions().determineWind(); g.setupTeams(); g.setPhase(IGame.Phase.PHASE_STARTING_SCENARIO); g.setupRoundDeployment(); g.setExternalGameId(parseExternalGameId(p)); g.setVictoryContext(new HashMap<String, Object>()); g.createVictoryConditions();
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()); }
Mockito.when(mockGame.getBoard()).thenReturn(mockBoard); Mockito.when(mockGame.getSmokeCloudList()).thenReturn( new ArrayList<SmokeCloud>()); Mockito.when(mockGame.getOptions()).thenReturn(mockOptions); Mockito.when(mockGame.getEntitiesVector()).thenReturn(entitiesVector); Mockito.when(mockGame.getEntitiesVector()).thenReturn(entitiesVector); Mockito.when(ae.getECCMInfo()).thenReturn(null); entitiesVector.add(ae); entitiesVector.add(additionalEnemy); Mockito.when(mockGame.getEntitiesVector()).thenReturn(entitiesVector); result = ComputeECM.isAffectedByECM(ae, aePos, aePos); TestCase.assertEquals(false, result);
if (getOptions().booleanOption(OptionsConstants.INIT_INF_MOVE_MULTI) && (entity instanceof Infantry) && (phase == Phase.PHASE_MOVEMENT)) { if ((getInfantryLeft(entity.getOwnerId()) % getOptions().intOption( OptionsConstants.INIT_INF_PROTO_MOVE_MULTI)) != 1) { if (hasMoreTurns()) { GameTurn nextTurn = turnVector.elementAt(turnIndex + 1); if (nextTurn instanceof GameTurn.EntityClassTurn) { if (getOptions().booleanOption(OptionsConstants.INIT_PROTOS_MOVE_MULTI) && (entity instanceof Protomech) && (phase == Phase.PHASE_MOVEMENT)) { if ((getProtomechsLeft(entity.getOwnerId()) % getOptions() .intOption(OptionsConstants.INIT_INF_PROTO_MOVE_MULTI)) != 1) { if (hasMoreTurns()) { GameTurn nextTurn = turnVector.elementAt(turnIndex + 1); if (nextTurn instanceof GameTurn.EntityClassTurn) { if (getOptions().booleanOption(OptionsConstants.ADVGRNDMOV_VEHICLE_LANCE_MOVEMENT) && (entity instanceof Tank) && (phase == Phase.PHASE_MOVEMENT)) { if ((getVehiclesLeft(entity.getOwnerId()) % getOptions() .intOption(OptionsConstants.ADVGRNDMOV_VEHICLE_LANCE_MOVEMENT_NUMBER)) != 1) { if (hasMoreTurns()) { GameTurn nextTurn = turnVector.elementAt(turnIndex + 1); if (nextTurn instanceof GameTurn.EntityClassTurn) {
/** * Return a List of Entities at Coords <code>c</code> * * @param c The coordinates to check * @return <code>List<Entity></code> */ public List<Entity> getEntitiesVector(Coords c) { return getEntitiesVector(c, false); }
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()); }
/** * Returns true if the player has any valid units this turn that are not * infantry, not protomechs, or not either of those. This method is * utitilized by the "A players Infantry moves after that players other * units", and "A players Protomechs move after that players other units" * options. */ public boolean checkForValidNonInfantryAndOrProtomechs(int playerId) { Iterator<Entity> iter = getPlayerEntities(getPlayer(playerId), false) .iterator(); while (iter.hasNext()) { Entity entity = iter.next(); boolean excluded = false; if ((entity instanceof Infantry) && getOptions().booleanOption(OptionsConstants.INIT_INF_MOVE_LATER)) { excluded = true; } else if ((entity instanceof Protomech) && getOptions().booleanOption(OptionsConstants.INIT_PROTOS_MOVE_LATER)) { excluded = true; } if (!excluded && getTurn().isValidEntity(entity, this)) { return true; } } return false; }
public Campaign() { id = UUID.randomUUID(); game = new Game(); player = new Player(0, "self"); game.addPlayer(0, player); currentReport = new ArrayList<String>(); currentReportHTML = ""; gameOptions.initialize(); gameOptions.getOption("year").setValue(getGameYear()); game.setOptions(gameOptions); customs = new ArrayList<String>(); shoppingList = new ShoppingList();
entityIds.put(new Integer(id), entity); } else { id = getNextEntityId(); entity.setId(id); entityIds.put(id, entity); updateEntityPositionLookup(entity, null); && getOptions().booleanOption(OptionsConstants.RPG_CONDITIONAL_EJECTION)) { ((Mech) entity).setAutoEject(true); if (((Mech) entity).hasCase() if (genEvent) { entity.setInitialBV(entity.calculateBattleValue(false, false)); processGameEvent(new GameEntityNewEvent(this, entity));
Mockito.when(mockGame.getBoard()).thenReturn(mockBoard); Mockito.when(mockGame.getSmokeCloudList()).thenReturn( new ArrayList<SmokeCloud>()); Mockito.when(mockGame.getOptions()).thenReturn(mockOptions);
boolean useTeamInit = getOptions().getOption(OptionsConstants.BASE_TEAM_INITIATIVE) .booleanValue(); for (Enumeration<IPlayer> i = getPlayers(); i.hasMoreElements(); ) { final IPlayer player = i.nextElement(); for (Enumeration<IPlayer> i = getPlayers(); i.hasMoreElements(); ) { final IPlayer player = i.nextElement(); if (player.getTeam() == t) { if ((teams != null) && (getPhase() != Phase.PHASE_LOUNGE)) { for (Team newTeam : initTeams) { for (Team oldTeam : teams) {
public void createVictoryConditions() { victory = new Victory(getOptions()); }
bv = new BoardView1(new Game(), null, null); bv.setPreferredSize(getSize()); bvc = bv.getComponent();
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)); }