📄 game.java
字号:
playerIds.put(new Integer(id), player); updatePlayer(player); } protected void updatePlayer(Player player) { processGameEvent(new GamePlayerChangeEvent(this,player)); } public void removePlayer(int id) { Player playerToRemove = getPlayer(id); players.removeElement(playerToRemove); playerIds.remove(new Integer(id)); processGameEvent(new GamePlayerChangeEvent(this,playerToRemove)); } /** * Returns the number of entities owned by the player, regardless of * their status, as long as they are in the game. */ public int getEntitiesOwnedBy(Player player) { int count = 0; for (Enumeration i = entities.elements(); i.hasMoreElements();) { Entity entity = (Entity)i.nextElement(); if (entity.getOwner().equals(player)) { count++; } } return count; } /** * Returns the number of entities owned by the player, regardless of * their status. */ public int getAllEntitiesOwnedBy(Player player) { int count = 0; for (Enumeration i = entities.elements(); i.hasMoreElements();) { Entity entity = (Entity)i.nextElement(); if (entity.getOwner().equals(player)) { count++; } } for (Enumeration i = vOutOfGame.elements(); i.hasMoreElements();) { Entity entity = (Entity)i.nextElement(); if (entity.getOwner().equals(player)) { count++; } } return count; } /** * Returns the number of non-destroyed entityes owned by the player */ public int getLiveEntitiesOwnedBy(Player player) { int count = 0; for (Enumeration i = entities.elements(); i.hasMoreElements();) { Entity entity = (Entity)i.nextElement(); if (entity.getOwner().equals(player) && !entity.isDestroyed()) { count++; } } return count; } /** * Returns the number of non-destroyed deployed entities owned * by the player. Ignore offboard units and captured Mek pilots. */ public int getLiveDeployedEntitiesOwnedBy(Player player) { int count = 0; for (Enumeration i = entities.elements(); i.hasMoreElements();) { Entity entity = (Entity)i.nextElement(); if ( entity.getOwner().equals(player) && !entity.isDestroyed() && entity.isDeployed() && !entity.isOffBoard() && !entity.isCaptured() ) { count++; } } return count; } /** * Returns true if the player has a valid unit with the Tactical Genius * pilot special ability. */ public boolean hasTacticalGenius(Player player) { for (Enumeration i = entities.elements(); i.hasMoreElements();) { Entity entity = (Entity)i.nextElement(); if (entity.getCrew().getOptions().booleanOption("tactical_genius") && entity.getOwner().equals(player) && !entity.isDestroyed() && entity.isDeployed() && !entity.getCrew().isUnconscious()) { return true; } } return false; } /** * Returns how much higher than 50 or lower than -30 * degrees, divided by ten, rounded up, the temperature is */ public int getTemperatureDifference() { int i = 0; if (getOptions().intOption("temperature") >= -30 && getOptions().intOption("temperature") <= 50 ) return i; else if (getOptions().intOption("temperature") < -30) { do { i++; } while (getOptions().intOption("temperature") + i * 10 < -30); return i; } else do { i++; } while (getOptions().intOption("temperature") - i * 10 > 50); return i; } /** * Get a vector of entity objects that are "acceptable" to attack with this entity */ public Vector getValidTargets(Entity entity) { Vector ents = new Vector(); boolean friendlyFire = getOptions().booleanOption("friendly_fire"); for (Enumeration i = entities.elements(); i.hasMoreElements();) { Entity otherEntity = (Entity)i.nextElement(); // Even if friendly fire is acceptable, do not shoot yourself // Enemy units not on the board can not be shot. if ( otherEntity.getPosition() != null && !otherEntity.isOffBoard() && ( entity.isEnemyOf(otherEntity) || (friendlyFire && entity.getId() != otherEntity.getId()) ) ) { ents.addElement( otherEntity ); } } return ents; } /** * Returns true if this phase has turns. If false, the phase is simply * waiting for everybody to declare "done". */ public boolean phaseHasTurns(int phase) { switch (phase) { case PHASE_SET_ARTYAUTOHITHEXES : case PHASE_DEPLOY_MINEFIELDS : case PHASE_DEPLOYMENT : case PHASE_MOVEMENT : case PHASE_FIRING : case PHASE_PHYSICAL : case PHASE_TARGETING : case PHASE_OFFBOARD : return true; default : return false; } } /** * Returns the current GameTurn object */ public GameTurn getTurn() { if (turnIndex < 0 || turnIndex >= turnVector.size()) { return null; } return (GameTurn)turnVector.elementAt(turnIndex); } /** Changes to the next turn, returning it. */ public GameTurn changeToNextTurn() { turnIndex++; return getTurn(); } /** Resets the turn index to -1 (awaiting first turn) */ public void resetTurnIndex() { turnIndex = -1; } /** Returns true if there is a turn after the current one */ public boolean hasMoreTurns() { return turnVector.size() > (turnIndex + 1); } /** Inserts a turn that will come directly after the current one */ public void insertNextTurn(GameTurn turn) { turnVector.insertElementAt(turn, turnIndex + 1); } /** Returns an Enumeration of the current turn list */ public Enumeration getTurns() { return turnVector.elements(); } /** Returns the current turn index */ public int getTurnIndex() { return turnIndex; } /** Sets the current turn index */ public void setTurnIndex(int turnIndex) { this.turnIndex = turnIndex; processGameEvent(new GameTurnChangeEvent(this,getPlayer(getTurn().getPlayerNum()))); } /** Returns the current turn vector */ public Vector getTurnVector() { return turnVector; } /** Sets the current turn vector */ public void setTurnVector(Vector turnVector) { this.turnVector = turnVector; } public int getPhase() { return phase; } public void setPhase(int phase) { final int oldPhase = this.phase; this.phase = phase; // Handle phase-specific items. switch (phase) { case PHASE_LOUNGE : reset(); break; case IGame.PHASE_MOVEMENT : resetActions(); break; case IGame.PHASE_FIRING : resetActions(); break; case IGame.PHASE_PHYSICAL : resetActions(); break; case IGame.PHASE_INITIATIVE : resetActions(); resetCharges(); resetLayMinefieldActions(); break; // TODO Is there better solution to handle charges? case IGame.PHASE_PHYSICAL_REPORT: case IGame.PHASE_END: resetCharges(); resetLayMinefieldActions(); break; } processGameEvent(new GamePhaseChangeEvent(this, oldPhase, phase)); } public int getLastPhase() { return lastPhase; } public void setLastPhase(int lastPhase) { this.lastPhase = lastPhase; } public void setDeploymentComplete(boolean deploymentComplete) { this.deploymentComplete = deploymentComplete; } public boolean isDeploymentComplete() { return deploymentComplete; } /** * Sets up up the hashtable of who deploys when */ public void setupRoundDeployment() { deploymentTable = new Hashtable(); for ( int i = 0; i < entities.size(); i++ ) { Entity ent = (Entity)entities.elementAt(i); if (ent.isDeployed()) { continue; } Vector roundVec = (Vector)deploymentTable.get(new Integer(ent.getDeployRound())); if ( null == roundVec ) { roundVec = new Vector(); deploymentTable.put(new Integer(ent.getDeployRound()), roundVec); } roundVec.addElement(ent); lastDeploymentRound = Math.max(lastDeploymentRound, ent.getDeployRound()); } } /** * Checks to see if we've past our deployment completion */ public void checkForCompleteDeployment() { setDeploymentComplete(lastDeploymentRound < getRoundCount()); } /** * Check to see if we should deploy this round */ public boolean shouldDeployThisRound() { return shouldDeployForRound(getRoundCount()); } public boolean shouldDeployForRound(int round) { Vector vec = getEntitiesToDeployForRound(round); return ( ((null == vec) || (vec.size() == 0)) ? false : true); } private Vector getEntitiesToDeployForRound(int round) { return (Vector)deploymentTable.get(new Integer(round)); } /** * Clear this round from this list of entities to deploy */ public void clearDeploymentThisRound() { deploymentTable.remove(new Integer(getRoundCount())); } /** * Returns a vector of entities that have not yet deployed */ public Vector getUndeployedEntities() { Vector entList = new Vector(); Enumeration iter = deploymentTable.elements(); while ( iter.hasMoreElements() ) { Vector vecTemp = (Vector)iter.nextElement(); for ( int i = 0; i < vecTemp.size(); i++ ) { entList.addElement(vecTemp.elementAt(i)); } } return entList; } /** * Returns an enumeration of all the entites in the game. */ public Enumeration getEntities() { return entities.elements(); } public Entity getPreviousEntityFromList (Entity current) { if (current!=null && entities != null && entities.contains(current)) { int prev = entities.indexOf(current) - 1; if (prev < 0) prev = entities.size() - 1; //wrap around to end return (Entity)entities.elementAt(prev); } return null; } public Entity getNextEntityFromList (Entity current) { if (current!=null && entities!=null && entities.contains(current)) { int next = entities.indexOf(current)+1; if (next >= entities.size()) next = 0; // wrap-around to begining return (Entity)entities.elementAt(next); } return null; } /** * Returns the actual vector for the entities */ public Vector getEntitiesVector() { return entities; } public void setEntitiesVector(Vector entities) { this.entities = entities; reindexEntities(); processGameEvent(new GameEntityNewEvent(this, entities)); } /** * Returns the actual vector for the out-of-game entities */ public Vector getOutOfGameEntitiesVector() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -