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 'Lances' to 'Strategic Formations', Expanded Functionality #5250

Merged
merged 8 commits into from
Nov 29, 2024
54 changes: 18 additions & 36 deletions MekHQ/src/mekhq/AtBGameThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,29 @@
*/
package mekhq;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;

import javax.swing.JOptionPane;

import io.sentry.Sentry;
import megamek.client.AbstractClient;
import megamek.client.Client;
import megamek.client.bot.BotClient;
import megamek.client.bot.princess.Princess;
import megamek.client.generator.RandomCallsignGenerator;
import megamek.client.ui.swing.ClientGUI;
import megamek.common.Entity;
import megamek.common.IAero;
import megamek.common.Infantry;
import megamek.common.MapSettings;
import megamek.common.Minefield;
import megamek.common.UnitType;
import megamek.common.*;
import megamek.common.planetaryconditions.PlanetaryConditions;
import megamek.logging.MMLogger;
import mekhq.campaign.force.Force;
import mekhq.campaign.force.Lance;
import mekhq.campaign.mission.AtBContract;
import mekhq.campaign.mission.AtBDynamicScenario;
import mekhq.campaign.mission.AtBScenario;
import mekhq.campaign.mission.BotForce;
import mekhq.campaign.mission.Scenario;
import mekhq.campaign.force.StrategicFormation;
import mekhq.campaign.mission.*;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.unit.Unit;

import javax.swing.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.*;

/**
* Enhanced version of GameThread which imports settings and non-player units
* into the MM game
Expand Down Expand Up @@ -277,8 +259,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.getLance(campaign) != null)
&& (scenario.getLance(campaign).getForceId() == scenario.getLanceForceId())
if (scenario.getLanceRole().isScouting() && (scenario.getStrategicFormation(campaign) != null)
&& (scenario.getStrategicFormation(campaign).getForceId() == scenario.getStrategicFormationId())
&& !useDropship) {
deploymentRound = Math.max(deploymentRound, 6 - speed);
}
Expand Down Expand Up @@ -346,7 +328,7 @@ public void run() {
}
deploymentRound = Math.max(entity.getDeployRound(), scenario.getDeploymentDelay() - speed);
if (!useDropship && scenario.getLanceRole().isScouting()
&& (scenario.getLance(campaign).getForceId() == scenario.getLanceForceId())) {
&& (scenario.getStrategicFormation(campaign).getForceId() == scenario.getStrategicFormationId())) {
deploymentRound = Math.max(deploymentRound, 6 - speed);
}
}
Expand Down Expand Up @@ -537,12 +519,12 @@ protected List<Entity> setupBotEntities(BotClient botClient, BotForce botForce,
int lanceSize;

if (botForce.getTeam() == 2) {
lanceSize = Lance.getStdLanceSize(contract.getEnemy());
lanceSize = StrategicFormation.getStdLanceSize(contract.getEnemy());
} else {
lanceSize = Lance.getStdLanceSize(contract.getEmployerFaction());
lanceSize = StrategicFormation.getStdLanceSize(contract.getEmployerFaction());
}

Comparator<Entity> comp = Comparator.comparing(((Entity e) -> e.getEntityMajorTypeName(e.getEntityType())));
Comparator<Entity> comp = Comparator.comparing(((Entity e) -> Entity.getEntityMajorTypeName(e.getEntityType())));
Dismissed Show dismissed Hide dismissed
comp = comp.thenComparing(((Entity e) -> e.getRunMP()), Comparator.reverseOrder());
comp = comp.thenComparing(((Entity e) -> e.getRole().toString()));
entitiesSorted.sort(comp);
Expand All @@ -553,13 +535,13 @@ protected List<Entity> setupBotEntities(BotClient botClient, BotForce botForce,
}

if ((i != 0)
&& !lastType.equals(entity.getEntityMajorTypeName(entity.getEntityType()))) {
&& !lastType.equals(Entity.getEntityMajorTypeName(entity.getEntityType()))) {
forceIdLance++;
lanceName = RCG.generate();
i = forceIdLance * lanceSize;
}

lastType = entity.getEntityMajorTypeName(entity.getEntityType());
lastType = Entity.getEntityMajorTypeName(entity.getEntityType());
entity.setOwner(botClient.getLocalPlayer());
String fName = String.format(forceName, lanceName, forceIdLance);
entity.setForceString(fName);
Expand Down
69 changes: 34 additions & 35 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import mekhq.campaign.finances.*;
import mekhq.campaign.finances.enums.TransactionType;
import mekhq.campaign.force.Force;
import mekhq.campaign.force.Lance;
import mekhq.campaign.force.StrategicFormation;
import mekhq.campaign.icons.StandardForceIcon;
import mekhq.campaign.icons.UnitIcon;
import mekhq.campaign.log.HistoricalLogEntry;
Expand Down Expand Up @@ -199,7 +199,7 @@ public class Campaign implements ITechManager {

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

private Faction faction;
private int techFactionCode;
Expand Down Expand Up @@ -309,7 +309,7 @@ public Campaign() {
setRankSystemDirect(Ranks.getRankSystemFromCode(Ranks.DEFAULT_SYSTEM_CODE));
forces = new Force(name);
forceIds.put(0, forces);
lances = new Hashtable<>();
strategicFormations = new Hashtable<>();
finances = new Finances();
astechPool = 0;
medicPool = 0;
Expand Down Expand Up @@ -448,16 +448,16 @@ public List<Force> getAllForces() {
return new ArrayList<>(forceIds.values());
}

public void importLance(Lance l) {
lances.put(l.getForceId(), l);
public void importLance(StrategicFormation l) {
strategicFormations.put(l.getForceId(), l);
}

public Hashtable<Integer, Lance> getLances() {
return lances;
public Hashtable<Integer, StrategicFormation> getStrategicFormations() {
Dismissed Show dismissed Hide dismissed
return strategicFormations;
}

public ArrayList<Lance> getLanceList() {
return lances.values().stream()
public ArrayList<StrategicFormation> getStrategicFormationList() {
return strategicFormations.values().stream()
.filter(l -> forceIds.containsKey(l.getForceId()))
.collect(Collectors.toCollection(ArrayList::new));
}
Expand Down Expand Up @@ -904,8 +904,8 @@ public void addForce(Force force, Force superForce) {
lastForceId = id;

if (campaignOptions.isUseAtB() && !force.getUnits().isEmpty()) {
if (null == lances.get(id)) {
lances.put(id, new Lance(force.getId(), this));
if (null == strategicFormations.get(id)) {
strategicFormations.put(id, new StrategicFormation(force.getId(), this));
}
}

Expand Down Expand Up @@ -1003,22 +1003,21 @@ public void addUnitToForce(@Nullable Unit u, int id) {

if (campaignOptions.isUseAtB()) {
if ((null != prevForce) && prevForce.getUnits().isEmpty()) {
lances.remove(prevForce.getId());
strategicFormations.remove(prevForce.getId());
}

if ((null == lances.get(id)) && (null != force)) {
lances.put(id, new Lance(force.getId(), this));
if ((null == strategicFormations.get(id)) && (null != force)) {
strategicFormations.put(id, new StrategicFormation(force.getId(), this));
}
}
}

/**
* Adds force and all its subforces to the AtB lance table
*/

private void addAllLances(Force force) {
if (!force.getUnits().isEmpty()) {
lances.put(force.getId(), new Lance(force.getId(), this));
if (force.isStrategicFormation()) {
strategicFormations.put(force.getId(), new StrategicFormation(force.getId(), this));
}
for (Force f : force.getSubForces()) {
addAllLances(f);
Expand Down Expand Up @@ -3618,7 +3617,7 @@ public int getDeploymentDeficit(AtBContract contract) {
int role = -Math.max(1, contract.getRequiredLances() / 2);

final AtBLanceRole requiredLanceRole = contract.getContractType().getRequiredLanceRole();
for (Lance l : lances.values()) {
for (StrategicFormation l : strategicFormations.values()) {
if (!l.getRole().isUnassigned() && (l.getMissionId() == contract.getId())) {
total++;
if (l.getRole() == requiredLanceRole) {
Expand Down Expand Up @@ -3717,8 +3716,8 @@ && getLocation().getJumpPath().getLastSystem().getId().equals(contract.getSystem
// 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.getLanceForceId();
if ((lances.get(forceId) != null) && !forceIds.get(forceId).isDeployed()) {
int forceId = s.getStrategicFormationId();
if ((strategicFormations.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 @@ -3776,11 +3775,11 @@ private void processNewDayATB() {
if (getLocalDate().getDayOfWeek() == DayOfWeek.MONDAY) {
processShipSearch();

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

Expand Down Expand Up @@ -4841,9 +4840,9 @@ public void removePerson(final @Nullable Person person, final boolean log) {
* commanding officer and
* the minimum experience level of the unit's members.
*
* @param l The {@link Lance} to calculate XP to award for training.
* @param l The {@link StrategicFormation} to calculate XP to award for training.
*/
private void awardTrainingXP(final Lance l) {
private void awardTrainingXP(final StrategicFormation l) {
for (UUID trainerId : forceIds.get(l.getForceId()).getAllUnits(true)) {
Unit trainerUnit = getHangar().getUnit(trainerId);

Expand Down Expand Up @@ -4967,7 +4966,7 @@ public void removeForce(Force force) {
}

if (campaignOptions.isUseAtB()) {
lances.remove(fid);
strategicFormations.remove(fid);
}

if (null != force.getParentForce()) {
Expand Down Expand Up @@ -5020,7 +5019,7 @@ public void removeUnitFromForce(Unit u) {
}

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

if (!lances.isEmpty()) {
MHQXMLUtility.writeSimpleXMLOpenTag(pw, indent++, "lances");
for (Lance l : lances.values()) {
if (!strategicFormations.isEmpty()) {
MHQXMLUtility.writeSimpleXMLOpenTag(pw, indent++, "strategicFormations");
for (StrategicFormation l : strategicFormations.values()) {
if (forceIds.containsKey(l.getForceId())) {
l.writeToXML(pw, indent);
}
}
MHQXMLUtility.writeSimpleXMLCloseTag(pw, --indent, "lances");
MHQXMLUtility.writeSimpleXMLCloseTag(pw, --indent, "strategicFormations");
}
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "shipSearchStart", getShipSearchStart());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "shipSearchType", shipSearchType);
Expand Down Expand Up @@ -6627,8 +6626,8 @@ public TargetRoll getTargetForAcquisition(final IAcquisitionWork acquisition,
}

public @Nullable AtBContract getAttachedAtBContract(Unit unit) {
if (null != unit && null != lances.get(unit.getForceId())) {
return lances.get(unit.getForceId()).getContract(this);
if (null != unit && null != strategicFormations.get(unit.getForceId())) {
return strategicFormations.get(unit.getForceId()).getContract(this);
}
return null;
}
Expand Down
Loading
Loading