Skip to content

Commit

Permalink
Removed getPlayersVector (depricated)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjhancock committed Sep 9, 2024
1 parent 1fb20a0 commit 30bd768
Show file tree
Hide file tree
Showing 16 changed files with 1,124 additions and 968 deletions.
4 changes: 2 additions & 2 deletions megamek/src/megamek/client/ui/swing/EditBotsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected void initialize() {
}

protected void refreshPlayers() {
ghostAndBotPlayers = game.getPlayersVector().stream()
ghostAndBotPlayers = game.getPlayersList().stream()
.filter(client -> client.isGhost() || client.isBot())
.sorted(Comparator.comparingInt(Player::getId)).collect(Collectors.toList());
ghostAndBotPlayers.forEach(player -> botConfigs.put(player, new BehaviorSettings()));
Expand Down Expand Up @@ -342,7 +342,7 @@ public Map<String, BehaviorSettings> getChangedBots() {
* Returns the result of the dialog with respect to selected princess bots to be
* kicked
* The result may be empty, but not null.
*
*
* @return a Set of bot player names to be kicked. May be empty but not null
*/
public Set<String> getKickBots() {
Expand Down
595 changes: 347 additions & 248 deletions megamek/src/megamek/client/ui/swing/MovementDisplay.java

Large diffs are not rendered by default.

72 changes: 43 additions & 29 deletions megamek/src/megamek/common/AbstractGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
import megamek.server.scriptedevent.TriggeredEvent;

/**
* This is a base class to derive all types of Game (TW, AS, BF, SBF...) from. Any such game will have players, units
* This is a base class to derive all types of Game (TW, AS, BF, SBF...) from.
* Any such game will have players, units
* (InGameObjects) and Forces (even if empty); the base class manages these.
*/
public abstract class AbstractGame implements IGame {
Expand All @@ -49,7 +50,10 @@ public abstract class AbstractGame implements IGame {
/** The players present in the game mapped to their id as key */
protected final ConcurrentHashMap<Integer, Player> players = new ConcurrentHashMap<>();

/** The InGameObjects (units such as Entity and others) present in the game mapped to their id as key */
/**
* The InGameObjects (units such as Entity and others) present in the game
* mapped to their id as key
*/
protected final ConcurrentHashMap<Integer, InGameObject> inGameObjects = new ConcurrentHashMap<>();

/** The teams present in the game */
Expand All @@ -62,35 +66,43 @@ public abstract class AbstractGame implements IGame {

/**
* This Map holds all game boards together with a unique ID for each.
* For the "legacy" Game that currently only allows a single board, that board always uses ID 0.
* To support game types that use board types other than hex boards, a superclass or interface should
* For the "legacy" Game that currently only allows a single board, that board
* always uses ID 0.
* To support game types that use board types other than hex boards, a
* superclass or interface should
* be used instead of Board in the future.
*/
private final Map<Integer, Board> gameBoards = new HashMap<>();

/**
* The forces present in the game. The top level force holds all forces and force-less entities
* The forces present in the game. The top level force holds all forces and
* force-less entities
* and should therefore not be shown.
*/
protected Forces forces = new Forces(this);

/**
* This map links deployment rounds to lists of Deployables that deploy in respective rounds. It only contains
* units/objects that are not yet deployed or will redeploy (returning Aeros, units going from one board to
* This map links deployment rounds to lists of Deployables that deploy in
* respective rounds. It only contains
* units/objects that are not yet deployed or will redeploy (returning Aeros,
* units going from one board to
* another if implemented). For those, the list is updated every round.
*/
private final Map<Integer, List<Deployable>> deploymentTable = new HashMap<>();

/**
* The round counter. It gets incremented before initiative; round 0 is initial deployment only.
* The round counter. It gets incremented before initiative; round 0 is initial
* deployment only.
*/
protected int currentRound = -1;

protected int turnIndex = AWAITING_FIRST_TURN;

/**
* This list contains all scripted events that may happen during the course of the game. This list
* should only ever be present on the server. Only the results of events should be sent to clients.
* This list contains all scripted events that may happen during the course of
* the game. This list
* should only ever be present on the server. Only the results of events should
* be sent to clients.
*/
protected final List<TriggeredEvent> scriptedEvents = new ArrayList<>();

Expand All @@ -114,12 +126,6 @@ public void addPlayer(int id, Player player) {
players.put(id, player);
}

@Override
@Deprecated
public Vector<Player> getPlayersVector() {
return new Vector<>(players.values());
}

@Override
@Deprecated
public Enumeration<Player> getPlayers() {
Expand Down Expand Up @@ -188,7 +194,7 @@ public void fireGameEvent(GameEvent event) {
}
// The iteration must allow and support concurrent modification of the list!
// Testing shows that a CopyOnWriteArrayList does not work
for (Enumeration<GameListener> e = gameListeners.elements(); e.hasMoreElements(); ) {
for (Enumeration<GameListener> e = gameListeners.elements(); e.hasMoreElements();) {
event.fireEvent(e.nextElement());
}
}
Expand All @@ -202,9 +208,11 @@ public void receiveBoard(int boardId, Board board) {

@Override
public void receiveBoards(Map<Integer, Board> boards) {
// cycle the entries so an event can be fired for each to allow listeners to register and unregister
// cycle the entries so an event can be fired for each to allow listeners to
// register and unregister
boards.forEach(this::receiveBoard);
// some old boards might not have been replaced by new ones, so clear the map and refill
// some old boards might not have been replaced by new ones, so clear the map
// and refill
gameBoards.clear();
gameBoards.putAll(boards);
}
Expand All @@ -231,14 +239,16 @@ public void setCurrentRound(int currentRound) {

/**
* Empties the list of pending EntityActions completely.
*
* @see #getActionsVector()
*/
public void clearActions() {
pendingActions.clear();
}

/**
* Removes all pending EntityActions by the InGameObject (Entity, unit) of the given ID from the list
* Removes all pending EntityActions by the InGameObject (Entity, unit) of the
* given ID from the list
* of pending actions.
*/
public void removeActionsFor(int id) {
Expand All @@ -253,25 +263,30 @@ public void removeAction(EntityAction action) {
}

/**
* Returns the pending EntityActions. Do not use to modify the actions; Arlith said: I will be
* Returns the pending EntityActions. Do not use to modify the actions; Arlith
* said: I will be
* angry. &gt;:[
*/
public List<EntityAction> getActionsVector() {
return Collections.unmodifiableList(pendingActions);
}

/**
* Adds the specified action to the list of pending EntityActions for this phase and fires a GameNewActionEvent.
* Adds the specified action to the list of pending EntityActions for this phase
* and fires a GameNewActionEvent.
*/
public void addAction(EntityAction action) {
pendingActions.add(action);
fireGameEvent(new GameNewActionEvent(this, action));
}

/**
* Clears and re-calculates the deployment table, i.e. assembles all units/objects in the game
* that are undeployed (that includes returning units or reinforcements) together with the game
* round that they are supposed to deploy on. This method can be called at any time in the game
* Clears and re-calculates the deployment table, i.e. assembles all
* units/objects in the game
* that are undeployed (that includes returning units or reinforcements)
* together with the game
* round that they are supposed to deploy on. This method can be called at any
* time in the game
* and will assemble deployment according to the present game state.
*/
public void setupDeployment() {
Expand Down Expand Up @@ -353,7 +368,6 @@ protected void setTurnIndex(int turnIndex) {
this.turnIndex = turnIndex;
}


public boolean hasBoardLocation(@Nullable BoardLocation boardLocation) {
return hasBoardLocation(boardLocation.coords(), boardLocation.boardId());
}
Expand Down Expand Up @@ -395,8 +409,9 @@ public List<ICarryable> getGroundObjects(Coords coords) {
}

/**
* @return Collection of objects on the ground. Best to use getGroundObjects(Coords)
* if looking for objects in specific hex
* @return Collection of objects on the ground. Best to use
* getGroundObjects(Coords)
* if looking for objects in specific hex
*/
public Map<Coords, List<ICarryable>> getGroundObjects() {
return groundObjects;
Expand All @@ -409,7 +424,6 @@ public void setGroundObjects(Map<Coords, List<ICarryable>> groundObjects) {
this.groundObjects = groundObjects;
}


@Override
public final List<TriggeredEvent> scriptedEvents() {
return Collections.unmodifiableList(scriptedEvents);
Expand Down
Loading

0 comments on commit 30bd768

Please sign in to comment.