Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed Strategic Formations to Combat Teams #5340

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions MekHQ/src/mekhq/AtBGameThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import java.util.*;
import java.util.stream.Collectors;

import static mekhq.campaign.force.StrategicFormation.getStandardForceSize;
import static mekhq.campaign.force.CombatTeam.getStandardForceSize;

/**
* Enhanced version of GameThread which imports settings and non-player units
Expand Down Expand Up @@ -267,8 +267,8 @@ public void run() {
// Set scenario type-specific delay
deploymentRound = Math.max(entity.getDeployRound(), scenario.getDeploymentDelay() - speed);
// Lances deployed in scout roles always deploy units in 6-walking speed turns
if (scenario.getLanceRole().isScouting() && (scenario.getStrategicFormation(campaign) != null)
&& (scenario.getStrategicFormation(campaign).getForceId() == scenario.getStrategicFormationId())
if (scenario.getLanceRole().isScouting() && (scenario.getCombatTeamById(campaign) != null)
&& (scenario.getCombatTeamById(campaign).getForceId() == scenario.getCombatTeamId())
&& !useDropship) {
deploymentRound = Math.max(deploymentRound, 6 - speed);
}
Expand Down Expand Up @@ -336,7 +336,7 @@ public void run() {
}
deploymentRound = Math.max(entity.getDeployRound(), scenario.getDeploymentDelay() - speed);
if (!useDropship && scenario.getLanceRole().isScouting()
&& (scenario.getStrategicFormation(campaign).getForceId() == scenario.getStrategicFormationId())) {
&& (scenario.getCombatTeamById(campaign).getForceId() == scenario.getCombatTeamId())) {
deploymentRound = Math.max(deploymentRound, 6 - speed);
}
}
Expand Down
118 changes: 59 additions & 59 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
import mekhq.campaign.event.*;
import mekhq.campaign.finances.*;
import mekhq.campaign.finances.enums.TransactionType;
import mekhq.campaign.force.CombatTeam;
import mekhq.campaign.force.Force;
import mekhq.campaign.force.StrategicFormation;
import mekhq.campaign.icons.StandardForceIcon;
import mekhq.campaign.icons.UnitIcon;
import mekhq.campaign.log.HistoricalLogEntry;
Expand Down Expand Up @@ -142,15 +142,15 @@
import java.util.Map.Entry;
import java.util.stream.Collectors;

import static mekhq.campaign.force.StrategicFormation.recalculateStrategicFormations;
import static mekhq.campaign.force.CombatTeam.recalculateCombatTeams;
import static mekhq.campaign.market.contractMarket.ContractAutomation.performAutomatedActivation;
import static mekhq.campaign.mission.AtBContract.pickRandomCamouflage;
import static mekhq.campaign.personnel.SkillType.S_ADMIN;
import static mekhq.campaign.personnel.backgrounds.BackgroundsController.randomMercenaryCompanyNameGenerator;
import static mekhq.campaign.personnel.education.EducationController.getAcademy;
import static mekhq.campaign.personnel.turnoverAndRetention.RetirementDefectionTracker.Payout.isBreakingContract;
import static mekhq.campaign.unit.Unit.SITE_FACILITY_BASIC;
import static mekhq.utilities.ReportingUtilities.CLOSING_SPAN_TAG;
import static mekhq.campaign.mission.AtBContract.pickRandomCamouflage;
/**
* The main campaign class, keeps track of teams and units
*
Expand Down Expand Up @@ -203,7 +203,7 @@

// hierarchically structured Force object to define TO&E
private Force forces;
private Hashtable<Integer, StrategicFormation> strategicFormations; // AtB
private Hashtable<Integer, CombatTeam> combatTeams; // AtB

private Faction faction;
private int techFactionCode;
Expand Down Expand Up @@ -318,7 +318,7 @@
setRankSystemDirect(Ranks.getRankSystemFromCode(Ranks.DEFAULT_SYSTEM_CODE));
forces = new Force(name);
forceIds.put(0, forces);
strategicFormations = new Hashtable<>();
combatTeams = new Hashtable<>();
finances = new Finances();
astechPool = 0;
medicPool = 0;
Expand Down Expand Up @@ -459,45 +459,45 @@
}

/**
* Adds a {@link StrategicFormation} to the {@code strategicFormations} {@link Hashtable} using
* Adds a {@link CombatTeam} to the {@code combatTeams} {@link Hashtable} using
* {@code forceId} as the key.
*
* @param strategicFormation the {@link StrategicFormation} to be added to the {@link Hashtable}
* @param combatTeam the {@link CombatTeam} to be added to the {@link Hashtable}
*/
public void addStrategicFormation(StrategicFormation strategicFormation) {
strategicFormations.put(strategicFormation.getForceId(), strategicFormation);
public void addCombatTeam(CombatTeam combatTeam) {
combatTeams.put(combatTeam.getForceId(), combatTeam);
}

/**
* Removes a {@link StrategicFormation} from the {@code strategicFormations} {@link Hashtable}
* using {@code forceId} as they key.
* Removes a {@link CombatTeam} from the {@code combatTeams} {@link Hashtable} using
* {@code forceId} as the key.
*
* @param forceId the key of the {@link StrategicFormation} to be removed from the {@link Hashtable}
* @param forceId the key of the {@link CombatTeam} to be removed from the {@link Hashtable}
*/
public void removeStrategicFormation(final int forceId) {
this.strategicFormations.remove(forceId);
public void removeCombatTeam(final int forceId) {
this.combatTeams.remove(forceId);
}

/**
* Returns the {@link Hashtable} containing all the {@link StrategicFormation} objects after
* Returns the {@link Hashtable} containing all the {@link CombatTeam} objects after
* removing the ineligible ones. Although sanitization might not be necessary, it ensures that
* there is no need for {@code isEligible()} checks when fetching the {@link Hashtable}.
*
* @return the sanitized {@link Hashtable} of {@link StrategicFormation} objects stored in the
* @return the sanitized {@link Hashtable} of {@link CombatTeam} objects stored in the
* current campaign.
*/
public Hashtable<Integer, StrategicFormation> getStrategicFormationsTable() {
public Hashtable<Integer, CombatTeam> getCombatTeamsTable() {

Check notice

Code scanning / CodeQL

Exposing internal representation Note

getCombatTeamsTable exposes the internal representation stored in field combatTeams. The value may be modified
after this call to getCombatTeamsTable
.
// Here we sanitize the list, ensuring ineligible formations have been removed before
// returning the hashtable. In theory, this shouldn't be necessary, however, having this
// sanitizing step should remove the need for isEligible() checks whenever we fetch the
// hashtable.
List<Integer> formationsToSanitize = new ArrayList<>();
for (StrategicFormation strategicFormation : strategicFormations.values()) {
if (!strategicFormation.isEligible(this)) {
formationsToSanitize.add(strategicFormation.getForceId());
for (CombatTeam combatTeam : combatTeams.values()) {
if (!combatTeam.isEligible(this)) {
formationsToSanitize.add(combatTeam.getForceId());
try {
Force force = getForce(strategicFormation.getForceId());
force.setStrategicFormation(false);
Force force = getForce(combatTeam.getForceId());
force.setCombatTeamStatus(false);
} catch (Exception ex) {
// We're not too worried if we can't find the associated Force,
// as this just means it has been deleted at some point and not removed correctly.
Expand All @@ -506,27 +506,27 @@
}

for (int id : formationsToSanitize) {
strategicFormations.remove(id);
combatTeams.remove(id);
}

return strategicFormations;
return combatTeams;
}

/**
* Returns an {@link ArrayList} of all {@link StrategicFormation} objects in the
* {@code strategicFormations} {@link Hashtable}.
* Calls the {@code getStrategicFormationsTable()} method to sanitize the {@link Hashtable}
* Returns an {@link ArrayList} of all {@link CombatTeam} objects in the
* {@code combatTeams} {@link Hashtable}.
* Calls the {@code getCombatTeamsTable()} method to sanitize the {@link Hashtable}
* before conversion to {@link ArrayList}.
*
* @return an {@link ArrayList} of all the {@link StrategicFormation} objects in the
* {@code strategicFormations} {@link Hashtable}
* @return an {@link ArrayList} of all the {@link CombatTeam} objects in the
* {@code combatTeams} {@link Hashtable}
*/
public ArrayList<StrategicFormation> getAllStrategicFormations() {
// This call allows us to utilize the self-sanitizing feature of getStrategicFormationsTable(),
public ArrayList<CombatTeam> getAllCombatTeams() {
// This call allows us to utilize the self-sanitizing feature of getCombatTeamsTable(),
// without needing to directly include the code here, too.
strategicFormations = getStrategicFormationsTable();
combatTeams = getCombatTeamsTable();

return strategicFormations.values().stream()
return combatTeams.values().stream()
.filter(l -> forceIds.containsKey(l.getForceId()))
.collect(Collectors.toCollection(ArrayList::new));
}
Expand Down Expand Up @@ -975,7 +975,7 @@
force.updateCommander(this);

if (campaignOptions.isUseAtB()) {
recalculateStrategicFormations(this);
recalculateCombatTeams(this);
}
}

Expand Down Expand Up @@ -1069,18 +1069,18 @@
}

if (campaignOptions.isUseAtB()) {
recalculateStrategicFormations(this);
recalculateCombatTeams(this);
}
}

/**
* Adds force and all its subforces to the AtB lance table
* Adds force and all its subforces to the Combat Teams table
*/
private void addAllStrategicFormations(Force force) {
recalculateStrategicFormations(this);
private void addAllCombatTeams(Force force) {
recalculateCombatTeams(this);

for (Force subForce : force.getSubForces()) {
addAllStrategicFormations(subForce);
addAllCombatTeams(subForce);
}
}

Expand Down Expand Up @@ -3714,7 +3714,7 @@
int role = -Math.max(1, contract.getRequiredLances() / 2);

final AtBLanceRole requiredLanceRole = contract.getContractType().getRequiredLanceRole();
for (StrategicFormation l : strategicFormations.values()) {
for (CombatTeam l : combatTeams.values()) {
if (!l.getRole().isUnassigned() && (l.getMissionId() == contract.getId())) {
total++;
if (l.getRole() == requiredLanceRole) {
Expand Down Expand Up @@ -3813,8 +3813,8 @@
// If there is a standard battle set for today, deploy the lance.
for (final AtBScenario s : contract.getCurrentAtBScenarios()) {
if ((s.getDate() != null) && s.getDate().equals(getLocalDate())) {
int forceId = s.getStrategicFormationId();
if ((strategicFormations.get(forceId) != null) && !forceIds.get(forceId).isDeployed()) {
int forceId = s.getCombatTeamId();
if ((combatTeams.get(forceId) != null) && !forceIds.get(forceId).isDeployed()) {
// If any unit in the force is under repair, don't deploy the force
// Merely removing the unit from deployment would break with user expectation
boolean forceUnderRepair = false;
Expand Down Expand Up @@ -3872,11 +3872,11 @@
if (getLocalDate().getDayOfWeek() == DayOfWeek.MONDAY) {
processShipSearch();

// Training Experience - Award to eligible training Strategic Formations on active contracts
getStrategicFormationsTable().values().stream()
.filter(strategicFormation -> strategicFormation.getRole().isTraining()
&& (strategicFormation.getContract(this) != null) && strategicFormation.isEligible(this)
&& strategicFormation.getContract(this).isActiveOn(getLocalDate(), true))
// Training Experience - Award to eligible training Combat Teams on active contracts
getCombatTeamsTable().values().stream()
.filter(combatTeam -> combatTeam.getRole().isTraining()
&& (combatTeam.getContract(this) != null) && combatTeam.isEligible(this)
&& combatTeam.getContract(this).isActiveOn(getLocalDate(), true))
.forEach(this::awardTrainingXP);
}

Expand Down Expand Up @@ -4404,7 +4404,7 @@
private void processNewDayForces() {
// update formation levels
Force.populateFormationLevelsFromOrigin(this);
recalculateStrategicFormations(this);
recalculateCombatTeams(this);

// Update the force icons based on the end-of-day unit status if desired
if (MekHQ.getMHQOptions().getNewDayForceIconOperationalStatus()) {
Expand Down Expand Up @@ -4981,9 +4981,9 @@
* commanding officer and
* the minimum experience level of the unit's members.
*
* @param l The {@link StrategicFormation} to calculate XP to award for training.
* @param l The {@link CombatTeam} to calculate XP to award for training.
*/
private void awardTrainingXP(final StrategicFormation l) {
private void awardTrainingXP(final CombatTeam l) {
for (UUID trainerId : forceIds.get(l.getForceId()).getAllUnits(true)) {
Unit trainerUnit = getHangar().getUnit(trainerId);

Expand Down Expand Up @@ -5120,7 +5120,7 @@
}

if (campaignOptions.isUseAtB()) {
recalculateStrategicFormations(this);
recalculateCombatTeams(this);
}
}

Expand Down Expand Up @@ -5154,7 +5154,7 @@
}

if (campaignOptions.isUseAtB() && force.getUnits().isEmpty()) {
strategicFormations.remove(force.getId());
combatTeams.remove(force.getId());
}
}
}
Expand Down Expand Up @@ -5730,14 +5730,14 @@
// CAW: implicit DEPENDS-ON to the <missions> node, do not move this above it
contractMarket.writeToXML(pw, indent);

if (!strategicFormations.isEmpty()) {
MHQXMLUtility.writeSimpleXMLOpenTag(pw, indent++, "strategicFormations");
for (StrategicFormation l : strategicFormations.values()) {
if (!combatTeams.isEmpty()) {
MHQXMLUtility.writeSimpleXMLOpenTag(pw, indent++, "combatTeams");
for (CombatTeam l : combatTeams.values()) {
if (forceIds.containsKey(l.getForceId())) {
l.writeToXML(pw, indent);
}
}
MHQXMLUtility.writeSimpleXMLCloseTag(pw, --indent, "strategicFormations");
MHQXMLUtility.writeSimpleXMLCloseTag(pw, --indent, "combatTeams");
}
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "shipSearchStart", getShipSearchStart());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "shipSearchType", shipSearchType);
Expand Down Expand Up @@ -6763,8 +6763,8 @@
}

public @Nullable AtBContract getAttachedAtBContract(Unit unit) {
if (null != unit && null != strategicFormations.get(unit.getForceId())) {
return strategicFormations.get(unit.getForceId()).getContract(this);
if (null != unit && null != combatTeams.get(unit.getForceId())) {
return combatTeams.get(unit.getForceId()).getContract(this);
}
return null;
}
Expand Down Expand Up @@ -8410,7 +8410,7 @@
}
}

addAllStrategicFormations(this.forces);
addAllCombatTeams(this.forces);

// Determine whether or not there is an active contract
setHasActiveContract();
Expand Down
Loading
Loading